1. 程式人生 > >在windchill中如何監聽workItem進行任務郵件定製

在windchill中如何監聽workItem進行任務郵件定製

在windchill定製開發中,有一種場景,需要在定製接收的任務郵件, 但是workitem物件用poststore監聽不到、可以通過監聽的是workitemlink 達到workItem建立時,定製郵件。

package ext.vivo.common.service;

/**
 * @version 1.0 2017-11-6
 * @author weiting
 */
public interface WorkItemListenerService {

}



package ext.vivo.common.service;
/**
 * @version 1.0 2017-11-6
 * @author
weiting */
import java.util.ArrayList; import java.util.List; import javax.mail.internet.InternetAddress; import org.apache.log4j.Logger; import com.elead.core.model.ExtWorkFlowPBO; import com.elead.extwf.docWorkFlow.util.DocWorkflowUtil; import com.elead.util.WfUICommonUtil; import ext.vivo.common.util.MailUtil; import
wt.doc.WTDocument; import wt.events.KeyedEvent; import wt.events.KeyedEventListener; import wt.fc.PersistenceManagerEvent; import wt.httpgw.URLFactory; import wt.log4j.LogR; import wt.org.WTPrincipalReference; import wt.services.ServiceEventListenerAdapter; import wt.services.StandardManager; import
wt.session.SessionHelper; import wt.session.sessionResource; import wt.util.WTException; import wt.workflow.engine.WfProcess; import wt.workflow.work.WfAssignedActivity; import wt.workflow.work.WorkItem; import wt.workflow.work.WorkItemLink; @SuppressWarnings("serial") public class StandardWorkItemListenerService extends StandardManager implements WorkItemListenerService { private static final String CLASSNAME = StandardWorkItemListenerService.class.getName(); private static Logger logger = LogR.getLogger(CLASSNAME); private KeyedEventListener listener = null; public String getConceptualClassname() { return this.CLASSNAME; } public static StandardWorkItemListenerService newStandardWorkItemListenerService() throws WTException { StandardWorkItemListenerService instance = new StandardWorkItemListenerService(); instance.initialize(); return instance; } class WorkItemListener extends ServiceEventListenerAdapter { public WorkItemListener(String manager_name) { super(manager_name); } public void notifyVetoableEvent(Object event) throws Exception { if (!(event instanceof KeyedEvent)) return; KeyedEvent eventObject = (KeyedEvent) event; Object busObject = eventObject.getEventTarget(); String strEventType = eventObject.getEventType(); if ( strEventType.equals(PersistenceManagerEvent.POST_STORE)) { if(busObject instanceof WorkItemLink) { WorkItemLink link=(WorkItemLink) busObject; WorkItem wrkItem= (WorkItem) link.getWorkItem(); if(wrkItem.getPrimaryBusinessObject()!=null) { Object primaryObj=wrkItem.getPrimaryBusinessObject().getObject(); if( primaryObj instanceof ExtWorkFlowPBO) { ExtWorkFlowPBO pbo=(ExtWorkFlowPBO)primaryObj; WTDocument doc=DocWorkflowUtil.getDocByPBO(pbo); String name=doc.getName(); String pboOid=WfUICommonUtil.obj2Oid(pbo); WfAssignedActivity wfactivity=(WfAssignedActivity) wrkItem.getSource().getObject(); WfProcess wfprocess=wfactivity.getParentProcess(); List<InternetAddress> list = new ArrayList<InternetAddress>(); InternetAddress emaiAdress = new InternetAddress(wrkItem.getOwnership().getOwner().getEMail(),wrkItem.getOwnership().getOwner().getEMail()); list.add(emaiAdress); WTPrincipalReference user=SessionHelper.manager.getPrincipalReference(); String fromUserMail =user.getEMail(); String fromUserFullName=user.getFullName(); URLFactory factory = new URLFactory(); String host = factory.getBaseHREF(); String docURL = host + "netmarkets/ext/inner-index.html?docType="+pbo.getName()+"&wfprocessid="+ WfUICommonUtil.getOidByPersistable(wfprocess)+"&pboid="+ pboOid+"&workItemid="+ WfUICommonUtil.getOidByPersistable(wrkItem)+"&wfactivityid="+ WfUICommonUtil.getOidByPersistable(wfactivity); String mailUrl ="請您點選文件連結檢視:"+"< a href='" + docURL + "'>" + name + "</ a>"; MailUtil.sendMail("待辦通知:【"+pbo.getDescription()+"】"+name, mailUrl, list,fromUserMail,fromUserFullName); } } } } } } protected void performStartupProcess() { String speaker = CLASSNAME + ".performStartupProcess"; logger.debug("=> IN " + speaker); listener = new WorkItemListener(getConceptualClassname()); getManagerService().addEventListener(listener, PersistenceManagerEvent.generateEventKey(PersistenceManagerEvent.POST_STORE)); logger.debug("=> OUT " + speaker); } }