cancel
Showing results for 
Search instead for 
Did you mean: 

Web Script AMP

cgonzalez
Champ on-the-rise
Champ on-the-rise
Hello.

It is posible to include Web Scripts in an AMP file.


If it's posible, how should i do this?

Thanks
13 REPLIES 13

jbarmash
Champ in-the-making
Champ in-the-making
Yes, it's very possible.   As part of the AMP file, you can add bootstrapping information, i.e. which content is to be added to Alfresco.  You can thus add webscripts to Alfresco content directories.  I wouldn't be surprised if there are examples on the forge, or you can check out how record management module handles bootstrapping - it uploads some JavaScript sciprts into Script directory, and also some to Presentation Scripts directory. 

http://wiki.alfresco.com/wiki/Bootstrap_Data
http://wiki.alfresco.com/wiki/Data_Dictionary_Guide

http://wiki.alfresco.com/wiki/AMP_Files

cgonzalez
Champ on-the-rise
Champ on-the-rise
Thanks for you reply.


I have readed all the information you posted but i still don't know where to put my web scripts definition in the amp structure. I have readed some examples in this forum ,http://forums.alfresco.com/viewtopic.php?p=21923&sid=8ecabec3aede660f927083d5caa345c7 but i can't get they work.


The record management doesn't seem to have any web script definition inside.

Any tip?

jbarmash
Champ in-the-making
Champ in-the-making
Where you put them in the amp structure does not matter at all. what does matter is how you bootstrap it.  bootstrap code allows you to refer to an xml file which points to how nodes are supposed to be added. 

You can add your information in one of two ways - in an xml file that points to files explicitly, or an ACP file, (which also has an xml file that points to file, it's just easier to generate it through space export).

The easiest way to do this is: 
   1. Put your webscripts into the appropriate directory in data dictionary. 
   2. Delete ALL webscripts OTHER than yours. 
   3. Do an export of the contents of the directory. This will create an ACP file.  Download the ACP file to your desktop and copy it to one of the module directories (e.g. bootstrap).
   4. Create bootstrap-context.xml in context subdirectory of your module, i.e. config\alfresco\module\org.alfresco.module.yourmodule\context\
   5.  In the file, add a bean for bootstrapping, and point it to the acp file: 

   <!– Bootstrap –>
    <bean id="org_alfresco_module_bootstrapSpaces" class="org.alfresco.repo.module.ImporterModuleComponent" parent="module.baseComponent">
        <property name="moduleId" value="org.alfresco.module.yourmodule.project" />
        <property name="name" value="org.alfresco.module.yourmodule.bootstrapSpaces" />
        <property name="description" value="Initial data requirements" />
        <property name="sinceVersion" value="0.4" />
        <property name="appliesFromVersion" value="0.4" />

        <!– Data properties –>
        <property name="importer" ref="spacesBootstrap"/>
        <property name="bootstrapViews">
            <list>
                <props>
                    <prop key="path">/cm:categoryRoot/cm:generalclassifiable</prop>
                    <prop key="location">alfresco/module/org.alfresco.module.yourmodule/bootstrap/rm_categories.xml</prop>
       </props>
            <props>
<props>
                     <prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}/Web Scripts</prop>
                     <prop key="location">alfresco/bootstrap/web_scripts.acp</prop>
                 </props>
            </list>
        </property>
    </bean>

In the snippet above, web_scripts.acp should get exploded to Web Scripts directory (i am not sure about the exact string you should be using there, so you might have to play around with that one). 

After that, you can start testing.  The bootstrap happens when you startup the first time after installing that AMP.  There is no good way to uninstall AMP right now, so for testing purposes, you can delete your db and file store, and recreate it from scratch.  There might be a better way, don't know.

Ok, this should help.  Now I just need to add this to the Wiki….

cgonzalez
Champ on-the-rise
Champ on-the-rise
Thanks so much for your help. But i still can't to deploy my web scripts using an amp file.

This is my amp structure

/
>>config/
>>>>alfresco/
>>>>>>mymodule/
>>>>>>>>context/
>>>>>>>>>>bootstrap-context.xml
>>>>>>>>webscripts/
>>>>>>>>>>webscripts.acp
>>>>>>>>module-context.xml
>>module.properties



This is my bootstrap-context.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
  <bean id="mymodule.bootstrapSpaces" class="org.alfresco.repo.module.ImporterModuleComponent" parent="module.baseComponent">
    <property name="moduleId" value="mymodule" />
    <property name="name" value="mymodule.bootstrap" />
    <property name="description" value="Initial data requirements" />
    <property name="sinceVersion" value="1.0" />
    <property name="appliesFromVersion" value="5.0" />
    <property name="executeOnceOnly" value="false" />
    <!– Data properties –>
    <property name="importer" ref="spacesBootstrap"/>
    <property name="bootstrapViews">
      <list>
        <props>
          <prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}/cm:webscripts</prop>
          <prop key="location">alfresco/module/mymodule/webscripts/webscripts.acp</prop>
        </props>
      </list>
    </property>
  </bean>
</beans>



This is my model-context.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
  <import resource="classpath:alfresco/module/mymodule/context/bootstrap-context.xml" />
</beans>

And this is my model.properties

# MyModule properties
module.id=mymodule
module.version=1.0
module.title=Title of My Module
module.description=Description of my module


Any Tip??

I don't get any error mensage  in the installation of the module. But i don't get the web scripts deployed.


Thanks

jbarmash
Champ in-the-making
Champ in-the-making
As a way to test things out, change cm:webscripts to one of the other locations in Data Dictionary, make sure it loads there.   Then if that works, then the process works, the only problem is how to address the web scripts space, which I am not 100% sure about.   But at least once you convince yourself that the other syntax correctly, then the rest of the problem is more contained.  Please post the syntax if you figure it out.

I just updated this page with some of the other locations:

http://wiki.alfresco.com/wiki/Bootstrap_Data

cgonzalez
Champ on-the-rise
Champ on-the-rise
Hi,

Because there's not good way to uninstall AMP right now and this make not easy testing the bootstrap I have changed the context-model.xml to add a new webscipt.classpathstore as follow.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
  <import resource="classpath:alfresco/module/mymodule/context/bootstrap-context.xml" />
 
  <bean parent="webscripts.classpathstore">
    <property name="classPath"><value>alfresco/module/mymodule/webscripts/</value></property>
  </bean>
   
</beans>

I think this is a better solution than use the bootstrapt. Because you don't have to install over and over again. You just can add an remove web scripts from your amp file.


I hope it helps.

stijndereede
Champ in-the-making
Champ in-the-making
In my AMP (developed as Eclipse project), my webscripts are located at:
"\config\alfresco\templates\webscripts\org\alfresco\module\{module-name}"

When installing the AMP, they are automatically mapped to "\alfresco\templates\webscripts\org\alfresco\module\{module-name}", and there is no need to bootstrap them in an XML file.
As I understood from the documentation on the Wiki this method is recommended.

jbarmash
Champ in-the-making
Champ in-the-making
Yes, this will work fine.  You lose ability to edit it easily going foward, but this doesn't matter once you are done with development.

So probably a good way to do development is the following:

1. Write the web scripts while having them in Data Dictionary \ Web Scripts directory for easy editing / modification (so don't have to restart server).
2. Export them and put it in module, adding a reference to them in you *-context files.

jbarmash
Champ in-the-making
Champ in-the-making
I implemented ability to uninstall AMPs using MMT.  I attached the new code and patch file here:
  http://issues.alfresco.com/browse/AR-1349
and also posted it here:

http://forums.alfresco.com/viewtopic.php?f=10&t=11589