Search in sources :

Example 1 with RelationshipInterface

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

the class StructrUiTest method createTestRelationships.

protected List<RelationshipInterface> createTestRelationships(final Class relType, final int number) throws FrameworkException {
    List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
    final GenericNode startNode = nodes.get(0);
    final GenericNode endNode = nodes.get(1);
    List<RelationshipInterface> rels = new LinkedList<>();
    for (int i = 0; i < number; i++) {
        rels.add(app.create(startNode, endNode, relType));
    }
    return rels;
}
Also used : GenericNode(org.structr.core.entity.GenericNode) RelationshipInterface(org.structr.core.graph.RelationshipInterface) LinkedList(java.util.LinkedList)

Example 2 with RelationshipInterface

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

the class Template method renderContent.

/*
	public static final org.structr.common.View uiView                                   = new org.structr.common.View(Content.class, PropertyView.Ui,
		children, childrenIds, content, contentType, parent, pageId, hideOnDetail, hideOnIndex, sharedComponent, syncedNodes, dataKey, restQuery, cypherQuery, xpathQuery, functionQuery,
		showForLocales, hideForLocales, showConditions, hideConditions, isContent
	);

	public static final org.structr.common.View publicView                               = new org.structr.common.View(Content.class, PropertyView.Public,
		children, childrenIds, content, contentType, parent, pageId, hideOnDetail, hideOnIndex, sharedComponent, syncedNodes, dataKey, restQuery, cypherQuery, xpathQuery, functionQuery,
		showForLocales, hideForLocales, showConditions, hideConditions, isContent
	);
	*/
public static void renderContent(final Template thisTemplate, final RenderContext renderContext, final int depth) throws FrameworkException {
    final SecurityContext securityContext = thisTemplate.getSecurityContext();
    final EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
    if (EditMode.DEPLOYMENT.equals(editMode)) {
        final DOMNode _syncedNode = thisTemplate.getSharedComponent();
        final AsyncBuffer out = renderContext.getBuffer();
        if (depth > 0) {
            out.append(DOMNode.indent(depth, renderContext));
        }
        DOMNode.renderDeploymentExportComments(thisTemplate, out, true);
        out.append("<structr:template src=\"");
        if (_syncedNode != null) {
            // use name of synced node
            final String _name = _syncedNode.getProperty(AbstractNode.name);
            out.append(_name != null ? _name.concat("-").concat(_syncedNode.getUuid()) : _syncedNode.getUuid());
        } else {
            // use name of local template
            final String _name = thisTemplate.getProperty(AbstractNode.name);
            out.append(_name != null ? _name.concat("-").concat(thisTemplate.getUuid()) : thisTemplate.getUuid());
        }
        out.append("\"");
        DOMNode.renderSharedComponentConfiguration(thisTemplate, out, editMode);
        // include custom attributes in templates as well!
        DOMNode.renderCustomAttributes(thisTemplate, out, securityContext, renderContext);
        out.append(">");
        // fetch children
        final List<RelationshipInterface> rels = thisTemplate.getChildRelationships();
        if (rels.isEmpty()) {
            // No child relationships, maybe this node is in sync with another node
            if (_syncedNode != null) {
                rels.addAll(_syncedNode.getChildRelationships());
            }
        }
        for (final RelationshipInterface rel : rels) {
            final DOMNode subNode = (DOMNode) rel.getTargetNode();
            subNode.render(renderContext, depth + 1);
        }
        out.append(DOMNode.indent(depth, renderContext));
        out.append("</structr:template>");
        out.append(DOMNode.indent(depth - 1, renderContext));
    } else {
        // "super" call using static method..
        Content.renderContent(thisTemplate, renderContext, depth);
    }
}
Also used : SecurityContext(org.structr.common.SecurityContext) RelationshipInterface(org.structr.core.graph.RelationshipInterface) EditMode(org.structr.web.common.RenderContext.EditMode) AsyncBuffer(org.structr.web.common.AsyncBuffer)

Example 3 with RelationshipInterface

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

the class ValidationHelper method isValidGloballyUniqueProperty.

