Search in sources :

Example 16 with GraphObject

use of org.structr.core.GraphObject in project structr by structr.

the class PropertyMap method javaTypeToDatabaseType.

// ----- static methods -----
public static PropertyMap javaTypeToDatabaseType(SecurityContext securityContext, GraphObject wrapped, Map<String, Object> source) throws FrameworkException {
    final PropertyMap resultMap = new PropertyMap();
    final GraphObject entity = unwrap(wrapped);
    if (source != null) {
        for (Entry<String, Object> entry : source.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (key != null) {
                final PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForDatabaseName(entity.getClass(), key);
                final PropertyConverter converter = propertyKey.databaseConverter(securityContext, entity);
                if (converter != null) {
                    try {
                        Object propertyValue = converter.convert(value);
                        resultMap.put(propertyKey, propertyValue);
                    } catch (ClassCastException cce) {
                        throw new FrameworkException(422, "Invalid JSON input for key " + propertyKey.jsonName() + ", expected a JSON " + propertyKey.typeName() + ".");
                    }
                } else {
                    resultMap.put(propertyKey, value);
                }
            }
        }
    }
    return resultMap;
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) PropertyConverter(org.structr.core.converter.PropertyConverter) GraphObject(org.structr.core.GraphObject) GraphObject(org.structr.core.GraphObject)

Example 17 with GraphObject

use of org.structr.core.GraphObject in project structr by structr.

the class PropertyMap method databaseTypeToJavaType.

public static PropertyMap databaseTypeToJavaType(SecurityContext securityContext, Class<? extends GraphObject> entityType, Map<String, Object> source) throws FrameworkException {
    PropertyMap resultMap = new PropertyMap();
    if (source != null) {
        for (Entry<String, Object> entry : source.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (key != null) {
                PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForDatabaseName(entityType, key);
                PropertyConverter converter = propertyKey.databaseConverter(securityContext);
                if (converter != null) {
                    try {
                        Object propertyValue = converter.revert(value);
                        resultMap.put(propertyKey, propertyValue);
                    } catch (ClassCastException cce) {
                        throw new FrameworkException(422, "Invalid JSON input for key " + propertyKey.jsonName() + ", expected a JSON " + propertyKey.typeName() + ".");
                    }
                } else {
                    resultMap.put(propertyKey, value);
                }
            }
        }
    }
    return resultMap;
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) PropertyConverter(org.structr.core.converter.PropertyConverter) GraphObject(org.structr.core.GraphObject)

Example 18 with GraphObject

use of org.structr.core.GraphObject in project structr by structr.

the class EndNodes method getSearchAttribute.

@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, List<T> searchValue, boolean exactMatch, final Query query) {
    final Predicate<GraphObject> predicate = query != null ? query.toPredicate() : null;
    final SourceSearchAttribute attr = new SourceSearchAttribute(occur);
    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded = false;
    if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {
        if (exactMatch) {
            for (NodeInterface node : searchValue) {
                switch(occur) {
                    case REQUIRED:
                        if (!alreadyAdded) {
                            // the first result is the basis of all subsequent intersections
                            intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                            // the next additions are intersected with this one
                            alreadyAdded = true;
                        } else {
                            intersectionResult.retainAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                        }
                        break;
                    case OPTIONAL:
                        intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                        break;
                    case FORBIDDEN:
                        break;
                }
            }
        } else {
            // loose search behaves differently, all results must be combined
            for (NodeInterface node : searchValue) {
                intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
            }
        }
        attr.setResult(intersectionResult);
    } else {
        // value in the given field
        return new EmptySearchAttribute(this, null);
    }
    return attr;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SourceSearchAttribute(org.structr.core.graph.search.SourceSearchAttribute) EmptySearchAttribute(org.structr.core.graph.search.EmptySearchAttribute) GraphObject(org.structr.core.GraphObject) NodeInterface(org.structr.core.graph.NodeInterface)

Example 19 with GraphObject

use of org.structr.core.GraphObject in project structr by structr.

the class EntityNotionProperty method getSearchAttribute.

@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, T searchValue, boolean exactMatch, final Query query) {
    final Predicate<GraphObject> predicate = query != null ? query.toPredicate() : null;
    final SourceSearchAttribute attr = new SourceSearchAttribute(occur);
    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded = false;
    try {
        if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {
            final App app = StructrApp.getInstance(securityContext);
            final PropertyKey key = notion.getPrimaryPropertyKey();
            final PropertyConverter inputConverter = key != null ? key.inputConverter(securityContext) : null;
            // transform search values using input convert of notion property
            final Object transformedValue = inputConverter != null ? inputConverter.convert(searchValue) : searchValue;
            if (exactMatch) {
                Result<AbstractNode> result = app.nodeQuery(entityProperty.relatedType()).and(key, transformedValue).getResult();
                for (AbstractNode node : result.getResults()) {
                    switch(occur) {
                        case REQUIRED:
                            if (!alreadyAdded) {
                                // the first result is the basis of all subsequent intersections
                                intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                                // the next additions are intersected with this one
                                alreadyAdded = true;
                            } else {
                                intersectionResult.retainAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                            }
                            break;
                        case OPTIONAL:
                            intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                            break;
                        case FORBIDDEN:
                            break;
                    }
                }
            } else {
                Result<AbstractNode> result = app.nodeQuery(entityProperty.relatedType()).and(key, transformedValue, false).getResult();
                // loose search behaves differently, all results must be combined
                for (AbstractNode node : result.getResults()) {
                    intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                }
            }
            attr.setResult(intersectionResult);
        } else {
            // value in the given field
            return new EmptySearchAttribute(this, null);
        }
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
    return attr;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) FrameworkException(org.structr.common.error.FrameworkException) SourceSearchAttribute(org.structr.core.graph.search.SourceSearchAttribute) AbstractNode(org.structr.core.entity.AbstractNode) EmptySearchAttribute(org.structr.core.graph.search.EmptySearchAttribute) GraphObject(org.structr.core.GraphObject) PropertyConverter(org.structr.core.converter.PropertyConverter) GraphObject(org.structr.core.GraphObject)

Example 20 with GraphObject

use of org.structr.core.GraphObject in project structr by structr.

the class GroupProperty method getGroupedProperties.

// ----- interface PropertyGroup -----
@Override
public PropertyMap getGroupedProperties(SecurityContext securityContext, GraphObject source) {
    PropertyMap groupedProperties = new PropertyMap();
    Boolean nullValuesOnly = source.getProperty(nullValuesOnlyProperty);
    // return immediately, as there are no properties in this group
    if (nullValuesOnly != null && nullValuesOnly.booleanValue()) {
        return null;
    }
    for (PropertyKey key : propertyKeys.values()) {
        Object value = source.getProperty(key);
        groupedProperties.put(key, value);
        if (value != null) {
            nullValuesOnly = false;
        }
    }
    return groupedProperties;
}
Also used : GraphObject(org.structr.core.GraphObject)

Aggregations

GraphObject (org.structr.core.GraphObject)151 FrameworkException (org.structr.common.error.FrameworkException)58 PropertyKey (org.structr.core.property.PropertyKey)39 LinkedList (java.util.LinkedList)35 SecurityContext (org.structr.common.SecurityContext)25 App (org.structr.core.app.App)25 StructrApp (org.structr.core.app.StructrApp)24 Tx (org.structr.core.graph.Tx)23 List (java.util.List)22 PropertyConverter (org.structr.core.converter.PropertyConverter)22 AbstractNode (org.structr.core.entity.AbstractNode)18 GraphObjectMap (org.structr.core.GraphObjectMap)17 NodeInterface (org.structr.core.graph.NodeInterface)17 LinkedHashSet (java.util.LinkedHashSet)15 PropertyMap (org.structr.core.property.PropertyMap)13 Map (java.util.Map)12 RestMethodResult (org.structr.rest.RestMethodResult)11 ConfigurationProvider (org.structr.schema.ConfigurationProvider)10 Result (org.structr.core.Result)9 ArrayList (java.util.ArrayList)8