Search in sources :

Example 6 with SchemaProperty

use of org.structr.core.entity.SchemaProperty in project structr by structr.

the class SchemaHelper method extractViews.

public static void extractViews(final Schema entity, final Map<String, Set<String>> views, final Set<String> relPropertyNames, final ErrorBuffer errorBuffer) throws FrameworkException {
    final PropertyContainer propertyContainer = entity.getPropertyContainer();
    final ConfigurationProvider config = StructrApp.getConfiguration();
    Class superClass = config.getNodeEntityClass(entity.getSuperclassName());
    if (superClass == null) {
        superClass = config.getRelationshipEntityClass(entity.getSuperclassName());
    }
    if (superClass == null) {
        superClass = AbstractNode.class;
    }
    for (final String rawViewName : getViews(propertyContainer)) {
        if (!rawViewName.startsWith("___") && propertyContainer.hasProperty(rawViewName)) {
            final String value = propertyContainer.getProperty(rawViewName).toString();
            final String[] parts = value.split("[,\\s]+");
            final String viewName = rawViewName.substring(2);
            if (entity instanceof AbstractSchemaNode) {
                final List<String> nonGraphProperties = new LinkedList<>();
                final List<SchemaProperty> properties = new LinkedList<>();
                final AbstractSchemaNode schemaNode = (AbstractSchemaNode) entity;
                final App app = StructrApp.getInstance();
                if (app.nodeQuery(SchemaView.class).and(SchemaView.schemaNode, schemaNode).and(AbstractNode.name, viewName).getFirst() == null) {
                    // add parts to view, overrides defaults (because of clear() above)
                    for (int i = 0; i < parts.length; i++) {
                        String propertyName = parts[i].trim();
                        while (propertyName.startsWith("_")) {
                            propertyName = propertyName.substring(1);
                        }
                        // append this as a workaround to include remote properties
                        if (propertyName.endsWith("Property")) {
                            propertyName = propertyName.substring(0, propertyName.length() - "Property".length());
                        }
                        final SchemaProperty propertyNode = app.nodeQuery(SchemaProperty.class).and(SchemaProperty.schemaNode, schemaNode).andName(propertyName).getFirst();
                        if (propertyNode != null) {
                            properties.add(propertyNode);
                        } else {
                            nonGraphProperties.add(propertyName);
                        }
                    }
                    app.create(SchemaView.class, new NodeAttribute<>(SchemaView.schemaNode, schemaNode), new NodeAttribute<>(SchemaView.schemaProperties, properties), new NodeAttribute<>(SchemaView.name, viewName), new NodeAttribute<>(SchemaView.nonGraphProperties, StringUtils.join(nonGraphProperties, ",")));
                    schemaNode.removeProperty(new StringProperty(rawViewName));
                }
            }
        }
    }
    final List<SchemaView> schemaViews = entity.getSchemaViews();
    if (schemaViews != null) {
        for (final SchemaView schemaView : schemaViews) {
            final String nonGraphProperties = schemaView.getProperty(SchemaView.nonGraphProperties);
            final String viewName = schemaView.getName();
            // clear view before filling it again
            Set<String> view = views.get(viewName);
            if (view == null) {
                view = new LinkedHashSet<>();
                views.put(viewName, view);
            }
            final List<SchemaProperty> schemaProperties = schemaView.getProperty(SchemaView.schemaProperties);
            for (final SchemaProperty property : schemaProperties) {
                if (property.getProperty(SchemaProperty.isBuiltinProperty) && !property.getProperty(SchemaProperty.isDynamic)) {
                    view.add(SchemaHelper.cleanPropertyName(property.getPropertyName()));
                } else {
                    view.add(SchemaHelper.cleanPropertyName(property.getPropertyName() + "Property"));
                }
            }
            // add properties that are not part of the graph
            if (StringUtils.isNotBlank(nonGraphProperties)) {
                for (final String propertyName : nonGraphProperties.split("[, ]+")) {
                    if (SchemaHelper.isDynamic(entity.getClassName(), propertyName)) {
                        view.add(SchemaHelper.cleanPropertyName(propertyName + "Property"));
                    } else if (relPropertyNames.contains(propertyName)) {
                        view.add(SchemaHelper.cleanPropertyName(propertyName) + "Property");
                    } else if (basePropertyNames.contains(propertyName)) {
                        view.add(SchemaHelper.cleanPropertyName(propertyName));
                    } else {
                        logger.warn("Unknown property {} in non-graph properties, ignoring.", propertyName);
                        SchemaHelper.isDynamic(entity.getClassName(), propertyName);
                    }
                }
            }
            final String order = schemaView.getProperty(SchemaView.sortOrder);
            if (order != null) {
                applySortOrder(view, order);
            }
        }
    }
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) PropertyContainer(org.structr.api.graph.PropertyContainer) SchemaProperty(org.structr.core.entity.SchemaProperty) StringProperty(org.structr.core.property.StringProperty) LinkedList(java.util.LinkedList) SchemaView(org.structr.core.entity.SchemaView) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode)

