Search in sources :

Example 1 with DuplicateRecordException

use of org.alfresco.bm.dataload.rm.exceptions.DuplicateRecordException in project records-management by Alfresco.

the class ScheduleInPlaceRecordLoaders method scheduleFile.

/**
 * Helper method that creates a declare record event for the provided file
 *
 * @param fileToSchedule info of the file to declare as record
 * @param eventOutputMsg
 * @return the declare as record event for the provided file
 * @throws EventAlreadyScheduledException if the provided file has already been scheduled
 */
private Event scheduleFile(RecordData fileToSchedule, StringBuilder eventOutputMsg) throws EventAlreadyScheduledException {
    eventOutputMsg.append("Sheduled file to be declared as record: " + fileToSchedule.getId() + ". ");
    // Create record in database to lock it
    try {
        recordService.createRecord(fileToSchedule);
    } catch (DuplicateRecordException ex) {
        throw new EventAlreadyScheduledException(eventNameDeclareInPlaceRecord, fileToSchedule.getId());
    }
    // Create an event
    DBObject declareData = BasicDBObjectBuilder.start().add(FIELD_ID, fileToSchedule.getId()).add(FIELD_USERNAME, username).add(FIELD_PASSWORD, password).get();
    Event declareEvent = new Event(getEventNameDeclareInPlaceRecord(), declareData);
    // Each load event must be associated with a session
    String sessionId = sessionService.startSession(declareData);
    declareEvent.setSessionId(sessionId);
    return declareEvent;
}
Also used : DuplicateRecordException(org.alfresco.bm.dataload.rm.exceptions.DuplicateRecordException) EventAlreadyScheduledException(org.alfresco.bm.dataload.rm.exceptions.EventAlreadyScheduledException) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject)

Aggregations

DBObject (com.mongodb.DBObject)1 DuplicateRecordException (org.alfresco.bm.dataload.rm.exceptions.DuplicateRecordException)1 EventAlreadyScheduledException (org.alfresco.bm.dataload.rm.exceptions.EventAlreadyScheduledException)1 Event (org.alfresco.bm.event.Event)1