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());