Search in sources :

Example 11 with ObjectData

use of org.apache.chemistry.opencmis.commons.data.ObjectData in project structr by structr.

the class CMISObjectService method getObjectByPath.

@Override
public ObjectData getObjectByPath(final String repositoryId, final String path, final String propertyFilter, final Boolean includeAllowableActions, final IncludeRelationships includeRelationships, final String renditionFilter, final Boolean includePolicyIds, final Boolean includeAcl, final ExtensionsData extension) {
    final PropertyKey<String> pathKey = StructrApp.key(AbstractFile.class, "path");
    final App app = StructrApp.getInstance();
    ObjectData result = null;
    try (final Tx tx = app.tx()) {
        final AbstractFile file = app.nodeQuery(AbstractFile.class).and(pathKey, path).getFirst();
        if (file != null) {
            result = CMISObjectWrapper.wrap(file, propertyFilter, includeAllowableActions);
        }
        tx.success();
    } catch (Throwable t) {
        logger.warn("", t);
    }
    if (result != null) {
        return result;
    }
    throw new CmisObjectNotFoundException("Object with path " + path + " does not exist");
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData)

Example 12 with ObjectData

use of org.apache.chemistry.opencmis.commons.data.ObjectData in project iaf by ibissource.

the class ObjectServiceImpl method getObject.

@Override
public ObjectData getObject(String repositoryId, String objectId, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePolicyIds, Boolean includeAcl, ExtensionsData extensions) {
    boolean bypass = AppConstants.getInstance().getBoolean("cmis.proxy.bypass.getObject", false);
    if (!bypass) {
        ObjectData objectData = objectService.getObject(repositoryId, objectId, filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl, extensions);
        return objectData;
    } else {
        XmlBuilder cmisXml = new XmlBuilder("cmis");
        cmisXml.addSubElement(buildXml("repositoryId", repositoryId));
        cmisXml.addSubElement(buildXml("objectId", objectId));
        cmisXml.addSubElement(buildXml("filter", filter));
        cmisXml.addSubElement(buildXml("includeAllowableActions", includeAllowableActions));
        cmisXml.addSubElement(buildXml("includePolicies", includePolicyIds));
        cmisXml.addSubElement(buildXml("includeAcl", includeAcl));
        ObjectDataImpl impl = new ObjectDataImpl();
        try {
            IPipeLineSession messageContext = new PipeLineSessionBase();
            String result = CmisServletDispatcher.getInstance().getCmisListener().processRequest(null, cmisXml.toXML(), messageContext);
            Element cmisElement;
            if (XmlUtils.isWellFormed(result, "cmis")) {
                cmisElement = XmlUtils.buildElement(result);
            } else {
                cmisElement = XmlUtils.buildElement("<cmis/>");
            }
            // Handle allowable actions
            Element allowableActionsElem = XmlUtils.getFirstChildTag(cmisElement, "allowableActions");
            if (allowableActionsElem != null) {
                AllowableActionsImpl allowableActions = new AllowableActionsImpl();
                Set<Action> actions = EnumSet.noneOf(Action.class);
                Iterator<Node> actionIterator = XmlUtils.getChildTags(allowableActionsElem, "action").iterator();
                while (actionIterator.hasNext()) {
                    String property = XmlUtils.getStringValue((Element) actionIterator.next());
                    actions.add(Action.fromValue(property));
                }
                allowableActions.setAllowableActions(actions);
                impl.setAllowableActions(allowableActions);
            }
            // Handle isExactAcl
            impl.setIsExactAcl(XmlUtils.getChildTagAsBoolean(cmisElement, "isExactAcl"));
            // Handle policyIds
            Element policyIdsElem = XmlUtils.getFirstChildTag(cmisElement, "policyIds");
            if (policyIdsElem != null) {
                PolicyIdListImpl policyIdList = new PolicyIdListImpl();
                List<String> policies = new ArrayList<String>();
                Iterator<Node> policyIterator = XmlUtils.getChildTags(allowableActionsElem, "policyId").iterator();
                while (policyIterator.hasNext()) {
                    String policyId = XmlUtils.getStringValue((Element) policyIterator.next());
                    policies.add(policyId);
                }
                policyIdList.setPolicyIds(policies);
                impl.setPolicyIds(policyIdList);
            }
            // Handle properties
            impl.setProperties(processProperties(cmisElement));
        } catch (Exception e) {
            log.error("error creating CMIS objectData: " + e.getMessage(), e.getCause());
        }
        impl.setRenditions(null);
        impl.setExtensions(null);
        impl.setChangeEventInfo(null);
        impl.setRelationships(null);
        return impl;
    }
}
Also used : Action(org.apache.chemistry.opencmis.commons.enums.Action) PolicyIdListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PolicyIdListImpl) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ArrayList(java.util.ArrayList) AllowableActionsImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.AllowableActionsImpl) ObjectDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl) ParseException(java.text.ParseException) SenderException(nl.nn.adapterframework.core.SenderException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 13 with ObjectData

use of org.apache.chemistry.opencmis.commons.data.ObjectData in project copper-cms by PogeyanOSS.

the class ObjectActor method appendContent.

private JSONObject appendContent(PostRequest request) throws CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = request.getObjectId();
    String changeToken = request.getParameter(QueryGetRequest.PARAM_CHANGE_TOKEN);
    boolean isLastChunk = request.getBooleanParameter(QueryGetRequest.CONTROL_IS_LAST_CHUNK, false);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Holder<String> objectIdHolder = new Holder<String>(objectId);
    Holder<String> changeTokenHolder = (changeToken == null ? null : new Holder<String>(changeToken));
    if (request.getContentStream() == null) {
        CmisObjectService.Impl.appendContentStream(request.getRepositoryId(), objectIdHolder, changeTokenHolder, null, isLastChunk);
    } else {
        CmisObjectService.Impl.appendContentStream(request.getRepositoryId(), objectIdHolder, changeTokenHolder, request.getContentStream(), isLastChunk);
    }
    String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_DOCUMENT);
    if (object == null) {
        throw new CmisRuntimeException("Object is null!");
    }
    // return object
    JSONObject jsonObject = JSONConverter.convert(object, null, JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Holder(org.apache.chemistry.opencmis.commons.spi.Holder) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 14 with ObjectData

use of org.apache.chemistry.opencmis.commons.data.ObjectData in project copper-cms by PogeyanOSS.

the class ObjectActor method update.

@SuppressWarnings("unused")
private JSONObject update(PostRequest request) throws CmisRuntimeException, CmisObjectNotFoundException, CmisRuntimeException, CmisUpdateConflictException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = request.getObjectId();
    IBaseObject data = DBUtils.BaseDAO.getByObjectId(request.getRepositoryId(), objectId, null);
    String typeId = CmisPropertyConverter.Impl.getTypeIdForObject(request.getRepositoryId(), objectId);
    String changeToken = request.getParameter(QueryGetRequest.CONTROL_CHANGE_TOKEN);
    String token = request.getParameter(QueryGetRequest.PARAM_TOKEN);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Holder<String> objectIdHolder = new Holder<String>(objectId.toString());
    Holder<String> changeTokenHolder = (changeToken == null ? null : new Holder<String>(changeToken));
    Properties properties = CmisPropertyConverter.Impl.createUpdateProperties(request.getPropertyData(), typeId, null, Collections.singletonList(objectId.toString()), request.getRepositoryId(), data);
    CmisObjectService.Impl.updateProperties(request.getRepositoryId(), objectIdHolder, changeTokenHolder, properties, null, null, request.getUserObject());
    String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), request.getBaseTypeId());
    if (object == null) {
        throw new CmisRuntimeException("Object is null!");
    }
    // return object
    JSONObject jsonObject = JSONConverter.convert(object, null, JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Holder(org.apache.chemistry.opencmis.commons.spi.Holder) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) Properties(org.apache.chemistry.opencmis.commons.data.Properties) IBaseObject(com.pogeyan.cmis.api.data.IBaseObject) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 15 with ObjectData

