Search in sources :

Example 1 with FunctionProperty

use of org.structr.core.property.FunctionProperty in project structr by structr.

the class AbstractNode method setProperties.

@Override
public void setProperties(final SecurityContext securityContext, final PropertyMap properties) throws FrameworkException {
    if (!isGranted(Permission.write, securityContext)) {
        internalSystemPropertiesUnlocked = false;
        readOnlyPropertiesUnlocked = false;
        throw new FrameworkException(403, "Modification not permitted.");
    }
    for (final PropertyKey key : properties.keySet()) {
        final Object value = properties.get(key);
        final Object oldValue = getProperty(key);
        // no old value exists  OR  old value exists and is NOT equal => set property
        if (((oldValue == null) && (value != null)) || ((oldValue != null) && (!oldValue.equals(value)) || (key instanceof FunctionProperty))) {
            if (!key.equals(GraphObject.id)) {
                // check for system properties
                if (key.isSystemInternal() && !internalSystemPropertiesUnlocked) {
                    throw new FrameworkException(422, "Property " + key.jsonName() + " is an internal system property", new InternalSystemPropertyToken(getClass().getSimpleName(), key));
                }
                // check for read-only properties
                if ((key.isReadOnly() || key.isWriteOnce()) && !readOnlyPropertiesUnlocked && !securityContext.isSuperUser()) {
                    throw new FrameworkException(422, "Property " + key.jsonName() + " is read-only", new ReadOnlyPropertyToken(getClass().getSimpleName(), key));
                }
            }
        }
    }
    NodeInterface.super.setProperties(securityContext, properties);
}
Also used : ReadOnlyPropertyToken(org.structr.common.error.ReadOnlyPropertyToken) FrameworkException(org.structr.common.error.FrameworkException) InternalSystemPropertyToken(org.structr.common.error.InternalSystemPropertyToken) GraphObject(org.structr.core.GraphObject) FunctionProperty(org.structr.core.property.FunctionProperty) PropertyKey(org.structr.core.property.PropertyKey)

Aggregations

FrameworkException (org.structr.common.error.FrameworkException)1 InternalSystemPropertyToken (org.structr.common.error.InternalSystemPropertyToken)1 ReadOnlyPropertyToken (org.structr.common.error.ReadOnlyPropertyToken)1 GraphObject (org.structr.core.GraphObject)1 FunctionProperty (org.structr.core.property.FunctionProperty)1 PropertyKey (org.structr.core.property.PropertyKey)1