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");
}
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");
}
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);
}
}
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
}
}
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);
}
}
Aggregations