Package org.geomajas.layer.feature

Examples of org.geomajas.layer.feature.FeatureModel


      InternalFeature oldFeature = context.getOptional(PipelineCode.OLD_FEATURE_KEY, InternalFeature.class);
      if (null != oldFeature) {
        // get original geometry from storage to assure not changed by transformation and available
        Object feature = layer.read(oldFeature.getId());
        context.put(PipelineCode.FEATURE_DATA_OBJECT_KEY, feature); // put in context to prevent getting twice
        FeatureModel featureModel = layer.getFeatureModel();
        Geometry oldGeometry = featureModel.getGeometry(feature);
        if (null != oldGeometry) {
          // invalidate
          recorder.record("layer", "Invalidate geometry for old version of feature");
          Envelope oldEnvelope = oldGeometry.getEnvelopeInternal();
          log.debug("invalidate old feature area {}", oldEnvelope);
View Full Code Here


    }
    return filteredAttributes;
  }

  private Map<String, Attribute> getAttributes(VectorLayer layer, Object featureBean) throws LayerException {
    FeatureModel featureModel = layer.getFeatureModel();
    FeatureInfo featureInfo = layer.getLayerInfo().getFeatureInfo();
    String geometryAttributeName = featureInfo.getGeometryType().getName();
    boolean lazy = layer instanceof VectorLayerLazyFeatureConversionSupport &&
        ((VectorLayerLazyFeatureConversionSupport) layer).useLazyFeatureConversion();

    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    for (AttributeInfo attribute : featureInfo.getAttributes()) {
      String name = attribute.getName();
      if (!name.equals(geometryAttributeName)) {
        Attribute value;
        if (lazy) {
          // need to use the correct lazy type to allow instanceof to work
          if (attribute instanceof AssociationAttributeInfo) {
            switch (((AssociationAttributeInfo) attribute).getType()) {
              case MANY_TO_ONE:
                value = new LazyManyToOneAttribute(featureModel, featureBean, name);
                break;
              case ONE_TO_MANY:
                value = new LazyOneToManyAttribute(featureModel, featureBean, name);
                break;
              default:
                throw new LayerException(ExceptionCode.UNEXPECTED_PROBLEM,
                    "Coding error, not all AssociationType options are covered");
            }
          } else {
            PrimitiveType type = ((PrimitiveAttributeInfo) attribute).getType();
            value = new LazyPrimitiveAttribute(type, featureModel, featureBean, name);
          }
        } else {
          value = featureModel.getAttribute(featureBean, name);
        }
        attributes.put(name, value);
      }
    }
    return attributes;
View Full Code Here

   *             oops
   */
  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());
        }
      }

View Full Code Here

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

    private static Pattern ID_PATTERN = Pattern.compile("@(\\w+:)?id");

    protected static Pattern PROPERTY_PATTERN = Pattern.compile("((\\w+)(\\.|/))*(\\w+)");

    public boolean canHandle(Object object, String xpath, Class target) {
      FeatureModel fm = FeatureModelRegistry.getRegistry().lookup(object);
      return (fm != null);
    }
View Full Code Here

      FeatureModel fm = FeatureModelRegistry.getRegistry().lookup(object);
      return (fm != null);
    }

    public Object get(Object object, String xpath, Class target) throws IllegalArgumentException {
      FeatureModel fm = FeatureModelRegistry.getRegistry().lookup(object);
      if (null == fm) {
        throw new IllegalArgumentException("Objects of type " + object.getClass().getName() +
            " not registered in FeatureModelRegistry");
      }
      try {
        if (xpath.equals(fm.getGeometryAttributeName())) {
          return fm.getGeometry(object);
        } else if (ID_PATTERN.matcher(xpath).matches()) {
          return fm.getId(object);
        } else if (PROPERTY_PATTERN.matcher(xpath).matches()) {
          return fm.getAttribute(object, xpath).getValue();
        } else {
          return null;
        }
      } catch (LayerException e) {
        throw new IllegalArgumentException(e);
View Full Code Here

TOP

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

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.