09-29-2010 11:39 AM
public Reference searchByPathAndFileName(String xpath, String filename) throws Exception{
log.info("start call to AlfrescoSearch.searchByPathAndFileName");
Reference ref = null;
if(!xpath.endsWith("/")) {
xpath = xpath.concat("/");
}
String queryString = "+@cm\\:name:\"" + filename + "\" +PATH:\""+ xpath + "*\"";
log.info("queryString: " + queryString);
getQueryResults(queryString);
Query query = new Query(Constants.QUERY_LANG_LUCENE, queryString);
/* Execute the query */
QueryResult queryResult = WebServiceFactory.getRepositoryService().query(getStoreRef(), query, false);
/* Display the results */
ResultSet resultSet = queryResult.getResultSet();
ResultSetRow[] rows = resultSet.getRows();
if (rows != null) {
/* Get the infomation from the result set */
Map<String, String> namedValuesMap = null;
for(ResultSetRow row : rows) {
String nodeId = row.getNode().getId();
log.info("nodeId of the file found: " + nodeId);
ref = new Reference(getStoreRef(), nodeId, null);
// ContentResult contentResult = new ContentResult(nodeId);
NamedValue[] namedValues = row.getColumns();
log.info("number of properties: " + namedValues.length);
namedValuesMap = new HashMap<String, String>();
// iterate through the columns of the result set to extract specific named values
for (NamedValue namedValue : namedValues) {
log.debug("named value property: " + namedValue.getName());
log.debug("named value value: " + namedValue.getValue());
namedValuesMap.put(namedValue.getName(), namedValue.getValue());
}
} //next row
String name = namedValuesMap.get("{http://www.alfresco.org/model/content/1.0}name");
log.info("Got file name: " + name);
String uuid = namedValuesMap.get("{http://www.alfresco.org/model/system/1.0}node-uuid");
log.info("Got file uuid: " + uuid);
String versionable = namedValuesMap.get("{http://www.alfresco.org/model/content/1.0}versionable");
log.info("Got versionable: " + versionable);
} // end if
log.info("done call to AlfrescoSearch.searchByPathAndFileName");
return ref;
}
public Reference searchByPath(String xpath) throws Exception {
Reference ref = null;
if(!xpath.endsWith("/")){
xpath = xpath.concat("/");
}
String queryString = "+PATH:\"/app:company_home/st:sites/cm:CostAllocation/cm:documentLibrary/*\"";
Query query = new Query(Constants.QUERY_LANG_LUCENE, queryString);
/* Execute the query */
QueryResult queryResult = WebServiceFactory.getRepositoryService().query(getStoreRef(), query, false);
/* Display the results */
ResultSet resultSet = queryResult.getResultSet();
ResultSetRow[] rows = resultSet.getRows();
if (rows != null) {
/* Get the infomation from the result set */
Map<String, String> namedValuesMap = null;
for(ResultSetRow row : rows) {
String nodeId = row.getNode().getId();
ref = new Reference(getStoreRef(), nodeId, null);
NamedValue[] namedValues = row.getColumns();
namedValuesMap = new HashMap<String, String>();
// iterate through the columns of the result set to extract specific named values
for (NamedValue namedValue : namedValues) {
namedValuesMap.put(namedValue.getName(), namedValue.getValue());
}
String path = namedValuesMap.get("{http://www.alfresco.org/model/content/1.0}path");
path = path.replace("/{http://www.alfresco.org/model/application/1.0}", "/app:");
path = path.replace("/{http://www.alfresco.org/model/site/1.0}", "/st:");
path = path.replace("/{http://www.alfresco.org/model/content/1.0}", "/cm:");
log.info("path: " + path);
} //next row
} // end if
return ref;
}
private List<ContentResult> getQueryResults(String queryString) throws Exception {
log.info("Query:" + queryString);
List<ContentResult> results = new ArrayList<ContentResult>();
Query query = new Query(Constants.QUERY_LANG_LUCENE, queryString);
// Execute the query
QueryResult queryResult = WebServiceFactory.getRepositoryService().query(getStoreRef(), query, false);
// Display the results
ResultSet resultSet = queryResult.getResultSet();
ResultSetRow[] rows = resultSet.getRows();
if (rows != null) {
// Get the infomation from the result set
for(ResultSetRow row : rows) {
String nodeId = row.getNode().getId();
ContentResult contentResult = new ContentResult(nodeId);
NamedValue[] namedValues = row.getColumns();
log.info("number of properties: " + namedValues.length);
Map<String, String> namedValuesMap = new HashMap<String, String>();
// iterate through the columns of the result set to extract specific named values
for (NamedValue namedValue : namedValues) {
log.debug("named value property: " + namedValue.getName());
namedValuesMap.put(namedValue.getName(), namedValue.getValue());
}
String uuid = namedValuesMap.get("{http://www.alfresco.org/model/system/1.0}node-uuid");
log.info("Got file uuid: " + uuid);
if(uuid != null){
}
// Use the content service to figure out the URL
Content[] readResult = WebServiceFactory.getContentService().read(new Predicate(new Reference[]{new Reference(getStoreRef(), nodeId, null)}, getStoreRef(), null), Constants.PROP_CONTENT);
Content content = readResult[0];
contentResult.setUrl(content.getUrl());
results.add(contentResult);
} //next row
} // end if
return results;
}
public Store getStoreRef() {
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
return storeRef;
}
04-21-2014 06:12 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.