docIds.addAll(task.getTargetDocumentsIds()); String docIdVar = task.getVariable(TaskService.VariableName.documentId.name()); if (!docIds.contains(docIdVar)) { docIds.add(docIdVar); String docRepo = task.getVariable(TaskService.VariableName.documentRepositoryName.name()); List<DocumentModel> documents = new ArrayList<>(); if (coreSession.getRepositoryName().equals(docRepo)) {
protected void createTask(DocumentModel document, CoreSession session, NuxeoPrincipal principal) { String[] actorIds = getValidatorsFor(document); Map<String, String> variables = new HashMap<String, String>(); variables.put(Task.TaskVariableName.needi18n.name(), "true"); variables.put(Task.TaskVariableName.taskType.name(), PUBLISH_TASK_TYPE); variables.put(TaskService.VariableName.documentId.name(), document.getId()); variables.put(TaskService.VariableName.documentRepositoryName.name(), document.getRepositoryName()); variables.put(TaskService.VariableName.initiator.name(), principal.getName()); getTaskService().createTask(session, principal, document, TASK_NAME, Arrays.asList(actorIds), false, TASK_NAME, null, null, variables, null); DocumentEventContext ctx = new DocumentEventContext(session, principal, document); ctx.setProperty(NotificationConstants.RECIPIENTS_KEY, actorIds); getEventProducer().fireEvent(ctx.newEvent(TaskEventNames.WORKFLOW_TASK_START)); }
variables.put(TaskService.VariableName.documentId.name(), document.getId()); variables.put(TaskService.VariableName.documentRepositoryName.name(), document.getRepositoryName()); variables.put(TaskService.VariableName.directive.name(), directive); variables.put(TaskService.VariableName.createdFromTaskService.name(), "true"); if (taskVariables != null) { variables.putAll(taskVariables);
Boolean validated = Boolean.valueOf(task.getVariable(TaskService.VariableName.validated.name()));
protected void endTask(DocumentModel document, NuxeoPrincipal currentUser, CoreSession session, String comment, PublishingEvent event) { List<Task> tis = getTaskService().getTaskInstances(document, currentUser, session); String initiator = null; for (Task task : tis) { if (task.getName().equals(TASK_NAME)) { initiator = (String) task.getVariable(TaskService.VariableName.initiator.name()); task.end(session); // make sure taskDoc is attached to prevent sending event with null session DocumentModel taskDocument = task.getDocument(); if (taskDocument.getSessionId() == null) { taskDocument.attach(coreSession.getSessionId()); } session.saveDocument(taskDocument); break; } } DocumentModel liveDoc = getLiveDocument(session, document); Map<String, Serializable> properties = new HashMap<String, Serializable>(); if (initiator != null) { properties.put(NotificationConstants.RECIPIENTS_KEY, new String[] { initiator }); } notifyEvent(event.name(), properties, comment, null, liveDoc, session); }
@Override public String endTask(CoreSession coreSession, NuxeoPrincipal principal, Task task, String comment, String eventName, boolean isValidated) { // put user comment on the task if (!StringUtils.isEmpty(comment)) { task.addComment(principal.getName(), comment); } // end the task, adding boolean marker that task was validated or // rejected task.setVariable(TaskService.VariableName.validated.name(), String.valueOf(isValidated)); task.end(coreSession); // make sure taskDoc is attached to prevent sending event with null session DocumentModel taskDocument = task.getDocument(); if (taskDocument.getSessionId() == null) { taskDocument.attach(coreSession.getSessionId()); } coreSession.saveDocument(taskDocument); if (StringUtils.isNotBlank(eventName)) { TaskEventNotificationHelper.notifyTaskEnded(coreSession, principal, task, comment, eventName, null); } return isValidated ? TaskEventNames.WORKFLOW_TASK_COMPLETED : TaskEventNames.WORKFLOW_TASK_REJECTED; }