1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.kuali.student.r2.core.class1.atp.service.impl; |
12 | |
|
13 | |
import java.util.ArrayList; |
14 | |
import java.util.Date; |
15 | |
import java.util.HashMap; |
16 | |
import java.util.HashSet; |
17 | |
import java.util.List; |
18 | |
import java.util.Map; |
19 | |
import java.util.Set; |
20 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
21 | |
import org.kuali.student.common.util.UUIDHelper; |
22 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
23 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
24 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
25 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
26 | |
import org.kuali.student.r2.common.exceptions.AlreadyExistsException; |
27 | |
import org.kuali.student.r2.common.exceptions.DataValidationErrorException; |
28 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
29 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
30 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
31 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
32 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
33 | |
import org.kuali.student.r2.common.exceptions.ReadOnlyException; |
34 | |
import org.kuali.student.r2.common.exceptions.VersionMismatchException; |
35 | |
import org.kuali.student.r2.core.atp.dto.AtpAtpRelationInfo; |
36 | |
import org.kuali.student.r2.core.atp.dto.AtpInfo; |
37 | |
import org.kuali.student.r2.core.atp.dto.MilestoneInfo; |
38 | |
import org.kuali.student.r2.core.atp.service.AtpService; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class AtpServiceMockImpl implements AtpService { |
46 | |
|
47 | 0 | private Map<String, AtpInfo> atpCache = new HashMap<String, AtpInfo>(); |
48 | 0 | private Map<String, MilestoneInfo> milestoneCache = new HashMap<String, MilestoneInfo>(); |
49 | 0 | private Map<String, AtpAtpRelationInfo> atpAtpRltnCache = new HashMap<String, AtpAtpRelationInfo>(); |
50 | 0 | private Map<String, Set<String>> milestonesForAtp = new HashMap<String, Set<String>>(); |
51 | |
|
52 | |
@Override |
53 | |
public AtpInfo getAtp(String atpId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
54 | 0 | AtpInfo atp = atpCache.get(atpId); |
55 | 0 | if (null == atp) { |
56 | 0 | throw new DoesNotExistException("No atp found for: " + atpId); |
57 | |
|
58 | |
} |
59 | 0 | return atp; |
60 | |
} |
61 | |
|
62 | |
@Override |
63 | |
public List<AtpInfo> getAtpsByDate(Date searchDate, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
64 | |
|
65 | 0 | List<AtpInfo> atpList = new ArrayList<AtpInfo>(); |
66 | |
|
67 | 0 | Set<String> keys = atpCache.keySet(); |
68 | |
|
69 | 0 | for (String key : keys) { |
70 | 0 | AtpInfo atp = atpCache.get(key); |
71 | 0 | if ((atp.getStartDate().before(searchDate) || atp.getStartDate().equals(searchDate)) && (atp.getEndDate().after(searchDate) || atp.getEndDate().equals(searchDate))) { |
72 | 0 | atpList.add(atp); |
73 | |
} |
74 | 0 | } |
75 | |
|
76 | 0 | return atpList; |
77 | |
|
78 | |
} |
79 | |
|
80 | |
@Override |
81 | |
public List<AtpInfo> getAtpsByDates(Date startDate, Date endDate, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
82 | 0 | List<AtpInfo> atpList = new ArrayList<AtpInfo>(); |
83 | |
|
84 | 0 | Set<String> keys = atpCache.keySet(); |
85 | |
|
86 | 0 | for (String key : keys) { |
87 | 0 | AtpInfo atp = atpCache.get(key); |
88 | 0 | if (startDate.before(atp.getStartDate()) && endDate.after(atp.getEndDate())) { |
89 | 0 | atpList.add(atp); |
90 | |
} |
91 | 0 | } |
92 | |
|
93 | 0 | return atpList; |
94 | |
|
95 | |
} |
96 | |
|
97 | |
@Override |
98 | |
public List<AtpInfo> getAtpsByDateAndType(Date searchDate, String searchTypeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
99 | |
PermissionDeniedException { |
100 | 0 | List<AtpInfo> atpList = new ArrayList<AtpInfo>(); |
101 | 0 | for (AtpInfo atp : this.getAtpsByDate(searchDate, context)) { |
102 | 0 | if (searchTypeKey.equals(atp.getTypeKey())) { |
103 | 0 | atpList.add(atp); |
104 | |
} |
105 | |
} |
106 | 0 | return atpList; |
107 | |
} |
108 | |
|
109 | |
@Override |
110 | |
public List<AtpInfo> getAtpsByDatesAndType(Date searchDate, Date endDate, String searchTypeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, |
111 | |
OperationFailedException, PermissionDeniedException { |
112 | 0 | List<AtpInfo> atpList = new ArrayList<AtpInfo>(); |
113 | 0 | for (AtpInfo atp : this.getAtpsByDates(searchDate, endDate, context)) { |
114 | 0 | if (searchTypeKey.equals(atp.getTypeKey())) { |
115 | 0 | atpList.add(atp); |
116 | |
} |
117 | |
} |
118 | 0 | return atpList; |
119 | |
} |
120 | |
|
121 | |
@Override |
122 | |
public List<AtpInfo> getAtpsByStartDateRange(Date searchDateRangeStart, Date searchDateRangeEnd, ContextInfo context) throws InvalidParameterException, MissingParameterException, |
123 | |
OperationFailedException, PermissionDeniedException { |
124 | 0 | List<AtpInfo> atpList = new ArrayList<AtpInfo>(); |
125 | 0 | for (AtpInfo atp : atpCache.values()) { |
126 | 0 | if (searchDateRangeStart.before(atp.getStartDate()) && searchDateRangeEnd.after(atp.getStartDate())) { |
127 | 0 | atpList.add(atp); |
128 | |
} |
129 | |
} |
130 | 0 | return atpList; |
131 | |
} |
132 | |
|
133 | |
@Override |
134 | |
public List<AtpInfo> getAtpsByStartDateRangeAndType(Date searchDateRangeStart, Date searchDateRangeEnd, String searchTypeKey, ContextInfo context) throws InvalidParameterException, |
135 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
136 | 0 | List<AtpInfo> atpList = new ArrayList<AtpInfo>(); |
137 | 0 | for (AtpInfo atp : this.getAtpsByStartDateRange(searchDateRangeStart, searchDateRangeEnd, context)) { |
138 | 0 | if (searchTypeKey.equals(atp.getTypeKey())) { |
139 | 0 | atpList.add(atp); |
140 | |
} |
141 | |
} |
142 | 0 | return atpList; |
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public List<String> getAtpIdsByType(String atpTypeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
147 | 0 | List<String> atpIds = new ArrayList<String>(); |
148 | |
|
149 | 0 | Set<String> keys = atpCache.keySet(); |
150 | |
|
151 | 0 | for (String key : keys) { |
152 | 0 | AtpInfo atp = atpCache.get(key); |
153 | 0 | if (atp.getTypeKey().equalsIgnoreCase(atpTypeKey)) { |
154 | 0 | atpIds.add(atp.getId()); |
155 | |
} |
156 | 0 | } |
157 | |
|
158 | 0 | return atpIds; |
159 | |
} |
160 | |
|
161 | |
@Override |
162 | |
public List<AtpInfo> getAtpsByCode(String code, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
163 | |
|
164 | 0 | return new ArrayList<AtpInfo>(); |
165 | |
} |
166 | |
|
167 | |
@Override |
168 | |
public List<AtpInfo> getAtpsByIds(List<String> atpIds, ContextInfo context) throws InvalidParameterException, DoesNotExistException, MissingParameterException, OperationFailedException, |
169 | |
PermissionDeniedException { |
170 | 0 | List<AtpInfo> atpList = new ArrayList<AtpInfo>(); |
171 | |
|
172 | 0 | for (String key : atpIds) { |
173 | 0 | atpList.add(this.getAtp(key, context)); |
174 | |
} |
175 | |
|
176 | 0 | return atpList; |
177 | |
} |
178 | |
|
179 | |
@Override |
180 | |
public MilestoneInfo getMilestone(String milestoneId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
181 | |
|
182 | 0 | MilestoneInfo milestone = milestoneCache.get(milestoneId); |
183 | 0 | if (null == milestone) { |
184 | 0 | throw new DoesNotExistException("No milestone found for: " + milestoneId); |
185 | |
} |
186 | |
|
187 | 0 | return new MilestoneInfo (milestone); |
188 | |
} |
189 | |
|
190 | |
@Override |
191 | |
public List<MilestoneInfo> getMilestonesForAtp(String atpId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
192 | 0 | List<MilestoneInfo> list = new ArrayList<MilestoneInfo>(); |
193 | 0 | if (!this.milestonesForAtp.containsKey(atpId)) { |
194 | 0 | this.milestonesForAtp.put(atpId, new HashSet<String>()); |
195 | |
} |
196 | 0 | Set<String> milestoneIds = this.milestonesForAtp.get(atpId); |
197 | 0 | for (String id : milestoneIds) { |
198 | |
MilestoneInfo info; |
199 | |
try { |
200 | 0 | info = this.getMilestone(id, context); |
201 | 0 | } catch (DoesNotExistException ex) { |
202 | 0 | throw new OperationFailedException("id in set not in milestone" + id, ex); |
203 | 0 | } |
204 | 0 | list.add(info); |
205 | 0 | } |
206 | 0 | return list; |
207 | |
} |
208 | |
|
209 | |
@Override |
210 | |
public List<MilestoneInfo> getMilestonesByDatesForAtp(String atpId, Date startDate, Date endDate,ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
211 | 0 | return null; |
212 | |
|
213 | |
} |
214 | |
|
215 | |
@Override |
216 | |
public List<MilestoneInfo> getMilestonesByTypeForAtp(String atpId,String milestoneTypeKey,ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
217 | 0 | return null; |
218 | |
|
219 | |
} |
220 | |
|
221 | |
@Override |
222 | |
public List<MilestoneInfo> getMilestonesByDates(Date startDate, Date endDate, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
223 | 0 | List<MilestoneInfo> milestoneList = new ArrayList<MilestoneInfo>(); |
224 | |
|
225 | 0 | Set<String> keys = milestoneCache.keySet(); |
226 | |
|
227 | 0 | for (String key : keys) { |
228 | 0 | MilestoneInfo milestone = milestoneCache.get(key); |
229 | |
|
230 | 0 | if (milestone.getIsDateRange()) { |
231 | 0 | if ((startDate.before(milestone.getStartDate()) || startDate.equals(milestone.getStartDate())) && (endDate.after(milestone.getEndDate()) || endDate.equals(milestone.getEndDate()))) { |
232 | 0 | milestoneList.add(milestone); |
233 | |
} |
234 | |
} else { |
235 | 0 | if ((startDate.before(milestone.getStartDate()) || startDate.equals(milestone.getStartDate()))) { |
236 | 0 | milestoneList.add(milestone); |
237 | |
} |
238 | |
} |
239 | 0 | } |
240 | |
|
241 | 0 | return milestoneList; |
242 | |
} |
243 | |
|
244 | |
@Override |
245 | |
public List<MilestoneInfo> getMilestonesByIds(List<String> milestoneIds, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
246 | |
OperationFailedException, PermissionDeniedException { |
247 | 0 | List<MilestoneInfo> milestoneList = new ArrayList<MilestoneInfo>(); |
248 | |
|
249 | 0 | for (String key : milestoneIds) { |
250 | 0 | milestoneList.add(this.getMilestone(key, context)); |
251 | |
} |
252 | |
|
253 | 0 | return milestoneList; |
254 | |
} |
255 | |
|
256 | |
@Override |
257 | |
public List<String> getMilestoneIdsByType(String milestoneTypeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
258 | |
PermissionDeniedException { |
259 | 0 | List<String> milestoneIds = new ArrayList<String>(); |
260 | |
|
261 | 0 | Set<String> keys = milestoneCache.keySet(); |
262 | |
|
263 | 0 | for (String key : keys) { |
264 | 0 | MilestoneInfo milestone = milestoneCache.get(key); |
265 | 0 | if (milestone.getTypeKey().equalsIgnoreCase(milestoneTypeKey)) { |
266 | 0 | milestoneIds.add(milestone.getId()); |
267 | |
} |
268 | 0 | } |
269 | |
|
270 | 0 | return milestoneIds; |
271 | |
} |
272 | |
|
273 | |
@Override |
274 | |
public List<String> searchForAtpIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
275 | |
PermissionDeniedException { |
276 | |
|
277 | 0 | return new ArrayList<String>(); |
278 | |
} |
279 | |
|
280 | |
@Override |
281 | |
public List<AtpInfo> searchForAtps(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
282 | |
|
283 | 0 | return new ArrayList<AtpInfo>(); |
284 | |
} |
285 | |
|
286 | |
public List<ValidationResultInfo> validateAtp(String validationType, String atpTypeKey, AtpInfo atpInfo, ContextInfo context) throws DoesNotExistException, InvalidParameterException, |
287 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
288 | 0 | return new ArrayList<ValidationResultInfo>(); |
289 | |
} |
290 | |
|
291 | |
@Override |
292 | |
public AtpInfo createAtp(String atpTypeKey, |
293 | |
AtpInfo atpInfo, |
294 | |
ContextInfo context) |
295 | |
throws DataValidationErrorException, InvalidParameterException, MissingParameterException, |
296 | |
OperationFailedException, PermissionDeniedException { |
297 | 0 | MockHelper helper = new MockHelper(); |
298 | 0 | AtpInfo info = new AtpInfo(atpInfo); |
299 | 0 | info.setMeta(helper.createMeta(context)); |
300 | 0 | if (info.getId() == null) { |
301 | 0 | info.setId(UUIDHelper.genStringUUID()); |
302 | |
} |
303 | 0 | helper.setIdOnAttributesThatDoNotHaveOne(info.getAttributes()); |
304 | 0 | this.atpCache.put(info.getId(), info); |
305 | 0 | return new AtpInfo(info); |
306 | |
} |
307 | |
|
308 | |
@Override |
309 | |
public AtpInfo updateAtp(String atpId, AtpInfo atpInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, |
310 | |
OperationFailedException, PermissionDeniedException, VersionMismatchException { |
311 | 0 | AtpInfo existing = this.atpCache.get(atpId); |
312 | 0 | if (existing == null) { |
313 | 0 | throw new DoesNotExistException(atpId); |
314 | |
} |
315 | 0 | if (!atpInfo.getMeta().getVersionInd().equals(existing.getMeta().getVersionInd())) { |
316 | 0 | throw new VersionMismatchException("Updated by " + existing.getMeta().getUpdateId() + " on " + existing.getMeta().getUpdateId() + " with version of " + existing.getMeta().getVersionInd()); |
317 | |
} |
318 | 0 | AtpInfo atp = new AtpInfo(atpInfo); |
319 | 0 | atp.setMeta(new MockHelper().updateMeta(existing.getMeta(), context)); |
320 | 0 | new MockHelper ().setIdOnAttributesThatDoNotHaveOne(atp.getAttributes()); |
321 | 0 | this.atpCache.put(atpId, atp); |
322 | 0 | return new AtpInfo(atp); |
323 | |
} |
324 | |
|
325 | |
@Override |
326 | |
public StatusInfo deleteAtp(String atpId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
327 | |
PermissionDeniedException { |
328 | 0 | if (this.atpCache.remove(atpId) == null) { |
329 | 0 | throw new DoesNotExistException(atpId); |
330 | |
} |
331 | 0 | StatusInfo status = new StatusInfo(); |
332 | 0 | status.setSuccess(Boolean.TRUE); |
333 | 0 | return status; |
334 | |
} |
335 | |
|
336 | |
@Override |
337 | |
public List<MilestoneInfo> getImpactedMilestones(String milestoneId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
338 | 0 | return new ArrayList<MilestoneInfo>(); |
339 | |
} |
340 | |
|
341 | |
@Override |
342 | |
public List<String> searchForMilestoneIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
343 | |
PermissionDeniedException { |
344 | |
|
345 | 0 | return new ArrayList<String>(); |
346 | |
} |
347 | |
|
348 | |
@Override |
349 | |
public List<MilestoneInfo> searchForMilestones(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
350 | |
PermissionDeniedException { |
351 | |
|
352 | 0 | return new ArrayList<MilestoneInfo>(); |
353 | |
} |
354 | |
|
355 | |
@Override |
356 | |
public List<ValidationResultInfo> validateMilestone(String validationType, MilestoneInfo milestoneInfo, ContextInfo context) throws DoesNotExistException, InvalidParameterException, |
357 | |
MissingParameterException, OperationFailedException { |
358 | 0 | return new ArrayList<ValidationResultInfo>(); |
359 | |
} |
360 | |
|
361 | |
@Override |
362 | |
public MilestoneInfo createMilestone(String milestoneTypeKey, |
363 | |
MilestoneInfo milestoneInfo, ContextInfo context) |
364 | |
throws DataValidationErrorException, InvalidParameterException, |
365 | |
MissingParameterException, |
366 | |
OperationFailedException, PermissionDeniedException { |
367 | |
|
368 | 0 | if (milestoneInfo.getId() != null) { |
369 | 0 | if (this.milestoneCache.containsKey(milestoneInfo.getId())) { |
370 | 0 | throw new DataValidationErrorException(milestoneInfo.getId()); |
371 | |
} |
372 | |
} |
373 | |
|
374 | 0 | MockHelper helper = new MockHelper(); |
375 | 0 | MilestoneInfo info = new MilestoneInfo(milestoneInfo); |
376 | 0 | info.setMeta(helper.createMeta(context)); |
377 | 0 | if (info.getId() == null) { |
378 | 0 | info.setId(UUIDHelper.genStringUUID()); |
379 | |
} |
380 | 0 | defaultBooleansToFalse (info); |
381 | |
|
382 | 0 | info.setStartDate(DateUtil.startOfDayfIsAllDay (info.getIsAllDay(), info.getStartDate())); |
383 | 0 | info.setEndDate(DateUtil.endOfDayIfIsAllDay (info.getIsAllDay (), DateUtil.nullIfNotDateRange(info.getIsDateRange(), info.getEndDate()))); |
384 | 0 | this.milestoneCache.put(info.getId(), info); |
385 | 0 | return new MilestoneInfo(info); |
386 | |
} |
387 | |
|
388 | |
private void defaultBooleansToFalse (MilestoneInfo info) { |
389 | 0 | if (info.getIsAllDay() == null) { |
390 | 0 | info.setIsAllDay(Boolean.FALSE); |
391 | |
} |
392 | 0 | if (info.getIsDateRange() == null) { |
393 | 0 | info.setIsDateRange(Boolean.FALSE); |
394 | |
} |
395 | 0 | if (info.getIsInstructionalDay() == null) { |
396 | 0 | info.setIsInstructionalDay(Boolean.FALSE); |
397 | |
} |
398 | 0 | if (info.getIsRelative() == null) { |
399 | 0 | info.setIsRelative(Boolean.FALSE); |
400 | |
} |
401 | 0 | } |
402 | |
|
403 | |
@Override |
404 | |
public MilestoneInfo updateMilestone(String milestoneId, MilestoneInfo milestoneInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, |
405 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
406 | 0 | MilestoneInfo existing = this.milestoneCache.get(milestoneId); |
407 | 0 | if (existing == null) { |
408 | 0 | throw new DoesNotExistException(milestoneId); |
409 | |
} |
410 | 0 | if (!milestoneInfo.getMeta().getVersionInd().equals(existing.getMeta().getVersionInd())) { |
411 | 0 | throw new VersionMismatchException("Updated by " + existing.getMeta().getUpdateId() + " on " + existing.getMeta().getUpdateId() + " with version of " + existing.getMeta().getVersionInd()); |
412 | |
} |
413 | 0 | MilestoneInfo info = new MilestoneInfo(milestoneInfo); |
414 | 0 | info.setMeta(new MockHelper().updateMeta(existing.getMeta(), context)); |
415 | 0 | defaultBooleansToFalse (info); |
416 | |
|
417 | 0 | info.setStartDate(DateUtil.startOfDayfIsAllDay (info.getIsAllDay(), info.getStartDate())); |
418 | 0 | info.setEndDate(DateUtil.endOfDayIfIsAllDay (info.getIsAllDay (), DateUtil.nullIfNotDateRange(info.getIsDateRange(), info.getEndDate()))); |
419 | 0 | this.milestoneCache.put(milestoneId, info); |
420 | 0 | return new MilestoneInfo(info); |
421 | |
} |
422 | |
|
423 | |
@Override |
424 | |
public StatusInfo deleteMilestone(String milestoneId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
425 | |
PermissionDeniedException { |
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | 0 | if (this.milestoneCache.remove(milestoneId) == null) { |
431 | 0 | throw new DoesNotExistException(milestoneId); |
432 | |
} |
433 | 0 | StatusInfo status = new StatusInfo(); |
434 | 0 | status.setSuccess(Boolean.TRUE); |
435 | 0 | return status; |
436 | |
} |
437 | |
|
438 | |
@Override |
439 | |
public MilestoneInfo calculateMilestone(String milestoneId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
440 | 0 | return getMilestone(milestoneId, contextInfo); |
441 | |
} |
442 | |
|
443 | |
@Override |
444 | |
public StatusInfo addMilestoneToAtp(String milestoneId,String atpId, ContextInfo contextInfo) |
445 | |
throws AlreadyExistsException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
446 | |
|
447 | 0 | if (!this.milestonesForAtp.containsKey(atpId)) { |
448 | 0 | this.milestonesForAtp.put(atpId, new HashSet<String>()); |
449 | |
} |
450 | 0 | Set<String> milestones = this.milestonesForAtp.get(atpId); |
451 | 0 | if (milestones.contains(milestoneId)) { |
452 | 0 | throw new AlreadyExistsException(); |
453 | |
} |
454 | 0 | milestones.add(milestoneId); |
455 | 0 | StatusInfo status = new StatusInfo(); |
456 | 0 | status.setSuccess(Boolean.TRUE); |
457 | 0 | return status; |
458 | |
} |
459 | |
|
460 | |
@Override |
461 | |
public StatusInfo removeMilestoneFromAtp(String milestoneId, String atpId, ContextInfo contextInfo) |
462 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
463 | 0 | if (!this.milestonesForAtp.containsKey(atpId)) { |
464 | 0 | this.milestonesForAtp.put(atpId, new HashSet<String>()); |
465 | |
} |
466 | 0 | Set<String> milestones = this.milestonesForAtp.get(atpId); |
467 | 0 | if (!milestones.contains(milestoneId)) { |
468 | 0 | throw new DoesNotExistException(); |
469 | |
} |
470 | 0 | milestones.remove(milestoneId); |
471 | 0 | StatusInfo status = new StatusInfo(); |
472 | 0 | status.setSuccess(Boolean.TRUE); |
473 | 0 | return status; |
474 | |
} |
475 | |
|
476 | |
@Override |
477 | |
public AtpAtpRelationInfo getAtpAtpRelation(String atpAtpRelationId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
478 | |
OperationFailedException, PermissionDeniedException { |
479 | 0 | AtpAtpRelationInfo atpRltn = atpAtpRltnCache.get(atpAtpRelationId); |
480 | 0 | if (null == atpRltn) { |
481 | 0 | throw new DoesNotExistException("No atp atp relationship found for: " + atpAtpRelationId); |
482 | |
} |
483 | |
|
484 | 0 | return new AtpAtpRelationInfo(atpRltn); |
485 | |
} |
486 | |
|
487 | |
@Override |
488 | |
public List<AtpAtpRelationInfo> getAtpAtpRelationsByIds(List<String> atpAtpRelationIds, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, |
489 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
490 | |
|
491 | 0 | List<AtpAtpRelationInfo> atpRltnList = new ArrayList<AtpAtpRelationInfo>(); |
492 | |
|
493 | 0 | for (String id : atpAtpRelationIds) { |
494 | 0 | atpRltnList.add(this.getAtpAtpRelation(id, contextInfo)); |
495 | |
} |
496 | |
|
497 | 0 | return atpRltnList; |
498 | |
} |
499 | |
|
500 | |
@Override |
501 | |
public List<String> getAtpAtpRelationIdsByType(String atpAtpRelationTypeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
502 | |
PermissionDeniedException { |
503 | 0 | List<String> atpRltnList = new ArrayList<String>(); |
504 | |
|
505 | 0 | Set<String> atpRltnIds = atpAtpRltnCache.keySet(); |
506 | |
|
507 | 0 | for (String id : atpRltnIds) { |
508 | 0 | AtpAtpRelationInfo rltn = atpAtpRltnCache.get(id); |
509 | 0 | if (rltn.getTypeKey().equalsIgnoreCase(atpAtpRelationTypeKey)) { |
510 | 0 | atpRltnList.add(id); |
511 | |
} |
512 | 0 | } |
513 | |
|
514 | 0 | return atpRltnList; |
515 | |
} |
516 | |
|
517 | |
@Override |
518 | |
public List<AtpAtpRelationInfo> getAtpAtpRelationsByAtp(String atpId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
519 | |
PermissionDeniedException { |
520 | 0 | List<AtpAtpRelationInfo> atpRltnList = new ArrayList<AtpAtpRelationInfo>(); |
521 | |
|
522 | 0 | Set<String> atpRltnIds = atpAtpRltnCache.keySet(); |
523 | |
|
524 | 0 | for (String id : atpRltnIds) { |
525 | 0 | AtpAtpRelationInfo rltn = atpAtpRltnCache.get(id); |
526 | 0 | if (rltn.getAtpId().equals(atpId) || rltn.getRelatedAtpId().equals(atpId)) { |
527 | 0 | atpRltnList.add(new AtpAtpRelationInfo(rltn)); |
528 | |
} |
529 | 0 | } |
530 | |
|
531 | 0 | return atpRltnList; |
532 | |
} |
533 | |
|
534 | |
@Override |
535 | |
public List<AtpAtpRelationInfo> getAtpAtpRelationsByAtps(String atpId, ContextInfo contextInfo) throws InvalidParameterException, |
536 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
537 | 0 | return new ArrayList(); |
538 | |
} |
539 | |
|
540 | |
@Override |
541 | |
public List<AtpAtpRelationInfo> getAtpAtpRelationsByTypeAndAtp(String atpId, String atpRelationTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
542 | 0 | List<AtpAtpRelationInfo> list = new ArrayList<AtpAtpRelationInfo> (); |
543 | 0 | for (AtpAtpRelationInfo info : this.atpAtpRltnCache.values()) { |
544 | 0 | if (info.getAtpId().equals(atpId)) { |
545 | 0 | if (info.getTypeKey().equals (atpRelationTypeKey)) { |
546 | 0 | list.add (new AtpAtpRelationInfo (info)); |
547 | |
} |
548 | |
} |
549 | |
} |
550 | 0 | return list; |
551 | |
} |
552 | |
|
553 | |
@Override |
554 | |
public List<String> searchForAtpAtpRelationIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
555 | |
PermissionDeniedException { |
556 | |
|
557 | 0 | return new ArrayList<String>(); |
558 | |
} |
559 | |
|
560 | |
@Override |
561 | |
public List<AtpAtpRelationInfo> searchForAtpAtpRelations(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
562 | |
PermissionDeniedException { |
563 | |
|
564 | 0 | return new ArrayList<AtpAtpRelationInfo>(); |
565 | |
} |
566 | |
|
567 | |
@Override |
568 | |
public List<ValidationResultInfo> validateAtpAtpRelation(String validationTypeKey, String atpId, String atpPeerId, String atpAtpRelationTypeKey, AtpAtpRelationInfo atpAtpRelationInfo, |
569 | |
ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
570 | 0 | return new ArrayList<ValidationResultInfo>(); |
571 | |
} |
572 | |
|
573 | |
@Override |
574 | |
public AtpAtpRelationInfo createAtpAtpRelation(String atpId, |
575 | |
String relatedAtpId, |
576 | |
String atpAtpRelationTypeKey, |
577 | |
AtpAtpRelationInfo atpAtpRelationInfo, |
578 | |
ContextInfo contextInfo) |
579 | |
throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, |
580 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, |
581 | |
ReadOnlyException { |
582 | 0 | MockHelper helper = new MockHelper(); |
583 | 0 | AtpAtpRelationInfo info = new AtpAtpRelationInfo(atpAtpRelationInfo); |
584 | 0 | info.setMeta(helper.createMeta(contextInfo)); |
585 | 0 | if (info.getId() == null) { |
586 | 0 | info.setId(UUIDHelper.genStringUUID()); |
587 | |
} |
588 | 0 | this.atpAtpRltnCache.put(info.getId(), info); |
589 | 0 | return info; |
590 | |
} |
591 | |
|
592 | |
@Override |
593 | |
public AtpAtpRelationInfo updateAtpAtpRelation(String atpAtpRelationId, AtpAtpRelationInfo atpAtpRelationInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, |
594 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
595 | 0 | AtpAtpRelationInfo existing = this.atpAtpRltnCache.get(atpAtpRelationId); |
596 | 0 | if (existing == null) { |
597 | 0 | throw new DoesNotExistException(atpAtpRelationId); |
598 | |
} |
599 | 0 | if (!atpAtpRelationInfo.getMeta().getVersionInd().equals(existing.getMeta().getVersionInd())) { |
600 | 0 | throw new VersionMismatchException("Updated by " + existing.getMeta().getUpdateId() + " on " + existing.getMeta().getUpdateId() + " with version of " + existing.getMeta().getVersionInd()); |
601 | |
} |
602 | 0 | AtpAtpRelationInfo aari = new AtpAtpRelationInfo(atpAtpRelationInfo); |
603 | 0 | aari.setMeta(new MockHelper().updateMeta(existing.getMeta(), context)); |
604 | |
|
605 | |
|
606 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
607 | 0 | for (AttributeInfo att : atpAtpRelationInfo.getAttributes()) { |
608 | 0 | atts.add(new AttributeInfo(att)); |
609 | |
} |
610 | 0 | aari.setAttributes(atts); |
611 | 0 | this.atpAtpRltnCache.put(atpAtpRelationId, aari); |
612 | |
|
613 | 0 | return aari; |
614 | |
} |
615 | |
|
616 | |
@Override |
617 | |
public StatusInfo deleteAtpAtpRelation(String atpAtpRelationId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
618 | |
PermissionDeniedException { |
619 | 0 | if (this.atpAtpRltnCache.remove(atpAtpRelationId) == null) { |
620 | 0 | throw new DoesNotExistException(atpAtpRelationId); |
621 | |
} |
622 | 0 | StatusInfo status = new StatusInfo(); |
623 | 0 | status.setSuccess(Boolean.TRUE); |
624 | 0 | return status; |
625 | |
} |
626 | |
} |
627 | |
|