use of org.apache.chemistry.opencmis.commons.data.ObjectData in project copper-cms by PogeyanOSS.

the class ObjectActor method createItem.

private JSONObject createItem(PostRequest request) throws CmisInvalidArgumentException, CmisObjectNotFoundException, IllegalArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    String principalId = request.getUserObject().getUserDN();
    IUserGroupObject[] groups = request.getUserObject().getGroups();
    if (!Helpers.getGroupPermission(permission, groups)) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String folderId = request.getObjectId() != null ? request.getObjectId() : null;
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Properties prop = CmisPropertyConverter.Impl.createNewProperties(request.getPropertyData(), request.getRepositoryId());
    Acl aclImp = CmisUtils.Object.getAcl(request.getAddAcl(), principalId, permission);
    String newObjectId = CmisObjectService.Impl.createItem(request.getRepositoryId(), prop, folderId, request.getPolicies(), aclImp, request.getRemoveAcl(), request.getUserObject().getUserDN());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_ITEM);
    if (object == null) {
        throw new CmisRuntimeException("New folder is null!");
    }
    // return object
    JSONObject jsonObject = JSONConverter.convert(object, null, JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : IUserGroupObject(com.pogeyan.cmis.api.auth.IUserGroupObject) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Properties(org.apache.chemistry.opencmis.commons.data.Properties) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Aggregations

ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)32 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)23 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)22 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)20 Properties (org.apache.chemistry.opencmis.commons.data.Properties)8 Holder (org.apache.chemistry.opencmis.commons.spi.Holder)7 IUserGroupObject (com.pogeyan.cmis.api.auth.IUserGroupObject)6 Acl (org.apache.chemistry.opencmis.commons.data.Acl)6 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)3 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)3 App (org.structr.core.app.App)3 StructrApp (org.structr.core.app.StructrApp)3 Tx (org.structr.core.graph.Tx)3 BaseMessage (com.pogeyan.cmis.api.BaseMessage)2 IBaseObject (com.pogeyan.cmis.api.data.IBaseObject)2 ArrayList (java.util.ArrayList)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 Folder (org.apache.chemistry.opencmis.client.api.Folder)2 Policy (org.apache.chemistry.opencmis.client.api.Policy)2 ObjectParentData (org.apache.chemistry.opencmis.commons.data.ObjectParentData)2