Package org.geomajas.layer.feature

Examples of org.geomajas.layer.feature.InternalFeature


   
    // 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));
    feature.setGeometry(geometry);
    newFeatures.add(feature);
    layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);

    Iterator<FeatureBean> iterator =
        (Iterator<FeatureBean>) beanLayer.getElements(filterService.createTrueFilter(), 0, 0);
View Full Code Here


    Filter filter = filterService.createFidFilter(new String[]{"3"});
    List<InternalFeature> features = layerService.getFeatures(LAYER_ID,
        geoService.getCrs2(beanLayer.getLayerInfo().getCrs()), filter, null,
        VectorLayerService.FEATURE_INCLUDE_ALL);
    Assert.assertEquals(1, features.size());
    InternalFeature feature = features.get(0);
    Assert.assertEquals("3", feature.getId());
    Assert.assertNotNull(feature.getGeometry());
    Assert.assertNotNull(feature.getAttributes().get(STRING_ATTR));
  }
View Full Code Here

* @author Joachim Van der Auwera
*/
public class SaveOrUpdateDeleteStep extends AbstractSaveOrUpdateStep {

  public void execute(PipelineContext context, Object response) throws GeomajasException {
    InternalFeature newFeature = context.getOptional(PipelineCode.FEATURE_KEY, InternalFeature.class);
    if (null == newFeature) {
      // delete ?
      InternalFeature oldFeature = context.getOptional(PipelineCode.OLD_FEATURE_KEY, InternalFeature.class);
      if (null != oldFeature) {
        String layerId = context.get(PipelineCode.LAYER_ID_KEY, String.class);
        if (securityContext.isFeatureDeleteAuthorized(layerId, oldFeature)) {
          VectorLayer layer = context.get(PipelineCode.LAYER_KEY, VectorLayer.class);
          Object featureObj = layer.read(oldFeature.getId());
          if (null != featureObj) {
            Filter securityFilter = getSecurityFilter(layer,
                securityContext.getDeleteAuthorizedArea(layerId));
            if (securityFilter.evaluate(featureObj)) {
              layer.delete(oldFeature.getId());
            } else {
              throw new GeomajasSecurityException(ExceptionCode.FEATURE_DELETE_PROHIBITED,
                  oldFeature.getId(), securityContext.getUserId());
            }
          }
        } else {
          throw new GeomajasSecurityException(ExceptionCode.FEATURE_DELETE_PROHIBITED,
              oldFeature.getId(), securityContext.getUserId());
        }
      }
      context.setFinished(true); // stop pipeline execution
    }
  }
View Full Code Here

* @author Joachim Van der Auwera
*/
public class SaveOrUpdateUpdateStep extends AbstractSaveOrUpdateStep {

  public void execute(PipelineContext context, Object response) throws GeomajasException {
    InternalFeature oldFeature = context.getOptional(PipelineCode.OLD_FEATURE_KEY, InternalFeature.class);
    InternalFeature newFeature = context.get(PipelineCode.FEATURE_KEY, InternalFeature.class);
    if (null != oldFeature) {
      String layerId = context.get(PipelineCode.LAYER_ID_KEY, String.class);
      VectorLayer layer = context.get(PipelineCode.LAYER_KEY, VectorLayer.class);
      if (securityContext.isFeatureUpdateAuthorized(layerId, oldFeature, newFeature)) {
        if (null == context.getOptional(PipelineCode.FEATURE_DATA_OBJECT_KEY)) {
          context.put(PipelineCode.FEATURE_DATA_OBJECT_KEY, layer.read(newFeature.getId()));
        }
      } else {
        throw new GeomajasSecurityException(ExceptionCode.FEATURE_UPDATE_PROHIBITED,
            oldFeature.getId(), securityContext.getUserId());
      }
View Full Code Here

  public void setId(String id) {
    this.id = id;
  }

  public void execute(PipelineContext context, Object response) throws GeomajasException {
    InternalFeature oldFeature = context.getOptional(PipelineCode.OLD_FEATURE_KEY, InternalFeature.class);
    if (null != oldFeature) {
      InternalFeature newFeature = context.get(PipelineCode.FEATURE_KEY, InternalFeature.class);
      if (null == oldFeature.getId() || !oldFeature.getId().equals(newFeature.getId())) {
        int index = context.get(PipelineCode.INDEX_KEY, Integer.class);
        throw new GeomajasException(ExceptionCode.FEATURE_ID_MISMATCH, index);
      }
    }
  }
View Full Code Here

* @author Joachim Van der Auwera
*/
public class SaveOrUpdateSaveStep extends AbstractSaveOrUpdateStep {

  public void execute(PipelineContext context, Object response) throws GeomajasException {
    InternalFeature newFeature = context.getOptional(PipelineCode.FEATURE_KEY, InternalFeature.class);
    Object feature = context.get(PipelineCode.FEATURE_DATA_OBJECT_KEY);
    String layerId = context.get(PipelineCode.LAYER_ID_KEY, String.class);
    VectorLayer layer = context.get(PipelineCode.LAYER_KEY, VectorLayer.class);
    FeatureModel featureModel = layer.getFeatureModel();
    Boolean isCreateObject = context.getOptional(PipelineCode.IS_CREATE_KEY, Boolean.class);
    boolean isCreate  = false;
    if (null != isCreateObject && isCreateObject) {
      isCreate = true;
    }

    // Assure only writable attributes are set
    Map<String, Attribute> requestAttributes = newFeature.getAttributes();
    Map<String, Attribute> filteredAttributes = new HashMap<String, Attribute>();
    if (null != requestAttributes) {
      for (Map.Entry<String, Attribute> entry : requestAttributes.entrySet()) {
        String key = entry.getKey();
        if (securityContext.isAttributeWritable(layerId, newFeature, key)) {
          filteredAttributes.put(key, entry.getValue());
        }
      }
    }
    featureModel.setAttributes(feature, filteredAttributes);

    if (newFeature.getGeometry() != null) {
      featureModel.setGeometry(feature, newFeature.getGeometry());
    }

    Filter securityFilter;
    if (isCreate) {
      securityFilter = getSecurityFilter(layer, securityContext.getCreateAuthorizedArea(layerId));
    } else {
      securityFilter = getSecurityFilter(layer, securityContext.getUpdateAuthorizedArea(layerId));
    }
    if (securityFilter.evaluate(feature)) {
      context.put(PipelineCode.FEATURE_DATA_OBJECT_KEY, layer.saveOrUpdate(feature));
      if (isCreate) {
        newFeature.setId(featureModel.getId(feature));
      }
    } else {
      if (isCreate) {
        throw new GeomajasSecurityException(ExceptionCode.FEATURE_CREATE_PROHIBITED,
            securityContext.getUserId());
      } else {
        throw new GeomajasSecurityException(ExceptionCode.FEATURE_UPDATE_PROHIBITED, newFeature.getId(),
            securityContext.getUserId());       
      }
    }
  }
View Full Code Here

    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());
    Assert.assertTrue(internalFeature.isEditable());
  }
View Full Code Here

    Assert.assertTrue(internalFeature.isEditable());
  }

