1
2
3
4
5 package org.kuali.student.r2.core.process;
6
7
8 import org.kuali.rice.core.api.criteria.AndPredicate;
9 import org.kuali.rice.core.api.criteria.LikePredicate;
10 import org.kuali.rice.core.api.criteria.Predicate;
11 import org.kuali.rice.core.api.criteria.QueryByCriteria;
12 import org.kuali.student.common.mock.MockService;
13 import org.kuali.student.r2.common.dto.ContextInfo;
14 import org.kuali.student.r2.common.dto.RichTextInfo;
15 import org.kuali.student.r2.common.dto.StatusInfo;
16 import org.kuali.student.r2.common.dto.ValidationResultInfo;
17 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
18 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
19 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
20 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
21 import org.kuali.student.r2.common.exceptions.MissingParameterException;
22 import org.kuali.student.r2.common.exceptions.OperationFailedException;
23 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
24 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
25 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
26 import org.kuali.student.r2.core.constants.PopulationServiceConstants;
27 import org.kuali.student.r2.core.population.dto.PopulationCategoryInfo;
28 import org.kuali.student.r2.core.population.dto.PopulationInfo;
29 import org.kuali.student.r2.core.population.dto.PopulationRuleInfo;
30 import org.kuali.student.r2.core.population.service.PopulationService;
31
32 import javax.jws.WebParam;
33 import java.util.ArrayList;
34 import java.util.Date;
35 import java.util.HashMap;
36 import java.util.HashSet;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.Set;
40
41 public class ProcessPocPopulationServiceMockImpl implements PopulationService, MockService {
42
43 private Map<String, PopulationInfo> populations;
44 private Map<String, Set<String>> caches;
45
46 public ProcessPocPopulationServiceMockImpl() {
47 initialize();
48 }
49
50
51 @Override
52 public void clear() {
53
54 if (this.caches != null)
55 this.caches.clear();
56
57 if (this.populations != null)
58 this.populations.clear();
59
60 initialize();
61
62 }
63
64
65 private void initialize() {
66 try {
67 populations = new HashMap<String, PopulationInfo>();
68 caches = new HashMap<String, Set<String>>();
69
70 final String ALL_STUDENTS = PopulationServiceConstants.EVERYONE_POPULATION_KEY;
71 final String SUMMER_ONLY_STUDENTS = PopulationServiceConstants.SUMMER_ONLY_STUDENTS_POPULATION_KEY;
72 final String SENIOR_ONLY_STUDENTS = "kuali.population.senior.only.student";
73 final String ATHLETES_ONLY_STUDENTS = "kuali.population.athletes.only.student";
74
75 PopulationInfo allStudentsPopulation = new PopulationInfo();
76 allStudentsPopulation.setId(ALL_STUDENTS);
77 allStudentsPopulation.setName("All students");
78 RichTextInfo allStudDesc = new RichTextInfo();
79 allStudDesc.setPlain("All students population");
80 allStudentsPopulation.setDescr(allStudDesc);
81 createPopulation(allStudentsPopulation, new ContextInfo());
82
83 PopulationInfo summerOnlyStudentsPopulation = new PopulationInfo();
84 summerOnlyStudentsPopulation.setId(SUMMER_ONLY_STUDENTS);
85 summerOnlyStudentsPopulation.setName("Summer only students");
86 RichTextInfo summerDesc = new RichTextInfo();
87 summerDesc.setPlain("Summer only students population");
88 summerOnlyStudentsPopulation.setDescr(summerDesc);
89 createPopulation(summerOnlyStudentsPopulation, new ContextInfo());
90
91 PopulationInfo seniorsOnlyStudentsPopulation = new PopulationInfo();
92 seniorsOnlyStudentsPopulation.setId(SENIOR_ONLY_STUDENTS);
93 seniorsOnlyStudentsPopulation.setName("Senior students");
94 RichTextInfo seniorsDesc = new RichTextInfo();
95 seniorsDesc.setPlain("Senior only students");
96 seniorsOnlyStudentsPopulation.setDescr(seniorsDesc);
97 createPopulation(seniorsOnlyStudentsPopulation, new ContextInfo());
98
99 PopulationInfo athletesOnlyStudentsPopulation = new PopulationInfo();
100 athletesOnlyStudentsPopulation.setId(ATHLETES_ONLY_STUDENTS);
101 athletesOnlyStudentsPopulation.setName("Athletes only students");
102 RichTextInfo athletesDesc = new RichTextInfo();
103 athletesDesc.setPlain("Athletes students population");
104 athletesOnlyStudentsPopulation.setDescr(athletesDesc);
105 createPopulation(athletesOnlyStudentsPopulation, new ContextInfo());
106
107
108 generateStudentPopulations(SUMMER_ONLY_STUDENTS, "SUMMER_ONLY_STUDENTS", 5000);
109 generateStudentPopulations(SENIOR_ONLY_STUDENTS,"SENIOR_ONLY_STUDENTS", 5000);
110 generateStudentPopulations(ATHLETES_ONLY_STUDENTS,"ATHLETES_ONLY_STUDENTS", 550);
111
112
113 caches.get(SUMMER_ONLY_STUDENTS).add("2155");
114
115 caches.get(ALL_STUDENTS).add("2005");
116 caches.get(ALL_STUDENTS).add("2016");
117 caches.get(ALL_STUDENTS).add("2132");
118 caches.get(ALL_STUDENTS).add("2166");
119 caches.get(ALL_STUDENTS).add("2272");
120 caches.get(ALL_STUDENTS).add("2374");
121 caches.get(ALL_STUDENTS).add("2397");
122 caches.get(ALL_STUDENTS).add("2406");
123
124
125 caches.get(ALL_STUDENTS).addAll(caches.get(SUMMER_ONLY_STUDENTS));
126 caches.get(ALL_STUDENTS).addAll(caches.get(SENIOR_ONLY_STUDENTS));
127 caches.get(ALL_STUDENTS).addAll(caches.get(ATHLETES_ONLY_STUDENTS));
128
129
130 } catch (Exception e) {
131 throw new RuntimeException("Error initializing", e);
132 }
133 }
134
135 private void generateStudentPopulations(String populationCacheKey, String populationPrefix, int numToGenerate){
136 int base = 100000000;
137
138 for(int i = 0; i<numToGenerate; i++){
139 caches.get(populationCacheKey).add(populationPrefix + (base + i));
140 }
141 }
142
143 @Override
144 public Boolean isMemberAsOfDate(@WebParam(name = "personId") String personId, @WebParam(name = "populationId") String populationId, @WebParam(name = "date") Date date, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
145 if (null == personId || 0 == personId.length()) {
146 throw new MissingParameterException("personId");
147 }
148 if (null == populationId || 0 == populationId.length()) {
149 throw new MissingParameterException("populationId");
150 }
151
152 Set<String> cache = caches.get(populationId);
153 if (null == cache) {
154 throw new DoesNotExistException("populationId '" + populationId + "' not found");
155 }
156 return cache.contains(personId);
157 }
158
159 @Override
160 public List<String> getMembersAsOfDate(@WebParam(name = "populationId") String populationId, @WebParam(name = "date") Date date, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
161 if (null == populationId || 0 == populationId.length()) {
162 throw new MissingParameterException("populationId");
163 }
164
165 Set<String> cache = caches.get(populationId);
166 if (null == cache) {
167 throw new DoesNotExistException("populationId '" + populationId + "' not found");
168 }
169 return new ArrayList<String>(cache);
170 }
171
172 @Override
173 public PopulationInfo getPopulation(@WebParam(name = "populationId") String populationId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
174 if (null == populationId || 0 == populationId.length()) {
175 throw new MissingParameterException("populationId");
176 }
177
178 PopulationInfo population = populations.get(populationId);
179 if (null == population) {
180 throw new DoesNotExistException("populationId '" + populationId + "' not found");
181 }
182 return population;
183 }
184
185 @Override
186 public List<PopulationInfo> getPopulationsByIds(@WebParam(name = "populationIds") List<String> populationIds, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
187 if (0 == populationIds.size()) {
188 throw new MissingParameterException("populationIds");
189 }
190
191 List<PopulationInfo> result = new ArrayList<PopulationInfo>();
192 for (String populationId : populationIds) {
193 PopulationInfo population = populations.get(populationId);
194 if (null == population) {
195 throw new DoesNotExistException("populationId '" + populationId + "' not found");
196 }
197 result.add(population);
198 }
199 return result;
200 }
201
202 @Override
203 public List<String> getPopulationIdsByType(@WebParam(name = "populationTypeId") String populationTypeId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
204 throw new OperationFailedException("Method not implemented.");
205 }
206
207 @Override
208 public List<PopulationInfo> getPopulationsForPopulationRule(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
209 throw new OperationFailedException("Method not implemented.");
210 }
211
212 @Override
213 public List<String> searchForPopulationIds(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
214 throw new OperationFailedException("Method not implemented.");
215 }
216
217 @Override
218 public List<PopulationInfo> searchForPopulations(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
219
220 String name="",desc="";
221 if(criteria == null){
222 throw new MissingParameterException("SearchCriteria is null");
223 }
224 AndPredicate predicate = (AndPredicate)criteria.getPredicate();
225 Set<Predicate> predicates = predicate.getPredicates();
226 for(Predicate simplePredicate:predicates){
227 if(((LikePredicate)simplePredicate).getPropertyPath().equalsIgnoreCase("name")){
228 name = ((LikePredicate)simplePredicate).getValue().getValue().toString();
229 } else{
230 desc = ((LikePredicate)simplePredicate).getValue().getValue().toString();
231 }
232 }
233 List<PopulationInfo> populationInfos = new ArrayList<PopulationInfo>();
234 for(String key:populations.keySet()){
235 if(key != null){
236 PopulationInfo populationInfo = populations.get(key);
237 if(populationInfo.getName().toLowerCase().indexOf(name.toLowerCase())>=0 && populationInfo.getDescr().getPlain().toLowerCase().indexOf(desc.toLowerCase())>=0){
238 populationInfos.add(populationInfo);
239 }
240 }
241 }
242 return populationInfos;
243 }
244
245 @Override
246 public List<ValidationResultInfo> validatePopulation(@WebParam(name = "validationTypeId") String validationTypeId, @WebParam(name = "populationInfo") PopulationInfo populationInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
247 throw new OperationFailedException("Method not implemented.");
248 }
249
250 @Override
251 public PopulationInfo createPopulation(@WebParam(name = "populationInfo") PopulationInfo populationInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
252 populations.put(populationInfo.getId(), populationInfo);
253 caches.put(populationInfo.getId(), new HashSet<String>());
254 return populationInfo;
255 }
256
257 @Override
258 public PopulationInfo updatePopulation(@WebParam(name = "populationId") String populationId, @WebParam(name = "populationInfo") PopulationInfo populationInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
259 throw new OperationFailedException("Method not implemented.");
260 }
261
262 @Override
263 public StatusInfo deletePopulation(@WebParam(name = "populationId") String populationId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
264 if (null == populationId || 0 == populationId.length()) {
265 throw new MissingParameterException("populationId");
266 }
267
268 PopulationInfo population = populations.get(populationId);
269 if (null == population) {
270 throw new DoesNotExistException("populationId '" + populationId + "' not found");
271 }
272 populations.remove(populationId);
273 caches.remove(populationId);
274 return new StatusInfo();
275 }
276
277 @Override
278 public PopulationRuleInfo getPopulationRule(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
279 throw new OperationFailedException("Method not implemented.");
280 }
281
282 @Override
283 public List<PopulationRuleInfo> getPopulationRulesByIds(@WebParam(name = "populationRuleIds") List<String> populationRuleIds, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
284 throw new OperationFailedException("Method not implemented.");
285 }
286
287 @Override
288 public List<String> getPopulationRuleIdsByType(@WebParam(name = "populationTypeKey") String populationTypeKey, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
289 throw new OperationFailedException("Method not implemented.");
290 }
291
292 @Override
293 public PopulationRuleInfo getPopulationRuleForPopulation(@WebParam(name = "populationid") String populationKey, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
294 throw new OperationFailedException("Method not implemented.");
295 }
296
297 @Override
298 public List<String> searchForPopulationRuleIds(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
299 throw new OperationFailedException("Method not implemented.");
300 }
301
302 @Override
303 public List<PopulationRuleInfo> searchForPopulationRules(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
304 throw new OperationFailedException("Method not implemented.");
305 }
306
307 @Override
308 public List<ValidationResultInfo> validatePopulationRule(@WebParam(name = "validationTypeKey") String validationTypeKey, @WebParam(name = "populationRuleInfo") PopulationRuleInfo populationInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
309 throw new OperationFailedException("Method not implemented.");
310 }
311
312 @Override
313 public PopulationRuleInfo createPopulationRule(@WebParam(name = "populationInfo") PopulationRuleInfo populationInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
314 throw new OperationFailedException("Method not implemented.");
315 }
316
317 @Override
318 public PopulationRuleInfo updatePopulationRule(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "populationInfo") PopulationRuleInfo populationInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
319 throw new OperationFailedException("Method not implemented.");
320 }
321
322 @Override
323 public StatusInfo deletePopulationRule(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
324 throw new OperationFailedException("Method not implemented.");
325 }
326
327 @Override
328 public StatusInfo applyPopulationRuleToPopulation(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "populationId") String populationId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
329 throw new OperationFailedException("Method not implemented.");
330 }
331
332 @Override
333 public StatusInfo removePopulationRuleFromPopulation(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "populationId") String populationId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
334 throw new OperationFailedException("Method not implemented.");
335 }
336
337 @Override
338 public PopulationCategoryInfo getPopulationCategory(String populationCategoryId, ContextInfo contextInfo)
339 throws DoesNotExistException
340 ,InvalidParameterException
341 ,MissingParameterException
342 ,OperationFailedException
343 ,PermissionDeniedException
344 {
345 throw new OperationFailedException("Method not implemented.");
346 }
347
348 @Override
349 public List<PopulationCategoryInfo> getPopulationCategoriesByIds(List<String> populationCategoryIds, ContextInfo contextInfo)
350 throws DoesNotExistException
351 ,InvalidParameterException
352 ,MissingParameterException
353 ,OperationFailedException
354 ,PermissionDeniedException
355 {
356 throw new OperationFailedException("Method not implemented.");
357 }
358
359 @Override
360 public List<String> getPopulationCategoryIdsByType(String populationTypeKey, ContextInfo contextInfo)
361 throws InvalidParameterException
362 ,MissingParameterException
363 ,OperationFailedException
364 ,PermissionDeniedException
365 {
366 throw new OperationFailedException("Method not implemented.");
367 }
368
369 @Override
370 public List<PopulationCategoryInfo> getPopulationCategoriesForPopulation(String populationId, ContextInfo contextInfo)
371 throws InvalidParameterException
372 ,MissingParameterException
373 ,OperationFailedException
374 ,PermissionDeniedException
375 {
376 throw new OperationFailedException("Method not implemented.");
377 }
378
379 @Override
380 public List<String> searchForPopulationCategoryIds(QueryByCriteria criteria, ContextInfo contextInfo)
381 throws InvalidParameterException
382 ,MissingParameterException
383 ,OperationFailedException
384 ,PermissionDeniedException
385 {
386 throw new OperationFailedException("Method not implemented.");
387 }
388
389 @Override
390 public List<PopulationCategoryInfo> searchForPopulationCategories(QueryByCriteria criteria, ContextInfo contextInfo)
391 throws InvalidParameterException
392 ,MissingParameterException
393 ,OperationFailedException
394 ,PermissionDeniedException
395 {
396 throw new OperationFailedException("Method not implemented.");
397 }
398
399 @Override
400 public List<ValidationResultInfo> validatePopulationCategory(String validationTypeKey, String populationCategoryTypeKey, PopulationCategoryInfo populationCategoryInfo, ContextInfo contextInfo)
401 throws DoesNotExistException
402 ,InvalidParameterException
403 ,MissingParameterException
404 ,OperationFailedException
405 ,PermissionDeniedException
406 {
407 throw new OperationFailedException("Method not implemented.");
408 }
409
410 @Override
411 public PopulationCategoryInfo createPopulationCategory(String populationCategoryTypeKey, PopulationCategoryInfo populationCategoryInfo, ContextInfo contextInfo)
412 throws DataValidationErrorException
413 ,InvalidParameterException
414 ,MissingParameterException
415 ,OperationFailedException
416 ,PermissionDeniedException
417 ,ReadOnlyException
418 {
419 throw new OperationFailedException("Method not implemented.");
420 }
421
422 @Override
423 public PopulationCategoryInfo updatePopulationCategory(String populationCategoryId, PopulationCategoryInfo populationInfo, ContextInfo contextInfo)
424 throws DataValidationErrorException
425 ,DoesNotExistException
426 ,InvalidParameterException
427 ,MissingParameterException
428 ,OperationFailedException
429 ,PermissionDeniedException
430 ,ReadOnlyException
431 ,VersionMismatchException
432 {
433 throw new OperationFailedException("Method not implemented.");
434 }
435
436 @Override
437 public StatusInfo deletePopulationCategory(String populationCategoryId, ContextInfo contextInfo)
438 throws DoesNotExistException
439 ,InvalidParameterException
440 ,MissingParameterException
441 ,OperationFailedException
442 ,PermissionDeniedException
443 {
444 throw new OperationFailedException("Method not implemented.");
445 }
446
447 @Override
448 public StatusInfo addPopulationToPopulationCategory(String populationId, String populationCategoryId, ContextInfo contextInfo)
449 throws AlreadyExistsException
450 ,DoesNotExistException
451 ,InvalidParameterException
452 ,MissingParameterException
453 ,OperationFailedException
454 ,PermissionDeniedException
455 {
456 throw new OperationFailedException("Method not implemented.");
457 }
458
459 @Override
460 public StatusInfo removePopulationFromPopulationCategory(String populationId, String populationCategoryId, ContextInfo contextInfo)
461 throws DoesNotExistException
462 ,InvalidParameterException
463 ,MissingParameterException
464 ,OperationFailedException
465 ,PermissionDeniedException
466 {
467 throw new OperationFailedException("Method not implemented.");
468 }
469
470 }