Search in sources :

Example 16 with CmisRuntimeException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project copper-cms by PogeyanOSS.

the class AclActor method getAcl.

private JSONObject getAcl(QueryGetRequest t) throws CmisObjectNotFoundException, CmisRuntimeException {
    String permission = t.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(t.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = t.getObjectId();
    Boolean onlyBasicPermissions = t.getBooleanParameter(QueryGetRequest.PARAM_ONLY_BASIC_PERMISSIONS);
    Acl objectAcl = CmisAclServices.Impl.getAcl(t.getRepositoryId(), objectId, onlyBasicPermissions, null, null, t.getUserObject().getUserDN());
    if (objectAcl == null) {
        throw new CmisRuntimeException("object acl is null!");
    }
    JSONObject jsonObject = JSONConverter.convert(objectAcl);
    return jsonObject;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Acl(org.apache.chemistry.opencmis.commons.data.Acl) CapabilityAcl(org.apache.chemistry.opencmis.commons.enums.CapabilityAcl)

Example 17 with CmisRuntimeException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project copper-cms by PogeyanOSS.

the class DiscoveryActor method getContentChanges.

private JSONObject getContentChanges(QueryGetRequest request) throws CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String changeLogToken = request.getParameter(QueryGetRequest.PARAM_CHANGE_LOG_TOKEN);
    Boolean includeProperties = request.getBooleanParameter(QueryGetRequest.PARAM_PROPERTIES);
    String filter = request.getParameter(QueryGetRequest.PARAM_FILTER);
    Boolean includePolicyIds = request.getBooleanParameter(QueryGetRequest.PARAM_POLICY_IDS);
    Boolean includeAcl = request.getBooleanParameter(QueryGetRequest.PARAM_ACL);
    BigInteger maxItems = request.getBigIntegerParameter(QueryGetRequest.PARAM_MAX_ITEMS);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.PARAM_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Holder<String> changeLogTokenHolder = new Holder<String>(changeLogToken);
    ObjectList changes = CmisDiscoveryService.Impl.getContentChanges(request.getRepositoryId(), changeLogTokenHolder, includeProperties, filter, includePolicyIds, includeAcl, maxItems, null, request.getUserObject());
    JSONObject jsonChanges = JSONConverter.convert(changes, CmisTypeCacheService.get(request.getRepositoryId()), JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    jsonChanges.put(JSONConstants.JSON_OBJECTLIST_CHANGE_LOG_TOKEN, changeLogTokenHolder.getValue());
    return jsonChanges;
}
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) BigInteger(java.math.BigInteger) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 18 with CmisRuntimeException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project copper-cms by PogeyanOSS.

the class NavigationActor method getFolderTree.

private JSONArray getFolderTree(QueryGetRequest request) throws CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String folderId = request.getObjectId();
    String filter = request.getParameter(QueryGetRequest.PARAM_FILTER);
    BigInteger depth = request.getBigIntegerParameter(QueryGetRequest.PARAM_DEPTH);
    Boolean includeAllowableActions = request.getBooleanParameter(QueryGetRequest.PARAM_ALLOWABLE_ACTIONS);
    IncludeRelationships includeRelationships = request.getEnumParameter(QueryGetRequest.PARAM_RELATIONSHIPS, IncludeRelationships.class);
    String renditionFilter = request.getParameter(QueryGetRequest.PARAM_RENDITION_FILTER);
    Boolean includePathSegment = request.getBooleanParameter(QueryGetRequest.PARAM_PATH_SEGMENT);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.PARAM_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    List<ObjectInFolderContainer> folderTree = CmisNavigationService.Impl.getFolderTree(request.getRepositoryId(), folderId, depth, filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, null, request.getUserObject());
    if (folderTree == null) {
        throw new CmisRuntimeException("Folder Tree are null!");
    }
    JSONArray jsonDescendants = new JSONArray();
    for (ObjectInFolderContainer descendant : folderTree) {
        jsonDescendants.add(JSONConverter.convert(descendant, CmisTypeCacheService.get(request.getRepositoryId()), succinct, dateTimeFormat));
    }
    return jsonDescendants;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) BigInteger(java.math.BigInteger) IncludeRelationships(org.apache.chemistry.opencmis.commons.enums.IncludeRelationships) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 19 with CmisRuntimeException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project copper-cms by PogeyanOSS.

the class NavigationActor method getDescendants.

