Package org.geomajas.layer.feature

Examples of org.geomajas.layer.feature.Feature


  public void testPersistAddFeatureTransaction() throws Exception {
    PersistTransactionRequest request = new PersistTransactionRequest();
    request.setCrs(CRS);
    FeatureTransaction featureTransaction = new FeatureTransaction();
    featureTransaction.setLayerId(LAYER_ID);
    Feature feature = new Feature();
    GeometryFactory factory = new GeometryFactory();
    Geometry circle =
        dtoConverter.toDto(geoService.createCircle(factory.createPoint(new Coordinate(0, 0)), 10, 10));
    feature.setGeometry(circle);
    featureTransaction.setNewFeatures(new Feature[] {feature});
    request.setFeatureTransaction(featureTransaction);
    PersistTransactionResponse response = (PersistTransactionResponse) dispatcher.execute(
        PersistTransactionRequest.COMMAND, request, null, "en");
    if (response.isError()) {
View Full Code Here


    SearchByPointResponse sbp = (SearchByPointResponse) response;
    Map<String, List<Feature>> map = sbp.getFeatureMap();
    Assert.assertNotNull(map);
    List<Feature> features = map.get(layer);
    Assert.assertEquals(1, features.size());
    Feature feature = features.get(0);
    Assert.assertEquals("belt.2", feature.getId());
    Assert.assertEquals("Tropical", feature.getAttributes().get("BELT").getValue());
    Assert.assertEquals("2", feature.getAttributes().get("FID").getValue());
  }
View Full Code Here

  private Feature toDto(SimpleFeature feature) {
    if (feature == null) {
      return null;
    }
    Feature dto = new Feature(feature.getID());

    HashMap<String, Attribute> attributes = new HashMap<String, Attribute>();

    for (AttributeDescriptor desc : feature.getType().getAttributeDescriptors()) {
      Object obj = feature.getAttribute(desc.getName());
      if (null != obj) {
        attributes.put(desc.getLocalName(), new StringAttribute(obj.toString()));
      }
    }
    dto.setAttributes(attributes);
    dto.setId(feature.getID());

    dto.setUpdatable(false);
    dto.setDeletable(false);
    return dto;

  }
View Full Code Here

    Geometry geometry;

    login("marino");
    oldFeatures = new ArrayList<InternalFeature>();
    newFeatures = new ArrayList<InternalFeature>();
    feature = converterService.toInternal(new Feature());
    feature.setId("4");
    feature.setLayer(beanLayer);
    // feature needs a geometry or exceptions all over
    geometry = geometryFactory.createPoint(new Coordinate(1.5, 1.5));
    feature.setGeometry(geometry);   
    newFeatures.add(feature);
    try {
      layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
      Assert.fail("create should have failed");
    } catch (GeomajasSecurityException gse) {
      Assert.assertEquals(ExceptionCode.FEATURE_CREATE_PROHIBITED, gse.getExceptionCode());
    }
    filter = filterService.createFidFilter(new String[]{"4"});
    oldFeatures = layerService.getFeatures(LAYER_ID,
        crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
    Assert.assertEquals(0, oldFeatures.size());

    login("luc");
    oldFeatures = new ArrayList<InternalFeature>();
    newFeatures = new ArrayList<InternalFeature>();
    feature = converterService.toInternal(new Feature());
    feature.setId("4");
    feature.setLayer(beanLayer);
    // feature needs a geometry or exceptions all over
    geometry = geometryFactory.createPoint(new Coordinate(1.5, 1.5));
    feature.setGeometry(geometry);
View Full Code Here

    login("marino");
    // verify failing
    oldFeatures = new ArrayList<InternalFeature>();
    newFeatures = new ArrayList<InternalFeature>();
    feature = converterService.toInternal(new Feature());
    feature.setId("4");
    feature.setLayer(beanLayer);
    // feature needs a geometry or exceptions all over
    geometry = geometryFactory.createPoint(new Coordinate(5.5, 5.5));
    feature.setGeometry(geometry);
    newFeatures.add(feature);
    try {
      layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
      Assert.fail("create area not checked");
    } catch (GeomajasSecurityException gse) {
      Assert.assertEquals(ExceptionCode.FEATURE_CREATE_PROHIBITED, gse.getExceptionCode());
    }
    filter = filterService.createFidFilter(new String[]{"4"});
    oldFeatures = layerService.getFeatures(LAYER_ID,
        crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
    Assert.assertEquals(0, oldFeatures.size());
    // verify success
    oldFeatures = new ArrayList<InternalFeature>();
    newFeatures = new ArrayList<InternalFeature>();
    feature = converterService.toInternal(new Feature());
    feature.setId("4");
    feature.setLayer(beanLayer);
    // feature needs a geometry or exceptions all over
    geometry = geometryFactory.createPoint(new Coordinate(1.5, 1.5));
    feature.setGeometry(geometry);
View Full Code Here

   
    // Create first
    CoordinateReferenceSystem crs = geoService.getCrs(beanLayer.getLayerInfo().getCrs());
    List<InternalFeature> oldFeatures = new ArrayList<InternalFeature>();
    List<InternalFeature> newFeatures = new ArrayList<InternalFeature>();
    InternalFeature feature = converterService.toInternal(new Feature());
    feature.setId("4");
    feature.setLayer(beanLayer);
    // feature needs a geometry or exceptions all over
    GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel());
    Geometry geometry = geometryFactory.createPoint(new Coordinate(1.5, 1.5));
View Full Code Here

   */
  public Feature toDto(InternalFeature feature, int featureIncludes) throws GeomajasException {
    if (feature == null) {
      return null;
    }
    Feature dto = new Feature(feature.getId());
    if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES) != 0 && null != feature.getAttributes()) {
      // need to assure lazy attributes are converted to non-lazy attributes
      Map<String, Attribute> attributes = new HashMap<String, Attribute>();
      for (Map.Entry<String, Attribute> entry : feature.getAttributes().entrySet()) {
        Attribute value = entry.getValue();
        if (value instanceof LazyAttribute) {
          value = ((LazyAttribute) value).instantiate();
        }
        attributes.put(entry.getKey(), value);
      }
      dto.setAttributes(attributes);
    }
    if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_LABEL) != 0) {
      dto.setLabel(feature.getLabel());
    }
    if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_GEOMETRY) != 0) {
      dto.setGeometry(toDto(feature.getGeometry()));
    }
    if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_STYLE) != 0 && null != feature.getStyleInfo()) {
      dto.setStyleId(feature.getStyleInfo().getStyleId());
    }
    InternalFeatureImpl vFeature = (InternalFeatureImpl) feature;
    dto.setClipped(vFeature.isClipped());
    dto.setUpdatable(feature.isEditable());
    dto.setDeletable(feature.isDeletable());
    return dto;
  }
