@Test public void testPositiveValidate() { Set<String> idsToValidate = new HashSet<String>(Arrays.asList(assoc1Current.getEntityId(), assoc1Past.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, idsToValidate).containsAll(idsToValidate)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_SECTION_ASSOCIATION, entityType, ids)) { return Collections.emptySet(); } Set<String> otherStudentIds = new HashSet<String>(); Map<String, Set<String>> studentIdToSSA = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); for(Entity ssa : getRepo().findAll(EntityNames.STUDENT_SECTION_ASSOCIATION, query)) { Map<String, Object> body = ssa.getBody(); if (getDirectStudentIds().contains(body.get(ParameterConstants.STUDENT_ID))) { continue; } if (!isFieldExpired(body, ParameterConstants.END_DATE, false)) { String studentId = (String) ssa.getBody().get(ParameterConstants.STUDENT_ID); otherStudentIds.add(studentId); if(!studentIdToSSA.containsKey(studentId)) { studentIdToSSA.put(studentId, new HashSet<String>()); } studentIdToSSA.get(studentId).add(ssa.getEntityId()); } else { return Collections.emptySet(); } } Set<String> result; if(otherStudentIds.isEmpty()) { result = ids; } else { result = getValidIds(studentValidator.validate(EntityNames.STUDENT, otherStudentIds), studentIdToSSA); } return result; }
TransitiveStudentToStudentSectionAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_SECTION_ASSOCIATION, entityType, ids)) { return Collections.emptySet(); } Set<String> otherStudentIds = new HashSet<String>(); Map<String, Set<String>> studentIdToSSA = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); for(Entity ssa : getRepo().findAll(EntityNames.STUDENT_SECTION_ASSOCIATION, query)) { Map<String, Object> body = ssa.getBody(); if (getDirectStudentIds().contains(body.get(ParameterConstants.STUDENT_ID))) { continue; } if (!isFieldExpired(body, ParameterConstants.END_DATE, false)) { String studentId = (String) ssa.getBody().get(ParameterConstants.STUDENT_ID); otherStudentIds.add(studentId); if(!studentIdToSSA.containsKey(studentId)) { studentIdToSSA.put(studentId, new HashSet<String>()); } studentIdToSSA.get(studentId).add(ssa.getEntityId()); } else { return Collections.emptySet(); } } Set<String> result; if(otherStudentIds.isEmpty()) { result = ids; } else { result = getValidIds(studentValidator.validate(EntityNames.STUDENT, otherStudentIds), studentIdToSSA); } return result; } }
TransitiveStudentToStudentSectionAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_SECTION_ASSOCIATION, entityType, ids)) { return Collections.emptySet(); } Set<String> otherStudentIds = new HashSet<String>(); Map<String, Set<String>> studentIdToSSA = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); for(Entity ssa : getRepo().findAll(EntityNames.STUDENT_SECTION_ASSOCIATION, query)) { Map<String, Object> body = ssa.getBody(); if (getDirectStudentIds().contains(body.get(ParameterConstants.STUDENT_ID))) { continue; } if (!isFieldExpired(body, ParameterConstants.END_DATE, false)) { String studentId = (String) ssa.getBody().get(ParameterConstants.STUDENT_ID); otherStudentIds.add(studentId); if(!studentIdToSSA.containsKey(studentId)) { studentIdToSSA.put(studentId, new HashSet<String>()); } studentIdToSSA.get(studentId).add(ssa.getEntityId()); } else { return Collections.emptySet(); } } Set<String> result; if(otherStudentIds.isEmpty()) { result = ids; } else { result = getValidIds(studentValidator.validate(EntityNames.STUDENT, otherStudentIds), studentIdToSSA); } return result; }  }
TransitiveStudentToStudentSectionAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_SECTION_ASSOCIATION, entityType, ids)) { return Collections.emptySet(); } Set<String> otherStudentIds = new HashSet<String>(); Map<String, Set<String>> studentIdToSSA = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); for(Entity ssa : getRepo().findAll(EntityNames.STUDENT_SECTION_ASSOCIATION, query)) { Map<String, Object> body = ssa.getBody(); if (getDirectStudentIds().contains(body.get(ParameterConstants.STUDENT_ID))) { continue; } if (!isFieldExpired(body, ParameterConstants.END_DATE, false)) { String studentId = (String) ssa.getBody().get(ParameterConstants.STUDENT_ID); otherStudentIds.add(studentId); if(!studentIdToSSA.containsKey(studentId)) { studentIdToSSA.put(studentId, new HashSet<String>()); } studentIdToSSA.get(studentId).add(ssa.getEntityId()); } else { return Collections.emptySet(); } } Set<String> result; if(otherStudentIds.isEmpty()) { result = ids; } else { result = getValidIds(studentValidator.validate(EntityNames.STUDENT, otherStudentIds), studentIdToSSA); } return result; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); }
TransitiveStudentToStudentSectionAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_SECTION_ASSOCIATION, entityType, ids)) { return Collections.emptySet(); } Set<String> otherStudentIds = new HashSet<String>(); Map<String, Set<String>> studentIdToSSA = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); for(Entity ssa : getRepo().findAll(EntityNames.STUDENT_SECTION_ASSOCIATION, query)) { Map<String, Object> body = ssa.getBody(); if (getDirectStudentIds().contains(body.get(ParameterConstants.STUDENT_ID))) { continue; } if (!isFieldExpired(body, ParameterConstants.END_DATE, false)) { String studentId = (String) ssa.getBody().get(ParameterConstants.STUDENT_ID); otherStudentIds.add(studentId); if(!studentIdToSSA.containsKey(studentId)) { studentIdToSSA.put(studentId, new HashSet<String>()); } studentIdToSSA.get(studentId).add(ssa.getEntityId()); } else { return Collections.emptySet(); } } Set<String> result; if(otherStudentIds.isEmpty()) { result = ids; } else { result = getValidIds(studentValidator.validate(EntityNames.STUDENT, otherStudentIds), studentIdToSSA); } return result; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids);  }