Search in sources :

Example 11 with AbstractRelationship

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

the class BasicTest method test07CascadeDeleteConditional.

/**
 * DELETE_IF_CONSTRAINT_WOULD_BE_VIOLATED should
 * trigger delete cascade from start to end node only
 * if the remote node would not be valid afterwards
 */
@Test
public void test07CascadeDeleteConditional() {
    try {
        AbstractRelationship rel = cascadeRel(TestOne.class, TestTwo.class, Relation.CONSTRAINT_BASED);
        NodeInterface sourceNode;
        String startNodeId;
        String endNodeId;
        try (final Tx tx = app.tx()) {
            startNodeId = rel.getSourceNode().getUuid();
            endNodeId = rel.getTargetNode().getUuid();
            sourceNode = rel.getSourceNode();
        }
        deleteCascade(sourceNode);
        try (final Tx tx = app.tx()) {
            // Start node should be deleted
            assertNodeNotFound(startNodeId);
            // End node should be deleted
            assertNodeNotFound(endNodeId);
        }
        rel = cascadeRel(TestOne.class, TestThree.class, Relation.CONSTRAINT_BASED);
        try (final Tx tx = app.tx()) {
            startNodeId = rel.getSourceNode().getUuid();
            endNodeId = rel.getTargetNode().getUuid();
            sourceNode = rel.getSourceNode();
        }
        deleteCascade(sourceNode);
        try (final Tx tx = app.tx()) {
            // Start node should be deleted
            assertNodeNotFound(startNodeId);
            // End node should still be there
            assertNodeExists(endNodeId);
        }
        rel = cascadeRel(TestOne.class, TestFour.class, Relation.CONSTRAINT_BASED);
        try (final Tx tx = app.tx()) {
            startNodeId = rel.getSourceNode().getUuid();
            endNodeId = rel.getTargetNode().getUuid();
            sourceNode = rel.getSourceNode();
        }
        deleteCascade(sourceNode);
        try (final Tx tx = app.tx()) {
            // Start node should be deleted
            assertNodeNotFound(startNodeId);
            // End node should still be there
            assertNodeExists(endNodeId);
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : TestFour(org.structr.core.entity.TestFour) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestThree(org.structr.core.entity.TestThree) AbstractRelationship(org.structr.core.entity.AbstractRelationship) TestOne(org.structr.core.entity.TestOne) NodeInterface(org.structr.core.graph.NodeInterface) Test(org.junit.Test)

Example 12 with AbstractRelationship

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

the class StructrConfigHtmlWriter method value.

@Override
public RestWriter value(String value) throws IOException {
    if (!hasName) {
        currentElement = currentElement.block("li");
    }
    if ("id".equals(lastName)) {
        if (currentObject == null) {
            currentElement.inline("a").css("id").attr(new Href(restPath + "/" + value + propertyView)).text("\"", value, "\"");
        } else if (currentObject instanceof AbstractRelationship) {
            currentElement.inline("a").css("id").attr(new Href(restPath + "/" + currentObject.getProperty(AbstractRelationship.type) + "/" + value + propertyView)).text("\"", value, "\"");
        } else {
            currentElement.inline("a").css("id").attr(new Href(restPath + "/" + currentObject.getType() + "/" + value + propertyView)).text("\"", value, "\"");
        }
    } else {
        // escape backslashes in strings
        value = value.replaceAll("\\\\", "\\\\\\\\");
        // escape quotation marks inside strings
        value = value.replaceAll("\"", "\\\\\\\"");
        // Escape for HTML output
        value = StringUtils.replaceEach(value, new String[] { "&", "<", ">" }, new String[] { "&amp;", "&lt;", "&gt;" });
        currentElement.inline("span").css("string").text("\"", value, "\"");
    }
    // end LI
    currentElement = currentElement.parent();
    hasName = false;
    return this;
}
Also used : AbstractRelationship(org.structr.core.entity.AbstractRelationship) Href(org.structr.api.util.html.attr.Href)

Example 13 with AbstractRelationship

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

the class StructrJsonHtmlWriter method value.

@Override
public RestWriter value(String value) throws IOException {
    if (!hasName) {
        currentElement = currentElement.block("li");
    }
    if ("id".equals(lastName)) {
        if (currentObject == null) {
            currentElement.inline("a").css("id").attr(new Href(restPath + "/" + value + propertyView)).text("\"", value, "\"");
        } else if (currentObject instanceof AbstractRelationship) {
            currentElement.inline("a").css("id").attr(new Href(restPath + "/" + currentObject.getProperty(AbstractRelationship.type) + "/" + value + propertyView)).text("\"", value, "\"");
        } else {
            currentElement.inline("a").css("id").attr(new Href(restPath + "/" + currentObject.getType() + "/" + value + propertyView)).text("\"", value, "\"");
        }
    } else {
        // escape backslashes in strings
        value = value.replaceAll("\\\\", "\\\\\\\\");
        // escape quotation marks inside strings
        value = value.replaceAll("\"", "\\\\\\\"");
        // Escape for HTML output
        value = StringUtils.replaceEach(value, new String[] { "&", "<", ">" }, new String[] { "&amp;", "&lt;", "&gt;" });
        currentElement.inline("span").css("string").text("\"", value, "\"");
    }
    // end LI
    currentElement = currentElement.parent();
    hasName = false;
    return this;
}
Also used : AbstractRelationship(org.structr.core.entity.AbstractRelationship) Href(org.structr.api.util.html.attr.Href)

Example 14 with AbstractRelationship

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

the class RelationshipEndNodeTypeConverter method revert.

@Override
public Object revert(String source) {
    if (currentObject instanceof AbstractRelationship) {
        final AbstractRelationship rel = (AbstractRelationship) currentObject;
        final NodeInterface endNode = rel.getTargetNode();
        if (endNode != null) {
            return endNode.getType();
        }
    }
    return null;
}
Also used : AbstractRelationship(org.structr.core.entity.AbstractRelationship) NodeInterface(org.structr.core.graph.NodeInterface)

Example 15 with AbstractRelationship

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

the class RelationshipStartNodeTypeConverter method revert.

@Override
public Object revert(Object source) {
    if (currentObject instanceof AbstractRelationship) {
        final AbstractRelationship rel = (AbstractRelationship) currentObject;
        final NodeInterface startNode = rel.getSourceNode();
        if (startNode != null) {
            return startNode.getType();
        }
    }
    return null;
}
Also used : AbstractRelationship(org.structr.core.entity.AbstractRelationship) NodeInterface(org.structr.core.graph.NodeInterface)

Aggregations

AbstractRelationship (org.structr.core.entity.AbstractRelationship)31 NodeInterface (org.structr.core.graph.NodeInterface)15 FrameworkException (org.structr.common.error.FrameworkException)11 AbstractNode (org.structr.core.entity.AbstractNode)9 SecurityContext (org.structr.common.SecurityContext)7 GraphObject (org.structr.core.GraphObject)6 Tx (org.structr.core.graph.Tx)6 Test (org.junit.Test)4 DatabaseService (org.structr.api.DatabaseService)4 App (org.structr.core.app.App)4 StructrApp (org.structr.core.app.StructrApp)4 ArrayList (java.util.ArrayList)3 TestOne (org.structr.core.entity.TestOne)3 PropertyKey (org.structr.core.property.PropertyKey)3 Href (org.structr.api.util.html.attr.Href)2 TestTwo (org.structr.core.entity.TestTwo)2 CreationContainer (org.structr.core.graph.CreationContainer)2 DOMNode (org.structr.web.entity.dom.DOMNode)2 FileOutputStream (java.io.FileOutputStream)1 HashSet (java.util.HashSet)1