@Test public void testCanValidateStaffProgramAssociation() { Entity sea = helper.generateEdorgWithParent(null); Entity lea = helper.generateEdorgWithParent(sea.getEntityId()); Entity school = helper.generateEdorgWithParent(lea.getEntityId()); helper.generateStaffEdorg(helper.STAFF_ID, lea.getEntityId(), false); Entity sca = helper.generateStaffProgram(helper.STAFF_ID, helper.generateProgram().getEntityId(), false, true); cohortIds.add(sca.getEntityId()); assertTrue(validator.validate(EntityNames.STAFF_PROGRAM_ASSOCIATION, cohortIds).equals(cohortIds)); for (int i = 0; i < 5; ++i) { sca = helper.generateStaffProgram(i + "", helper.generateProgram().getEntityId(), false, true); helper.generateStaffEdorg(i + "", school.getEntityId(), false); cohortIds.add(sca.getEntityId()); } assertTrue(validator.validate(EntityNames.STAFF_PROGRAM_ASSOCIATION, cohortIds).equals(cohortIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; }  }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }