Пример #1
0
  /**
   * Returns a new id for a feature of the given type.
   *
   * @param ft (mapped) feature type (irrelevant for this generator)
   * @param ta datastore transaction (context)
   * @return a new feature id.
   * @throws IdGenerationException
   */
  @Override
  public FeatureId getNewId(MappedFeatureType ft, DatastoreTransaction ta)
      throws IdGenerationException {

    FeatureId fid = null;

    MappedGMLId fidDefinition = ft.getGMLId();
    if (fidDefinition.getKeySize() != 1) {
      throw new IdGenerationException(
          "Cannot generate feature ids that are mapped to "
              + fidDefinition.getKeySize()
              + " columns.");
    }
    if (fidDefinition.getIdFields()[0].getType() == Types.VARCHAR
        || fidDefinition.getIdFields()[0].getType() == Types.CHAR) {
      String uuidString =
          "UUID_"
              + (macSet
                  ? new UUID(mac, (long) (Math.random() * Long.MAX_VALUE))
                  : UUID.randomUUID());
      fid = new FeatureId(ft, new Object[] {uuidString});
    } else {
      // TODO add handling of NUMERIC columns (>= 128 bit)
      throw new IdGenerationException(
          "UUIDGenerator may currently only be used for VARCHAR fields.");
    }
    return fid;
  }
Пример #2
0
  GmlResult handleRequest(GetGmlObject request) {
    if (!config.hasUniquePrefixMapping()) {
      return new GmlResult(
          request, new InconsistentRequestException(get("WFS_CONF_FT_PREFICES_NOT_UNIQUE2")));
    }
    String objectId = request.getObjectId();
    MappedFeatureType type = config.getFeatureType(objectId);

    if (type == null) {
      LOG.logDebug("The GML type could not be determined for the incoming GMLObjectID");
      return new GmlResult(
          request,
          new InvalidParameterValueException("getgmlobject", get("WFS_NO_SUCH_FEATURE", objectId)));
    }

    if (type.isAbstract()) {
      String msg = Messages.getMessage("WFS_FEATURE_TYPE_ABSTRACT", type.getName());
      return new GmlResult(request, new OGCWebServiceException("getgmlobject", msg));
    }
    if (!type.isVisible()) {
      String msg = Messages.getMessage("WFS_FEATURE_TYPE_INVISIBLE", type.getName());
      return new GmlResult(request, new OGCWebServiceException("getgmlobject", msg));
    }

    int idx = objectId.indexOf("_GEOM_");
    int geom = -1;
    if (idx > 0) {
      try {
        geom = parseInt(objectId.substring(idx + 6));
      } catch (NumberFormatException e) {
        LOG.logDebug("Stack trace: ", e);
        return new GmlResult(
            request,
            new InvalidParameterValueException(
                "getgmlobject", get("WFS_NO_SUCH_FEATURE", request.getObjectId())));
      }
      objectId = objectId.substring(0, idx);
      LOG.logDebug("Trying to find geometry object number " + geom);
    }

    LOG.logDebug("Feature ID: ", objectId);

    Set<FeatureId> set = singleton(new FeatureId(objectId));
    Filter filter = new FeatureFilter(new ArrayList<FeatureId>(set));

    Datastore ds = type.getGMLSchema().getDatastore();

    Query q =
        new Query(
            null,
            null,
            null,
            null,
            null,
            new QualifiedName[] {type.getName()},
            null,
            null,
            filter,
            null,
            -1,
            -1);
    try {
      FeatureCollection col = ds.performQuery(q, new MappedFeatureType[] {type});
      if (col.size() == 0) {
        return new GmlResult(
            request,
            new InvalidParameterValueException(
                "getgmlobject", get("WFS_NO_SUCH_FEATURE", request.getObjectId())));
      }
      Feature feature = col.getFeature(0);

      // different formats are not supported anyway, so just use the first one
      FormatType format =
          config.getFeatureTypeList().getFeatureType(type.getName()).getOutputFormats()[0];

      if (geom > -1) {
        try {
          return new GmlResult(request, feature.getGeometryPropertyValues()[geom], format);
        } catch (ArrayIndexOutOfBoundsException e) {
          return new GmlResult(
              request,
              new InvalidParameterValueException(
                  "getgmlobject", get("WFS_NO_SUCH_FEATURE", request.getObjectId())));
        }
      }

      return new GmlResult(request, feature, format);
    } catch (DatastoreException e) {
      LOG.logDebug("Stack trace: ", e);
      return new GmlResult(request, new OGCWebServiceException("getgmlobject", e.getMessage()));
    } catch (UnknownCRSException e) {
      LOG.logDebug("Stack trace: ", e);
      return new GmlResult(request, new OGCWebServiceException("getgmlobject", e.getMessage()));
    }
  }