private JSONArray getDescendants(QueryGetRequest request) throws CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String folderId = request.getObjectId();
    String filter = request.getParameter(QueryGetRequest.PARAM_FILTER);
    BigInteger depth = request.getBigIntegerParameter(QueryGetRequest.PARAM_DEPTH);
    Boolean includeAllowableActions = request.getBooleanParameter(QueryGetRequest.PARAM_ALLOWABLE_ACTIONS);
    includeAllowableActions = includeAllowableActions == null ? false : includeAllowableActions;
    IncludeRelationships includeRelationships = request.getEnumParameter(QueryGetRequest.PARAM_RELATIONSHIPS, IncludeRelationships.class);
    String renditionFilter = request.getParameter(QueryGetRequest.PARAM_RENDITION_FILTER);
    Boolean includePathSegment = request.getBooleanParameter(QueryGetRequest.PARAM_PATH_SEGMENT);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.PARAM_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    List<ObjectInFolderContainer> descendants = CmisNavigationService.Impl.getDescendants(request.getRepositoryId(), folderId, depth, filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, null, request.getUserObject());
    if (descendants == null) {
        throw new CmisRuntimeException("Descendants are null!");
    }
    JSONArray jsonDescendants = new JSONArray();
    for (ObjectInFolderContainer descendant : descendants) {
        jsonDescendants.add(JSONConverter.convert(descendant, CmisTypeCacheService.get(request.getRepositoryId()), succinct, dateTimeFormat));
    }
    return jsonDescendants;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) BigInteger(java.math.BigInteger) IncludeRelationships(org.apache.chemistry.opencmis.commons.enums.IncludeRelationships) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 20 with CmisRuntimeException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project structr by structr.

the class CMISObjectService method createDocument.

@Override
public String createDocument(final String repositoryId, final Properties properties, final String folderId, final ContentStream contentStream, final VersioningState versioningState, final List<String> policies, final Acl addAces, final Acl removeAces, final ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    File newFile = null;
    String uuid = null;
    try (final Tx tx = app.tx()) {
        final String objectTypeId = getStringValue(properties, PropertyIds.OBJECT_TYPE_ID);
        final String fileName = getStringValue(properties, PropertyIds.NAME);
        final Class type = typeFromObjectTypeId(objectTypeId, BaseTypeId.CMIS_DOCUMENT, File.class);
        // check if type exists
        if (type != null) {
            // check that base type is cmis:folder
            final BaseTypeId baseTypeId = getBaseTypeId(type);
            if (baseTypeId != null && BaseTypeId.CMIS_DOCUMENT.equals(baseTypeId)) {
                final String mimeType = contentStream != null ? contentStream.getMimeType() : null;
                // create file
                newFile = FileHelper.createFile(securityContext, new byte[0], mimeType, type, fileName);
                if (newFile != null) {
                    // find and set parent if it exists
                    if (!CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
                        final Folder parent = app.get(Folder.class, folderId);
                        if (parent != null) {
                            newFile.setParent(parent);
                        } else {
                            throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
                        }
                    }
                    uuid = newFile.getUuid();
                    if (contentStream != null) {
                        final InputStream inputStream = contentStream.getStream();
                        if (inputStream != null) {
                            // copy file and update metadata
                            try (final OutputStream outputStream = newFile.getOutputStream(false, false)) {
                                IOUtils.copy(inputStream, outputStream);
                            }
                            inputStream.close();
                            FileHelper.updateMetadata(newFile);
                        }
                    }
                }
            } else {
                throw new CmisConstraintException("Cannot create cmis:document of type " + objectTypeId);
            }
        } else {
            throw new CmisObjectNotFoundException("Type with ID " + objectTypeId + " does not exist");
        }
        tx.success();
    } catch (Throwable t) {
        throw new CmisRuntimeException("New document could not be created: " + t.getMessage());
    }
    // start indexing after transaction is finished
    if (newFile != null) {
        newFile.notifyUploadCompletion();
    }
    return uuid;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) InputStream(java.io.InputStream) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) OutputStream(java.io.OutputStream) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) Folder(org.structr.web.entity.Folder) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File)

Aggregations

CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)49 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)35 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)35 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)22 BigInteger (java.math.BigInteger)10 Properties (org.apache.chemistry.opencmis.commons.data.Properties)10 Acl (org.apache.chemistry.opencmis.commons.data.Acl)8 JSONArray (org.apache.chemistry.opencmis.commons.impl.json.JSONArray)8 Holder (org.apache.chemistry.opencmis.commons.spi.Holder)8 IUserGroupObject (com.pogeyan.cmis.api.auth.IUserGroupObject)6 IncludeRelationships (org.apache.chemistry.opencmis.commons.enums.IncludeRelationships)6 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)6 Map (java.util.Map)4 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)4 IOException (java.io.IOException)3 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)3 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)3 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)3 IBaseObject (com.pogeyan.cmis.api.data.IBaseObject)2 InputStream (java.io.InputStream)2