cancel
Showing results for 
Search instead for 
Did you mean: 

Help extending the 'People' Javascript API in 2.1.

chrisb
Champ in-the-making
Champ in-the-making
I am currently trying to add some extra functionality to the People Javascript API functionality.

My new functionality will most likely just consist of new methods for creating alfresco users using the Java API calls (I already have some code to do this).

I just wanted to clarify a few things in terms of the best approach for the organisation and deployment of the new functionality, especially bearing in mind these features may be added to the Javascript API anyway at a later date?

I am planning to create a new POJO class (PeopleUtils?) under the org.alfresco.repo.jscript package, using the skeleton of the current People.java as a starting point and adding the methods I need.

What is the best way to build / structure the new class for ease of deployment and modularity? Can I build the class and config files into a separate WAR file and deploy as an extension, or would I have to rebuild Alfresco to add in my extra Javascript functionality?

The wiki briefly mentions a new extension mechanism for additions to the Javascript API available for this as of 2.0, but doesn't go into much detail. It also gives the ScriptLogger as an example and suggests extending from org.alfresco.repo.jscript.BaseScriptImplementation. However in the 2.1.0 HEAD the ScriptLogger class extends BaseProcessorExtension?

I'll admit I am not a Spring / JavaBeans expert by any means so feel free to let me know if I am missing something obvious  Smiley Happy . Just after some advice and details on how to structure things to avoid a lot of rework later!

Thanks.
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
The future-proof mechanism is to build a JavaScript extension as mentioned in the wiki. The problem you have correctly spotted is that this interface has changed between 2.0 and 2.1. In Alfresco 2.1 we now support multiple script and template engines (i.e. PHP in the java VM!) which also meant that the extension mechanism for the scripting engine was refactored. The end result is that if you write JavaScript extension class in 2.0 it will need to be changed to extend BaseProcessorExtension in 2.1. It's not a big change, but I understand it is annoying if you have already started so sorry about that in advance Smiley Happy

If you create your class, then you use Spring to configure it in as mentioned in the Wiki - you should be able to deloy it as usual as an Alfresco jar extension rather than adding it directly to the Alfresco WAR - as you can use the Spring override config mechanism. When 2.1 is release you will have to change it slightly as mentioned above.

Hope this helps,

Kevin

chrisb
Champ in-the-making
Champ in-the-making
Hi Kevin,

Thats really useful info, and should allow me to get on with my development.

Thanks.

chrisb
Champ in-the-making
Champ in-the-making
OK, I think I am close to getting this up and running (fingers crossed!).

Just a question on using the Spring bean config override and where it should reside? Am I right in thinking my override should be in the following file:

/etc/alfresco/config/more-config.xml

With an import added to the following file to include the above file:

<extension>/alfresco/extension/custom-services-context.xml

bean config I plan to use is:


<bean id="peopleUtilsScript" parent="baseJavascriptExtension" class="org.alfresco.repo.jscript.PeopleUtils">
  <property name="extensionName">
    <value>peopleutils</value>
  </property>
  <property name="serviceRegistry">
    <ref bean="ServiceRegistry" />
  </property>
</bean>

Code for the creation of the Person object is in a war file to be deployed in the extension area of my alfresco install.

Thanks

kevinr
Star Contributor
Star Contributor
Yes i believe that is the correct config setup for adding the bean def.

Thanks,

Kevin