//init role to process :
Object teamSpec = null;
if (pn != null && pn instanceof TeamManaged) {
TeamReference teamRef = ((TeamManaged) pn).getTeamId();
if (teamRef != null) {
teamSpec = teamRef;
}
logger.debug("createProcess Proofing Process teamRef = " + teamRef.toString());
}
if (teamSpec == null) {
String teamTemplateName = "Default";
TeamTemplate tt = TeamHelper.service.getTeamTemplate(containerRef, teamTemplateName);
if (tt != null) {
TeamTemplateReference teamTemplateRef = TeamTemplateReference.newTeamTemplateReference(tt);
teamSpec = teamTemplateRef;
}
logger.debug("createProcess Proofing Process teamSpecDefault = " + teamSpec.toString());
}
logger.debug("createProcess Proofing Process teamSpec = " + teamSpec.toString());
//PS:最为稳妥的方式就是通过代码手工添加
initiateProcessRole( pn, wfprocess);
WfProcess wfprocess = WfEngineHelper.service.createProcess(wfprocessdefinition, teamSpec, containerRef);
//启动流程
WfEngineHelper.service.startProcessImmediate(wfprocess, processdata, WORKFLOW_PRIORITY);
public static void initiateProcessRole(PromotionNotice pn, WfProcess process) {
try {
QueryResult qr = ProofingProcessImp.queryFormData4ProcessNumber(pn.getNumber());
//不同流程类型对应不同的角色和组
ProofingProcessBean cuBoxForm =null;
while (qr.hasMoreElements()) {
FormData_Xml form = (FormData_Xml) qr.nextElement();
String formXml = form.getDataInfo().getContents();
cuBoxForm = XMLMapper.fromXml(formXml, ProofingProcessBean.class);
}
String category = cuBoxForm.getCategory();
List<String> roleList = new ArrayList<String>();
List<String> groupList = new ArrayList<String>();
if("PCB".equals(category)){
roleList.add("EDA Engineer");
if("Y".equals(cuBoxForm.getIsPreResearch()) || "Demo".equals(cuBoxForm.getProductName())){
roleList.add("MPM");
roleList.add("PPM");
}
groupList.add("EDA Engineer_HZ");
}
if("CU BOX".equals(category)){
roleList.add("Packing Team");
roleList.add("PDM");
roleList.add("CTS");
groupList.add(cuBoxForm.getCtsGroup());
}
if("Special Label & Sleeve & White Box".equals(category) ){
roleList.add("Packing Team");
roleList.add("CTS");
groupList.add(cuBoxForm.getCtsGroup());
}
if("LCD Sticker&Back Cover Sticker".equals(category) ){
roleList.add("PDM");
roleList.add("MPM");
roleList.add("CTS");
groupList.add(cuBoxForm.getCtsGroup());
}
for (int i = 0; i <roleList.size() ; i++) {
String roleName = roleList.get(i);
Role role = Role.toRole(roleName);
PDMLinkProduct product = (PDMLinkProduct) pn.getContainer();
// 项目团队
ContainerTeam productTeam = (ContainerTeam) product.getContainerTeamReference().getObject();
// Workflow团队
Team wfTeam = (Team) process.getTeamId().getObject();
// delete the pricipal from Workflow Team
Enumeration<WTPrincipalReference> wfTeamEnu = wfTeam.getPrincipalTarget(role);
while (wfTeamEnu.hasMoreElements()) {
wfTeam.deletePrincipalTarget(role, wfTeamEnu.nextElement().getPrincipal());
}
// add the procipal to Workflow Team from Product Team
Enumeration<WTPrincipalReference> productRoles = productTeam.getPrincipalTarget(role);
while (productRoles.hasMoreElements()) {
wfTeam.addPrincipal(role, productRoles.nextElement().getPrincipal());
}
}
} catch (WTInvalidParameterException e) {
e.printStackTrace();
} catch (WTRuntimeException e) {
e.printStackTrace();
} catch (WTException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}