public DashBoardItemImpl(Task task, Locale locale) { this(task, task.getDocument(), locale); }
public DashBoardItemImpl(Task task, DocumentModel document, Locale locale) { this.task = task; this.document = document; this.locale = locale; id = task.getId(); name = task.getName(); description = task.getDescription(); dueDate = task.getDueDate(); startDate = task.getCreated(); directive = task.getDirective(); List<TaskComment> comments = task.getComments(); if (comments != null && !comments.isEmpty()) { comment = comments.get(comments.size() - 1).getText(); } else { comment = null; } if (dueDate != null) { Date today = new Date(); expired = dueDate.before(today); } else { expired = false; } }
protected boolean isCreatedFromCreateTaskOperation() { return Boolean.parseBoolean(getTask().getVariable("createdFromCreateTaskOperation")); }
protected boolean isTaskActionAuthorized(String taskName) throws NuxeoException { boolean isAuthorized = false; super.tasks = null; List<Task> currentDocumentTasks = getCurrentDocumentTasks();// get tasks for current users and users of its groups if (currentDocumentTasks != null) { Iterator<Task> iterator = currentDocumentTasks.iterator(); while (iterator.hasNext() && !isAuthorized){ Task task = iterator.next(); if (task.isOpened() && taskName.equals(task.getName())) { isAuthorized = true; } } } return isAuthorized; }
protected void updateTaskInfo(CoreSession session, GraphRoute graph, Task task, String status) { String nodeId = task.getVariable(DocumentRoutingConstants.TASK_NODE_ID_KEY); if (StringUtils.isEmpty(nodeId)) { throw new DocumentRouteException("No nodeId found on task: " + task.getId()); } GraphNode node = graph.getNode(nodeId); NuxeoPrincipal principal = session.getPrincipal(); String actor = principal.getActingUser(); node.updateTaskInfo(task.getId(), true, status, actor, null); }
GraphRoute workflowInstance = null; GraphNode node = null; String workflowInstanceId = item.getProcessId(); final String nodeId = item.getVariable(DocumentRoutingConstants.TASK_NODE_ID_KEY); try (SessionWrapper wrapper = ctx.getSession(item.getDocument())) { if (StringUtils.isNotBlank(workflowInstanceId)) { NodeAccessRunner nodeAccessRunner = new NodeAccessRunner(wrapper.getSession(), workflowInstanceId, jg.writeStringField("id", item.getDocument().getId()); jg.writeStringField("name", item.getName()); jg.writeStringField("workflowInstanceId", workflowInstanceId); if (workflowInstance != null) { jg.writeStringField("state", item.getDocument().getCurrentLifeCycleState()); jg.writeStringField("directive", item.getDirective()); jg.writeStringField("created", DateParser.formatW3CDateTime(item.getCreated())); jg.writeStringField("dueDate", DateParser.formatW3CDateTime(item.getDueDate())); jg.writeStringField("nodeName", item.getVariable(DocumentRoutingConstants.TASK_NODE_ID_KEY)); for (String docId : item.getTargetDocumentsIds()) { IdRef idRef = new IdRef(docId); if (wrapper.getSession().exists(idRef)) { writeActors(item.getActors(), isFetchActors, jg); jg.writeEndArray(); writeActors(item.getDelegatedActors(), isFetchActors, jg); jg.writeEndArray();
String routeId = task.getProcessId(); if (routeId != null) { DocumentModel routeDoc = session.getDocument(new IdRef(routeId)); GraphNode node = routeInstance.getNode(task.getType()); if (node == null) { throw new DocumentRouteException( task.getDocument().refresh(); eventProperties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, DocumentRoutingConstants.ROUTING_CATEGORY); eventProperties.put("taskName", task.getName()); eventProperties.put("delegatedActors", (Serializable) delegatedActors); eventProperties.put("modelId", routeInstance.getModelId()); long timeSinceWfStarted = RoutingAuditHelper.computeDurationSinceWfStarted(task.getProcessId()); if (timeSinceWfStarted >= 0) { eventProperties.put(RoutingAuditHelper.TIME_SINCE_WF_STARTED, timeSinceWfStarted); long timeSinceTaskStarted = RoutingAuditHelper.computeDurationSinceTaskStarted(task.getId()); if (timeSinceWfStarted >= 0) { eventProperties.put(RoutingAuditHelper.TIME_SINCE_TASK_STARTED, timeSinceTaskStarted); task.getDocument()); envContext.setProperties(eventProperties); EventProducer eventProducer = Framework.getService(EventProducer.class);
nodeId = task.getVariable(DocumentRoutingConstants.TASK_NODE_ID_KEY); if (StringUtils.isEmpty(nodeId)) { throw new DocumentRouteException("No nodeId found on task: " + taskId); Map<String, Serializable> eventProperties = new HashMap<>(); eventProperties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, DocumentRoutingConstants.ROUTING_CATEGORY); eventProperties.put("taskName", task.getName()); eventProperties.put("modelName", graph.getModelName()); eventProperties.put("action", status); long duration = RoutingAuditHelper.computeDurationSinceTaskStarted(task.getId()); if (duration >= 0) { eventProperties.put(RoutingAuditHelper.TIME_SINCE_TASK_STARTED, duration); long timeSinceWfStarted = RoutingAuditHelper.computeDurationSinceWfStarted(task.getProcessId()); if (timeSinceWfStarted >= 0) { eventProperties.put(RoutingAuditHelper.TIME_SINCE_WF_STARTED, timeSinceWfStarted); DocumentEventContext envContext = new DocumentEventContext(session, session.getPrincipal(), task.getDocument()); envContext.setProperties(eventProperties); EventProducer eventProducer = Framework.getService(EventProducer.class);
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); }
if (task.hasEnded() || task.isCancelled()) { continue; log.warn("Cannot get doc for task " + task.getId() + ", error: " + e.getMessage()); task.getName())); } else { if (!LifeCycleConstants.DELETED_STATE.equals(doc.getCurrentLifeCycleState())) { String taskName = I18NUtils.getMessageString("messages", (String) task.getName(), null, Locale.FRENCH); obj.element("startDate", task.getCreated()); obj.element("dueDate", task.getDueDate());
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)) { notificationRecipients.add(task.getInitiator()); notificationRecipients.addAll(task.getActors()); eventProperties.put(NotificationConstants.RECIPIENTS_KEY, notificationRecipients); if (extraEventProperties != null) { eventProperties.putAll(extraEventProperties); boolean taskEndedByDelegatedActor = task.getDelegatedActors() != null && task.getDelegatedActors().contains(principal.getName()); for (DocumentModel doc : documents) { notifyEvent(coreSession, doc, principal, task, eventName, eventProperties, comment, null);
protected void getAllTasks() { error = null; errorMessage = null; userTasks = new ArrayList<>(); CoreSession coreSession = getCoreSession(); boolean filterTrashDocs = getFilterDocumentsInTrash(); NuxeoPrincipal pal = coreSession.getPrincipal(); TaskService taskService = Framework.getService(TaskService.class); List<Task> tasks = taskService.getAllCurrentTaskInstances(coreSession, getSortInfos()); if (tasks != null) { for (Task task : tasks) { List<String> targetDocumentsIds = task.getTargetDocumentsIds(); boolean hasTargetDocuments = targetDocumentsIds != null && !targetDocumentsIds.isEmpty(); if (task.hasEnded() || task.isCancelled() || !hasTargetDocuments) { continue; } DocumentModel doc = taskService.getTargetDocumentModel(task, coreSession); if (doc != null) { if (!filterTrashDocs || !doc.isTrashed()) { userTasks.add(new DashBoardItemImpl(task, doc, getLocale())); } } else { log.warn(String.format("User '%s' has a task of type '%s' on a missing or deleted document", pal.getName(), task.getName())); } } } }
/** * Finds an ACL name specific to the task (there may be several tasks applying permissions to the same document). */ protected static String getRoutingACLName(Task task) { return getRoutingACLName(task.getId()); }
long timeSinceWfStarted = RoutingAuditHelper.computeDurationSinceWfStarted(task.getProcessId()); if (timeSinceWfStarted >= 0) { eventProperties.put(RoutingAuditHelper.TIME_SINCE_WF_STARTED, timeSinceWfStarted); DocumentEventContext envContext = new DocumentEventContext(session, session.getPrincipal(), task.getDocument()); envContext.setProperties(eventProperties); EventProducer eventProducer = Framework.getService(EventProducer.class); node.addTaskInfo(task.getId());
Boolean validated = Boolean.valueOf(task.getVariable(TaskService.VariableName.validated.name())); chain = task.getVariable(OperationTaskVariableName.acceptOperationChain.name()); } else { chain = task.getVariable(OperationTaskVariableName.rejectOperationChain.name()); ctx.put(OperationTaskVariableName.taskDocument.name(), task.getDocument());
@Override public void handleEvent(Event event) { if (!DocumentEventTypes.ABOUT_TO_REMOVE.equals(event.getName())) { return; } DocumentEventContext docCtx; if (event.getContext() instanceof DocumentEventContext) { docCtx = (DocumentEventContext) event.getContext(); } else { return; } DocumentModel doc = docCtx.getSourceDocument(); CoreSession session = docCtx.getCoreSession(); if (doc.hasFacet(DocumentRoutingConstants.ROUTING_TASK_FACET_NAME)) { Task task = doc.getAdapter(Task.class); String routeId = task.getProcessId(); IdRef routeIdRef = new IdRef(routeId); if (StringUtils.isNotBlank(routeId) && session.exists(routeIdRef)) { GraphRoute graphRoute = session.getDocument(routeIdRef).getAdapter(GraphRoute.class); String nodeId = task.getVariable(DocumentRoutingConstants.TASK_NODE_ID_KEY); if (StringUtils.isNotBlank(nodeId)) { GraphNode graphNode = graphRoute.getNode(nodeId); graphNode.removeTaskInfo(task.getId()); } } } }
@OperationMethod public DocumentModelList getAllTasks(DocumentModel doc) { DocumentModelList taskDocs = new DocumentModelListImpl(); List<Task> tasks; if (nodeId == null && processId == null) { NuxeoPrincipal principal = username != null ? userManager.getPrincipal(username) : null; tasks = taskService.getTaskInstances(doc, principal, session); for (Task task : tasks) { taskDocs.add(task.getDocument()); } return taskDocs; } if (nodeId == null || processId == null) { throw new NuxeoException("Need both nodeId and processId to invoke the operation with parameters"); } tasks = taskService.getAllTaskInstances(processId, nodeId, session); for (Task task : tasks) { if (task.getTargetDocumentsIds().contains(doc.getId())) { if (username == null || task.getActors().contains(username)) { taskDocs.add(task.getDocument()); } } } return taskDocs; }
if (!task.isOpened()) { log.info("Can not cancel task " + taskId + "as is not open"); return; task.cancel(session); String routeId = task.getProcessId(); if (routeId != null) { DocumentModel routeDoc = session.getDocument(new IdRef(routeId)); session.saveDocument(task.getDocument());
public boolean isValidateOnlineTask(Task task) throws NuxeoException { if (task != null) { return ToutaticeGlobalConst.CST_WORKFLOW_TASK_ONLINE_VALIDATE.equals(task.getName()); } return false; }
@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; }