instance.getActualInitiatorHumanActivity().getActivity().compensateToThis(instance);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public String processStart(ProcessStartMsg psMsg) throws Exception {
RoleMapping loggedRoleMapping = RoleMapping.create();
loggedRoleMapping.setEndpoint(psMsg.getInitiator());
loggedRoleMapping.fill(null);
Map genericContext = new HashMap();
genericContext.put(HumanActivity.GENERICCONTEXT_CURR_LOGGED_ROLEMAPPING, loggedRoleMapping);
genericContext.put("request", request);
pm.setGenericContext(genericContext);
String defVerId = pm.getProcessDefinitionProductionVersionByAlias(psMsg.getProcAlias());
String instanceId = pm.initializeProcess(defVerId);
ProcessInstance instance = pm.getProcessInstance(instanceId);
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);