| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
package org.kuali.student.r2.core.class1.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.r2.common.dto.ContextInfo; |
| 13 | |
import org.kuali.student.r2.common.dto.RichTextInfo; |
| 14 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
| 15 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
| 16 | |
import org.kuali.student.r2.common.exceptions.*; |
| 17 | |
import org.kuali.student.r2.common.util.constants.PopulationServiceConstants; |
| 18 | |
import org.kuali.student.r2.core.population.dto.PopulationInfo; |
| 19 | |
import org.kuali.student.r2.core.population.dto.PopulationRuleInfo; |
| 20 | |
import org.kuali.student.r2.core.population.service.PopulationService; |
| 21 | |
|
| 22 | |
import javax.jws.WebParam; |
| 23 | |
import java.util.*; |
| 24 | |
|
| 25 | |
public class ProcessPocPopulationServiceMockImpl implements PopulationService { |
| 26 | |
|
| 27 | |
private static Map<String, PopulationInfo> populations; |
| 28 | |
private static Map<String, Set<String>> caches; |
| 29 | |
private List<PopulationInfo> populationInfos; |
| 30 | |
|
| 31 | 0 | public ProcessPocPopulationServiceMockImpl() { |
| 32 | 0 | initialize(); |
| 33 | 0 | } |
| 34 | |
|
| 35 | |
private void initialize() { |
| 36 | |
try { |
| 37 | 0 | populations = new HashMap<String, PopulationInfo>(); |
| 38 | 0 | caches = new HashMap<String, Set<String>>(); |
| 39 | |
|
| 40 | 0 | final String ALL_STUDENTS = PopulationServiceConstants.EVERYONE_POPULATION_KEY; |
| 41 | 0 | final String SUMMER_ONLY_STUDENTS = PopulationServiceConstants.SUMMER_ONLY_STUDENTS_POPULATION_KEY; |
| 42 | 0 | final String SENIOR_ONLY_STUDENTS = "kuali.population.senior.only.student"; |
| 43 | 0 | final String ATHLETES_ONLY_STUDENTS = "kuali.population.athletes.only.student"; |
| 44 | |
|
| 45 | 0 | PopulationInfo allStudentsPopulation = new PopulationInfo(); |
| 46 | 0 | allStudentsPopulation.setId(ALL_STUDENTS); |
| 47 | 0 | allStudentsPopulation.setName("All students"); |
| 48 | 0 | RichTextInfo allStudDesc = new RichTextInfo(); |
| 49 | 0 | allStudDesc.setPlain("All students population"); |
| 50 | 0 | allStudentsPopulation.setDescr(allStudDesc); |
| 51 | 0 | createPopulation(allStudentsPopulation, new ContextInfo()); |
| 52 | |
|
| 53 | 0 | PopulationInfo summerOnlyStudentsPopulation = new PopulationInfo(); |
| 54 | 0 | summerOnlyStudentsPopulation.setId(SUMMER_ONLY_STUDENTS); |
| 55 | 0 | summerOnlyStudentsPopulation.setName("Summer only students"); |
| 56 | 0 | RichTextInfo summerDesc = new RichTextInfo(); |
| 57 | 0 | summerDesc.setPlain("Summer only students population"); |
| 58 | 0 | summerOnlyStudentsPopulation.setDescr(summerDesc); |
| 59 | 0 | createPopulation(summerOnlyStudentsPopulation, new ContextInfo()); |
| 60 | |
|
| 61 | 0 | PopulationInfo seniorsOnlyStudentsPopulation = new PopulationInfo(); |
| 62 | 0 | seniorsOnlyStudentsPopulation.setId(SENIOR_ONLY_STUDENTS); |
| 63 | 0 | seniorsOnlyStudentsPopulation.setName("Senior students"); |
| 64 | 0 | RichTextInfo seniorsDesc = new RichTextInfo(); |
| 65 | 0 | seniorsDesc.setPlain("Senior only students"); |
| 66 | 0 | seniorsOnlyStudentsPopulation.setDescr(seniorsDesc); |
| 67 | 0 | createPopulation(seniorsOnlyStudentsPopulation, new ContextInfo()); |
| 68 | |
|
| 69 | 0 | PopulationInfo athletesOnlyStudentsPopulation = new PopulationInfo(); |
| 70 | 0 | athletesOnlyStudentsPopulation.setId(ATHLETES_ONLY_STUDENTS); |
| 71 | 0 | athletesOnlyStudentsPopulation.setName("Athletes only students"); |
| 72 | 0 | RichTextInfo athletesDesc = new RichTextInfo(); |
| 73 | 0 | athletesDesc.setPlain("Athletes students population"); |
| 74 | 0 | athletesOnlyStudentsPopulation.setDescr(athletesDesc); |
| 75 | 0 | createPopulation(athletesOnlyStudentsPopulation, new ContextInfo()); |
| 76 | |
|
| 77 | |
|
| 78 | 0 | generateStudentPopulations(SUMMER_ONLY_STUDENTS, "SUMMER_ONLY_STUDENTS", 5000); |
| 79 | 0 | generateStudentPopulations(SENIOR_ONLY_STUDENTS,"SENIOR_ONLY_STUDENTS", 5000); |
| 80 | 0 | generateStudentPopulations(ATHLETES_ONLY_STUDENTS,"ATHLETES_ONLY_STUDENTS", 550); |
| 81 | |
|
| 82 | |
|
| 83 | 0 | caches.get(SUMMER_ONLY_STUDENTS).add("2155"); |
| 84 | |
|
| 85 | 0 | caches.get(ALL_STUDENTS).add("2005"); |
| 86 | 0 | caches.get(ALL_STUDENTS).add("2016"); |
| 87 | 0 | caches.get(ALL_STUDENTS).add("2132"); |
| 88 | 0 | caches.get(ALL_STUDENTS).add("2166"); |
| 89 | 0 | caches.get(ALL_STUDENTS).add("2272"); |
| 90 | 0 | caches.get(ALL_STUDENTS).add("2374"); |
| 91 | 0 | caches.get(ALL_STUDENTS).add("2397"); |
| 92 | 0 | caches.get(ALL_STUDENTS).add("2406"); |
| 93 | |
|
| 94 | |
|
| 95 | 0 | caches.get(ALL_STUDENTS).addAll(caches.get(SUMMER_ONLY_STUDENTS)); |
| 96 | 0 | caches.get(ALL_STUDENTS).addAll(caches.get(SENIOR_ONLY_STUDENTS)); |
| 97 | 0 | caches.get(ALL_STUDENTS).addAll(caches.get(ATHLETES_ONLY_STUDENTS)); |
| 98 | |
|
| 99 | |
|
| 100 | 0 | } catch (Exception e) { |
| 101 | 0 | e.printStackTrace(); |
| 102 | 0 | } |
| 103 | 0 | } |
| 104 | |
|
| 105 | |
private void generateStudentPopulations(String populationCacheKey, String populationPrefix, int numToGenerate){ |
| 106 | 0 | int base = 100000000; |
| 107 | |
|
| 108 | 0 | for(int i = 0; i<numToGenerate; i++){ |
| 109 | 0 | caches.get(populationCacheKey).add(populationPrefix + (base + i)); |
| 110 | |
} |
| 111 | 0 | } |
| 112 | |
|
| 113 | |
@Override |
| 114 | |
public Boolean isMember(@WebParam(name = "personId") String personId, @WebParam(name = "populationId") String populationId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 115 | 0 | if (null == personId || 0 == personId.length()) { |
| 116 | 0 | throw new MissingParameterException("personId"); |
| 117 | |
} |
| 118 | 0 | if (null == populationId || 0 == populationId.length()) { |
| 119 | 0 | throw new MissingParameterException("populationId"); |
| 120 | |
} |
| 121 | |
|
| 122 | 0 | Set<String> cache = caches.get(populationId); |
| 123 | 0 | if (null == cache) { |
| 124 | 0 | throw new DoesNotExistException("populationId '" + populationId + "' not found"); |
| 125 | |
} |
| 126 | 0 | return cache.contains(personId); |
| 127 | |
} |
| 128 | |
|
| 129 | |
@Override |
| 130 | |
public List<String> getMembers(@WebParam(name = "populationId") String populationId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 131 | 0 | if (null == populationId || 0 == populationId.length()) { |
| 132 | 0 | throw new MissingParameterException("populationId"); |
| 133 | |
} |
| 134 | |
|
| 135 | 0 | Set<String> cache = caches.get(populationId); |
| 136 | 0 | if (null == cache) { |
| 137 | 0 | throw new DoesNotExistException("populationId '" + populationId + "' not found"); |
| 138 | |
} |
| 139 | 0 | return new ArrayList<String>(cache); |
| 140 | |
} |
| 141 | |
|
| 142 | |
@Override |
| 143 | |
public PopulationInfo getPopulation(@WebParam(name = "populationId") String populationId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 144 | 0 | if (null == populationId || 0 == populationId.length()) { |
| 145 | 0 | throw new MissingParameterException("populationId"); |
| 146 | |
} |
| 147 | |
|
| 148 | 0 | PopulationInfo population = populations.get(populationId); |
| 149 | 0 | if (null == population) { |
| 150 | 0 | throw new DoesNotExistException("populationId '" + populationId + "' not found"); |
| 151 | |
} |
| 152 | 0 | return population; |
| 153 | |
} |
| 154 | |
|
| 155 | |
@Override |
| 156 | |
public List<PopulationInfo> getPopulationsByIds(@WebParam(name = "populationIds") List<String> populationIds, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 157 | 0 | if (0 == populationIds.size()) { |
| 158 | 0 | throw new MissingParameterException("populationIds"); |
| 159 | |
} |
| 160 | |
|
| 161 | 0 | List<PopulationInfo> result = new ArrayList<PopulationInfo>(); |
| 162 | 0 | for (String populationId : populationIds) { |
| 163 | 0 | PopulationInfo population = populations.get(populationId); |
| 164 | 0 | if (null == population) { |
| 165 | 0 | throw new DoesNotExistException("populationId '" + populationId + "' not found"); |
| 166 | |
} |
| 167 | 0 | result.add(population); |
| 168 | 0 | } |
| 169 | 0 | return result; |
| 170 | |
} |
| 171 | |
|
| 172 | |
@Override |
| 173 | |
public List<String> getPopulationKeysByType(@WebParam(name = "populationTypeId") String populationTypeId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 174 | 0 | throw new OperationFailedException("Method not implemented."); |
| 175 | |
} |
| 176 | |
|
| 177 | |
@Override |
| 178 | |
public List<PopulationInfo> getPopulationsForPopulationRule(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 179 | 0 | throw new OperationFailedException("Method not implemented."); |
| 180 | |
} |
| 181 | |
|
| 182 | |
@Override |
| 183 | |
public List<String> searchForPopulationKeys(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 184 | 0 | throw new OperationFailedException("Method not implemented."); |
| 185 | |
} |
| 186 | |
|
| 187 | |
@Override |
| 188 | |
public List<PopulationInfo> searchForPopulations(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 189 | |
|
| 190 | 0 | String name="",desc=""; |
| 191 | 0 | if(criteria == null){ |
| 192 | 0 | throw new MissingParameterException("SearchCriteria is null"); |
| 193 | |
} |
| 194 | 0 | AndPredicate predicate = (AndPredicate)criteria.getPredicate(); |
| 195 | 0 | Set<Predicate> predicates = predicate.getPredicates(); |
| 196 | 0 | for(Predicate simplePredicate:predicates){ |
| 197 | 0 | if(((LikePredicate)simplePredicate).getPropertyPath().equalsIgnoreCase("name")){ |
| 198 | 0 | name = ((LikePredicate)simplePredicate).getValue().getValue().toString(); |
| 199 | |
} else{ |
| 200 | 0 | desc = ((LikePredicate)simplePredicate).getValue().getValue().toString(); |
| 201 | |
} |
| 202 | |
} |
| 203 | 0 | List<PopulationInfo> populationInfos = new ArrayList<PopulationInfo>(); |
| 204 | 0 | for(String key:populations.keySet()){ |
| 205 | 0 | if(key != null){ |
| 206 | 0 | PopulationInfo populationInfo = populations.get(key); |
| 207 | 0 | if(populationInfo.getName().toLowerCase().indexOf(name.toLowerCase())>=0 && populationInfo.getDescr().getPlain().toLowerCase().indexOf(desc.toLowerCase())>=0){ |
| 208 | 0 | populationInfos.add(populationInfo); |
| 209 | |
} |
| 210 | 0 | } |
| 211 | |
} |
| 212 | 0 | return populationInfos; |
| 213 | |
} |
| 214 | |
|
| 215 | |
@Override |
| 216 | |
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 { |
| 217 | 0 | throw new OperationFailedException("Method not implemented."); |
| 218 | |
} |
| 219 | |
|
| 220 | |
@Override |
| 221 | |
public PopulationInfo createPopulation(@WebParam(name = "populationInfo") PopulationInfo populationInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
| 222 | 0 | populations.put(populationInfo.getId(), populationInfo); |
| 223 | 0 | caches.put(populationInfo.getId(), new HashSet<String>()); |
| 224 | 0 | return populationInfo; |
| 225 | |
} |
| 226 | |
|
| 227 | |
@Override |
| 228 | |
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 { |
| 229 | 0 | throw new OperationFailedException("Method not implemented."); |
| 230 | |
} |
| 231 | |
|
| 232 | |
@Override |
| 233 | |
public StatusInfo deletePopulation(@WebParam(name = "populationId") String populationId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 234 | 0 | if (null == populationId || 0 == populationId.length()) { |
| 235 | 0 | throw new MissingParameterException("populationId"); |
| 236 | |
} |
| 237 | |
|
| 238 | 0 | PopulationInfo population = populations.get(populationId); |
| 239 | 0 | if (null == population) { |
| 240 | 0 | throw new DoesNotExistException("populationId '" + populationId + "' not found"); |
| 241 | |
} |
| 242 | 0 | populations.remove(populationId); |
| 243 | 0 | caches.remove(populationId); |
| 244 | 0 | return new StatusInfo(); |
| 245 | |
} |
| 246 | |
|
| 247 | |
@Override |
| 248 | |
public PopulationRuleInfo getPopulationRule(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 249 | 0 | throw new OperationFailedException("Method not implemented."); |
| 250 | |
} |
| 251 | |
|
| 252 | |
@Override |
| 253 | |
public List<PopulationRuleInfo> getPopulationRulesByIds(@WebParam(name = "populationRuleIds") List<String> populationRuleIds, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 254 | 0 | throw new OperationFailedException("Method not implemented."); |
| 255 | |
} |
| 256 | |
|
| 257 | |
@Override |
| 258 | |
public List<String> getPopulationRuleIdsByType(@WebParam(name = "populationTypeKey") String populationTypeKey, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 259 | 0 | throw new OperationFailedException("Method not implemented."); |
| 260 | |
} |
| 261 | |
|
| 262 | |
@Override |
| 263 | |
public PopulationRuleInfo getPopulationRuleForPopulation(@WebParam(name = "populationid") String populationKey, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 264 | 0 | throw new OperationFailedException("Method not implemented."); |
| 265 | |
} |
| 266 | |
|
| 267 | |
@Override |
| 268 | |
public List<String> searchForPopulationRuleIds(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 269 | 0 | throw new OperationFailedException("Method not implemented."); |
| 270 | |
} |
| 271 | |
|
| 272 | |
@Override |
| 273 | |
public List<PopulationRuleInfo> searchForPopulationRules(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 274 | 0 | throw new OperationFailedException("Method not implemented."); |
| 275 | |
} |
| 276 | |
|
| 277 | |
@Override |
| 278 | |
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 { |
| 279 | 0 | throw new OperationFailedException("Method not implemented."); |
| 280 | |
} |
| 281 | |
|
| 282 | |
@Override |
| 283 | |
public PopulationRuleInfo createPopulationRule(@WebParam(name = "populationInfo") PopulationRuleInfo populationInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
| 284 | 0 | throw new OperationFailedException("Method not implemented."); |
| 285 | |
} |
| 286 | |
|
| 287 | |
@Override |
| 288 | |
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 { |
| 289 | 0 | throw new OperationFailedException("Method not implemented."); |
| 290 | |
} |
| 291 | |
|
| 292 | |
@Override |
| 293 | |
public StatusInfo deletePopulationRule(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 294 | 0 | throw new OperationFailedException("Method not implemented."); |
| 295 | |
} |
| 296 | |
|
| 297 | |
@Override |
| 298 | |
public StatusInfo applyPopulationRuleToPopulation(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "populationId") String populationId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 299 | 0 | throw new OperationFailedException("Method not implemented."); |
| 300 | |
} |
| 301 | |
|
| 302 | |
@Override |
| 303 | |
public StatusInfo removePopulationRuleFromPopulation(@WebParam(name = "populationRuleId") String populationRuleId, @WebParam(name = "populationId") String populationId, @WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 304 | 0 | throw new OperationFailedException("Method not implemented."); |
| 305 | |
} |
| 306 | |
|
| 307 | |
|
| 308 | |
} |