use of org.apache.chemistry.opencmis.client.api.QueryResult 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 org.apache.chemistry.opencmis.client.api.QueryResult in project SearchServices by Alfresco.
the class CMISDataCreatorTest method testCreateLots.
public void testCreateLots() throws Exception {
Session session = getSession("admin", "admin");
Folder root = session.getRootFolder();
String folderNameBase = getRootFolderName();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
properties.put(PropertyIds.NAME, folderNameBase);
Folder base = root.createFolder(properties);
for (int i = 0; i < 10; i++) {
AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl("" + i + i + i);
List<String> permissions = new ArrayList<String>(1);
permissions.add(BasicPermissions.ALL);
List<Ace> addAces = new ArrayList<Ace>(1);
addAces.add(new AccessControlEntryImpl(principal, permissions));
base.addAcl(addAces, AclPropagation.PROPAGATE);
}
Thread last = null;
for (int i = 0; i < 10; i++) {
Creator creator = new Creator(base.getPath(), i);
Thread thread = new Thread(creator);
thread.start();
last = thread;
}
if (last != null) {
last.join();
}
ItemIterable<QueryResult> result = session.query("select * from cmis:folder", false);
assertTrue(result.getTotalNumItems() > 0);
// result = session.query("select * from cmis:folder where cmis:name = '"+folderName+"'", false);
// assertTrue(result.getTotalNumItems() > 0);
}
use of org.apache.chemistry.opencmis.client.api.QueryResult in project SearchServices by Alfresco.
the class CMISDataCreatorTest method testQueryFolderProperties.
public void testQueryFolderProperties() {
Session session = getSession("admin", "admin");
String folderName = getRootFolderName();
Folder root = session.getRootFolder();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
properties.put(PropertyIds.NAME, folderName);
// create the folder
Folder newFolder = root.createFolder(properties);
ItemIterable<QueryResult> result = session.query("select * from cmis:folder where cmis:name = '" + folderName + "'", false);
assertEquals(1, result.getTotalNumItems());
String uniqueName = getUniqueName();
Map<String, Object> uProperties = new HashMap<String, Object>();
uProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
uProperties.put(PropertyIds.NAME, uniqueName);
Folder uniqueFolder = newFolder.createFolder(uProperties);
result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND IN_FOLDER('" + uniqueFolder.getParentId() + "')", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:folder where IN_FOLDER('" + uniqueFolder.getParentId() + "')", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:createdBy = '" + uniqueFolder.getCreatedBy() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:objectId = '" + uniqueFolder.getId() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:lastModifiedBy = '" + uniqueFolder.getLastModifiedBy() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:folder where cmis:name = '" + uniqueFolder.getName() + "'", false);
assertEquals(1, result.getTotalNumItems());
String creationDate = ISO8601DateFormat.format(uniqueFolder.getCreationDate().getTime());
result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:creationDate = '" + creationDate + "'", false);
assertEquals(1, result.getTotalNumItems());
String modificationDate = ISO8601DateFormat.format(uniqueFolder.getLastModificationDate().getTime());
result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:lastModificationDate = '" + modificationDate + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:objectTypeId = '" + uniqueFolder.getType().getQueryName() + "'", false);
assertEquals(1, result.getTotalNumItems());
result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:baseTypeId = '" + uniqueFolder.getBaseType().getQueryName() + "'", false);
assertEquals(1, result.getTotalNumItems());
}
use of org.apache.chemistry.opencmis.client.api.QueryResult in project camel by apache.
the class CMISSessionFacade method retrieveResult.
//some duplication
public List<Map<String, Object>> retrieveResult(Boolean retrieveContent, Integer readSize, ItemIterable<QueryResult> itemIterable) {
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
boolean queryForContent = retrieveContent != null ? retrieveContent : readContent;
int documentsToRead = readSize != null ? readSize : readCount;
int count = 0;
int pageNumber = 0;
boolean finished = false;
while (!finished) {
ItemIterable<QueryResult> currentPage = itemIterable.skipTo(count).getPage();
LOG.debug("Processing page {}", pageNumber);
for (QueryResult item : currentPage) {
Map<String, Object> properties = CMISHelper.propertyDataToMap(item.getProperties());
if (queryForContent) {
InputStream inputStream = getContentStreamFor(item);
properties.put(CamelCMISConstants.CAMEL_CMIS_CONTENT_STREAM, inputStream);
}
result.add(properties);
count++;
if (count == documentsToRead) {
finished = true;
break;
}
}
pageNumber++;
if (!currentPage.getHasMoreItems()) {
finished = true;
}
}
return result;
}
use of org.apache.chemistry.opencmis.client.api.QueryResult in project camel by apache.
the class CMISSessionFacade method pollWithQuery.
private int pollWithQuery(CMISConsumer cmisConsumer) throws Exception {
int count = 0;
int pageNumber = 0;
boolean finished = false;
ItemIterable<QueryResult> itemIterable = executeQuery(query);
while (!finished) {
ItemIterable<QueryResult> currentPage = itemIterable.skipTo(count).getPage();
LOG.debug("Processing page {}", pageNumber);
for (QueryResult item : currentPage) {
Map<String, Object> properties = CMISHelper.propertyDataToMap(item.getProperties());
Object objectTypeId = item.getPropertyValueById(PropertyIds.OBJECT_TYPE_ID);
InputStream inputStream = null;
if (readContent && CamelCMISConstants.CMIS_DOCUMENT.equals(objectTypeId)) {
inputStream = getContentStreamFor(item);
}
cmisConsumer.sendExchangeWithPropsAndBody(properties, inputStream);
count++;
if (count == readCount) {
finished = true;
break;
}
}
pageNumber++;
if (!currentPage.getHasMoreItems()) {
finished = true;
}
}
return count;
}
Aggregations