@Test public void testValidStaffStaffAssociationNoEndDate() { setupCurrentUser(staff1); Set<String> staffId = new HashSet<String>(Arrays.asList(staff2.getEntityId())); assertTrue(validator.validate(EntityNames.STAFF, staffId).equals(staffId)); assertTrue(validator.validate(EntityNames.STAFF, staffId).equals(staffId)); }
@SuppressWarnings("unchecked") @Override public Set<String> validate(String entityName, Set<String> staffIds) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF, entityName, staffIds)) { return Collections.EMPTY_SET; } Set<String> validIds = new HashSet<String>(); NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria("staffReference", NeutralCriteria.CRITERIA_IN, staffIds)); basicQuery.setIncludeFields(Arrays.asList("educationOrganizationReference", "staffReference")); LOG.info("Attempting to validate transitively from staff to staff with ids {}", staffIds); injectEndDateQuery(basicQuery); Iterable<Entity> edOrgAssoc = repo.findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, basicQuery); Map<String, Set<String>> staffEdorgMap = new HashMap<String, Set<String>>(); populateMapFromMongoResponse(staffEdorgMap, edOrgAssoc); Set<String> edOrgLineage = getStaffEdOrgLineage(); if (edOrgLineage.isEmpty() || staffEdorgMap.isEmpty()) { return Collections.EMPTY_SET; } for (Entry<String, Set<String>> entry : staffEdorgMap.entrySet()) { Set<String> tmpSet = new HashSet<String>(entry.getValue()); tmpSet.retainAll(edOrgLineage); if (tmpSet.size() != 0) { validIds.add(entry.getKey()); } } validIds.addAll(validateThrough(EntityNames.STAFF_PROGRAM_ASSOCIATION, "programId")); validIds.addAll(validateThrough(EntityNames.STAFF_COHORT_ASSOCIATION, "cohortId")); basicQuery = new NeutralQuery(new NeutralCriteria("_id", "in", edOrgLineage)); Iterable<Entity> edorgs = repo.findAll(EntityNames.EDUCATION_ORGANIZATION, basicQuery); List<String> programs = new ArrayList<String>(); for (Entity e : edorgs) { Object value = e.getBody().get("programReference"); if (value != null) { if (List.class.isAssignableFrom(value.getClass())) { programs.addAll((List<String>) value); } else if (String.class.isAssignableFrom(value.getClass())) { programs.add((String) value); } } } validIds.addAll(getIds(EntityNames.STAFF_PROGRAM_ASSOCIATION, "programId", programs)); basicQuery = new NeutralQuery(new NeutralCriteria("educationOrgId", "in", edOrgLineage)); List<String> cohorts = (List<String>) repo.findAllIds(EntityNames.COHORT, basicQuery); validIds.addAll(getIds(EntityNames.STAFF_COHORT_ASSOCIATION, "cohortId", cohorts)); validIds.retainAll(staffIds); return validIds; }
TransitiveStaffToStaffValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityName, Set<String> staffIds) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF, entityName, staffIds)) { return Collections.EMPTY_SET; } Set<String> validIds = new HashSet<String>(); NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria("staffReference", NeutralCriteria.CRITERIA_IN, staffIds)); basicQuery.setIncludeFields(Arrays.asList("educationOrganizationReference", "staffReference")); LOG.info("Attempting to validate transitively from staff to staff with ids {}", staffIds); injectEndDateQuery(basicQuery); Iterable<Entity> edOrgAssoc = repo.findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, basicQuery); Map<String, Set<String>> staffEdorgMap = new HashMap<String, Set<String>>(); populateMapFromMongoResponse(staffEdorgMap, edOrgAssoc); Set<String> edOrgLineage = getStaffEdOrgLineage(); if (edOrgLineage.isEmpty() || staffEdorgMap.isEmpty()) { return Collections.EMPTY_SET; } for (Entry<String, Set<String>> entry : staffEdorgMap.entrySet()) { Set<String> tmpSet = new HashSet<String>(entry.getValue()); tmpSet.retainAll(edOrgLineage); if (tmpSet.size() != 0) { validIds.add(entry.getKey()); } } validIds.addAll(validateThrough(EntityNames.STAFF_PROGRAM_ASSOCIATION, "programId")); validIds.addAll(validateThrough(EntityNames.STAFF_COHORT_ASSOCIATION, "cohortId")); basicQuery = new NeutralQuery(new NeutralCriteria("_id", "in", edOrgLineage)); Iterable<Entity> edorgs = repo.findAll(EntityNames.EDUCATION_ORGANIZATION, basicQuery); List<String> programs = new ArrayList<String>(); for (Entity e : edorgs) { Object value = e.getBody().get("programReference"); if (value != null) { if (List.class.isAssignableFrom(value.getClass())) { programs.addAll((List<String>) value); } else if (String.class.isAssignableFrom(value.getClass())) { programs.add((String) value); } } } validIds.addAll(getIds(EntityNames.STAFF_PROGRAM_ASSOCIATION, "programId", programs)); basicQuery = new NeutralQuery(new NeutralCriteria("educationOrgId", "in", edOrgLineage)); List<String> cohorts = (List<String>) repo.findAllIds(EntityNames.COHORT, basicQuery); validIds.addAll(getIds(EntityNames.STAFF_COHORT_ASSOCIATION, "cohortId", cohorts)); validIds.retainAll(staffIds); return validIds; } }
TransitiveStaffToStaffValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityName, Set<String> staffIds) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF, entityName, staffIds)) { return Collections.EMPTY_SET; } Set<String> validIds = new HashSet<String>(); NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria("staffReference", NeutralCriteria.CRITERIA_IN, staffIds)); basicQuery.setIncludeFields(Arrays.asList("educationOrganizationReference", "staffReference")); LOG.info("Attempting to validate transitively from staff to staff with ids {}", staffIds); injectEndDateQuery(basicQuery); Iterable<Entity> edOrgAssoc = repo.findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, basicQuery); Map<String, Set<String>> staffEdorgMap = new HashMap<String, Set<String>>(); populateMapFromMongoResponse(staffEdorgMap, edOrgAssoc); Set<String> edOrgLineage = getStaffEdOrgLineage(); if (edOrgLineage.isEmpty() || staffEdorgMap.isEmpty()) { return Collections.EMPTY_SET; } for (Entry<String, Set<String>> entry : staffEdorgMap.entrySet()) { Set<String> tmpSet = new HashSet<String>(entry.getValue()); tmpSet.retainAll(edOrgLineage); if (tmpSet.size() != 0) { validIds.add(entry.getKey()); } } validIds.addAll(validateThrough(EntityNames.STAFF_PROGRAM_ASSOCIATION, "programId")); validIds.addAll(validateThrough(EntityNames.STAFF_COHORT_ASSOCIATION, "cohortId")); basicQuery = new NeutralQuery(new NeutralCriteria("_id", "in", edOrgLineage)); Iterable<Entity> edorgs = repo.findAll(EntityNames.EDUCATION_ORGANIZATION, basicQuery); List<String> programs = new ArrayList<String>(); for (Entity e : edorgs) { Object value = e.getBody().get("programReference"); if (value != null) { if (List.class.isAssignableFrom(value.getClass())) { programs.addAll((List<String>) value); } else if (String.class.isAssignableFrom(value.getClass())) { programs.add((String) value); } } } validIds.addAll(getIds(EntityNames.STAFF_PROGRAM_ASSOCIATION, "programId", programs)); basicQuery = new NeutralQuery(new NeutralCriteria("educationOrgId", "in", edOrgLineage)); List<String> cohorts = (List<String>) repo.findAllIds(EntityNames.COHORT, basicQuery); validIds.addAll(getIds(EntityNames.STAFF_COHORT_ASSOCIATION, "cohortId", cohorts)); validIds.retainAll(staffIds); return validIds; }  }
TransitiveStaffToStaffValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityName, Set<String> staffIds) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF, entityName, staffIds)) { return Collections.EMPTY_SET; } Set<String> validIds = new HashSet<String>(); NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria("staffReference", NeutralCriteria.CRITERIA_IN, staffIds)); basicQuery.setIncludeFields(Arrays.asList("educationOrganizationReference", "staffReference")); LOG.info("Attempting to validate transitively from staff to staff with ids {}", staffIds); injectEndDateQuery(basicQuery); Iterable<Entity> edOrgAssoc = repo.findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, basicQuery); Map<String, Set<String>> staffEdorgMap = new HashMap<String, Set<String>>(); populateMapFromMongoResponse(staffEdorgMap, edOrgAssoc); Set<String> edOrgLineage = getStaffEdOrgLineage(); if (edOrgLineage.isEmpty() || staffEdorgMap.isEmpty()) { return Collections.EMPTY_SET; } for (Entry<String, Set<String>> entry : staffEdorgMap.entrySet()) { Set<String> tmpSet = new HashSet<String>(entry.getValue()); tmpSet.retainAll(edOrgLineage); if (tmpSet.size() != 0) { validIds.add(entry.getKey()); } } validIds.addAll(validateThrough(EntityNames.STAFF_PROGRAM_ASSOCIATION, "programId")); validIds.addAll(validateThrough(EntityNames.STAFF_COHORT_ASSOCIATION, "cohortId")); basicQuery = new NeutralQuery(new NeutralCriteria("_id", "in", edOrgLineage)); Iterable<Entity> edorgs = repo.findAll(EntityNames.EDUCATION_ORGANIZATION, basicQuery); List<String> programs = new ArrayList<String>(); for (Entity e : edorgs) { Object value = e.getBody().get("programReference"); if (value != null) { if (List.class.isAssignableFrom(value.getClass())) { programs.addAll((List<String>) value); } else if (String.class.isAssignableFrom(value.getClass())) { programs.add((String) value); } } } validIds.addAll(getIds(EntityNames.STAFF_PROGRAM_ASSOCIATION, "programId", programs)); basicQuery = new NeutralQuery(new NeutralCriteria("educationOrgId", "in", edOrgLineage)); List<String> cohorts = (List<String>) repo.findAllIds(EntityNames.COHORT, basicQuery); validIds.addAll(getIds(EntityNames.STAFF_COHORT_ASSOCIATION, "cohortId", cohorts)); validIds.retainAll(staffIds); return validIds; }  @Override boolean canValidate(String entityType, boolean transitive); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityName, Set<String> staffIds); @Override SecurityUtil.UserContext getContext(); }
TransitiveStaffToStaffValidator extends AbstractContextValidator { @SuppressWarnings("unchecked") @Override public Set<String> validate(String entityName, Set<String> staffIds) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF, entityName, staffIds)) { return Collections.EMPTY_SET; } Set<String> validIds = new HashSet<String>(); NeutralQuery basicQuery = new NeutralQuery(new NeutralCriteria("staffReference", NeutralCriteria.CRITERIA_IN, staffIds)); basicQuery.setIncludeFields(Arrays.asList("educationOrganizationReference", "staffReference")); LOG.info("Attempting to validate transitively from staff to staff with ids {}", staffIds); injectEndDateQuery(basicQuery); Iterable<Entity> edOrgAssoc = repo.findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, basicQuery); Map<String, Set<String>> staffEdorgMap = new HashMap<String, Set<String>>(); populateMapFromMongoResponse(staffEdorgMap, edOrgAssoc); Set<String> edOrgLineage = getStaffEdOrgLineage(); if (edOrgLineage.isEmpty() || staffEdorgMap.isEmpty()) { return Collections.EMPTY_SET; } for (Entry<String, Set<String>> entry : staffEdorgMap.entrySet()) { Set<String> tmpSet = new HashSet<String>(entry.getValue()); tmpSet.retainAll(edOrgLineage); if (tmpSet.size() != 0) { validIds.add(entry.getKey()); } } validIds.addAll(validateThrough(EntityNames.STAFF_PROGRAM_ASSOCIATION, "programId")); validIds.addAll(validateThrough(EntityNames.STAFF_COHORT_ASSOCIATION, "cohortId")); basicQuery = new NeutralQuery(new NeutralCriteria("_id", "in", edOrgLineage)); Iterable<Entity> edorgs = repo.findAll(EntityNames.EDUCATION_ORGANIZATION, basicQuery); List<String> programs = new ArrayList<String>(); for (Entity e : edorgs) { Object value = e.getBody().get("programReference"); if (value != null) { if (List.class.isAssignableFrom(value.getClass())) { programs.addAll((List<String>) value); } else if (String.class.isAssignableFrom(value.getClass())) { programs.add((String) value); } } } validIds.addAll(getIds(EntityNames.STAFF_PROGRAM_ASSOCIATION, "programId", programs)); basicQuery = new NeutralQuery(new NeutralCriteria("educationOrgId", "in", edOrgLineage)); List<String> cohorts = (List<String>) repo.findAllIds(EntityNames.COHORT, basicQuery); validIds.addAll(getIds(EntityNames.STAFF_COHORT_ASSOCIATION, "cohortId", cohorts)); validIds.retainAll(staffIds); return validIds; }  @Override boolean canValidate(String entityType, boolean transitive); @SuppressWarnings("unchecked") @Override Set<String> validate(String entityName, Set<String> staffIds); @Override SecurityUtil.UserContext getContext();  }