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.atp.service.AtpService;
14 import org.kuali.student.core.proposal.dto.ProposalInfo;
15 import org.kuali.student.lum.program.service.ProgramService;
16 import org.kuali.student.lum.program.service.ProgramServiceConstants;
17 import org.springframework.transaction.annotation.Transactional;
18
19 @Transactional(readOnly=true, rollbackFor={Throwable.class})
20 public class ProgramPostProcessorBase extends KualiStudentPostProcessorBase {
21 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProgramPostProcessorBase.class);
22
23 private ProgramService programService;
24 private StateChangeService stateChangeService;
25
26 @Override
27 protected void processWithdrawActionTaken(ActionTakenEvent actionTakenEvent, ProposalInfo proposalInfo) throws Exception {
28 LOG.info("Will set CLU state to '" + DtoConstants.STATE_DRAFT + "'");
29 String programId = getProgramId(proposalInfo);
30 getStateChangeService().changeState(programId, DtoConstants.STATE_DRAFT);
31 }
32
33 @Override
34 protected boolean processCustomActionTaken(ActionTakenEvent actionTakenEvent, ActionTakenValue actionTaken, ProposalInfo proposalInfo) throws Exception {
35
36 return true;
37 }
38
39 @Override
40 protected boolean processCustomRouteStatusChange(DocumentRouteStatusChange statusChangeEvent, ProposalInfo proposalInfo) throws Exception {
41
42
43 String programId = getProgramId(proposalInfo);
44 String endEntryTerm = proposalInfo.getAttributes().get("prevEndProgramEntryTerm");
45 String endEnrollTerm = proposalInfo.getAttributes().get("prevEndTerm");
46 String endInstAdmitTerm = proposalInfo.getAttributes().get("prevEndInstAdmitTerm");
47 getStateChangeService().changeState(endEntryTerm, endEnrollTerm, endInstAdmitTerm, programId, getCluStateForRouteStatus("",statusChangeEvent.getNewRouteStatus()));
48 return true;
49 }
50
51 protected String getProgramId(ProposalInfo proposalInfo) throws OperationFailedException {
52 if (proposalInfo.getProposalReference().size() != 1) {
53 LOG.error("Found " + proposalInfo.getProposalReference().size() + " CLU objects linked to proposal with proposalId='" + proposalInfo.getId() + "'. Must have exactly 1 linked.");
54 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.");
55 }
56 return proposalInfo.getProposalReference().get(0);
57 }
58
59
60
61
62
63
64 protected String getCluStateForRouteStatus(String currentCluState, String newWorkflowStatusCode) {
65 if (StringUtils.equals(KEWConstants.ROUTE_HEADER_SAVED_CD, newWorkflowStatusCode)) {
66 return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_DRAFT);
67 } else if (KEWConstants.ROUTE_HEADER_CANCEL_CD .equals(newWorkflowStatusCode)) {
68 return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_NOT_APPROVED);
69 } else if (KEWConstants.ROUTE_HEADER_ENROUTE_CD.equals(newWorkflowStatusCode)) {
70 return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_DRAFT);
71 } else if (KEWConstants.ROUTE_HEADER_DISAPPROVED_CD.equals(newWorkflowStatusCode)) {
72
73
74
75 return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_NOT_APPROVED);
76 } else if (KEWConstants.ROUTE_HEADER_PROCESSED_CD.equals(newWorkflowStatusCode)) {
77 return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_ACTIVE);
78 } else if (KEWConstants.ROUTE_HEADER_EXCEPTION_CD.equals(newWorkflowStatusCode)) {
79 return getCourseStateFromNewState(currentCluState, DtoConstants.STATE_DRAFT);
80 } else {
81
82 return null;
83 }
84 }
85
86
87
88
89
90 protected String getCourseStateFromNewState(String currentCourseState, String newCourseState) {
91 if (LOG.isInfoEnabled()) {
92 LOG.info("current CLU state is '" + currentCourseState + "' and new CLU state will be '" + newCourseState + "'");
93 }
94 return getStateFromNewState(currentCourseState, newCourseState);
95 }
96
97
98 protected ProgramService getProgramService() {
99 if (this.programService == null) {
100 this.programService = (ProgramService) GlobalResourceLoader.getService(new QName(ProgramServiceConstants.PROGRAM_NAMESPACE,"ProgramService"));
101 }
102 return this.programService;
103 }
104
105
106 protected StateChangeService getStateChangeService() {
107 if (this.stateChangeService == null) {
108 MajorDisciplineStateChangeServiceImpl stateChangeService = new MajorDisciplineStateChangeServiceImpl();
109 stateChangeService.setProgramService(getProgramService());
110 stateChangeService.setAtpService((AtpService)GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/atp","AtpService")));
111 this.stateChangeService = stateChangeService;
112 }
113
114 return this.stateChangeService;
115 }
116
117 }