Hi There,
I would like to add a computed group to a workspace at creation.
I understand that I need to create an eventListener for this for the event documentCreated:
<?xml version="1.0"?>
<component name="WorkspaceCreationListener">
<extension target="org.nuxeo.ecm.core.event.EventServiceComponent" point="listener">
<listener name="documentCreated" async="false" postCommit="false" priority="120"
class="WorkspaceCreationListener">
</listener>
</extension>
</component>
My Listener class looks like this:
public class WorkspaceCreationListener implements EventListener {
private static final String TENANT_GROUP_PREFIX = "tenant-" ;
private static final String TENANT_ADMINISTRATORS_GROUP_SUFFIX = "_tenantAdministrators";
private CoreSession session;
@Override
public void handleEvent(Event event) throws ClientException {
EventContext ctx = event.getContext();
if (ctx != null)
session = ctx.getCoreSession();
if (!(ctx instanceof DocumentEventContext)) {
return;
}
DocumentModel doc = ((DocumentEventContext) ctx).getSourceDocument();
if (doc == null) {
return;
}
if (doc.getType().equals("Workspace")){
String tenantId = ((NuxeoPrincipal) ctx.getPrincipal()).getTenantId();
process(doc,ctx.getPrincipal().toString(),tenantId);
}
}
public void process(DocumentModel doc, String userId, String tenantId) throws ClientException {
setACEs(doc,userId);
setACEs(doc,computeTenantAdministratorsGroup(tenantId));
/* doc.setPropertyValue("creator", emet); perhap to position, i'm not enough sure */
}
public static String computeTenantAdministratorsGroup(String tenantId) {
return TENANT_GROUP_PREFIX + tenantId
+ TENANT_ADMINISTRATORS_GROUP_SUFFIX;
}
private void setACEs(DocumentModel doc, String userId) throws ClientException {
ACP acp = doc.getACP();
ACL acl = acp.getOrCreateACL();
int WorkspaceAdminACEIndex = acl.indexOf(new ACE(userId, SecurityConstants.EVERYTHING, true));
if (WorkspaceAdminACEIndex == -1) {
ACE ace = new ACE(userId, SecurityConstants.EVERYTHING, true);
acl.add(0,ace);
acp.addACL(acl);
doc.setACP(acp, true);
}
session.saveDocument(doc);
session.save();
}
}
However It seems like I'm getting an infinite loop.
Any ideas on this?
Thanks,
Bauke Roo