Search in sources :

Example 21 with PropertyKey

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

the class QueryConfig method handleFieldArguments.

public void handleFieldArguments(final SecurityContext securityContext, final Class type, final Field parentField, final Field field) throws FrameworkException {
    final ConfigurationProvider config = StructrApp.getConfiguration();
    final PropertyKey parentKey = config.getPropertyKeyForJSONName(type, parentField.getName());
    final PropertyKey key = config.getPropertyKeyForJSONName(type, field.getName(), false);
    final List<SearchTuple> searchTuples = new LinkedList<>();
    Occurrence occurrence = Occurrence.REQUIRED;
    // parse arguments
    for (final Argument argument : field.getArguments()) {
        final String name = argument.getName();
        final Value value = argument.getValue();
        switch(name) {
            case "_equals":
                searchTuples.add(new SearchTuple(castValue(securityContext, key.relatedType(), key, value), true));
                break;
            case "_contains":
                searchTuples.add(new SearchTuple(castValue(securityContext, key.relatedType(), key, value), false));
                break;
            case "_conj":
                occurrence = getOccurrence(value);
                break;
            default:
                break;
        }
    }
    // only add field if a value was set
    for (final SearchTuple tuple : searchTuples) {
        addAttribute(parentKey, key.getSearchAttribute(securityContext, occurrence, tuple.value, tuple.exact, null), occurrence);
    }
}
Also used : Argument(graphql.language.Argument) ConfigurationProvider(org.structr.schema.ConfigurationProvider) ObjectValue(graphql.language.ObjectValue) Value(graphql.language.Value) StringValue(graphql.language.StringValue) IntValue(graphql.language.IntValue) BooleanValue(graphql.language.BooleanValue) Occurrence(org.structr.api.search.Occurrence) PropertyKey(org.structr.core.property.PropertyKey) LinkedList(java.util.LinkedList)

Example 22 with PropertyKey

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

the class QueryConfig method handleTypeArguments.

public void handleTypeArguments(final SecurityContext securityContext, final Class type, final List<Argument> arguments) throws FrameworkException {
    // parse arguments
    for (final Argument argument : arguments) {
        final String name = argument.getName();
        final Value value = argument.getValue();
        switch(name) {
            case "_page":
                this.page = getIntegerValue(value, 1);
                break;
            case "_pageSize":
            case "_first":
                this.pageSize = getIntegerValue(value, Integer.MAX_VALUE);
                break;
            case "_sort":
                this.sortKeySource = getStringValue(value, "name");
                this.sortKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, sortKeySource, false);
                break;
            case "_desc":
                this.sortDescending = getBooleanValue(value, false);
                break;
            default:
                // handle simple selections like an _equals on the field
                final PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, name, false);
                if (key != null) {
                    addAttribute(key, key.getSearchAttribute(securityContext, Occurrence.REQUIRED, castValue(securityContext, type, key, value), true, null), Occurrence.REQUIRED);
                }
                break;
        }
    }
}
Also used : Argument(graphql.language.Argument) ObjectValue(graphql.language.ObjectValue) Value(graphql.language.Value) StringValue(graphql.language.StringValue) IntValue(graphql.language.IntValue) BooleanValue(graphql.language.BooleanValue) PropertyKey(org.structr.core.property.PropertyKey)

Example 23 with PropertyKey

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

the class JarConfigurationProvider method registerPropertySet.

/**
 * Registers the given set of property keys for the view with name
 * <code>propertyView</code> and the given prefix of entities with the
 * given type.
 *
 * @param type the type of the entities for which the view will be
 * registered
 * @param propertyView the name of the property view for which the
 * property set will be registered
 * @param propertySet the set of property keys to register for the given
 * view
 */
@Override
public void registerPropertySet(Class type, String propertyView, PropertyKey... propertySet) {
    Map<String, Set<PropertyKey>> propertyViewMap = getPropertyViewMapForType(type);
    Set<PropertyKey> properties = propertyViewMap.get(propertyView);
    if (properties == null) {
        properties = new LinkedHashSet<>();
        propertyViewMap.put(propertyView, properties);
    }
    // are most likely from a more concrete class.
    for (final PropertyKey key : propertySet) {
        // between different keys
        if (properties.contains(key)) {
            properties.remove(key);
        }
        properties.add(key);
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) PropertyKey(org.structr.core.property.PropertyKey)

Example 24 with PropertyKey

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

the class JarConfigurationProvider method getPropertyKeyForDatabaseName.

@Override
public PropertyKey getPropertyKeyForDatabaseName(Class type, String dbName, boolean createGeneric) {
    Map<String, PropertyKey> classDBNamePropertyMap = getClassDBNamePropertyMapForType(type);
    PropertyKey key = classDBNamePropertyMap.get(dbName);
    if (key == null) {
        // first try: uuid
        if (GraphObject.id.dbName().equals(dbName)) {
            return GraphObject.id;
        }
        if (createGeneric) {
            key = new GenericProperty(dbName);
        }
    }
    return key;
}
Also used : GenericProperty(org.structr.core.property.GenericProperty) PropertyKey(org.structr.core.property.PropertyKey)

Example 25 with PropertyKey

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

the class Resource method findPropertyKey.

// ----- protected methods -----
protected PropertyKey findPropertyKey(final TypedIdResource typedIdResource, final TypeResource typeResource) {
    Class sourceNodeType = typedIdResource.getTypeResource().getEntityClass();
    String rawName = typeResource.getRawType();
    PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(sourceNodeType, rawName, false);
    if (key == null) {
        // try to convert raw name into lower-case variable name
        key = StructrApp.getConfiguration().getPropertyKeyForJSONName(sourceNodeType, CaseHelper.toLowerCamelCase(rawName), false);
    }
    return key;
}
Also used : 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