Search in sources :

Example 1 with InvalidPropertySchemaToken

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

the class SchemaHelper method getSourceGenerator.

// ----- private methods -----
private static PropertySourceGenerator getSourceGenerator(final ErrorBuffer errorBuffer, final String className, final PropertyDefinition propertyDefinition) throws FrameworkException {
    final String propertyName = propertyDefinition.getPropertyName();
    final Type propertyType = propertyDefinition.getPropertyType();
    final Class<? extends PropertySourceGenerator> parserClass = parserMap.get(propertyType);
    try {
        return parserClass.getConstructor(ErrorBuffer.class, String.class, PropertyDefinition.class).newInstance(errorBuffer, className, propertyDefinition);
    } catch (Throwable t) {
        logger.warn("", t);
    }
    errorBuffer.add(new InvalidPropertySchemaToken(SchemaProperty.class.getSimpleName(), propertyName, propertyName, "invalid_property_definition", "Unknow value type " + source + ", options are " + Arrays.asList(Type.values()) + "."));
    throw new FrameworkException(422, "Invalid property definition for property " + propertyDefinition.getPropertyName(), errorBuffer);
}
Also used : GraphQLScalarType(graphql.schema.GraphQLScalarType) GraphQLOutputType(graphql.schema.GraphQLOutputType) ErrorBuffer(org.structr.common.error.ErrorBuffer) FrameworkException(org.structr.common.error.FrameworkException) InvalidPropertySchemaToken(org.structr.common.error.InvalidPropertySchemaToken) StringBasedPropertyDefinition(org.structr.schema.parser.StringBasedPropertyDefinition) PropertyDefinition(org.structr.schema.parser.PropertyDefinition)

Example 2 with InvalidPropertySchemaToken

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

the class ExtendNotionPropertyWithUuid method handleMigration.

@Override
public void handleMigration(final ErrorToken errorToken) throws FrameworkException {
    final Object messageObject = errorToken.getDetail();
    if (messageObject != null) {
        final String message = (String) messageObject;
        if (message.startsWith("Invalid notion property expression for property ") && message.endsWith(".")) {
            if (errorToken instanceof InvalidPropertySchemaToken) {
                final App app = StructrApp.getInstance();
                final InvalidPropertySchemaToken token = (InvalidPropertySchemaToken) errorToken;
                final String typeName = token.getType();
                final String propertyName = token.getProperty();
                final SchemaNode type = app.nodeQuery(SchemaNode.class).andName(typeName).getFirst();
                if (type != null) {
                    final SchemaProperty property = app.nodeQuery(SchemaProperty.class).and(SchemaProperty.schemaNode, type).and(SchemaProperty.name, propertyName).getFirst();
                    if (property != null) {
                        // load format property
                        final String format = property.getProperty(SchemaProperty.format);
                        // store corrected version of format property
                        property.setProperty(SchemaProperty.format, format + ", id");
                    }
                }
            }
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) SchemaNode(org.structr.core.entity.SchemaNode) SchemaProperty(org.structr.core.entity.SchemaProperty) InvalidPropertySchemaToken(org.structr.common.error.InvalidPropertySchemaToken)

Example 3 with InvalidPropertySchemaToken

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

the class NumericalPropertyParser method parseFormatString.

@Override
public void parseFormatString(final Schema entity, final String expression) throws FrameworkException {
    boolean error = false;
    final String rangeFormatErrorMessage = "Range expression must describe a (possibly open-ended) interval, e.g. [10,99] or ]9,100[ for all two-digit integers";
    if (StringUtils.isNotBlank(expression)) {
        if ((expression.startsWith("[") || expression.startsWith("]")) && (expression.endsWith("[") || expression.endsWith("]"))) {
            final String range = expression.substring(1, expression.length() - 1);
            final String[] parts = range.split(",+");
            if (parts.length == 2) {
                lowerBound = parseNumber(getErrorBuffer(), parts[0].trim(), "lower");
                upperBound = parseNumber(getErrorBuffer(), parts[1].trim(), "upper");
                if (lowerBound == null || upperBound == null) {
                    error = true;
                }
                lowerExclusive = expression.startsWith("]");
                upperExclusive = expression.endsWith("[");
            } else {
                error = true;
            }
            if (!error) {
                addGlobalValidator(new Validator("isValid" + getUnqualifiedValueType() + "InRange", getClassName(), getSourcePropertyName(), expression));
            }
        } else {
            error = true;
        }
    }
    if (error) {
        reportError(new InvalidPropertySchemaToken(SchemaNode.class.getSimpleName(), source.getPropertyName(), expression, "invalid_range_expression", rangeFormatErrorMessage));
    }
}
Also used : InvalidPropertySchemaToken(org.structr.common.error.InvalidPropertySchemaToken)

Example 4 with InvalidPropertySchemaToken

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

the class EnumPropertyParser method parseFormatString.

@Override
public void parseFormatString(final Schema entity, String expression) throws FrameworkException {
    final String[] enumTypes = expression.split("[, ]+");
    if (StringUtils.isNotBlank(expression) && enumTypes.length > 0) {
        enumTypeName = StringUtils.capitalize(getSourcePropertyName());
        // create enum type
        enumType = ", " + enumTypeName + ".class";
        // build enum type definition
        final StringBuilder buf = new StringBuilder();
        buf.append("\n\tpublic enum ").append(enumTypeName).append(" {\n\t\t");
        for (int i = 0; i < enumTypes.length; i++) {
            final String element = enumTypes[i];
            if (element.matches("[a-zA-Z_]{1}[a-zA-Z0-9_]*")) {
                buf.append(element);
                // comma separation
                if (i < enumTypes.length - 1) {
                    buf.append(", ");
                }
            } else {
                reportError(new InvalidPropertySchemaToken(SchemaNode.class.getSimpleName(), this.source.getPropertyName(), expression, "invalid_property_definition", "Invalid enum type name, must match [a-zA-Z_]{1}[a-zA-Z0-9_]*."));
            }
        }
        buf.append("\n\t};");
        addEnumDefinition(buf.toString());
    } else if (source.getFqcn() != null) {
        // no enum type definition, use external type
        enumTypeName = source.getFqcn();
        // create enum type
        enumType = ", " + enumTypeName + ".class";
    } else {
        reportError(new InvalidPropertySchemaToken(SchemaNode.class.getSimpleName(), this.source.getPropertyName(), expression, "invalid_property_definition", "No enum types found, please specify a list of types, e.g. (red, green, blue)"));
    }
}
Also used : SchemaNode(org.structr.core.entity.SchemaNode) InvalidPropertySchemaToken(org.structr.common.error.InvalidPropertySchemaToken)

Example 5 with InvalidPropertySchemaToken

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

the class NotionPropertyParser 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(entity.getClassName(), source.getPropertyName(), expression, "invalid_property_definition", "Empty notion property expression for property " + source.getPropertyName() + "."));
    }
    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) {
            // determine related type from relationship
            relatedType = entity.getRelatedType(baseProperty);
            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 = EntityNotionProperty.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 = CollectionNotionProperty.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");
            }
            buf.append(",");
            final boolean isBoolean = (parts.length == 3 && ("true".equals(parts[2].toLowerCase())));
            isAutocreate = isBoolean;
            // use PropertyNotion when only a single element is given
            if (parts.length == 2 || isBoolean) {
                buf.append(" new PropertyNotion(");
                isPropertySet = false;
            } else {
                buf.append(" new PropertySetNotion(");
                isPropertySet = true;
            }
            for (int i = 1; i < parts.length; i++) {
                String propertyName = parts[i];
                String fullPropertyName = propertyName;
                if (!"true".equals(propertyName.toLowerCase()) && !propertyName.contains(".")) {
                    buf.append(relatedType);
                    buf.append(".");
                    fullPropertyName = relatedType + "." + fullPropertyName;
                }
                fullPropertyName = extendPropertyName(fullPropertyName, null);
                properties.add(fullPropertyName);
                propertyName = extendPropertyName(propertyName, relatedType);
                buf.append(propertyName);
                if (i < parts.length - 1) {
                    buf.append(", ");
                }
            }
            buf.append(")");
        } else {
            throw new FrameworkException(422, "Invalid notion property expression for property " + source.getPropertyName() + ".", new InvalidPropertySchemaToken(entity.getClassName(), source.getPropertyName(), expression, "invalid_property_definition", "Invalid notion property expression for property " + source.getPropertyName() + "."));
        }
        if (properties.isEmpty()) {
            throw new FrameworkException(422, "Invalid notion property expression for property " + source.getPropertyName() + ".", new InvalidPropertySchemaToken(entity.getClassName(), source.getPropertyName(), expression, "invalid_property_definition", "Invalid notion property expression for property " + source.getPropertyName() + ", notion must define at least one property."));
        }
    }
    parameters = buf.toString();
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) CollectionNotionProperty(org.structr.core.property.CollectionNotionProperty) InvalidPropertySchemaToken(org.structr.common.error.InvalidPropertySchemaToken) EntityNotionProperty(org.structr.core.property.EntityNotionProperty)

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