@Override public DocumentModelList getAttachedDocuments(CoreSession session) { List<String> docIds = getDocumentRoute(session).getAttachedDocuments(); List<DocumentRef> refs = new ArrayList<DocumentRef>(); for (String id : docIds) { IdRef idRef = new IdRef(id); if (session.exists(idRef)) { refs.add(idRef); } } return session.getDocuments(refs.toArray(new DocumentRef[] {})); }
@Override public void cancel(DocumentRoute routeInstance, CoreSession session) { final String routeDocId = routeInstance.getDocument().getId(); new UnrestrictedSessionRunner(session) { @Override public void run() { DocumentModel routeDoc = session.getDocument(new IdRef(routeDocId)); DocumentRoute routeInstance = routeDoc.getAdapter(DocumentRoute.class); if (routeInstance == null) { throw new NuxeoException("Document " + routeDoc + " can not be adapted to a DocumentRoute"); } routeInstance.cancel(session); } }.runUnrestricted(); Map<String, Serializable> properties = new HashMap<String, Serializable>(); properties.put(WORKFLOW_NAME_EVENT_PROPERTY_KEY, routeInstance.getTitle()); properties.put(WORKFLOW_ID_EVENT_PROPERTY_KEY, routeDocId); EventFirer.fireEvent(session, routeInstance.getAttachedDocuments(session), properties, DocumentRoutingConstants.Events.workflowCanceled.name()); } }
@Override public void finishTask(CoreSession session, DocumentRoute route, Task task, boolean delete) throws DocumentRouteException { DocumentModelList docs = route.getAttachedDocuments(session); try { removePermissionsForTaskActors(session, docs, task); // delete task if (delete) { session.removeDocument(new IdRef(task.getId())); } } catch (DocumentNotFoundException e) { throw new DocumentRouteException("Cannot finish task", e); } }
try (SessionWrapper wrapper = ctx.getSession(item.getDocument())) { final boolean isFetchAttachedDocumentIds = ctx.getFetched(ENTITY_TYPE).contains(FETCH_ATTACHED_DOCUMENTS); for (String docId : item.getAttachedDocuments()) { if (isFetchAttachedDocumentIds) { IdRef idRef = new IdRef(docId);
@Override public void run() { DocumentModel routeDoc = session.getDocument(new IdRef(workflowInstanceId)); DocumentRoute routeInstance = routeDoc.getAdapter(DocumentRoute.class); List<String> attachedDocumentIds = routeInstance.getAttachedDocuments(); if (attachedDocumentIds.isEmpty()) { return; } for (String attachedDocumentId : attachedDocumentIds) { if (session.exists(new IdRef(attachedDocumentId))) { return; } } DocumentRoutingEngineService routingEngine = Framework.getService(DocumentRoutingEngineService.class); routingEngine.cancel(routeInstance, session); isWorkflowCanceled = true; } }
@Override public List<DocumentModel> getWorkflowInputDocuments(CoreSession session, Task task) { String routeInstanceId; try { routeInstanceId = task.getProcessId(); } catch (PropertyException e) { throw new DocumentRouteException("Can not get the related workflow instance"); } if (StringUtils.isEmpty(routeInstanceId)) { throw new DocumentRouteException("Can not get the related workflow instance"); } DocumentModel routeDoc; try { routeDoc = session.getDocument(new IdRef(routeInstanceId)); } catch (DocumentNotFoundException e) { throw new DocumentRouteException("No workflow with the id:" + routeInstanceId); } DocumentRoute route = routeDoc.getAdapter(DocumentRoute.class); return route.getAttachedDocuments(session); }
DocumentModel docRoute = session.getDocument(new IdRef(routeId)); DocumentRoute route = docRoute.getAdapter(DocumentRoute.class); List<String> relatedDocIds = route.getAttachedDocuments(); route.cancel(session);
public String startRoute() throws ClientException { DocumentModel currentDocument = navigationContext.getCurrentDocument(); DocumentRoute currentRoute = currentDocument.getAdapter(DocumentRoute.class); if (currentRoute == null) { log.warn("Current document is not a workflow model"); facesMessages.add( StatusMessage.Severity.ERROR, resourcesAccessor.getMessages().get( "label.document.routing.no.workflow")); return null; } getDocumentRoutingService().createNewInstance( currentDocument.getName(), currentRoute.getAttachedDocuments(), documentManager, true); Events.instance().raiseEvent(EventNames.DOCUMENT_CHILDREN_CHANGED, currentDocument); Events.instance().raiseEvent(TaskEventNames.WORKFLOW_NEW_STARTED); webActions.resetTabList(); return null; }