@Test public void testInvalidIncident() { Set<String> ids = list(disciplineIncident3.getEntityId()); assertFalse(validator.validate(EntityNames.DISCIPLINE_INCIDENT, ids).equals(ids)); ids = list(disciplineIncident3.getEntityId(), disciplineIncident1.getEntityId()); assertFalse(validator.validate(EntityNames.DISCIPLINE_INCIDENT, ids).equals(ids)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.DISCIPLINE_INCIDENT, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> discIncidentIds = new HashSet<String>(ids); String myself = SecurityUtil.getSLIPrincipal().getEntity().getEntityId(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, discIncidentIds)); query.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, myself)); Iterable<Entity> incidents = getRepo().findAll(EntityNames.DISCIPLINE_INCIDENT, query); for (Entity ent : incidents) { discIncidentIds.remove(ent.getEntityId()); } if (discIncidentIds.size() == 0) { return ids; } query = new NeutralQuery(new NeutralCriteria(ParameterConstants.DISCIPLINE_INCIDENT_ID, NeutralCriteria.CRITERIA_IN, discIncidentIds)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_ID, ParameterConstants.DISCIPLINE_INCIDENT_ID)); Iterable<Entity> assocs = getRepo().findAll(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, query); Map<String, Set<String>> discIncToStudents = new HashMap<String, Set<String>>(); for (Entity assoc : assocs) { String studentId = (String) assoc.getBody().get(ParameterConstants.STUDENT_ID); String discIncId = (String) assoc.getBody().get(ParameterConstants.DISCIPLINE_INCIDENT_ID); Set<String> studentList = discIncToStudents.get(discIncId); if (studentList == null) { studentList = new HashSet<String>(); discIncToStudents.put(discIncId, studentList); } studentList.add(studentId); } Set<String> validIncidents = new HashSet<String>(ids); validIncidents.removeAll(discIncidentIds); for (String discIncId : discIncToStudents.keySet()) { Set<String> validStudent = studentValidator.validate(EntityNames.STUDENT, discIncToStudents.get(discIncId)); if (validStudent.size() > 0) { validIncidents.add(discIncId); } } return validIncidents; }
TeacherToDisciplineIncidentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.DISCIPLINE_INCIDENT, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> discIncidentIds = new HashSet<String>(ids); String myself = SecurityUtil.getSLIPrincipal().getEntity().getEntityId(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, discIncidentIds)); query.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, myself)); Iterable<Entity> incidents = getRepo().findAll(EntityNames.DISCIPLINE_INCIDENT, query); for (Entity ent : incidents) { discIncidentIds.remove(ent.getEntityId()); } if (discIncidentIds.size() == 0) { return ids; } query = new NeutralQuery(new NeutralCriteria(ParameterConstants.DISCIPLINE_INCIDENT_ID, NeutralCriteria.CRITERIA_IN, discIncidentIds)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_ID, ParameterConstants.DISCIPLINE_INCIDENT_ID)); Iterable<Entity> assocs = getRepo().findAll(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, query); Map<String, Set<String>> discIncToStudents = new HashMap<String, Set<String>>(); for (Entity assoc : assocs) { String studentId = (String) assoc.getBody().get(ParameterConstants.STUDENT_ID); String discIncId = (String) assoc.getBody().get(ParameterConstants.DISCIPLINE_INCIDENT_ID); Set<String> studentList = discIncToStudents.get(discIncId); if (studentList == null) { studentList = new HashSet<String>(); discIncToStudents.put(discIncId, studentList); } studentList.add(studentId); } Set<String> validIncidents = new HashSet<String>(ids); validIncidents.removeAll(discIncidentIds); for (String discIncId : discIncToStudents.keySet()) { Set<String> validStudent = studentValidator.validate(EntityNames.STUDENT, discIncToStudents.get(discIncId)); if (validStudent.size() > 0) { validIncidents.add(discIncId); } } return validIncidents; } }
TeacherToDisciplineIncidentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.DISCIPLINE_INCIDENT, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> discIncidentIds = new HashSet<String>(ids); String myself = SecurityUtil.getSLIPrincipal().getEntity().getEntityId(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, discIncidentIds)); query.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, myself)); Iterable<Entity> incidents = getRepo().findAll(EntityNames.DISCIPLINE_INCIDENT, query); for (Entity ent : incidents) { discIncidentIds.remove(ent.getEntityId()); } if (discIncidentIds.size() == 0) { return ids; } query = new NeutralQuery(new NeutralCriteria(ParameterConstants.DISCIPLINE_INCIDENT_ID, NeutralCriteria.CRITERIA_IN, discIncidentIds)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_ID, ParameterConstants.DISCIPLINE_INCIDENT_ID)); Iterable<Entity> assocs = getRepo().findAll(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, query); Map<String, Set<String>> discIncToStudents = new HashMap<String, Set<String>>(); for (Entity assoc : assocs) { String studentId = (String) assoc.getBody().get(ParameterConstants.STUDENT_ID); String discIncId = (String) assoc.getBody().get(ParameterConstants.DISCIPLINE_INCIDENT_ID); Set<String> studentList = discIncToStudents.get(discIncId); if (studentList == null) { studentList = new HashSet<String>(); discIncToStudents.put(discIncId, studentList); } studentList.add(studentId); } Set<String> validIncidents = new HashSet<String>(ids); validIncidents.removeAll(discIncidentIds); for (String discIncId : discIncToStudents.keySet()) { Set<String> validStudent = studentValidator.validate(EntityNames.STUDENT, discIncToStudents.get(discIncId)); if (validStudent.size() > 0) { validIncidents.add(discIncId); } } return validIncidents; }  }
TeacherToDisciplineIncidentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.DISCIPLINE_INCIDENT, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> discIncidentIds = new HashSet<String>(ids); String myself = SecurityUtil.getSLIPrincipal().getEntity().getEntityId(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, discIncidentIds)); query.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, myself)); Iterable<Entity> incidents = getRepo().findAll(EntityNames.DISCIPLINE_INCIDENT, query); for (Entity ent : incidents) { discIncidentIds.remove(ent.getEntityId()); } if (discIncidentIds.size() == 0) { return ids; } query = new NeutralQuery(new NeutralCriteria(ParameterConstants.DISCIPLINE_INCIDENT_ID, NeutralCriteria.CRITERIA_IN, discIncidentIds)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_ID, ParameterConstants.DISCIPLINE_INCIDENT_ID)); Iterable<Entity> assocs = getRepo().findAll(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, query); Map<String, Set<String>> discIncToStudents = new HashMap<String, Set<String>>(); for (Entity assoc : assocs) { String studentId = (String) assoc.getBody().get(ParameterConstants.STUDENT_ID); String discIncId = (String) assoc.getBody().get(ParameterConstants.DISCIPLINE_INCIDENT_ID); Set<String> studentList = discIncToStudents.get(discIncId); if (studentList == null) { studentList = new HashSet<String>(); discIncToStudents.put(discIncId, studentList); } studentList.add(studentId); } Set<String> validIncidents = new HashSet<String>(ids); validIncidents.removeAll(discIncidentIds); for (String discIncId : discIncToStudents.keySet()) { Set<String> validStudent = studentValidator.validate(EntityNames.STUDENT, discIncToStudents.get(discIncId)); if (validStudent.size() > 0) { validIncidents.add(discIncId); } } return validIncidents; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToDisciplineIncidentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.DISCIPLINE_INCIDENT, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> discIncidentIds = new HashSet<String>(ids); String myself = SecurityUtil.getSLIPrincipal().getEntity().getEntityId(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, discIncidentIds)); query.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, myself)); Iterable<Entity> incidents = getRepo().findAll(EntityNames.DISCIPLINE_INCIDENT, query); for (Entity ent : incidents) { discIncidentIds.remove(ent.getEntityId()); } if (discIncidentIds.size() == 0) { return ids; } query = new NeutralQuery(new NeutralCriteria(ParameterConstants.DISCIPLINE_INCIDENT_ID, NeutralCriteria.CRITERIA_IN, discIncidentIds)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_ID, ParameterConstants.DISCIPLINE_INCIDENT_ID)); Iterable<Entity> assocs = getRepo().findAll(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, query); Map<String, Set<String>> discIncToStudents = new HashMap<String, Set<String>>(); for (Entity assoc : assocs) { String studentId = (String) assoc.getBody().get(ParameterConstants.STUDENT_ID); String discIncId = (String) assoc.getBody().get(ParameterConstants.DISCIPLINE_INCIDENT_ID); Set<String> studentList = discIncToStudents.get(discIncId); if (studentList == null) { studentList = new HashSet<String>(); discIncToStudents.put(discIncId, studentList); } studentList.add(studentId); } Set<String> validIncidents = new HashSet<String>(ids); validIncidents.removeAll(discIncidentIds); for (String discIncId : discIncToStudents.keySet()) { Set<String> validStudent = studentValidator.validate(EntityNames.STUDENT, discIncToStudents.get(discIncId)); if (validStudent.size() > 0) { validIncidents.add(discIncId); } } return validIncidents; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }