Search in sources :

Example 6 with InvalidPropertySchemaToken

use of org.structr.common.error.InvalidPropertySchemaToken in project structr by structr.

the class IdNotionPropertyParser method parseFormatString.

@Override
public void parseFormatString(final Schema entity, String expression) throws FrameworkException {
    if (StringUtils.isBlank(expression)) {
        // reportError(new InvalidPropertySchemaToken(SchemaNode.class.getSimpleName(), expression, "invalid_property_definition", "Empty notion property expression."));
        throw new FrameworkException(422, "Empty notion property expression for property " + source.getPropertyName() + ".", new InvalidPropertySchemaToken(SchemaNode.class.getSimpleName(), this.source.getPropertyName(), expression, "invalid_property_definition", "Empty notion property expression."));
    }
    final StringBuilder buf = new StringBuilder();
    final String[] parts = expression.split("[, ]+");
    if (parts.length > 0) {
        boolean isBuiltinProperty = false;
        baseProperty = parts[0];
        multiplicity = entity.getMultiplicity(baseProperty);
        if (multiplicity != null) {
            switch(multiplicity) {
                case "1X":
                    // this line exists because when a NotionProperty is set up for a builtin propery
                    // (like for example "owner", there must not be the string "Property" appended
                    // to the property name, and the SchemaNode returns the above "extended" multiplicity
                    // string when it has detected a fallback property name like "owner" from NodeInterface.
                    // no break!
                    isBuiltinProperty = true;
                case "1":
                    propertyType = EntityIdProperty.class.getSimpleName();
                    break;
                case "*X":
                    // this line exists because when a NotionProperty is set up for a builtin propery
                    // (like for example "owner", there must not be the string "Property" appended
                    // to the property name, and the SchemaNode returns the above "extended" multiplicity
                    // string when it has detected a fallback property name like "owner" from NodeInterface.
                    // no break!
                    isBuiltinProperty = true;
                case "*":
                    propertyType = CollectionIdProperty.class.getSimpleName();
                    break;
                default:
                    break;
            }
            buf.append(", ");
            buf.append(entity.getClassName());
            buf.append(".");
            buf.append(baseProperty);
            // append "Property" only if it is NOT a builtin property!
            if (!isBuiltinProperty) {
                buf.append("Property");
            }
            if (parts.length == 3 && "true".equals(parts[2].toLowerCase())) {
                isAutocreate = true;
                buf.append(", true");
            }
        } else {
            throw new FrameworkException(422, "Invalid notion property expression for property " + source.getPropertyName() + ".", new InvalidPropertySchemaToken(SchemaNode.class.getSimpleName(), this.source.getPropertyName(), expression, "invalid_property_definition", "Invalid notion property expression."));
        }
    }
    parameters = buf.toString();
}
Also used : EntityIdProperty(org.structr.core.property.EntityIdProperty) FrameworkException(org.structr.common.error.FrameworkException) InvalidPropertySchemaToken(org.structr.common.error.InvalidPropertySchemaToken) CollectionIdProperty(org.structr.core.property.CollectionIdProperty)

Aggregations

InvalidPropertySchemaToken (org.structr.common.error.InvalidPropertySchemaToken)6 FrameworkException (org.structr.common.error.FrameworkException)3 SchemaNode (org.structr.core.entity.SchemaNode)2 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 GraphQLScalarType (graphql.schema.GraphQLScalarType)1 ErrorBuffer (org.structr.common.error.ErrorBuffer)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 SchemaProperty (org.structr.core.entity.SchemaProperty)1 CollectionIdProperty (org.structr.core.property.CollectionIdProperty)1 CollectionNotionProperty (org.structr.core.property.CollectionNotionProperty)1 EntityIdProperty (org.structr.core.property.EntityIdProperty)1 EntityNotionProperty (org.structr.core.property.EntityNotionProperty)1 PropertyDefinition (org.structr.schema.parser.PropertyDefinition)1 StringBasedPropertyDefinition (org.structr.schema.parser.StringBasedPropertyDefinition)1