1 | |
package org.kuali.student.lum.workflow; |
2 | |
|
3 | |
import javax.xml.namespace.QName; |
4 | |
|
5 | |
import org.apache.commons.lang.StringUtils; |
6 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
7 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
8 | |
import org.kuali.rice.kew.postprocessor.ActionTakenEvent; |
9 | |
import org.kuali.rice.kew.postprocessor.DocumentRouteStatusChange; |
10 | |
import org.kuali.rice.kew.util.KEWConstants; |
11 | |
import org.kuali.student.common.dto.DtoConstants; |
12 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
13 | |
import org.kuali.student.core.proposal.dto.ProposalInfo; |
14 | |
import org.kuali.student.lum.program.service.ProgramService; |
15 | |
import org.kuali.student.lum.program.service.ProgramServiceConstants; |
16 | |
import org.springframework.transaction.annotation.Transactional; |
17 | |
|
18 | |
@Transactional(readOnly=true, rollbackFor={Throwable.class}) |
19 | 0 | public class ProgramPostProcessorBase extends KualiStudentPostProcessorBase { |
20 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProgramPostProcessorBase.class); |
21 | |
|
22 | |
private ProgramService programService; |
23 | |
private StateChangeService stateChangeService; |
24 | |
|
25 | |
@Override |
26 | |
protected void processWithdrawActionTaken(ActionTakenEvent actionTakenEvent, ProposalInfo proposalInfo) throws Exception { |
27 | 0 | LOG.info("Will set CLU state to '" + DtoConstants.STATE_DRAFT + "'"); |
28 | 0 | String programId = getProgramId(proposalInfo); |
29 | 0 | getStateChangeService().changeState(programId, DtoConstants.STATE_DRAFT); |
30 | 0 | } |
31 | |
|
32 | |
@Override |
33 | |
protected boolean processCustomActionTaken(ActionTakenEvent actionTakenEvent, ActionTakenValue actionTaken, ProposalInfo proposalInfo) throws Exception { |
34 | |
|
35 | 0 | return true; |
36 | |
} |
37 | |
|
38 | |
@Override |
39 | |
protected boolean processCustomRouteStatusChange(DocumentRouteStatusChange statusChangeEvent, ProposalInfo proposalInfo) throws Exception { |
40 | |
|
41 | |
|
42 | 0 | String programId = getProgramId(proposalInfo); |
43 | 0 | getStateChangeService().changeState(programId, getCluStateForRouteStatus("",statusChangeEvent.getNewRouteStatus())); |
44 | 0 | return true; |
45 | |
} |
46 | |
|
47 | |
protected String getProgramId(ProposalInfo proposalInfo) throws OperationFailedException { |
48 | 0 | if (proposalInfo.getProposalReference().size() != 1) { |
49 | 0 | LOG.error("Found " + proposalInfo.getProposalReference().size() + " CLU objects linked to proposal with proposalId='" + proposalInfo.getId() + "'. Must have exactly 1 linked."); |
50 | 0 | throw new OperationFailedException("Found " + proposalInfo.getProposalReference().size() + " CLU objects linked to proposal with docId='" + proposalInfo.getWorkflowId() + "' and proposalId='" + proposalInfo.getId() + "'. Must have exactly 1 linked."); |
51 | |
} |
52 | 0 | return proposalInfo.getProposalReference().get(0); |
53 | |
} |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
protected String getCluStateForRouteStatus(String currentCluState, String newWorkflowStatusCode) { |
61 | 0 | if (StringUtils.equals(KEWConstants.ROUTE_HEADER_SAVED_CD, newWorkflowStatusCode)) { |
62 | 0 | return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_DRAFT); |
63 | 0 | } else if (KEWConstants.ROUTE_HEADER_CANCEL_CD .equals(newWorkflowStatusCode)) { |
64 | 0 | return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_DRAFT); |
65 | 0 | } else if (KEWConstants.ROUTE_HEADER_ENROUTE_CD.equals(newWorkflowStatusCode)) { |
66 | 0 | return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_DRAFT); |
67 | 0 | } else if (KEWConstants.ROUTE_HEADER_DISAPPROVED_CD.equals(newWorkflowStatusCode)) { |
68 | |
|
69 | |
|
70 | |
|
71 | 0 | return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_DRAFT); |
72 | 0 | } else if (KEWConstants.ROUTE_HEADER_PROCESSED_CD.equals(newWorkflowStatusCode)) { |
73 | 0 | return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_APPROVED); |
74 | 0 | } else if (KEWConstants.ROUTE_HEADER_EXCEPTION_CD.equals(newWorkflowStatusCode)) { |
75 | 0 | return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_DRAFT); |
76 | |
} else { |
77 | |
|
78 | 0 | return null; |
79 | |
} |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
protected String getCourseStateFromNewState(String currentCourseState, String newCourseState) { |
87 | 0 | if (LOG.isInfoEnabled()) { |
88 | 0 | LOG.info("current CLU state is '" + currentCourseState + "' and new CLU state will be '" + newCourseState + "'"); |
89 | |
} |
90 | 0 | return getStateFromNewState(currentCourseState, newCourseState); |
91 | |
} |
92 | |
|
93 | |
|
94 | |
protected ProgramService getProgramService() { |
95 | 0 | if (this.programService == null) { |
96 | 0 | this.programService = (ProgramService) GlobalResourceLoader.getService(new QName(ProgramServiceConstants.PROGRAM_NAMESPACE,"ProgramService")); |
97 | |
} |
98 | 0 | return this.programService; |
99 | |
} |
100 | |
|
101 | |
protected StateChangeService getStateChangeService() { |
102 | 0 | if (this.stateChangeService == null) { |
103 | 0 | MajorDisciplineStateChangeServiceImpl stateChangeService = new MajorDisciplineStateChangeServiceImpl(); |
104 | 0 | stateChangeService.setProgramService(getProgramService()); |
105 | 0 | this.stateChangeService = stateChangeService; |
106 | |
} |
107 | |
|
108 | 0 | return this.stateChangeService; |
109 | |
} |
110 | |
|
111 | |
} |