@Override public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { String url = HandlerUtils.getFirstTypedParameter(workItem.getParameters(), String.class); try { if (url == null) throw new Exception("No URL given"); DocumentInformation docInfo = docManager.getDocumentInformation(workItem); if (docInfo == null) throw new Exception("No document associated with this workflow"); Theo theo = docInfo.getTheo(); int theoOutput = theo.openWindow(docInfo, workItem.getProcessInstanceId(), "", url, 700, 600); workItem.getResults().put("wndIDOutput", theoOutput); } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } finally { manager.completeWorkItem(workItem.getId(), workItem.getResults()); } }
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { if (this.session == null) { if (this.manager == null) { this.manager = manager; } else { if (this.manager != manager) { throw new IllegalArgumentException( "This WSHumanTaskHandler can only be used for one WorkItemManager"); } } } connect(); Task task = new Task(); String taskName = (String) workItem.getParameter("TaskName"); if (taskName != null) { List<I18NText> names = new ArrayList<I18NText>(); names.add(new I18NText("en-UK", taskName)); task.setNames(names); } String comment = (String) workItem.getParameter("Comment"); if (comment != null) { List<I18NText> descriptions = new ArrayList<I18NText>(); descriptions.add(new I18NText("en-UK", comment)); task.setDescriptions(descriptions); List<I18NText> subjects = new ArrayList<I18NText>(); subjects.add(new I18NText("en-UK", comment)); task.setSubjects(subjects); } String priorityString = (String) workItem.getParameter("Priority"); int priority = 0; if (priorityString != null) { try { priority = new Integer(priorityString); } catch (NumberFormatException e) { // do nothing } } task.setPriority(priority); TaskData taskData = new TaskData(); taskData.setWorkItemId(workItem.getId()); taskData.setProcessInstanceId(workItem.getProcessInstanceId()); if (session != null && session.getProcessInstance(workItem.getProcessInstanceId()) != null) { taskData.setProcessId( session.getProcessInstance(workItem.getProcessInstanceId()).getProcess().getId()); } if (session != null && (session instanceof StatefulKnowledgeSession)) { taskData.setProcessSessionId(((StatefulKnowledgeSession) session).getId()); } taskData.setSkipable(!"false".equals(workItem.getParameter("Skippable"))); // Sub Task Data Long parentId = (Long) workItem.getParameter("ParentId"); if (parentId != null) { taskData.setParentId(parentId); } String subTaskStrategiesCommaSeparated = (String) workItem.getParameter("SubTaskStrategies"); if (subTaskStrategiesCommaSeparated != null && !subTaskStrategiesCommaSeparated.equals("")) { String[] subTaskStrategies = subTaskStrategiesCommaSeparated.split(","); List<SubTasksStrategy> strategies = new ArrayList<SubTasksStrategy>(); for (String subTaskStrategyString : subTaskStrategies) { SubTasksStrategy subTaskStrategy = SubTasksStrategyFactory.newStrategy(subTaskStrategyString); strategies.add(subTaskStrategy); } task.setSubTaskStrategies(strategies); } PeopleAssignments assignments = new PeopleAssignments(); List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>(); String actorId = (String) workItem.getParameter("ActorId"); if (actorId != null && actorId.trim().length() > 0) { String[] actorIds = actorId.split(","); for (String id : actorIds) { potentialOwners.add(new User(id.trim())); } // Set the first user as creator ID??? hmmm might be wrong if (potentialOwners.size() > 0) { taskData.setCreatedBy((User) potentialOwners.get(0)); } } String groupId = (String) workItem.getParameter("GroupId"); if (groupId != null && groupId.trim().length() > 0) { String[] groupIds = groupId.split(","); for (String id : groupIds) { potentialOwners.add(new Group(id.trim())); } } assignments.setPotentialOwners(potentialOwners); List<OrganizationalEntity> businessAdministrators = new ArrayList<OrganizationalEntity>(); businessAdministrators.add(new User("Administrator")); assignments.setBusinessAdministrators(businessAdministrators); task.setPeopleAssignments(assignments); task.setTaskData(taskData); ContentData content = null; Object contentObject = workItem.getParameter("Content"); if (contentObject == null) { contentObject = workItem.getParameters(); } if (contentObject != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out; try { out = new ObjectOutputStream(bos); out.writeObject(contentObject); out.close(); content = new ContentData(); content.setContent(bos.toByteArray()); content.setAccessType(AccessType.Inline); } catch (IOException e) { e.printStackTrace(); } } client.addTask(task, content); }