@Override public DocumentModel getTargetDocumentModel(Task task, CoreSession coreSession) { try { // TODO handle while target documents from task return coreSession.getDocument(new IdRef(task.getTargetDocumentsIds().get(0))); } catch (DocumentNotFoundException e) { return null; } }
/** * Save required metadata of task * on document associated to validation workflow. * * @param task */ private void saveMetaData(Task task) { Map<String, Serializable> formVariables = this.getFormVariables(task); /* Only one document associated with task */ String docId = task.getTargetDocumentsIds().get(0); DocumentModel document = documentManager.getDocument(new IdRef(docId)); Set<Entry<String, String>> metaDataSet = CnsConstants.METADATA.entrySet(); for (Entry<String, String> metaData : metaDataSet) { document.setPropertyValue(metaData.getValue(), formVariables.get(metaData.getKey())); } documentManager.saveDocument(document); }
docIds.addAll(task.getTargetDocumentsIds());
/** * {@inheritDoc} */ @Override public void handleEvent(Event event) throws ClientException { EventContext ctx = event.getContext(); CoreSession session = ctx.getCoreSession(); String eventName = event.getName(); if (event.getContext() instanceof DocumentEventContext) { DocumentEventContext docCtx = (DocumentEventContext) event.getContext(); DocumentModel document = docCtx.getSourceDocument(); if (DocumentEventTypes.BEFORE_DOC_UPDATE.equals(eventName)) { if (WorkflowsConstants.TASKDOC_TYPE.equals(document.getType())) { Task task = document.getAdapter(Task.class); String taskName = task.getName(); Map<String, Serializable> formVariables = getFormVariables(task); if (WorkflowsConstants.CHOOSE_PARTICIPANTS_TASKS.contains(taskName) || CnsConstants.CNS_VALIDATION_TASK.equals(taskName)) { /* Only one document associated with task */ String docId = task.getTargetDocumentsIds().get(0); DocumentModel currentDoc = session.getDocument(new IdRef(docId)); Set<Entry<String, String>> metaDataSet = CnsConstants.METADATA.entrySet(); for (Entry<String, String> metaData : metaDataSet) { formVariables.put(metaData.getKey(), currentDoc.getPropertyValue(metaData.getValue())); } fillFormVariables(session, task, formVariables); } } } } }
session.saveDocument(taskDoc); List<DocumentModel> docs = new ArrayList<>(); for (String string : task.getTargetDocumentsIds()) { docs.add(session.getDocument(new IdRef(string)));
for (String string : task.getTargetDocumentsIds()) { docs.add(session.getDocument(new IdRef(string)));
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())); } } } }
for (String docId : item.getTargetDocumentsIds()) { IdRef idRef = new IdRef(docId); if (wrapper.getSession().exists(idRef)) {
@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; }