Search in sources :

Example 36 with CmisObjectNotFoundException

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

the class CMISObjectService method createFolder.

@Override
public String createFolder(final String repositoryId, final Properties properties, final String folderId, final List<String> policies, final Acl addAces, final Acl removeAces, final ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    String uuid = null;
    try (final Tx tx = app.tx()) {
        final String objectTypeId = getStringValue(properties, PropertyIds.OBJECT_TYPE_ID);
        final Class type = typeFromObjectTypeId(objectTypeId, BaseTypeId.CMIS_FOLDER, Folder.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_FOLDER.equals(baseTypeId)) {
                // create folder
                final AbstractFile newFolder = (AbstractFile) app.create(type, PropertyMap.cmisTypeToJavaType(securityContext, type, properties));
                // 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) {
                        newFolder.setParent(parent);
                    } else {
                        throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
                    }
                }
                uuid = newFolder.getUuid();
            } else {
                throw new CmisConstraintException("Cannot create cmis:folder of type " + objectTypeId);
            }
        } else {
            throw new CmisObjectNotFoundException("Type with ID " + objectTypeId + " does not exist");
        }
        tx.success();
    } catch (Throwable t) {
        throw new CmisRuntimeException("New folder could not be created: " + t.getMessage());
    }
    return uuid;
}
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) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) Folder(org.structr.web.entity.Folder)

Example 37 with CmisObjectNotFoundException

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

the class CMISRepositoryService method getTypeChildren.

@Override
public TypeDefinitionList getTypeChildren(String repositoryId, String typeId, Boolean includePropertyDefinitions, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
    // important: children are the direct children of a type, as opposed to the descendants
    final CMISTypeDefinitionListWrapper results = new CMISTypeDefinitionListWrapper(maxItems, skipCount);
    if (typeId != null) {
        final BaseTypeId baseTypeId = getBaseTypeId(typeId);
        if (baseTypeId != null) {
            results.addAll(getBaseTypeChildren(baseTypeId, includePropertyDefinitions));
        } else {
            final Class type = StructrApp.getConfiguration().getNodeEntityClass(typeId);
            if (type != null) {
                results.addAll(getTypeChildren(typeId, includePropertyDefinitions));
            } else {
                throw new CmisObjectNotFoundException("Type with ID " + typeId + " does not exist");
            }
        }
    } else {
        results.add(getDocumentTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value(), includePropertyDefinitions, true));
        results.add(getFolderTypeDefinition(BaseTypeId.CMIS_FOLDER.value(), includePropertyDefinitions, true));
        results.add(getItemTypeDefinition(BaseTypeId.CMIS_ITEM.value(), includePropertyDefinitions, true));
        results.add(getPolicyTypeDefinition(BaseTypeId.CMIS_POLICY.value(), includePropertyDefinitions, true));
        results.add(getRelationshipTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value(), includePropertyDefinitions, true));
        results.add(getSecondaryTypeDefinition(BaseTypeId.CMIS_SECONDARY.value(), includePropertyDefinitions, true));
    }
    return results;
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CMISTypeDefinitionListWrapper(org.structr.files.cmis.wrapper.CMISTypeDefinitionListWrapper) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId)

Aggregations

CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)37 App (org.structr.core.app.App)12 StructrApp (org.structr.core.app.StructrApp)12 Tx (org.structr.core.graph.Tx)12 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)11 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)9 ObjectType (org.apache.chemistry.opencmis.client.api.ObjectType)9 HashMap (java.util.HashMap)7 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)7 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)7 IOException (java.io.IOException)6 FrameworkException (org.structr.common.error.FrameworkException)6 AbstractFile (org.structr.web.entity.AbstractFile)6 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)5 Folder (org.apache.chemistry.opencmis.client.api.Folder)5 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)5 ArrayList (java.util.ArrayList)4 Document (org.apache.chemistry.opencmis.client.api.Document)4 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)4 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)4