cancel
Showing results for 
Search instead for 
Did you mean: 

Using 'import' clause within a webscript controller in a jar

franco_valente
Champ in-the-making
Champ in-the-making
Hi,
I want to override existing web-tier scripts "/components/workflow/start" and package it into a jar extension.
I modified the workflow.lib.js library included in the controller start-workflow.get.js:
<import resource="classpath:alfresco/site-webscripts/org/alfresco/components/workflow/workflow.lib.js">
model.workflowDefinitions = getWorkflowDefinitions();
I have this file structure that I create a jar from:
alfresco/web-extension/site-webscripts/org/alfresco/components/workflow/workflow.lib.js
META-INF/share-config-custom.xml

Packaging this into a jar, the resource workflow.lib.js is not imported (the original file is taken instead). Why?
Does the "classpath" in the javascript controller not refers to jar resources?

I also tried overriding start-workflow.get.js and generated a jar with this file structure:
alfresco/web-extension/site-webscripts/org/alfresco/components/workflow/workflow.lib.js
alfresco/web-extension/site-webscripts/org/alfresco/components/workflow/start-workflow.get.js
META-INF/share-config-custom.xml

.. but nothing!

I tried to import another js file too..:
<import resource="classpath:alfresco/site-webscripts/org/alfresco/components/workflow/custom-workflow.lib.js">
model.workflowDefinitions = getWorkflowDefinitions();
jar structure:
alfresco/web-extension/site-webscripts/org/alfresco/components/workflow/custom-workflow.lib.js
alfresco/web-extension/site-webscripts/org/alfresco/components/workflow/start-workflow.get.js
META-INF/share-config-custom.xml

But this generated a NullPointerException…

Obviously the workaround was to include all the library code into the start-workflow.get.js file, removing the "import" clause, but… that was not very nice!

Any advice?
2 REPLIES 2

franco_valente
Champ in-the-making
Champ in-the-making
Am I missing something? Or this kind of extension must be packaged as an amp only?

erikwinlof
Confirmed Champ
Confirmed Champ
No an amp isn't necessary, a jar should be fine.

If you look closer at the import statement you can see that it doesn't include the "web-extension" in the path, therefor you must place your file in:
alfresco/site-webscripts/org/alfresco/components/workflow/workflow.lib.js
instead of
alfresco/web-extension/site-webscripts/org/alfresco/components/workflow/workflow.lib.js

If you were running 4.0 you could probably have used the new extensibility features, meaning you could invoke your own custom .get.js file after the original webscripts have executed. This gives you a chance of modifying the "model" before the templates are executed. You can read more about this here:
http://blogs.alfresco.com/wp/ddraper/2011/08/05/customizing-alfresco-share-javascript-controllers/

But since it seems you're running 3.4 you should go with overriding .lib.js as above.

Cheers,

:: Erik