@Test public void testCanValidateValidCohortAssociation() { Mockito.when(mockStudentValidator.validate(Mockito.eq(EntityNames.STUDENT), Mockito.any(Set.class))) .thenReturn(new HashSet<String>(Arrays.asList("Boop"))); for (int i = 0; i < 10; ++i) { cohortIds.add(helper.generateStudentCohort("Boop", "" + i, false).getEntityId()); } assertTrue(validator.validate(EntityNames.STUDENT_COHORT_ASSOCIATION, cohortIds).equals(cohortIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(STUDENT_ASSOCIATIONS, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> associations = new HashMap<String, Set<String>>(); NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> assocs = getRepo().findAll(entityType, basicQuery); for (Entity assoc : assocs) { String studentId = (String) assoc.getBody().get(ParameterConstants.STUDENT_ID); if (!isFieldExpired(assoc.getBody(), ParameterConstants.END_DATE, true)) { if (!associations.containsKey(studentId)) { associations.put(studentId, new HashSet<String>()); } associations.get(studentId).add(assoc.getEntityId()); } } Set<String> validStudents = studentValidator.validate(EntityNames.STUDENT, associations.keySet()); return getValidIds(validStudents, associations); }
StaffToStudentCohortProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(STUDENT_ASSOCIATIONS, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> associations = new HashMap<String, Set<String>>(); NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> assocs = getRepo().findAll(entityType, basicQuery); for (Entity assoc : assocs) { String studentId = (String) assoc.getBody().get(ParameterConstants.STUDENT_ID); if (!isFieldExpired(assoc.getBody(), ParameterConstants.END_DATE, true)) { if (!associations.containsKey(studentId)) { associations.put(studentId, new HashSet<String>()); } associations.get(studentId).add(assoc.getEntityId()); } } Set<String> validStudents = studentValidator.validate(EntityNames.STUDENT, associations.keySet()); return getValidIds(validStudents, associations); } }
StaffToStudentCohortProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(STUDENT_ASSOCIATIONS, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> associations = new HashMap<String, Set<String>>(); NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> assocs = getRepo().findAll(entityType, basicQuery); for (Entity assoc : assocs) { String studentId = (String) assoc.getBody().get(ParameterConstants.STUDENT_ID); if (!isFieldExpired(assoc.getBody(), ParameterConstants.END_DATE, true)) { if (!associations.containsKey(studentId)) { associations.put(studentId, new HashSet<String>()); } associations.get(studentId).add(assoc.getEntityId()); } } Set<String> validStudents = studentValidator.validate(EntityNames.STUDENT, associations.keySet()); return getValidIds(validStudents, associations); }  }
StaffToStudentCohortProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(STUDENT_ASSOCIATIONS, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> associations = new HashMap<String, Set<String>>(); NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> assocs = getRepo().findAll(entityType, basicQuery); for (Entity assoc : assocs) { String studentId = (String) assoc.getBody().get(ParameterConstants.STUDENT_ID); if (!isFieldExpired(assoc.getBody(), ParameterConstants.END_DATE, true)) { if (!associations.containsKey(studentId)) { associations.put(studentId, new HashSet<String>()); } associations.get(studentId).add(assoc.getEntityId()); } } Set<String> validStudents = studentValidator.validate(EntityNames.STUDENT, associations.keySet()); return getValidIds(validStudents, associations); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToStudentCohortProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(STUDENT_ASSOCIATIONS, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> associations = new HashMap<String, Set<String>>(); NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> assocs = getRepo().findAll(entityType, basicQuery); for (Entity assoc : assocs) { String studentId = (String) assoc.getBody().get(ParameterConstants.STUDENT_ID); if (!isFieldExpired(assoc.getBody(), ParameterConstants.END_DATE, true)) { if (!associations.containsKey(studentId)) { associations.put(studentId, new HashSet<String>()); } associations.get(studentId).add(assoc.getEntityId()); } } Set<String> validStudents = studentValidator.validate(EntityNames.STUDENT, associations.keySet()); return getValidIds(validStudents, associations); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }