Search in sources :

Example 11 with CmisObjectNotFoundException

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

the class LatestAccessibleStateIdTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    try {
        // create folder and document
        Folder testFolder = createTestFolder(session);
        Document doc = createDocument(session, testFolder, "lateststate.txt", "latest state");
        DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
        if (!docType.getPropertyDefinitions().containsKey(PropertyIds.LATEST_ACCESSIBLE_STATE_ID)) {
            addResult(createResult(SKIPPED, "Repository does not support the Latest State Identifier feature extension. Test skipped!"));
            doc.delete(true);
            return;
        }
        // check latest accessible state ID
        f = createResult(FAILURE, "Latest Accessible State ID is not set!");
        addResult(assertStringNotEmpty(doc.getLatestAccessibleStateId(), null, f));
        // get document with latest accessible state ID
        try {
            CmisObject latestStateObject = session.getObject(doc.getLatestAccessibleStateId(), SELECT_ALL_NO_CACHE_OC);
            if (latestStateObject instanceof Document) {
                f = createResult(FAILURE, "Latest Accessible State IDs of the orignal and the retrieved document don't match!");
                addResult(assertEquals(doc.getLatestAccessibleStateId(), ((Document) latestStateObject).getLatestAccessibleStateId(), null, f));
            } else {
                addResult(createResult(FAILURE, "Object retrieved with the Latest Accessible State ID is not a document!"));
            }
        } catch (CmisObjectNotFoundException onf) {
            addResult(createResult(FAILURE, "Document could not be retrieved with the Latest Accessible State ID!"));
        }
        doc.delete(true);
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 12 with CmisObjectNotFoundException

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

the class BaseTypesTest method run.

@Override
public void run(Session session) {
    CmisTestResult failure;
    // check base types
    Set<String> cmisTypes = new HashSet<String>();
    cmisTypes.add(BaseTypeId.CMIS_DOCUMENT.value());
    cmisTypes.add(BaseTypeId.CMIS_FOLDER.value());
    cmisTypes.add(BaseTypeId.CMIS_RELATIONSHIP.value());
    cmisTypes.add(BaseTypeId.CMIS_POLICY.value());
    if (session.getRepositoryInfo().getCmisVersion() != CmisVersion.CMIS_1_0) {
        cmisTypes.add(BaseTypeId.CMIS_ITEM.value());
        cmisTypes.add(BaseTypeId.CMIS_SECONDARY.value());
    }
    for (TypeDefinition typeDef : session.getTypeChildren(null, false)) {
        String typeId = typeDef.getId();
        if (typeId == null || !cmisTypes.contains(typeId)) {
            addResult(createResult(FAILURE, "Base type has an invalid ID: " + typeId));
        }
        if (typeDef.getPropertyDefinitions() != null && !typeDef.getPropertyDefinitions().isEmpty()) {
            addResult(createResult(WARNING, "Property type definitions were not requested but delivered. Type ID: " + typeId));
        }
    }
    // document
    try {
        TypeDefinition documentType = session.getTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value());
        addResult(checkTypeDefinition(session, documentType, "Document type spec compliance: " + documentType.getId()));
        failure = createResult(FAILURE, "Document type has the wrong base type: " + documentType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_DOCUMENT, documentType.getBaseTypeId(), null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(FAILURE, "Document type not available!", e, false));
    }
    // folder
    try {
        TypeDefinition folderType = session.getTypeDefinition(BaseTypeId.CMIS_FOLDER.value());
        addResult(checkTypeDefinition(session, folderType, "Folder type spec compliance: " + folderType.getId()));
        failure = createResult(FAILURE, "Folder type has the wrong base type: " + folderType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_FOLDER, folderType.getBaseTypeId(), null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(FAILURE, "Folder type not available!", e, false));
    }
    // relationship
    try {
        TypeDefinition relationshipType = session.getTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value());
        addResult(checkTypeDefinition(session, relationshipType, "Relationship type spec compliance: " + relationshipType.getId()));
        failure = createResult(FAILURE, "Relationship type has the wrong base type: " + relationshipType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_RELATIONSHIP, relationshipType.getBaseTypeId(), null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(WARNING, "Relationship type not available!", e, false));
    }
    // policy
    try {
        TypeDefinition policyType = session.getTypeDefinition(BaseTypeId.CMIS_POLICY.value());
        addResult(checkTypeDefinition(session, policyType, "Policy type spec compliance: " + policyType.getId()));
        failure = createResult(FAILURE, "Policy type has the wrong base type: " + policyType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_POLICY, policyType.getBaseTypeId(), null, failure));
    } catch (CmisInvalidArgumentException e) {
        addResult(createResult(WARNING, "Policy type not available!", e, false));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(WARNING, "Policy type not available!", e, false));
    }
    // CMIS 1.1 types
    if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_1) {
        // item
        try {
            TypeDefinition itemType = session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
            addResult(checkTypeDefinition(session, itemType, "Item type spec compliance: " + itemType.getId()));
            failure = createResult(FAILURE, "Item type has the wrong base type: " + itemType.getBaseTypeId());
            addResult(assertEquals(BaseTypeId.CMIS_ITEM, itemType.getBaseTypeId(), null, failure));
        } catch (CmisInvalidArgumentException e) {
            addResult(createResult(WARNING, "Item type not available!", e, false));
        } catch (CmisObjectNotFoundException e) {
            addResult(createResult(WARNING, "Item type not available!", e, false));
        }
        // secondary type
        try {
            TypeDefinition secondaryType = session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
            addResult(checkTypeDefinition(session, secondaryType, "Secondary type spec compliance: " + secondaryType.getId()));
            failure = createResult(FAILURE, "Secondary type has the wrong base type: " + secondaryType.getBaseTypeId());
            addResult(assertEquals(BaseTypeId.CMIS_SECONDARY, secondaryType.getBaseTypeId(), null, failure));
        } catch (CmisInvalidArgumentException e) {
            addResult(createResult(WARNING, "Secondary type not available!", e, false));
        } catch (CmisObjectNotFoundException e) {
            addResult(createResult(WARNING, "Secondary type not available!", e, false));
        }
    } else {
        try {
            session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
            addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:item type definition!"));
        } catch (CmisBaseException e) {
        // expected
        }
        try {
            session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
            addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:secondary type definition!"));
        } catch (CmisBaseException e) {
        // expected
        }
    }
    // simple getTypeChildren paging test - skipping over all base types mut
    // return an empty list
    TypeDefinitionList typeDefinitionList = session.getBinding().getRepositoryService().getTypeChildren(session.getRepositoryInfo().getId(), null, false, BigInteger.valueOf(100), BigInteger.valueOf(6), null);
    if (typeDefinitionList == null) {
        addResult(createResult(FAILURE, "getTypeChildren() returned nothing!"));
    } else {
        if (typeDefinitionList.getList() != null && !typeDefinitionList.getList().isEmpty()) {
            addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned a list of " + typeDefinitionList.getList().size() + " elements."));
        }
        if (Boolean.TRUE.equals(typeDefinitionList.hasMoreItems())) {
            addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned hasMoreItems == true."));
        }
    }
    // test getTypeDescendants()
    int numOfTypes = runTypeChecks(session, session.getTypeDescendants(null, -1, true));
    addResult(createInfoResult("Checked " + numOfTypes + " type definitions."));
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) TypeDefinitionList(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) HashSet(java.util.HashSet) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 13 with CmisObjectNotFoundException

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

