@OperationMethod() public DocumentModel run(DocumentModel document) throws Exception { List<String> docIds = new ArrayList<String>(1); docIds.add(document.getId()); routingService.createNewInstance(workflowName, docIds, documentManager, true); return document; }
@Override public void endTask(CoreSession session, Task task, Map<String, Object> data, String status) throws DocumentRouteException { DocumentRoutingService routing = Framework.getService(DocumentRoutingService.class); routing.endTask(session, task, data, status); }
public List<DocumentModel> findRelatedRoute(String documentId) throws ClientException { List<DocumentModel> docs = new ArrayList<DocumentModel>(); if(documentId == null || "".equals(documentId)) { return docs; } List<DocumentRoute> relatedRoutes = getDocumentRoutingService().getDocumentRoutesForAttachedDocument( documentManager, documentId); for (DocumentRoute documentRoute : relatedRoutes) { docs.add(documentRoute.getDocument()); } return docs; }
@Override public DocumentRoute startSubRoute() throws DocumentRouteException { String subRouteModelId = getSubRouteModelId(); // create the instance without starting it DocumentRoutingService service = Framework.getService(DocumentRoutingService.class); List<String> docs = graph.getAttachedDocuments(); String subRouteInstanceId = service.createNewInstance(subRouteModelId, docs, getSession(), false); // set info about parent in subroute DocumentModel subRouteInstance = getSession().getDocument(new IdRef(subRouteInstanceId)); subRouteInstance.setPropertyValue(GraphRoute.PROP_PARENT_ROUTE, getDocument().getParentRef().toString()); subRouteInstance.setPropertyValue(GraphRoute.PROP_PARENT_NODE, getDocument().getName()); subRouteInstance = getSession().saveDocument(subRouteInstance); // set info about subroute in parent document.setPropertyValue(PROP_SUB_ROUTE_INSTANCE_ID, subRouteInstanceId); saveDocument(); // start the sub-route Map<String, Serializable> map = getSubRouteInitialVariables(); service.startInstance(subRouteInstanceId, docs, map, getSession()); // return the sub-route // subRouteInstance.refresh(); DocumentRoute subRoute = subRouteInstance.getAdapter(DocumentRoute.class); return subRoute; }
/** * @return model of Direct Validation workflow. * @throws ClientException */ public DocumentModel getDirectValidationWorkflowModel() throws ClientException { String id = getDocumentRoutingService().getRouteModelDocIdWithId(documentManager, CnsConstants.CNS_VALIDATION_WF); return getRouteModel(id); }
@GET public List<Task> getUserRelatedWorkflowTasks(@QueryParam("userId") String userId, @QueryParam("workflowInstanceId") String workflowInstanceId, @QueryParam("workflowModelName") String workflowModelName) { return Framework.getService(DocumentRoutingService.class).getTasks(null, userId, workflowInstanceId, workflowModelName, getContext().getCoreSession()); }
@Override public List<DocumentModel> getWorkflowInputDocuments(CoreSession session, Task task) throws DocumentRouteException { DocumentRoutingService routing = Framework.getService(DocumentRoutingService.class); return routing.getWorkflowInputDocuments(session, task); }
@PUT @Path("{taskId}/delegate") public Response delegateTask(@PathParam("taskId") String taskId, @QueryParam("delegatedActors") List<String> delegatedActors, @QueryParam("comment") String comment) { Framework.getService(DocumentRoutingService.class).delegateTask(getContext().getCoreSession(), taskId, delegatedActors, comment); return Response.ok().status(Status.OK).build(); }
@GET public List<DocumentRoute> getWorkflowModels(@Context UriInfo uriInfo) { return Framework.getService(DocumentRoutingService.class).getAvailableDocumentRouteModel( getContext().getCoreSession()); }
@Override public void write(JsonGenerator jg, DocumentModel document) throws IOException { jg.writeFieldName(NAME); jg.writeStartArray(); try (SessionWrapper wrapper = ctx.getSession(document)) { DocumentRoutingService documentRoutingService = Framework.getService(DocumentRoutingService.class); List<DocumentRoute> documentRoutes = documentRoutingService.getDocumentRelatedWorkflows(document, wrapper.getSession()); for (DocumentRoute documentRoute : documentRoutes) { writeEntity(documentRoute, jg); } } finally { jg.writeEndArray(); } }
private DocumentModel getOnlineWorkflowModel() throws NuxeoException { String id = getDocumentRoutingService().getRouteModelDocIdWithId(documentManager, ToutaticeGlobalConst.CST_WORKFLOW_PROCESS_ONLINE); return getRouteModel(id); }
@GET public List<Task> doGet(@QueryParam("userId") String userId, @QueryParam("workflowInstanceId") String workflowInstanceId, @QueryParam("workflowModelName") String workflowModelName) { DocumentModel doc = getTarget().getAdapter(DocumentModel.class); return Framework.getService(DocumentRoutingService.class).getTasks(doc, userId, workflowInstanceId, workflowModelName, getContext().getCoreSession()); }
@OperationMethod public DocumentModel run(DocumentModel taskDoc) { Task task = taskDoc.getAdapter(Task.class); if (task == null) { throw new NuxeoException("Input document is not a Task"); } List<DocumentModel> docs = routing.getWorkflowInputDocuments(session, task); if (docs.size() == 0) { throw new NuxeoException("Can not fetch the input documents in the related workflow instance"); } if (docs.size() > 1) { log.warn("Using as mapping source only the first document in the input documents in the workflow"); } mappingService.mapProperties(session, docs.get(0), taskDoc, mappingName); return taskDoc; } }
/** * @since 5.8 */ public String delegateTask(TaskInfo taskInfo) { try { Framework.getLocalService(DocumentRoutingService.class).delegateTask( documentManager, taskInfo.getTaskId(), taskInfo.getActors(), taskInfo.getComment()); Events.instance().raiseEvent(TaskEventNames.WORKFLOW_TASK_DELEGATED); } catch (DocumentRouteException e) { log.error(e); facesMessages.add(StatusMessage.Severity.ERROR, messages.get("workflow.feedback.error.taskEnded")); } return null; }
List<DocumentRoute> wfModels = documentRoutingService.getAvailableDocumentRouteModel(session); List<String> modelNames = new ArrayList<String>(); for (DocumentRoute model : wfModels) {
@GET public List<DocumentRoute> doGet() { DocumentModel doc = getTarget().getAdapter(DocumentModel.class); return Framework.getService(DocumentRoutingService.class).getDocumentRelatedWorkflows(doc, getContext().getCoreSession()); }
protected void startNewInstance(List<String> ids) { Map<String, Serializable> vars = new HashMap<String, Serializable>(); if (variables != null) { for (Entry<String, String> entry : variables.entrySet()) { vars.put(entry.getKey(), entry.getValue()); } } vars.put(DocumentRoutingConstants._MAP_VAR_FORMAT_JSON, Boolean.TRUE); String workflowId = documentRoutingService.createNewInstance(id, ids, vars, session, Boolean.TRUE.equals(start)); ctx.put("WorkflowId", workflowId); // to be consistent with all the other workflow variablesin the context // @since 5.7.2 ctx.put("workflowInstanceId", workflowId); } }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel completeTask(DocumentModel task) { Map<String, Object> data = new HashMap<String, Object>(); if (comment != null) { data.put("comment", comment); } // the service expects an unique map containing both worflow and // nodeVariables if (nodeVariables != null) { data.put(Constants.VAR_WORKFLOW_NODE, nodeVariables); } if (workflowVariables != null) { data.put(Constants.VAR_WORKFLOW, workflowVariables); } data.put(DocumentRoutingConstants._MAP_VAR_FORMAT_JSON, Boolean.TRUE); documentRoutingService.endTask(session, task.getAdapter(Task.class), data, status); return task; } }
public boolean isWorkflowRunningForDocument(DocumentModel document) throws NuxeoException { List<DocumentRoute> documentRoutes = getDocumentRoutingService().getDocumentRoutesForAttachedDocument(documentManager, document.getId()); return (documentRoutes != null && !documentRoutes.isEmpty()); }
@Override protected WorkflowRequest readEntity(JsonNode jn) throws IOException { String workflowModelName = getStringField(jn, "workflowModelName"); List<String> attachedDocumentIds = new ArrayList<String>(); JsonNode attachedDocumentIdsNode = jn.get("attachedDocumentIds"); if (attachedDocumentIdsNode != null) { for (Iterator<JsonNode> it = attachedDocumentIdsNode.elements(); it.hasNext();) { attachedDocumentIds.add(it.next().textValue()); } } Map<String, Serializable> variables = new HashMap<>(); JsonNode variablesNode = jn.get("variables"); if (variablesNode != null) { try (SessionWrapper closeable = ctx.getSession(null)) { CoreSession session = closeable.getSession(); String workflowModelId = documentRoutingService.getRouteModelDocIdWithId(session, workflowModelName); DocumentModel model = session.getDocument(new IdRef(workflowModelId)); String workflowSchemaFacet = (String) model.getPropertyValue(GraphRoute.PROP_VARIABLES_FACET); CompositeType type = schemaManager.getFacet(workflowSchemaFacet); String workflowSchema = type.getSchemaNames()[0]; variables.putAll(getVariables(variablesNode, workflowSchema)); } } return new WorkflowRequest(workflowModelName, attachedDocumentIds, variables); }