@Test public void testCanNotValidateDisciplineIncidentFromOtherSchool() { Entity school = helper.generateEdorgWithParent(null); Entity school2 = helper.generateEdorgWithParent(null); Mockito.when( mockSchoolValidator.validate(EntityNames.SCHOOL, new HashSet<String>(Arrays.asList(school2.getEntityId())))).thenReturn(Collections.EMPTY_SET); helper.generateStaffEdorg(helper.STAFF_ID, school.getEntityId(), false); Entity di = helper.generateDisciplineIncident(school2.getEntityId()); diIds.add(di.getEntityId()); assertFalse(validator.validate(EntityNames.DISCIPLINE_INCIDENT, diIds).equals(diIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.DISCIPLINE_INCIDENT, entityType, ids)) { return Collections.emptySet(); } boolean match = false; Set<String> validIds = new HashSet<String>(); for (String id : ids) { match = false; NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.DISCIPLINE_INCIDENT_ID, NeutralCriteria.OPERATOR_EQUAL, id)); Iterable<Entity> associations = getRepo().findAll(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, basicQuery); for (Entity association : associations) { Set<String> sdia = subStudentValidator.validate(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, new HashSet<String>(Arrays.asList(association.getEntityId()))); if (!sdia.isEmpty()) { match = true; } } basicQuery = new NeutralQuery( new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, id)); Entity di = getRepo().findOne(EntityNames.DISCIPLINE_INCIDENT, basicQuery); if (di == null) { continue; } basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, di.getBody().get(ParameterConstants.SCHOOL_ID))); Entity edorg = getRepo().findOne(EntityNames.EDUCATION_ORGANIZATION, basicQuery); if (edorg == null) { continue; } Set<String> schoolId = new HashSet<String>(Arrays.asList(edorg.getEntityId())); Set<String> validSchools = schoolValidator.validate(EntityNames.SCHOOL, schoolId); if (!validSchools.isEmpty()) { match = true; } if (match) { validIds.add(id); } } return validIds; }
StaffToDisciplineIncidentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.DISCIPLINE_INCIDENT, entityType, ids)) { return Collections.emptySet(); } boolean match = false; Set<String> validIds = new HashSet<String>(); for (String id : ids) { match = false; NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.DISCIPLINE_INCIDENT_ID, NeutralCriteria.OPERATOR_EQUAL, id)); Iterable<Entity> associations = getRepo().findAll(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, basicQuery); for (Entity association : associations) { Set<String> sdia = subStudentValidator.validate(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, new HashSet<String>(Arrays.asList(association.getEntityId()))); if (!sdia.isEmpty()) { match = true; } } basicQuery = new NeutralQuery( new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, id)); Entity di = getRepo().findOne(EntityNames.DISCIPLINE_INCIDENT, basicQuery); if (di == null) { continue; } basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, di.getBody().get(ParameterConstants.SCHOOL_ID))); Entity edorg = getRepo().findOne(EntityNames.EDUCATION_ORGANIZATION, basicQuery); if (edorg == null) { continue; } Set<String> schoolId = new HashSet<String>(Arrays.asList(edorg.getEntityId())); Set<String> validSchools = schoolValidator.validate(EntityNames.SCHOOL, schoolId); if (!validSchools.isEmpty()) { match = true; } if (match) { validIds.add(id); } } return validIds; } }
StaffToDisciplineIncidentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.DISCIPLINE_INCIDENT, entityType, ids)) { return Collections.emptySet(); } boolean match = false; Set<String> validIds = new HashSet<String>(); for (String id : ids) { match = false; NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.DISCIPLINE_INCIDENT_ID, NeutralCriteria.OPERATOR_EQUAL, id)); Iterable<Entity> associations = getRepo().findAll(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, basicQuery); for (Entity association : associations) { Set<String> sdia = subStudentValidator.validate(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, new HashSet<String>(Arrays.asList(association.getEntityId()))); if (!sdia.isEmpty()) { match = true; } } basicQuery = new NeutralQuery( new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, id)); Entity di = getRepo().findOne(EntityNames.DISCIPLINE_INCIDENT, basicQuery); if (di == null) { continue; } basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, di.getBody().get(ParameterConstants.SCHOOL_ID))); Entity edorg = getRepo().findOne(EntityNames.EDUCATION_ORGANIZATION, basicQuery); if (edorg == null) { continue; } Set<String> schoolId = new HashSet<String>(Arrays.asList(edorg.getEntityId())); Set<String> validSchools = schoolValidator.validate(EntityNames.SCHOOL, schoolId); if (!validSchools.isEmpty()) { match = true; } if (match) { validIds.add(id); } } return validIds; }  }
StaffToDisciplineIncidentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.DISCIPLINE_INCIDENT, entityType, ids)) { return Collections.emptySet(); } boolean match = false; Set<String> validIds = new HashSet<String>(); for (String id : ids) { match = false; NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.DISCIPLINE_INCIDENT_ID, NeutralCriteria.OPERATOR_EQUAL, id)); Iterable<Entity> associations = getRepo().findAll(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, basicQuery); for (Entity association : associations) { Set<String> sdia = subStudentValidator.validate(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, new HashSet<String>(Arrays.asList(association.getEntityId()))); if (!sdia.isEmpty()) { match = true; } } basicQuery = new NeutralQuery( new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, id)); Entity di = getRepo().findOne(EntityNames.DISCIPLINE_INCIDENT, basicQuery); if (di == null) { continue; } basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, di.getBody().get(ParameterConstants.SCHOOL_ID))); Entity edorg = getRepo().findOne(EntityNames.EDUCATION_ORGANIZATION, basicQuery); if (edorg == null) { continue; } Set<String> schoolId = new HashSet<String>(Arrays.asList(edorg.getEntityId())); Set<String> validSchools = schoolValidator.validate(EntityNames.SCHOOL, schoolId); if (!validSchools.isEmpty()) { match = true; } if (match) { validIds.add(id); } } return validIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); void setSubStudentValidator(StaffToSubStudentEntityValidator subStudentValidator); void setSchoolValidator(GenericToEdOrgValidator schoolValidator); @Override SecurityUtil.UserContext getContext(); }
StaffToDisciplineIncidentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.DISCIPLINE_INCIDENT, entityType, ids)) { return Collections.emptySet(); } boolean match = false; Set<String> validIds = new HashSet<String>(); for (String id : ids) { match = false; NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.DISCIPLINE_INCIDENT_ID, NeutralCriteria.OPERATOR_EQUAL, id)); Iterable<Entity> associations = getRepo().findAll(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, basicQuery); for (Entity association : associations) { Set<String> sdia = subStudentValidator.validate(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, new HashSet<String>(Arrays.asList(association.getEntityId()))); if (!sdia.isEmpty()) { match = true; } } basicQuery = new NeutralQuery( new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, id)); Entity di = getRepo().findOne(EntityNames.DISCIPLINE_INCIDENT, basicQuery); if (di == null) { continue; } basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, di.getBody().get(ParameterConstants.SCHOOL_ID))); Entity edorg = getRepo().findOne(EntityNames.EDUCATION_ORGANIZATION, basicQuery); if (edorg == null) { continue; } Set<String> schoolId = new HashSet<String>(Arrays.asList(edorg.getEntityId())); Set<String> validSchools = schoolValidator.validate(EntityNames.SCHOOL, schoolId); if (!validSchools.isEmpty()) { match = true; } if (match) { validIds.add(id); } } return validIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); void setSubStudentValidator(StaffToSubStudentEntityValidator subStudentValidator); void setSchoolValidator(GenericToEdOrgValidator schoolValidator); @Override SecurityUtil.UserContext getContext();  }