Search in sources :

Example 11 with CmisConstraintException

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

the class FileSystemStorageService method moveFolder.

@Override
public void moveFolder(String objectId, String sourcePath, String targetPath) throws IOException, IllegalArgumentException {
    LOG.info("Move Folder for Sourcepath and Targetpath{},{}", sourcePath, targetPath);
    try {
        String rootpath = this.storeSettings.getFileLocation();
        if (rootpath == null) {
            LOG.error("Local storage path is undefined");
            throw new CmisConstraintException("Local storage path is undefined");
        }
        File sourceDir = new File(gettingFolderPath(this.storeSettings.getFileLocation(), sourcePath));
        targetPath = createSourceInTarget(gettingFolderPath(this.storeSettings.getFileLocation(), targetPath), sourcePath);
        File targetDir = new File(targetPath);
        FileUtils.copyDirectory(sourceDir, targetDir);
        File deleteSourceDir = new File(gettingFolderPath(this.storeSettings.getFileLocation(), sourcePath));
        FileUtils.deleteDirectory(deleteSourceDir);
    } catch (IOException e) {
        LOG.error("createLocalStorageService exception: {}, {}", e.getMessage(), ExceptionUtils.getStackTrace(e));
        throw new IllegalArgumentException("Could not create Folder: " + e.getMessage());
    }
}
Also used : CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) IOException(java.io.IOException) File(java.io.File)

Example 12 with CmisConstraintException

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

the class FileSystemStorageService method deleteFolder.

@Override
public void deleteFolder(String folderName) {
    LOG.info("Delete Folder:{}" + folderName);
    String respositoryRoot = null;
    try {
        LOG.debug("Delete Folder:{}" + folderName);
        String rootpath = this.storeSettings.getFileLocation();
        if (rootpath == null) {
            LOG.error("Local storage path is undefined");
            throw new CmisConstraintException("Local storage path is undefined");
        }
        respositoryRoot = rootpath + "\\" + folderName;
        File deleteSourceDir = new File(respositoryRoot);
        FileUtils.deleteDirectory(deleteSourceDir);
    } catch (Exception e) {
        LOG.error("createLocalStorageService exception: {}, {}", e.getMessage(), ExceptionUtils.getStackTrace(e));
    }
}
Also used : CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) 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 13 with CmisConstraintException

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

the class CreateInvalidTypeTest method run.

