Search in sources :

Example 11 with PropertyKey

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

the class SearchCommand method or.

@Override
public <P> org.structr.core.app.Query<T> or(final PropertyMap attributes) {
    for (final Map.Entry<PropertyKey, Object> entry : attributes.entrySet()) {
        final PropertyKey key = entry.getKey();
        final Object value = entry.getValue();
        or(key, value);
    }
    return this;
}
Also used : GraphObject(org.structr.core.GraphObject) LinkedHashMap(java.util.LinkedHashMap) PropertyMap(org.structr.core.property.PropertyMap) Map(java.util.Map) PropertyKey(org.structr.core.property.PropertyKey)

Example 12 with PropertyKey

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

the class GraphObjectModificationState method delete.

public void delete(boolean passive) {
    int statusBefore = status;
    if (passive) {
        status |= STATE_DELETED_PASSIVELY;
    }
    status |= STATE_DELETED;
    if (status != statusBefore) {
        // copy all properties on deletion
        for (final PropertyKey key : object.getPropertyKeys(PropertyView.Public)) {
            removedProperties.put(key, object.getProperty(key));
        }
        modified = true;
    }
    updateCache();
}
Also used : PropertyKey(org.structr.core.property.PropertyKey)

Example 13 with PropertyKey

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

the class SetFunction method apply.

@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
    if (arrayHasMinLengthAndAllElementsNotNull(sources, 2)) {
        final SecurityContext securityContext = ctx.getSecurityContext();
        final ConfigurationProvider config = StructrApp.getConfiguration();
        Class type = null;
        PropertyMap propertyMap = null;
        if (sources[0] instanceof GraphObject) {
            final GraphObject source = (GraphObject) sources[0];
            type = source.getEntityType();
        }
        if (type == null) {
            throw new FrameworkException(422, "Can't get type of object '" + sources[0].toString() + "' in set() method!");
        }
        final GraphObject sourceObject = (GraphObject) sources[0];
        if (sources.length == 2 && sources[1] instanceof Map) {
            propertyMap = PropertyMap.inputTypeToJavaType(securityContext, type, (Map) sources[1]);
        } else if (sources.length == 2 && sources[1] instanceof GraphObjectMap) {
            propertyMap = PropertyMap.inputTypeToJavaType(securityContext, type, ((GraphObjectMap) sources[1]).toMap());
        } else if (sources.length == 2 && sources[1] instanceof String) {
            final Gson gson = new GsonBuilder().create();
            final Map<String, Object> values = deserialize(gson, sources[1].toString());
            if (values != null) {
                propertyMap = PropertyMap.inputTypeToJavaType(securityContext, type, values);
            }
        } else if (sources.length > 2) {
            propertyMap = new PropertyMap();
            final int parameter_count = sources.length;
            if (parameter_count % 2 == 0) {
                throw new FrameworkException(400, "Invalid number of parameters: " + parameter_count + ". Should be uneven: " + (ctx.isJavaScriptContext() ? ERROR_MESSAGE_SET_JS : ERROR_MESSAGE_SET));
            }
            for (int c = 1; c < parameter_count; c += 2) {
                final PropertyKey key = config.getPropertyKeyForJSONName(type, sources[c].toString());
                if (key != null) {
                    final PropertyConverter inputConverter = key.inputConverter(securityContext);
                    Object value = sources[c + 1];
                    if (inputConverter != null) {
                        value = inputConverter.convert(value);
                    }
                    propertyMap.put(key, value);
                }
            }
        } else {
            throw new FrameworkException(422, "Invalid use of builtin method set, usage: set(entity, params..)");
        }
        if (propertyMap != null) {
            sourceObject.setProperties(securityContext, propertyMap);
        }
    } else {
        logParameterError(caller, sources, ctx.isJavaScriptContext());
    }
    return "";
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) GsonBuilder(com.google.gson.GsonBuilder) ConfigurationProvider(org.structr.schema.ConfigurationProvider) Gson(com.google.gson.Gson) GraphObject(org.structr.core.GraphObject) PropertyMap(org.structr.core.property.PropertyMap) GraphObjectMap(org.structr.core.GraphObjectMap) SecurityContext(org.structr.common.SecurityContext) PropertyConverter(org.structr.core.converter.PropertyConverter) GraphObject(org.structr.core.GraphObject) PropertyMap(org.structr.core.property.PropertyMap) Map(java.util.Map) GraphObjectMap(org.structr.core.GraphObjectMap) PropertyKey(org.structr.core.property.PropertyKey)

