@Test public void testCanGetAccessToCurrentStudentSectionAssociation() throws Exception { Map<String, Object> goodStudentSectionAssociation = buildStudentSectionAssociation("student123", "section123", new DateTime().plusDays(1)); Entity association = new MongoEntity(EntityNames.STUDENT_SECTION_ASSOCIATION, goodStudentSectionAssociation); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.STUDENT_SECTION_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(Arrays.asList(association)); Set<String> associations = new HashSet<String>(); associations.add(association.getEntityId()); studentIds.add("student123"); Mockito.when(staffToStudentValidator.validate(EntityNames.STUDENT, studentIds)).thenReturn(studentIds); assertTrue(validator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, associations).equals(associations)); }
@SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(entityType, query); if (entities != null) { for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); Object studentInfo = body.get(ParameterConstants.STUDENT_ID); if (studentInfo instanceof Collection) { students = putStudents((Collection<String>) studentInfo, entity.getEntityId(), students); } else if (studentInfo instanceof String) { students = putStudents(Arrays.asList((String) studentInfo), entity.getEntityId(), students); } } } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }
StaffToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(entityType, query); if (entities != null) { for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); Object studentInfo = body.get(ParameterConstants.STUDENT_ID); if (studentInfo instanceof Collection) { students = putStudents((Collection<String>) studentInfo, entity.getEntityId(), students); } else if (studentInfo instanceof String) { students = putStudents(Arrays.asList((String) studentInfo), entity.getEntityId(), students); } } } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
StaffToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(entityType, query); if (entities != null) { for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); Object studentInfo = body.get(ParameterConstants.STUDENT_ID); if (studentInfo instanceof Collection) { students = putStudents((Collection<String>) studentInfo, entity.getEntityId(), students); } else if (studentInfo instanceof String) { students = putStudents(Arrays.asList((String) studentInfo), entity.getEntityId(), students); } } } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }  }
StaffToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(entityType, query); if (entities != null) { for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); Object studentInfo = body.get(ParameterConstants.STUDENT_ID); if (studentInfo instanceof Collection) { students = putStudents((Collection<String>) studentInfo, entity.getEntityId(), students); } else if (studentInfo instanceof String) { students = putStudents(Arrays.asList((String) studentInfo), entity.getEntityId(), students); } } } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }  @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(entityType, query); if (entities != null) { for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); Object studentInfo = body.get(ParameterConstants.STUDENT_ID); if (studentInfo instanceof Collection) { students = putStudents((Collection<String>) studentInfo, entity.getEntityId(), students); } else if (studentInfo instanceof String) { students = putStudents(Arrays.asList((String) studentInfo), entity.getEntityId(), students); } } } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }  @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }