use of org.apache.chemistry.opencmis.client.api.Property 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.client.api.Property 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();
}
Aggregations