Fix so that Project Space policy code is moved to emailserver:aliasable onAddAspect - fixes 2 bugs and allows creation of project from any Project template

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7876 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2008-01-08 19:16:24 +00:00
parent c1fa7ba626
commit ace73cf22c
3 changed files with 30 additions and 43 deletions

View File

@@ -0,0 +1,25 @@
logger.log("onAddAspect policy code for emailserver:aliasable");
var emailfolder = behaviour.args[0];
// search for an app:projectfolder parent node
var parent = emailfolder.parent;
while (parent != null && parent.hasPermission("Read"))
{
if (parent.type == "{http://www.alfresco.org/model/application/1.0}projectfolder")
{
logger.log("Found parent app:project folder: " + parent.name);
var alias = normalise(parent.name);
parent.properties["emailserver:alias"] = alias;
parent.save();
logger.log("Applied email alias of: " + alias);
break;
}
parent = parent.parent;
}
function normalise(s)
{
// email alias has strict constraint
return new String(s).toLowerCase().replace(/[^a-z^0-9^.]/g, "-");
}

View File

@@ -1,39 +0,0 @@
// onCreateNode policy code for app:projectfolder
logger.log("onCreateNode policy code for app:projectfolder");
var project = behaviour.args[0].child;
if (project.children.length == 0)
{
// perform deep copy of Project template contents into this node
var templates = search.luceneSearch("+PATH:\"/app:company_home/app:dictionary/app:space_templates/*\" +TYPE:\"{http://www.alfresco.org/model/application/1.0}projectfolder\"");
if (templates.length == 0)
{
logger.log("No app:project templates found to copy!");
}
else
{
logger.log("Copying app:project template into new project...");
for each (var child in templates[0].children)
{
child.copy(project, true);
}
// search for the email archive child folder
var results = search.luceneSearch("+PATH:\"" + project.qnamePath + "/*\" +ASPECT:\"{http://www.alfresco.org/model/emailserver/1.0}aliasable\"");
if (results.length == 1)
{
results[0].properties["emailserver:alias"] = normalise(project.name);
results[0].save();
logger.log("Applied email alias of: " + normalise(project.name));
}
else
{
logger.log("No email archive folder found!");
}
}
}
function normalise(s)
{
// email alias has strict constraint
return new String(s).toLowerCase().replace(/[^a-z^0-9^.]/g, "-");
}

View File

@@ -4,19 +4,20 @@
<!-- Project bean definitions -->
<beans>
<!-- Project behaviour registration -->
<bean id="app_projectfolder_onCreateNode" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
<bean id="emailserver_aliasable_onAddAspect" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
<property name="policyName">
<value>{http://www.alfresco.org}onCreateNode</value>
<value>{http://www.alfresco.org}onAddAspect</value>
</property>
<property name="className">
<value>{http://www.alfresco.org/model/application/1.0}projectfolder</value>
<value>{http://www.alfresco.org/model/emailserver/1.0}aliasable</value>
</property>
<property name="behaviour">
<bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour">
<property name="notificationFrequency"><value>TRANSACTION_COMMIT</value></property>
<property name="location">
<bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
<constructor-arg>
<value>alfresco/module/projects/script/onCreateNode_app_projectfolder.js</value>
<value>alfresco/module/projects/script/onAddAspect_emailserver_aliasable.js</value>
</constructor-arg>
</bean>
</property>