Search in sources :

Example 16 with PropertyKey

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

the class DOMNode method getDataPropertyKeys.

static Set<PropertyKey> getDataPropertyKeys(final DOMNode thisNode) {
    final Set<PropertyKey> customProperties = new TreeSet<>();
    final org.structr.api.graph.Node dbNode = thisNode.getNode();
    final Iterable<String> props = dbNode.getPropertyKeys();
    for (final String key : props) {
        PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(thisNode.getClass(), key, false);
        if (propertyKey == null) {
            // support arbitrary data-* attributes
            propertyKey = new StringProperty(key);
        }
        if (key.startsWith("data-")) {
            if (propertyKey != null && propertyKey instanceof BooleanProperty && dbNode.hasProperty(key)) {
                final Object defaultValue = propertyKey.defaultValue();
                final Object nodeValue = dbNode.getProperty(key);
                // don't export boolean false values (which is the default)
                if (nodeValue != null && Boolean.FALSE.equals(nodeValue) && (defaultValue == null || nodeValue.equals(defaultValue))) {
                    continue;
                }
            }
            customProperties.add(propertyKey);
        } else if (key.startsWith(CustomHtmlAttributeProperty.CUSTOM_HTML_ATTRIBUTE_PREFIX)) {
            final CustomHtmlAttributeProperty customProp = new CustomHtmlAttributeProperty(propertyKey);
            customProperties.add(customProp);
        }
    }
    return customProperties;
}
Also used : TreeSet(java.util.TreeSet) BooleanProperty(org.structr.core.property.BooleanProperty) CustomHtmlAttributeProperty(org.structr.web.property.CustomHtmlAttributeProperty) StringProperty(org.structr.core.property.StringProperty) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Example 17 with PropertyKey

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

the class DOMNode method render.