Example 14 with PropertyKey

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

the class DOMElement method findOrCreateAttributeKey.

public static HtmlProperty findOrCreateAttributeKey(final DOMElement thisElement, final String name) {
    // try to find native html property defined in DOMElement or one of its subclasses
    final PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(thisElement.getEntityType(), name, false);
    if (key != null && key instanceof HtmlProperty) {
        return (HtmlProperty) key;
    } else {
        // create synthetic HtmlProperty
        final HtmlProperty htmlProperty = new HtmlProperty(name);
        htmlProperty.setDeclaringClass(DOMElement.class);
        return htmlProperty;
    }
}
Also used : HtmlProperty(org.structr.web.common.HtmlProperty) PropertyKey(org.structr.core.property.PropertyKey)

Example 15 with PropertyKey

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

the class DOMNode method renderCustomAttributes.

static void renderCustomAttributes(final DOMNode thisNode, final AsyncBuffer out, final SecurityContext securityContext, final RenderContext renderContext) throws FrameworkException {
    final EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
    for (PropertyKey key : thisNode.getDataPropertyKeys()) {
        String value = "";
        if (EditMode.DEPLOYMENT.equals(editMode)) {
            final Object obj = thisNode.getProperty(key);
            if (obj != null) {
                value = obj.toString();
            }
        } else {
            value = thisNode.getPropertyWithVariableReplacement(renderContext, key);
            if (value != null) {
                value = value.trim();
            }
        }
        if (!(EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode))) {
            value = escapeForHtmlAttributes(value);
        }
        if (StringUtils.isNotBlank(value)) {
            if (key instanceof CustomHtmlAttributeProperty) {
                out.append(" ").append(((CustomHtmlAttributeProperty) key).cleanName()).append("=\"").append(value).append("\"");
            } else {
                out.append(" ").append(key.dbName()).append("=\"").append(value).append("\"");
            }
        }
    }
    if (EditMode.DEPLOYMENT.equals(editMode) || EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode)) {
        if (EditMode.DEPLOYMENT.equals(editMode)) {
            // export name property if set
            final String name = thisNode.getProperty(AbstractNode.name);
            if (name != null) {
                out.append(" data-structr-meta-name=\"").append(escapeForHtmlAttributes(name)).append("\"");
            }
        }
        for (final String p : rawProps) {
            String htmlName = "data-structr-meta-" + CaseHelper.toUnderscore(p, false).replaceAll("_", "-");
            Object value = thisNode.getProperty(p);
            if (value != null) {
                final PropertyKey key = StructrApp.key(DOMNode.class, p);
                final boolean isBoolean = key instanceof BooleanProperty;
                final String stringValue = value.toString();
                if ((isBoolean && "true".equals(stringValue)) || (!isBoolean && StringUtils.isNotBlank(stringValue))) {
                    out.append(" ").append(htmlName).append("=\"").append(escapeForHtmlAttributes(stringValue)).append("\"");
                }
            }
        }
    }
}
Also used : BooleanProperty(org.structr.core.property.BooleanProperty) CustomHtmlAttributeProperty(org.structr.web.property.CustomHtmlAttributeProperty) EditMode(org.structr.web.common.RenderContext.EditMode) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Aggregations

PropertyKey (org.structr.core.property.PropertyKey)177 FrameworkException (org.structr.common.error.FrameworkException)108 Test (org.junit.Test)69 NodeInterface (org.structr.core.graph.NodeInterface)62 Tx (org.structr.core.graph.Tx)61 GraphObject (org.structr.core.GraphObject)59 StructrTest (org.structr.common.StructrTest)39 PropertyMap (org.structr.core.property.PropertyMap)37 List (java.util.List)31 Result (org.structr.core.Result)28 ConfigurationProvider (org.structr.schema.ConfigurationProvider)27 SecurityContext (org.structr.common.SecurityContext)26 LinkedList (java.util.LinkedList)22 StringProperty (org.structr.core.property.StringProperty)22 ErrorToken (org.structr.common.error.ErrorToken)20 Map (java.util.Map)18 PropertyConverter (org.structr.core.converter.PropertyConverter)18 NodeAttribute (org.structr.core.graph.NodeAttribute)17 App (org.structr.core.app.App)16 StructrApp (org.structr.core.app.StructrApp)16