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