  @Test
  public void toDto() throws GeomajasException {
    InternalFeature internalFeature = new InternalFeatureImpl();
    Assert.assertNotNull(converterService.toDto(internalFeature));

    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());
View Full Code Here

    Assert.assertEquals("", recorder.matches(CacheCategory.FEATURE,
        "Got item from cache"));

    // delete one item
    recorder.clear();
    InternalFeature org = features.get(2);
    List<InternalFeature> orgFeatures = new ArrayList<InternalFeature>();
    orgFeatures.add(org);
    List<InternalFeature> updFeatures = new ArrayList<InternalFeature>();
    updFeatures.add(null);
    vectorLayerService.saveOrUpdate(LAYER_BEANS, geoService.getCrs2("EPSG:4326"), orgFeatures, updFeatures);
View Full Code Here

    cache = (DummyCacheService) cacheManager.getCacheForTesting(LAYER_BEANS, CacheCategory.FEATURE);
    Assert.assertEquals(1, cache.size());
    FeaturesCacheContainer fcc = (FeaturesCacheContainer) cache.getObject();
    List<InternalFeature> features = fcc.getFeatures();
    Assert.assertEquals(3, features.size());
    InternalFeature feature = features.get(2);
    Assert.assertEquals(2, feature.getGeometry().getCoordinates()[0].x, DELTA);
    Assert.assertEquals(1, feature.getGeometry().getCoordinates()[0].y, DELTA);

    // get tile again, should put tile in cache again but use features and string from cache
    recorder.clear();
    tile = vectorLayerService.getTile(tmd);
    Assert.assertNotNull(tile);
    Assert.assertEquals(
        "<g id=\"beans.features.1-1-1\"><g style=\"fill:#995500;fill-opacity:0.6;stroke:#995500;" +
            "stroke-opacity:0.3;stroke-width:1px;\" id=\"beans.features.1-1-1.0\">" +
            "<path fill-rule=\"evenodd\" d=\"M445278 0l0 -334111 222639 0 0 334111 -222639 0 Z\" " +
            "id=\"2\"></path><path fill-rule=\"evenodd\" " +
            "d=\"M222639 -111325l0 -111359 556597 0 -111319 111359 -445278 0 Z\" id=\"3\"/></g></g>",
        tile.getFeatureContent());
    Assert.assertEquals("", recorder.matches(CacheCategory.TILE, "Put item in cache"));
    Assert.assertEquals("", recorder.matches(CacheCategory.FEATURE, "Got item from cache"));

    cache = (DummyCacheService) cacheManager.getCacheForTesting(LAYER_BEANS, CacheCategory.FEATURE);
    Assert.assertEquals(1, cache.size());
    fcc = (FeaturesCacheContainer) cache.getObject();
    features = fcc.getFeatures();
    Assert.assertEquals(3, features.size());
    feature = features.get(2);
    Assert.assertEquals(2, feature.getGeometry().getCoordinates()[0].x, DELTA);
    Assert.assertEquals(1, feature.getGeometry().getCoordinates()[0].y, DELTA);

  }
View Full Code Here

TOP

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

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.