View Full Code Here

        List<InternalFeature> temp = layerService.getFeatures(layerId, mapCrs, f, null,
            request.getFeatureIncludes(), 0, request.getMax());
        if (temp.size() > 0) {
          List<Feature> features = new ArrayList<Feature>();
          for (InternalFeature feature : temp) {
            Feature dto = dtoConverterService.toDto(feature);
            dto.setCrs(mapCrsCode);
            features.add(dto);
          }
          response.addLayer(layerId, features);
        }
      }
View Full Code Here

  @Autowired
  private DtoConverterService converterService;

  @Test
  public void toInternal() throws GeomajasException {
    Feature feature = new Feature();
    Assert.assertNotNull(converterService.toInternal(feature));

    feature.setId("id");
    feature.setLabel("label");
    feature.setDeletable(true);
    feature.setUpdatable(true);

    InternalFeature internalFeature = converterService.toInternal(feature);
    Assert.assertEquals("id", internalFeature.getId());
    Assert.assertEquals("label", internalFeature.getLabel());
    Assert.assertTrue(internalFeature.isDeletable());
View Full Code Here

    internalFeature.setId("id");
    internalFeature.setLabel("label");
    internalFeature.setDeletable(true);
    internalFeature.setEditable(true);

    Feature feature = converterService.toDto(internalFeature);
    Assert.assertEquals("id", feature.getId());
    Assert.assertEquals("label", feature.getLabel());
    Assert.assertTrue(feature.isDeletable());
    Assert.assertTrue(feature.isUpdatable());
  }
View Full Code Here

TOP

Related Classes of org.geomajas.layer.feature.Feature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.