示例#1
0
  public ValueCollectionType run(GetPropertyValueType request) throws WFSException {
    // check the request resolve
    if (request.isSetResolve() && !ResolveValueType.NONE.equals(request.getResolve())) {
      throw new WFSException(request, "Only resolve = none is supported", "InvalidParameterValue")
          .locator("resolve");
    }

    if (request.getValueReference() == null) {
      throw new WFSException(request, "No valueReference specified", "MissingParameterValue")
          .locator("valueReference");
    }

    // do a getFeature request
    GetFeatureType getFeature = Wfs20Factory.eINSTANCE.createGetFeatureType();
    getFeature.getAbstractQueryExpression().add(request.getAbstractQueryExpression());

    FeatureCollectionType fc =
        (FeatureCollectionType) delegate.run(GetFeatureRequest.adapt(getFeature)).getAdaptee();

    QueryType query = (QueryType) request.getAbstractQueryExpression();
    QName typeName = (QName) query.getTypeNames().iterator().next();
    FeatureTypeInfo featureType =
        catalog.getFeatureTypeByName(typeName.getNamespaceURI(), typeName.getLocalPart());

    try {
      // look for the attribute type
      AttributeTypeInfo attribute = null;
      for (AttributeTypeInfo at : featureType.attributes()) {
        if (at.getName().equals(request.getValueReference())) {
          attribute = at;
          break;
        }
      }
      if (attribute == null) {
        throw new WFSException(request, "No such attribute: " + request.getValueReference());
      }

      AttributeDescriptor descriptor = attribute.getAttribute();
      if (descriptor == null) {
        PropertyDescriptor pd = featureType.getFeatureType().getDescriptor(attribute.getName());
        if (pd instanceof AttributeDescriptor) {
          descriptor = (AttributeDescriptor) pd;
        }
      }

      if (descriptor == null) {
        throw new WFSException(request, "Unable to obtain descriptor for " + attribute.getName());
      }

      // create value collection type from feature collection
      ValueCollectionType vc = Wfs20Factory.eINSTANCE.createValueCollectionType();
      vc.setTimeStamp(fc.getTimeStamp());
      vc.setNumberMatched(fc.getNumberMatched());
      vc.setNumberReturned(fc.getNumberReturned());
      vc.getMember().add(new PropertyValueCollection(fc.getMember().iterator().next(), descriptor));
      // TODO: next/previous but point back at GetPropertyValue
      // vc.setNext(fc.getNext());
      // vc.setPrevious(fc.getPrevious());
      return vc;
    } catch (IOException e) {
      throw new WFSException(request, e);
    }
  }
  public AbstractMappingFeatureIterator(
      AppSchemaDataAccess store,
      FeatureTypeMapping mapping,
      Query query,
      Query unrolledQuery,
      boolean removeQueryLimitIfDenormalised,
      boolean hasPostFilter)
      throws IOException {
    this.store = store;
    this.attf = new AppSchemaFeatureFactoryImpl();

    this.mapping = mapping;

    // validate and initialise resolve options
    Hints hints = query.getHints();
    ResolveValueType resolveVal = (ResolveValueType) hints.get(Hints.RESOLVE);
    boolean resolve =
        ResolveValueType.ALL.equals(resolveVal) || ResolveValueType.LOCAL.equals(resolveVal);
    if (!resolve && resolveVal != null && !ResolveValueType.NONE.equals(resolveVal)) {
      throw new IllegalArgumentException(
          "Resolve:" + resolveVal.getName() + " is not supported in app-schema!");
    }
    Integer atd = (Integer) hints.get(Hints.ASSOCIATION_TRAVERSAL_DEPTH);
    resolveDepth = resolve ? atd == null ? 0 : atd : 0;
    resolveTimeOut = (Integer) hints.get(Hints.RESOLVE_TIMEOUT);

    namespaces = mapping.getNamespaces();
    namespaceAwareFilterFactory = new FilterFactoryImplNamespaceAware(namespaces);

    Object includeProps = query.getHints().get(Query.INCLUDE_MANDATORY_PROPS);
    includeMandatory = includeProps instanceof Boolean && ((Boolean) includeProps).booleanValue();

    if (mapping.isDenormalised()) {
      // we need to disable the max number of features retrieved so we can
      // sort them manually just in case the data is denormalised.  Do this
      // by overriding the max features for this query just before executing
      // it.  Note that the original maxFeatures value was copied to
      // this.requestMaxFeatures in the constructor and will be re-applied after
      // the rows have been returned
      if (removeQueryLimitIfDenormalised) {
        this.dataMaxFeatures = 1000000;
        if (hasPostFilter) {
          // true max features will be handled in PostFilteringMappingFeatureIterator
          this.requestMaxFeatures = 1000000;
        } else {
          this.requestMaxFeatures = query.getMaxFeatures();
        }
      } else {
        this.dataMaxFeatures = query.getMaxFeatures();
        this.requestMaxFeatures = query.getMaxFeatures();
      }
    } else {
      this.requestMaxFeatures = query.getMaxFeatures();
      this.dataMaxFeatures = query.getMaxFeatures();
    }

    if (unrolledQuery == null) {
      unrolledQuery = getUnrolledQuery(query);
      if (query instanceof JoiningQuery && unrolledQuery instanceof JoiningQuery) {
        ((JoiningQuery) unrolledQuery).setRootMapping(((JoiningQuery) query).getRootMapping());
      }
    }

    // NC - property names
    if (query != null && query.getProperties() != null) {
      setPropertyNames(query.getProperties());
    } else {
      setPropertyNames(null); // we need the actual property names (not surrogates) to do
      // this...
    }
    xpathAttributeBuilder = new XPath();
    xpathAttributeBuilder.setFeatureFactory(attf);
    initialiseSourceFeatures(mapping, unrolledQuery, query.getCoordinateSystemReproject());
    xpathAttributeBuilder.setFilterFactory(namespaceAwareFilterFactory);
  }