use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class CmisSender method sendMessageForActionFind.
private String sendMessageForActionFind(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Element queryElement = null;
try {
if (XmlUtils.isWellFormed(message, "query")) {
queryElement = XmlUtils.buildElement(message);
} else {
queryElement = XmlUtils.buildElement("<query/>");
}
} catch (DomBuilderException e) {
throw new SenderException(e);
}
String statement = XmlUtils.getChildTagAsString(queryElement, "statement");
String maxItems = XmlUtils.getChildTagAsString(queryElement, "maxItems");
String skipCount = XmlUtils.getChildTagAsString(queryElement, "skipCount");
String searchAllVersions = XmlUtils.getChildTagAsString(queryElement, "searchAllVersions");
String includeAllowableActions = XmlUtils.getChildTagAsString(queryElement, "includeAllowableActions");
OperationContext operationContext = session.createOperationContext();
if (StringUtils.isNotEmpty(maxItems)) {
operationContext.setMaxItemsPerPage(Integer.parseInt(maxItems));
}
boolean sav = false;
if (StringUtils.isNotEmpty(searchAllVersions)) {
sav = Boolean.parseBoolean(searchAllVersions);
}
if (StringUtils.isNotEmpty(includeAllowableActions)) {
operationContext.setIncludeAllowableActions(Boolean.parseBoolean(searchAllVersions));
}
ItemIterable<QueryResult> q = session.query(statement, sav, operationContext);
if (StringUtils.isNotEmpty(skipCount)) {
long sc = Long.parseLong(skipCount);
q = q.skipTo(sc);
}
if (StringUtils.isNotEmpty(maxItems)) {
q = q.getPage();
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
XmlBuilder rowsetXml = new XmlBuilder("rowset");
for (QueryResult qResult : q) {
XmlBuilder rowXml = new XmlBuilder("row");
for (PropertyData<?> property : qResult.getProperties()) {
rowXml.addSubElement(getPropertyXml(property));
}
rowsetXml.addSubElement(rowXml);
}
cmisXml.addSubElement(rowsetXml);
return cmisXml.toXML();
}
use of nl.nn.adapterframework.core.SenderException 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 nl.nn.adapterframework.core.SenderException 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 nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class CmisSender method processProperties.
private void processProperties(Element propertiesElement, Map props) throws SenderException {
Collection properties = XmlUtils.getChildTags(propertiesElement, "property");
Iterator iter = properties.iterator();
while (iter.hasNext()) {
Element propertyElement = (Element) iter.next();
String property = XmlUtils.getStringValue(propertyElement);
if (StringUtils.isNotEmpty(property)) {
String nameAttr = propertyElement.getAttribute("name");
String typeAttr = propertyElement.getAttribute("type");
if (StringUtils.isEmpty(typeAttr) || typeAttr.equalsIgnoreCase("string")) {
props.put(nameAttr, property);
} else if (typeAttr.equalsIgnoreCase("datetime")) {
String formatStringAttr = propertyElement.getAttribute("formatString");
if (StringUtils.isEmpty(formatStringAttr)) {
formatStringAttr = FORMATSTRING_BY_DEFAULT;
}
DateFormat df = new SimpleDateFormat(formatStringAttr);
Date date;
try {
date = df.parse(property);
} catch (ParseException e) {
throw new SenderException(getLogPrefix() + "exception parsing date [" + property + "] using formatString [" + formatStringAttr + "]", e);
}
props.put(nameAttr, date);
} else {
log.warn(getLogPrefix() + "unknown type [" + typeAttr + "], assuming 'string'");
props.put(nameAttr, property);
}
if (log.isDebugEnabled()) {
log.debug(getLogPrefix() + "set property name [" + nameAttr + "] value [" + property + "]");
}
} else {
log.debug(getLogPrefix() + "empty property found, ignoring");
}
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class XmlFileElementIteratorPipe method iterateInput.
protected void iterateInput(Object input, IPipeLineSession session, String correlationID, Map threadContext, ItemCallback callback) throws SenderException, TimeOutException {
InputStream xmlInput;
try {
xmlInput = new FileInputStream((String) input);
} catch (FileNotFoundException e) {
throw new SenderException("could not find file [" + input + "]", e);
}
ItemCallbackCallingHandler handler = new ItemCallbackCallingHandler(callback);
log.debug("obtaining list of elements [" + getElementName() + "] using sax parser");
try {
SAXParserFactory parserFactory = XmlUtils.getSAXParserFactory();
parserFactory.setNamespaceAware(true);
SAXParser saxParser = parserFactory.newSAXParser();
saxParser.parse(xmlInput, handler);
} catch (Exception e) {
if (handler.getTimeOutException() != null) {
throw handler.getTimeOutException();
}
if (!handler.isStopRequested()) {
throw new SenderException("Could not extract list of elements [" + getElementName() + "] using sax parser", e);
}
}
}
Aggregations