use of org.alfresco.bm.dataload.rm.exceptions.EventAlreadyScheduledException in project records-management by Alfresco.
the class ScheduleInPlaceRecordLoaders method processEvent.
@Override
protected EventResult processEvent(Event event) throws Exception {
if (!enabled) {
return new EventResult(DECLARING_NOT_WANTED_MSG, new Event(getEventNameComplete(), null));
}
long sessionCount = sessionService.getActiveSessionsCount();
int loaderSessionsToCreate = maxActiveLoaders - (int) sessionCount;
StringBuilder eventOutputMsg = new StringBuilder();
List<Event> nextEvents = new ArrayList<>(loaderSessionsToCreate + 1);
/*
* Prepare files
*/
restCoreAPI.authenticateUser(new UserModel(username, password));
prepareFilesToBeDeclared(eventOutputMsg);
if (unscheduledFilesCache.isEmpty()) {
// Make sure there are no files in process of being declared.
int scheduledInPlaceRecords = (int) recordService.getRecordCountInSpecifiedPaths(ExecutionState.SCHEDULED.name(), null);
if (scheduledInPlaceRecords > 0) {
// Reschedule self. Allow events to finish before raising the done event
Event nextEvent = new Event(getEventNameRescheduleSelf(), System.currentTimeMillis() + loadCheckDelay, null);
nextEvents.add(nextEvent);
eventOutputMsg.append("Waiting for " + scheduledInPlaceRecords + " in progress declare in place records events. Rescheduled self.");
return new EventResult(eventOutputMsg.toString(), nextEvents);
}
// no more files to declare, raise done event
return new EventResult(DONE_EVENT_MSG, new Event(getEventNameComplete(), null));
}
/*
* Schedule worker events
*/
for (int i = 0; i < loaderSessionsToCreate; i++) {
RecordData record = unscheduledFilesCache.poll();
if (record == null) {
break;
}
try {
nextEvents.add(scheduleFile(record, eventOutputMsg));
} catch (EventAlreadyScheduledException ex) {
logger.info("File " + record.getId() + " has already been scheduled. Skip it.", ex);
}
}
numberOfRecordsDeclared += nextEvents.size();
/*
* Reschedule self
*/
Event nextEvent = new Event(getEventNameRescheduleSelf(), System.currentTimeMillis() + loadCheckDelay, null);
nextEvents.add(nextEvent);
eventOutputMsg.append("Raised further " + (nextEvents.size() - 1) + " events and rescheduled self.");
return new EventResult(eventOutputMsg.toString(), nextEvents);
}
use of org.alfresco.bm.dataload.rm.exceptions.EventAlreadyScheduledException 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;
}
Aggregations