1 | |
package org.kuali.student.r2.common.service.impl; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import javax.jws.WebService; |
7 | |
import javax.persistence.NoResultException; |
8 | |
|
9 | |
import org.kuali.student.r2.common.dao.StateDao; |
10 | |
import org.kuali.student.r2.common.dao.StateProcessDao; |
11 | |
import org.kuali.student.r2.common.dao.StateProcessRelationDao; |
12 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
13 | |
import org.kuali.student.r2.common.dto.StateInfo; |
14 | |
import org.kuali.student.r2.common.dto.StateProcessInfo; |
15 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
16 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
17 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
18 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
19 | |
import org.kuali.student.r2.common.model.StateEntity; |
20 | |
import org.kuali.student.r2.common.model.StateProcessEntity; |
21 | |
import org.kuali.student.r2.common.service.StateService; |
22 | |
import org.springframework.transaction.annotation.Transactional; |
23 | |
|
24 | |
@WebService(name = "StateService", serviceName = "StateService", portName = "StateService", targetNamespace = "http://student.kuali.org/wsdl/state") |
25 | |
@Transactional(readOnly=true,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
26 | 0 | public class StateServiceImpl implements StateService{ |
27 | |
|
28 | |
private StateDao stateDao; |
29 | |
private StateProcessDao spDao; |
30 | |
private StateProcessRelationDao sprDao; |
31 | |
|
32 | |
public StateDao getStateDao() { |
33 | 0 | return stateDao; |
34 | |
} |
35 | |
public void setStateDao(StateDao stateDao) { |
36 | 0 | this.stateDao = stateDao; |
37 | 0 | } |
38 | |
|
39 | |
public StateProcessDao getSpDao() { |
40 | 0 | return spDao; |
41 | |
} |
42 | |
public void setSpDao(StateProcessDao spDao) { |
43 | 0 | this.spDao = spDao; |
44 | 0 | } |
45 | |
|
46 | |
public StateProcessRelationDao getSprDao() { |
47 | 0 | return sprDao; |
48 | |
} |
49 | |
public void setSprDao(StateProcessRelationDao sprDao) { |
50 | 0 | this.sprDao = sprDao; |
51 | 0 | } |
52 | |
|
53 | |
|
54 | |
@Override |
55 | |
public StateProcessInfo getProcessByKey(String processKey, ContextInfo context) |
56 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
57 | 0 | StateProcessEntity sp = spDao.getProcessByKey(processKey); |
58 | 0 | if (null == sp) { |
59 | 0 | throw new DoesNotExistException("This process does not exist: processKey=" + processKey); |
60 | |
} |
61 | 0 | return sp.toDto(); |
62 | |
} |
63 | |
|
64 | |
@Override |
65 | |
public List<String> getProcessByObjectType(String objectTypeKey, ContextInfo context) |
66 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
67 | 0 | return new ArrayList<String>(); |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
public StateInfo getState(String processKey, String stateKey, ContextInfo context) |
72 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
73 | |
OperationFailedException { |
74 | 0 | StateEntity state = null; |
75 | |
try{ |
76 | 0 | state = stateDao.getState(processKey, stateKey); |
77 | 0 | }catch(NoResultException ex){ |
78 | 0 | throw new DoesNotExistException("This state does not exist: processKey=" + processKey + ", stateKey=" + stateKey); |
79 | 0 | } |
80 | 0 | if (null == state) { |
81 | 0 | throw new DoesNotExistException("This state does not exist: processKey=" + processKey + ", stateKey=" + stateKey); |
82 | |
} |
83 | 0 | return state.toDto(); |
84 | |
} |
85 | |
|
86 | |
@Override |
87 | |
public List<StateInfo> getStatesByProcess(String processKey, ContextInfo context) |
88 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
89 | |
OperationFailedException { |
90 | 0 | List<StateInfo> stateInfos = null; |
91 | |
List<StateEntity> states; |
92 | |
|
93 | |
try{ |
94 | 0 | states = stateDao.getStatesByProcess(processKey); |
95 | 0 | }catch(NoResultException ex){ |
96 | 0 | throw new DoesNotExistException("No state exists for this process: " + processKey); |
97 | 0 | } |
98 | |
|
99 | 0 | if(null != states && !states.isEmpty()){ |
100 | 0 | stateInfos = new ArrayList<StateInfo>(); |
101 | 0 | for(StateEntity se : states){ |
102 | 0 | stateInfos.add(se.toDto()); |
103 | |
} |
104 | |
} |
105 | |
else |
106 | 0 | throw new DoesNotExistException("No state exists for this process: " + processKey); |
107 | |
|
108 | 0 | return stateInfos; |
109 | |
} |
110 | |
|
111 | |
@Override |
112 | |
public List<StateInfo> getInitialValidStates(String processKey, ContextInfo context) |
113 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
114 | |
OperationFailedException { |
115 | 0 | List<StateInfo> stateInfos = null; |
116 | |
List<StateEntity> states; |
117 | |
|
118 | |
try{ |
119 | 0 | states = sprDao.getInitialValidStates(processKey); |
120 | 0 | }catch(NoResultException ex){ |
121 | 0 | throw new DoesNotExistException("No valid initial state exists for this process: " + processKey); |
122 | 0 | } |
123 | |
|
124 | 0 | if(null != states && !states.isEmpty()){ |
125 | 0 | stateInfos = new ArrayList<StateInfo>(); |
126 | 0 | for(StateEntity se : states){ |
127 | 0 | stateInfos.add(se.toDto()); |
128 | |
} |
129 | |
} |
130 | |
else |
131 | 0 | throw new DoesNotExistException("No valid initial state exists for this process: " + processKey); |
132 | |
|
133 | 0 | return stateInfos; |
134 | |
} |
135 | |
|
136 | |
@Override |
137 | |
public StateInfo getNextHappyState(String processKey, |
138 | |
String currentStateKey, ContextInfo context) |
139 | |
throws DoesNotExistException, InvalidParameterException, |
140 | |
MissingParameterException, OperationFailedException { |
141 | 0 | StateEntity state = null; |
142 | |
|
143 | |
try{ |
144 | 0 | state = sprDao.getNextHappyState(processKey, currentStateKey); |
145 | 0 | }catch(NoResultException ex){ |
146 | 0 | throw new DoesNotExistException("No next state: processKey=" + processKey + ", stateKey=" + currentStateKey); |
147 | 0 | } |
148 | |
|
149 | 0 | if (null == state) { |
150 | 0 | throw new DoesNotExistException("No next state: processKey=" + processKey + ", stateKey=" + currentStateKey); |
151 | |
} |
152 | 0 | return state.toDto(); |
153 | |
} |
154 | |
|
155 | |
} |