Search in sources :

Example 46 with AbstractNode

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

the class SearchAndSortingTest method test08SearchByStaticMethod02.

@Test
public void test08SearchByStaticMethod02() {
    try {
        PropertyMap props = new PropertyMap();
        final PropertyKey key = AbstractNode.name;
        final String name = "89w3hkl sdfghsdkljth";
        props.put(key, name);
        final AbstractNode node = createTestNode(TestOne.class, props);
        try (final Tx tx = app.tx()) {
            Result result = app.nodeQuery(TestOne.class).andName(name).includeDeletedAndHidden().getResult();
            assertTrue(result.size() == 1);
            assertTrue(result.get(0).equals(node));
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) TestOne(org.structr.core.entity.TestOne) PropertyKey(org.structr.core.property.PropertyKey) Result(org.structr.core.Result) Test(org.junit.Test)

Example 47 with AbstractNode

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

the class SearchAndSortingTest method test10SearchByEmptyDateField.

@Test
public void test10SearchByEmptyDateField() {
    try {
        PropertyMap props = new PropertyMap();
        AbstractNode node = createTestNode(TestOne.class, props);
        try (final Tx tx = app.tx()) {
            Result result = app.nodeQuery(TestOne.class).and(TestOne.aDate, null).includeDeletedAndHidden().getResult();
            assertTrue(result.size() == 1);
            assertTrue(result.get(0).equals(node));
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) TestOne(org.structr.core.entity.TestOne) Result(org.structr.core.Result) Test(org.junit.Test)

Example 48 with AbstractNode

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

the class SearchAndSortingTest method test13SearchByEmptyDoubleField.

@Test
public void test13SearchByEmptyDoubleField() {
    try {
        PropertyMap props = new PropertyMap();
        AbstractNode node = createTestNode(TestOne.class, props);
        try (final Tx tx = app.tx()) {
            Result result = app.nodeQuery(TestOne.class).and(TestOne.aDouble, null).includeDeletedAndHidden().getResult();
            assertTrue(result.size() == 1);
            assertTrue(result.get(0).equals(node));
            tx.success();
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) TestOne(org.structr.core.entity.TestOne) Result(org.structr.core.Result) Test(org.junit.Test)

Example 49 with AbstractNode

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

the class EntityResolverResource method doPost.

@Override
public RestMethodResult doPost(final Map<String, Object> propertySet) throws FrameworkException {
    // TODO: fetch nodes with superuser security context, collect forbidden nodes and return
    // in error response
    RestMethodResult result = new RestMethodResult(200);
    for (Object o : propertySet.values()) {
        if (o instanceof String) {
            String id = (String) o;
            AbstractNode node = (AbstractNode) StructrApp.getInstance().getNodeById(id);
            if (node != null) {
                result.addContent(node);
            }
        }
    }
    return result;
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) RestMethodResult(org.structr.rest.RestMethodResult)

Example 50 with AbstractNode

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

the class UpdateCommand method processMessage.

// ~--- methods --------------------------------------------------------
@Override
public void processMessage(final WebSocketMessage webSocketData) throws FrameworkException {
    final App app = StructrApp.getInstance(getWebSocket().getSecurityContext());
    final Boolean recValue = (Boolean) webSocketData.getNodeData().get("recursive");
    final String nodeId = (String) webSocketData.getNodeData().get("nodeId");
    final boolean rec = recValue != null ? recValue : false;
    final GraphObject obj = getGraphObject(webSocketData.getId(), nodeId);
    if (obj == null) {
        logger.warn("Graph object with uuid {} not found.", webSocketData.getId());
        getWebSocket().send(MessageBuilder.status().code(404).build(), true);
        return;
    }
    webSocketData.getNodeData().remove("recursive");
    // If it's a node, check permissions
    try (final Tx tx = app.tx()) {
        if (obj instanceof AbstractNode) {
            final AbstractNode node = (AbstractNode) obj;
            if (!node.isGranted(Permission.write, getWebSocket().getSecurityContext())) {
                getWebSocket().send(MessageBuilder.status().message("No write permission").code(400).build(), true);
                logger.warn("No write permission for {} on {}", new Object[] { getWebSocket().getCurrentUser().toString(), obj.toString() });
                tx.success();
                return;
            }
            tx.success();
        }
    }
    final Set<GraphObject> entities = new LinkedHashSet<>();
    PropertyMap properties = null;
    try (final Tx tx = app.tx()) {
        collectEntities(entities, obj, null, rec);
        properties = PropertyMap.inputTypeToJavaType(this.getWebSocket().getSecurityContext(), obj.getClass(), webSocketData.getNodeData());
        tx.success();
    }
    final Iterator<GraphObject> iterator = entities.iterator();
    while (iterator.hasNext()) {
        count = 0;
        try (final Tx tx = app.tx()) {
            while (iterator.hasNext() && count++ < 100) {
                setProperties(iterator.next(), properties, true);
            }
            // commit and close transaction
            tx.success();
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) LinkedHashSet(java.util.LinkedHashSet) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) AbstractNode(org.structr.core.entity.AbstractNode) GraphObject(org.structr.core.GraphObject)

Aggregations

AbstractNode (org.structr.core.entity.AbstractNode)62 FrameworkException (org.structr.common.error.FrameworkException)31 Tx (org.structr.core.graph.Tx)20 App (org.structr.core.app.App)18 StructrApp (org.structr.core.app.StructrApp)18 GraphObject (org.structr.core.GraphObject)17 SecurityContext (org.structr.common.SecurityContext)16 PropertyMap (org.structr.core.property.PropertyMap)12 Result (org.structr.core.Result)10 Test (org.junit.Test)9 AbstractRelationship (org.structr.core.entity.AbstractRelationship)9 LinkedList (java.util.LinkedList)8 TestOne (org.structr.core.entity.TestOne)8 DatabaseService (org.structr.api.DatabaseService)7 NodeInterface (org.structr.core.graph.NodeInterface)7 PropertyKey (org.structr.core.property.PropertyKey)7 Principal (org.structr.core.entity.Principal)6 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)5 DOMNode (org.structr.web.entity.dom.DOMNode)5 LinkedHashSet (java.util.LinkedHashSet)4