@Test public void testCanNotValidateOutsideOfEdorg() { Entity sea = helper.generateEdorgWithParent(null); Entity lea = helper.generateEdorgWithParent(sea.getEntityId()); Entity school2 = helper.generateEdorgWithParent(null); helper.generateStaffEdorg(helper.STAFF_ID, lea.getEntityId(), false); Entity sca = helper.generateStaffCohort("MOOP", helper.generateCohort(school2.getEntityId()).getEntityId(), false, true); cohortIds.add(sca.getEntityId()); assertFalse(validator.validate(EntityNames.STAFF_COHORT_ASSOCIATION, cohortIds).equals(cohortIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffToSCA = new HashMap<String, Set<String>>(); Iterable<Entity> staffCohorts = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity staff : staffCohorts) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if(!staffToSCA.containsKey(id)) { staffToSCA.put(id, new HashSet<String>()); } staffToSCA.get(id).add(staff.getEntityId()); } Set<String> staffIds = staffValidator.validate(EntityNames.STAFF, staffToSCA.keySet()); return getValidIds(staffIds, staffToSCA); }
StaffToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffToSCA = new HashMap<String, Set<String>>(); Iterable<Entity> staffCohorts = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity staff : staffCohorts) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if(!staffToSCA.containsKey(id)) { staffToSCA.put(id, new HashSet<String>()); } staffToSCA.get(id).add(staff.getEntityId()); } Set<String> staffIds = staffValidator.validate(EntityNames.STAFF, staffToSCA.keySet()); return getValidIds(staffIds, staffToSCA); } }
StaffToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffToSCA = new HashMap<String, Set<String>>(); Iterable<Entity> staffCohorts = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity staff : staffCohorts) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if(!staffToSCA.containsKey(id)) { staffToSCA.put(id, new HashSet<String>()); } staffToSCA.get(id).add(staff.getEntityId()); } Set<String> staffIds = staffValidator.validate(EntityNames.STAFF, staffToSCA.keySet()); return getValidIds(staffIds, staffToSCA); }  }
StaffToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffToSCA = new HashMap<String, Set<String>>(); Iterable<Entity> staffCohorts = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity staff : staffCohorts) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if(!staffToSCA.containsKey(id)) { staffToSCA.put(id, new HashSet<String>()); } staffToSCA.get(id).add(staff.getEntityId()); } Set<String> staffIds = staffValidator.validate(EntityNames.STAFF, staffToSCA.keySet()); return getValidIds(staffIds, staffToSCA); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffToSCA = new HashMap<String, Set<String>>(); Iterable<Entity> staffCohorts = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity staff : staffCohorts) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if(!staffToSCA.containsKey(id)) { staffToSCA.put(id, new HashSet<String>()); } staffToSCA.get(id).add(staff.getEntityId()); } Set<String> staffIds = staffValidator.validate(EntityNames.STAFF, staffToSCA.keySet()); return getValidIds(staffIds, staffToSCA); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }