cancel
Showing results for 
Search instead for 
Did you mean: 

send email to space users

tico
Champ in-the-making
Champ in-the-making
Hi all,

I'd like to create an action which sends an email to space users… I dont want to select recipients as the existing 'Email space users' does. The goal is to send an email when content is dropped in a space. Recipients is automaticaly updated following space users. That means if the action is associated with an other space, recipients could be not the same.

I had a look to http://wiki.alfresco.com/wiki/JavaScript_API#ScriptAction_API, and I believe its not far from what I'm expecting… Unfortunately, I have no idea how to retrieve space users.

Any help would be welcome.

Thanks

Eric.
6 REPLIES 6

kevinr
Star Contributor
Star Contributor
The API to retrieve the full set of permissions applied to a Node is not available in JavaScript yet. I have added a JIRA item for it for 2.1:
http://issues.alfresco.com/browse/AR-1346

Currently you can use the People API from JavaScript to retrieve the person members of a Group and you can get each email address from 'cm:email' property the person nodes it returns - so half what you need is there already, but you need the API I mention above to find out what users/groups are assigned to a node in the first place.

Thanks,

Kevin

tico
Champ in-the-making
Champ in-the-making
Thanks Kevin

I'll investigate further… i'll keep this thread up2date.

Eric.

flyer
Champ in-the-making
Champ in-the-making
I whish to do the same.

I've noticed that we can add custom javascript method:
http://wiki.alfresco.com/wiki/JavaScript_API#Adding_custom_Script_APIs
Perhaps somebody has already made this job but I cannot find it. I will try to do it instead of waiting for 2.1 (or later) but I'm not a java expert.

You can notice that this feature is already available in template (freemarker):
http://wiki.alfresco.com/wiki/Template
into space.permissions object.

kevinr
Star Contributor
Star Contributor
Yes for now (pre 2.1) you could add a custom javascript object that performs the same functionality and call that from your script.

The API (now complete and in HEAD) for 2.1 will be exactly the same as the FreeMarker one for this.

Thanks,

Kevin

flyer
Champ in-the-making
Champ in-the-making
I've tried this code:

package perext;

import java.util.Set;

import org.alfresco.repo.jscript.BaseScriptImplementation;
import org.alfresco.repo.jscript.Node;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;

public class Perext extends BaseScriptImplementation {

    /**
     * @return Array of permissions applied to this Node.
     * Strings returned are of the format [ALLOWED|DENIED];[USERNAME|GROUPNAME];PERMISSION for example
     * ALLOWED;kevinr;Consumer so can be easily tokenized on the ';' character.
     */
    public String[] getPermissions(Node node)
    {
        // initialise app content
        ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
        // get registry of services
        ServiceRegistry services = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
   
        String userName = services.getAuthenticationService().getCurrentUserName();
        Set<AccessPermission> acls = services.getPermissionService().getAllSetPermissions(node.getNodeRef());
        String[] permissions = new String[acls.size()];
        int count = 0;
        for (AccessPermission permission : acls)
        {
            StringBuilder buf = new StringBuilder(64);
            buf.append(permission.getAccessStatus())
                .append(';')
                .append(permission.getAuthority())
                .append(';')
                .append(permission.getPermission());
            permissions[count++] = buf.toString();
        }
        return permissions;
    }

}

I've added this to webapps/alfresco/WEB-INF/classes/alfresco/script-services-context.xml:

    <bean id="perextScript" parent="baseScriptImplementation" class="perext.Perext">
        <property name="scriptName">
            <value>perext</value>
        </property>
    </bean>

And the jar file containing perext.class into webapps/alfresco/WEB-INF/lib.

but I've got:

21:30:09,514 ERROR [hibernate.engine.ActionQueue] could not release a cache lock
org.hibernate.cache.CacheException: java.lang.IllegalStateException: The org.hibernate.cache.UpdateTimestampsCache Cache is not alive.
…(snip)…
21:30:09,598 ERROR [util.transaction.SpringAwareUserTransaction] Transaction didn't commit
org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/8558e240-d8b0-11db-88a6-67c46e9dea50': Wrapped org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverConnector' defined in class path resource [alfresco/core-services-context.xml]: Initialization of bean failed; nested exception is java.io.IOException: Cannot bind to URL [rmi://localhost:50500/alfresco/jmxrmi]: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi] (AlfrescoScript#12)
        at org.alfresco.repo.jscript.RhinoScriptService.executeScript(RhinoScriptService.java:168)
…(snip)…
21:30:15,763 ERROR [quartz.core.JobRunShell] Job DEFAULT.org.springframework.scheduling.quartz.JobDetailBean#1e3bbd7 threw an unhandled Exception:
java.lang.IllegalStateException: The org.alfresco.repo.domain.hibernate.TransactionImpl Cache is not alive.
21:30:15,766 ERROR [quartz.core.ErrorLogger] Job (DEFAULT.org.springframework.scheduling.quartz.JobDetailBean#1e3bbd7 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.IllegalStateException: The org.alfresco.repo.domain.hibernate.TransactionImpl Cache is not alive.]
        at org.quartz.core.JobRunShell.run(JobRunShell.java:213)

Any Idea ?

kevinr
Star Contributor
Star Contributor
The problem is the use of the 'services' object here:

// initialise app content
        ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
        // get registry of services
        ServiceRegistry services = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);

You cannot have more than one Spring app context in the application, instead look at the examples we have we use configuration to inject the required service objects into the bean. So for example the code for the script helper class:
org.alfresco.repo.jscript.ScriptUtils
uses the ServiceRegistry object. It has a setter method for it:

    /**
     * Sets the service registry
     *
     * @param services  the service registry
     */
    public void setServiceRegistry(ServiceRegistry services)
    {
        this.services = services;
    }
and the configuration sets via spring thus:

    <bean id="utilsScript" parent="baseScriptImplementation" class="org.alfresco.repo.jscript.ScriptUtils">
        <property name="scriptName">
            <value>utils</value>
        </property>
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
    </bean>

Note that property for 'serviceRegistry'. Follow the same pattern for your script class and it will work.

Thanks,

Kevin