@Test public void testHeterogeneousList() { vth.generateStaffEdorg(USER_ID, ED_ORG, false); Set<String> teacherIds = new HashSet<String>(Arrays.asList("Just Cause", "Armaggedon", "Awareness", "Chaos Mastery", "Life Mastery", "Death and Decay", "Node Mastery", "Artificer", "Warlord", "Conjurer")); List<String> successes = new ArrayList<String>(); for (String id : teacherIds) { if (Math.random() > 0.5) { vth.generateStaffEdorg(id, ED_ORG, false); successes.add(id); } else { vth.generateStaffEdorg(id, "Arcanus", false); } } Assert.assertFalse(val.validate(EntityNames.TEACHER, teacherIds).containsAll(teacherIds)); for (String id : teacherIds) { if (successes.contains(id)) { Assert.assertTrue(val.validate(EntityNames.TEACHER, Collections.singleton(id)).contains(id)); } else { Assert.assertFalse(val.validate(EntityNames.TEACHER, Collections.singleton(id)).contains(id)); } } }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; }  }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }