Search in sources :

Example 26 with ContentStreamImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl in project structr by structr.

the class CMISObjectService method createDocumentFromSource.

@Override
public String createDocumentFromSource(String repositoryId, String sourceId, Properties properties, String folderId, VersioningState versioningState, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) {
    // copy existing document
    final App app = StructrApp.getInstance(securityContext);
    String uuid = null;
    try (final Tx tx = app.tx()) {
        final File existingDocument = app.get(File.class, sourceId);
        if (existingDocument != null) {
            try (final InputStream inputStream = existingDocument.getInputStream()) {
                final ContentStreamImpl copyContentStream = new ContentStreamImpl();
                copyContentStream.setFileName(existingDocument.getName());
                copyContentStream.setMimeType(existingDocument.getContentType());
                copyContentStream.setLength(BigInteger.valueOf(existingDocument.getSize()));
                copyContentStream.setStream(inputStream);
                uuid = createDocument(repositoryId, properties, folderId, copyContentStream, versioningState, policies, addAces, removeAces, extension);
            }
        } else {
            throw new CmisObjectNotFoundException("Document with ID " + sourceId + " does not exist");
        }
        tx.success();
    } catch (Throwable t) {
        throw new CmisRuntimeException("New document could not be created: " + t.getMessage());
    }
    return uuid;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) InputStream(java.io.InputStream) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File)

Aggregations

ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)26 HashMap (java.util.HashMap)21 Document (org.apache.chemistry.opencmis.client.api.Document)18 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)17 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)16 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)15 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)15 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)15 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)15 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)15 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)15 Folder (org.apache.chemistry.opencmis.client.api.Folder)15 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)15 Test (org.junit.Test)15 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 FileContentWriter (org.alfresco.repo.content.filestore.FileContentWriter)13 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)13 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)13 ContentReader (org.alfresco.service.cmr.repository.ContentReader)13