Search in sources :

Example 66 with NodeAttribute

use of org.structr.core.graph.NodeAttribute in project structr by structr.

the class StructrApp method create.

@Override
public <T extends NodeInterface> T create(final Class<T> type, final NodeAttribute<?>... attributes) throws FrameworkException {
    final List<NodeAttribute<?>> attrs = new LinkedList<>(Arrays.asList(attributes));
    final CreateNodeCommand<T> command = command(CreateNodeCommand.class);
    // add type information when creating a node
    attrs.add(new NodeAttribute(AbstractNode.type, type.getSimpleName()));
    return command.execute(attrs);
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) LinkedList(java.util.LinkedList)

Example 67 with NodeAttribute

use of org.structr.core.graph.NodeAttribute in project structr by structr.

the class SchemaHelper method createDynamicGrants.

public static List<DynamicResourceAccess> createDynamicGrants(final String signature) {
    final List<DynamicResourceAccess> grants = new LinkedList<>();
    final long initialFlagsValue = 0;
    final App app = StructrApp.getInstance();
    try {
        ResourceAccess grant = app.nodeQuery(ResourceAccess.class).and(ResourceAccess.signature, signature).getFirst();
        if (grant == null) {
            // create new grant
            grants.add(app.create(DynamicResourceAccess.class, new NodeAttribute(DynamicResourceAccess.signature, signature), new NodeAttribute(DynamicResourceAccess.flags, initialFlagsValue)));
            logger.debug("New signature created: {}", new Object[] { (signature) });
        }
        final String schemaSig = schemaResourceSignature(signature);
        ResourceAccess schemaGrant = app.nodeQuery(ResourceAccess.class).and(ResourceAccess.signature, schemaSig).getFirst();
        if (schemaGrant == null) {
            // create additional grant for the _schema resource
            grants.add(app.create(DynamicResourceAccess.class, new NodeAttribute(DynamicResourceAccess.signature, schemaSig), new NodeAttribute(DynamicResourceAccess.flags, initialFlagsValue)));
            logger.debug("New signature created: {}", new Object[] { schemaSig });
        }
        final String uiSig = uiViewResourceSignature(signature);
        ResourceAccess uiViewGrant = app.nodeQuery(ResourceAccess.class).and(ResourceAccess.signature, uiSig).getFirst();
        if (uiViewGrant == null) {
            // create additional grant for the Ui view
            grants.add(app.create(DynamicResourceAccess.class, new NodeAttribute(DynamicResourceAccess.signature, uiSig), new NodeAttribute(DynamicResourceAccess.flags, initialFlagsValue)));
            logger.debug("New signature created: {}", new Object[] { uiSig });
        }
    } catch (Throwable t) {
        logger.warn("", t);
    }
    return grants;
}
Also used : DynamicResourceAccess(org.structr.core.entity.DynamicResourceAccess) App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) ResourceAccess(org.structr.core.entity.ResourceAccess) DynamicResourceAccess(org.structr.core.entity.DynamicResourceAccess) NodeAttribute(org.structr.core.graph.NodeAttribute) LinkedList(java.util.LinkedList)

Example 68 with NodeAttribute

use of org.structr.core.graph.NodeAttribute in project structr by structr.

the class OWLInstance method resolveRelationships.