Example 7 with SchemaProperty

use of org.structr.core.entity.SchemaProperty in project structr by structr.

the class StructrNumberProperty method createDatabaseSchema.

@Override
SchemaProperty createDatabaseSchema(final App app, final AbstractSchemaNode schemaNode) throws FrameworkException {
    final SchemaProperty property = super.createDatabaseSchema(app, schemaNode);
    final PropertyMap properties = new PropertyMap();
    properties.put(SchemaProperty.propertyType, Type.Double.name());
    if (minimum != null && maximum != null) {
        final StringBuilder range = new StringBuilder();
        if (exclusiveMinimum) {
            range.append("]");
        } else {
            range.append("[");
        }
        range.append(minimum);
        range.append(",");
        range.append(maximum);
        if (exclusiveMaximum) {
            range.append("[");
        } else {
            range.append("]");
        }
        properties.put(SchemaProperty.format, range.toString());
    }
    property.setProperties(SecurityContext.getSuperUserInstance(), properties);
    return property;
}
Also used : SchemaProperty(org.structr.core.entity.SchemaProperty) PropertyMap(org.structr.core.property.PropertyMap)

Example 8 with SchemaProperty

use of org.structr.core.entity.SchemaProperty in project structr by structr.

the class StructrPasswordProperty method createDatabaseSchema.

@Override
SchemaProperty createDatabaseSchema(final App app, final AbstractSchemaNode schemaNode) throws FrameworkException {
    final SchemaProperty property = super.createDatabaseSchema(app, schemaNode);
    final PropertyMap properties = new PropertyMap();
    properties.put(SchemaProperty.propertyType, Type.Password.name());
    properties.put(SchemaProperty.format, getFormat());
    properties.put(SchemaProperty.contentType, getContentType());
    property.setProperties(SecurityContext.getSuperUserInstance(), properties);
    return property;
}
Also used : SchemaProperty(org.structr.core.entity.SchemaProperty) PropertyMap(org.structr.core.property.PropertyMap)

Example 9 with SchemaProperty

use of org.structr.core.entity.SchemaProperty in project structr by structr.

the class StructrStringArrayProperty method createDatabaseSchema.

@Override
SchemaProperty createDatabaseSchema(final App app, final AbstractSchemaNode schemaNode) throws FrameworkException {
    final SchemaProperty property = super.createDatabaseSchema(app, schemaNode);
    property.setProperty(SchemaProperty.propertyType, Type.StringArray.name());
    return property;
}
Also used : SchemaProperty(org.structr.core.entity.SchemaProperty)

Example 10 with SchemaProperty

use of org.structr.core.entity.SchemaProperty in project structr by structr.

the class StructrStringProperty method createDatabaseSchema.

@Override
SchemaProperty createDatabaseSchema(final App app, final AbstractSchemaNode schemaNode) throws FrameworkException {
    final SchemaProperty property = super.createDatabaseSchema(app, schemaNode);
    final PropertyMap properties = new PropertyMap();
    properties.put(SchemaProperty.propertyType, Type.String.name());
    properties.put(SchemaProperty.format, getFormat());
    properties.put(SchemaProperty.contentType, getContentType());
    property.setProperties(SecurityContext.getSuperUserInstance(), properties);
    return property;
}
Also used : SchemaProperty(org.structr.core.entity.SchemaProperty) PropertyMap(org.structr.core.property.PropertyMap)

Aggregations

SchemaProperty (org.structr.core.entity.SchemaProperty)34 PropertyMap (org.structr.core.property.PropertyMap)23 FrameworkException (org.structr.common.error.FrameworkException)7 SchemaNode (org.structr.core.entity.SchemaNode)7 Tx (org.structr.core.graph.Tx)7 LinkedList (java.util.LinkedList)5 App (org.structr.core.app.App)5 StructrApp (org.structr.core.app.StructrApp)5 Test (org.junit.Test)4 SchemaMethod (org.structr.core.entity.SchemaMethod)4 SchemaView (org.structr.core.entity.SchemaView)4 AbstractSchemaNode (org.structr.core.entity.AbstractSchemaNode)3 FrontendTest (org.structr.web.basic.FrontendTest)3 ResourceAccessTest (org.structr.web.basic.ResourceAccessTest)3 LinkedHashSet (java.util.LinkedHashSet)2 TreeSet (java.util.TreeSet)2 PropertyContainer (org.structr.api.graph.PropertyContainer)2 NodeAttribute (org.structr.core.graph.NodeAttribute)2 StructrPath (org.structr.files.ssh.filesystem.StructrPath)2 URI (java.net.URI)1