我尝试创建一种行为,在点击Alfresco新用户页面中的“创建用户”按钮后,最终会发送自动生成的邮件。 有人可以指导如何进行此操作吗?之前我创建了一个规则,每当我发送新用户时都会调用该规则。此规则用于管理使用新用户名和密码发送自动生成的邮件。
虽然这几乎正常,但根据用户的说法,这是一个临时解决方案。所以现在我必须创建自动生成邮件的行为。 请指导我..
package com.autoMailgenerate;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CreateUserHandler {
private static Logger logger = LoggerFactory.getLogger(CreateUserHandler.class);
private PolicyComponent eventManager;
private ServiceRegistry serviceRegistry;
public void setServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
public void setPolicyComponent(PolicyComponent policyComponent) {
this.eventManager = policyComponent;
}
public void registerEventHandlers() {
eventManager.bindClassBehaviour(
NodeServicePolicies.OnCreateNodePolicy.QNAME,
ContentModel.TYPE_CONTENT,
new JavaBehaviour(this, "onaddUser",
Behaviour.NotificationFrequency.TRANSACTION_COMMIT));
}
public void onaddUser(ChildAssociationRef parentChildAssocRef) {
NodeRef parentFolderRef = parentChildAssocRef.getParentRef();
NodeRef newuserRef = parentChildAssocRef.getChildRef();
// Check if node exists, might be moved, or created and deleted in same transaction.
/* if (newuserRef == null || !serviceRegistry.getNodeService().exists(newuserRef)) {
// Does not exist, nothing to do
logger.warn("onaddUser: A new user was added but removed in same transaction");
return;
} else {
logger.info("onaddUser: A new user with ref ({}) was just created in folder ({})",
newuserRef, parentFolderRef);
}*/
try {
if (!parentFolderRef.equals("/Repository/User Homes")) {
throw new AlfrescoRuntimeException("onaddUser: A new user was added but removed in same transaction");
}
} finally {
if (logger.isDebugEnabled())
logger.debug("onaddUser: A new user with ref ({}) was just created in folder ({})",
newuserRef, parentFolderRef);
System.out.println("Creation of user"+newuserRef);
}
}
}
也创建了一个bean ......
<bean id="com.autoMailgenerate.createUserHandler"
class="com.autoMailgenerate.CreateUserHandler" init-method="registerEventHandlers">
<property name="policyComponent">
<ref bean="policyComponent" />
</property>
<property name="serviceRegistry">
<ref bean="ServiceRegistry" />
</property>
</bean>