use of org.structr.core.entity.AbstractNode in project structr by structr.
the class PatchCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final PropertyKey<String> contentKey = StructrApp.key(Content.class, "content");
final AbstractNode node = getNode(webSocketData.getId());
Map<String, Object> properties = webSocketData.getNodeData();
String patch = (String) properties.get("patch");
if (node != null) {
final DiffMatchPatch dmp = new DiffMatchPatch();
final String oldText = node.getProperty(contentKey);
final LinkedList<Patch> patches = new LinkedList<>(dmp.patchFromText(patch));
final Object[] results = dmp.patchApply(patches, oldText);
try {
node.setProperty(contentKey, results[0].toString());
TransactionCommand.registerNodeCallback(node, callback);
} catch (Throwable t) {
logger.warn("Could not apply patch {}", patch);
getWebSocket().send(MessageBuilder.status().code(400).message("Could not apply patch. " + t.getMessage()).build(), true);
}
} else {
logger.warn("Node with uuid {} not found.", webSocketData.getId());
getWebSocket().send(MessageBuilder.status().code(404).message("Node with uuid " + webSocketData.getId() + " not found.").build(), true);
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class SetPermissionCommand method processMessage.
// ~--- methods --------------------------------------------------------
@Override
public void processMessage(final WebSocketMessage webSocketData) {
AbstractNode obj = getNode(webSocketData.getId());
boolean rec = (Boolean) webSocketData.getNodeData().get("recursive");
String principalId = (String) webSocketData.getNodeData().get("principalId");
String permission = (String) webSocketData.getNodeData().get("permission");
String action = (String) webSocketData.getNodeData().get("action");
if (principalId == null) {
logger.error("This command needs a principalId");
getWebSocket().send(MessageBuilder.status().code(400).build(), true);
}
Principal principal = (Principal) getNode(principalId);
if (principal == null) {
logger.error("No principal found with id {}", new Object[] { principalId });
getWebSocket().send(MessageBuilder.status().code(400).build(), true);
}
webSocketData.getNodeData().remove("recursive");
if (obj != null) {
final App app = StructrApp.getInstance(getWebSocket().getSecurityContext());
try (final Tx nestedTx = app.tx()) {
if (!((AbstractNode) obj).isGranted(Permission.accessControl, getWebSocket().getSecurityContext())) {
logger.warn("No access control permission for {} on {}", new Object[] { getWebSocket().getCurrentUser().toString(), obj.toString() });
getWebSocket().send(MessageBuilder.status().message("No access control permission").code(400).build(), true);
nestedTx.success();
return;
}
nestedTx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
}
try {
final Value<Tx> value = new StaticValue<>(null);
setPermission(value, app, obj, principal, action, Permissions.valueOf(permission), rec);
// commit and close transaction
final Tx tx = value.get(null);
if (tx != null) {
tx.success();
tx.close();
value.set(null, null);
}
webSocketData.setResult(Arrays.asList(principal));
// send only over local connection (no broadcast)
getWebSocket().send(webSocketData, true);
} catch (FrameworkException ex) {
logger.error("Unable to set permissions: {}", ((FrameworkException) ex).toString());
getWebSocket().send(MessageBuilder.status().code(400).build(), true);
}
} else {
logger.warn("Graph object with uuid {} not found.", webSocketData.getId());
getWebSocket().send(MessageBuilder.status().code(404).build(), true);
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class CMISAclService method applyAcl.
/**
* Applies the given Acl exclusively, i.e. removes all other permissions / grants first.
*
* @param repositoryId
* @param objectId
* @param acl
* @param aclPropagation
*
* @return the resulting Acl
*/
public Acl applyAcl(final String repositoryId, final String objectId, final Acl acl, final AclPropagation aclPropagation) {
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
final AbstractNode node = app.get(AbstractNode.class, objectId);
if (node != null) {
node.revokeAll();
// process add ACL entries
for (final Ace toAdd : acl.getAces()) {
applyAce(node, toAdd, false);
}
tx.success();
// return the wrapper which implements the Acl interface
return CMISObjectWrapper.wrap(node, null, false);
}
} catch (FrameworkException fex) {
logger.warn("", fex);
}
throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class Property method index.
@Override
public void index(final GraphObject entity, final Object value) {
if (entity instanceof AbstractNode) {
final NodeService nodeService = Services.getInstance().getService(NodeService.class);
final AbstractNode node = (AbstractNode) entity;
final Node dbNode = node.getNode();
final Index<Node> index = nodeService.getNodeIndex();
if (index != null) {
try {
index.remove(dbNode, dbName);
if (value != null || isIndexedWhenEmpty()) {
index.add(dbNode, dbName, value, valueType());
}
} catch (Throwable t) {
logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
logger.warn("", t);
}
}
} else if (entity instanceof AbstractRelationship) {
final NodeService nodeService = Services.getInstance().getService(NodeService.class);
final AbstractRelationship rel = (AbstractRelationship) entity;
final Relationship dbRel = rel.getRelationship();
final Index<Relationship> index = nodeService.getRelationshipIndex();
if (index != null) {
try {
index.remove(dbRel, dbName);
if (value != null || isIndexedWhenEmpty()) {
index.add(dbRel, dbName, value, valueType());
}
} catch (Throwable t) {
logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
}
}
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class ODSExporter method writeObjectToCell.
static void writeObjectToCell(final OdfTableCell cell, final Object val) {
if (val instanceof String) {
cell.setStringValue((String) val);
} else if (val instanceof Integer) {
Integer i = (Integer) val;
cell.setDoubleValue(i.doubleValue());
} else if (val instanceof Double) {
cell.setDoubleValue((Double) val);
} else if (val instanceof Boolean) {
cell.setBooleanValue((Boolean) val);
} else if (val instanceof AbstractNode) {
AbstractNode node = (AbstractNode) val;
cell.setStringValue(node.getProperty(new StringProperty("id")));
} else if (val != null) {
cell.setStringValue(val.toString());
}
}
Aggregations