the class FileSystemStorageService method setContent.

@Override
public void setContent(String objectId, String objectName, String oldFileName, String path, ContentStream inputStream) {
    LOG.info("setContent dataId:{}" + objectName, objectId);
    try {
        // LOG.debug("setContent dataId:{}" + objectName,objectId);
        if (!getFileExtensionExists(objectName)) {
            objectName = objectName + MimeUtils.guessExtensionFromMimeType(inputStream.getMimeType());
        }
        File fileName = new File(gettingFolderPath(this.storeSettings.getFileLocation(), gettingDocNamePath(path)) + File.separator + objectName);
        if (!fileName.exists()) {
            LOG.error("setContent exception: {}", "File not found");
        }
        if (oldFileName != null) {
            File oldFile = new File(oldFileName);
            oldFile.delete();
        }
        writeContent(fileName, inputStream.getStream());
    } catch (Exception e) {
        LOG.error("setContent exception: {}, {}", e.getMessage(), ExceptionUtils.getStackTrace(e));
        throw new CmisObjectNotFoundException(e.getMessage(), e);
    }
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) File(java.io.File) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) IOException(java.io.IOException)

Example 14 with CmisObjectNotFoundException

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

the class CMISRepositoryService method getTypeDescendants.

@Override
public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth, Boolean includePropertyDefinitions, ExtensionsData extension) {
    // important: descendants are ALL children and children of children, i.e. the whole tree
    /*
		Id typeId: The typeId of an object-type specified in the repository.
		 - If specified, then the repository MUST return all of descendant types of the specified type.
		 - If not specified, then the Repository MUST return all types and MUST ignore the value of the depth parameter.
		*/
    final List<TypeDefinitionContainer> results = new LinkedList<>();
    if (typeId != null) {
        final BaseTypeId baseTypeId = getBaseTypeId(typeId);
        if (baseTypeId != null) {
            final TypeDefinition typeDefinition = getTypeDefinition(repositoryId, typeId, extension);
            final TypeDefinitionContainer container = getTypeDefinitionContainer(typeDefinition, includePropertyDefinitions);
            results.add(container);
        } else {
            final Class type = StructrApp.getConfiguration().getNodeEntityClass(typeId);
            if (type != null) {
                final TypeDefinition typeDefinition = extendTypeDefinition(type, includePropertyDefinitions);
                if (typeDefinition != null) {
                    results.add(getTypeDefinitionContainer(typeDefinition, includePropertyDefinitions));
                } else {
                    throw new CmisObjectNotFoundException("Type with ID " + typeId + " does not exist");
                }
            } else {
                throw new CmisObjectNotFoundException("Type with ID " + typeId + " does not exist");
            }
        }
    } else {
        results.add(getTypeDefinitionContainer(getDocumentTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value(), includePropertyDefinitions, true), includePropertyDefinitions));
        results.add(getTypeDefinitionContainer(getFolderTypeDefinition(BaseTypeId.CMIS_FOLDER.value(), includePropertyDefinitions, true), includePropertyDefinitions));
        results.add(getTypeDefinitionContainer(getItemTypeDefinition(BaseTypeId.CMIS_ITEM.value(), includePropertyDefinitions, true), includePropertyDefinitions));
        results.add(getTypeDefinitionContainer(getPolicyTypeDefinition(BaseTypeId.CMIS_POLICY.value(), includePropertyDefinitions, true), includePropertyDefinitions));
        results.add(getTypeDefinitionContainer(getRelationshipTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value(), includePropertyDefinitions, true), includePropertyDefinitions));
        results.add(getTypeDefinitionContainer(getSecondaryTypeDefinition(BaseTypeId.CMIS_SECONDARY.value(), includePropertyDefinitions, true), includePropertyDefinitions));
    }
    return results;
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) TypeDefinitionContainer(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer) LinkedList(java.util.LinkedList) MutableTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableTypeDefinition) MutablePolicyTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutablePolicyTypeDefinition) MutableRelationshipTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableRelationshipTypeDefinition) MutableFolderTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableFolderTypeDefinition) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) MutableDocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableDocumentTypeDefinition) MutableSecondaryTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableSecondaryTypeDefinition) MutableItemTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableItemTypeDefinition)

Example 15 with CmisObjectNotFoundException

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

the class CMISAclService method getAcl.

@Override
public Acl getAcl(final String repositoryId, final String objectId, final Boolean onlyBasicPermissions, final ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        final AbstractNode node = app.get(AbstractNode.class, objectId);
        if (node != null) {
            return CMISObjectWrapper.wrap(node, null, false);
        }
        tx.success();
    } 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) 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)

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