cancel
Showing results for 
Search instead for 
Did you mean: 

[solved]Writing a custom behaviour on user create

zomurn
Champ in-the-making
Champ in-the-making
Hi,

I'am writing a custom behavior after reading the good article named "behavior-article.pdf".
So here is what I want to do :

When the administration create a user, I want to "catch the event" (does it correspond to onCreateStore event ?) so to create automticaly two directories in his home space.

So I declared the bean for spring and wrote a "test" javascript to see if it is called. :

My-model-context.xml

<bean id="onCreateUserStore" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">      <property name="policyName">         <value>{http://www.alfresco.org}onCreateStore</value>      </property>      <property name="className">         <value>{http://www.alfresco.org/model/system/1.0}store_root</value>      </property>      <property name="behaviour">         <bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour">            <property name="location">               <bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">                  <constructor-arg>                     <value>alfresco/extension/scripts/onCreateUser.js</value>                  </constructor-arg>               </bean>            </property>         </bean>      </property>   </bean>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

onCreateUser.js :

logger.log("Start onCreateUser.js…");if (behaviour == null) {   logger.log("The behaviour object has not been set");}//check the name of the behaviourif (behaviour.name == null && behaviour.name != "onCreateStore") {   logger.log("The behaviour name has not been set correctly");}else {   logger.log("Behaviour name: " + behaviour.name);}//check the argumentsif (behaviour.args == null) {   logger.log("The args have not been set");} else {   if (behaviour.args.length == 1) {      var user = behaviour.args[0];      logger.log("init user's workspace");      logger.log("end user's workspace");   }}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I put the log4j for jscript to debug. When this script is run ? To which act the onCreateStore correspond to ? (is it when a new user is added ?)
More generally, to which action are binded the events ?
I'd like to catch the action on user create …

Thanks for your help !
2 REPLIES 2

zomurn
Champ in-the-making
Champ in-the-making
I noticed that the onCreateStore event is launched at the time alfresco is initializing when you do the first deployment….so it is usefull to prepare application environment I think (pre process before login into app)
I outlined the problem simply creating a rule when a folder is created in user's home space (ie, when we defined a new user and specify his home folder name) Smiley Happy.

daniel_gradecak
Confirmed Champ
Confirmed Champ
why don't you just bind your behavior to the type cmSmiley Tongueerson and onCreateNode policy?