1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.enrollment.lui.mock; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.HashMap; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
import java.util.UUID; |
23 | |
import java.util.logging.Level; |
24 | |
import java.util.logging.Logger; |
25 | |
import org.kuali.student.common.dto.ContextInfo; |
26 | |
|
27 | |
import org.kuali.student.common.dto.StatusInfo; |
28 | |
import org.kuali.student.common.infc.HoldsLuService; |
29 | |
import org.kuali.student.common.exceptions.AlreadyExistsException; |
30 | |
import org.kuali.student.common.exceptions.CircularRelationshipException; |
31 | |
import org.kuali.student.common.exceptions.DataValidationErrorException; |
32 | |
import org.kuali.student.common.exceptions.DependentObjectsExistException; |
33 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
34 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
35 | |
import org.kuali.student.common.exceptions.MissingParameterException; |
36 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
37 | |
import org.kuali.student.common.exceptions.PermissionDeniedException; |
38 | |
import org.kuali.student.common.exceptions.VersionMismatchException; |
39 | |
import org.kuali.student.enrollment.lpr.mock.MockHelper; |
40 | |
import org.kuali.student.enrollment.lui.dto.LuiInfo; |
41 | |
import org.kuali.student.enrollment.lui.dto.LuiLuiRelationInfo; |
42 | |
import org.kuali.student.lum.lu.service.LuService; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class LuiServiceMockPersistenceImpl extends LuiServiceAdapter |
48 | |
implements HoldsLuService { |
49 | |
|
50 | |
private LuService luService; |
51 | |
|
52 | |
@Override |
53 | |
public LuService getLuService() { |
54 | 0 | return luService; |
55 | |
} |
56 | |
|
57 | |
@Override |
58 | |
public void setLuService(LuService luService) { |
59 | 0 | this.luService = luService; |
60 | 0 | } |
61 | 0 | private Map<String, LuiInfo> luiCache = new HashMap<String, LuiInfo>(); |
62 | 0 | private Map<String, LuiLuiRelationInfo> llrCache = new HashMap<String, LuiLuiRelationInfo>(); |
63 | |
|
64 | |
@Override |
65 | |
public LuiInfo createLui(String cluId, |
66 | |
String atpKey, |
67 | |
LuiInfo luiInfo, |
68 | |
ContextInfo context) |
69 | |
throws AlreadyExistsException, |
70 | |
DataValidationErrorException, |
71 | |
DoesNotExistException, |
72 | |
InvalidParameterException, |
73 | |
MissingParameterException, |
74 | |
OperationFailedException, |
75 | |
PermissionDeniedException { |
76 | 0 | LuiInfo.Builder builder = new LuiInfo.Builder(luiInfo); |
77 | 0 | MockHelper helper = new MockHelper(); |
78 | 0 | builder.setId(UUID.randomUUID().toString()).setCluId(cluId); |
79 | 0 | builder.setAtpKey(atpKey).metaInfo(helper.createMeta(context)); |
80 | 0 | LuiInfo copy = builder.build(); |
81 | 0 | this.luiCache.put(copy.getId(), copy); |
82 | 0 | return copy; |
83 | |
} |
84 | |
|
85 | |
@Override |
86 | |
public LuiLuiRelationInfo createLuiLuiRelation(String luiId, |
87 | |
String relatedLuiId, |
88 | |
String luLuRelationType, |
89 | |
LuiLuiRelationInfo luiLuiRelationInfo, |
90 | |
ContextInfo context) |
91 | |
throws AlreadyExistsException, |
92 | |
CircularRelationshipException, |
93 | |
DataValidationErrorException, |
94 | |
DoesNotExistException, |
95 | |
InvalidParameterException, |
96 | |
MissingParameterException, |
97 | |
OperationFailedException, |
98 | |
PermissionDeniedException { |
99 | 0 | MockHelper helper = new MockHelper(); |
100 | 0 | LuiLuiRelationInfo.Builder builder = new LuiLuiRelationInfo.Builder(luiLuiRelationInfo).id(UUID.randomUUID().toString()).luiId(luiId); |
101 | 0 | LuiLuiRelationInfo copy = builder.relatedLuiId(relatedLuiId).type(luLuRelationType).metaInfo(helper.createMeta(context)).build(); |
102 | 0 | this.llrCache.put(copy.getId(), copy); |
103 | 0 | return copy; |
104 | |
} |
105 | |
|
106 | |
@Override |
107 | |
public StatusInfo deleteLui(String luiId, ContextInfo context) throws DependentObjectsExistException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
108 | 0 | if (this.luiCache.remove(luiId) == null) { |
109 | 0 | throw new DoesNotExistException(luiId); |
110 | |
} |
111 | 0 | return new StatusInfo.Builder().success(Boolean.TRUE).build(); |
112 | |
} |
113 | |
|
114 | |
@Override |
115 | |
public StatusInfo deleteLuiLuiRelation(String luiLuiRelationId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
116 | 0 | if (this.luiCache.remove(luiLuiRelationId) == null) { |
117 | 0 | throw new DoesNotExistException(luiLuiRelationId); |
118 | |
} |
119 | 0 | return new StatusInfo.Builder().success(Boolean.TRUE).build(); |
120 | |
} |
121 | |
|
122 | |
@Override |
123 | |
public LuiInfo getLui(String luiId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
124 | 0 | LuiInfo bean = this.luiCache.get(luiId); |
125 | 0 | if (bean == null) { |
126 | 0 | throw new DoesNotExistException(luiId); |
127 | |
} |
128 | 0 | return bean; |
129 | |
} |
130 | |
|
131 | |
@Override |
132 | |
public List<String> getLuiIdsByCluId(String cluId, ContextInfo context) |
133 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException { |
134 | 0 | List<String> luiIds = new ArrayList<String>(); |
135 | 0 | for (LuiInfo info : this.luiCache.values()) { |
136 | 0 | if (info.getCluId().equals(cluId)) { |
137 | 0 | luiIds.add(info.getId()); |
138 | |
} |
139 | |
} |
140 | 0 | return luiIds; |
141 | |
} |
142 | |
|
143 | |
@Override |
144 | |
public List<String> getLuiIdsByRelation(String relatedLuiId, String luLuRelationType, ContextInfo context) |
145 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException { |
146 | 0 | List<String> luiIds = new ArrayList<String>(); |
147 | 0 | for (LuiLuiRelationInfo info : this.llrCache.values()) { |
148 | 0 | if (info.getRelatedLuiId().equals(relatedLuiId)) { |
149 | 0 | if (info.getType().equals(luLuRelationType)) { |
150 | 0 | luiIds.add(info.getLuiId()); |
151 | |
} |
152 | |
} |
153 | |
} |
154 | 0 | return luiIds; |
155 | |
} |
156 | |
|
157 | |
@Override |
158 | |
public List<String> getLuiIdsInAtpByCluId(String cluId, String atpKey, ContextInfo context) |
159 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
160 | 0 | List<String> luiIds = new ArrayList<String>(); |
161 | 0 | for (LuiInfo info : this.luiCache.values()) { |
162 | 0 | if (info.getCluId().equals(cluId)) { |
163 | 0 | luiIds.add(info.getId()); |
164 | |
} |
165 | |
} |
166 | 0 | return luiIds; |
167 | |
} |
168 | |
|
169 | |
@Override |
170 | |
public LuiLuiRelationInfo getLuiLuiRelation(String luiLuiRelationId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
171 | 0 | LuiLuiRelationInfo bean = this.llrCache.get(luiLuiRelationId); |
172 | 0 | if (bean == null) { |
173 | 0 | throw new DoesNotExistException(luiLuiRelationId); |
174 | |
} |
175 | 0 | return bean; |
176 | |
} |
177 | |
|
178 | |
@Override |
179 | |
public List<LuiLuiRelationInfo> getLuiLuiRelationsByLui(String luiId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
180 | 0 | List<LuiLuiRelationInfo> infos = new ArrayList<LuiLuiRelationInfo>(); |
181 | 0 | for (LuiLuiRelationInfo info : this.llrCache.values()) { |
182 | 0 | if (info.getLuiId().equals(luiId)) { |
183 | 0 | infos.add(info); |
184 | |
} |
185 | |
} |
186 | 0 | return infos; |
187 | |
} |
188 | |
|
189 | |
@Override |
190 | |
public List<LuiInfo> getLuisByIdList(List<String> luiIdList, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
191 | 0 | List<LuiInfo> infos = new ArrayList<LuiInfo>(); |
192 | 0 | for (LuiInfo info : this.luiCache.values()) { |
193 | |
|
194 | 0 | if (luiIdList.contains(info.getId())) { |
195 | 0 | infos.add(info); |
196 | |
} |
197 | |
} |
198 | 0 | return infos; |
199 | |
} |
200 | |
|
201 | |
@Override |
202 | |
public List<LuiInfo> getLuisByRelation(String relatedLuiId, String luLuRelationType, ContextInfo context) |
203 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException { |
204 | 0 | List<LuiInfo> infos = new ArrayList<LuiInfo>(); |
205 | 0 | for (LuiLuiRelationInfo info : this.llrCache.values()) { |
206 | |
|
207 | 0 | if (info.getRelatedLuiId().equals(relatedLuiId)) { |
208 | 0 | if (info.getType().equals(luLuRelationType)) { |
209 | |
try { |
210 | 0 | infos.add(this.getLui(info.getLuiId(), context)); |
211 | 0 | } catch (DoesNotExistException ex) { |
212 | 0 | throw new OperationFailedException |
213 | |
("Referenetial integrity bad for luiId on llr" |
214 | |
+ info.getLuiId() + " llr.id=" + info.getId()); |
215 | 0 | } |
216 | |
} |
217 | |
} |
218 | |
} |
219 | 0 | return infos; |
220 | |
} |
221 | |
|
222 | |
@Override |
223 | |
public List<LuiInfo> getLuisInAtpByCluId(String cluId, String atpKey, ContextInfo context) |
224 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException { |
225 | 0 | List<LuiInfo> infos = new ArrayList<LuiInfo>(); |
226 | 0 | for (LuiInfo info : this.luiCache.values()) { |
227 | |
|
228 | 0 | if (info.getCluId().equals(cluId)) { |
229 | 0 | if (info.getAtpKey().equals(atpKey)) { |
230 | 0 | infos.add(info); |
231 | |
} |
232 | |
} |
233 | |
} |
234 | 0 | return infos; |
235 | |
} |
236 | |
|
237 | |
@Override |
238 | |
public List<String> getRelatedLuiIdsByLuiId(String luiId, String luLuRelationType, ContextInfo context) |
239 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException { |
240 | 0 | List<String> luiIds = new ArrayList<String>(); |
241 | 0 | for (LuiLuiRelationInfo info : this.llrCache.values()) { |
242 | 0 | if (info.getLuiId().equals(luiId)) { |
243 | 0 | if (info.getType().equals(luLuRelationType)) { |
244 | 0 | luiIds.add(info.getRelatedLuiId()); |
245 | |
} |
246 | |
} |
247 | |
} |
248 | 0 | return luiIds; |
249 | |
} |
250 | |
|
251 | |
@Override |
252 | |
public List<LuiInfo> getRelatedLuisByLuiId(String luiId, String luLuRelationType, ContextInfo context) |
253 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException { |
254 | 0 | List<LuiInfo> luiIds = new ArrayList<LuiInfo>(); |
255 | 0 | for (LuiLuiRelationInfo info : this.llrCache.values()) { |
256 | 0 | if (info.getLuiId().equals(luiId)) { |
257 | 0 | if (info.getType().equals(luLuRelationType)) { |
258 | |
try { |
259 | 0 | luiIds.add(this.getLui(info.getRelatedLuiId(), context)); |
260 | 0 | } catch (DoesNotExistException ex) { |
261 | 0 | throw new OperationFailedException |
262 | |
("Referenetial integrity bad for luiId on llr" |
263 | |
+ info.getLuiId() + " llr.id=" + info.getId()); |
264 | |
|
265 | 0 | } |
266 | |
} |
267 | |
} |
268 | |
} |
269 | 0 | return luiIds; |
270 | |
} |
271 | |
|
272 | |
@Override |
273 | |
public LuiInfo updateLui(String luiId, LuiInfo luiInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
274 | 0 | LuiInfo existing = this.luiCache.get(luiId); |
275 | 0 | if (existing == null) { |
276 | 0 | throw new DoesNotExistException(luiId); |
277 | |
} |
278 | 0 | if (!luiInfo.getMetaInfo().getVersionInd().equals( |
279 | |
existing.getMetaInfo().getVersionInd())) { |
280 | 0 | throw new VersionMismatchException( |
281 | |
"Updated by " + existing.getMetaInfo().getUpdateId() + " on " |
282 | |
+ existing.getMetaInfo().getUpdateId() + " with version of " |
283 | |
+ existing.getMetaInfo().getVersionInd()); |
284 | |
} |
285 | 0 | MockHelper helper = new MockHelper(); |
286 | 0 | LuiInfo copy = new LuiInfo.Builder(luiInfo).metaInfo(helper.updateMeta(existing.getMetaInfo(), context)).build(); |
287 | 0 | this.luiCache.put(luiId, copy); |
288 | |
|
289 | 0 | return new LuiInfo.Builder(copy).build(); |
290 | |
} |
291 | |
|
292 | |
@Override |
293 | |
public LuiLuiRelationInfo updateLuiLuiRelation(String luiLuiRelationId, LuiLuiRelationInfo luiLuiRelationInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
294 | 0 | LuiLuiRelationInfo existing = this.llrCache.get(luiLuiRelationId); |
295 | 0 | if (existing == null) { |
296 | 0 | throw new DoesNotExistException(luiLuiRelationId); |
297 | |
} |
298 | 0 | if (!luiLuiRelationInfo.getMetaInfo().getVersionInd().equals( |
299 | |
existing.getMetaInfo().getVersionInd())) { |
300 | 0 | throw new VersionMismatchException( |
301 | |
"Updated by " + existing.getMetaInfo().getUpdateId() + " on " |
302 | |
+ existing.getMetaInfo().getUpdateId() + " with version of " |
303 | |
+ existing.getMetaInfo().getVersionInd()); |
304 | |
} |
305 | 0 | MockHelper helper = new MockHelper(); |
306 | 0 | LuiLuiRelationInfo copy = new LuiLuiRelationInfo.Builder(luiLuiRelationInfo).metaInfo(helper.updateMeta(existing.getMetaInfo(), context)).build(); |
307 | 0 | this.llrCache.put(luiLuiRelationId, copy); |
308 | 0 | return copy; |
309 | |
|
310 | |
} |
311 | |
|
312 | |
@Override |
313 | |
public LuiInfo updateLuiState(String luiId, String luState, ContextInfo context) |
314 | |
throws DataValidationErrorException, |
315 | |
DoesNotExistException, |
316 | |
InvalidParameterException, |
317 | |
MissingParameterException, |
318 | |
OperationFailedException, |
319 | |
PermissionDeniedException { |
320 | 0 | LuiInfo existing = this.getLui(luiId, context); |
321 | 0 | LuiInfo updated = new LuiInfo.Builder(existing).setState(luState).build(); |
322 | |
try { |
323 | 0 | return this.updateLui(luiId, updated, context); |
324 | 0 | } catch (VersionMismatchException ex) { |
325 | 0 | throw new OperationFailedException("someone changed version since get ", ex); |
326 | |
} |
327 | |
} |
328 | |
} |
329 | |
|