Search in sources :

Example 1 with CmisConstraintException

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

the class ChangeTokenTest method runUpdateDocumentTest.

private void runUpdateDocumentTest(Session session, Folder testFolder) {
    Document doc = createDocument(session, testFolder, "update1.txt", "Hello World!");
    try {
        if (doc.getChangeToken() == null) {
            addResult(createResult(SKIPPED, "Repository does not provide change tokens for documents. Test skipped!"));
            return;
        }
        DocumentTypeDefinition type = (DocumentTypeDefinition) doc.getType();
        PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME);
        if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT || !doc.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES)) {
            addResult(createResult(SKIPPED, "Document name can't be changed. Test skipped!"));
            return;
        }
        // the first update should succeed
        Map<String, Object> properties2 = new HashMap<String, Object>();
        properties2.put(PropertyIds.NAME, "update2.txt");
        ObjectId newId = doc.updateProperties(properties2, false);
        if (!doc.getId().equals(newId.getId())) {
            // the repository created a new version
            // -> a change token test does not make sense
            addResult(createResult(INFO, "The repository created a new version. Change tokens are not relevant here."));
        } else {
            try {
                Map<String, Object> properties3 = new HashMap<String, Object>();
                properties3.put(PropertyIds.NAME, "update3.txt");
                doc.updateProperties(properties3, false);
                addResult(createResult(FAILURE, "Updating properties a second time with the same change token " + "should result in an UpdateConflict exception!"));
            // } catch (CmisUpdateConflictException e) {
            } catch (CmisConstraintException e) {
            // expected exception
            }
        }
    } finally {
        deleteObject(doc);
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 2 with CmisConstraintException

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

the class ChangeTokenTest method runContentTest.

private void runContentTest(Session session, Folder testFolder) {
    if (session.getRepositoryInfo().getCapabilities().getContentStreamUpdatesCapability() != CapabilityContentStreamUpdates.ANYTIME) {
        addResult(createResult(SKIPPED, "Repository doesn't allow to replace content. Test skipped!"));
        return;
    }
    Document doc = createDocument(session, testFolder, "content1.txt", "Hello World!");
    try {
        if (doc.getChangeToken() == null) {
            addResult(createResult(SKIPPED, "Repository does not provide change tokens for documents. Test skipped!"));
            return;
        }
        if (!doc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
            addResult(createResult(SKIPPED, "Document content can't be changed. Test skipped!"));
            return;
        }
        byte[] contentBytes = IOUtils.toUTF8Bytes("New content");
        ContentStream contentStream = new ContentStreamImpl("content2.txt", BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
        ObjectId newId = doc.setContentStream(contentStream, true, false);
        if (newId == null) {
            // -> get the latest id from the version series
            if (Boolean.TRUE.equals(((DocumentTypeDefinition) doc.getType()).isVersionable())) {
                List<Document> versions = doc.getAllVersions();
                if (versions == null || versions.size() < 1) {
                    addResult(createResult(FAILURE, "Repository returned an empty list of document versions!"));
                } else {
                    // the latest document is at the top of the list
                    newId = versions.get(0);
                }
            } else {
                // the document type is not versionable
                // -> the repository couldn't create a new version
                newId = doc;
            }
        }
        if (newId != null) {
            if (!doc.getId().equals(newId.getId())) {
                // the repository created a new version
                // -> a change token test does not make sense
                addResult(createResult(INFO, "The repository created a new version. Change tokens are not relevant here."));
            } else {
                try {
                    doc.setContentStream(contentStream, true, false);
                    addResult(createResult(FAILURE, "Updating content a second time with the same change token " + "should result in an UpdateConflict exception!"));
                // } catch (CmisUpdateConflictException uce) {
                } catch (CmisConstraintException e) {
                // expected exception
                }
            }
        }
    } finally {
        deleteObject(doc);
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 3 with CmisConstraintException

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

the class FileSystemStorageService method setStoreSettings.

@Override
public void setStoreSettings(IRepositoryStorageSettings storeSettings) {
    if (storeSettings instanceof FileSystemStorageStoreSettings) {
        FileSystemStorageStoreSettings fileStore = (FileSystemStorageStoreSettings) storeSettings;
        String rootpath = fileStore.getFileLocation();
        if (rootpath == null) {
            LOG.error("Local storage path is undefined");
            throw new CmisConstraintException("Local storage path is undefined");
        }
        File directory = new File(rootpath);
        if (!directory.exists()) {
            directory.mkdirs();
        }
        this.storeSettings = (FileSystemStorageStoreSettings) storeSettings;
    } else {
        LOG.error("writeContent exception: {}", "Respository Setting details not valid");
        throw new IllegalArgumentException("Respository Setting details not valid");
    }
}
Also used : CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) File(java.io.File)

Example 4 with CmisConstraintException

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

the class FileSystemStorageService method rename.

@Override
public void rename(String oldPath, String newPath) throws IOException, IllegalArgumentException {
    LOG.debug("Rename of oldname into newname:{},{}", oldPath, newPath);
    String rootpath = this.storeSettings.getFileLocation();
    if (rootpath == null) {
        LOG.error("Local storage path is undefined");
        throw new CmisConstraintException("Local storage path is undefined");
    }
    File oldFile = new File(gettingFolderPath(this.storeSettings.getFileLocation(), oldPath));
    File newFile = new File(gettingFolderPath(this.storeSettings.getFileLocation(), newPath));
    oldFile.renameTo(newFile);
}
Also used : CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) File(java.io.File)

Example 5 with CmisConstraintException

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

the class CMISObjectService method updateProperties.

@Override
public void updateProperties(final String repositoryId, final Holder<String> objectId, final Holder<String> changeToken, final Properties properties, final ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    final String id = objectId.getValue();
    try (final Tx tx = app.tx()) {
        final AbstractNode obj = app.get(AbstractNode.class, id);
        if (obj != null) {
            final PropertyMap propertyMap = PropertyMap.cmisTypeToJavaType(securityContext, obj.getClass(), properties);
            if (propertyMap != null) {
                obj.setProperties(securityContext, propertyMap);
            }
        } else {
            throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
        }
        tx.success();
    } catch (FrameworkException fex) {
        throw new CmisConstraintException(fex.getMessage(), fex);
    }
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)

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