Search in sources :

Example 71 with PropertyKey

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

the class AbstractNode method evaluate.

@Override
public final Object evaluate(final ActionContext actionContext, final String key, final String defaultValue) throws FrameworkException {
    switch(key) {
        case "owner":
            return getOwnerNode();
        case "_path":
            if (rawPathSegment != null) {
                return new RelationshipFactory<>(actionContext.getSecurityContext()).adapt(rawPathSegment);
            } else {
                return null;
            }
        default:
            // evaluate object value or return default
            final PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(entityType, key, false);
            if (propertyKey != null) {
                final Object value = getProperty(propertyKey, actionContext.getPredicate());
                if (value != null) {
                    return value;
                }
            }
            final Object value = invokeMethod(key, Collections.EMPTY_MAP, false);
            if (value != null) {
                return value;
            }
            return Function.numberOrString(defaultValue);
    }
}
Also used : GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Example 72 with PropertyKey

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

the class AbstractRelationship method getDynamicProperties.

public PropertyMap getDynamicProperties() {
    final PropertyMap propertyMap = new PropertyMap();
    final Class type = getClass();
    for (final PropertyKey key : StructrApp.getConfiguration().getPropertySet(type, PropertyView.All)) {
        // include all dynamic keys in definition
        if (key.isDynamic() || key.isCMISProperty()) {
            // only include primitives here
            final PropertyType dataType = key.getDataType();
            if (dataType != null) {
                propertyMap.put(key, getProperty(key));
            }
        }
    }
    return propertyMap;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) PropertyKey(org.structr.core.property.PropertyKey)

Example 73 with PropertyKey

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

the class SchemaNode method getPropertyKeys.

@Override
public Set<PropertyKey> getPropertyKeys(final String propertyView) {
    final List<PropertyKey> propertyKeys = new LinkedList<>(Iterables.toList(super.getPropertyKeys(propertyView)));
    // add "custom" property keys as String properties
    for (final String key : SchemaHelper.getProperties(getNode())) {
        final PropertyKey newKey = new StringProperty(key);
        newKey.setDeclaringClass(getClass());
        propertyKeys.add(newKey);
    }
    Collections.sort(propertyKeys, (o1, o2) -> {
        return o1.jsonName().compareTo(o2.jsonName());
    });
    return new LinkedHashSet<>(propertyKeys);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StringProperty(org.structr.core.property.StringProperty) PropertyKey(org.structr.core.property.PropertyKey) LinkedList(java.util.LinkedList)

Example 74 with PropertyKey

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

the class SchemaNode method getRelatedType.

@Override
public String getRelatedType(final String propertyNameToCheck) {
    String relatedType = getRelatedType(this, propertyNameToCheck);
    if (relatedType == null) {
        try {
            final String parentClass = getProperty(SchemaNode.extendsClass);
            if (parentClass != null) {
                // check if property is defined in parent class
                final SchemaNode parentSchemaNode = StructrApp.getInstance().nodeQuery(SchemaNode.class).andName(StringUtils.substringAfterLast(parentClass, ".")).getFirst();
                if (parentSchemaNode != null) {
                    relatedType = getRelatedType(parentSchemaNode, propertyNameToCheck);
                }
            }
        } catch (FrameworkException ex) {
            logger.warn("Can't find schema node for parent class!", ex);
        }
    }
    if (relatedType != null) {
        return relatedType;
    }
    // fallback, search NodeInterface (this allows the owner relationship to be used in Notions!)
    final PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(NodeInterface.class, propertyNameToCheck, false);
    if (key != null) {
        final Class relatedTypeClass = key.relatedType();
        if (relatedTypeClass != null) {
            return relatedTypeClass.getSimpleName();
        }
    }
    return null;
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) PropertyKey(org.structr.core.property.PropertyKey)

Example 75 with PropertyKey

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

the class SchemaRelationshipNode method getPropertyKeys.

@Override
public Set<PropertyKey> getPropertyKeys(final String propertyView) {
    final Set<PropertyKey> propertyKeys = new LinkedHashSet<>(Iterables.toList(super.getPropertyKeys(propertyView)));
    // add "custom" property keys as String properties
    for (final String key : SchemaHelper.getProperties(getNode())) {
        final PropertyKey newKey = new StringProperty(key);
        newKey.setDeclaringClass(getClass());
        propertyKeys.add(newKey);
    }
    return propertyKeys;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StringProperty(org.structr.core.property.StringProperty) 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