@Test public void testHeterogenousList() { Set<String> idsToValidate = new HashSet<String>(Arrays.asList(this.vth.generateTeacherSchool(USER_ID, SCHOOL_ID).getEntityId(), this.vth.generateTeacherSchool("Ssss'ra", "Arcanus").getEntityId(), this.vth.generateTeacherSchool("Kali", "Arcanus") .getEntityId())); Assert.assertFalse(val.validate(CORRECT_ENTITY_TYPE, idsToValidate).containsAll(idsToValidate)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> tsa = getRepo().findAll(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> teachers = new HashSet<String>(); Map<String, Set<String>> teacherToTSA = new HashMap<String, Set<String>>(); for (Entity e : tsa) { String teacherId = (String) e.getBody().get(ParameterConstants.TEACHER_ID); teachers.add(teacherId); if(!teacherToTSA.containsKey(teacherId)) { teacherToTSA.put(teacherId, new HashSet<String>()); } teacherToTSA.get(teacherId).add(e.getEntityId()); } Set<String> validTeacherIds = val.validate(EntityNames.TEACHER, teachers); return getValidIds(validTeacherIds, teacherToTSA); }
TransitiveTeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> tsa = getRepo().findAll(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> teachers = new HashSet<String>(); Map<String, Set<String>> teacherToTSA = new HashMap<String, Set<String>>(); for (Entity e : tsa) { String teacherId = (String) e.getBody().get(ParameterConstants.TEACHER_ID); teachers.add(teacherId); if(!teacherToTSA.containsKey(teacherId)) { teacherToTSA.put(teacherId, new HashSet<String>()); } teacherToTSA.get(teacherId).add(e.getEntityId()); } Set<String> validTeacherIds = val.validate(EntityNames.TEACHER, teachers); return getValidIds(validTeacherIds, teacherToTSA); } }
TransitiveTeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> tsa = getRepo().findAll(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> teachers = new HashSet<String>(); Map<String, Set<String>> teacherToTSA = new HashMap<String, Set<String>>(); for (Entity e : tsa) { String teacherId = (String) e.getBody().get(ParameterConstants.TEACHER_ID); teachers.add(teacherId); if(!teacherToTSA.containsKey(teacherId)) { teacherToTSA.put(teacherId, new HashSet<String>()); } teacherToTSA.get(teacherId).add(e.getEntityId()); } Set<String> validTeacherIds = val.validate(EntityNames.TEACHER, teachers); return getValidIds(validTeacherIds, teacherToTSA); }  }
TransitiveTeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> tsa = getRepo().findAll(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> teachers = new HashSet<String>(); Map<String, Set<String>> teacherToTSA = new HashMap<String, Set<String>>(); for (Entity e : tsa) { String teacherId = (String) e.getBody().get(ParameterConstants.TEACHER_ID); teachers.add(teacherId); if(!teacherToTSA.containsKey(teacherId)) { teacherToTSA.put(teacherId, new HashSet<String>()); } teacherToTSA.get(teacherId).add(e.getEntityId()); } Set<String> validTeacherIds = val.validate(EntityNames.TEACHER, teachers); return getValidIds(validTeacherIds, teacherToTSA); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TransitiveTeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> tsa = getRepo().findAll(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> teachers = new HashSet<String>(); Map<String, Set<String>> teacherToTSA = new HashMap<String, Set<String>>(); for (Entity e : tsa) { String teacherId = (String) e.getBody().get(ParameterConstants.TEACHER_ID); teachers.add(teacherId); if(!teacherToTSA.containsKey(teacherId)) { teacherToTSA.put(teacherId, new HashSet<String>()); } teacherToTSA.get(teacherId).add(e.getEntityId()); } Set<String> validTeacherIds = val.validate(EntityNames.TEACHER, teachers); return getValidIds(validTeacherIds, teacherToTSA); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }