/**
  * Determine the districts based upon the EdOrgs supplied.
  *
  * <p>If an SEA is encountered, this is any LEA directly below the SEA. If an LEA or school is
  * encountered, this is the top-most LEA, i.e. the LEA directly associated with the SEA.
  *
  * @param edOrgs - EdOrgs to search
  * @return - List of district entity IDs
  */
 public List<String> getDistricts(Set<String> edOrgs) {
   NeutralQuery query =
       new NeutralQuery(
           new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, edOrgs, false));
   Set<String> entities = new HashSet<String>();
   for (Entity entity : repo.findAll(EntityNames.EDUCATION_ORGANIZATION, query)) {
     if (helper.isLEA(entity)) {
       List<Entity> topLEAs = helper.getTopLEAOfEdOrg(entity);
       if (topLEAs != null) {
         for (Entity topLEA : topLEAs) {
           entities.add(topLEA.getEntityId());
         }
       }
     } else if (helper.isSchool(entity)) {
       List<Entity> topLEAs = helper.getTopLEAOfEdOrg(entity);
       if (topLEAs != null) {
         for (Entity topLEA : topLEAs) {
           entities.add(topLEA.getEntityId());
         }
       }
     } else { // isSEA
       entities.addAll(getDirectChildLEAsOfEdOrg(entity));
     }
   }
   return new ArrayList<String>(entities);
 }
  private Set<String> getDirectChildLEAsOfEdOrg(String edOrgId) {
    Set<String> toReturn = new HashSet<String>();
    NeutralQuery query = new NeutralQuery(0);
    query.addCriteria(new NeutralCriteria("parentEducationAgencyReference", "=", edOrgId));

    for (Entity entity : repo.findAll(EntityNames.EDUCATION_ORGANIZATION, query)) {
      if (helper.isLEA(entity)) {
        toReturn.add(entity.getEntityId());
      }
    }
    return toReturn;
  }
  public List<String> getDirectSchoolsLineage(Entity principal, boolean getLineage) {
    Set<String> ids = getDirectEdorgs(principal);
    Iterable<Entity> edorgs =
        repo.findAll(
            EntityNames.EDUCATION_ORGANIZATION,
            new NeutralQuery(
                new NeutralCriteria(
                    ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids, false)));

    List<String> schools = new ArrayList<String>();
    for (Entity e : edorgs) {
      if (helper.isSchool(e)) {
        schools.add(e.getEntityId());
        if (getLineage) {
          schools.addAll(extractEdorgFromMeta(e));
        }
      }
    }

    return schools;
  }
 @SuppressWarnings("unchecked")
 public boolean isSchool(Entity entity) {
   // passing through
   return helper.isSchool(entity);
 }
 /**
  * Given an edorg entity, returns the SEA to which it belongs
  *
  * @param entity
  * @return SEA
  */
 public String getSEAOfEdOrg(Entity entity) {
   return helper.getSEAOfEdOrg(entity);
 }
 public boolean isSEA(Entity entity) {
   // passing through
   return helper.isSEA(entity);
 }