AnsweredAssumed Answered

Getting the Node Data???

Question asked by peterstb on Aug 21, 2009
Latest reply on Oct 4, 2009 by pmonks
Hi Folks,

I'm a newbie to Alfresco, and am really struggling with how to extract the content of a repository node, for presentation in a web service client. 

From the Alfresco Web Client, I added a new piece of content (plain text), called "MyContent", with the value "This is my content in the repository".  Now, from a web service client, I want to query for "MyContent" and be able to present the value…

I can get to the node, and can view the details of the node, including the UUID and the contenturl, consisting of the encrypted binary file name, but can't figure out how to actually extract the value from that node.

I have searched many threads and have tried inserting pieces of code from many of the examples out there, but I always seem to be missing one piece or another.  Here is some of the basic code I have been playing around with:

RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService("http://localhost:8080/alfresco/api");  

Query query = new Query(Constants.QUERY_LANG_LUCENE, "@cm\\:name:'MyContent'");
QueryResult queryResult = repositoryService.query(STORE, query, false);

// Display the results
ResultSet resultSet = queryResult.getResultSet();
ResultSetRow[] rows = resultSet.getRows();
if (rows == null)
     System.out.println("No query results found.");
else {
     for (ResultSetRow row : rows) {
          System.out.println("UID: "+ row.getNode().getId());
          System.out.println("Type: "+ row.getNode().getType());
          NamedValue[] values = row.getColumns();
          System.out.println("Properties: ");
          for (NamedValue col : values) {
               System.out.println("\tName: " + col.getName());
               System.out.println("\tValue: " + col.getValue());

     String firstResultId = rows[0].getNode().getId();
     Reference reference = new Reference(STORE, firstResultId, null);
     Node[] a = repositoryService.get(new Predicate(new Reference[]{reference}, STORE, null));
     for(int i=0;i<a[0].getProperties().length;i++) {

I have also found the following sample code that seems to get me closer, using NodeRef and NodeService classes, but I just don't understand enough about how the API works to tie it all together (Don't have a ServiceRegistry object to pass in)

private static ContentData getContentData(ServiceRegistry registry, String nodeId, StoreRef storeRef) {
     NodeRef nodeRef = new NodeRef(storeRef, nodeId);
     // retrieve the Content Property (represented as a ContentData object in Alfresco)
     NodeService nodeService = registry.getNodeService();
     return (ContentData)nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);

I know how to get the Node Id, and figured out how to get the StoreRef, through the following code:
StoreRef storeRef = new StoreRef(STORE.getScheme(), STORE.getAddress());

I just can't seem to get all of the pieces to fit.

Does anyone have a simple example to share?  I haven't even scratched the surface of what I would like to be able to do, through the web services API, but would feel a whole lot better, if I could simply display a piece of content, based on a simple lookup.

Any assistance will be greatly appreciated!

Best Regards,
Todd Peterson