Package org.geomajas.layer.feature

Examples of org.geomajas.layer.feature.InternalFeature


    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.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));
  }
View Full Code Here


    Authentication auth2 = getAttributeAuthentication();
    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.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));
  }
View Full Code Here

    Authentication auth2 = getAttributeAuthentication();
    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.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("rea"));
    Assert.assertFalse(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("wri"));
    Assert.assertTrue(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertFalse(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));
  }
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.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("vis"));
    Assert.assertFalse(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertTrue(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));

    feature.getAttributes().put(ATTRIBUTE_ID, new StringAttribute("upd"));
    Assert.assertTrue(securityContext.isAttributeReadable(LAYER_ID, feature, ATTRIBUTE_ID));
    Assert.assertFalse(securityContext.isAttributeWritable(LAYER_ID, feature, ATTRIBUTE_ID));
  }
View Full Code Here

      return false;
    } else {
      if (!(obj instanceof InternalFeature)) {
        return false;
      }
      InternalFeature other = (InternalFeature) obj;
      return id.equals(other.getId());
    }
  }
View Full Code Here

      int count = 0;
      while (it.hasNext()) {
        log.debug("process feature");
        Object featureObj = it.next();
        Geometry geometry = layer.getFeatureModel().getGeometry(featureObj);
        InternalFeature feature = convertFeature(featureObj, geometry, layer, transformation,
            styleFilters, style.getLabelStyle(), featureIncludes);
        if (null != feature) {
          count++;
          if (count > offset) {
            features.add(feature);
View Full Code Here

   */
  private InternalFeature convertFeature(Object feature, Geometry geometry, VectorLayer layer,
      CrsTransform transformation, List<StyleFilter> styles, LabelStyleInfo labelStyle, int featureIncludes)
      throws GeomajasException {
    FeatureModel featureModel = layer.getFeatureModel();
    InternalFeature res = new InternalFeatureImpl();
    res.setId(featureModel.getId(feature));
    res.setLayer(layer);
    res.setGeometry(geometry); // in layer coordinate space for security checks
    res = attributeService.getAttributes(layer, res, feature); // includes security checks

    if (null != res) {
      // add and clear data according to the feature includes
      // unfortunately the data needs to be there for the security tests and can only be removed later
      if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_LABEL) != 0) {
        String labelAttr = labelStyle.getLabelAttributeName();
        Attribute attribute = featureModel.getAttribute(feature, labelAttr);
        if (null != attribute && null != attribute.getValue()) {
          res.setLabel(attribute.getValue().toString());
        }
      }

      // If allowed, add the geometry (transformed!) to the InternalFeature:
      if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_GEOMETRY) != 0) {
        Geometry transformed;
        if (null != transformation) {
          transformed = geoService.transform(geometry, transformation);
        } else {
          transformed = geometry;
        }
        res.setGeometry(transformed);
      } else {
        res.setGeometry(null);
      }

      // If allowed, add the style definition to the InternalFeature:
      if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_STYLE) != 0) {
        res.setStyleDefinition(findStyleFilter(feature, styles).getStyleDefinition());
      }

      // If allowed, add the attributes to the InternalFeature:
      if ((featureIncludes & VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES) == 0) {
        res.setAttributes(null);
      }
    }

    return res;
  }
View Full Code Here

  @Test
  public void testGetFeaturesAttributeAuthorization() throws Exception {
    List<InternalFeature> features;
    CoordinateReferenceSystem crs = beanLayer.getCrs();
    InternalFeature feature;

    login("luc");
    features = layerService.getFeatures(LAYER_ID, crs, null, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
    Assert.assertEquals(3, features.size());
    feature = features.get(0);
    Assert.assertTrue(feature.isEditable());
    Assert.assertTrue(feature.isDeletable());
    Assert.assertTrue(feature.getAttributes().get(STRING_ATTR).isEditable());
    Assert.assertTrue(feature.getAttributes().get(BOOLEAN_ATTR).isEditable());
    Assert.assertTrue(feature.getAttributes().get(INTEGER_ATTR).isEditable());
    feature = features.get(1);
    Assert.assertTrue(feature.isEditable());
    Assert.assertTrue(feature.isDeletable());
    Assert.assertTrue(feature.getAttributes().get(STRING_ATTR).isEditable());
    Assert.assertTrue(feature.getAttributes().get(BOOLEAN_ATTR).isEditable());
    Assert.assertTrue(feature.getAttributes().get(INTEGER_ATTR).isEditable());
    feature = features.get(2);
    Assert.assertTrue(feature.isEditable());
    Assert.assertTrue(feature.isDeletable());
    Assert.assertTrue(feature.getAttributes().get(STRING_ATTR).isEditable());
    Assert.assertTrue(feature.getAttributes().get(BOOLEAN_ATTR).isEditable());
    Assert.assertTrue(feature.getAttributes().get(INTEGER_ATTR).isEditable());

    login("marino");
    features = layerService.getFeatures(LAYER_ID, crs, null, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
    Assert.assertEquals(3, features.size());
    for (InternalFeature testFeature : features) {
View Full Code Here

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

    login("marino");
    filter = filterService.createFidFilter(new String[]{"1"});
    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"));
    feature.getAttributes().put(INTEGER_ATTR, new IntegerAttribute(12345));
    layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
    // check changes
    filter = filterService.createFidFilter(new String[]{"1"});
    oldFeatures = layerService.getFeatures(LAYER_ID, crs, filter, null,
        VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
    Assert.assertEquals(1, oldFeatures.size());
    feature = oldFeatures.get(0);
    Assert.assertEquals("bean1", feature.getAttributes().get(STRING_ATTR).getValue()); // org value, not updated   
    Assert.assertEquals(12345, feature.getAttributes().get(INTEGER_ATTR).getValue()); // updated
  }
View Full Code Here

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

    login("marino");
    // should be able to update feature "1"
    filter = filterService.createFidFilter(new String[]{"1"});
    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 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("should have throw GeomajasSecurityException");
    } catch (GeomajasSecurityException gse) {
      Assert.assertEquals(ExceptionCode.FEATURE_UPDATE_PROHIBITED, gse.getExceptionCode());
    }

    login("luc");
    // luc should be able to modify "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"));
    layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
  }
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.