コード例 #1
0
  /**
   * The type of filter that returns should be in a single Or filter OR(a,b,c) instead of ((a OR b)
   * or c)
   */
  @Test
  public void testUnrollFid() throws Exception {
    Set<FeatureId> fids = new HashSet();
    String fid1 = "station_no.1"; // exists
    String fid2 = "station_no.500"; // doesn't exists
    fids.add(ff.featureId(fid1));
    fids.add(ff.featureId(fid2));
    Id fidFilter = ff.id(fids);
    Filter unrolled = (Filter) fidFilter.accept(visitor, null);
    assertNotNull(unrolled);
    assertTrue(unrolled instanceof OrImpl);
    List<Filter> filters = ((OrImpl) unrolled).getChildren();
    assertEquals(2, filters.size());
    for (Filter f : filters) {
      assertTrue(f instanceof IsEqualsToImpl);
    }

    FeatureCollection<SimpleFeatureType, SimpleFeature> results =
        mapping.getSource().getFeatures(unrolled);
    assertEquals(1, getCount(results));

    FeatureIterator<SimpleFeature> features = results.features();
    SimpleFeature unmappedFeature = (SimpleFeature) features.next();

    features.close();

    assertNotNull(unmappedFeature);
    Object object = unmappedFeature.getProperty("station_no").getValue();
    assertEquals(fid1, object);
  }
コード例 #2
0
  /**
   * Implementation for tests of fid -> fid unmapping.
   *
   * @param idExpression
   * @throws Exception
   */
  private void checkUnrollIdExpression(Expression idExpression) throws Exception {
    AttributeMapping featureMapping = null;
    Name featurePath = mapping.getTargetFeature().getName();
    QName featureName = Types.toQName(featurePath);
    for (Iterator it = mapping.getAttributeMappings().iterator(); it.hasNext(); ) {
      AttributeMapping attMapping = (AttributeMapping) it.next();
      StepList targetXPath = attMapping.getTargetXPath();
      if (targetXPath.size() > 1) {
        continue;
      }
      Step step = (Step) targetXPath.get(0);
      if (featureName.equals(step.getName())) {
        featureMapping = attMapping;
        break;
      }
    }
    featureMapping.setIdentifierExpression(idExpression);
    this.visitor = new UnmappingFilterVisitor(this.mapping);

    // retrieve a single sample feature
    Feature sourceFeature = DataUtilities.first(mapping.getSource().getFeatures());
    String fid = sourceFeature.getIdentifier().toString();
    Id fidFilter = ff.id(Collections.singleton(ff.featureId(fid)));
    Filter unrolled = (Filter) fidFilter.accept(visitor, null);
    assertNotNull(unrolled);
    assertTrue(unrolled instanceof Id);

    FeatureCollection<SimpleFeatureType, SimpleFeature> results =
        mapping.getSource().getFeatures(unrolled);
    assertEquals(1, getCount(results));

    SimpleFeature unmappedFeature = DataUtilities.first(results);

    assertEquals(fid, unmappedFeature.getID());
  }
コード例 #3
0
  /**
   * Mapping specifies station_no --> wq_plus/@id. A FidFilter over wq_plus type should result in a
   * compare equals filter over the station_no attribute of wq_ir_results simple type.
   */
  @Test
  public void testUnrollFidMappedToAttribute() throws Exception {
    String fid = "station_no.1";
    Id fidFilter = ff.id(Collections.singleton(ff.featureId(fid)));

    Filter unrolled = (Filter) fidFilter.accept(visitor, null);
    assertNotNull(unrolled);

    FeatureCollection<SimpleFeatureType, SimpleFeature> results =
        mapping.getSource().getFeatures(unrolled);
    assertEquals(1, getCount(results));

    FeatureIterator<SimpleFeature> features = results.features();
    SimpleFeature unmappedFeature = (SimpleFeature) features.next();
    features.close();

    assertNotNull(unmappedFeature);
    Object object = unmappedFeature.getProperty("station_no").getValue();
    assertEquals(fid, object);
  }