@POST @Path("tasks") @Produces(MediaType.APPLICATION_JSON) public BaseDTO tasks(@HeaderParam("sessionId") String sessionId) throws Exception { logger.info("start"); PimDevice pimDevice = pimDeviceManager.findUniqueBy("sessionId", sessionId); if (pimDevice == null) { BaseDTO result = new BaseDTO(); result.setCode(401); result.setMessage("auth fail"); return result; } String userId = pimDevice.getUserId(); String tenantId = "1"; Page page = humanTaskConnector.findPersonalTasks(userId, tenantId, 1, 10); List<HumanTaskDTO> humanTaskDtos = (List<HumanTaskDTO>) page.getResult(); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (HumanTaskDTO humanTaskDto : humanTaskDtos) { Map<String, Object> map = new HashMap<String, Object>(); map.put("id", humanTaskDto.getId()); map.put("name", humanTaskDto.getName()); map.put("presentationSubject", humanTaskDto.getPresentationSubject()); map.put("createTime", dateFormat.format(humanTaskDto.getCreateTime())); map.put("assignee", humanTaskDto.getAssignee()); map.put("assigneeDisplayName", userConnector.findById(userId).getDisplayName()); list.add(map); } String json = jsonMapper.toJson(list); BaseDTO result = new BaseDTO(); result.setCode(200); result.setData(json); logger.info("end"); return result; }
@POST @Path("completeTask") @Produces(MediaType.APPLICATION_JSON) public BaseDTO completeTask( @HeaderParam("sessionId") String sessionId, @FormParam("taskId") String taskId, @FormParam("data") String data) throws Exception { logger.info("start : {} {}", taskId, data); String humanTaskId = taskId; PimDevice pimDevice = pimDeviceManager.findUniqueBy("sessionId", sessionId); if (pimDevice == null) { BaseDTO result = new BaseDTO(); result.setCode(401); result.setMessage("auth fail"); return result; } String userId = pimDevice.getUserId(); String tenantId = "1"; Map<String, Object> map = jsonMapper.fromJson(data, Map.class); map.put("taskId", humanTaskId); Record record = null; FormParameter formParameter = null; HumanTaskDTO humanTaskDto = null; FormDTO formDto = null; formParameter = doSaveRecord(map, userId, tenantId); humanTaskId = formParameter.getHumanTaskId(); operationService.saveDraft(userId, tenantId, formParameter); formDto = humanTaskConnector.findTaskForm(humanTaskId); humanTaskDto = humanTaskConnector.findHumanTask(humanTaskId); String processInstanceId = humanTaskDto.getProcessInstanceId(); record = keyValueConnector.findByRef(processInstanceId); record = new RecordBuilder().build(record, formParameter.getMultiValueMap(), tenantId); keyValueConnector.save(record); Xform xform = new XformBuilder() .setStoreConnector(storeConnector) .setContent(formDto.getContent()) .setRecord(record) .build(); Map<String, Object> taskParameters = xform.getMapData(); logger.info("taskParameters : {}", taskParameters); String comment = ""; String action = ""; try { humanTaskConnector.completeTask(humanTaskId, userId, action, comment, taskParameters); } catch (IllegalStateException ex) { logger.error(ex.getMessage(), ex); return null; } if (record == null) { record = new Record(); } record = new RecordBuilder().build(record, STATUS_RUNNING, humanTaskDto.getProcessInstanceId()); keyValueConnector.save(record); BaseDTO result = new BaseDTO(); result.setCode(200); result.setData(data); logger.info("end"); return result; }