if (StringUtils.hasText(psMsg.getInstanceName())) {
instance.setName(psMsg.getInstanceName());
}
this.bindProcessInfo(instance, psMsg);
HumanActivity initiatorHumanActivity = (HumanActivity) instance.getProcessDefinition().getInitiatorHumanActivityReference(instance.getProcessTransactionContext()).getActivity();
if (initiatorHumanActivity instanceof ExternalApprovalActivity) {
pm.executeProcess(instanceId);
// 결재선 정보 가져오기
ApproverDAO approverDAO = new ApproverDAO(DefaultConnectionFactory.create().getDataSource());
ApprovalLineDAO approvalLineDAO = new ApprovalLineDAO(DefaultConnectionFactory.create().getDataSource());
ApprovalLine al = approvalLineDAO.get(psMsg.getApprovalKey());
al.setLineStatus(ExternalApprovalActivity.SIGN_DRAFT);
al.setInstanceId(Integer.parseInt(instanceId));
List<Approver> approverList = approverDAO.list(psMsg.getApprovalKey());
List<HumanActivity> approvalActs = new ArrayList<HumanActivity>();
// 결재선 다이나믹 체인지 Start
ProcessDefinition tempPd = (ProcessDefinition) instance.getProcessDefinition().clone();
HumanActivity draftAct = (HumanActivity) tempPd.getInitiatorHumanActivityReference(instance.getProcessTransactionContext()).getActivity();
if (StringUtils.hasText(psMsg.getMainParam())) {
draftAct.setExtValue1(psMsg.getMainParam());
}
if (StringUtils.hasText(psMsg.getSubParam())) {
draftAct.setExtValue2(psMsg.getSubParam());
}
Activity approvalLineAct = draftAct.getParentActivity();
while (!(approvalLineAct instanceof ExternalApprovalLineActivity)) {
approvalLineAct = approvalLineAct.getParentActivity();
}
ComplexActivity parent = (ComplexActivity) approvalLineAct;
if (parent.getChildActivities().size() > 1) {
parent.getChildActivities().clear();
parent.addChildActivity(draftAct);
}
String preApprovalType = null;
for (Approver approver : approverList) {
if (ExternalApprovalActivity.APPROVAL_TYPE_DRAFT.equalsIgnoreCase(approver.getType())) {
approver.setTracingTag(draftAct.getTracingTag());
approver.setTaskId(draftAct.getTaskIds(instance)[0]);
approver.setTruthEmpCode(approver.getEmpCode());
approver.setStatus(ExternalApprovalActivity.SIGN_DRAFT);
approver.setEndDate(new Timestamp(Calendar.getInstance().getTimeInMillis()));
approver.setComment(psMsg.getComment());
approvalActs.add(draftAct);
continue;
}
ExternalApprovalActivity childAct = (ExternalApprovalActivity) draftAct.clone();
childAct.setName("결재");
childAct.setTracingTag(null);
childAct.setRole(null);
childAct.setApprovalTypeByString(approver.getType());
RoleMapping rm = RoleMapping.create();
rm.setEndpoint(approver.getEmpCode());
rm.fill(instance);
// 결재 -> 합의
if (!ExternalApprovalActivity.APPROVAL_TYPE_COOPERATION.equals(preApprovalType) && ExternalApprovalActivity.APPROVAL_TYPE_COOPERATION.equals(approver.getType())) {
AllActivity allAct = new AllActivity();
allAct.setTracingTag(null);
parent.addChildActivity(allAct);
parent = allAct;
// 합의 -> 결재
} else if (ExternalApprovalActivity.APPROVAL_TYPE_COOPERATION.equals(preApprovalType) && !ExternalApprovalActivity.APPROVAL_TYPE_COOPERATION.equals(approver.getType())) {
parent = (ComplexActivity) approvalLineAct;
}
parent.addChildActivity(childAct);
childAct.setApprover(instance, rm);
approver.setTracingTag(childAct.getTracingTag());
preApprovalType = approver.getType();
approvalActs.add(childAct);
}
// tempPd.registerToProcessDefinition(false, false);
pm.changeProcessDefinition(instanceId, tempPd);
// 결재선 다이나믹 체인지 End
instance.setProperty(approvalLineAct.getTracingTag(), ExternalApprovalLineActivity.KEY_APPR_KEY, psMsg.getApprovalKey());
approvalLineDAO.update(al);
approverDAO.update(approverList);
if (psMsg.isFirstTaskCompleted()) {
pm.completeWorkitem(instanceId, draftAct.getTracingTag(), null, new org.uengine.kernel.ResultPayload());
}
} else {
if (psMsg.isFirstTaskCompleted()) {