@Test public void testPositiveValidate() { Set<String> idsToValidate = new HashSet<String>(Arrays.asList(assoc1Current.getEntityId(), assoc1Past.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_COHORT_ASSOCIATION, idsToValidate).containsAll(idsToValidate)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(STUDENT_ASSOCIATIONS, entityType, ids)) { return Collections.emptySet(); } Set<String> otherStudentIds = new HashSet<String>(); Set<String> toValidateIds = new HashSet<String>(ids); Entity self = SecurityUtil.getSLIPrincipal().getEntity(); List<Entity> associations = self.getEmbeddedData().get(entityType); for(Entity assoc : associations) { if (ids.contains(assoc.getEntityId())) { toValidateIds.remove(assoc.getEntityId()); } } if (toValidateIds.isEmpty()) { return ids; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, toValidateIds)); Map<String, Set<String>> studentIdsToAssoc = new HashMap<String, Set<String>>(); for(Entity association : getRepo().findAll(entityType, query)) { Map<String, Object>body = association.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, false)) { String studentId = (String) body.get(ParameterConstants.STUDENT_ID); otherStudentIds.add(studentId); if(!studentIdsToAssoc.containsKey(studentId)) { studentIdsToAssoc.put(studentId, new HashSet<String>()); } studentIdsToAssoc.get(studentId).add(association.getEntityId()); } else { return Collections.emptySet(); } } Set<String> validStudentIds = studentValidator.validate(EntityNames.STUDENT, otherStudentIds); toValidateIds.removeAll(getValidIds(validStudentIds, studentIdsToAssoc)); Set<String> validIds = new HashSet<String>(ids); validIds.removeAll(toValidateIds); return validIds; }
StudentToStudentAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(STUDENT_ASSOCIATIONS, entityType, ids)) { return Collections.emptySet(); } Set<String> otherStudentIds = new HashSet<String>(); Set<String> toValidateIds = new HashSet<String>(ids); Entity self = SecurityUtil.getSLIPrincipal().getEntity(); List<Entity> associations = self.getEmbeddedData().get(entityType); for(Entity assoc : associations) { if (ids.contains(assoc.getEntityId())) { toValidateIds.remove(assoc.getEntityId()); } } if (toValidateIds.isEmpty()) { return ids; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, toValidateIds)); Map<String, Set<String>> studentIdsToAssoc = new HashMap<String, Set<String>>(); for(Entity association : getRepo().findAll(entityType, query)) { Map<String, Object>body = association.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, false)) { String studentId = (String) body.get(ParameterConstants.STUDENT_ID); otherStudentIds.add(studentId); if(!studentIdsToAssoc.containsKey(studentId)) { studentIdsToAssoc.put(studentId, new HashSet<String>()); } studentIdsToAssoc.get(studentId).add(association.getEntityId()); } else { return Collections.emptySet(); } } Set<String> validStudentIds = studentValidator.validate(EntityNames.STUDENT, otherStudentIds); toValidateIds.removeAll(getValidIds(validStudentIds, studentIdsToAssoc)); Set<String> validIds = new HashSet<String>(ids); validIds.removeAll(toValidateIds); return validIds; } }
StudentToStudentAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(STUDENT_ASSOCIATIONS, entityType, ids)) { return Collections.emptySet(); } Set<String> otherStudentIds = new HashSet<String>(); Set<String> toValidateIds = new HashSet<String>(ids); Entity self = SecurityUtil.getSLIPrincipal().getEntity(); List<Entity> associations = self.getEmbeddedData().get(entityType); for(Entity assoc : associations) { if (ids.contains(assoc.getEntityId())) { toValidateIds.remove(assoc.getEntityId()); } } if (toValidateIds.isEmpty()) { return ids; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, toValidateIds)); Map<String, Set<String>> studentIdsToAssoc = new HashMap<String, Set<String>>(); for(Entity association : getRepo().findAll(entityType, query)) { Map<String, Object>body = association.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, false)) { String studentId = (String) body.get(ParameterConstants.STUDENT_ID); otherStudentIds.add(studentId); if(!studentIdsToAssoc.containsKey(studentId)) { studentIdsToAssoc.put(studentId, new HashSet<String>()); } studentIdsToAssoc.get(studentId).add(association.getEntityId()); } else { return Collections.emptySet(); } } Set<String> validStudentIds = studentValidator.validate(EntityNames.STUDENT, otherStudentIds); toValidateIds.removeAll(getValidIds(validStudentIds, studentIdsToAssoc)); Set<String> validIds = new HashSet<String>(ids); validIds.removeAll(toValidateIds); return validIds; }  }
StudentToStudentAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(STUDENT_ASSOCIATIONS, entityType, ids)) { return Collections.emptySet(); } Set<String> otherStudentIds = new HashSet<String>(); Set<String> toValidateIds = new HashSet<String>(ids); Entity self = SecurityUtil.getSLIPrincipal().getEntity(); List<Entity> associations = self.getEmbeddedData().get(entityType); for(Entity assoc : associations) { if (ids.contains(assoc.getEntityId())) { toValidateIds.remove(assoc.getEntityId()); } } if (toValidateIds.isEmpty()) { return ids; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, toValidateIds)); Map<String, Set<String>> studentIdsToAssoc = new HashMap<String, Set<String>>(); for(Entity association : getRepo().findAll(entityType, query)) { Map<String, Object>body = association.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, false)) { String studentId = (String) body.get(ParameterConstants.STUDENT_ID); otherStudentIds.add(studentId); if(!studentIdsToAssoc.containsKey(studentId)) { studentIdsToAssoc.put(studentId, new HashSet<String>()); } studentIdsToAssoc.get(studentId).add(association.getEntityId()); } else { return Collections.emptySet(); } } Set<String> validStudentIds = studentValidator.validate(EntityNames.STUDENT, otherStudentIds); toValidateIds.removeAll(getValidIds(validStudentIds, studentIdsToAssoc)); Set<String> validIds = new HashSet<String>(ids); validIds.removeAll(toValidateIds); return validIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); }
StudentToStudentAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(STUDENT_ASSOCIATIONS, entityType, ids)) { return Collections.emptySet(); } Set<String> otherStudentIds = new HashSet<String>(); Set<String> toValidateIds = new HashSet<String>(ids); Entity self = SecurityUtil.getSLIPrincipal().getEntity(); List<Entity> associations = self.getEmbeddedData().get(entityType); for(Entity assoc : associations) { if (ids.contains(assoc.getEntityId())) { toValidateIds.remove(assoc.getEntityId()); } } if (toValidateIds.isEmpty()) { return ids; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, toValidateIds)); Map<String, Set<String>> studentIdsToAssoc = new HashMap<String, Set<String>>(); for(Entity association : getRepo().findAll(entityType, query)) { Map<String, Object>body = association.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, false)) { String studentId = (String) body.get(ParameterConstants.STUDENT_ID); otherStudentIds.add(studentId); if(!studentIdsToAssoc.containsKey(studentId)) { studentIdsToAssoc.put(studentId, new HashSet<String>()); } studentIdsToAssoc.get(studentId).add(association.getEntityId()); } else { return Collections.emptySet(); } } Set<String> validStudentIds = studentValidator.validate(EntityNames.STUDENT, otherStudentIds); toValidateIds.removeAll(getValidIds(validStudentIds, studentIdsToAssoc)); Set<String> validIds = new HashSet<String>(ids); validIds.removeAll(toValidateIds); return validIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids);  }