Пример #3
0
  /**
   * Handles a {@link GetFeature} request by delegating the contained {@link Query} objects to
   * different Threads.
   *
   * <p>If at least one query fails an exception will be thrown and all running threads will be
   * stopped.
   *
   * @param getFeature
   * @return result of the request
   * @throws OGCWebServiceException
   */
  FeatureResult handleRequest(GetFeature getFeature) throws OGCWebServiceException {
    LOG.entering();

    if (getFeature.getMaxFeatures() > maxFeatures) {
      getFeature.setMaxFeatures(maxFeatures);
    }

    LOG.logDebug("maxFeatures " + getFeature.getMaxFeatures());

    Query[] queries = getFeature.getQuery();
    List<Callable<FeatureCollection>> queryTasks =
        new ArrayList<Callable<FeatureCollection>>(queries.length);

    for (Query query : queries) {
      QualifiedName[] ftNames = query.getTypeNames();
      // TODO joins between feature types
      if (ftNames.length > 1) {
        String msg =
            "Multiple feature types in a Query (joins over feature types) "
                + "are not the supported by this WFS implementation.";
        throw new OGCWebServiceException(this.getClass().getName(), msg);
      }
      QualifiedName ftName = ftNames[0];

      MappedFeatureType ft = this.service.getMappedFeatureType(ftName);

      if (ft == null) {
        String msg = Messages.getMessage("WFS_FEATURE_TYPE_UNKNOWN", ftName);
        throw new OGCWebServiceException(this.getClass().getName(), msg);
      }
      if (!ft.isVisible()) {
        String msg = Messages.getMessage("WFS_FEATURE_TYPE_INVISIBLE", ftName);
        throw new OGCWebServiceException(this.getClass().getName(), msg);
      }

      // check and normalized requested SRS
      String srsName = query.getSrsName();
      if (srsName != null) {
        WFSFeatureType wfsFT =
            this.service.getCapabilities().getFeatureTypeList().getFeatureType(ftName);
        String normalizedSrsName = normalizeSrsName(srsName);
        query.setSrsName(normalizedSrsName);

        if (!(wfsFT.supportsSrs(normalizedSrsName))) {
          String msg = Messages.getMessage("WFS_FEATURE_TYPE_SRS_UNSUPPORTED", ftName, srsName);
          throw new OGCWebServiceException(this.getClass().getName(), msg);
        }
      }

      QueryTask task = new QueryTask(query, ft);
      queryTasks.add(task);
    }

    WFSConfiguration conf = (WFSConfiguration) service.getCapabilities();
    long timeout = conf.getDeegreeParams().getRequestTimeLimit() * 1000;
    if (timeout > MAX_TIMEOUT_MILLIS) {
      // limit max timeout
      timeout = MAX_TIMEOUT_MILLIS;
    }

    List<ExecutionFinishedEvent<FeatureCollection>> finishedEvents = null;
    try {
      finishedEvents = Executor.getInstance().performSynchronously(queryTasks, timeout);
    } catch (InterruptedException e) {
      String msg = "Exception occured while waiting for the GetFeature results: " + e.getMessage();
      throw new OGCWebServiceException(this.getClass().getName(), msg);
    }

    // use id of the request as id of the result feature collection
    // to allow identification of the original request that produced
    // the feature collection
    FeatureCollection fc = null;
    if (getFeature.getResultType() == RESULT_TYPE.RESULTS) {
      fc = mergeResults(getFeature.getId(), finishedEvents);
    } else {
      fc = mergeHits(getFeature.getId(), finishedEvents);
    }

    FeatureResult fr = new FeatureResult(getFeature, fc);

    LOG.exiting();
    return fr;
  }