Windchill任务审批意见非空检查

Approve Engineering Change Request is a multiple user task, there are three vote options: Approve, Research_Required and Reject.

Requirements: If user votes on “Research_Required” and “Reject”, then comment is mandatory, currently we don’t have check for this.

Technical solution Options

  1. Use the code in Complete transition, but his only works for Single user tasks.
  2. Use java script check thru UI
  3. Create a class extends StandardNmWorkItemService service class

Below is how I achieve this using #3.

First, add this service to wt.properties

wt.services.service.10041=com.ptc.netmarkets.work.NmWorkItemService/MyNmWorkitemService

Below is the code of the service.

package ext.hhi.services;

import java.util.HashMap;
import java.util.Iterator;

import wt.fc.ObjectReference;
import wt.fc.Persistable;
import wt.method.RemoteMethodServer;
import wt.util.WTException;
import wt.workflow.engine.WfActivity;
import wt.workflow.work.WorkItem;
import com.ptc.netmarkets.util.beans.NmCommandBean;
import com.ptc.netmarkets.work.StandardNmWorkItemService;

import ext.hhi.utils.MiscHelper;
import ext.hhi.utils.StringUtil;

public class MyNmWorkitemService extends StandardNmWorkItemService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7130504123627625857L;
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	public static MyNmWorkitemService newMyNmWorkitemService() throws WTException {
		MyNmWorkitemService service = new MyNmWorkitemService();
		service.initialize();
		return service;
	}
	@Override
	public void complete(NmCommandBean commandBean, HashMap map) throws WTException {
		if (!RemoteMethodServer.ServerFlag) {
			String method = "complete";
			Class<?>[] argTypes = {NmCommandBean.class,HashMap.class};
			Object[] argValues = {commandBean, map};
			try {
				RemoteMethodServer.getDefault().invoke(method, null, this, argTypes, argValues);
			}
			catch (Exception e) {
				if (e instanceof WTException) {
					throw (WTException) e;
				} else {
					throw new WTException(e);
				}
			}
		}
		validateComplete(commandBean, map);
		super.complete(commandBean, map);
	}
	private void validateComplete(NmCommandBean commandBean, HashMap<?, ?> map) throws WTException {
		for(Object mapKey:map.keySet()) {
			System.out.println("params key is:" + mapKey.toString());
		}
		for(Object mapValue:map.values()) {
			System.out.println("params value is:" + mapValue.toString());
		}
		com.ptc.netmarkets.model.NmOid nmoid = commandBean.getPageOid();
		WorkItem workitem = getWorkItem(nmoid);
		ObjectReference sourceReference = workitem.getSource();
		if(sourceReference != null) {
			Persistable sourceObject = sourceReference.getObject();
			if(sourceObject != null && sourceObject instanceof WfActivity) {
				WfActivity activity = (WfActivity)sourceObject;
				String activityName = activity.getName();
				if("Your activity".equals(activityName)) {
					String vote = MiscHelper.fixValue(getUserRoute(map));
					String comments = MiscHelper.fixValue(getUserComments(map));
					System.out.println("vote:" + route);
					System.out.println("comments:" + comments);
					if(vote.equalsIgnoreCase("Research_Required")||vote.equalsIgnoreCase("Reject")) {
						if(StringUtil.isEmpty(comments)) {
							throw new WTException("Research_Required or Reject Comments are required.");
						}
					}
				}
			}
		}
	}
	 private static String getUserComments(HashMap<?, ?> params) {
	        String comments = "";
	        try {
	            Iterator<?> it = params.keySet().iterator();
	            while (it.hasNext()) {
	                String key = (String) it.next();
	                if(key.trim().endsWith("comments___textarea"))
	                	comments = (String) params.get(key); 
	            }
	        } catch (Exception e) {
	        	System.out.println("getUserComment Error");
	        	e.printStackTrace();
	        }
	        System.out.println("Inisde get user comments:" + comments);
	        return comments;
	    }
    private static String getUserRoute(HashMap<?,?> params) {
        String route = "";
        try {
            Iterator<?> it = params.keySet().iterator();
            while (it.hasNext()) {
                String key = (String) it.next();
                if(key.endsWith("WfUserEvent0___radio"))
                	route = (String) params.get(key);
            }
        } catch (Exception e) {
        	System.out.println("getUserRoute error");
            e.printStackTrace();
        }
        System.out.println("Vote option is:" + route);
        return route;
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值