Search in sources :

Example 51 with AbstractNode

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);
    }
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) DiffMatchPatch(org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch) DiffMatchPatch(org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch) Patch(org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch.Patch) LinkedList(java.util.LinkedList)

Example 52 with AbstractNode

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);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) StaticValue(org.structr.core.StaticValue) Principal(org.structr.core.entity.Principal)

Example 53 with AbstractNode

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");
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Ace(org.apache.chemistry.opencmis.commons.data.Ace) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) AbstractNode(org.structr.core.entity.AbstractNode)

Example 54 with AbstractNode

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 });
            }
        }
    }
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) NodeService(org.structr.core.graph.NodeService) Node(org.structr.api.graph.Node) AbstractNode(org.structr.core.entity.AbstractNode) AbstractRelationship(org.structr.core.entity.AbstractRelationship) AbstractRelationship(org.structr.core.entity.AbstractRelationship) Relationship(org.structr.api.graph.Relationship) GraphObject(org.structr.core.GraphObject) AbstractCypherIndex(org.structr.bolt.index.AbstractCypherIndex) Index(org.structr.api.index.Index)

Example 55 with AbstractNode

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());
    }
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) StringProperty(org.structr.core.property.StringProperty)

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