use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class DeleteRelationshipCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final AbstractRelationship obj = getRelationship(webSocketData.getId());
if (obj != null) {
StructrApp.getInstance(securityContext).delete(obj);
}
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class AbstractCommand method getRelationship.
/**
* Returns the relationship to which the uuid parameter
* of this command refers to.
*
* @param id
* @return the node
*/
public AbstractRelationship getRelationship(final String id) {
if (id == null) {
return null;
}
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
final AbstractRelationship rel = (AbstractRelationship) app.getRelationshipById(id);
tx.success();
return rel;
} catch (FrameworkException fex) {
logger.warn("Unable to get relationship", fex);
}
return null;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class GraphObject method setProperties.
/**
* Sets the given properties.
*
* @param securityContext
* @param properties
* @throws FrameworkException
*/
default void setProperties(final SecurityContext securityContext, final PropertyMap properties) throws FrameworkException {
final CreationContainer container = new CreationContainer(this);
boolean atLeastOnePropertyChanged = false;
for (final Entry<PropertyKey, Object> attr : properties.entrySet()) {
final PropertyKey key = attr.getKey();
final Object value = attr.getValue();
if (key.indexable(value)) {
final Object oldValue = getProperty(key);
if (!value.equals(oldValue)) {
atLeastOnePropertyChanged = true;
// bulk set possible, store in container
key.setProperty(securityContext, container, value);
if (isNode()) {
if (!key.isUnvalidated()) {
TransactionCommand.nodeModified(securityContext.getCachedUser(), (AbstractNode) this, key, getProperty(key), value);
}
if (key instanceof TypeProperty) {
if (this instanceof NodeInterface) {
final Class type = StructrApp.getConfiguration().getNodeEntityClass((String) value);
TypeProperty.updateLabels(StructrApp.getInstance().getDatabaseService(), (NodeInterface) this, type, true);
}
}
} else if (isRelationship()) {
if (!key.isUnvalidated()) {
TransactionCommand.relationshipModified(securityContext.getCachedUser(), (AbstractRelationship) this, key, getProperty(key), value);
}
if (key instanceof TypeProperty) {
if (this instanceof NodeInterface) {
final Class type = StructrApp.getConfiguration().getNodeEntityClass((String) value);
TypeProperty.updateLabels(StructrApp.getInstance().getDatabaseService(), (NodeInterface) this, type, true);
}
}
}
}
} else {
// bulk set NOT possible, set on entity
if (key.isSystemInternal()) {
unlockSystemPropertiesOnce();
}
setProperty(key, value);
}
}
if (atLeastOnePropertyChanged) {
// set primitive values directly for better performance
getPropertyContainer().setProperties(container.getData());
}
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class BulkRebuildIndexCommand method rebuildRelationshipIndex.
private void rebuildRelationshipIndex(final String relType) {
final RelationshipFactory relFactory = new RelationshipFactory(SecurityContext.getSuperUserInstance());
final DatabaseService graphDb = (DatabaseService) arguments.get("graphDb");
final Iterator<AbstractRelationship> relIterator = Iterables.map(relFactory, Iterables.filter(new StructrAndSpatialPredicate(true, false, false), graphDb.getRelationshipsByType(relType))).iterator();
if (relType == null) {
info("Relationship type not set, starting (re-)indexing all relationships");
} else {
info("Starting (re-)indexing all relationships of type {}", new Object[] { relType });
}
long count = bulkGraphOperation(securityContext, relIterator, 1000, "RebuildRelIndex", new BulkGraphOperation<AbstractRelationship>() {
@Override
public void handleGraphObject(SecurityContext securityContext, AbstractRelationship rel) {
rel.updateInIndex();
}
@Override
public void handleThrowable(SecurityContext securityContext, Throwable t, AbstractRelationship rel) {
logger.warn("Unable to index relationship {}: {}", new Object[] { rel, t.getMessage() });
}
@Override
public void handleTransactionFailure(SecurityContext securityContext, Throwable t) {
logger.warn("Unable to index relationship: {}", t.getMessage());
}
});
info("Done with (re-)indexing {} relationships", count);
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class DeleteNodeCommand method doDeleteNode.
private void doDeleteNode(final NodeInterface node) {
if (TransactionCommand.isDeleted(node.getNode())) {
return;
}
try {
if (!deletedNodes.contains(node) && node.getUuid() == null) {
logger.warn("Will not delete node which has no UUID, dumping stack.");
Thread.dumpStack();
return;
}
} catch (java.lang.IllegalStateException ise) {
logger.warn("Trying to delete a node which is already deleted", ise.getMessage());
return;
} catch (org.structr.api.NotFoundException nfex) {
// exception can be ignored, node is already deleted
}
deletedNodes.add(node);
App app = StructrApp.getInstance(securityContext);
try {
List<NodeInterface> nodesToCheckAfterDeletion = new LinkedList<>();
// by relationships which are marked with DELETE_OUTGOING
for (AbstractRelationship rel : node.getOutgoingRelationships()) {
// deleted rels can be null..
if (rel != null) {
int cascadeDelete = rel.cascadeDelete();
NodeInterface endNode = rel.getTargetNode();
if ((cascadeDelete & Relation.CONSTRAINT_BASED) == Relation.CONSTRAINT_BASED) {
nodesToCheckAfterDeletion.add(endNode);
}
if (!deletedNodes.contains(endNode) && ((cascadeDelete & Relation.SOURCE_TO_TARGET) == Relation.SOURCE_TO_TARGET)) {
// remove end node from index
endNode.removeFromIndex();
doDeleteNode(endNode);
}
}
}
// by relationships which are marked with DELETE_INCOMING
for (AbstractRelationship rel : node.getIncomingRelationships()) {
// deleted rels can be null
if (rel != null) {
final int cascadeDelete = rel.cascadeDelete();
final NodeInterface startNode = rel.getSourceNode();
if ((cascadeDelete & Relation.CONSTRAINT_BASED) == Relation.CONSTRAINT_BASED) {
nodesToCheckAfterDeletion.add(startNode);
}
if (!deletedNodes.contains(startNode) && ((cascadeDelete & Relation.TARGET_TO_SOURCE) == Relation.TARGET_TO_SOURCE)) {
// remove start node from index
startNode.removeFromIndex();
doDeleteNode(startNode);
}
}
}
// deletion callback, must not prevent node deletion!
node.onNodeDeletion();
// Delete any relationship (this is PASSIVE DELETION)
for (AbstractRelationship r : node.getRelationships()) {
if (r != null) {
app.delete(r);
}
}
// still valid after node deletion
for (NodeInterface nodeToCheck : nodesToCheckAfterDeletion) {
ErrorBuffer errorBuffer = new ErrorBuffer();
if (!deletedNodes.contains(nodeToCheck) && !nodeToCheck.isValid(errorBuffer)) {
// remove end node from index
nodeToCheck.removeFromIndex();
doDeleteNode(nodeToCheck);
}
}
} catch (Throwable t) {
t.printStackTrace();
logger.warn("Exception while deleting node {}: {}", node, t.getMessage());
}
return;
}
Aggregations