Programatically deleting documents

I've set up a scheduled event listener that will delete documents that are no longer considered relevant. It seems to be working, I'm just concerned by the some of the log messages that seem to be triggered by various nuxeo processes directly after it finishes running.

16:37:22,412 INFO  [ScheduledUnsavedContentUtil] Removed 10 unsaved documents
16:37:22,448 WARN  [NXAuditEventsService] Document associated to event does not exists anymore
16:37:22,449 WARN  [NXAuditEventsService] Document associated to event does not exists anymore
16:37:22,449 WARN  [NXAuditEventsService] Document associated to event does not exists anymore
16:37:22,450 WARN  [NXAuditEventsService] Document associated to event does not exists anymore
16:37:22,450 WARN  [NXAuditEventsService] Document associated to event does not exists anymore
16:37:22,451 WARN  [NXAuditEventsService] Document associated to event does not exists anymore
16:37:22,451 WARN  [NXAuditEventsService] Document associated to event does not exists anymore
16:37:22,451 WARN  [NXAuditEventsService] Document associated to event does not exists anymore
16:37:22,452 WARN  [NXAuditEventsService] Document associated to event does not exists anymore
16:37:22,452 WARN  [NXAuditEventsService] Document associated to event does not exists anymore

The code that is responsible for deleting the documents is below, the getCandidates() method is using an NXQL query to determine which docs to target :

    DocumentModelList documentModelList = getCandidates();
    LOG.info("About to remove " + documentModelList.size() + " unsaved documents");

    DocumentRef[] docRefs = new DocumentRef[documentModelList.size()];

    int i = 0;
    for (DocumentModel documentModel : documentModelList)
    {
        docRefs[i++] = documentModel.getRef();
    }
    coreSession.removeDocuments(docRefs);
    coreSession.save();

Are those warnings anything to be concerned about? Or is there something I should be running that will clean up any remaining state related to these documents?

1 votes

1 answers

1251 views

ANSWER



Hi,

You do well and you can ignore this message. This warn is generated because during the entry audit generation. Audit service try to fetch all information he can on the document, and here he try to get the state of the document.

But this information is not fetched into the documentModel attached to the event “DocumentDeleted”. We are using the lazy fetch, thats why some information can not be present into the documentModel.

So the audit log warn that audit will create the entry without the lifecycle state of the document.

We have the same warning when you remove permanently document from the trash view, into the Manage tab. But since the 5.5 version the level of this log has been changed to debug.

My deduction is you are using an old version of Nuxeo. I let you move to the Nuxeo 5.5 that is so cool :D

Thanks for you question.

1 votes