Search in sources :

Example 11 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class CMISObjectService method updateProperties.

@Override
public void updateProperties(final String repositoryId, final Holder<String> objectId, final Holder<String> changeToken, final Properties properties, final ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    final String id = objectId.getValue();
    try (final Tx tx = app.tx()) {
        final AbstractNode obj = app.get(AbstractNode.class, id);
        if (obj != null) {
            final PropertyMap propertyMap = PropertyMap.cmisTypeToJavaType(securityContext, obj.getClass(), properties);
            if (propertyMap != null) {
                obj.setProperties(securityContext, propertyMap);
            }
        } else {
            throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
        }
        tx.success();
    } catch (FrameworkException fex) {
        throw new CmisConstraintException(fex.getMessage(), fex);
    }
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)

Example 12 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class CMISObjectService method bulkUpdateProperties.

@Override
public List<BulkUpdateObjectIdAndChangeToken> bulkUpdateProperties(final String repositoryId, final List<BulkUpdateObjectIdAndChangeToken> objectIdsAndChangeTokens, final Properties properties, final List<String> addSecondaryTypeIds, final List<String> removeSecondaryTypeIds, final ExtensionsData extension) {
    final List<BulkUpdateObjectIdAndChangeToken> result = new LinkedList<>();
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        for (final BulkUpdateObjectIdAndChangeToken token : objectIdsAndChangeTokens) {
            final AbstractNode obj = app.get(AbstractNode.class, token.getId());
            if (obj != null) {
                final PropertyMap propertyMap = PropertyMap.cmisTypeToJavaType(securityContext, obj.getClass(), properties);
                if (propertyMap != null) {
                    obj.setProperties(securityContext, propertyMap);
                }
                result.add(token);
            }
        }
        tx.success();
    } catch (FrameworkException fex) {
        throw new CmisConstraintException(fex.getMessage(), fex);
    }
    return result;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) BulkUpdateObjectIdAndChangeToken(org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) LinkedList(java.util.LinkedList)

Example 13 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class CMISObjectService method deleteObject.

@Override
public void deleteObject(String repositoryId, String objectId, Boolean allVersions, ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        final Principal principal = securityContext.getUser(false);
        final AbstractNode obj = app.get(AbstractNode.class, objectId);
        if (obj != null) {
            if (principal.isGranted(Permission.delete, securityContext)) {
                if (obj.isNode()) {
                    // getSyncNode() returns the node or null
                    app.delete(obj.getSyncNode());
                } else {
                    // getSyncRelationship() return the relationship or null
                    app.delete(obj.getSyncRelationship());
                }
            } else {
                throw new CmisPermissionDeniedException("Cannot delete object with ID " + objectId);
            }
        } else {
            throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
        }
        tx.success();
    } catch (FrameworkException fex) {
        throw new CmisConstraintException(fex.getMessage(), fex);
    }
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) Principal(org.structr.core.entity.Principal)

Example 14 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class RelationshipResource method doGet.

@Override
public Result doGet(final PropertyKey sortKey, final boolean sortDescending, final int pageSize, final int page) throws FrameworkException {
    // fetch all results, paging is applied later
    final List<? extends GraphObject> results = wrappedResource.doGet(null, false, NodeFactory.DEFAULT_PAGE_SIZE, NodeFactory.DEFAULT_PAGE).getResults();
    final App app = StructrApp.getInstance();
    if (results != null && !results.isEmpty()) {
        try {
            final List<GraphObject> resultList = new LinkedList<>();
            for (GraphObject obj : results) {
                if (obj instanceof AbstractNode) {
                    final List<? extends RelationshipInterface> relationships = Direction.INCOMING.equals(direction) ? Iterables.toList(((AbstractNode) obj).getIncomingRelationships()) : Iterables.toList(((AbstractNode) obj).getOutgoingRelationships());
                    if (relationships != null) {
                        boolean filterInternalRelationshipTypes = false;
                        if (securityContext != null && securityContext.getRequest() != null) {
                            final String filterInternal = securityContext.getRequest().getParameter(REQUEST_PARAMETER_FILTER_INTERNAL_RELATIONSHIP_TYPES);
                            if (filterInternal != null) {
                                filterInternalRelationshipTypes = "true".equals(filterInternal);
                            }
                        }
                        // the result set using the request parameter "filterInternal=true"
                        if (filterInternalRelationshipTypes) {
                            for (final RelationshipInterface rel : relationships) {
                                if (!rel.isInternal()) {
                                    resultList.add(rel);
                                }
                            }
                        } else {
                            resultList.addAll(relationships);
                        }
                    }
                }
            }
            final int rawResultCount = resultList.size();
            return new Result(PagingHelper.subList(resultList, pageSize, page), rawResultCount, true, false);
        } catch (Throwable t) {
            logger.warn("Exception while fetching relationships", t);
        }
    } else {
        logger.info("No results from parent..");
    }
    throw new IllegalPathException(getResourceSignature() + " can only be applied to a non-empty resource");
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) IllegalPathException(org.structr.rest.exception.IllegalPathException) AbstractNode(org.structr.core.entity.AbstractNode) GraphObject(org.structr.core.GraphObject) LinkedList(java.util.LinkedList) Result(org.structr.core.Result) RelationshipInterface(org.structr.core.graph.RelationshipInterface)

Example 15 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class GetIncomingRelationshipsFunction method apply.

@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
    final List<AbstractRelationship> list = new ArrayList<>();
    if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
        final Object source = sources[0];
        final Object target = sources[1];
        AbstractNode sourceNode = null;
        AbstractNode targetNode = null;
        if (source instanceof AbstractNode && target instanceof AbstractNode) {
            sourceNode = (AbstractNode) source;
            targetNode = (AbstractNode) target;
        } else {
            logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
            return "Error: entities are not nodes.";
        }
        if (sources.length == 2) {
            for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
                final NodeInterface s = rel.getSourceNode();
                final NodeInterface t = rel.getTargetNode();
                // We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
                if (s != null && t != null && s.equals(targetNode) && t.equals(sourceNode)) {
                    list.add(rel);
                }
            }
        } else if (sources.length == 3) {
            // dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
            final String relType = (String) sources[2];
            for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
                final NodeInterface s = rel.getSourceNode();
                final NodeInterface t = rel.getTargetNode();
                // We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
                if (s != null && t != null && rel.getRelType().name().equals(relType) && s.equals(targetNode) && t.equals(sourceNode)) {
                    list.add(rel);
                }
            }
        }
    } else {
        logParameterError(caller, sources, ctx.isJavaScriptContext());
    }
    return list;
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) AbstractRelationship(org.structr.core.entity.AbstractRelationship) ArrayList(java.util.ArrayList) NodeInterface(org.structr.core.graph.NodeInterface)

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