use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project copper-cms by PogeyanOSS.
the class LatestAccessibleStateIdTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
try {
// create folder and document
Folder testFolder = createTestFolder(session);
Document doc = createDocument(session, testFolder, "lateststate.txt", "latest state");
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
if (!docType.getPropertyDefinitions().containsKey(PropertyIds.LATEST_ACCESSIBLE_STATE_ID)) {
addResult(createResult(SKIPPED, "Repository does not support the Latest State Identifier feature extension. Test skipped!"));
doc.delete(true);
return;
}
// check latest accessible state ID
f = createResult(FAILURE, "Latest Accessible State ID is not set!");
addResult(assertStringNotEmpty(doc.getLatestAccessibleStateId(), null, f));
// get document with latest accessible state ID
try {
CmisObject latestStateObject = session.getObject(doc.getLatestAccessibleStateId(), SELECT_ALL_NO_CACHE_OC);
if (latestStateObject instanceof Document) {
f = createResult(FAILURE, "Latest Accessible State IDs of the orignal and the retrieved document don't match!");
addResult(assertEquals(doc.getLatestAccessibleStateId(), ((Document) latestStateObject).getLatestAccessibleStateId(), null, f));
} else {
addResult(createResult(FAILURE, "Object retrieved with the Latest Accessible State ID is not a document!"));
}
} catch (CmisObjectNotFoundException onf) {
addResult(createResult(FAILURE, "Document could not be retrieved with the Latest Accessible State ID!"));
}
doc.delete(true);
} finally {
// delete the test folder
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project copper-cms by PogeyanOSS.
the class BaseTypesTest method run.
@Override
public void run(Session session) {
CmisTestResult failure;
// check base types
Set<String> cmisTypes = new HashSet<String>();
cmisTypes.add(BaseTypeId.CMIS_DOCUMENT.value());
cmisTypes.add(BaseTypeId.CMIS_FOLDER.value());
cmisTypes.add(BaseTypeId.CMIS_RELATIONSHIP.value());
cmisTypes.add(BaseTypeId.CMIS_POLICY.value());
if (session.getRepositoryInfo().getCmisVersion() != CmisVersion.CMIS_1_0) {
cmisTypes.add(BaseTypeId.CMIS_ITEM.value());
cmisTypes.add(BaseTypeId.CMIS_SECONDARY.value());
}
for (TypeDefinition typeDef : session.getTypeChildren(null, false)) {
String typeId = typeDef.getId();
if (typeId == null || !cmisTypes.contains(typeId)) {
addResult(createResult(FAILURE, "Base type has an invalid ID: " + typeId));
}
if (typeDef.getPropertyDefinitions() != null && !typeDef.getPropertyDefinitions().isEmpty()) {
addResult(createResult(WARNING, "Property type definitions were not requested but delivered. Type ID: " + typeId));
}
}
// document
try {
TypeDefinition documentType = session.getTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value());
addResult(checkTypeDefinition(session, documentType, "Document type spec compliance: " + documentType.getId()));
failure = createResult(FAILURE, "Document type has the wrong base type: " + documentType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_DOCUMENT, documentType.getBaseTypeId(), null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Document type not available!", e, false));
}
// folder
try {
TypeDefinition folderType = session.getTypeDefinition(BaseTypeId.CMIS_FOLDER.value());
addResult(checkTypeDefinition(session, folderType, "Folder type spec compliance: " + folderType.getId()));
failure = createResult(FAILURE, "Folder type has the wrong base type: " + folderType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_FOLDER, folderType.getBaseTypeId(), null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Folder type not available!", e, false));
}
// relationship
try {
TypeDefinition relationshipType = session.getTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value());
addResult(checkTypeDefinition(session, relationshipType, "Relationship type spec compliance: " + relationshipType.getId()));
failure = createResult(FAILURE, "Relationship type has the wrong base type: " + relationshipType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_RELATIONSHIP, relationshipType.getBaseTypeId(), null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Relationship type not available!", e, false));
}
// policy
try {
TypeDefinition policyType = session.getTypeDefinition(BaseTypeId.CMIS_POLICY.value());
addResult(checkTypeDefinition(session, policyType, "Policy type spec compliance: " + policyType.getId()));
failure = createResult(FAILURE, "Policy type has the wrong base type: " + policyType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_POLICY, policyType.getBaseTypeId(), null, failure));
} catch (CmisInvalidArgumentException e) {
addResult(createResult(WARNING, "Policy type not available!", e, false));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Policy type not available!", e, false));
}
// CMIS 1.1 types
if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_1) {
// item
try {
TypeDefinition itemType = session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
addResult(checkTypeDefinition(session, itemType, "Item type spec compliance: " + itemType.getId()));
failure = createResult(FAILURE, "Item type has the wrong base type: " + itemType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_ITEM, itemType.getBaseTypeId(), null, failure));
} catch (CmisInvalidArgumentException e) {
addResult(createResult(WARNING, "Item type not available!", e, false));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Item type not available!", e, false));
}
// secondary type
try {
TypeDefinition secondaryType = session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
addResult(checkTypeDefinition(session, secondaryType, "Secondary type spec compliance: " + secondaryType.getId()));
failure = createResult(FAILURE, "Secondary type has the wrong base type: " + secondaryType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_SECONDARY, secondaryType.getBaseTypeId(), null, failure));
} catch (CmisInvalidArgumentException e) {
addResult(createResult(WARNING, "Secondary type not available!", e, false));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Secondary type not available!", e, false));
}
} else {
try {
session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:item type definition!"));
} catch (CmisBaseException e) {
// expected
}
try {
session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:secondary type definition!"));
} catch (CmisBaseException e) {
// expected
}
}
// simple getTypeChildren paging test - skipping over all base types mut
// return an empty list
TypeDefinitionList typeDefinitionList = session.getBinding().getRepositoryService().getTypeChildren(session.getRepositoryInfo().getId(), null, false, BigInteger.valueOf(100), BigInteger.valueOf(6), null);
if (typeDefinitionList == null) {
addResult(createResult(FAILURE, "getTypeChildren() returned nothing!"));
} else {
if (typeDefinitionList.getList() != null && !typeDefinitionList.getList().isEmpty()) {
addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned a list of " + typeDefinitionList.getList().size() + " elements."));
}
if (Boolean.TRUE.equals(typeDefinitionList.hasMoreItems())) {
addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned hasMoreItems == true."));
}
}
// test getTypeDescendants()
int numOfTypes = runTypeChecks(session, session.getTypeDescendants(null, -1, true));
addResult(createInfoResult("Checked " + numOfTypes + " type definitions."));
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project copper-cms by PogeyanOSS.
the class FileSystemStorageService method setContent.
@Override
public void setContent(String objectId, String objectName, String oldFileName, String path, ContentStream inputStream) {
LOG.info("setContent dataId:{}" + objectName, objectId);
try {
// LOG.debug("setContent dataId:{}" + objectName,objectId);
if (!getFileExtensionExists(objectName)) {
objectName = objectName + MimeUtils.guessExtensionFromMimeType(inputStream.getMimeType());
}
File fileName = new File(gettingFolderPath(this.storeSettings.getFileLocation(), gettingDocNamePath(path)) + File.separator + objectName);
if (!fileName.exists()) {
LOG.error("setContent exception: {}", "File not found");
}
if (oldFileName != null) {
File oldFile = new File(oldFileName);
oldFile.delete();
}
writeContent(fileName, inputStream.getStream());
} catch (Exception e) {
LOG.error("setContent exception: {}, {}", e.getMessage(), ExceptionUtils.getStackTrace(e));
throw new CmisObjectNotFoundException(e.getMessage(), e);
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project structr by structr.
the class CMISRepositoryService method getTypeDescendants.
@Override
public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth, Boolean includePropertyDefinitions, ExtensionsData extension) {
// important: descendants are ALL children and children of children, i.e. the whole tree
/*
Id typeId: The typeId of an object-type specified in the repository.
- If specified, then the repository MUST return all of descendant types of the specified type.
- If not specified, then the Repository MUST return all types and MUST ignore the value of the depth parameter.
*/
final List<TypeDefinitionContainer> results = new LinkedList<>();
if (typeId != null) {
final BaseTypeId baseTypeId = getBaseTypeId(typeId);
if (baseTypeId != null) {
final TypeDefinition typeDefinition = getTypeDefinition(repositoryId, typeId, extension);
final TypeDefinitionContainer container = getTypeDefinitionContainer(typeDefinition, includePropertyDefinitions);
results.add(container);
} else {
final Class type = StructrApp.getConfiguration().getNodeEntityClass(typeId);
if (type != null) {
final TypeDefinition typeDefinition = extendTypeDefinition(type, includePropertyDefinitions);
if (typeDefinition != null) {
results.add(getTypeDefinitionContainer(typeDefinition, includePropertyDefinitions));
} else {
throw new CmisObjectNotFoundException("Type with ID " + typeId + " does not exist");
}
} else {
throw new CmisObjectNotFoundException("Type with ID " + typeId + " does not exist");
}
}
} else {
results.add(getTypeDefinitionContainer(getDocumentTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value(), includePropertyDefinitions, true), includePropertyDefinitions));
results.add(getTypeDefinitionContainer(getFolderTypeDefinition(BaseTypeId.CMIS_FOLDER.value(), includePropertyDefinitions, true), includePropertyDefinitions));
results.add(getTypeDefinitionContainer(getItemTypeDefinition(BaseTypeId.CMIS_ITEM.value(), includePropertyDefinitions, true), includePropertyDefinitions));
results.add(getTypeDefinitionContainer(getPolicyTypeDefinition(BaseTypeId.CMIS_POLICY.value(), includePropertyDefinitions, true), includePropertyDefinitions));
results.add(getTypeDefinitionContainer(getRelationshipTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value(), includePropertyDefinitions, true), includePropertyDefinitions));
results.add(getTypeDefinitionContainer(getSecondaryTypeDefinition(BaseTypeId.CMIS_SECONDARY.value(), includePropertyDefinitions, true), includePropertyDefinitions));
}
return results;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project structr by structr.
the class CMISAclService method getAcl.
@Override
public Acl getAcl(final String repositoryId, final String objectId, final Boolean onlyBasicPermissions, final ExtensionsData extension) {
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
final AbstractNode node = app.get(AbstractNode.class, objectId);
if (node != null) {
return CMISObjectWrapper.wrap(node, null, false);
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
Aggregations