Search in sources :

Example 6 with NotFoundException

use of org.structr.api.NotFoundException in project structr by structr.

the class BasicTest method test01DeleteRelationship.

@Test
public void test01DeleteRelationship() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestSix testSix = createTestNode(TestSix.class);
        SixOneOneToOne rel = null;
        assertNotNull(testOne);
        assertNotNull(testSix);
        try (final Tx tx = app.tx()) {
            rel = app.create(testSix, testOne, SixOneOneToOne.class);
            tx.success();
        }
        assertNotNull(rel);
        try {
            // try to delete relationship
            rel.getRelationship().delete();
            fail("Should have raised an org.neo4j.graphdb.NotInTransactionException");
        } catch (NotInTransactionException e) {
        }
        // Relationship still there
        assertNotNull(rel);
        try (final Tx tx = app.tx()) {
            app.delete(rel);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            String uuid = rel.getUuid();
            fail("Deleted entity should have thrown an exception on access.");
        } catch (NotFoundException iex) {
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NotInTransactionException(org.structr.api.NotInTransactionException) NotFoundException(org.structr.api.NotFoundException) TestOne(org.structr.core.entity.TestOne) SixOneOneToOne(org.structr.core.entity.SixOneOneToOne) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 7 with NotFoundException

use of org.structr.api.NotFoundException in project structr by structr.

the class CypherTest method test04DeleteAfterIndexLookup.

@Test
public void test04DeleteAfterIndexLookup() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestSix testSix = createTestNode(TestSix.class);
        SixOneOneToOne rel = null;
        assertNotNull(testOne);
        assertNotNull(testSix);
        try (final Tx tx = app.tx()) {
            rel = app.create(testSix, testOne, SixOneOneToOne.class);
            tx.success();
        }
        assertNotNull(rel);
        try (final Tx tx = app.tx()) {
            GraphObject searchRes = app.getNodeById(testSix.getUuid());
            assertNotNull(searchRes);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            testSix.getRelationships().iterator().next().getRelationship().delete();
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            rel.getUuid();
            fail("Accessing a deleted relationship should thow an exception.");
            tx.success();
        } catch (NotFoundException nfex) {
            assertNotNull(nfex.getMessage());
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NotFoundException(org.structr.api.NotFoundException) TestOne(org.structr.core.entity.TestOne) GraphObject(org.structr.core.GraphObject) SixOneOneToOne(org.structr.core.entity.SixOneOneToOne) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 8 with NotFoundException

use of org.structr.api.NotFoundException in project structr by structr.

the class SyncTransmission method doRemote.

@Override
public Boolean doRemote(final CloudConnection client) throws IOException, FrameworkException {
    int count = 0;
    try (final Tx tx = StructrApp.getInstance().tx()) {
        for (final ModificationEvent event : transaction) {
            final GraphObject graphObject = event.getGraphObject();
            if (event.isDeleted()) {
                final String id = event.getRemovedProperties().get(GraphObject.id);
                if (id != null) {
                    client.send(new Delete(id));
                }
            } else {
                try {
                    final Set<String> propertyKeys = new LinkedHashSet<>();
                    // collect all possibly modified property keys
                    mapPropertyKeysToStrings(propertyKeys, event.getNewProperties().keySet());
                    mapPropertyKeysToStrings(propertyKeys, event.getModifiedProperties().keySet());
                    mapPropertyKeysToStrings(propertyKeys, event.getRemovedProperties().keySet());
                    if (graphObject.isNode()) {
                        if (graphObject instanceof File) {
                            sendFile(client, (File) graphObject, CloudService.CHUNK_SIZE);
                        } else {
                            client.send(new NodeDataContainer(graphObject.getSyncNode(), count, propertyKeys));
                        }
                    } else {
                        client.send(new RelationshipDataContainer(graphObject.getSyncRelationship(), count, propertyKeys));
                    }
                } catch (NotFoundException nfex) {
                    logger.info("Trying to synchronize deleted entity, ignoring");
                }
            }
            count++;
        }
        tx.success();
    }
    // synchronize last sync timestamp with slave instance
    // (we're sending out own instance ID (master) for the slave to store)
    final String masterId = StructrApp.getInstance().getInstanceId();
    client.send(new ReplicationStatus(masterId, StructrApp.getInstance().getGlobalSetting(masterId + ".lastModified", 0L)));
    // wait for end of transmission
    client.waitForTransmission();
    return true;
}
Also used : Delete(org.structr.cloud.message.Delete) LinkedHashSet(java.util.LinkedHashSet) Tx(org.structr.core.graph.Tx) FileNodeDataContainer(org.structr.cloud.message.FileNodeDataContainer) NodeDataContainer(org.structr.cloud.message.NodeDataContainer) NotFoundException(org.structr.api.NotFoundException) GraphObject(org.structr.core.GraphObject) RelationshipDataContainer(org.structr.cloud.message.RelationshipDataContainer) ModificationEvent(org.structr.core.graph.ModificationEvent) File(org.structr.dynamic.File)

Example 9 with NotFoundException

use of org.structr.api.NotFoundException in project structr by structr.

the class StructrApp method getRelationshipById.

@Override
public RelationshipInterface getRelationshipById(final Class type, final String uuid) throws FrameworkException {
    if (uuid == null) {
        return null;
    }
    final Long id = getRelFromCache(uuid);
    if (id == null) {
        final Query query = relationshipQuery().uuid(uuid);
        // set type for faster query
        if (type != null) {
            query.andType(type);
        } else {
            logger.warn("Relationship access by UUID is deprecated and not supported by Neo4j, this can take a very long time. Please examine the following stack trace and amend.");
            Thread.dumpStack();
        }
        final GraphObject entity = query.getFirst();
        if (entity != null) {
            relUuidMap.put(uuid, entity.getId());
            return (RelationshipInterface) entity;
        }
    } else {
        try {
            return relFactory.instantiate(getDatabaseService().getRelationshipById(id));
        } catch (NotFoundException ignore) {
            relUuidMap.remove(uuid);
        }
    }
    return null;
}
Also used : RelationshipInterface(org.structr.core.graph.RelationshipInterface) NotFoundException(org.structr.api.NotFoundException) GraphObject(org.structr.core.GraphObject)

Example 10 with NotFoundException

use of org.structr.api.NotFoundException in project structr by structr.

the class StructrApp method getNodeById.

@Override
public NodeInterface getNodeById(final Class type, final String uuid) throws FrameworkException {
    if (uuid == null) {
        return null;
    }
    final Long nodeId = getNodeFromCache(uuid);
    if (nodeId == null) {
        final Query query = nodeQuery().uuid(uuid);
        // set type for faster query
        if (type != null) {
            query.andType(type);
        }
        final GraphObject entity = query.getFirst();
        if (entity != null) {
            nodeUuidMap.put(uuid, entity.getId());
            return (NodeInterface) entity;
        }
    } else {
        try {
            return nodeFactory.instantiate(getDatabaseService().getNodeById(nodeId));
        } catch (NotFoundException ignore) {
            nodeUuidMap.remove(uuid);
        }
    }
    return null;
}
Also used : NotFoundException(org.structr.api.NotFoundException) GraphObject(org.structr.core.GraphObject) NodeInterface(org.structr.core.graph.NodeInterface)

Aggregations

NotFoundException (org.structr.api.NotFoundException)11 Tx (org.structr.core.graph.Tx)6 Test (org.junit.Test)5 FrameworkException (org.structr.common.error.FrameworkException)5 SixOneOneToOne (org.structr.core.entity.SixOneOneToOne)5 TestOne (org.structr.core.entity.TestOne)5 TestSix (org.structr.core.entity.TestSix)5 GraphObject (org.structr.core.GraphObject)4 LinkedHashSet (java.util.LinkedHashSet)2 NoSuchRecordException (org.neo4j.driver.v1.exceptions.NoSuchRecordException)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Record (org.neo4j.driver.v1.Record)1 StatementResult (org.neo4j.driver.v1.StatementResult)1 Value (org.neo4j.driver.v1.Value)1 ServiceUnavailableException (org.neo4j.driver.v1.exceptions.ServiceUnavailableException)1 TransientException (org.neo4j.driver.v1.exceptions.TransientException)1 DatabaseService (org.structr.api.DatabaseService)1 NetworkException (org.structr.api.NetworkException)1