use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project copper-cms by PogeyanOSS.
the class FileSystemStorageService method appendContent.
/**
* Append a content.
*
* @param dataId,
* contentStream, isLastChunk the content identifier.
* @return ContentStream the old ContentStream for the objectId
*/
@Override
public ContentStream appendContent(String objectId, String objectName, String path, ContentStream contentStream, Boolean isLastChunk) {
ContentStream oldContent = null;
LOG.info("appendContent dataId:{}" + objectName);
try {
LOG.debug("appendContent dataId:{}" + objectName);
if (!getFileExtensionExists(objectName)) {
objectName = objectName + MimeUtils.guessExtensionFromMimeType(contentStream.getMimeType());
}
File appendFileName = new File(gettingFolderPath(this.storeSettings.getFileLocation(), gettingDocNamePath(path)) + File.separator + objectName);
if (!appendFileName.exists()) {
LOG.error("appendContent exception: {}", "File not found");
}
// write content, if available
SequenceInputStream id = null;
if (contentStream != null && contentStream.getStream() != null) {
// if (isLastChunk.equals(true)) {
// id = new SequenceInputStream(new
// FileInputStream(appendFileName), contentStream.getStream());
// } else {
// id = new SequenceInputStream(contentStream.getStream(), new
// FileInputStream(appendFileName));
// }
id = new SequenceInputStream(new FileInputStream(appendFileName), contentStream.getStream());
Files.write(Paths.get(gettingFolderPath(this.storeSettings.getFileLocation(), gettingDocNamePath(path)) + File.separator + objectName), ByteStreams.toByteArray(id), StandardOpenOption.WRITE);
id.close();
oldContent = getContent(objectName, path, contentStream.getMimeType(), BigInteger.valueOf(appendFileName.length()));
}
} catch (Exception e) {
LOG.error("appendContent exception: {}, {}", e.getMessage(), ExceptionUtils.getStackTrace(e));
throw new CmisObjectNotFoundException(e.getMessage(), e);
}
return oldContent;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createFolder.
/**
* Creates a folder.
*/
protected Folder createFolder(Session session, Folder parent, String name, String objectTypeId) {
if (parent == null) {
throw new IllegalArgumentException("Parent is not set!");
}
if (name == null) {
throw new IllegalArgumentException("Name is not set!");
}
if (objectTypeId == null) {
throw new IllegalArgumentException("Object Type ID is not set!");
}
// check type
ObjectType type;
try {
type = session.getTypeDefinition(objectTypeId);
} catch (CmisObjectNotFoundException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Folder type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Folder type '" + objectTypeId + "' is not creatable!", true));
return null;
}
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
Folder result = null;
try {
// create the folder
result = parent.createFolder(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Folder could not be created! Exception: " + e.getMessage(), e, true));
return null;
}
try {
CmisTestResult f;
// check folder name
f = createResult(FAILURE, "Folder name does not match!", false);
addResult(assertEquals(name, result.getName(), null, f));
// check the new folder
String[] propertiesToCheck = new String[result.getType().getPropertyDefinitions().size()];
int i = 0;
for (String propId : result.getType().getPropertyDefinitions().keySet()) {
propertiesToCheck[i++] = propId;
}
addResult(checkObject(session, result, propertiesToCheck, "New folder object spec compliance"));
// check object parents
List<Folder> objectParents = result.getParents();
f = createResult(FAILURE, "Newly created folder has no or more than one parent! ID: " + result.getId(), true);
addResult(assertEquals(1, objectParents.size(), null, f));
f = createResult(FAILURE, "First object parent of the newly created folder does not match parent! ID: " + result.getId(), true);
assertShallowEquals(parent, objectParents.get(0), null, f);
// check folder parent
Folder folderParent = result.getFolderParent();
f = createResult(FAILURE, "Newly created folder has no folder parent! ID: " + result.getId(), true);
addResult(assertNotNull(folderParent, null, f));
f = createResult(FAILURE, "Folder parent of the newly created folder does not match parent! ID: " + result.getId(), true);
assertShallowEquals(parent, folderParent, null, f);
// check children of parent
boolean found = false;
for (CmisObject child : parent.getChildren(SELECT_ALL_NO_CACHE_OC)) {
if (child == null) {
addResult(createResult(FAILURE, "Parent folder contains a null child!", true));
} else {
if (result.getId().equals(child.getId())) {
found = true;
f = createResult(FAILURE, "Folder and parent child don't match! ID: " + result.getId(), true);
assertShallowEquals(result, child, null, f);
break;
}
}
}
if (!found) {
addResult(createResult(FAILURE, "Folder is not a child of the parent folder! ID: " + result.getId(), true));
}
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created folder is invalid! Exception: " + e.getMessage(), e, true));
}
return result;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createPolicy.
/**
* Creates a policy.
*/
protected Policy createPolicy(Session session, Folder parent, String name, String policyText, String objectTypeId) {
if (parent == null) {
throw new IllegalArgumentException("Parent is not set!");
}
if (name == null) {
throw new IllegalArgumentException("Name is not set!");
}
if (objectTypeId == null) {
throw new IllegalArgumentException("Object Type ID is not set!");
}
// check type
ObjectType type;
try {
type = session.getTypeDefinition(objectTypeId);
} catch (CmisObjectNotFoundException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Policy type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Policy type '" + objectTypeId + "' is not creatable!", true));
return null;
}
boolean isFilable = Boolean.TRUE.equals(type.isFileable());
addResult(createResult(INFO, "Policy type '" + objectTypeId + "' is " + (isFilable ? "" : "not ") + "filable."));
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
if (policyText != null) {
properties.put(PropertyIds.POLICY_TEXT, policyText);
}
Policy result = null;
try {
// create the item
if (isFilable) {
result = parent.createPolicy(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
} else {
ObjectId policyId = session.createPolicy(properties, null, null, null, null);
result = (Policy) session.getObject(policyId, SELECT_ALL_NO_CACHE_OC);
}
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Policy could not be created! Exception: " + e.getMessage(), e, true));
return null;
}
CmisTestResult f;
try {
// check item name
f = createResult(FAILURE, "Policy name does not match!", false);
addResult(assertEquals(name, result.getName(), null, f));
addResult(checkObject(session, result, getAllProperties(result), "New policy object spec compliance"));
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created policy is invalid! Exception: " + e.getMessage(), e, true));
}
// check parents
List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
if (isFilable) {
boolean found = false;
for (Folder folder : parents) {
if (parent.getId().equals(folder.getId())) {
found = true;
break;
}
}
if (!found) {
addResult(createResult(FAILURE, "The folder the item has been created in is not in the list of the item parents!"));
}
} else {
f = createResult(FAILURE, "Policy is not filable but has a parent!", false);
addResult(assertIsTrue(parents.isEmpty(), null, f));
}
return result;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method deleteType.
/**
* Deletes a type.
*/
protected void deleteType(Session session, String typeId) {
ObjectType type = session.getTypeDefinition(typeId);
if (type == null) {
addResult(createResult(FAILURE, "Type does not exist and therefore cannot be deleted! ID: " + typeId));
return;
}
// check if type can be deleted
if (type.getTypeMutability() == null) {
addResult(createResult(FAILURE, "Type does not provide type mutability data! ID: " + typeId));
} else {
if (!Boolean.TRUE.equals(type.getTypeMutability().canDelete())) {
addResult(createResult(WARNING, "Type indicates that it cannot be deleted. Trying it anyway. ID: " + typeId));
}
}
// delete it
try {
session.deleteType(typeId);
} catch (CmisBaseException e) {
addResult(createResult(FAILURE, "Deleting type '" + typeId + "' failed: " + e.getMessage(), e, false));
return;
}
// check if the type still exists
try {
session.getTypeDefinition(typeId);
addResult(createResult(FAILURE, "Type should not exist anymore but it is still there! ID: " + typeId, true));
} catch (CmisObjectNotFoundException e) {
// expected result
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project copper-cms by PogeyanOSS.
the class BaseTypesTest method runTypeChecks.
private int runTypeChecks(Session session, List<Tree<ObjectType>> types) {
if (types == null) {
return 0;
}
int numOfTypes = 0;
CmisTestResult failure;
for (Tree<ObjectType> tree : types) {
failure = createResult(FAILURE, "Types tree contains null leaf!");
addResult(assertNotNull(tree, null, failure));
if (tree != null) {
numOfTypes++;
addResult(checkTypeDefinition(session, tree.getItem(), "Type spec compliance: " + tree.getItem().getId()));
// clear the cache to ensure that the type definition is
// reloaded from the repository
session.clear();
try {
TypeDefinition reloadedType = session.getTypeDefinition(tree.getItem().getId());
addResult(checkTypeDefinition(session, reloadedType, "Type spec compliance: " + (reloadedType == null ? "?" : reloadedType.getId())));
failure = createResult(FAILURE, "Type fetched via getTypeDescendants() is does not macth type fetched via getTypeDefinition(): " + tree.getItem().getId());
addResult(assertEquals(tree.getItem(), reloadedType, null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Type fetched via getTypeDescendants() is not available via getTypeDefinition(): " + tree.getItem().getId(), e, false));
}
// clear the cache again to ensure that the type definition
// children are reloaded from the repository
session.clear();
try {
ItemIterable<ObjectType> reloadedTypeChildren = session.getTypeChildren(tree.getItem().getId(), true);
// check type children
Map<String, ObjectType> typeChilden = new HashMap<String, ObjectType>();
for (ObjectType childType : reloadedTypeChildren) {
if (childType == null) {
addResult(createResult(FAILURE, "The list of types contains a null entry!"));
continue;
}
addResult(checkTypeDefinition(session, childType, "Type spec compliance: " + childType.getId()));
typeChilden.put(childType.getId(), childType);
}
// compare type children and type descendants
if (tree.getChildren() == null) {
failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
addResult(assertEquals(0, typeChilden.size(), null, failure));
} else {
// collect the children
Map<String, ObjectType> typeDescendants = new HashMap<String, ObjectType>();
for (Tree<ObjectType> childType : tree.getChildren()) {
if ((childType != null) && (childType.getItem() != null)) {
typeDescendants.put(childType.getItem().getId(), childType.getItem());
}
}
failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
addResult(assertEquals(typeDescendants.size(), typeChilden.size(), null, failure));
for (ObjectType compareType : typeDescendants.values()) {
failure = createResult(FAILURE, "Type fetched via getTypeDescendants() doesn't match type fetched via getTypeChildren(): " + tree.getItem().getId());
addResult(assertEquals(compareType, typeChilden.get(compareType.getId()), null, failure));
}
}
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Type children fetched via getTypeDescendants() are not available via getTypeChildren(): " + tree.getItem().getId(), e, false));
}
numOfTypes += runTypeChecks(session, tree.getChildren());
}
}
return numOfTypes;
}
Aggregations