@Test public void testCanNotValidateInvalidCohort() { Entity lea = helper.generateEdorgWithParent(null); Entity school = helper.generateEdorgWithParent(lea.getEntityId()); Entity school2 = helper.generateEdorgWithParent(null); helper.generateStaffEdorg(helper.STAFF_ID, school.getEntityId(), false); Entity cohort = helper.generateCohort(lea.getEntityId()); cohortIds.add(cohort.getEntityId()); assertFalse(validator.validate(EntityNames.COHORT, cohortIds).size() == cohortIds.size()); cohortIds.clear(); cohort = helper.generateCohort(school2.getEntityId()); cohortIds.add(cohort.getEntityId()); assertFalse(validator.validate(EntityNames.COHORT, cohortIds).size() == cohortIds.size()); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> myCohortIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return myCohortIds; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } else { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } basicQuery = new NeutralQuery(new NeutralCriteria("educationOrgId", NeutralCriteria.CRITERIA_IN, getStaffEdOrgLineage())); Iterable<Entity> cohorts = getRepo().findAll(EntityNames.COHORT, basicQuery); for (Entity cohort : cohorts) { myCohortIds.add(cohort.getEntityId()); } myCohortIds.retainAll(ids); return myCohortIds; }
StaffToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> myCohortIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return myCohortIds; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } else { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } basicQuery = new NeutralQuery(new NeutralCriteria("educationOrgId", NeutralCriteria.CRITERIA_IN, getStaffEdOrgLineage())); Iterable<Entity> cohorts = getRepo().findAll(EntityNames.COHORT, basicQuery); for (Entity cohort : cohorts) { myCohortIds.add(cohort.getEntityId()); } myCohortIds.retainAll(ids); return myCohortIds; } }
StaffToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> myCohortIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return myCohortIds; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } else { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } basicQuery = new NeutralQuery(new NeutralCriteria("educationOrgId", NeutralCriteria.CRITERIA_IN, getStaffEdOrgLineage())); Iterable<Entity> cohorts = getRepo().findAll(EntityNames.COHORT, basicQuery); for (Entity cohort : cohorts) { myCohortIds.add(cohort.getEntityId()); } myCohortIds.retainAll(ids); return myCohortIds; }  }
StaffToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> myCohortIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return myCohortIds; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } else { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } basicQuery = new NeutralQuery(new NeutralCriteria("educationOrgId", NeutralCriteria.CRITERIA_IN, getStaffEdOrgLineage())); Iterable<Entity> cohorts = getRepo().findAll(EntityNames.COHORT, basicQuery); for (Entity cohort : cohorts) { myCohortIds.add(cohort.getEntityId()); } myCohortIds.retainAll(ids); return myCohortIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> myCohortIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return myCohortIds; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } else { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } basicQuery = new NeutralQuery(new NeutralCriteria("educationOrgId", NeutralCriteria.CRITERIA_IN, getStaffEdOrgLineage())); Iterable<Entity> cohorts = getRepo().findAll(EntityNames.COHORT, basicQuery); for (Entity cohort : cohorts) { myCohortIds.add(cohort.getEntityId()); } myCohortIds.retainAll(ids); return myCohortIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }