target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void testCanValidate() { assertTrue(validator.canValidate(EntityNames.STUDENT_SECTION_ASSOCIATION, true)); assertFalse(validator.canValidate(EntityNames.STUDENT_SECTION_ASSOCIATION, false)); assertFalse(validator.canValidate(EntityNames.STUDENT_COHORT_ASSOCIATION, true)); assertFalse(validator.canValidate(EntityNames.STUDENT_COHORT_ASSOCIATION, false)); assertFalse(validator.canValidate(EntityNames.STUDENT_PROGRAM_ASSOCIATION, true)); assertFalse(validator.canValidate(EntityNames.STUDENT_PROGRAM_ASSOCIATION, false)); assertFalse(validator.canValidate(EntityNames.STUDENT_SCHOOL_ASSOCIATION, true)); assertFalse(validator.canValidate(EntityNames.PROGRAM, false)); assertFalse(validator.canValidate(EntityNames.ASSESSMENT, true)); assertFalse(validator.canValidate(EntityNames.GRADEBOOK_ENTRY, true)); assertFalse(validator.canValidate(EntityNames.COHORT, true)); assertFalse(validator.canValidate(EntityNames.STAFF_COHORT_ASSOCIATION, false)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return isStudentOrParent() && EntityNames.STUDENT_SECTION_ASSOCIATION.equals(entityType) && isTransitive; }
TransitiveStudentToStudentSectionAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStudentOrParent() && EntityNames.STUDENT_SECTION_ASSOCIATION.equals(entityType) && isTransitive; } }
TransitiveStudentToStudentSectionAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStudentOrParent() && EntityNames.STUDENT_SECTION_ASSOCIATION.equals(entityType) && isTransitive; } }
TransitiveStudentToStudentSectionAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStudentOrParent() && EntityNames.STUDENT_SECTION_ASSOCIATION.equals(entityType) && isTransitive; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); }
TransitiveStudentToStudentSectionAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStudentOrParent() && EntityNames.STUDENT_SECTION_ASSOCIATION.equals(entityType) && isTransitive; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); }
@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); }
@Test public void testHeterogeneousValidate() { Set<String> idsToValidate = new HashSet<String>(Arrays.asList(assoc1Current.getEntityId(), assoc2.getEntityId())); assertFalse(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); }
@Test public void testCanValidate() { assertTrue(validator.canValidate(EntityNames.SECTION, false)); assertTrue(validator.canValidate(EntityNames.SECTION, true)); assertFalse(validator.canValidate(EntityNames.ATTENDANCE, false)); assertFalse(validator.canValidate(EntityNames.ATTENDANCE, true)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.SECTION.equals(entityType); }
TeacherToSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.SECTION.equals(entityType); } }
TeacherToSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.SECTION.equals(entityType); } }
TeacherToSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.SECTION.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.SECTION.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateSingleSection() { helper.generateTeacherSchool(ValidatorTestHelper.STAFF_ID, ValidatorTestHelper.ED_ORG_ID); Entity section = helper.generateSection(ValidatorTestHelper.ED_ORG_ID); helper.generateTSA(ValidatorTestHelper.STAFF_ID, section.getEntityId(), false); sectionIds.add(section.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotValidateInvalidSection() { helper.generateTeacherSchool(ValidatorTestHelper.STAFF_ID, ValidatorTestHelper.ED_ORG_ID); Entity section = helper.generateSection(ValidatorTestHelper.ED_ORG_ID); helper.generateTSA("BEEPBOOP", section.getEntityId(), false); sectionIds.add(section.getEntityId()); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); helper.generateTSA(ValidatorTestHelper.STAFF_ID, "DERPBERP", false); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateMultiple() { helper.generateTeacherSchool(ValidatorTestHelper.STAFF_ID, ValidatorTestHelper.ED_ORG_ID); for (int i = 0; i < 10; ++i) { Entity section = helper.generateSection(ValidatorTestHelper.ED_ORG_ID); helper.generateTSA(ValidatorTestHelper.STAFF_ID, section.getEntityId(), false); sectionIds.add(section.getEntityId()); } assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testValidateIntersection() { helper.generateTeacherSchool(ValidatorTestHelper.STAFF_ID, ValidatorTestHelper.ED_ORG_ID); Entity section = null; for (int i = 0; i < 10; ++i) { section = helper.generateSection(ValidatorTestHelper.ED_ORG_ID); helper.generateTSA(ValidatorTestHelper.STAFF_ID, section.getEntityId(), false); sectionIds.add(section.getEntityId()); } section = helper.generateSection(ValidatorTestHelper.ED_ORG_ID); sectionIds.add(section.getEntityId()); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); helper.generateTSA("DERPDERP", section.getEntityId(), false); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); helper.generateTSA(ValidatorTestHelper.STAFF_ID, "MERPMERP", false); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); helper.generateTSA(ValidatorTestHelper.STAFF_ID, section.getEntityId(), false); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> sectionIds = new HashSet<String>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.SECTION_ID, NeutralCriteria.CRITERIA_IN, ids)); query.addCriteria(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> associations = getRepo().findAll(EntityNames.TEACHER_SECTION_ASSOCIATION, query); if (associations != null) { for (Entity association : associations) { if (!dateHelper.isFieldExpired(association.getBody(), ParameterConstants.END_DATE)) { sectionIds.add((String) association.getBody().get(ParameterConstants.SECTION_ID)); } } } return sectionIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void shouldAddAppropriateContextForReference() throws IOException { NeutralRecordEntity entity = createSourceEntity(); DidRefConfig refConfig = createRefConfig("Simple_DID_ref_config.json"); DidEntityConfig entityConfig = createEntityConfig("Simple_DID_entity_config.json"); mockRefConfig(refConfig, ENTITY_TYPE); mockEntityConfig(entityConfig, ENTITY_TYPE); Mockito.when(schemaRepository.getSchema(ENTITY_TYPE)).thenReturn(null); Map<String, String> naturalKeys = new HashMap<String, String>(); naturalKeys.put(SRC_KEY_FIELD, SRC_KEY_VALUE); String entityType = ENTITY_TYPE; String tenantId = TENANT; NaturalKeyDescriptor ndk = new NaturalKeyDescriptor(naturalKeys, tenantId, entityType, null); Mockito.when(didGenerator.generateId(Mockito.eq(ndk))).thenReturn(DID_VALUE); AbstractMessageReport errorReport = new DummyMessageReport(); EntityConfig oldEntityConfig = Mockito.mock(EntityConfig.class); Mockito.when(entityConfigs.getEntityConfiguration(Mockito.anyString())).thenReturn(oldEntityConfig); List<RefDef> references = new ArrayList<RefDef>(); Mockito.when(oldEntityConfig.getReferences()).thenReturn(references); RefDef refDef1 = Mockito.mock(RefDef.class); Ref ref1 = Mockito.mock(Ref.class); Mockito.when(ref1.getEntityType()).thenReturn(ENTITY_TYPE); Mockito.when(refDef1.getRef()).thenReturn(ref1); references.add(refDef1); RefDef refDef2 = Mockito.mock(RefDef.class); Ref ref2 = Mockito.mock(Ref.class); Mockito.when(ref2.getEntityType()).thenReturn("wrongEntityType"); Mockito.when(refDef2.getRef()).thenReturn(ref2); references.add(refDef2); ReportStats reportStats = new SimpleReportStats(); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); Assert.assertEquals(DID_VALUE, entity.getBody().get(REF_FIELD)); Assert.assertFalse("no errors should be reported from reference resolution ", reportStats.hasErrors()); }
public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
@Test public void testCanValidate() { assertTrue(validator.canValidate(EntityNames.STAFF_PROGRAM_ASSOCIATION, false)); assertTrue(validator.canValidate(EntityNames.STAFF_PROGRAM_ASSOCIATION, true)); assertFalse(validator.canValidate(EntityNames.PROGRAM, true)); assertFalse(validator.canValidate(EntityNames.PROGRAM, false)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STAFF_PROGRAM_ASSOCIATION.equals(entityType) && isStaff(); }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STAFF_PROGRAM_ASSOCIATION.equals(entityType) && isStaff(); } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STAFF_PROGRAM_ASSOCIATION.equals(entityType) && isStaff(); } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STAFF_PROGRAM_ASSOCIATION.equals(entityType) && isStaff(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STAFF_PROGRAM_ASSOCIATION.equals(entityType) && isStaff(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateStaffProgramAssociation() { Entity sea = helper.generateEdorgWithParent(null); Entity lea = helper.generateEdorgWithParent(sea.getEntityId()); Entity school = helper.generateEdorgWithParent(lea.getEntityId()); helper.generateStaffEdorg(helper.STAFF_ID, lea.getEntityId(), false); Entity sca = helper.generateStaffProgram(helper.STAFF_ID, helper.generateProgram().getEntityId(), false, true); cohortIds.add(sca.getEntityId()); assertTrue(validator.validate(EntityNames.STAFF_PROGRAM_ASSOCIATION, cohortIds).equals(cohortIds)); for (int i = 0; i < 5; ++i) { sca = helper.generateStaffProgram(i + "", helper.generateProgram().getEntityId(), false, true); helper.generateStaffEdorg(i + "", school.getEntityId(), false); cohortIds.add(sca.getEntityId()); } assertTrue(validator.validate(EntityNames.STAFF_PROGRAM_ASSOCIATION, cohortIds).equals(cohortIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotValidateExpiredAssociation() { Entity school = helper.generateEdorgWithParent(null); helper.generateStaffEdorg(helper.STAFF_ID, school.getEntityId(), false); Entity sca = helper.generateStaffProgram(helper.STAFF_ID, helper.generateProgram() .getEntityId(), true, false); cohortIds.add(sca.getEntityId()); assertFalse(validator.validate(EntityNames.STAFF_PROGRAM_ASSOCIATION, cohortIds).equals(cohortIds)); cohortIds.clear(); cleanProgramData(); helper.generateStaffEdorg(helper.STAFF_ID, school.getEntityId(), true); sca = helper.generateStaffProgram(helper.STAFF_ID, helper.generateProgram() .getEntityId(), false, false); cohortIds.add(sca.getEntityId()); assertFalse(validator.validate(EntityNames.STAFF_PROGRAM_ASSOCIATION, cohortIds).equals(cohortIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotValidateOutsideOfEdorg() { Entity sea = helper.generateEdorgWithParent(null); Entity lea = helper.generateEdorgWithParent(sea.getEntityId()); helper.generateEdorgWithParent(lea.getEntityId()); helper.generateEdorgWithParent(null); helper.generateStaffEdorg(helper.STAFF_ID, lea.getEntityId(), false); Entity sca = helper.generateStaffProgram("MOOP", helper.generateProgram().getEntityId(), false, true); cohortIds.add(sca.getEntityId()); assertFalse(validator.validate(EntityNames.STAFF_PROGRAM_ASSOCIATION, cohortIds).equals(cohortIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotValidateAtStateLevel() { Entity sea = helper.generateEdorgWithParent(null); Entity lea = helper.generateEdorgWithParent(sea.getEntityId()); helper.generateEdorgWithParent(lea.getEntityId()); helper.generateStaffEdorg(helper.STAFF_ID, lea.getEntityId(), false); Entity sca = helper.generateStaffProgram("MOOP", helper.generateProgram().getEntityId(), false, true); cohortIds.add(sca.getEntityId()); assertFalse(validator.validate(EntityNames.STAFF_PROGRAM_ASSOCIATION, cohortIds).equals(cohortIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToStaffProgramAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_PROGRAM_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Map<String, Set<String>> staffIdsToSPA = new HashMap<String, Set<String>>(); Iterable<Entity> staffPrograms = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, basicQuery); for (Entity staff : staffPrograms) { Map<String, Object> body = staff.getBody(); if (isFieldExpired(body, ParameterConstants.END_DATE, true)) { continue; } String id = (String) body.get(ParameterConstants.STAFF_ID); if (!staffIdsToSPA.containsKey(id)) { staffIdsToSPA.put(id, new HashSet<String>()); } staffIdsToSPA.get(id).add(staff.getEntityId()); } Set<String> validStaffs = staffValidator.validate(EntityNames.STAFF, staffIdsToSPA.keySet()); Set<String> validSPA = getValidIds(validStaffs, staffIdsToSPA); return validSPA; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateStaffToTeacherSchoolAssociation() throws Exception { assertTrue(validator.canValidate(EntityNames.TEACHER_SCHOOL_ASSOCIATION, false)); assertTrue(validator.canValidate(EntityNames.TEACHER_SCHOOL_ASSOCIATION, true)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.TEACHER_SCHOOL_ASSOCIATION.equals(entityType); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.TEACHER_SCHOOL_ASSOCIATION.equals(entityType); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.TEACHER_SCHOOL_ASSOCIATION.equals(entityType); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.TEACHER_SCHOOL_ASSOCIATION.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.TEACHER_SCHOOL_ASSOCIATION.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testDeniedStaffToOtherEntities() throws Exception { assertFalse(validator.canValidate(EntityNames.STUDENT, true)); assertFalse(validator.canValidate(EntityNames.STUDENT, false)); assertFalse(validator.canValidate(EntityNames.TEACHER, true)); assertFalse(validator.canValidate(EntityNames.TEACHER, false)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.TEACHER_SCHOOL_ASSOCIATION.equals(entityType); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.TEACHER_SCHOOL_ASSOCIATION.equals(entityType); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.TEACHER_SCHOOL_ASSOCIATION.equals(entityType); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.TEACHER_SCHOOL_ASSOCIATION.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.TEACHER_SCHOOL_ASSOCIATION.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testNullTeacherSchoolAssociation() throws Exception { assertTrue(validator.validate(EntityNames.TEACHER_SCHOOL_ASSOCIATION, null).isEmpty()); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testEmptyTeacherSchoolAssociation() throws Exception { Set<String> teacherSchoolAssociations = new HashSet<String>(); assertTrue(validator.validate(EntityNames.TEACHER_SCHOOL_ASSOCIATION, teacherSchoolAssociations).isEmpty()); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanGetAccessToTeacherSchoolAssociation() throws Exception { Set<String> teacherSchoolAssociations = new HashSet<String>(); Map<String, Object> association = buildTeacherSchoolAssociation("teacher123", "school123"); Entity teacherSchoolAssociation = new MongoEntity(EntityNames.TEACHER_SCHOOL_ASSOCIATION, association); teacherSchoolAssociations.add(teacherSchoolAssociation.getEntityId()); schoolIds.add("school123"); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.TEACHER_SCHOOL_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(Arrays.asList(teacherSchoolAssociation)); Mockito.when(staffToSchoolValidator.validate(EntityNames.EDUCATION_ORGANIZATION, schoolIds)).thenReturn(schoolIds); assertTrue(validator.validate(EntityNames.TEACHER_SCHOOL_ASSOCIATION, teacherSchoolAssociations).equals(teacherSchoolAssociations)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void shouldResolveSimpleDid() throws IOException { NeutralRecordEntity entity = createSourceEntity(); DidRefConfig refConfig = createRefConfig("Simple_DID_ref_config.json"); DidEntityConfig entityConfig = createEntityConfig("Simple_DID_entity_config.json"); mockRefConfig(refConfig, ENTITY_TYPE); mockEntityConfig(entityConfig, ENTITY_TYPE); Mockito.when(schemaRepository.getSchema(ENTITY_TYPE)).thenReturn(null); Map<String, String> naturalKeys = new HashMap<String, String>(); naturalKeys.put(SRC_KEY_FIELD, SRC_KEY_VALUE); String entityType = ENTITY_TYPE; String tenantId = TENANT; NaturalKeyDescriptor ndk = new NaturalKeyDescriptor(naturalKeys, tenantId, entityType, null); Mockito.when(didGenerator.generateId(Mockito.eq(ndk))).thenReturn(DID_VALUE); AbstractMessageReport errorReport = new DummyMessageReport(); ReportStats reportStats = new SimpleReportStats(); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); Assert.assertEquals(DID_VALUE, entity.getBody().get(REF_FIELD)); Assert.assertFalse("no errors should be reported from reference resolution ", reportStats.hasErrors()); }
public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
@Test public void testCanNotGetAccessToTeacherSchoolAssociationDueToBadLookup() throws Exception { Set<String> teacherSchoolAssociations = new HashSet<String>(); Map<String, Object> association = buildTeacherSchoolAssociation("teacher123", "school123"); Entity teacherSchoolAssociation = new MongoEntity(EntityNames.TEACHER_SCHOOL_ASSOCIATION, association); teacherSchoolAssociations.add(teacherSchoolAssociation.getEntityId()); schoolIds.add("school123"); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.TEACHER_SCHOOL_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(new ArrayList<Entity>()); assertFalse(validator.validate(EntityNames.TEACHER_SCHOOL_ASSOCIATION, teacherSchoolAssociations).equals(teacherSchoolAssociations)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotGetAccessToTeacherSchoolAssociation() throws Exception { Set<String> teacherSchoolAssociations = new HashSet<String>(); Map<String, Object> association = buildTeacherSchoolAssociation("teacher123", "school123"); Entity teacherSchoolAssociation = new MongoEntity(EntityNames.TEACHER_SCHOOL_ASSOCIATION, association); teacherSchoolAssociations.add(teacherSchoolAssociation.getEntityId()); schoolIds.add("school123"); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.TEACHER_SCHOOL_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(Arrays.asList(teacherSchoolAssociation)); Mockito.when(staffToSchoolValidator.validate(EntityNames.EDUCATION_ORGANIZATION, schoolIds)).thenReturn(Collections.EMPTY_SET); assertFalse(validator.validate(EntityNames.TEACHER_SCHOOL_ASSOCIATION, teacherSchoolAssociations).equals(teacherSchoolAssociations)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> teacherSchoolAssociations = getRepo().findAll(entityType, query); Map<String, Set<String>> schools = new HashMap<String, Set<String>>(); if (teacherSchoolAssociations != null) { for (Entity teacherSchoolAssociation : teacherSchoolAssociations) { Map<String, Object> body = teacherSchoolAssociation.getBody(); String school = (String) body.get("schoolId"); if (!schools.containsKey(school)) { schools.put(school, new HashSet<String>()); } schools.get(school).add(teacherSchoolAssociation.getEntityId()); } } if (schools.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validSchools = validator.validate(EntityNames.EDUCATION_ORGANIZATION, schools.keySet()); return getValidIds(validSchools, schools); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidate() { assertTrue(validator.canValidate(EntityNames.COHORT, false)); assertFalse(validator.canValidate(EntityNames.COHORT, true)); assertFalse(validator.canValidate(EntityNames.COMPETENCY_LEVEL_DESCRIPTOR, false)); assertFalse(validator.canValidate(EntityNames.STAFF_COHORT_ASSOCIATION, true)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return !isStudentOrParent() && !isTransitive && EntityNames.COHORT.equals(entityType); }
GenericToCohortValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return !isStudentOrParent() && !isTransitive && EntityNames.COHORT.equals(entityType); } }
GenericToCohortValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return !isStudentOrParent() && !isTransitive && EntityNames.COHORT.equals(entityType); } }
GenericToCohortValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return !isStudentOrParent() && !isTransitive && EntityNames.COHORT.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
GenericToCohortValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return !isStudentOrParent() && !isTransitive && EntityNames.COHORT.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test(expected = IllegalArgumentException.class) public void testValidateWrongType() { validator.validate(EntityNames.ASSESSMENT, new HashSet<String>(Arrays.asList("Jomolungma"))); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanAccessAll() { List<String> descs = Arrays.asList("Just Cause", "Armaggedon", "Awareness"); Set<String> cohortIds = new HashSet<String>(); for (String desc : descs) { cohortIds.add(this.generateCohortAndAssociate(USER_ID, desc)); } Assert.assertEquals(validator.validate(EntityNames.COHORT, cohortIds).size(), cohortIds.size()); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCannotAccessAll() { List<String> descs = Arrays.asList("Just Cause", "Armaggedon", "Awareness"); Set<String> cohortIds = new HashSet<String>(); for (String desc : descs) { cohortIds.add(this.generateCohort(USER_ID, desc)); } Assert.assertFalse(validator.validate(EntityNames.COHORT, cohortIds).size() == cohortIds.size()); for (String id : cohortIds) { Assert.assertFalse(validator.validate(EntityNames.COHORT, Collections.singleton(id)).size() == 1); } }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testHeterogeneousList() { List<String> descs = Arrays.asList("Just Cause", "Armaggedon", "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>(); for (String desc : descs) { if (desc.endsWith("y")) { cohortIds.add(this.generateCohort(USER_ID, desc)); } else { String id = this.generateCohortAndAssociate(USER_ID, desc); cohortIds.add(id); successes.add(id); } } Assert.assertFalse(validator.validate(EntityNames.COHORT, cohortIds).size() == cohortIds.size()); for (String id : cohortIds) { if(successes.contains(id)) { Assert.assertEquals(validator.validate(EntityNames.COHORT, Collections.singleton(id)).size(), 1); } else { Assert.assertFalse(validator.validate(EntityNames.COHORT, Collections.singleton(id)).size() == 1); } } }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotValidateStudentRecordFlag() { Set<String> cohortIds = new HashSet<String>(); Entity lea = helper.generateEdorgWithParent(null); Entity school = helper.generateEdorgWithParent(lea.getEntityId()); helper.generateStaffEdorg(helper.STAFF_ID, school.getEntityId(), false); Entity cohort = helper.generateCohort(lea.getEntityId()); cohortIds.add(cohort.getEntityId()); helper.generateStaffCohort(helper.STAFF_ID, cohort.getEntityId(), false, false); assertFalse(validator.validate(EntityNames.COHORT, cohortIds).size() == cohortIds.size()); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
GenericToCohortValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COHORT, entityType, ids)) { return new HashSet<String>(); } NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { basicQuery.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } Set<String> myCohortIds = new HashSet<String>(); Iterable<Entity> scas = getRepo().findAll(EntityNames.STAFF_COHORT_ASSOCIATION, basicQuery); for (Entity sca : scas) { Map<String, Object> body = sca.getBody(); if (!isFieldExpired(body, ParameterConstants.END_DATE, true)) { myCohortIds.add((String) body.get(ParameterConstants.COHORT_ID)); } } myCohortIds.retainAll(ids); return myCohortIds; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidate() { setContext(seaStaff, Arrays.asList(SecureRoleRightAccessImpl.SEA_ADMINISTRATOR)); assertTrue(validator.canValidate(EntityNames.SECTION, true)); assertTrue(validator.canValidate(EntityNames.SECTION, false)); assertFalse(validator.canValidate(EntityNames.ATTENDANCE, true)); assertFalse(validator.canValidate(EntityNames.ATTENDANCE, false)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.SECTION.equals(entityType) && isStaff(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.SECTION.equals(entityType) && isStaff(); } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.SECTION.equals(entityType) && isStaff(); } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.SECTION.equals(entityType) && isStaff(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.SECTION.equals(entityType) && isStaff(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotValidate() { setContext(educator2, Arrays.asList(SecureRoleRightAccessImpl.EDUCATOR)); SecurityUtil.setUserContext(SecurityUtil.UserContext.TEACHER_CONTEXT); assertFalse(validator.canValidate(EntityNames.SECTION, true)); assertFalse(validator.canValidate(EntityNames.SECTION, false)); assertFalse(validator.canValidate(EntityNames.ATTENDANCE, true)); assertFalse(validator.canValidate(EntityNames.ATTENDANCE, false)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.SECTION.equals(entityType) && isStaff(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.SECTION.equals(entityType) && isStaff(); } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.SECTION.equals(entityType) && isStaff(); } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.SECTION.equals(entityType) && isStaff(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.SECTION.equals(entityType) && isStaff(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void shouldIgnoreOptionalEmptyRefs() throws IOException { NeutralRecordEntity entity = createSourceEntity(); DidRefConfig refConfig = createRefConfig("Simple_DID_ref_config.json"); DidEntityConfig entityConfig = createEntityConfig("optional_DID_entity_config.json"); mockRefConfig(refConfig, ENTITY_TYPE); mockEntityConfig(entityConfig, ENTITY_TYPE); Mockito.when(schemaRepository.getSchema(ENTITY_TYPE)).thenReturn(null); Map<String, String> naturalKeys = new HashMap<String, String>(); naturalKeys.put(SRC_KEY_FIELD, SRC_KEY_VALUE); String entityType = ENTITY_TYPE; String tenantId = TENANT; NaturalKeyDescriptor ndk = new NaturalKeyDescriptor(naturalKeys, tenantId, entityType, null); Mockito.when(didGenerator.generateId(Mockito.eq(ndk))).thenReturn(DID_VALUE); AbstractMessageReport errorReport = new DummyMessageReport(); ReportStats reportStats = new SimpleReportStats(); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); Assert.assertEquals(DID_VALUE, entity.getBody().get(REF_FIELD)); Assert.assertFalse("no errors should be reported from reference resolution ", reportStats.hasErrors()); }
public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
@Test public void testSeaAdministratorCanSeeSectionAtSchool() { setContext(seaStaff, Arrays.asList(SecureRoleRightAccessImpl.SEA_ADMINISTRATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); sectionIds.add(section2.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testLeaAdministratorCanSeeSectionAtSchool() { setContext(lea1Staff, Arrays.asList(SecureRoleRightAccessImpl.LEA_ADMINISTRATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testLeaAdministratorCanNotSeeSectionAtSchool() { setContext(lea2Staff, Arrays.asList(SecureRoleRightAccessImpl.LEA_ADMINISTRATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testSchoolAdministratorCanSeeSectionAtSchool() { setContext(school1Staff, Arrays.asList(SecureRoleRightAccessImpl.IT_ADMINISTRATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testSchoolAdministratorCanNotSeeSectionAtSchool() { setContext(school2Staff, Arrays.asList(SecureRoleRightAccessImpl.IT_ADMINISTRATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testEducatorCanSeeSectionAtSchool() { setContext(educator1, Arrays.asList(SecureRoleRightAccessImpl.EDUCATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section1.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testEducatorCanNotSeeSectionAtSchool() { setContext(educator2, Arrays.asList(SecureRoleRightAccessImpl.EDUCATOR)); Set<String> sectionIds = new HashSet<String>(); sectionIds.add(section2.getEntityId()); assertTrue(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); sectionIds.add(section1.getEntityId()); assertFalse(validator.validate(EntityNames.SECTION, sectionIds).equals(sectionIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
StaffToGlobalSectionValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.SECTION, entityType, ids)) { return Collections.EMPTY_SET; } Set<String> edOrgLineage = getEdorgDescendents(getDirectEdorgs()); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)); query.addCriteria(new NeutralCriteria(ParameterConstants.SCHOOL_ID, NeutralCriteria.CRITERIA_IN, edOrgLineage)); Set<String> validSections = new HashSet<String>(); if (ids.size() != getRepo().count(entityType, query)) { Iterable<String> sections = getRepo().findAllIds(entityType, query); validSections = Sets.newHashSet(sections); } else { validSections = ids; } return validSections; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test(expected = IllegalArgumentException.class) public void testValidateWrongType() { val.validate(EntityNames.ASSESSMENT, new HashSet<String>(Arrays.asList("Jomolungma"))); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testSuccessOne() { Entity tsa = this.vth.generateTeacherSchool(USER_ID, "Myrran"); Set<String> ids = Collections.singleton(tsa.getEntityId()); Assert.assertTrue(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testSuccessMulti() { Set<String> ids = new HashSet<String>(); for (int i = 0; i < 100; i++) { ids.add(this.vth.generateTeacherSchool(USER_ID, "Myrran"+i).getEntityId()); } Assert.assertTrue(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void shouldResolveListOfReferences() throws IOException { NeutralRecordEntity entity = createSourceEntityWithRefList(); DidRefConfig refConfig = createRefConfig("Simple_DID_ref_config.json"); DidEntityConfig entityConfig = createEntityConfig("Simple_DID_entity_config.json"); mockRefConfig(refConfig, ENTITY_TYPE); mockEntityConfig(entityConfig, ENTITY_TYPE); Mockito.when(schemaRepository.getSchema(ENTITY_TYPE)).thenReturn(null); Map<String, String> naturalKeys1 = new HashMap<String, String>(); naturalKeys1.put(SRC_KEY_FIELD, SRC_KEY_VALUE_1); NaturalKeyDescriptor ndk1 = new NaturalKeyDescriptor(naturalKeys1, TENANT, ENTITY_TYPE, null); Map<String, String> naturalKeys2 = new HashMap<String, String>(); naturalKeys2.put(SRC_KEY_FIELD, SRC_KEY_VALUE_2); NaturalKeyDescriptor ndk2 = new NaturalKeyDescriptor(naturalKeys2, TENANT, ENTITY_TYPE, null); Mockito.when(didGenerator.generateId(Mockito.eq(ndk1))).thenReturn(DID_VALUE_1); Mockito.when(didGenerator.generateId(Mockito.eq(ndk2))).thenReturn(DID_VALUE_2); AbstractMessageReport errorReport = new DummyMessageReport(); ReportStats reportStats = new SimpleReportStats(); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); @SuppressWarnings("unchecked") List<String> did_list = (List<String>) entity.getBody().get(REF_FIELD); Assert.assertNotNull(did_list); Assert.assertEquals(2, did_list.size()); Assert.assertEquals(DID_VALUE_1, did_list.get(0)); Assert.assertEquals(DID_VALUE_2, did_list.get(1)); Assert.assertFalse("no errors should be reported from reference resolution ", reportStats.hasErrors()); }
public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
@Test public void testWrongId() { Set<String> ids = Collections.singleton("Hammerhands"); Assert.assertFalse(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); ids = Collections.singleton("Nagas"); Assert.assertFalse(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); ids = Collections.singleton("Phantom Warriors"); Assert.assertFalse(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testHeterogenousList() { Set<String> ids = new HashSet<String>(Arrays.asList(this.vth.generateTeacherSchool(USER_ID, "Myrran").getEntityId(), "Pikemen", "Pegasi")); Assert.assertFalse(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidate() { injector.setStudentContext(student1); assertTrue(validator.canValidate(EntityNames.ATTENDANCE, true)); assertTrue(validator.canValidate(EntityNames.ATTENDANCE, false)); assertTrue(validator.canValidate(EntityNames.STUDENT_ASSESSMENT, true)); assertTrue(validator.canValidate(EntityNames.STUDENT_ASSESSMENT, false)); assertTrue(validator.canValidate(EntityNames.STUDENT_GRADEBOOK_ENTRY, true)); assertTrue(validator.canValidate(EntityNames.STUDENT_GRADEBOOK_ENTRY, false)); assertTrue(validator.canValidate(EntityNames.GRADE, true)); assertTrue(validator.canValidate(EntityNames.GRADE, false)); assertTrue(validator.canValidate(EntityNames.STUDENT_ACADEMIC_RECORD, true)); assertTrue(validator.canValidate(EntityNames.STUDENT_ACADEMIC_RECORD, false)); assertTrue(validator.canValidate(EntityNames.REPORT_CARD, true)); assertTrue(validator.canValidate(EntityNames.REPORT_CARD, false)); assertTrue(validator.canValidate(EntityNames.STUDENT_SCHOOL_ASSOCIATION, true)); assertTrue(validator.canValidate(EntityNames.STUDENT_SCHOOL_ASSOCIATION, false)); assertFalse(validator.canValidate(EntityNames.STUDENT, false)); assertFalse(validator.canValidate(EntityNames.PARENT, true)); assertFalse(validator.canValidate(EntityNames.EDUCATION_ORGANIZATION, false)); assertFalse(validator.canValidate(EntityNames.STAFF, true)); assertFalse(validator.canValidate(EntityNames.DISCIPLINE_ACTION, false)); assertFalse(validator.canValidate(EntityNames.GRADUATION_PLAN, true)); assertFalse(validator.canValidate(EntityNames.PROGRAM, true)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return SUB_STUDENT_ENTITIES.contains(entityType) && isStudentOrParent(); }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return SUB_STUDENT_ENTITIES.contains(entityType) && isStudentOrParent(); } }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return SUB_STUDENT_ENTITIES.contains(entityType) && isStudentOrParent(); } }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return SUB_STUDENT_ENTITIES.contains(entityType) && isStudentOrParent(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return SUB_STUDENT_ENTITIES.contains(entityType) && isStudentOrParent(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); }
@Test public void testValidateSingleEntity() { injector.setStudentContext(student1); Set<String> idsToValidate = new HashSet<String>(Arrays.asList(attendance1.getEntityId())); assertTrue(validator.validate(EntityNames.ATTENDANCE, idsToValidate).containsAll(idsToValidate)); idsToValidate = new HashSet<String>(Arrays.asList(studentAcademicRecord1.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, idsToValidate).containsAll(idsToValidate)); injector.setStudentContext(student2); idsToValidate = new HashSet<String>(Arrays.asList(attendance2.getEntityId())); assertTrue(validator.validate(EntityNames.ATTENDANCE, idsToValidate).containsAll(idsToValidate)); idsToValidate = new HashSet<String>(Arrays.asList(studentAcademicRecord2.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, idsToValidate).containsAll(idsToValidate)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); } }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); } }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); }
@Test public void testValidateNegativeHeterogeneousList() { injector.setStudentContext(student1); Set<String> idsToValidate = new HashSet<String>(Arrays.asList(attendance1.getEntityId(),attendance2.getEntityId())); assertFalse(validator.validate(EntityNames.ATTENDANCE, idsToValidate).containsAll(idsToValidate)); idsToValidate = new HashSet<String>(Arrays.asList(studentAcademicRecord1.getEntityId(), studentAcademicRecord2.getEntityId())); assertFalse(validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, idsToValidate).containsAll(idsToValidate)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); } }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); } }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); }
StudentToSubStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); }
@Test(expected = IllegalArgumentException.class) public void testValidateWrongType() { val.validate(EntityNames.ASSESSMENT, new HashSet<String>(Arrays.asList("Jomolungma"))); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); 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(); }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); 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(); }
@Test public void testCanAccessAll() { vth.generateStaffEdorg(USER_ID, ED_ORG, false); Set<String> teacherIds = new HashSet<String>(Arrays.asList("Just Cause", "Armaggedon", "Awareness")); for (String id : teacherIds) { vth.generateStaffEdorg(id, ED_ORG, false); } Assert.assertTrue(val.validate(EntityNames.TEACHER, teacherIds).containsAll(teacherIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); 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(); }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); 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(); }
@Test public void testCannotAccessAll() { Set<String> teacherIds = new HashSet<String>(Arrays.asList("Just Cause", "Armaggedon", "Awareness")); for (String id : teacherIds) { vth.generateStaffEdorg(id, ED_ORG, false); } Assert.assertFalse(val.validate(EntityNames.TEACHER, teacherIds).containsAll(teacherIds)); for (String id : teacherIds) { Assert.assertFalse(val.validate(EntityNames.TEACHER, Collections.singleton(id)).contains(id)); } }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); 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(); }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); 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(); }
@Test public void testHeterogeneousList() { vth.generateStaffEdorg(USER_ID, ED_ORG, false); Set<String> teacherIds = new HashSet<String>(Arrays.asList("Just Cause", "Armaggedon", "Awareness", "Chaos Mastery", "Life Mastery", "Death and Decay", "Node Mastery", "Artificer", "Warlord", "Conjurer")); List<String> successes = new ArrayList<String>(); for (String id : teacherIds) { if (Math.random() > 0.5) { vth.generateStaffEdorg(id, ED_ORG, false); successes.add(id); } else { vth.generateStaffEdorg(id, "Arcanus", false); } } Assert.assertFalse(val.validate(EntityNames.TEACHER, teacherIds).containsAll(teacherIds)); for (String id : teacherIds) { if (successes.contains(id)) { Assert.assertTrue(val.validate(EntityNames.TEACHER, Collections.singleton(id)).contains(id)); } else { Assert.assertFalse(val.validate(EntityNames.TEACHER, Collections.singleton(id)).contains(id)); } } }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); 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(); }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); 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(); }
@Test public void testExpiredTeacher() { vth.generateStaffEdorg(USER_ID, ED_ORG, false); Set<String> teacherIds = new HashSet<String>(Arrays.asList("Just Cause")); for (String id : teacherIds) { vth.generateStaffEdorg(id, ED_ORG, true); } Assert.assertFalse(val.validate(EntityNames.TEACHER, teacherIds).containsAll(teacherIds)); for (String id : teacherIds) { vth.generateStaffEdorg(id, ED_ORG, false); } Assert.assertTrue(val.validate(EntityNames.TEACHER, teacherIds).containsAll(teacherIds)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); validIds.retainAll(ids); return validIds; } }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); 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(); }
TransitiveTeacherToTeacherValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER, entityType, ids)) { return Collections.emptySet(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "=", SecurityUtil .getSLIPrincipal().getEntity().getEntityId())); Iterable<Entity> tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); List<String> schools = new ArrayList<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { schools.add((String) e.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "in", schools)); nq.addCriteria(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, "in", ids)); tsa = getRepo().findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, nq); Set<String> validIds = new HashSet<String>(); for (Entity e : tsa) { if (!isFieldExpired(e.getBody(), ParameterConstants.END_DATE, false)) { validIds.add(e.getBody().get(ParameterConstants.STAFF_REFERENCE).toString()); } } validIds.add(SecurityUtil.getSLIPrincipal().getEntity().getEntityId()); 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(); }
@Test public void shouldFailFastForNonDidEntities() { NeutralRecordEntity entity = createSourceEntity(); AbstractMessageReport errorReport = new DummyMessageReport(); ReportStats reportStats = new SimpleReportStats(); mockEntityConfig(null, NON_DID_ENTITY_TYPE); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); Mockito.verify(didSchemaParser, Mockito.never()).getRefConfigs(); DidEntityConfig entityConfig = Mockito.mock(DidEntityConfig.class); mockEntityConfig(entityConfig, ENTITY_TYPE); Mockito.when(entityConfig.getReferenceSources()).thenReturn(null); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); Mockito.verify(didSchemaParser, Mockito.never()).getRefConfigs(); Mockito.when(entityConfig.getReferenceSources()).thenReturn(new ArrayList<DidRefSource>()); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); Mockito.verify(didSchemaParser, Mockito.never()).getRefConfigs(); }
public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
@Test(expected = MissingArgumentException.class) public void missingLocalDirValue() throws ParseException, MissingConfigException { String[] args = new String[] { "-u", "user", "-pass", "password", "-s", "server", "-d", "-port", "22" }; propUtils.getUploadProperties(args); }
public UploadProperties getUploadProperties(String[] args) throws ParseException, MissingConfigException { CommandLine cmd = parser.parse(OPTIONS, args); String user = cmd.getOptionValue(FLAG_USER); if (user == null) { throw new MissingConfigException(FLAG_USER); } String password = cmd.getOptionValue(FLAG_PASSWORD); if (password == null) { throw new MissingConfigException(FLAG_PASSWORD); } String server = cmd.getOptionValue(FLAG_SFTP_SERVER); if (server == null) { throw new MissingConfigException(FLAG_SFTP_SERVER); } String localDir = cmd.getOptionValue(FLAG_LOCAL_DIRECTORY); if (localDir == null) { throw new MissingConfigException(FLAG_LOCAL_DIRECTORY); } int port; try { port = Integer.parseInt(cmd.getOptionValue(FLAG_PORT)); } catch (NumberFormatException e) { throw new MissingConfigException(FLAG_PORT); } return new UploadProperties(user, password, server, localDir, port); }
PropertyUtils { public UploadProperties getUploadProperties(String[] args) throws ParseException, MissingConfigException { CommandLine cmd = parser.parse(OPTIONS, args); String user = cmd.getOptionValue(FLAG_USER); if (user == null) { throw new MissingConfigException(FLAG_USER); } String password = cmd.getOptionValue(FLAG_PASSWORD); if (password == null) { throw new MissingConfigException(FLAG_PASSWORD); } String server = cmd.getOptionValue(FLAG_SFTP_SERVER); if (server == null) { throw new MissingConfigException(FLAG_SFTP_SERVER); } String localDir = cmd.getOptionValue(FLAG_LOCAL_DIRECTORY); if (localDir == null) { throw new MissingConfigException(FLAG_LOCAL_DIRECTORY); } int port; try { port = Integer.parseInt(cmd.getOptionValue(FLAG_PORT)); } catch (NumberFormatException e) { throw new MissingConfigException(FLAG_PORT); } return new UploadProperties(user, password, server, localDir, port); } }
PropertyUtils { public UploadProperties getUploadProperties(String[] args) throws ParseException, MissingConfigException { CommandLine cmd = parser.parse(OPTIONS, args); String user = cmd.getOptionValue(FLAG_USER); if (user == null) { throw new MissingConfigException(FLAG_USER); } String password = cmd.getOptionValue(FLAG_PASSWORD); if (password == null) { throw new MissingConfigException(FLAG_PASSWORD); } String server = cmd.getOptionValue(FLAG_SFTP_SERVER); if (server == null) { throw new MissingConfigException(FLAG_SFTP_SERVER); } String localDir = cmd.getOptionValue(FLAG_LOCAL_DIRECTORY); if (localDir == null) { throw new MissingConfigException(FLAG_LOCAL_DIRECTORY); } int port; try { port = Integer.parseInt(cmd.getOptionValue(FLAG_PORT)); } catch (NumberFormatException e) { throw new MissingConfigException(FLAG_PORT); } return new UploadProperties(user, password, server, localDir, port); } PropertyUtils(CommandLineParser parser); }
PropertyUtils { public UploadProperties getUploadProperties(String[] args) throws ParseException, MissingConfigException { CommandLine cmd = parser.parse(OPTIONS, args); String user = cmd.getOptionValue(FLAG_USER); if (user == null) { throw new MissingConfigException(FLAG_USER); } String password = cmd.getOptionValue(FLAG_PASSWORD); if (password == null) { throw new MissingConfigException(FLAG_PASSWORD); } String server = cmd.getOptionValue(FLAG_SFTP_SERVER); if (server == null) { throw new MissingConfigException(FLAG_SFTP_SERVER); } String localDir = cmd.getOptionValue(FLAG_LOCAL_DIRECTORY); if (localDir == null) { throw new MissingConfigException(FLAG_LOCAL_DIRECTORY); } int port; try { port = Integer.parseInt(cmd.getOptionValue(FLAG_PORT)); } catch (NumberFormatException e) { throw new MissingConfigException(FLAG_PORT); } return new UploadProperties(user, password, server, localDir, port); } PropertyUtils(CommandLineParser parser); UploadProperties getUploadProperties(String[] args); }
PropertyUtils { public UploadProperties getUploadProperties(String[] args) throws ParseException, MissingConfigException { CommandLine cmd = parser.parse(OPTIONS, args); String user = cmd.getOptionValue(FLAG_USER); if (user == null) { throw new MissingConfigException(FLAG_USER); } String password = cmd.getOptionValue(FLAG_PASSWORD); if (password == null) { throw new MissingConfigException(FLAG_PASSWORD); } String server = cmd.getOptionValue(FLAG_SFTP_SERVER); if (server == null) { throw new MissingConfigException(FLAG_SFTP_SERVER); } String localDir = cmd.getOptionValue(FLAG_LOCAL_DIRECTORY); if (localDir == null) { throw new MissingConfigException(FLAG_LOCAL_DIRECTORY); } int port; try { port = Integer.parseInt(cmd.getOptionValue(FLAG_PORT)); } catch (NumberFormatException e) { throw new MissingConfigException(FLAG_PORT); } return new UploadProperties(user, password, server, localDir, port); } PropertyUtils(CommandLineParser parser); UploadProperties getUploadProperties(String[] args); static final String KEY_USER; static final String KEY_PASSWORD; static final String KEY_SFTP_SERVER; static final String KEY_LOCAL_DIRECTORY; static final String KEY_PORT; final static Options OPTIONS; }
@Test public void testCanValidate() { assertTrue(validator.canValidate(EntityNames.STUDENT_COMPETENCY, true)); assertTrue(validator.canValidate(EntityNames.STUDENT_COMPETENCY, false)); assertFalse(validator.canValidate(EntityNames.ATTENDANCE, false)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.STUDENT_COMPETENCY.equals(entityType); }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.STUDENT_COMPETENCY.equals(entityType); } }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.STUDENT_COMPETENCY.equals(entityType); } }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.STUDENT_COMPETENCY.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.STUDENT_COMPETENCY.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testValidComps() { Set<String> ids = new HashSet<String>(Arrays.asList(sComp1.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_COMPETENCY, ids).equals(ids)); ids = new HashSet<String>(Arrays.asList(sComp2.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_COMPETENCY, ids).equals(ids)); ids = new HashSet<String>(Arrays.asList(sComp1.getEntityId(), sComp2.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_COMPETENCY, ids).equals(ids)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); } }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); } }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testInvalidComps() { Set<String> ids = new HashSet<String>(Arrays.asList(sComp3.getEntityId())); assertFalse(validator.validate(EntityNames.STUDENT_COMPETENCY, ids).equals(ids)); ids = new HashSet<String>(Arrays.asList(sComp1.getEntityId(), sComp3.getEntityId())); assertFalse(validator.validate(EntityNames.STUDENT_COMPETENCY, ids).equals(ids)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); } }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); } }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateAsTeacher() { setupCurrentUser(teacher1); Assert.assertTrue("Must be able to validate", validator.canValidate(EntityNames.COURSE_TRANSCRIPT, false)); Assert.assertTrue("Must be able to validate", validator.canValidate(EntityNames.COURSE_TRANSCRIPT, true)); Assert.assertFalse("Must not be able to validate", validator.canValidate(EntityNames.ADMIN_DELEGATION, false)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.COURSE_TRANSCRIPT.equals(entityType); }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.COURSE_TRANSCRIPT.equals(entityType); } }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.COURSE_TRANSCRIPT.equals(entityType); } }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.COURSE_TRANSCRIPT.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isTeacher() && EntityNames.COURSE_TRANSCRIPT.equals(entityType); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testValidAssociations() { setupCurrentUser(teacher1); Assert.assertEquals(1, validator.validate(EntityNames.COURSE_TRANSCRIPT, new HashSet<String>(Arrays.asList(courseTranscript1.getEntityId()))).size()); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentAcademicRecordToCT = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String id = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if (!studentAcademicRecordToCT.containsKey(id)) { studentAcademicRecordToCT.put(id, new HashSet<String>()); } studentAcademicRecordToCT.get(id).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecordToCT.isEmpty()) { return Collections.EMPTY_SET; } Set<String> sarIds = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecordToCT.keySet()); return getValidIds(sarIds, studentAcademicRecordToCT); }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentAcademicRecordToCT = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String id = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if (!studentAcademicRecordToCT.containsKey(id)) { studentAcademicRecordToCT.put(id, new HashSet<String>()); } studentAcademicRecordToCT.get(id).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecordToCT.isEmpty()) { return Collections.EMPTY_SET; } Set<String> sarIds = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecordToCT.keySet()); return getValidIds(sarIds, studentAcademicRecordToCT); } }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentAcademicRecordToCT = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String id = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if (!studentAcademicRecordToCT.containsKey(id)) { studentAcademicRecordToCT.put(id, new HashSet<String>()); } studentAcademicRecordToCT.get(id).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecordToCT.isEmpty()) { return Collections.EMPTY_SET; } Set<String> sarIds = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecordToCT.keySet()); return getValidIds(sarIds, studentAcademicRecordToCT); } }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentAcademicRecordToCT = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String id = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if (!studentAcademicRecordToCT.containsKey(id)) { studentAcademicRecordToCT.put(id, new HashSet<String>()); } studentAcademicRecordToCT.get(id).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecordToCT.isEmpty()) { return Collections.EMPTY_SET; } Set<String> sarIds = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecordToCT.keySet()); return getValidIds(sarIds, studentAcademicRecordToCT); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentAcademicRecordToCT = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String id = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if (!studentAcademicRecordToCT.containsKey(id)) { studentAcademicRecordToCT.put(id, new HashSet<String>()); } studentAcademicRecordToCT.get(id).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecordToCT.isEmpty()) { return Collections.EMPTY_SET; } Set<String> sarIds = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecordToCT.keySet()); return getValidIds(sarIds, studentAcademicRecordToCT); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testInvalidAssociations() { setupCurrentUser(teacher1); Assert.assertEquals(0, validator.validate(EntityNames.COURSE_TRANSCRIPT, new HashSet<String>(Arrays.asList(UUID.randomUUID().toString()))).size()); Assert.assertEquals(0, validator.validate(EntityNames.COURSE_TRANSCRIPT, new HashSet<String>()).size()); Assert.assertEquals(0, validator.validate(EntityNames.COURSE_TRANSCRIPT, new HashSet<String>(Arrays.asList(courseTranscript2.getEntityId()))).size()); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentAcademicRecordToCT = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String id = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if (!studentAcademicRecordToCT.containsKey(id)) { studentAcademicRecordToCT.put(id, new HashSet<String>()); } studentAcademicRecordToCT.get(id).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecordToCT.isEmpty()) { return Collections.EMPTY_SET; } Set<String> sarIds = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecordToCT.keySet()); return getValidIds(sarIds, studentAcademicRecordToCT); }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentAcademicRecordToCT = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String id = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if (!studentAcademicRecordToCT.containsKey(id)) { studentAcademicRecordToCT.put(id, new HashSet<String>()); } studentAcademicRecordToCT.get(id).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecordToCT.isEmpty()) { return Collections.EMPTY_SET; } Set<String> sarIds = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecordToCT.keySet()); return getValidIds(sarIds, studentAcademicRecordToCT); } }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentAcademicRecordToCT = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String id = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if (!studentAcademicRecordToCT.containsKey(id)) { studentAcademicRecordToCT.put(id, new HashSet<String>()); } studentAcademicRecordToCT.get(id).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecordToCT.isEmpty()) { return Collections.EMPTY_SET; } Set<String> sarIds = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecordToCT.keySet()); return getValidIds(sarIds, studentAcademicRecordToCT); } }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentAcademicRecordToCT = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String id = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if (!studentAcademicRecordToCT.containsKey(id)) { studentAcademicRecordToCT.put(id, new HashSet<String>()); } studentAcademicRecordToCT.get(id).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecordToCT.isEmpty()) { return Collections.EMPTY_SET; } Set<String> sarIds = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecordToCT.keySet()); return getValidIds(sarIds, studentAcademicRecordToCT); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToCourseTranscriptValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentAcademicRecordToCT = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String id = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if (!studentAcademicRecordToCT.containsKey(id)) { studentAcademicRecordToCT.put(id, new HashSet<String>()); } studentAcademicRecordToCT.get(id).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecordToCT.isEmpty()) { return Collections.EMPTY_SET; } Set<String> sarIds = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecordToCT.keySet()); return getValidIds(sarIds, studentAcademicRecordToCT); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidate() { assertTrue(validator.canValidate(EntityNames.DISCIPLINE_INCIDENT, true)); assertTrue(validator.canValidate(EntityNames.DISCIPLINE_INCIDENT, false)); assertFalse(validator.canValidate(EntityNames.SECTION, true)); assertFalse(validator.canValidate(EntityNames.SECTION, false)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.DISCIPLINE_INCIDENT.equals(entityType); }
StaffToDisciplineIncidentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.DISCIPLINE_INCIDENT.equals(entityType); } }
StaffToDisciplineIncidentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.DISCIPLINE_INCIDENT.equals(entityType); } }
StaffToDisciplineIncidentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.DISCIPLINE_INCIDENT.equals(entityType); } @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 boolean canValidate(String entityType, boolean isTransitive) { return isStaff() && EntityNames.DISCIPLINE_INCIDENT.equals(entityType); } @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(); }
@Test public void testCanValidateDisciplineIncidentFromSchool() { Entity school = helper.generateEdorgWithParent(null); Set<String> schoolId = new HashSet<String>(Arrays.asList(school.getEntityId())); Mockito.when(mockSchoolValidator.validate(EntityNames.SCHOOL, schoolId)).thenReturn(schoolId); helper.generateStaffEdorg(helper.STAFF_ID, school.getEntityId(), false); Entity di = helper.generateDisciplineIncident(school.getEntityId()); diIds.add(di.getEntityId()); Assert.assertEquals(diIds, validator.validate(EntityNames.DISCIPLINE_INCIDENT, 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(); }
@Test public void testCanValidateDisciplineIncidentFromStudent() { Entity school = helper.generateEdorgWithParent(null); Entity di = helper.generateDisciplineIncident(school.getEntityId()); diIds.add(di.getEntityId()); Entity sdia = helper.generateStudentDisciplineIncidentAssociation("Berp", di.getEntityId()); Mockito.when( mockStudentValidator.validate(Mockito.eq(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION), Mockito.any(Set.class))).thenReturn(new HashSet<String>(Arrays.asList(sdia.getEntityId()))); assertTrue(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(); }
@Test public void testCanValidateDisciplineIncidentFromState() { Entity sea = helper.generateEdorgWithParent(null); Entity lea = helper.generateEdorgWithParent(sea.getEntityId()); Entity seoas = helper.generateStaffEdorg(helper.STAFF_ID, lea.getEntityId(), false); for (int i = 0; i < 10; ++i) { Entity school = helper.generateEdorgWithParent(lea.getEntityId()); Entity di = helper.generateDisciplineIncident(school.getEntityId()); diIds.add(di.getEntityId()); } Mockito.when(mockSchoolValidator.validate(Mockito.eq(EntityNames.SCHOOL), Mockito.any(Set.class))).thenReturn(new HashSet<String>(Arrays.asList(lea.getEntityId()))); Assert.assertEquals(diIds, validator.validate(EntityNames.DISCIPLINE_INCIDENT, diIds)); Mockito.when(mockSchoolValidator.validate(Mockito.eq(EntityNames.SCHOOL), Mockito.any(Set.class))).thenReturn(Collections.EMPTY_SET); diIds.add(helper.generateDisciplineIncident(sea.getEntityId()).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(); }
@Test public void shouldResolveNestedDid() throws IOException { DidRefConfig refConfig = createRefConfig("nested_DID_ref_config.json"); DidEntityConfig entityConfig = createEntityConfig("Simple_DID_entity_config.json"); AbstractMessageReport errorReport = new DummyMessageReport(); ReportStats reportStats = new SimpleReportStats(); NeutralRecordEntity entity = createNestedSourceEntity(); Map<String, String> naturalKeys = new HashMap<String, String>(); naturalKeys.put(SRC_KEY_FIELD, NESTED_DID_VALUE); String entityType = ENTITY_TYPE; String tenantId = TENANT; NaturalKeyDescriptor ndk = new NaturalKeyDescriptor(naturalKeys, tenantId, entityType, null); Map<String, String> nestedNaturalKeys = new HashMap<String, String>(); nestedNaturalKeys.put(NESTED_SRC_KEY_FIELD, NESTED_SRC_KEY_VALUE); NaturalKeyDescriptor nestedNdk = new NaturalKeyDescriptor(nestedNaturalKeys, tenantId, NESTED_ENTITY_TYPE, null); mockRefConfig(refConfig, ENTITY_TYPE); mockEntityConfig(entityConfig, ENTITY_TYPE); Mockito.when(schemaRepository.getSchema(ENTITY_TYPE)).thenReturn(null); Mockito.when(didGenerator.generateId(Mockito.eq(ndk))).thenReturn(DID_VALUE); Mockito.when(didGenerator.generateId(Mockito.eq(nestedNdk))).thenReturn(NESTED_DID_VALUE); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); Object resolvedId = entity.getBody().get(REF_FIELD); Assert.assertEquals(DID_VALUE, resolvedId); Assert.assertFalse("no errors should be reported from reference resolution ", reportStats.hasErrors()); }
public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
@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(); }
@Test public void testCanNotValidateDisciplineIncidentFromInvalidAssoc() { Mockito.when( mockStudentValidator.validate(Mockito.eq(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION), Mockito.any(Set.class))).thenReturn(Collections.EMPTY_SET); Entity school = helper.generateEdorgWithParent(null); Entity di = helper.generateDisciplineIncident(school.getEntityId()); diIds.add(di.getEntityId()); helper.generateStudentDisciplineIncidentAssociation("Berp", 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(); }
@Test(expected = IllegalArgumentException.class) public void testValidateWrongType() { val.validate(EntityNames.ASSESSMENT, new HashSet<String>(Arrays.asList("Jomolungma"))); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanAccessAll() { List<String> ids = Arrays.asList("Just Cause", "Armaggedon", "Awareness"); Set<String> sca = new HashSet<String>(); for (String id : ids) { sca.add(this.vth.generateStaffCohort(USER_ID, id, false, true).getEntityId()); } Assert.assertTrue(val.validate(EntityNames.STAFF_COHORT_ASSOCIATION, sca).equals(sca)); }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCannotAccessAll() { List<String> ids = Arrays.asList("Just Cause", "Armaggedon", "Awareness"); Set<String> sca = new HashSet<String>(); for (String id : ids) { sca.add(this.vth.generateStaffCohort("Sky Drake", id, false, true).getEntityId()); } Assert.assertFalse(val.validate(EntityNames.STAFF_COHORT_ASSOCIATION, sca).equals(sca)); for (String id : sca) { Set<String> single = Collections.singleton(id); Assert.assertFalse(val.validate(EntityNames.STAFF_COHORT_ASSOCIATION, single).equals(single)); } }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testHeterogeneousList() { List<String> ids = Arrays.asList("Just Cause", "Armaggedon", "Awareness", "Chaos Mastery", "Life Mastery", "Death and Decay", "Node Mastery", "Artificer", "Warlord", "Conjurer"); Set<String> sca = new HashSet<String>(); List<String> successes = new ArrayList<String>(); for (String id : ids) { if (Math.random() > 0.33) { sca.add(this.vth.generateStaffCohort("Sky Drake", id, false, true).getEntityId()); } else if (Math.random() > 0.5) { String id2 = this.vth.generateStaffCohort(USER_ID, id, false, true).getEntityId(); sca.add(id2); successes.add(id2); } else { sca.add("Earth Elemental"); } } Assert.assertFalse(val.validate(EntityNames.STAFF_COHORT_ASSOCIATION, sca).equals(sca)); for (String id : sca) { Set<String> single = Collections.singleton(id); if (successes.contains(id)) { Assert.assertTrue(val.validate(EntityNames.STAFF_COHORT_ASSOCIATION, single).equals(single)); } else { Assert.assertFalse(val.validate(EntityNames.STAFF_COHORT_ASSOCIATION, single).equals(single)); } } }
@Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
TeacherToStaffCohortAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_COHORT_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); nq.addCriteria(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); Iterable<String> result = getRepo().findAllIds(EntityNames.STAFF_COHORT_ASSOCIATION, nq); return Sets.newHashSet(result); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateTeacherToAttendance() throws Exception { assertTrue(validator.canValidate(EntityNames.ATTENDANCE, false)); }
@Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateTeacherToDisciplineAction() throws Exception { assertTrue(validator.canValidate(EntityNames.DISCIPLINE_ACTION, false)); }
@Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateTeacherToStudentAcademicRecord() throws Exception { assertTrue(validator.canValidate(EntityNames.STUDENT_ACADEMIC_RECORD, false)); }
@Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateTeacherToStudentAssessment() throws Exception { assertTrue(validator.canValidate(EntityNames.STUDENT_ASSESSMENT, false)); }
@Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void shouldResolveNestedDidWithOptionalNestedReference() throws IOException { NeutralRecordEntity entity = createEntity("NeutralRecord_StudentTranscriptAssoc_missingOptionalEdOrg.json"); DidRefConfig refConfig = createRefConfig("StudentAcademicRecord_optional_ref_config.json"); DidEntityConfig entityConfig = createEntityConfig("StudentTranscriptAssoc_entity_config.json"); AbstractMessageReport errorReport = new DummyMessageReport(); ReportStats reportStats = new SimpleReportStats(); Map<String, String> naturalKeys = new HashMap<String, String>(); naturalKeys.put("schoolId", ""); naturalKeys.put("sessionName", "Spring 2011 East Daybreak Junior High"); naturalKeys.put("schoolId", ""); String tenantId = TENANT; NaturalKeyDescriptor sessionNKD = new NaturalKeyDescriptor(naturalKeys, tenantId, "session", null); Mockito.when(didGenerator.generateId(Mockito.eq(sessionNKD))).thenReturn("sessionDID"); naturalKeys = new HashMap<String, String>(); naturalKeys.put("sessionId", "sessionDID"); NaturalKeyDescriptor studentAcademicRecordNKD = new NaturalKeyDescriptor(naturalKeys, tenantId, "studentAcademicRecord", null); Mockito.when(didGenerator.generateId(Mockito.eq(studentAcademicRecordNKD))).thenReturn( "studentAcademicRecordDID"); mockRefConfig(refConfig, "studentAcademicRecord"); mockEntityConfig(entityConfig, "studentTranscriptAssociation"); Mockito.when(schemaRepository.getSchema(ENTITY_TYPE)).thenReturn(null); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); Object resolvedId = entity.getBody().get("StudentAcademicRecordReference"); Assert.assertEquals("studentAcademicRecordDID", resolvedId); Assert.assertFalse("no errors should be reported from reference resolution ", reportStats.hasErrors()); }
public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
@Test public void testCanValidateTeacherToStudentDisciplineIncident() throws Exception { assertTrue(validator.canValidate(EntityNames.STUDENT_DISCIPLINE_INCIDENT_ASSOCIATION, false)); }
@Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateTeacherToStudentGradebookEntry() throws Exception { assertTrue(validator.canValidate(EntityNames.STUDENT_GRADEBOOK_ENTRY, false)); }
@Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateTeacherToStudentSchoolAssociation() throws Exception { assertTrue(validator.canValidate(EntityNames.STUDENT_SCHOOL_ASSOCIATION, false)); }
@Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateTeacherToStudentSectionAssociation() throws Exception { assertTrue(validator.canValidate(EntityNames.STUDENT_SECTION_ASSOCIATION, false)); }
@Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotValidateOtherEntities() throws Exception { assertFalse(validator.canValidate(EntityNames.STUDENT, false)); }
@Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean through) { return isTeacher() && isSubEntityOfStudent(entityType); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanGetAccessToAttendance() throws Exception { Set<String> studentIds = new HashSet<String>(); Set<String> attendances = new HashSet<String>(); Map<String, Object> attendance1 = buildAttendanceForStudent("student123", "school123"); Entity attendanceEntity1 = new MongoEntity("attendance", attendance1); attendances.add(attendanceEntity1.getEntityId()); studentIds.add("student123"); Mockito.when(mockRepo.findAll(Mockito.eq(EntityNames.ATTENDANCE), Mockito.any(NeutralQuery.class))).thenReturn( Arrays.asList(attendanceEntity1)); Mockito.when(teacherToStudentValidator.validate(EntityNames.STUDENT, studentIds)).thenReturn(studentIds); Assert.assertEquals(attendances.size(), validator.validate(EntityNames.ATTENDANCE, attendances).size()); }
@SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotGetAccessToAttendance() throws Exception { Set<String> attendances = new HashSet<String>(); Map<String, Object> attendance1 = buildAttendanceForStudent("student123", "school123"); Entity attendanceEntity1 = new MongoEntity("attendance", attendance1); attendances.add(attendanceEntity1.getEntityId()); studentIds.add("student123"); Mockito.when(mockRepo.findAll(Mockito.eq(EntityNames.ATTENDANCE), Mockito.any(NeutralQuery.class))).thenReturn( Arrays.asList(attendanceEntity1)); Mockito.when(teacherToStudentValidator.validate(EntityNames.STUDENT, studentIds)).thenReturn(Collections.EMPTY_SET); assertFalse(validator.validate(EntityNames.ATTENDANCE, attendances).size() == attendance1.size()); }
@SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanGetAccessToCurrentStudentSchoolAssociation() throws Exception { Map<String, Object> goodStudentSchoolAssociation = buildStudentSchoolAssociation("student123", "school123", new DateTime().plusHours(1)); Entity association = new MongoEntity(EntityNames.STUDENT_SCHOOL_ASSOCIATION, goodStudentSchoolAssociation); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.STUDENT_SCHOOL_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(Arrays.asList(association)); Set<String> associations = new HashSet<String>(); associations.add(association.getEntityId()); studentIds.add("student123"); Mockito.when(teacherToStudentValidator.validate(EntityNames.STUDENT, studentIds)).thenReturn(studentIds); Assert.assertEquals(studentIds.size(), validator.validate(EntityNames.STUDENT_SCHOOL_ASSOCIATION, associations).size()); }
@SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanGetAccessToStudentSchoolAssociationWithoutExitWithdrawDate() throws Exception { Map<String, Object> goodStudentSchoolAssociation = buildStudentSchoolAssociation("student123", "school123"); Entity association = new MongoEntity(EntityNames.STUDENT_SCHOOL_ASSOCIATION, goodStudentSchoolAssociation); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.STUDENT_SCHOOL_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(Arrays.asList(association)); Set<String> associations = new HashSet<String>(); associations.add(association.getEntityId()); studentIds.add("student123"); Mockito.when(teacherToStudentValidator.validate(EntityNames.STUDENT, studentIds)).thenReturn(studentIds); Assert.assertEquals(studentIds.size(), validator.validate(EntityNames.STUDENT_SCHOOL_ASSOCIATION, associations).size()); }
@SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testDeniedAccessToExpiredStudentSchoolAssociation() throws Exception { Map<String, Object> badStudentSchoolAssociation = buildStudentSchoolAssociation("student123", "school123", new DateTime().minusDays(1)); Entity association = new MongoEntity(EntityNames.STUDENT_SCHOOL_ASSOCIATION, badStudentSchoolAssociation); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.STUDENT_SCHOOL_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(Arrays.asList(association)); Set<String> associations = new HashSet<String>(); associations.add(association.getEntityId()); assertFalse(validator.validate(EntityNames.STUDENT_SCHOOL_ASSOCIATION, associations).size() == associations.size()); }
@SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@SuppressWarnings("unchecked") @Test public void shouldResolveDidsInEmbeddedList() throws IOException { NeutralRecordEntity entity = createSourceEmbeddedEntity(); DidRefConfig refConfig = createRefConfig("Simple_DID_ref_config.json"); DidEntityConfig entityConfig = createEntityConfig("Embedded_DID_entity_config.json"); mockRefConfig(refConfig, ENTITY_TYPE); mockEntityConfig(entityConfig, ENTITY_TYPE); Mockito.when(schemaRepository.getSchema(ENTITY_TYPE)).thenReturn(null); Map<String, String> naturalKeys1 = new HashMap<String, String>(); naturalKeys1.put(SRC_KEY_FIELD, SRC_KEY_VALUE_1); String entityType = ENTITY_TYPE; String tenantId = TENANT; NaturalKeyDescriptor ndk1 = new NaturalKeyDescriptor(naturalKeys1, tenantId, entityType, null); Map<String, String> naturalKeys2 = new HashMap<String, String>(); naturalKeys2.put(SRC_KEY_FIELD, SRC_KEY_VALUE_2); NaturalKeyDescriptor ndk2 = new NaturalKeyDescriptor(naturalKeys2, tenantId, entityType, null); Mockito.when(didGenerator.generateId(Mockito.eq(ndk1))).thenReturn(DID_VALUE_1); Mockito.when(didGenerator.generateId(Mockito.eq(ndk2))).thenReturn(DID_VALUE_2); AbstractMessageReport errorReport = new DummyMessageReport(); ReportStats reportStats = new SimpleReportStats(); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); List<Object> embeddedList = (List<Object>) entity.getBody().get(EMBEDDED_LIST_FIELD); Assert.assertNotNull(embeddedList); Assert.assertEquals(2, embeddedList.size()); Map<String, Object> subObj1 = (Map<String, Object>) embeddedList.get(0); Map<String, Object> subObj2 = (Map<String, Object>) embeddedList.get(1); Assert.assertEquals(DID_VALUE_1, subObj1.get(REF_FIELD)); Assert.assertEquals(DID_VALUE_2, subObj2.get(REF_FIELD)); Assert.assertFalse("no errors should be reported from reference resolution ", reportStats.hasErrors()); }
public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
@Test public void testCanGetAccessToCurrentStudentSectionAssociation() throws Exception { Map<String, Object> goodStudentSectionAssociation = buildStudentSectionAssociation("student123", "section123", new DateTime().plusDays(1)); Entity association = new MongoEntity(EntityNames.STUDENT_SECTION_ASSOCIATION, "assoc123", goodStudentSectionAssociation, null); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.STUDENT_SECTION_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(Arrays.asList(association)); Set<String> associations = new HashSet<String>(); associations.add(association.getEntityId()); studentIds.add("student123"); Mockito.when(teacherToStudentValidator.validate(EntityNames.STUDENT, studentIds)).thenReturn(studentIds); Assert.assertEquals(associations, validator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, associations)); }
@SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanGetAccessToStudentSectionAssociationWithoutEndDate() throws Exception { Map<String, Object> goodStudentSectionAssociation = buildStudentSectionAssociation("student123", "section123"); Entity association = new MongoEntity(EntityNames.STUDENT_SECTION_ASSOCIATION, goodStudentSectionAssociation); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.STUDENT_SECTION_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(Arrays.asList(association)); Set<String> associations = new HashSet<String>(); associations.add(association.getEntityId()); studentIds.add("student123"); Mockito.when(teacherToStudentValidator.validate(EntityNames.STUDENT, studentIds)).thenReturn(studentIds); Assert.assertEquals(studentIds.size(), validator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, associations).size()); }
@SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testDeniedAccessToExpiredStudentSectionAssociation() throws Exception { Map<String, Object> badStudentSectionAssociation = buildStudentSchoolAssociation("student123", "section123", new DateTime().minusDays(1)); Entity association = new MongoEntity(EntityNames.STUDENT_SECTION_ASSOCIATION, badStudentSectionAssociation); Mockito.when( mockRepo.findAll(Mockito.eq(EntityNames.STUDENT_SECTION_ASSOCIATION), Mockito.any(NeutralQuery.class))) .thenReturn(Arrays.asList(association)); Set<String> associations = new HashSet<String>(); associations.add(association.getEntityId()); assertFalse(validator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, associations).size() == associations.size()); }
@SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
TeacherToSubStudentEntityValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_ENTITIES_OF_STUDENT, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> students = new HashMap<String, Set<String>>(); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = repo.findAll(entityType, query); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ID) instanceof String) { students = putStudents(Arrays.asList((String) body.get(ParameterConstants.STUDENT_ID)), entity.getEntityId(), students); } else if (body.get(ParameterConstants.STUDENT_ID) instanceof List) { students = putStudents((List<String>) body.get(ParameterConstants.STUDENT_ID), entity.getEntityId(), students); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (students.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudents = validator.validate(EntityNames.STUDENT, students.keySet()); return getValidIds(validStudents, students); } @Override boolean canValidate(String entityType, boolean through); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityType, Set<String> ids); void setRepo(PagingRepositoryDelegate<Entity> repo); void setTeacherToStudentValidator(TeacherToStudentValidator teacherToStudentValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanValidateStaffToStudents() throws Exception { assertTrue(validator.canValidate(EntityNames.STUDENT, false)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STUDENT.equals(entityType) && isStaff(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STUDENT.equals(entityType) && isStaff(); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STUDENT.equals(entityType) && isStaff(); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STUDENT.equals(entityType) && isStaff(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STUDENT.equals(entityType) && isStaff(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotValidateOtherEntities() throws Exception { assertFalse(validator.canValidate(EntityNames.ATTENDANCE, false)); }
@Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STUDENT.equals(entityType) && isStaff(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STUDENT.equals(entityType) && isStaff(); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STUDENT.equals(entityType) && isStaff(); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STUDENT.equals(entityType) && isStaff(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public boolean canValidate(String entityType, boolean isTransitive) { return EntityNames.STUDENT.equals(entityType) && isStaff(); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanGetAccessThroughSingleValidAssociation() throws Exception { helper.generateStaffEdorg(STAFF_ID, ED_ORG_ID, NOT_EXPIRED); String studentId = helper.generateStudentAndStudentSchoolAssociation("2", edOrg.getEntityId(), NOT_EXPIRED); studentIds.add(studentId); assertTrue(validator.validate(EntityNames.STUDENT, studentIds).equals(studentIds)); }
@Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotGetAccessThroughInvalidAssociation() throws Exception { helper.generateStaffEdorg(STAFF_ID, ED_ORG_ID, NOT_EXPIRED); String studentId = helper.generateStudentAndStudentSchoolAssociation("2", ED_ORG_ID_2, NOT_EXPIRED); studentIds.add(studentId); assertFalse(validator.validate(EntityNames.STUDENT, studentIds).equals(studentIds)); }
@Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotGetAccessDueToExpiration() throws Exception { helper.generateStaffEdorg(STAFF_ID, ED_ORG_ID, NOT_EXPIRED); String studentId = helper.generateStudentAndStudentSchoolAssociation("2", ED_ORG_ID, IS_EXPIRED); studentIds.add(studentId); assertFalse(validator.validate(EntityNames.STUDENT, studentIds).equals(studentIds)); }
@Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanGetAccessThroughManyStudents() throws Exception { Set<String> expectedIds = new HashSet<String>(); for (int i = 0; i < N_TEST_EDORGS/2; ++i) { helper.generateStaffEdorg(STAFF_ID, edorgArray[ i ], NOT_EXPIRED); injector.addToAuthorizingEdOrgs( edorgArray[ i ] ); } for (int i = 0; i < N_TEST_EDORGS/2; ++i) { for (int j = -1; j > -31; --j) { String studentId = helper.generateStudentAndStudentSchoolAssociation(String.valueOf(j), edorgArray[ i ], NOT_EXPIRED); studentIds.add(studentId); expectedIds.add(studentId); } } assertTrue(validator.validate(EntityNames.STUDENT, studentIds).equals(studentIds)); for (int i = N_TEST_EDORGS/2; i < N_TEST_EDORGS; ++i) { for (int j = -1; j > -31; --j) { String studentId = helper.generateStudentAndStudentSchoolAssociation(String.valueOf(j), edorgArray[ i ], NOT_EXPIRED); studentIds.add(studentId); } } Assert.assertEquals(expectedIds, validator.validate(EntityNames.STUDENT, studentIds)); }
@Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanNotGetAccessThroughManyStudents() throws Exception { for (int i = N_TEST_EDORGS/2; i < N_TEST_EDORGS; ++i) { helper.generateStaffEdorg(STAFF_ID, edorgArray[ i ], NOT_EXPIRED); injector.addToAuthorizingEdOrgs( edorgArray[ i ] ); } for (int i = 0; i < N_TEST_EDORGS/2; ++i) { for (int j = -1; j > -31; --j) { String studentId = helper.generateStudentAndStudentSchoolAssociation(String.valueOf(j), edorgArray[ i ], NOT_EXPIRED); studentIds.add(studentId); } } assertFalse(validator.validate(EntityNames.STUDENT, studentIds).equals(studentIds)); }
@Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testErrorReportingOnEntityRefFieldMissing() throws IOException { AbstractMessageReport errorReport = new DummyMessageReport(); ReportStats reportStats = new SimpleReportStats(); NeutralRecordEntity entity = createSourceEntityMissingRefField(); DidRefConfig refConfig = createRefConfig("Simple_DID_ref_config.json"); DidEntityConfig entityConfig = createEntityConfig("Simple_DID_entity_config.json"); mockRefConfig(refConfig, ENTITY_TYPE); mockEntityConfig(entityConfig, ENTITY_TYPE); Mockito.when(schemaRepository.getSchema(ENTITY_TYPE)).thenReturn(null); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); Assert.assertNull("Id should not have been resolved", entity.getBody().get(REF_FIELD)); Assert.assertTrue("Errors should be reported from reference resolution ", reportStats.hasErrors()); }
public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
@Test public void testCanNotGetAccessThroughManyStudentsWithOneFailure() throws Exception { for (int i = 0; i < N_TEST_EDORGS/2; ++i) { helper.generateStaffEdorg(STAFF_ID, edorgArray[ i ], NOT_EXPIRED); injector.addToAuthorizingEdOrgs( edorgArray[ i ] ); } Set<String> expected = new HashSet<String>(); for (int i = 0; i < N_TEST_EDORGS/2; ++i) { for (int j = -1; j > -31; --j) { String studentId = helper.generateStudentAndStudentSchoolAssociation(String.valueOf(j), edorgArray[ i ], NOT_EXPIRED); studentIds.add(studentId); expected.add(studentId); } } String anotherEdOrg = helper.generateSchoolEdOrg(null).getEntityId(); String studentId = helper.generateStudentAndStudentSchoolAssociation("-32", anotherEdOrg, NOT_EXPIRED); studentIds.add(studentId); Assert.assertEquals(expected, validator.validate(EntityNames.STUDENT, studentIds)); }
@Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
@Test public void testCanGetAccessThroughCohort() { Entity cohort = helper.generateStudentCohort("Merp", "Derp", false); Mockito.when(mockCohortValidator.validate(Mockito.eq(EntityNames.COHORT), Mockito.anySet())).thenReturn(new HashSet<String>(Arrays.asList(cohort.getEntityId()))); helper.generateStaffEdorg(STAFF_ID, DERP, NOT_EXPIRED); for (int j = -1; j > -31; --j) { String studentId = helper.generateStudentAndStudentSchoolAssociation(String.valueOf(j), ED_ORG_ID, NOT_EXPIRED); studentIds.add(studentId); } assertTrue(validator.validate(EntityNames.STUDENT, studentIds).equals(studentIds)); }
@Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }
StaffToStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> studentIds) throws IllegalStateException { LOG.debug(">>>StaffToStudentValidator.validate(?)", entityType); LOG.debug(" studentIds: {}", (studentIds==null) ? "null" : studentIds.toString() ); if (!areParametersValid(EntityNames.STUDENT, entityType, studentIds)) { LOG.debug(" !areParametersValid"); return new HashSet<String>(); } return validateStaffToStudentContextThroughSharedEducationOrganization(studentIds); } @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> getValid(String entityType, Set<String> studentIds); @Override Set<String> validate(String entityType, Set<String> studentIds); void setProgramValidator(GenericToProgramValidator programValidator); void setCohortValidator(GenericToCohortValidator cohortValidator); @Override SecurityUtil.UserContext getContext(); }