public static synchronized boolean isValidGloballyUniqueProperty(final GraphObject object, final PropertyKey key, final ErrorBuffer errorBuffer) {
    if (key != null) {
        final Object value = object.getProperty(key);
        List<? extends GraphObject> result = null;
        try {
            if (object instanceof NodeInterface) {
                result = StructrApp.getInstance().nodeQuery(NodeInterface.class).and(key, value).disableSorting().getAsList();
            } else if (object instanceof RelationshipInterface) {
                result = StructrApp.getInstance().relationshipQuery(RelationshipInterface.class).and(key, value).disableSorting().getAsList();
            } else {
                logger.error("GraphObject is neither NodeInterface nor RelationshipInterface");
                return false;
            }
        } catch (FrameworkException fex) {
            logger.warn("Unable to fetch list of nodes for uniqueness check", fex);
        // handle error
        }
        if (result != null) {
            for (final GraphObject foundNode : result) {
                if (foundNode.getId() != object.getId()) {
                    // validation is aborted when the first validation failure occurs, so
                    // we can assume that the object currently exmained is the first
                    // existing object, hence all others get the error message with the
                    // UUID of the first one.
                    errorBuffer.add(new UniqueToken(object.getType(), key, object.getUuid()));
                    // error!
                    return false;
                }
            }
        }
    }
    // no error
    return true;
}
Also used : UniqueToken(org.structr.common.error.UniqueToken) FrameworkException(org.structr.common.error.FrameworkException) RelationshipInterface(org.structr.core.graph.RelationshipInterface) GraphObject(org.structr.core.GraphObject) GraphObject(org.structr.core.GraphObject) NodeInterface(org.structr.core.graph.NodeInterface)

Example 4 with RelationshipInterface

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

the class EndNodeGroup method getGroupedProperties.

@Override
public PropertyMap getGroupedProperties(SecurityContext securityContext, GraphObject source) {
    if (source instanceof RelationshipInterface) {
        RelationshipInterface rel = (RelationshipInterface) source;
        NodeInterface end = rel.getTargetNode();
        return super.getGroupedProperties(securityContext, end);
    }
    return null;
}
Also used : RelationshipInterface(org.structr.core.graph.RelationshipInterface) NodeInterface(org.structr.core.graph.NodeInterface)

Example 5 with RelationshipInterface

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

the class StartNodeGroup method getGroupedProperties.

@Override
public PropertyMap getGroupedProperties(SecurityContext securityContext, GraphObject source) {
    if (source instanceof AbstractRelationship) {
        RelationshipInterface rel = (RelationshipInterface) source;
        NodeInterface startNode = rel.getSourceNode();
        return super.getGroupedProperties(securityContext, startNode);
    }
    return null;
}
Also used : AbstractRelationship(org.structr.core.entity.AbstractRelationship) RelationshipInterface(org.structr.core.graph.RelationshipInterface) NodeInterface(org.structr.core.graph.NodeInterface)

Aggregations

RelationshipInterface (org.structr.core.graph.RelationshipInterface)28 NodeInterface (org.structr.core.graph.NodeInterface)15 GraphObject (org.structr.core.GraphObject)8 LinkedList (java.util.LinkedList)6 FrameworkException (org.structr.common.error.FrameworkException)6 PropertyMap (org.structr.core.property.PropertyMap)6 App (org.structr.core.app.App)5 StructrApp (org.structr.core.app.StructrApp)5 List (java.util.List)4 SecurityContext (org.structr.common.SecurityContext)4 AbstractNode (org.structr.core.entity.AbstractNode)4 GenericNode (org.structr.core.entity.GenericNode)4 Tx (org.structr.core.graph.Tx)4 RelationshipDataContainer (org.structr.cloud.message.RelationshipDataContainer)3 Result (org.structr.core.Result)3 PropertyKey (org.structr.core.property.PropertyKey)3 LinkedHashSet (java.util.LinkedHashSet)2 Test (org.junit.Test)2 NotFoundException (org.structr.api.NotFoundException)2 RelationshipType (org.structr.api.graph.RelationshipType)2