@Override public void run(CoreSession session, DocumentRouteElement element) { if (element.isRunning()) { return; } else { element.setRunning(session); } if (!(element instanceof DocumentRouteStep)) { throw new RuntimeException("Method run should be overriden in parent class."); } EventFirer.fireEvent(session, element, null, DocumentRoutingConstants.Events.beforeStepRunning.name()); try (OperationContext context = new OperationContext(session)) { context.put(DocumentRoutingConstants.OPERATION_STEP_DOCUMENT_KEY, element); context.setInput(element.getAttachedDocuments(session)); if (!element.isDone()) { EventFirer.fireEvent(session, element, null, DocumentRoutingConstants.Events.stepWaiting.name()); } String chainId = getDocumentRoutingService().getOperationChainId(element.getDocument().getType()); getAutomationService().run(context, chainId); } catch (OperationException e) { throw new NuxeoException(e); } }
@Override public void undo(CoreSession session, DocumentRouteElement element) { EventFirer.fireEvent(session, element, null, DocumentRoutingConstants.Events.beforeUndoingStep.name()); try (OperationContext context = new OperationContext(session)) { context.put(DocumentRoutingConstants.OPERATION_STEP_DOCUMENT_KEY, element); context.setInput(element.getAttachedDocuments(session)); String operationChainId; String docType = element.getDocument().getType(); if (element.isDone()) { operationChainId = getDocumentRoutingService().getUndoFromDoneOperationChainId(docType); } else if (element.isRunning()) { operationChainId = getDocumentRoutingService().getUndoFromRunningOperationChainId(docType); } else { throw new RuntimeException("Trying to undo a step neither in done nor running state."); } getAutomationService().run(context, operationChainId); } catch (OperationException e) { throw new NuxeoException(e); } EventFirer.fireEvent(session, element, null, DocumentRoutingConstants.Events.afterUndoingStep.name()); }