@Override
public void run(Session session) {
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        // test document creation
        try {
            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put(PropertyIds.NAME, "never.txt");
            properties.put(PropertyIds.OBJECT_TYPE_ID, getFolderTestTypeId());
            byte[] contentBytes = IOUtils.toUTF8Bytes("nothing");
            ContentStream contentStream = new ContentStreamImpl("never.txt", BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
            testFolder.createDocument(properties, contentStream, null);
            addResult(createResult(FAILURE, "Creation of a document with a folder type shouldn't work!"));
        } catch (Exception e) {
            if (!(e instanceof CmisInvalidArgumentException) && !(e instanceof CmisConstraintException)) {
                addResult(createResult(WARNING, "Creation of a document with a folder type threw an unexcpeted exception: " + e.toString()));
            }
        }
        // test folder creation
        try {
            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put(PropertyIds.NAME, "never");
            properties.put(PropertyIds.OBJECT_TYPE_ID, getDocumentTestTypeId());
            testFolder.createFolder(properties);
            addResult(createResult(FAILURE, "Creation of a folder with a document type shouldn't work!"));
        } catch (Exception e) {
            if (!(e instanceof CmisInvalidArgumentException) && !(e instanceof CmisConstraintException)) {
                addResult(createResult(WARNING, "Creation of a folder with a document type threw an unexcpeted exception: " + e.toString()));
            }
        }
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) Folder(org.apache.chemistry.opencmis.client.api.Folder) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Example 14 with CmisConstraintException

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

the class VersionDeleteTest method deleteVersion.

private void deleteVersion(Document versionDoc, Document previousDoc, int version) {
    CmisTestResult f;
    // check Allowable Action
    if (!versionDoc.hasAllowableAction(Action.CAN_DELETE_OBJECT)) {
        addResult(createResult(WARNING, "Version " + version + " does not have the Allowable Action 'canDeleteObject'."));
        return;
    }
    // get version history before delete
    List<Document> versionsBefore = versionDoc.getAllVersions();
    // delete and check
    try {
        versionDoc.delete(false);
    } catch (CmisInvalidArgumentException iae) {
        addResult(createResult(WARNING, "Deletion of version " + version + " failed with an invalidArgument exception. " + "Removing just one version doesn't seem to be supported."));
        return;
    } catch (CmisConstraintException ce) {
        addResult(createResult(WARNING, "Deletion of version " + version + " failed with an constraint exception. " + "Removing just one version doesn't seem to be supported."));
        return;
    }
    f = createResult(FAILURE, "Deleted version " + version + " still exists!");
    addResult(assertIsFalse(exists(versionDoc), null, f));
    // check version history after delete
    if (previousDoc != null) {
        List<Document> versionsAfter = previousDoc.getAllVersions();
        f = createResult(FAILURE, "After version " + version + " has been deleted, the version history should consist of " + (versionsBefore.size() - 1) + "  documents but is has " + versionsAfter.size() + " !");
        addResult(assertEquals(versionsBefore.size() - 1, versionsAfter.size(), null, f));
    }
}
Also used : CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 15 with CmisConstraintException

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

the class VersioningStateCreateTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    try {
        // create folder and document
        Folder testFolder = createTestFolder(session);
        DocumentTypeDefinition docType = (DocumentTypeDefinition) session.getTypeDefinition(getDocumentTestTypeId());
        if (!docType.isVersionable()) {
            addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
            return;
        }
        // major version
        Document docMajor = testFolder.createDocument(getProperties("major.txt"), getContentStream(), VersioningState.MAJOR, null, null, null, SELECT_ALL_NO_CACHE_OC);
        addResult(checkObject(session, docMajor, getAllProperties(docMajor), "Major version compliance"));
        f = createResult(FAILURE, "Document should be major version.");
        addResult(assertIsTrue(docMajor.isMajorVersion(), null, f));
        List<Document> versions = docMajor.getAllVersions();
        f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
        addResult(assertEquals(1, versions.size(), null, f));
        deleteObject(docMajor);
        // minor version
        try {
            Document docMinor = testFolder.createDocument(getProperties("minor.txt"), getContentStream(), VersioningState.MINOR, null, null, null, SELECT_ALL_NO_CACHE_OC);
            addResult(checkObject(session, docMinor, getAllProperties(docMinor), "Minor version compliance"));
            f = createResult(FAILURE, "Document should be minor version.");
            addResult(assertIsFalse(docMinor.isMajorVersion(), null, f));
            versions = docMinor.getAllVersions();
            f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
            addResult(assertEquals(1, versions.size(), null, f));
            deleteObject(docMinor);
        } catch (CmisConstraintException ce) {
            addResult(createResult(WARNING, "Creating a minor version failed! " + "The repository might not support minor versions. Exception: " + ce, ce, false));
        } catch (CmisInvalidArgumentException iae) {
            addResult(createResult(WARNING, "Creating a minor version failed! " + "The repository might not support minor versions.  Exception: " + iae, iae, false));
        }
        // checked out version
        try {
            Document docCheckedOut = testFolder.createDocument(getProperties("checkout.txt"), getContentStream(), VersioningState.CHECKEDOUT, null, null, null, SELECT_ALL_NO_CACHE_OC);
            addResult(checkObject(session, docCheckedOut, getAllProperties(docCheckedOut), "Checked out version compliance"));
            f = createResult(FAILURE, "Version series should be checked out.");
            addResult(assertIsTrue(docCheckedOut.isVersionSeriesCheckedOut(), null, f));
            versions = docCheckedOut.getAllVersions();
            f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
            addResult(assertEquals(1, versions.size(), null, f));
            docCheckedOut.cancelCheckOut();
        } catch (CmisConstraintException ce) {
            addResult(createResult(WARNING, "Creating a checked out version failed! " + "The repository might not support creating checked out versions. Exception: " + ce, ce, false));
        } catch (CmisInvalidArgumentException iae) {
            addResult(createResult(WARNING, "Creating a checked out version failed! " + "The repository might not  support creating checked out versions.  Exception: " + iae, iae, false));
        }
    } finally {
        deleteTestFolder();
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document)

Aggregations

CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)18 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)6 App (org.structr.core.app.App)6 StructrApp (org.structr.core.app.StructrApp)6 Tx (org.structr.core.graph.Tx)6 Document (org.apache.chemistry.opencmis.client.api.Document)5 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)5 File (java.io.File)4 HashMap (java.util.HashMap)4 Folder (org.apache.chemistry.opencmis.client.api.Folder)4 FrameworkException (org.structr.common.error.FrameworkException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)3 AbstractNode (org.structr.core.entity.AbstractNode)3 AbstractFile (org.structr.web.entity.AbstractFile)3 Folder (org.structr.web.entity.Folder)3 InputStream (java.io.InputStream)2 FileChannel (java.nio.channels.FileChannel)2 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)2