static void render(final DOMNode thisNode, final RenderContext renderContext, final int depth) throws FrameworkException {
    final SecurityContext securityContext = renderContext.getSecurityContext();
    if (!securityContext.isVisible(thisNode)) {
        return;
    }
    final GraphObject details = renderContext.getDetailsDataObject();
    final boolean detailMode = details != null;
    if (detailMode && thisNode.hideOnDetail()) {
        return;
    }
    if (!detailMode && thisNode.hideOnIndex()) {
        return;
    }
    final EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
    if (EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode) || EditMode.DEPLOYMENT.equals(editMode)) {
        thisNode.renderContent(renderContext, depth);
    } else {
        final String subKey = thisNode.getDataKey();
        if (StringUtils.isNotBlank(subKey)) {
            final GraphObject currentDataNode = renderContext.getDataObject();
            // fetch (optional) list of external data elements
            final Iterable<GraphObject> listData = checkListSources(thisNode, securityContext, renderContext);
            final PropertyKey propertyKey;
            if (thisNode.renderDetails() && detailMode) {
                renderContext.setDataObject(details);
                renderContext.putDataObject(subKey, details);
                thisNode.renderContent(renderContext, depth);
            } else {
                if (Iterables.isEmpty(listData) && currentDataNode != null) {
                    // There are two alternative ways of retrieving sub elements:
                    // First try to get generic properties,
                    // if that fails, try to create a propertyKey for the subKey
                    final Object elements = currentDataNode.getProperty(new GenericProperty(subKey));
                    renderContext.setRelatedProperty(new GenericProperty(subKey));
                    renderContext.setSourceDataObject(currentDataNode);
                    if (elements != null) {
                        if (elements instanceof Iterable) {
                            for (Object o : (Iterable) elements) {
                                if (o instanceof GraphObject) {
                                    GraphObject graphObject = (GraphObject) o;
                                    renderContext.putDataObject(subKey, graphObject);
                                    thisNode.renderContent(renderContext, depth);
                                }
                            }
                        }
                    } else {
                        propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(currentDataNode.getClass(), subKey, false);
                        renderContext.setRelatedProperty(propertyKey);
                        if (propertyKey != null) {
                            final Object value = currentDataNode.getProperty(propertyKey);
                            if (value != null) {
                                if (value instanceof Iterable) {
                                    for (final Object o : ((Iterable) value)) {
                                        if (o instanceof GraphObject) {
                                            renderContext.putDataObject(subKey, (GraphObject) o);
                                            thisNode.renderContent(renderContext, depth);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // reset data node in render context
                    renderContext.setDataObject(currentDataNode);
                    renderContext.setRelatedProperty(null);
                } else {
                    renderContext.setListSource(listData);
                    thisNode.renderNodeList(securityContext, renderContext, depth, subKey);
                }
            }
        } else {
            thisNode.renderContent(renderContext, depth);
        }
    }
}
Also used : SecurityContext(org.structr.common.SecurityContext) GenericProperty(org.structr.core.property.GenericProperty) EditMode(org.structr.web.common.RenderContext.EditMode) GraphObject(org.structr.core.GraphObject) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Example 18 with PropertyKey

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

the class DOMNode method cloneNode.

public static Node cloneNode(final DOMNode thisNode, boolean deep) {
    final SecurityContext securityContext = thisNode.getSecurityContext();
    if (deep) {
        return cloneAndAppendChildren(securityContext, thisNode);
    } else {
        final PropertyMap properties = new PropertyMap();
        for (Iterator<PropertyKey> it = thisNode.getPropertyKeys(PropertyView.Ui).iterator(); it.hasNext(); ) {
            final PropertyKey key = it.next();
            // skip blacklisted properties
            if (cloneBlacklist.contains(key.jsonName())) {
                continue;
            }
            if (!key.isUnvalidated()) {
                properties.put(key, thisNode.getProperty(key));
            }
        }
        // htmlView is necessary for the cloning of DOM nodes - otherwise some properties won't be cloned
        for (Iterator<PropertyKey> it = thisNode.getPropertyKeys(PropertyView.Html).iterator(); it.hasNext(); ) {
            final PropertyKey key = it.next();
            // skip blacklisted properties
            if (cloneBlacklist.contains(key.jsonName())) {
                continue;
            }
            if (!key.isUnvalidated()) {
                properties.put(key, thisNode.getProperty(key));
            }
        }
        if (thisNode instanceof LinkSource) {
            final LinkSource linkSourceElement = (LinkSource) thisNode;
            properties.put(StructrApp.key(LinkSource.class, "linkable"), linkSourceElement.getLinkable());
        }
        final App app = StructrApp.getInstance(securityContext);
        try {
            return app.create(thisNode.getClass(), properties);
        } catch (FrameworkException ex) {
            ex.printStackTrace();
            throw new DOMException(DOMException.INVALID_STATE_ERR, ex.toString());
        }
    }
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) DOMException(org.w3c.dom.DOMException) PropertyMap(org.structr.core.property.PropertyMap) FrameworkException(org.structr.common.error.FrameworkException) LinkSource(org.structr.web.entity.LinkSource) SecurityContext(org.structr.common.SecurityContext) PropertyKey(org.structr.core.property.PropertyKey)

Example 19 with PropertyKey

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

the class GraphObject method filterIndexableForCreation.

default void filterIndexableForCreation(final SecurityContext securityContext, final PropertyMap src, final CreationContainer indexable, final PropertyMap filtered) throws FrameworkException {
    for (final Iterator<Entry<PropertyKey, Object>> iterator = src.entrySet().iterator(); iterator.hasNext(); ) {
        final Entry<PropertyKey, Object> attr = iterator.next();
        final PropertyKey key = attr.getKey();
        final Object value = attr.getValue();
        if (key.indexable(value) && !key.isReadOnly() && !key.isSystemInternal() && !key.isUnvalidated()) {
            // value can be set directly, move to creation container
            key.setProperty(securityContext, indexable, value);
            iterator.remove();
            // store value to do notifications later
            filtered.put(key, value);
        }
    }
}
Also used : Entry(java.util.Map.Entry) PropertyKey(org.structr.core.property.PropertyKey)

Example 20 with PropertyKey

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

the class GraphQLQuery method init.

// ----- private methods -----
private void init(final SecurityContext securityContext, final Class type, final Field field, final String path) throws FrameworkException {
    final QueryConfig config = getConfig(path);
    config.handleTypeArguments(securityContext, type, field.getArguments());
    final SelectionSet selectionSet = field.getSelectionSet();
    if (selectionSet != null) {
        for (final Selection selection : selectionSet.getSelections()) {
            if (selection instanceof Field) {
                final Field childField = (Field) selection;
                final SelectionSet childSet = childField.getSelectionSet();
                final PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, childField.getName());
                final Class relatedType = key.relatedType() != null ? key.relatedType() : type;
                // add field to property set
                config.addPropertyKey(key);
                config.handleFieldArguments(securityContext, relatedType, field, childField);
                // recurse
                if (childSet != null) {
                    init(securityContext, relatedType, childField, path + "/" + childField.getName());
                }
            }
        }
    }
}
Also used : Field(graphql.language.Field) SelectionSet(graphql.language.SelectionSet) Selection(graphql.language.Selection) 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