public void doQuery(String cql, int maxItems) { Session cmisSession = getCmisSession(); OperationContext oc = new OperationContextImpl(); oc.setMaxItemsPerPage(maxItems); ItemIterable<QueryResult> results = cmisSession.query(cql, false, oc); for (QueryResult result : results) { for (PropertyData<?> prop : result.getProperties()) { System.out.println(prop.getQueryName() + ": " + prop.getFirstValue()); } System.out.println("--------------------------------------"); } System.out.println("--------------------------------------"); System.out.println("Total number: " + results.getTotalNumItems()); System.out.println("Has more: " + results.getHasMoreItems()); System.out.println("--------------------------------------"); }
private void doQuery(Session session, String stmt) { for (QueryResult qr : session.query(stmt, false)) { qr.getPropertyByQueryName("cmis:name"); } }
properties.put(PropertyIds.OBJECT_ID, (String) result.getPropertyValueById(PropertyIds.OBJECT_ID)); properties.put(PropertyIds.NAME, (String) result.getPropertyValueById(PropertyIds.NAME)); properties.put(Section.PROPERTY_TITLE, (String) result.getPropertyValueById(Section.PROPERTY_TITLE)); properties.put(Section.PROPERTY_DESCRIPTION, (String) result.getPropertyValueById(Section.PROPERTY_DESCRIPTION)); properties.put(Section.PROPERTY_EXCLUDE_FROM_NAV, (Boolean) result.getPropertyValueById(Section.PROPERTY_EXCLUDE_FROM_NAV)); List<String> configList = result.getPropertyMultivalueById(Section.PROPERTY_SECTION_CONFIG); properties.put(Section.PROPERTY_SECTION_CONFIG, (Serializable) configList); List<String> tagSummary = result.getPropertyMultivalueById(PROPERTY_TAG_SUMMARY); section.setTags(createTags(tagSummary)); section.setSectionFactory(this); sectionDetails.objectTypeId = (String) result.getPropertyValueById(PropertyIds.OBJECT_TYPE_ID); String parentId = (String) result.getPropertyValueById(PropertyIds.PARENT_ID); section.setPrimarySectionId(parentId);
Map<String, Serializable> properties = new TreeMap<String, Serializable>(); properties.put(PropertyIds.OBJECT_ID, (String) result.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue()); properties.put(PropertyIds.OBJECT_TYPE_ID, (Serializable) result.getPropertyById(PropertyIds.OBJECT_TYPE_ID) .getFirstValue()); properties.put(PropertyIds.NAME, (Serializable) result.getPropertyById(PropertyIds.NAME).getFirstValue()); properties.put(PropertyIds.CONTENT_STREAM_LENGTH, (Serializable) result.getPropertyById( PropertyIds.CONTENT_STREAM_LENGTH).getFirstValue()); properties.put(PropertyIds.CONTENT_STREAM_MIME_TYPE, (Serializable) result.getPropertyById( PropertyIds.CONTENT_STREAM_MIME_TYPE).getFirstValue()); properties.put(Resource.PROPERTY_TITLE, (Serializable) result.getPropertyById(Resource.PROPERTY_TITLE) .getFirstValue()); properties.put(Resource.PROPERTY_MODIFIED_TIME, SqlUtils.getDateProperty(result, Resource.PROPERTY_MODIFIED_TIME)); properties.put(Resource.PROPERTY_DESCRIPTION, (Serializable) result.getPropertyById( Resource.PROPERTY_DESCRIPTION).getFirstValue()); properties.put(Asset.PROPERTY_AVERAGE_RATING, (Serializable) result.getPropertyById( Asset.PROPERTY_AVERAGE_RATING).getFirstValue()); properties.put(Asset.PROPERTY_COMMENT_COUNT, (Serializable) result .getPropertyById(Asset.PROPERTY_COMMENT_COUNT).getFirstValue()); properties.put(Asset.PROPERTY_TAGS, (Serializable) result.getPropertyMultivalueById(Asset.PROPERTY_TAGS)); properties.put(Asset.PROPERTY_PUBLISHED_TIME, SqlUtils.getDateProperty(result, Asset.PROPERTY_PUBLISHED_TIME)); properties.put(Asset.PROPERTY_AUTHOR, (Serializable) result.getPropertyById(Asset.PROPERTY_AUTHOR) .getFirstValue()); List<String> parentSectionIds = result.getPropertyMultivalueById(Asset.PROPERTY_PARENT_SECTIONS); if (parentSectionIds == null || parentSectionIds.isEmpty())
.getPropertyValueByQueryName("SEARCH_SCORE")).scaleByPowerOfTen(2).intValue()));
if (qr.getProperties().isEmpty()) { addResult(results, createResult(FAILURE, "Query result is empty!")); } else { PropertyData<?> pd = qr.getPropertyByQueryName(propDef.getQueryName());
private VisitorFeedbackImpl buildFeedbackObject(QueryResult queryResult) { BigInteger rating = (BigInteger) queryResult.getPropertyValueById(PROP_RATING); VisitorFeedbackImpl feedback = buildFeedbackObject( (String) queryResult.getPropertyValueById(PROP_ARTICLE), (String) queryResult.getPropertyValueById(PROP_NAME), (String) queryResult.getPropertyValueById(PROP_EMAIL), (String) queryResult.getPropertyValueById(PROP_WEBSITE), (String) queryResult.getPropertyValueById(PROP_FEEDBACK_TYPE), (String) queryResult.getPropertyValueById(PROP_SUBJECT), (String) queryResult.getPropertyValueById(PROP_COMMENT), (Boolean) queryResult.getPropertyValueById(PROP_COMMENT_FLAGGED), rating == null ? null : rating.intValue()); feedback.setId((String) queryResult.getPropertyValueById(PropertyIds.OBJECT_ID)); feedback.setPostTime(((Calendar) queryResult.getPropertyValueById(PropertyIds.CREATION_DATE)).getTime()); return feedback; }
/** * Open CMIS returns dates as a Calendar but freemarker cannot * cope with these so convert them to a Date. * @param result Queryresult from CMIS * @param propertyId property name * @return Date */ public static Date getDateProperty(QueryResult result, String propertyId) { PropertyData<Object> property = result.getPropertyById(propertyId); if (property == null) return null; Calendar calendar = (Calendar)property.getFirstValue(); return calendar != null ? calendar.getTime() : null; } }
/** * Build a list of related target node ids for the collection * @param result * @return List<String> list of related resource ids */ private List<String> buildRelatedAssetList(QueryResult result) { List<String> relatedIds = new ArrayList<String>(); List<Relationship> relationships = result.getRelationships(); for (Relationship relationship : relationships) { String name = relationship.getPropertyValue(PropertyIds.NAME); String targetId = relationship.getPropertyValue(PropertyIds.TARGET_ID); log.debug(name+" "+targetId); relatedIds.add(targetId); } return relatedIds; }
ItemIterable<QueryResult> results = statement.query(false); for (QueryResult qr : results) { String folderId = qr.getPropertyValueByQueryName("folderId"); String folderName = qr.getPropertyValueByQueryName("folderName");
kickstartWorkflowInfo.setName((String) result.getPropertyValueById("cm:description")); kickstartWorkflowInfo.setId(processNameToBaseName((String) result.getPropertyValueById(PropertyIds.NAME))); GregorianCalendar createDate = result.getPropertyValueById(PropertyIds.CREATION_DATE); kickstartWorkflowInfo.setCreateTime(createDate.getTime()) ; workflowInfos.add(kickstartWorkflowInfo);
@Override public Map<String, Date> getModifiedTimesOfAssets(Collection<String> assetIds) { Map<String, Date> map = new TreeMap<String, Date>(); String idList = buildIdList(assetIds); String cmisQuery = MessageFormat.format(modifiedTimesByAssetIds, idList); ItemIterable<QueryResult> results = runQuery(cmisQuery); Iterator<QueryResult> iterator = results.iterator(); Date modifiedTime; String id; while (iterator.hasNext()) { QueryResult result = iterator.next(); modifiedTime = SqlUtils.getDateProperty(result, Resource.PROPERTY_MODIFIED_TIME); id = (String) result.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue(); map.put(id, modifiedTime); } return map; }
count++; String objectId = qr.getPropertyValueByQueryName("cmis:objectId");
String id = result.getPropertyValueById(PropertyIds.OBJECT_ID); String hostName = result.getPropertyValueById(WebSite.PROP_HOSTNAME); BigInteger hostPort = result.getPropertyValueById(WebSite.PROP_HOSTPORT); String context = result.getPropertyValueById(WebSite.PROP_CONTEXT); if (context == null) String title = result.getPropertyValueById(Asset.PROPERTY_TITLE); String description = result.getPropertyValueById(Asset.PROPERTY_DESCRIPTION); List<String> configList = result.getPropertyMultivalueById(WebSite.PROP_SITE_CONFIG); Map<String,String> configProperties = parseSiteConfig(configList);
log.debug("{} \nobjectTypeId={}\nname={}\ncreatedBy={}\nobjectId={}\ncontentStreamFileName={}\ncontentStreamMimeType={}\ncontentStreamLengt={}", i++, qr.getPropertyByQueryName("cmis:objectTypeId").getFirstValue(), qr.getPropertyByQueryName("cmis:name").getFirstValue(), qr.getPropertyByQueryName("cmis:createdBy").getFirstValue(), qr.getPropertyByQueryName("cmis:objectId").getFirstValue(), qr.getPropertyByQueryName("cmis:contentStreamFileName").getFirstValue(), qr.getPropertyByQueryName("cmis:contentStreamMimeType").getFirstValue(), qr.getPropertyByQueryName("cmis:contentStreamLength").getFirstValue()); CmisObject object = this.openCMISSession.getObject(qr.getPropertyByQueryName("cmis:objectId").getFirstValue().toString());
public void runFolderQuery(Session session, Folder testFolder) { if (!Boolean.TRUE.equals(testFolder.getType().isQueryable())) { addResult(createResult(SKIPPED, "Folder type '" + testFolder.getType().getId() + "' is not queryable. Folder query test skipped!")); return; } CmisTestResult f; QueryStatement[] statements = new QueryStatement[] { session.createQueryStatement("SELECT * FROM ? WHERE ? = ?"), session.createQueryStatement("SELECT * FROM ? WHERE ? IN (?)") }; for (QueryStatement statement : statements) { statement.setType(1, testFolder.getType()); statement.setProperty(2, testFolder.getType().getPropertyDefinitions().get(PropertyIds.OBJECT_ID)); statement.setString(3, testFolder.getId()); addResult(createInfoResult("Folder query: " + statement.toQueryString())); int count = 0; for (QueryResult qr : statement.query(false)) { count++; String objectId = qr.getPropertyValueByQueryName("cmis:objectId"); f = createResult(FAILURE, "Folder query returned unexpected object. Id: " + objectId); addResult(assertEquals(testFolder.getId(), objectId, null, f)); } f = createResult(FAILURE, "Folder query should return exactly one hit, but returned " + count + "."); addResult(assertEquals(1, count, null, f)); } }
String objectId = (String) qr.getPropertyByQueryName(objectIdQueryName).getFirstValue();
count++; String objectId = qr.getPropertyValueByQueryName("cmis:objectId");
count++; String folderName = qr.getPropertyValueByQueryName("folderName"); String folderId = qr.getPropertyValueByQueryName("folderId");