Search in sources :

Example 21 with CmisObjectNotFoundException

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

the class CMISObjectService method getContentStream.

@Override
public ContentStream getContentStream(final String repositoryId, final String objectId, final String streamId, final BigInteger offset, final BigInteger length, final ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    ContentStreamImpl result = null;
    try (final Tx tx = app.tx()) {
        final File file = app.get(File.class, objectId);
        if (file != null) {
            return new CMISContentStream(file, offset, length);
        }
        tx.success();
    } catch (Throwable t) {
        logger.warn("", t);
    }
    if (result != null) {
        return result;
    }
    throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
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) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File) CMISContentStream(org.structr.files.cmis.wrapper.CMISContentStream)

Example 22 with CmisObjectNotFoundException

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

the class CMISObjectService method getObjectByPath.

@Override
public ObjectData getObjectByPath(final String repositoryId, final String path, final String propertyFilter, final Boolean includeAllowableActions, final IncludeRelationships includeRelationships, final String renditionFilter, final Boolean includePolicyIds, final Boolean includeAcl, final ExtensionsData extension) {
    final PropertyKey<String> pathKey = StructrApp.key(AbstractFile.class, "path");
    final App app = StructrApp.getInstance();
    ObjectData result = null;
    try (final Tx tx = app.tx()) {
        final AbstractFile file = app.nodeQuery(AbstractFile.class).and(pathKey, path).getFirst();
        if (file != null) {
            result = CMISObjectWrapper.wrap(file, propertyFilter, includeAllowableActions);
        }
        tx.success();
    } catch (Throwable t) {
        logger.warn("", t);
    }
    if (result != null) {
        return result;
    }
    throw new CmisObjectNotFoundException("Object with path " + path + " does not exist");
}
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) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData)

Example 23 with CmisObjectNotFoundException

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

the class CMISObjectService method deleteObject.

@Override
public void deleteObject(String repositoryId, String objectId, Boolean allVersions, ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        final Principal principal = securityContext.getUser(false);
        final AbstractNode obj = app.get(AbstractNode.class, objectId);
        if (obj != null) {
            if (principal.isGranted(Permission.delete, securityContext)) {
                if (obj.isNode()) {
                    // getSyncNode() returns the node or null
                    app.delete(obj.getSyncNode());
                } else {
                    // getSyncRelationship() return the relationship or null
                    app.delete(obj.getSyncRelationship());
                }
            } else {
                throw new CmisPermissionDeniedException("Cannot delete object with ID " + objectId);
            }
        } 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) 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) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) Principal(org.structr.core.entity.Principal)

Example 24 with CmisObjectNotFoundException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project alfresco-remote-api by Alfresco.

the class TestCMIS method testTypeFiltering.

/**
 * ALF-18968
 *
 * @see QNameFilterImpl#listOfHardCodedExcludedTypes()
 */
@Test
public void testTypeFiltering() throws Exception {
    // Force an exclusion in order to test the exclusion inheritance
    cmisTypeExclusions.setExcluded(ActionModel.TYPE_ACTION_BASE, true);
    // Quick check
    assertTrue(cmisTypeExclusions.isExcluded(ActionModel.TYPE_ACTION_BASE));
    // Test that a type defined with this excluded parent type does not break the CMIS dictionary
    DictionaryBootstrap bootstrap = new DictionaryBootstrap();
    List<String> bootstrapModels = new ArrayList<String>();
    bootstrapModels.add("publicapi/test-model.xml");
    bootstrap.setModels(bootstrapModels);
    bootstrap.setDictionaryDAO(dictionaryDAO);
    bootstrap.setTenantService(tenantService);
    bootstrap.bootstrap();
    cmisDictionary.afterDictionaryInit();
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    // test that this type is excluded; the 'action' model (act prefix) is in the list of hardcoded exclusions
    QName type = QName.createQName("{http://www.alfresco.org/test/testCMIS}type1");
    assertTrue(cmisTypeExclusions.isExcluded(type));
    // and that we can't get to it through CMIS
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
    try {
        cmisSession.getTypeDefinition("D:testCMIS:type1");
        fail("Type should not be available");
    } catch (CmisObjectNotFoundException e) {
    // ok
    }
}
Also used : AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) DictionaryBootstrap(org.alfresco.repo.dictionary.DictionaryBootstrap) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 25 with CmisObjectNotFoundException

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

the class FileSystemStorageService method getContent.

@Override
public org.apache.chemistry.opencmis.commons.data.ContentStream getContent(String objectName, String path, String mimeType, BigInteger length) {
    LOG.info("getConetent file name:{}" + objectName);
    try {
        String objectNameWithExtension = objectName;
        if (LOG.isDebugEnabled()) {
            LOG.debug("getConetent file name:{}" + objectName);
        }
        if (!getFileExtensionExists(objectName)) {
            objectNameWithExtension = objectName + MimeUtils.guessExtensionFromMimeType(mimeType);
        }
        ContentStream contentStream = null;
        File file = new File(gettingFolderPath(this.storeSettings.getFileLocation(), gettingDocNamePath(path)) + File.separator + objectNameWithExtension);
        if (!file.isFile()) {
            return contentStream;
        }
        if (file.length() == 0) {
            return new ContentStreamImpl(objectName, length, MimeTypes.getMIMEType(file), new FileInputStream(file));
        }
        contentStream = new ContentStreamImpl(objectName, length, MimeTypes.getMIMEType(file), new FileInputStream(file));
        return contentStream;
    } catch (Exception e) {
        LOG.error("getContent exception: {}, {}", e.getMessage(), ExceptionUtils.getStackTrace(e));
        throw new CmisObjectNotFoundException(e.getMessage(), e);
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) IOException(java.io.IOException)

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