@Test public void testHeterogeneousList() { List<String> descs = Arrays.asList("Just Cause", "Armageddon", "Awareness", "Chaos Mastery", "Life Mastery", "Death and Decay", "Node Mastery", "Artificer", "Warlord", "Conjurer"); Set<String> cohortIds = new HashSet<String>(); List<String> successes = new ArrayList<String>(); cohortIds.add(this.generateCohort(USER_ID, "Artifacts Home World")); String idPerm = this.generateCohortAndAssociate(USER_ID, "Large Home World"); cohortIds.add(idPerm); successes.add(idPerm); for (String desc : descs) { if(Math.random()>0.5) { cohortIds.add(this.generateCohort(USER_ID, desc)); } else { String id = this.generateCohortAndAssociate(USER_ID, desc); cohortIds.add(id); successes.add(id); } } Assert.assertFalse(val.validate(EntityNames.COHORT, cohortIds).containsAll(cohortIds)); for (String id : cohortIds) { if(successes.contains(id)) { Assert.assertEquals(val.validate(EntityNames.COHORT, Collections.singleton(id)).size(), 1); } else { Assert.assertFalse(!val.validate(EntityNames.COHORT, Collections.singleton(id)).isEmpty()); } } }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> validIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return validIds; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); for (Entity entity : entities) { validIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } validIds.retainAll(ids); return validIds; }
TeacherToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> validIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return validIds; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); for (Entity entity : entities) { validIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } validIds.retainAll(ids); return validIds; } }
TeacherToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> validIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return validIds; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); for (Entity entity : entities) { validIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } validIds.retainAll(ids); return validIds; }  }
TeacherToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> validIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return validIds; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); for (Entity entity : entities) { validIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } 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(); }
TeacherToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { Set<String> validIds = new HashSet<String>(); if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return validIds; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.COHORT_ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<Entity> entities = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, nq); for (Entity entity : entities) { validIds.add((String) entity.getBody().get(ParameterConstants.COHORT_ID)); } 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();  }