String posOfchildToRun = null; try { posOfchildToRun = (String) element.getDocument().getPropertyValue( DocumentRoutingConstants.STEP_TO_BE_EXECUTED_NEXT_PROPERTY_NAME); } catch (PropertyException e) { if (!element.isRunning()) { element.setRunning(session); element.setDone(session); return; if (!child.isDone() && !child.isCanceled()) { if (!(child instanceof DocumentRouteStepsContainer)) { child.run(session); if (!child.isDone()) { return; child.run(session); if (!child.isDone()) { return; if (!child.isCanceled()) { child.cancel(session); element.setDone(session);
@Override public void updateRouteElement(DocumentRouteElement routeElement, CoreSession session) throws DocumentRouteNotLockedException { if (!isLockedByCurrentUser(routeElement.getDocumentRoute(session), session)) { throw new DocumentRouteNotLockedException(); } routeElement.save(session); }
/** * Returns true if the givenDoc is an routeElement that can be edited */ public boolean isEditableRouteElement(DocumentModel stepDoc) throws ClientException { DocumentRouteElement stepElement = stepDoc.getAdapter(DocumentRouteElement.class); return stepElement.isModifiable(); }
@Override public void cancel(CoreSession session, DocumentRouteElement element) { if (element.isCanceled()) { return; } if (element.isReady() || element.isDone()) { element.setCanceled(session); } else if (element.isRunning()) { try { undo(session, element); } finally { element.setCanceled(session); } } else { throw new RuntimeException("Not allowed to cancel an element neither in ready, done or running state."); } } }
@Override public void cancel(CoreSession session, DocumentRouteElement element) { List<DocumentRouteElement> children = getChildrenElement(session, element); for (DocumentRouteElement child : children) { child.cancel(session); } element.setCanceled(session); } }
@Override public void run(CoreSession session, DocumentRouteElement element) { List<DocumentRouteElement> children = getChildrenElement(session, element); if (!element.isRunning()) { element.setRunning(session); } if (children.isEmpty()) { element.setDone(session); return; } // run all the child unless there is a wait state for (DocumentRouteElement child : children) { if (!child.isDone()) { child.run(session); if (!child.isDone()) { return; } } } // all child ran, we're done element.setDone(session); } }
@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); } }
public DocumentModel getDocument() { return element.getDocument(); }
@Override public void removeRouteElement(DocumentRouteElement routeElement, CoreSession session) throws DocumentRouteNotLockedException { DocumentRoute parentRoute = routeElement.getDocumentRoute(session); if (!isLockedByCurrentUser(parentRoute, session)) { throw new DocumentRouteNotLockedException(); } session.removeDocument(routeElement.getDocument().getRef()); session.save();// the document will be queried later on }
static public void fireEvent(CoreSession coreSession, DocumentRouteElement element, Map<String, Serializable> eventProperties, String eventName, DocumentModel doc) { if (eventProperties == null) { eventProperties = new HashMap<String, Serializable>(); } eventProperties.put(DocumentRoutingConstants.TASK_ROUTE_INSTANCE_DOCUMENT_ID_KEY, element.getDocumentRoute(coreSession).getDocument().getId()); eventProperties.put(DocumentRoutingConstants.DOCUMENT_ELEMENT_EVENT_CONTEXT_KEY, element); eventProperties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, DocumentEventCategories.EVENT_DOCUMENT_CATEGORY); DocumentEventContext envContext = new DocumentEventContext(coreSession, coreSession.getPrincipal(), doc); envContext.setProperties(eventProperties); getEventProducer().fireEvent(envContext.newEvent(eventName)); }
DocumentModel stepMoveBefore = orderedChilds.get(selectedDocumentIndex - 1); DocumentRouteElement stepElementMoveBefore = stepMoveBefore.getAdapter(DocumentRouteElement.class); if (stepElementMoveBefore.isRunning()) { facesMessages.add( StatusMessage.Severity.WARN, return null; if (!stepElementMoveBefore.isModifiable()) { facesMessages.add( StatusMessage.Severity.WARN, DocumentModel stepMoveAfter = orderedChilds.get(selectedDocumentIndex + 1); DocumentRouteElement stepElementMoveAfter = stepMoveAfter.getAdapter(DocumentRouteElement.class); if (stepElementMoveAfter.isRunning()) { facesMessages.add( StatusMessage.Severity.WARN,
@Override public void run() { DocumentModel parent = session.getDocument(document.getParentRef()); DocumentRouteElement parentElement = parent.getAdapter(DocumentRouteElement.class); isRunning = parentElement.isRunning(); }
@Override public void followTransition(ElementLifeCycleTransistion transition, CoreSession session, boolean recursive) { if (document.followTransition(transition.name())) { if (Framework.isTestModeSet()) { session.save(); } document = session.getDocument(document.getRef()); } if (recursive) { DocumentModelList children = session.getChildren(document.getRef()); for (DocumentModel child : children) { DocumentRouteElement element = child.getAdapter(DocumentRouteElement.class); element.followTransition(transition, session, recursive); } } }
@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()); }
List<DocumentRouteElement> children = getChildrenElement(session, element); if (children.isEmpty()) { element.setRunning(session); element.setDone(session); return; if (!element.isRunning()) { element.setRunning(session); boolean someChildrenNotDone = false; for (DocumentRouteElement child : children) { child.run(session); if (!child.isDone()) { someChildrenNotDone = true; element.setDone(session); boolean someChildrenNotDone = false; for (DocumentRouteElement child : children) { if (!child.isDone()) { child.run(session); if (!child.isDone()) { someChildrenNotDone = true; element.setDone(session);
protected List<DocumentRouteElement> getChildrenElement(CoreSession session, DocumentRouteElement element) { DocumentModelList children = session.getChildren(element.getDocument().getRef()); List<DocumentRouteElement> elements = new ArrayList<DocumentRouteElement>(); for (DocumentModel model : children) { elements.add(model.getAdapter(DocumentRouteElement.class)); } return elements; }
public String goBackToRoute() throws ClientException { DocumentModel currentDocument = navigationContext.getCurrentDocument(); DocumentRouteElement docRouteElement = currentDocument.getAdapter(DocumentRouteElement.class); return webActions.setCurrentTabAndNavigate( docRouteElement.getDocumentRoute(documentManager).getDocument(), "TAB_DOCUMENT_ROUTE_ELEMENTS"); }
static public void fireEvent(CoreSession coreSession, DocumentRouteElement element, Map<String, Serializable> eventProperties, String eventName) { if (eventProperties == null) { eventProperties = new HashMap<String, Serializable>(); } eventProperties.put(DocumentRoutingConstants.DOCUMENT_ELEMENT_EVENT_CONTEXT_KEY, element); eventProperties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, DocumentRoutingConstants.ROUTING_CATEGORY); DocumentEventContext envContext = new DocumentEventContext(coreSession, coreSession.getPrincipal(), element.getDocument()); envContext.setProperties(eventProperties); getEventProducer().fireEvent(envContext.newEvent(eventName)); }
private DocumentRoute getParentRouteModel(DocumentRef documentRef, CoreSession session) { DocumentModel parentDoc = session.getDocument(documentRef); if (parentDoc.hasFacet(DocumentRoutingConstants.DOCUMENT_ROUTE_DOCUMENT_FACET)) { return parentDoc.getAdapter(DocumentRoute.class); } DocumentRouteElement rElement = parentDoc.getAdapter(DocumentRouteElement.class); return rElement.getDocumentRoute(session); }
/** * Returns true if the givenDoc is a step that can be edited */ public boolean isEditableStep(DocumentModel stepDoc) throws ClientException { DocumentRouteElement stepElement = stepDoc.getAdapter(DocumentRouteElement.class); // if fork, is not simple editable step if (stepDoc.hasFacet("Folderish")) { return false; } return stepElement.isModifiable(); }