public void resolveRelationships(final JsonSchema schema, final Map<String, OWLClass> owlClassesByFragment, final Map<URI, OWLInstance> instances, final Map<String, RDFDescription> descriptions, final Map<String, OWLProperty> properties) throws FrameworkException {
    if (instance != null && type != null) {
        OWLParserv2.logger.println("#################################################################################################");
        OWLParserv2.logger.println("Resolving relationships of " + type.getStructrName(true) + ": " + getId());
        final ConfigurationProvider config = StructrApp.getConfiguration();
        final NodeList propertyElements = getElement().getChildNodes();
        if (propertyElements != null) {
            final int len = propertyElements.getLength();
            for (int i = 0; i < len; i++) {
                final Node propertyElement = propertyElements.item(i);
                if (propertyElement instanceof Element) {
                    final Element element = (Element) propertyElement;
                    final String tagName = RDFItem.cleanName(element.getTagName());
                    final String reference = getAttribute(element, "rdf:resource");
                    if (reference != null) {
                        final OWLInstance relatedInstance = instances.get(URI.create(reference));
                        if (relatedInstance != null) {
                            final OWLClass relationshipType = owlClassesByFragment.get(tagName);
                            if (relationshipType != null) {
                                final List<OWLClass> sourceTypes = relationshipType.getActualSourceTypes();
                                final List<OWLClass> targetTypes = relationshipType.getActualTargetTypes();
                                final Class hyperRelationshipType = config.getNodeEntityClass(tagName);
                                if (hyperRelationshipType != null) {
                                    if (sourceTypes.size() == 1 && targetTypes.size() == 1) {
                                        final OWLClass sourceType = sourceTypes.get(0);
                                        final OWLClass targetType = targetTypes.get(0);
                                        final String sourcePropertyName = sourceType.getStructrName(false);
                                        final String targetPropertyName = targetType.getStructrName(false);
                                        final PropertyKey sourceKey = StructrApp.key(hyperRelationshipType, sourcePropertyName);
                                        final PropertyKey targetKey = StructrApp.key(hyperRelationshipType, targetPropertyName);
                                        if (sourceKey != null && targetKey != null) {
                                            if (this.instance != null && relatedInstance.instance != null) {
                                                final NodeInterface hyperNode = StructrApp.getInstance().create(hyperRelationshipType, new NodeAttribute(sourceKey, this.instance), new NodeAttribute(targetKey, relatedInstance.instance));
                                                // resolve properties that come via rdf:Description
                                                final String referenceId = getAttribute(element, "rdf:ID");
                                                if (referenceId != null && hyperNode != null) {
                                                    final RDFDescription description = descriptions.get(referenceId);
                                                    if (description != null) {
                                                        description.resolveProperties(hyperNode, owlClassesByFragment, properties);
                                                    }
                                                }
                                            } else {
                                                System.out.println("!!!!!!!! No instance found to set on " + getId());
                                            }
                                        } else {
                                            System.out.println("        No property keys found for " + sourcePropertyName + ", " + targetPropertyName);
                                        }
                                    } else {
                                        System.out.println("        Ambiguous source or target types: " + sourceTypes + ", " + targetTypes);
                                    }
                                } else {
                                    System.out.println("        Relationship type " + tagName + " not found for " + getId());
                                }
                            } else {
                                System.out.println("No type found for " + tagName);
                            }
                        } else {
                            System.out.println("        No instance found for " + reference);
                        }
                    }
                }
            }
        }
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) ConfigurationProvider(org.structr.schema.ConfigurationProvider) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) AbstractNode(org.structr.core.entity.AbstractNode) Element(org.w3c.dom.Element) PropertyKey(org.structr.core.property.PropertyKey) NodeInterface(org.structr.core.graph.NodeInterface)

Example 69 with NodeAttribute

use of org.structr.core.graph.NodeAttribute in project structr by structr.

the class OWLInstance method createDatabaseNode.

public void createDatabaseNode(final App app) throws FrameworkException {
    final ConfigurationProvider config = StructrApp.getConfiguration();
    final String className = type.getStructrName(true);
    nodeType = config.getNodeEntityClass(className);
    if (nodeType != null) {
        originIdKey = StructrApp.key(nodeType, "originId");
        if (originIdKey != null) {
            instance = app.create(nodeType, new NodeAttribute(originIdKey, getId().toString()));
            if (instance != null) {
                instances.put(getId(), instance);
            }
        } else {
            OWLParserv2.logger.println("NOT creating instance for " + getId() + ", no originId property key found.");
        }
    } else {
        OWLParserv2.logger.println("NOT creating instance for " + getId() + ", no node type found.");
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) ConfigurationProvider(org.structr.schema.ConfigurationProvider)

Example 70 with NodeAttribute

use of org.structr.core.graph.NodeAttribute in project structr by structr.

the class StructrUiTest method createTestNode.

protected <T extends NodeInterface> T createTestNode(final Class<T> type, final NodeAttribute... attrs) throws FrameworkException {
    final PropertyMap props = new PropertyMap();
    props.put(AbstractNode.type, type.getSimpleName());
    props.put(AbstractNode.name, type.getSimpleName());
    for (final NodeAttribute attr : attrs) {
        props.put(attr.getKey(), attr.getValue());
    }
    return app.create(type, props);
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) PropertyMap(org.structr.core.property.PropertyMap)

Aggregations

NodeAttribute (org.structr.core.graph.NodeAttribute)73 Tx (org.structr.core.graph.Tx)55 FrameworkException (org.structr.common.error.FrameworkException)54 Test (org.junit.Test)45 App (org.structr.core.app.App)23 StructrApp (org.structr.core.app.StructrApp)23 StructrUiTest (org.structr.web.StructrUiTest)21 LinkedList (java.util.LinkedList)19 PropertyKey (org.structr.core.property.PropertyKey)17 SchemaNode (org.structr.core.entity.SchemaNode)14 NodeInterface (org.structr.core.graph.NodeInterface)13 Principal (org.structr.core.entity.Principal)12 PropertyMap (org.structr.core.property.PropertyMap)12 StringProperty (org.structr.core.property.StringProperty)10 ConfigurationProvider (org.structr.schema.ConfigurationProvider)10 File (org.structr.web.entity.File)10 Folder (org.structr.web.entity.Folder)9 AbstractFile (org.structr.web.entity.AbstractFile)8 List (java.util.List)7 StructrTest (org.structr.common.StructrTest)7