@Test public void testCanNotGetAccessToTeacherSchoolAssociation() throws Exception { Set<String> teacherSchoolAssociations = new HashSet<String>(); Map<String, Object> association = buildTeacherSchoolAssociation("teacher123", "school123"); Entity teacherSchoolAssociation = new MongoEntity(EntityNames.TEACHER_SCHOOL_ASSOCIATION, association); teacherSchoolAssociations.add(teacherSchoolAssociation.getEntityId()); schoolIds.add("school123"); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.TEACHER_SCHOOL_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(Arrays.asList(teacherSchoolAssociation)); Mockito.when(staffToSchoolValidator.validate(EntityNames.EDUCATION_ORGANIZATION, schoolIds)).thenReturn(Collections.EMPTY_SET); assertFalse(validator.validate(EntityNames.TEACHER_SCHOOL_ASSOCIATION, teacherSchoolAssociations).equals(teacherSchoolAssociations)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); }  }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }