cancel
Showing results for 
Search instead for 
Did you mean: 

Access a lightWeightVersionStore node given a noderef

rmills
Champ in-the-making
Champ in-the-making
I'm trying to update the audit trail to preserve information from a Sharepoint to Alfresco migration.  We have a NodeRef in our webscript that points to a version in the lightWeightVersionStore.  But how do we access the node in the lightWeightVersionStore from the webscript to update the created by and date properties?
4 REPLIES 4

tommorris
Champ in-the-making
Champ in-the-making
I'm not sure if this is helpful, but have you considered using Java-Backed webscripts?
I prefer to use javascript webscripts but find that sooner or later I need to resort the features of the full Java API.
For example, you could use org.alfresco.service.cmr.repository.NodeService to get the details of a node from any store,
including lightWeightVersionStore (and then possibly use setProperty(NodeRef nodeRef, QName qname, java.io.Serializable value) to set some properties…).
Tom
http://www.ixxus.com

rmills
Champ in-the-making
Champ in-the-making
Thanks Tom.  That's something that's definitely been proposed, but we're trying to keep consistent with our approach.  What we had been doing was getting access to the NodeService in javascript somehow and getting a Java NodeRef to the version that we wanted to update in javascript.  In the end, we found a way to search on and access nodes in the lightWeightVersionStore in javascript webscripts.

The root variable search is available in all javascript webscripts to access the search api: http://wiki.alfresco.com/wiki/JavaScript_API#Search_API.  Well, what's failed to be mentioned is that the search is scoped only to workspace://SpacesStore.  Well, if you check out the script-services-context.xml there's a bean IDed as "searchScript":
<bean id="searchScript" parent="baseJavaScriptExtension" class="org.alfresco.repo.jscript.Search">
        <property name="extensionName">
            <value>search</value>
        </property>       
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
        <property name="storeUrl">
            <value>${spaces.store}</value>
        </property>
    </bean>
(spaces.store is defined in repository.properties as workspace://SpacesStore)

If you create a custom context file (ours is script-services-custom-context.xml) and put in it the extensions directory, you can create you own bean exactly as above:
<bean id="searchScriptVersionStore" parent="baseJavaScriptExtension" class="org.alfresco.repo.jscript.Search">
      <property name="extensionName">
         <value>searchVersionStore</value>
      </property>       
      <property name="serviceRegistry">
         <ref bean="ServiceRegistry"/>
      </property>
      <property name="storeUrl">
         <value>workspace://lightWeightVersionStore</value>
      </property>
   </bean>
As you can see, all we did was change the bean id, extensionName property (which is the variable in javascript), and the storeUrl (which we scope to our lightWeightVersionStore).  Then in our webscript:
var versionnode = searchVersionStore.findNode("workspace://lightWeightVersionStore/" + uuid );
worked like a charm.

tommorris
Champ in-the-making
Champ in-the-making
Hey. Now that's useful to know.
Thank you.

alr
Champ in-the-making
Champ in-the-making
Hello everyone,

can this cool feature also be applied to template-services-context.xml file, so that you can use the lightWeightVersionStore in Freemarker Templates as well? It would be so easy to access one's whole versioned content.

I've played a little bit around (like putting the code snippet into the templates-config-context.xml file, but always had an error that my defined variable is not available when executing the freemarker template via the TemplateContentServlet). Also using the same code which is used for ${spaces.store} (the normal workspaces spacesstore) in the template-services-context.xml did not work (where can I increase the debug output?).

Thanks for the Help!


–Alexander