cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the Node Data???

peterstb
Champ in-the-making
Champ in-the-making
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++) {
          if(a[0].getProperties(i).getName().equalsIgnoreCase("{http://www.alfresco.org/model/content/1.0}content"))
               System.out.println(a[0].getProperties(i).getValue());
     }
}

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
9 REPLIES 9

pmonks
Star Contributor
Star Contributor
Have you taken a look at the various example projects included in the SDK?  From memory there are 2 or 3 that demonstrate use of the Web Services (SOAP) API.

Also, you might consider using Web Scripts (http://wiki.alfresco.com/wiki/Web_Scripts) instead - they're more powerful than the SOAP APIs.

Cheers,
Peter

peterstb
Champ in-the-making
Champ in-the-making
Thanks so much for the response!

So, I started taking a look at the Web Scripts, and in theory like the idea of using RESTful services to access the data I need.  I decided to take some baby steps and start with the SimpleWebScript.java program.  Seems pretty straight-forward, although I can't gleen from the documentation where I should be putting the compiled class file SimpleWebScript.class???

There is a note, after the step of "Try running it":
Locations of the files
.jar file in <Alfresco>/tomcat/webapps/alfresco/WEB-INF/lib
web-scripts-application-context.xml - <Alfresco>/tomcat/webapps/alfresco/WEB-INF/classes/alfresco
simple.get.desc.xml  - <Alfresco>/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/demo


Am I supposed to package my class file in a .jar file and put it in the WEB-INF/lib directory, or is it referring to the supporting .jar files for the web scripts and JSON?  Or, both???

I did find the web-scripts-application-context.xml and made the necessary changes, as well as making a simple.get.desc.xml and putting it in my <Alfresco>/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/demo directory…

What is the missing step???

Thanks in advance for any help!

Todd

peterstb
Champ in-the-making
Champ in-the-making
So I've been googling for two days now, and constantly refreshing this post in the hopes that someone might have a link to a "simple" Web Service or WebScript example that works…  I'll settle for anything…  A HelloWorld world would be perfect!

I've been finding many examples out there, but none that seem to describe "step-by-step", how to develop, "deploy", and test a simple example.  The examples I have found seem to be missing some relevant information, such as I described above that prevent me from taking the ball over the goal-line.

I'm starting to wonder if Alfresco is going to be the right tool for us?  It seems like it has taken off very well in the industry, and seems to have a ton of capability.  If I can't get a simple HelloWorld going, to build from, I can't recommend it as a product that might meet the needs of several projects we have, in need of a WCMS solution.

I'm concerned that I'm just not looking in the right places, although the Alfresco Wiki's would presumably bet the best place to be looking???

Is there anyone out there that can point me in the right direction?  I'm boardering on desparate, before I abandon putting any more effort into proving that Alfresco might be a good fit for our company.

Any suggestions are greatly appreciated!

Thanks and best regards,
Todd

mrogers
Star Contributor
Star Contributor
To read the content from Java what you need is a ContentReader.   You can get one from the content service.

http://forums.alfresco.com/en/viewtopic.php?f=4&t=12090

You can also access the content of the nodes remotely by their URLs or through CMIS web scripts or ftp etc, etc.

peterstb
Champ in-the-making
Champ in-the-making
Thanks for the response…  I will definitely look into that, as we are primarily a Java shop.

I've currently shifted my focus to using WebScripts, and am recently (within the last hour) feeling like I'm starting to make a little progress.  I think that 90% of my problem is in understanding what resources (wiki's, tutorials, etc.) to use, and am finding the the version of Alfresco I have installed (3.2 Community) is partly the challenge. 

For example, I've been reading through the WebScripts Wiki at: http://wiki.alfresco.com/wiki/Web_Scripts#Invoking_a_Web_Script   This is where I finally started to make some progress.  I put in a  of URL, got an alf_ticket from my repository, was able to put in another URL (with the alf_ticket as a parm) and was able to see some level of my repository.  I'm thinking sweet!!!  Start diving in a little deeper and navigate from the Wiki to another Wiki at: http://wiki.alfresco.com/wiki/Web_Scripts#Examples_and_Guidelines  Sweet again!!!  Things are looking up for me!  Get to the Examples and Guidelines section and am thinking, ok, I'm not taking any shortcuts!  So, I navigate to the "Web Scripts Examples" Wiki at: http://wiki.alfresco.com/wiki/Web_Scripts_Examples, and none of the "simple" example URL's are working for me.  What's happened is I've navigated (I'm assuming here) to some samples based on Alfresco 2.1 and later (don't know how much "later" means), and the URL structure doesn't seem to match the URL structure of my 3.2 Community edition???

I'll take it on the chin and admit that there's probably a lot of user error, but it's really difficult to get my arms around the technical artifacts, I need, to make the 3.2 Community edition work in my enviornment, without accidentally stumbling onto Wiki's, tutorials, etc., based on previous versions, which may not work for me.

Is anybody else struggling with this?

By the way…  I'm sincerely greatful for the response…  I will definitely be researching further, as that was the inital path I was headed down.  Just needed to vent a little (and not directed at any of the posting responders)

Thanks again!
Todd

pmonks
Star Contributor
Star Contributor
It sounds like you're in a great position to update the wiki with some getting started / guided walk-through type information.  Perhaps you could take advantage of Alfresco's open source nature and contribute what you've learnt back to the community?

Cheers,
Peter

peterstb
Champ in-the-making
Champ in-the-making
Point taken Peter…

When I feel like I have my arms around this a little better, and think I can put something together to contribute I will do so.

Best Regards,
Todd

sgomez
Champ in-the-making
Champ in-the-making
Hi peterstb,

I had a hard time working with the Simple tutorial at http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples as well.  You are right to ask what the jar file was about because that did not help me at all.  What you need to do is move your built classes to Alfresco/WEB-INF/classes.  YOu can ignore the part about the jar file (perhaps someone with more expertise can go into detail how to make it work with the jar file, but I certainly did not need it).  As a side note, you should create a freemarker response file if your java file will not be doing it for you (*.get.json.ftl)

Once that is done and you have the correct description and freemarker files (*.get.desc.xml) as well as added a new bean for it, restart tomcat and you should be good.  It sucks, but you have to restart tomcat whenever you rebuild your files.  Maybe its just my environment, but redeploying alfresco does not reload my new classes.  Anyways, hope that helps you in some way.

pmonks
Star Contributor
Star Contributor
If you're using Tomcat, it's better not to directly manipulate the exploded webapp (anything under ${ALFRESCO_HOME}/tomcat/webapps/alfresco/) since Tomcat will re-explode the alfresco.war file at intervals, removing anything you've put in there manually (and doing so unexpectedly, in all likelihood).

A better option is to package up extensions into one or more AMP files (see http://wiki.alfresco.com/wiki/AMP_Files) then install them using the MMT tool (see http://wiki.alfresco.com/wiki/Module_Management_Tool) or the apply_amps.[bat|sh] script.

Cheers,
Peter