use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project iaf by ibissource.
the class CmisSender method sendMessageForActionGet.
private String sendMessageForActionGet(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
if (StringUtils.isEmpty(message)) {
throw new SenderException(getLogPrefix() + "input string cannot be empty but must contain a documentId");
}
CmisObject object = null;
try {
object = session.getObject(session.createObjectId(message));
} catch (CmisObjectNotFoundException e) {
if (StringUtils.isNotEmpty(getResultOnNotFound())) {
log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
return getResultOnNotFound();
} else {
throw new SenderException(e);
}
}
Document document = (Document) object;
ContentStream contentStream = document.getContentStream();
try {
InputStream inputStream = contentStream.getStream();
if (isStreamResultToServlet()) {
HttpServletResponse response = (HttpServletResponse) prc.getSession().get(IPipeLineSession.HTTP_RESPONSE_KEY);
String contentType = contentStream.getMimeType();
if (StringUtils.isNotEmpty(contentType)) {
log.debug(getLogPrefix() + "setting response Content-Type header [" + contentType + "]");
response.setHeader("Content-Type", contentType);
}
String contentDisposition = "attachment; filename=\"" + contentStream.getFileName() + "\"";
log.debug(getLogPrefix() + "setting response Content-Disposition header [" + contentDisposition + "]");
response.setHeader("Content-Disposition", contentDisposition);
OutputStream outputStream;
outputStream = response.getOutputStream();
Misc.streamToStream(inputStream, outputStream);
log.debug(getLogPrefix() + "copied document content input stream [" + inputStream + "] to output stream [" + outputStream + "]");
return "";
} else if (isGetProperties()) {
if (StringUtils.isNotEmpty(fileInputStreamSessionKey)) {
prc.getSession().put(getFileInputStreamSessionKey(), inputStream);
} else {
byte[] bytes = Misc.streamToBytes(inputStream);
prc.getSession().put(getFileContentSessionKey(), Base64.encodeBase64String(bytes));
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
XmlBuilder propertiesXml = new XmlBuilder("properties");
for (Iterator it = document.getProperties().iterator(); it.hasNext(); ) {
Property property = (Property) it.next();
propertiesXml.addSubElement(getPropertyXml(property));
}
cmisXml.addSubElement(propertiesXml);
return cmisXml.toXML();
} else {
return Misc.streamToString(inputStream, null, false);
}
} catch (IOException e) {
throw new SenderException(e);
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project iaf by ibissource.
the class CmisSender method sendMessageForActionFetch.
private String sendMessageForActionFetch(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Element queryElement = null;
try {
if (XmlUtils.isWellFormed(message, "cmis")) {
queryElement = XmlUtils.buildElement(message);
} else {
queryElement = XmlUtils.buildElement("<cmis/>");
}
} catch (DomBuilderException e) {
throw new SenderException(e);
}
String objectIdstr = XmlUtils.getChildTagAsString(queryElement, "objectId");
String filter = XmlUtils.getChildTagAsString(queryElement, "filter");
boolean includeAllowableActions = XmlUtils.getChildTagAsBoolean(queryElement, "includeAllowableActions");
boolean includePolicies = XmlUtils.getChildTagAsBoolean(queryElement, "includePolicies");
boolean includeAcl = XmlUtils.getChildTagAsBoolean(queryElement, "includeAcl");
OperationContext operationContext = session.createOperationContext();
if (StringUtils.isNotEmpty(filter))
operationContext.setFilterString(filter);
operationContext.setIncludeAllowableActions(includeAllowableActions);
operationContext.setIncludePolicies(includePolicies);
operationContext.setIncludeAcls(includeAcl);
CmisObject object = null;
try {
object = session.getObject(session.createObjectId(objectIdstr), operationContext);
} catch (CmisObjectNotFoundException e) {
if (StringUtils.isNotEmpty(getResultOnNotFound())) {
log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
return getResultOnNotFound();
} else {
throw new SenderException(e);
}
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
XmlBuilder propertiesXml = new XmlBuilder("properties");
for (Iterator it = object.getProperties().iterator(); it.hasNext(); ) {
Property property = (Property) it.next();
propertiesXml.addSubElement(getPropertyXml(property));
}
cmisXml.addSubElement(propertiesXml);
XmlBuilder allowableActionsXml = new XmlBuilder("allowableActions");
Set<Action> actions = object.getAllowableActions().getAllowableActions();
for (Action action : actions) {
XmlBuilder actionXml = new XmlBuilder("action");
actionXml.setValue(action.value());
allowableActionsXml.addSubElement(actionXml);
}
cmisXml.addSubElement(allowableActionsXml);
XmlBuilder isExactAclXml = new XmlBuilder("isExactAcl");
if (object.getAcl() != null)
isExactAclXml.setValue(object.getAcl().isExact().toString());
cmisXml.addSubElement(isExactAclXml);
XmlBuilder policiesXml = new XmlBuilder("policyIds");
List<ObjectId> policies = object.getPolicyIds();
if (policies != null) {
for (ObjectId objectId : policies) {
XmlBuilder policyXml = new XmlBuilder("policyId");
policyXml.setValue(objectId.getId());
policiesXml.addSubElement(policyXml);
}
}
cmisXml.addSubElement(policiesXml);
XmlBuilder relationshipsXml = new XmlBuilder("relationships");
List<Relationship> relationships = object.getRelationships();
if (relationships != null) {
for (Relationship relation : relationships) {
XmlBuilder policyXml = new XmlBuilder("relation");
policyXml.setValue(relation.getId());
relationshipsXml.addSubElement(policyXml);
}
}
cmisXml.addSubElement(relationshipsXml);
return cmisXml.toXML();
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project iaf by ibissource.
the class CmisSender method sendMessageForActionUpdate.
private String sendMessageForActionUpdate(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String objectId = null;
Map props = new HashMap();
Element cmisElement;
try {
if (XmlUtils.isWellFormed(message, "cmis")) {
cmisElement = XmlUtils.buildElement(message);
} else {
cmisElement = XmlUtils.buildElement("<cmis/>");
}
objectId = XmlUtils.getChildTagAsString(cmisElement, "id");
Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
if (propertiesElement != null) {
processProperties(propertiesElement, props);
}
} catch (DomBuilderException e) {
throw new SenderException(getLogPrefix() + "exception parsing [" + message + "]", e);
}
CmisObject object = null;
try {
object = session.getObject(session.createObjectId(objectId));
} catch (CmisObjectNotFoundException e) {
if (StringUtils.isNotEmpty(getResultOnNotFound())) {
log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
return getResultOnNotFound();
} else {
throw new SenderException(e);
}
}
object.updateProperties(props);
return object.getId();
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createItem.
/**
* Creates a item.
*/
protected Item createItem(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, "Item type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Item 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);
Item result = null;
try {
// create the item
result = parent.createItem(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Item could not be created! Exception: " + e.getMessage(), e, true));
return null;
}
try {
CmisTestResult f;
// check item name
f = createResult(FAILURE, "Item name does not match!", false);
addResult(assertEquals(name, result.getName(), null, f));
addResult(checkObject(session, result, getAllProperties(result), "New item object spec compliance"));
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created item is invalid! Exception: " + e.getMessage(), e, true));
}
// check parents
List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
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!"));
}
return result;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createRelationship.
/**
* Creates a relationship.
*/
protected Relationship createRelationship(Session session, String name, ObjectId source, ObjectId target, String objectTypeId) {
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, "Relationship type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Relationship 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);
properties.put(PropertyIds.SOURCE_ID, source.getId());
properties.put(PropertyIds.TARGET_ID, target.getId());
ObjectId relId;
Relationship result = null;
try {
relId = session.createRelationship(properties);
result = (Relationship) session.getObject(relId, SELECT_ALL_NO_CACHE_OC);
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Relationship could not be created! Exception: " + e.getMessage(), e, true));
}
if (result != null) {
try {
// check the new relationship
addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
}
}
return result;
}
Aggregations