cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve Content via Web Service API

gis-olli
Champ in-the-making
Champ in-the-making
Hello, i have a question in context to the Web Service API. I have added some properties to the content model. Now i search for this properties with a java client, using the API, e.g.:

Query query1 = new Query(Constants.QUERY_LANG_LUCENE, "+@\\{http\\://www.alfresco.org/model/content/1.0\\}MyProperty1:\'Value1\" AND +@\\{http\\://www.alfresco.org/model/content/1.0\\}MyProperty2:\'Value2\" AND (TYPE:\"{http://www.alfresco.org/model/content/1.0}content\")");

QueryResult queryResult = repositoryService.query(STORE, query1, true);

This query is ok, i get some Results. Now my Question, how can i get this documents, my query returns? I used the code examples from the Web Service API:

// Display the results
ResultSet resultSet = queryResult.getResultSet();
ResultSetRow[] rows = resultSet.getRows();
if (rows == null)
{
System.out.println("No query results found.");
}
else
{
System.out.println("Results from query:");
outputResultSet(rows);

// Get the id of the first result
String firstResultId = rows[0].getNode().getId();
Reference reference = new Reference(STORE, firstResultId, null);

// Get the parent(s) of the first result
QueryResult parentQueryResult = repositoryService.queryParents(reference);

// Get the parent of the first result
ResultSet parentResultSet = parentQueryResult.getResultSet();
ResultSetRow[] parentRows = parentResultSet.getRows();
if (parentRows == null)
{
System.out.println("No query results found.");
}
else
{
System.out.println("Results from parent query:");
outputResultSet(parentRows);

// Return the first parent (we can use in other samples)
String firstParentId = parentRows[0].getNode().getId();
parentReference = new Reference(STORE, firstParentId, null);
}
}

Can i get the Documents as java file objects or something else? Can anyone post an example?  Thx …
3 REPLIES 3

robertoroberto
Champ in-the-making
Champ in-the-making
I have the same problem…Can anyone post a sample code?

llin
Champ in-the-making
Champ in-the-making
Here is my way:


for(ResultSetRow row : rows) {
    String nodeId = row.getNode().getId();
    Reference reference = new Reference(LilacConstants.STORE, nodeId, null);
    Predicate predicate = new Predicate(new Reference[]{reference}, null, null);
               
    LilacDoc contentResult = new LilacDoc();
    contentResult.setId(nodeId);
               
    // Use the content service to figure out the URL
    ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
    Content[] readResult = contentService.read(predicate, Constants.PROP_CONTENT);
    Content content = readResult[0];
    contentResult.setUrl(content.getUrl() + "?ticket=" + AuthenticationUtils.getTicket());

……

Check JavaDoc for ContentServiceSoapBindingStub. "content.getUrl()" is the link to the file. Please note that some classes here are defined in my application. Don't worry about those.

robertoroberto
Champ in-the-making
Champ in-the-making
After this, How can get the file and copy on a folder x on my hard disk ?