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);
}
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;
}
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);
}
}
}
}
}
}
}
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.");
}
}
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);
}
Aggregations