예제 #1
0
파일: Postgres.java 프로젝트: n-/baleen
  private void processCoreferencedEntities(Integer docKey, List<Entity> entities)
      throws SQLException {
    Set<String> values = new HashSet<>();
    Set<String> externalIds = new HashSet<>();
    Set<String> geoJsons = new HashSet<>();

    Class<? extends Entity> type = null;

    for (Entity e : entities) {
      values.add(e.getValue());
      externalIds.add(e.getExternalId());

      if (e instanceof Location) {
        Location l = (Location) e;
        try {
          geoJsons.add(addCrsToGeoJSON(l.getGeoJson()));
        } catch (BaleenException ex) {
          getMonitor().warn("Unable to add CRS to GeoJSON", ex);
        }
      }

      type = getSuperclass(type, e.getClass());
    }

    Integer entityKey = executeEntityInsert(docKey, values, externalIds, type.getName());
    if (entityKey != null) {
      for (String geoJson : geoJsons) {
        executeEntityGeoInsert(entityKey, geoJson);
      }
    }
  }
  private List<String> getEntityIds(FSArray entityArray) {
    List<String> entities = new ArrayList<>();

    for (int x = 0; x < entityArray.size(); x++) {
      Entity ent = (Entity) entityArray.get(x);
      entities.add(ent.getExternalId());
    }

    return entities;
  }
  /**
   * Convert from an entity to a map.
   *
   * @param entity the entity to convert
   * @return a map containing the entity's fields (and history is required)
   */
  public Map<String, Object> convertEntity(Entity entity) {
    Map<String, Object> map = Maps.newHashMap();

    convertFeatures(map, entity);

    if (outputHistory && documentHistory != null) {
      Collection<HistoryEvent> events = documentHistory.getHistory(entity.getInternalId());
      convertHistory(map, events, entity.getInternalId());
    }
    putIfExists(map, fields.getExternalId(), entity.getExternalId());

    return map;
  }