Package org.geomajas.layer.feature

Examples of org.geomajas.layer.feature.InternalFeature


  @DirtiesContext
  public void testSaveOrUpdateCreateFeature() throws Exception {
    Filter filter;
    List<InternalFeature> oldFeatures;
    List<InternalFeature> newFeatures;
    InternalFeature feature;
    CoordinateReferenceSystem crs = beanLayer.getCrs();
    GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel());
    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);
    newFeatures.add(feature);
    layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
    filter = filterService.createFidFilter(new String[]{"4"});
    oldFeatures = layerService.getFeatures(LAYER_ID,
        crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
View Full Code Here


  @DirtiesContext
  public void testSaveOrUpdateUpdateArea() throws Exception {
    Filter filter;
    List<InternalFeature> oldFeatures;
    List<InternalFeature> newFeatures;
    InternalFeature feature;
    CoordinateReferenceSystem crs = beanLayer.getCrs();

    login("marino");
    // should be able to update feature "2"
    filter = filterService.createFidFilter(new String[]{"2"});
    oldFeatures = layerService.getFeatures(LAYER_ID, crs, filter, null,
        VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
    Assert.assertEquals(1, oldFeatures.size());
    feature = oldFeatures.get(0);
    newFeatures = new ArrayList<InternalFeature>();
    feature = feature.clone();
    newFeatures.add(feature);
    feature.getAttributes().put(STRING_ATTR, new StringAttribute("changed"));
    layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
    // should not be able to update feature "3"
    filter = filterService.createFidFilter(new String[]{"3"});
    oldFeatures = layerService.getFeatures(LAYER_ID, crs, filter, null,
        VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
    Assert.assertEquals(1, oldFeatures.size());
    feature = oldFeatures.get(0);
    newFeatures = new ArrayList<InternalFeature>();
    feature = feature.clone();
    newFeatures.add(feature);
    feature.getAttributes().put(STRING_ATTR, new StringAttribute("changed"));
    try {
      layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
      Assert.fail("update area not checked when updating");
    } catch (GeomajasException ge) {
      Assert.assertEquals(ExceptionCode.FEATURE_UPDATE_PROHIBITED, ge.getExceptionCode());
View Full Code Here

  @DirtiesContext
  public void testSaveOrUpdateDeleteArea() throws Exception {
    Filter filter;
    List<InternalFeature> oldFeatures;
    List<InternalFeature> newFeatures;
    InternalFeature feature;
    CoordinateReferenceSystem crs = beanLayer.getCrs();

    login("marino");
    // should not be able to delete feature "2"
    filter = filterService.createFidFilter(new String[]{"2"});
View Full Code Here

  @DirtiesContext
  public void testSaveOrUpdateCreateArea() throws Exception {
    Filter filter;
    List<InternalFeature> oldFeatures;
    List<InternalFeature> newFeatures;
    InternalFeature feature;
    CoordinateReferenceSystem crs = beanLayer.getCrs();
    GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel());
    Geometry geometry;

    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);
    newFeatures.add(feature);
    layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
    filter = filterService.createFidFilter(new String[]{"4"});
    oldFeatures = layerService.getFeatures(LAYER_ID,
        crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
View Full Code Here

    Authentication auth2 = getAuthentication(1); // base, allow all
    authentications.add(auth1);
    authentications.add(auth2);
    securityContext.setAuthentications("token", authentications);

    InternalFeature feature = new InternalFeatureImpl();
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    feature.setAttributes(attributes);
    attributes.put(ATTRIBUTE_ID, new StringAttribute("bla"));
    Assert.assertTrue(securityContext.isFeatureVisible(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature, feature));
    Assert.assertTrue(securityContext.isFeatureDeleteAuthorized(LAYER_ID, feature));
View Full Code Here

    Authentication auth2 = getFeatureAuthentication();
    authentications.add(auth1);
    authentications.add(auth2);
    securityContext.setAuthentications("token", authentications);

    InternalFeature feature = new InternalFeatureImpl();
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    feature.setAttributes(attributes);
    attributes.put(ATTRIBUTE_ID, new StringAttribute("bla"));
    Assert.assertTrue(securityContext.isFeatureVisible(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature, feature));
    Assert.assertTrue(securityContext.isFeatureDeleteAuthorized(LAYER_ID, feature));
View Full Code Here

    Authentication auth2 = getFeatureAuthentication();
    authentications.add(auth1);
    authentications.add(auth2);
    securityContext.setAuthentications("token", authentications);

    InternalFeature feature = new InternalFeatureImpl();
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    feature.setAttributes(attributes);
    attributes.put(ATTRIBUTE_ID, new StringAttribute("bla"));
    Assert.assertTrue(securityContext.isFeatureVisible(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature, feature));
    Assert.assertTrue(securityContext.isFeatureDeleteAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureCreateAuthorized(LAYER_ID, feature));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("vis"));
    Assert.assertFalse(securityContext.isFeatureVisible(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature, feature));
    Assert.assertTrue(securityContext.isFeatureDeleteAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureCreateAuthorized(LAYER_ID, feature));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("cre"));
    Assert.assertTrue(securityContext.isFeatureVisible(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature, feature));
    Assert.assertTrue(securityContext.isFeatureDeleteAuthorized(LAYER_ID, feature));
    Assert.assertFalse(securityContext.isFeatureCreateAuthorized(LAYER_ID, feature));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("upd"));
    Assert.assertTrue(securityContext.isFeatureVisible(LAYER_ID, feature));
    Assert.assertFalse(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature, feature));
    Assert.assertTrue(securityContext.isFeatureDeleteAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureCreateAuthorized(LAYER_ID, feature));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("org"));
    Assert.assertTrue(securityContext.isFeatureVisible(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature));
    Assert.assertFalse(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature, feature));
    Assert.assertTrue(securityContext.isFeatureDeleteAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureCreateAuthorized(LAYER_ID, feature));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("new"));
    Assert.assertTrue(securityContext.isFeatureVisible(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature));
    Assert.assertFalse(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature, feature));
    Assert.assertTrue(securityContext.isFeatureDeleteAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureCreateAuthorized(LAYER_ID, feature));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("del"));
    Assert.assertTrue(securityContext.isFeatureVisible(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureUpdateAuthorized(LAYER_ID, feature, feature));
    Assert.assertFalse(securityContext.isFeatureDeleteAuthorized(LAYER_ID, feature));
    Assert.assertTrue(securityContext.isFeatureCreateAuthorized(LAYER_ID, feature));
View Full Code Here

* @author Joachim Van der Auwera
*/
public class SaveOrUpdateCreateStep 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) {
      // create new feature
      String layerId = context.get(PipelineCode.LAYER_ID_KEY, String.class);
      VectorLayer layer = context.get(PipelineCode.LAYER_KEY, VectorLayer.class);
      FeatureModel featureModel = layer.getFeatureModel();
      if (securityContext.isFeatureCreateAuthorized(layerId, newFeature)) {
        Object feature;
        if (newFeature.getId() == null) {
          feature = featureModel.newInstance();
        } else {
          feature = featureModel.newInstance(newFeature.getId());
        }
        context.put(PipelineCode.FEATURE_DATA_OBJECT_KEY, feature);
        context.put(PipelineCode.IS_CREATE_KEY, true);
      } else {
        throw new GeomajasSecurityException(ExceptionCode.FEATURE_CREATE_PROHIBITED, securityContext
View Full Code Here

  public void testGetFeaturesLazy() throws Exception {
    List<InternalFeature> features = layerService.getFeatures(LAYER_ID,
        geoService.getCrs(beanLayer.getLayerInfo().getCrs()), null, null,
        VectorLayerService.FEATURE_INCLUDE_NONE);
    Assert.assertEquals(3, features.size());
    InternalFeature feature = features.get(0);
    Assert.assertNotNull(feature.getId());
    Assert.assertNull(feature.getGeometry());
    Assert.assertNull(feature.getAttributes());
    Assert.assertNull(feature.getLabel());
    Assert.assertNull(feature.getStyleInfo());
  }
View Full Code Here

    Filter filter = filterService.createFidFilter(new String[]{"3"});
    CoordinateReferenceSystem crs = geoService.getCrs(beanLayer.getLayerInfo().getCrs());
    List<InternalFeature> oldFeatures = layerService.getFeatures(LAYER_ID,
        crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
    Assert.assertEquals(1, oldFeatures.size());
    InternalFeature feature = oldFeatures.get(0);
    List<InternalFeature> newFeatures = new ArrayList<InternalFeature>();
    feature = feature.clone();
    feature.getAttributes().put(STRING_ATTR, new StringAttribute("changed"));
    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

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.