Windchill Code

WebService Client

  1. public class RmRemoteDelegate {  
  2.     private RMItemService query = null;  
  3.       
  4.     private static String ACCOUNTINFOFILEPATH = "";  
  5. //  private static File configFile = null; //配置文件  
  6.     static {  
  7.         //读取配置文件  
  8.         try {  
  9.             WTProperties wtproperties = WTProperties.getLocalProperties();  
  10.             ACCOUNTINFOFILEPATH = new StringBuffer().append(wtproperties.getProperty("wt.home"))  
  11.                     .append(System.getProperty("file.separator")).append("config").append(  
  12.                             System.getProperty("file.separator")).append(  
  13.                             "SystemIntegrationAccounts.properties").toString();  
  14. //            configFile = new File(ACCOUNTINFOFILEPATH);  
  15.         } catch (IOException e) {  
  16.             System.out.println("读取配置文件SystemIntegrationAccounts.properties失败!下面是异常信息:");  
  17.             e.printStackTrace();  
  18.         }  
  19.     }  
  20.     public RmRemoteDelegate() {  
  21.         try {  
  22.               
  23. //          Properties rmProperty = new Properties();  
  24. //          FileInputStream sysConfInput = null;  
  25.             String userName = null;  
  26.             String passWord = null;  
  27.             try {  
  28. //              sysConfInput = new FileInputStream(configFile);  
  29. //              rmProperty.load(sysConfInput);  
  30.                 String server = PropertiesUtil.getProperty(ACCOUNTINFOFILEPATH, "rm.url"); //rmProperty.getProperty("rm.url");  
  31.                 String accounts = PropertiesUtil.getProperty(ACCOUNTINFOFILEPATH,"rmServiceAccount");//rmProperty.getProperty("rmserviceAccount");  
  32.                 String dECstrDenc = DESEncoding.DeCode(accounts);  
  33.                 userName = dECstrDenc.substring(0, dECstrDenc.indexOf("="));  
  34.                 passWord = dECstrDenc.substring(dECstrDenc.indexOf("=") + 1);  
  35.                 RMItemServiceServiceLocator cws = new RMItemServiceServiceLocator();  
  36.                 cws.setRMItemEndpointAddress(server);  
  37.                 try {  
  38.                     query = cws.getRMItem();  
  39.                 } catch (ServiceException e) {  
  40.                     System.out.println("连接RM失败!");  
  41.                     throw new WTException(e);  
  42.                 }  
  43.                 RMItemSoapBindingStub stub = (RMItemSoapBindingStub) query;  
  44.                 stub.setUsername(userName);  
  45.                 stub.setPassword(passWord);  
  46.             } catch (Exception e) {  
  47.                 e.printStackTrace();  
  48.             }  
  49.               
  50.             /*RMItemServiceServiceLocator cws = new RMItemServiceServiceLocator(); 
  51.             try { 
  52.                 query = cws.getRMItem(); 
  53.             } catch (Exception e) { 
  54.                 e.printStackTrace(); 
  55.             } 
  56.             RMItemSoapBindingStub stub = (RMItemSoapBindingStub) query; 
  57. //          stub.setHeader(setSoapHeader(USERNAME, PASSWORD)); 
  58.             ((org.apache.axis.client.Stub)stub).setUsername(USERNAME); 
  59.             ((org.apache.axis.client.Stub)stub).setPassword(PASSWORD);*/  
  60.   
  61.               
  62.         } catch (Exception e) {  
  63.             e.printStackTrace();  
  64.         }  
  65.     }  
  66.       
  67.     private static SOAPHeaderElement setSoapHeader(String wsUserName,  
  68.             String wsPassword) {  
  69.   
  70.         SOAPHeaderElement soapHeaderElement = null;  
  71.         try {  
  72.             soapHeaderElement = new org.apache.axis.message.SOAPHeaderElement(  
  73.                     "wsse""Security");  
  74.             soapHeaderElement.setMustUnderstand(true);  
  75.             soapHeaderElement  
  76.                     .setNamespaceURI("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");  
  77.             SOAPElement token = soapHeaderElement  
  78.                     .addChildElement("UsernameToken");  
  79.             SOAPElement userName = token  
  80.                     .addChildElement(  
  81.                             "Username",  
  82.                             "wsse",  
  83.                             "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");  
  84.             userName.setValue(wsUserName);  
  85.             SOAPElement password = token  
  86.                     .addChildElement(  
  87.                             "Password",  
  88.                             "wsse",  
  89.                             "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");  
  90.             password.setValue(wsPassword);  
  91.   
  92.         } catch (Exception err) {  
  93.             err.printStackTrace();  
  94.         }  
  95.         return soapHeaderElement;  
  96.     }  
  97.       
  98.     public TreeNodeBean[] getItemTree(ext.huawei.integration.rm.client.GetItemTreeParamBean[] getItemTreePrarmBean) throws RemoteException {  
  99.         return query.getItemTree(getItemTreePrarmBean);  
  100.     }  
  101.   
  102. }  

windchill
获取容器对象下得角色与指定角色的成员 windchill
Java代码   收藏代码
  1. package ext.csc.util.core;  
  2.   
  3. import java.io.Serializable;  
  4. import java.util.ArrayList;  
  5. import java.util.Enumeration;  
  6. import java.util.Vector;  
  7.   
  8. import wt.fc.PersistenceHelper;  
  9. import wt.fc.QueryResult;  
  10. import wt.inf.container.OrgContainer;  
  11. import wt.inf.library.WTLibrary;  
  12. import wt.inf.team.ContainerTeam;  
  13. import wt.inf.team.ContainerTeamHelper;  
  14. import wt.inf.team.ContainerTeamManaged;  
  15. import wt.inf.team.StandardContainerTeamService;  
  16. import wt.method.RemoteAccess;  
  17. import wt.method.RemoteMethodServer;  
  18. import wt.org.OrganizationServicesHelper;  
  19. import wt.org.WTGroup;  
  20. import wt.org.WTPrincipal;  
  21. import wt.org.WTPrincipalReference;  
  22. import wt.pdmlink.PDMLinkProduct;  
  23. import wt.project.Role;  
  24. import wt.projmgmt.admin.Project2;  
  25. import wt.query.QuerySpec;  
  26. import wt.query.SearchCondition;  
  27. import wt.session.SessionServerHelper;  
  28. import wt.team.TeamException;  
  29. import wt.util.WTException;  
  30. import ext.csc.util.common.CSCDebug;  
  31.   
  32. /** 
  33.  * 该工具类封装了对于Container的一系列底层操作 
  34.  * @author mliu 
  35.  * 
  36.  */  
  37. public class CSCContainer implements RemoteAccess, Serializable{  
  38.     private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCContainer.class);   
  39.       
  40.     private static final long serialVersionUID = 5458003848567223542L;  
  41.   
  42.     /** 
  43.      * 通过名称查找PDMLinkProduct 
  44.      * @param name  查询PDMLinkProduct名称条件 
  45.      * @param accessControlled  是否受到权限制约 
  46.      * @return 返回查询到的PDMLinkProduct对象 
  47.      */  
  48.     public static PDMLinkProduct getPDMLinkProduct(String name, boolean accessControlled){  
  49.         try {  
  50.             if (!RemoteMethodServer.ServerFlag) {  
  51.                 return (PDMLinkProduct) RemoteMethodServer.getDefault().invoke("getPDMLinkProduct", CSCContainer.class.getName(), null,  
  52.                         new Class[] {String.classboolean.class},  
  53.                         new Object[] {name, accessControlled});  
  54.             } else {  
  55.                 PDMLinkProduct product = null;  
  56.                   
  57.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);  
  58.                 try {  
  59.                     QuerySpec qs = new QuerySpec(PDMLinkProduct.class);  
  60.                     SearchCondition sc = new  
  61.                             SearchCondition(PDMLinkProduct.class, PDMLinkProduct.NAME, SearchCondition.EQUAL, name, false);  
  62.                     qs.appendSearchCondition(sc);  
  63.                       
  64.                     QueryResult qr = PersistenceHelper.manager.find(qs);  
  65.   
  66.                     if (qr.hasMoreElements()){  
  67.                         product = (PDMLinkProduct)qr.nextElement();               
  68.                     }  
  69.                 } catch (Exception e) {  
  70.                     // TODO: handle exception  
  71.                     e.printStackTrace();  
  72.                 } finally {  
  73.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  74.                 }  
  75.   
  76.                 return product;  
  77.             }  
  78.         } catch (Exception e) {  
  79.             e.printStackTrace();  
  80.         }  
  81.         return null;  
  82.     }     
  83.       
  84.     /** 
  85.      * 通过名称查找WTLibrary 
  86.      * @param name  查询WTLibrary名称条件 
  87.      * @param accessControlled  是否受到权限制约 
  88.      * @return 返回查询到的WTLibrary对象 
  89.      */  
  90.     public static WTLibrary getLibrary(String name, boolean accessControlled){  
  91.         try {  
  92.             if (!RemoteMethodServer.ServerFlag) {  
  93.                 return (WTLibrary) RemoteMethodServer.getDefault().invoke("getLibrary", CSCContainer.class.getName(), null,  
  94.                         new Class[] {String.classboolean.class},  
  95.                         new Object[] {name, accessControlled});  
  96.             } else {  
  97.                 WTLibrary library = null;  
  98.                   
  99.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);  
  100.                 try {  
  101.                     QuerySpec qs = new QuerySpec(WTLibrary.class);  
  102.                     SearchCondition sc = new  
  103.                             SearchCondition(WTLibrary.class, WTLibrary.NAME, SearchCondition.EQUAL, name, false);  
  104.                     qs.appendSearchCondition(sc);  
  105.                       
  106.                     QueryResult qr = PersistenceHelper.manager.find(qs);  
  107.   
  108.                     if (qr.hasMoreElements()){  
  109.                         library = (WTLibrary)qr.nextElement();                
  110.                     }  
  111.                 } catch (Exception e) {  
  112.                     // TODO: handle exception  
  113.                     e.printStackTrace();  
  114.                 } finally {  
  115.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  116.                 }  
  117.   
  118.                 return library;  
  119.             }  
  120.         } catch (Exception e) {  
  121.             e.printStackTrace();  
  122.         }  
  123.         return null;  
  124.     }  
  125.       
  126.       
  127.     /** 
  128.      * 通过名称查找Project2 
  129.      * @param name  查询Project2名称条件 
  130.      * @param accessControlled  是否受到权限制约 
  131.      * @return 返回查询到的Project2对象 
  132.      */  
  133.     public static Project2 getProject(String name, boolean accessControlled){  
  134.         try {  
  135.             if (!RemoteMethodServer.ServerFlag) {  
  136.                 return (Project2) RemoteMethodServer.getDefault().invoke("getProject", CSCContainer.class.getName(), null,  
  137.                         new Class[] {String.classboolean.class},  
  138.                         new Object[] {name, accessControlled});  
  139.             } else {  
  140.                 Project2 project = null;  
  141.                   
  142.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);  
  143.                 try {  
  144.                     QuerySpec qs = new QuerySpec(Project2.class);  
  145.                     SearchCondition sc = new  
  146.                             SearchCondition(Project2.class, Project2.NAME, SearchCondition.EQUAL, name, false);  
  147.                     qs.appendSearchCondition(sc);  
  148.                       
  149.                     QueryResult qr = PersistenceHelper.manager.find(qs);  
  150.   
  151.                     if (qr.hasMoreElements()){  
  152.                         project = (Project2)qr.nextElement();                 
  153.                     }  
  154.                 } catch (Exception e) {  
  155.                     // TODO: handle exception  
  156.                     e.printStackTrace();  
  157.                 } finally {  
  158.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  159.                 }  
  160.   
  161.                 return project;  
  162.             }  
  163.         } catch (Exception e) {  
  164.             e.printStackTrace();  
  165.         }  
  166.         return null;  
  167.     }     
  168.       
  169.       
  170.     /** 
  171.      * 通过编号查找Project2 
  172.      * @param number    查询Project2编号条件 
  173.      * @param accessControlled  是否受到权限制约 
  174.      * @return 返回查询到的Project2对象 
  175.      */  
  176.     public static Project2 getProjectByNumber(String number, boolean accessControlled){  
  177.         try {  
  178.             if (!RemoteMethodServer.ServerFlag) {  
  179.                 return (Project2) RemoteMethodServer.getDefault().invoke("getProjectByNumber", CSCContainer.class.getName(), null,  
  180.                         new Class[] {String.classboolean.class},  
  181.                         new Object[] {number, accessControlled});  
  182.             } else {  
  183.                 Project2 project = null;  
  184.                   
  185.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);  
  186.                 try {  
  187.                     QuerySpec qs = new QuerySpec(Project2.class);  
  188.                     SearchCondition sc = new  
  189.                             SearchCondition(Project2.class, Project2.PROJECT_NUMBER, SearchCondition.EQUAL, number, false);  
  190.                     qs.appendSearchCondition(sc);  
  191.                       
  192.                     QueryResult qr = PersistenceHelper.manager.find(qs);  
  193.   
  194.                     if (qr.hasMoreElements()){  
  195.                         project = (Project2)qr.nextElement();                 
  196.                     }  
  197.                 } catch (Exception e) {  
  198.                     // TODO: handle exception  
  199.                     e.printStackTrace();  
  200.                 } finally {  
  201.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  202.                 }  
  203.   
  204.                 return project;  
  205.             }  
  206.         } catch (Exception e) {  
  207.             e.printStackTrace();  
  208.         }  
  209.         return null;  
  210.     }     
  211.       
  212.     /** 
  213.      * 通过名称查找OrgContainer组织对象 
  214.      * @param name  查询OrgContainer名称条件 
  215.      * @param accessControlled  是否受到权限制约 
  216.      * @return 返回查询到的OrgContainer对象 
  217.      */  
  218.     public static OrgContainer getOrgContainer(String name, boolean accessControlled) throws WTException{  
  219.         try {  
  220.             if (!RemoteMethodServer.ServerFlag) {  
  221.                 return (OrgContainer) RemoteMethodServer.getDefault().invoke("getOrgContainer", CSCContainer.class.getName(), null,  
  222.                         new Class[] {String.classboolean.class},  
  223.                         new Object[] {name, accessControlled});  
  224.             } else {  
  225.                 OrgContainer org = null;  
  226.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);  
  227.                 try {  
  228.                     QuerySpec criteria = new QuerySpec(OrgContainer.class);  
  229.                     criteria.appendWhere(new SearchCondition(OrgContainer.class,OrgContainer.NAME,SearchCondition.EQUAL,name,false));  
  230.                     QueryResult results = PersistenceHelper.manager.find(criteria);  
  231.                       
  232.                     if(results.hasMoreElements())  {  
  233.                         org = (OrgContainer)results.nextElement();  
  234.                     }else{  
  235.                         return null;  
  236.                     }  
  237.                 } catch (Exception e) {  
  238.                     // TODO: handle exception  
  239.                     e.printStackTrace();  
  240.                 } finally {  
  241.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  242.                 }  
  243.   
  244.                 return org;  
  245.             }  
  246.         } catch (Exception e) {  
  247.             e.printStackTrace();  
  248.         }  
  249.         return null;  
  250.     }   
  251.       
  252.       
  253.     /** 
  254.      * 得到Container对象的团队角色列表 
  255.      * @param teammanaged   可包含团队的Container对象 
  256.      * @return  Container团队角色列表 
  257.      */  
  258.     public static ArrayList<Role> getContainerTeamRoles(ContainerTeamManaged teammanaged){  
  259.         try {  
  260.             if (!RemoteMethodServer.ServerFlag) {  
  261.                 return (ArrayList<Role>) RemoteMethodServer.getDefault().invoke("getContainerTeamRoles", CSCContainer.class.getName(), null,  
  262.                         new Class[] {ContainerTeamManaged.class},  
  263.                         new Object[] {teammanaged});  
  264.             } else {  
  265.                 ArrayList<Role> result = new ArrayList<Role>();  
  266.                   
  267.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  268.                 try {  
  269.                     try {  
  270.                         ContainerTeam team = ContainerTeamHelper.service.getContainerTeam(teammanaged);           
  271.                         Vector v = team.getRoles();  
  272.                           
  273.                         if(v == null){  
  274.                             return result;  
  275.                         }  
  276.                         for (int i = 0; i < v.size(); i++) {  
  277.                             Object obj = v.get(i);  
  278.                             if(obj instanceof Role){  
  279.                                 Role role = (Role)obj;  
  280.                                 if(!result.contains(role))  
  281.                                     result.add(role);             
  282.                             }  
  283.                         }  
  284.                     } catch (TeamException e) {  
  285.                         e.printStackTrace();  
  286.                     } catch (WTException e) {  
  287.                         e.printStackTrace();  
  288.                     }  
  289.                 } catch (Exception e) {  
  290.                     // TODO: handle exception  
  291.                     e.printStackTrace();      
  292.                 } finally {  
  293.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  294.                 }  
  295.   
  296.                 return result;  
  297.             }  
  298.         } catch (Exception e) {  
  299.             e.printStackTrace();  
  300.         }  
  301.         return new ArrayList<Role>();       
  302.     }  
  303.       
  304.     /** 
  305.      * 得到Container对象的指定角色的成员列表 
  306.      * @param teammanaged   可包含团队的Container对象 
  307.      * @param role  指定的团队角色 
  308.      * @return  Container的指定Role的成员列表(WTPrincipalReference) 
  309.      */  
  310.     public static ArrayList<WTPrincipalReference> getContainerPrincipalByRole(ContainerTeamManaged teammanaged, Role role){  
  311.         try {  
  312.             if (!RemoteMethodServer.ServerFlag) {  
  313.                 return (ArrayList<WTPrincipalReference>) RemoteMethodServer.getDefault().invoke("getContainerPrincipalByRole", CSCContainer.class.getName(), null,  
  314.                         new Class[] {ContainerTeamManaged.class, Role.class},  
  315.                         new Object[] {teammanaged, role});  
  316.             } else {  
  317.                 ArrayList<WTPrincipalReference> result = new ArrayList<WTPrincipalReference>();  
  318.                   
  319.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  320.                 try {  
  321.                     try {  
  322.                         ContainerTeam team = ContainerTeamHelper.service.getContainerTeam(teammanaged);           
  323.                         StandardContainerTeamService scts = StandardContainerTeamService.newStandardContainerTeamService();  
  324.                           
  325.                         WTGroup wtgroup = scts.findContainerTeamGroup(team, ContainerTeamHelper.ROLE_GROUPS, role.toString());  
  326.                         if (wtgroup != null) {  
  327.                             Enumeration enumeration = OrganizationServicesHelper.manager.members(wtgroup, falsetrue);  
  328.                             while(enumeration.hasMoreElements()){  
  329.                                 WTPrincipalReference wtprincipalreference = WTPrincipalReference  
  330.                                         .newWTPrincipalReference((WTPrincipal) enumeration  
  331.                                                 .nextElement());  
  332.                                 if(!result.contains(wtprincipalreference)){  
  333.                                     result.add(wtprincipalreference);  
  334.                                 }                                 
  335.                             }  
  336.                         }  
  337.                     } catch (TeamException e) {  
  338.                         e.printStackTrace();  
  339.                     } catch (WTException e) {  
  340.                         e.printStackTrace();  
  341.                     }  
  342.                 } catch (Exception e) {  
  343.                     // TODO: handle exception  
  344.                     e.printStackTrace();      
  345.                 } finally {  
  346.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  347.                 }  
  348.   
  349.                 return result;  
  350.             }  
  351.         } catch (Exception e) {  
  352.             e.printStackTrace();  
  353.         }  
  354.         return new ArrayList<WTPrincipalReference>();       
  355.     }  
  356.       
  357.     public static void main(String[] args) throws WTException {  
  358.         //************************ Test of getPDMLinkProduct ********************************  
  359.         PDMLinkProduct product = CSCContainer.getPDMLinkProduct("GOLF_CART",  false);  
  360.         System.out.println("Find Product = " + product.getContainerName());  
  361.           
  362.         //************************ Test of getLibrary ********************************  
  363. /*      WTLibrary library = CSCContainer.getLibrary(args[0],  Boolean.parseBoolean(args[1]));  
  364.         System.out.println("Find Library = " + library);*/  
  365.           
  366.         //************************ Test of getProject ********************************  
  367. /*      Project2 project = CSCContainer.getProject(args[0],  Boolean.parseBoolean(args[1]));  
  368.         System.out.println("Find Project = " + project);        */  
  369.           
  370.         //************************ Test of getProjectByNumber ********************************  
  371. /*      Project2 project = CSCContainer.getProjectByNumber(args[0],  Boolean.parseBoolean(args[1]));  
  372.         System.out.println("Find Project = " + project);*/        
  373.           
  374.         //************************ Test of getProjectByNumber ********************************  
  375. /*      OrgContainer org = CSCContainer.getOrgContainer(args[0],  Boolean.parseBoolean(args[1]));  
  376.         System.out.println("Find OrgContainer = " + org);   */    
  377.           
  378.         //************************ Test of getContainerTeamRoles ********************************  
  379.         /*//PDMLinkProduct product = CSCContainer.getPDMLinkProduct(args[0], false);  
  380.         ArrayList<Role> roles = CSCContainer.getContainerTeamRoles(product);  
  381.         for (int i = 0; i < roles.size(); i++) {  
  382.             System.out.println("Find Role = " + roles.get(i));  
  383.         }*/  
  384.           
  385.         //************************ Test of getContainerPrincipalByRole ********************************  
  386.         //PDMLinkProduct product = CSCContainer.getPDMLinkProduct(args[0], false);  
  387.         ArrayList<Role> roles = CSCContainer.getContainerTeamRoles(product);  
  388.         for (int i = 0; i < roles.size(); i++) {  
  389.             System.out.println("Find Role = " + (roles.get(i)).getDisplay());  
  390.             ArrayList<WTPrincipalReference> principals = CSCContainer.getContainerPrincipalByRole(product, roles.get(i));  
  391.             for (int j = 0; j < principals.size(); j++) {  
  392.                 System.out.println("--> " + (principals.get(j)).getDisplayName());  
  393.             }  
  394.         }     
  395.     }  
  396. }  
乱码问题 乱码问题, windchill
Java代码   收藏代码
  1. http://wenku.baidu.com/view/a99291c458f5f61fb736667e.html  
  2.   
  3.   
  4. http://www.baidu.com/s?wd=ext+%D4%F5%C3%B4%B4%A6%C0%ED%C2%D2%C2%EB&rsv_bp=0&rsv_spt=3&inputT=79109  
model 建模 model 建模, windchill
Java代码   收藏代码
  1. package ext.ts.part;  
  2.   
  3. import java.io.Serializable;  
  4.   
  5. import com.google.gwt.i18n.client.LocalizableResource.GeneratedFrom;  
  6. import com.ptc.windchill.annotations.metadata.DerivedProperty;  
  7. import com.ptc.windchill.annotations.metadata.ForeignKeyRole;  
  8. import com.ptc.windchill.annotations.metadata.GenAsPersistable;  
  9. import com.ptc.windchill.annotations.metadata.GeneratedForeignKey;  
  10. import com.ptc.windchill.annotations.metadata.GeneratedProperty;  
  11. import com.ptc.windchill.annotations.metadata.MyRole;  
  12. import com.ptc.windchill.annotations.metadata.PropertyConstraints;  
  13.   
  14. import com.ptc.windchill.annotations.metadata.SupportedAPI;  
  15.   
  16. import wt.part.WTPart;  
  17. import wt.util.WTException;  
  18. @GenAsPersistable(superClass=WTPart.class,properties={@GeneratedProperty(name="attrString",  
  19.         type=String.class,constraints=@PropertyConstraints(required=false))  
  20.         },  
  21.  foreignKeys={  
  22.      @GeneratedForeignKey(foreignKeyRole=@ForeignKeyRole(name="master",type=ext.ts.part.TSPart.class,cascade=false,  
  23.              constraints=@PropertyConstraints(required=true)),myRole=@MyRole(name="iteration",supportedAPI=SupportedAPI.PUBLIC,cascade=false))  
  24. },derivedProperties={  
  25.     @DerivedProperty(name="masterAttrString",derivedFrom="master>masterAttrString")  
  26. }     
  27. )  
  28. public class TSPart extends _TSPart {  
  29.   static final long SerialVersionUID=1;  
  30.   public static TSPart newTSPart() throws WTException{  
  31.       final TSPart instance=new TSPart();  
  32.       instance.initialize();  
  33.       return instance;  
  34.   }  
  35. }  
该工具类封装了对于ManagedBaseline的一系列底层操作 windchill
Java代码   收藏代码
  1. package ext.csc.util.core;  
  2.   
  3. import java.io.Serializable;  
  4. import java.text.DecimalFormat;  
  5. import java.util.ArrayList;  
  6. import java.util.HashMap;  
  7.   
  8. import wt.fc.PersistenceHelper;  
  9. import wt.fc.QueryResult;  
  10. import wt.fc.collections.WTValuedHashMap;  
  11. import wt.folder.Folder;  
  12. import wt.folder.FolderHelper;  
  13. import wt.inf.container.WTContainerRef;  
  14. import wt.method.RemoteAccess;  
  15. import wt.method.RemoteMethodServer;  
  16. import wt.query.QuerySpec;  
  17. import wt.query.SearchCondition;  
  18. import wt.session.SessionServerHelper;  
  19. import wt.util.WTException;  
  20. import wt.vc.baseline.BaselineHelper;  
  21. import wt.vc.baseline.Baselineable;  
  22. import wt.vc.baseline.ManagedBaseline;  
  23.   
  24. import com.ptc.core.meta.common.TypeIdentifier;  
  25. import com.ptc.core.meta.common.TypeIdentifierHelper;  
  26. import com.ptc.windchill.enterprise.copy.server.CoreMetaUtility;  
  27.   
  28. import ext.csc.util.common.CSCDebug;  
  29.   
  30. /** 
  31.  * 该工具类封装了对于ManagedBaseline的一系列底层操作 
  32.  * @author mliu 
  33.  * 
  34.  */  
  35. public class CSCBaseline implements RemoteAccess, Serializable{  
  36.     private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCBaseline.class);        
  37.       
  38.     public static String FOLDER = "FOLDER"//创建文件夹 (默认:/Default)  
  39.     public static String DESCRIPTION = "DESCRIPTION"//描述  
  40.     public static String TYPE = "TYPE"//类型 (默认:wt.vc.baseline.ManagedBaseline)  
  41.       
  42.     private static final long serialVersionUID = -8423672460519840395L;  
  43.   
  44.     /** 
  45.      * 通过编号查找基线 
  46.      * @param number    查询基线编号条件 
  47.      * @param accessControlled  是否受到权限制约 
  48.      * @return  返回结果基线 
  49.      */  
  50.     public static ManagedBaseline getBaseline(String number, boolean accessControlled) {  
  51.         try {  
  52.             number = number.toUpperCase();  
  53.               
  54.             if (!RemoteMethodServer.ServerFlag) {  
  55.                 return (ManagedBaseline) RemoteMethodServer.getDefault().invoke("getBaseline", CSCBaseline.class.getName(), null,  
  56.                         new Class[] {String.classboolean.class},  
  57.                         new Object[] {number, accessControlled});  
  58.             } else {  
  59.                 ManagedBaseline baseline = null;  
  60.                   
  61.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);  
  62.                 try {  
  63.                     QuerySpec spec = new QuerySpec(ManagedBaseline.class);  
  64.                     spec.appendWhere(  
  65.                             new SearchCondition(ManagedBaseline.class,  
  66.                                     ManagedBaseline.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });  
  67.                       
  68.                     QueryResult qr = PersistenceHelper.manager.find(spec);  
  69.                     if (qr.hasMoreElements()){  
  70.                         baseline = (ManagedBaseline)qr.nextElement();  
  71.                     }  
  72.                 } catch (Exception e) {  
  73.                     // TODO: handle exception  
  74.                     e.printStackTrace();  
  75.                 } finally {  
  76.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  77.                 }  
  78.   
  79.                 return baseline;  
  80.             }  
  81.         } catch (Exception e) {  
  82.             e.printStackTrace();  
  83.         }  
  84.         return null;  
  85.     }     
  86.       
  87.   
  88.     /** 
  89.      * 通过基线内容对象查找基线 
  90.      * @param baselineable  查询内容对象 
  91.      * @return  返回结果基线集 
  92.      */  
  93.     public static ArrayList<ManagedBaseline> getBaselineByBaselineable(Baselineable baselineable) {  
  94.         ArrayList<ManagedBaseline> results = new ArrayList<ManagedBaseline>();  
  95.           
  96.         try {  
  97.             if (!RemoteMethodServer.ServerFlag) {  
  98.                 return (ArrayList<ManagedBaseline>) RemoteMethodServer.getDefault().invoke("getBaselineByBaselineable", CSCBaseline.class.getName(), null,  
  99.                         new Class[] {Baselineable.class},  
  100.                         new Object[] {baselineable});  
  101.             } else {  
  102.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  103.                 try {  
  104.                     QueryResult qr = BaselineHelper.service.getBaselines(baselineable);  
  105.                     while (qr.hasMoreElements()){                 
  106.                         ManagedBaseline baseline = (ManagedBaseline)qr.nextElement();     
  107.                         if(!results.contains(baseline)){  
  108.                             results.add(baseline);  
  109.                         }                         
  110.                     }  
  111.                 } catch (Exception e) {  
  112.                     // TODO: handle exception  
  113.                     e.printStackTrace();  
  114.                 } finally {  
  115.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  116.                 }  
  117.   
  118.                 return results;  
  119.             }  
  120.         } catch (Exception e) {  
  121.             e.printStackTrace();  
  122.         }  
  123.         return null;  
  124.     }  
  125.       
  126.       
  127.     /** 
  128.      * 得到默认的基线序列号 
  129.      * @return 10位的序列号字符串 
  130.      */  
  131.     public static String getDefaultBaselineSeqNumber(){  
  132.         String bitFormat = "";  
  133.           
  134.         try{  
  135.             for (int i = 0; i < 10; i++) {  
  136.                 bitFormat = bitFormat + "0";  
  137.             }  
  138.               
  139.             int seq = Integer.parseInt(PersistenceHelper.manager.getNextSequence(ManagedBaseline.class));  
  140.             DecimalFormat format = new DecimalFormat(bitFormat);  
  141.             return format.format(seq);  
  142.         }catch(Exception ex){  
  143.             ex.printStackTrace();  
  144.         }  
  145.         return null;  
  146.     }     
  147.       
  148.       
  149.     /** 
  150.      * 创建基线 
  151.      * @param number    编号 (默认为系统的Baseline Sequence)     
  152.      * @param name      名称 (必须) 
  153.      * @param attributes    固定属性对应表 (必须) 
  154.      * @param containerRef  上下文 
  155.      * @return  如果指定编号的基线存在,则返回该基线 
  156.      */   
  157.     public static ManagedBaseline createBaseline(String number, String name, HashMap attributes, WTContainerRef containerRef){  
  158.         try {  
  159.             if (!RemoteMethodServer.ServerFlag) {  
  160.                 return (ManagedBaseline) RemoteMethodServer.getDefault().invoke("createBaseline", CSCBaseline.class.getName(), null,  
  161.                         new Class[] {String.class, String.class, HashMap.class, WTContainerRef.class},  
  162.                         new Object[] {number, name, attributes, containerRef});  
  163.             } else {  
  164.                 ManagedBaseline baseline = null;  
  165.   
  166.                 try {  
  167.                     String baselineDesc = "";  
  168.                     String baselineType = "";  
  169.                     String baselineFolder = "";                   
  170.                       
  171.                     if(attributes != null){  
  172.                         baselineDesc = (String)attributes.get(CSCBaseline.DESCRIPTION);  
  173.                         baselineType = (String)attributes.get(CSCBaseline.TYPE);  
  174.                         baselineFolder = (String)attributes.get(CSCBaseline.FOLDER);  
  175.                     }  
  176.                                           
  177.                     if(containerRef == null){  
  178.                         return null;  
  179.                     }  
  180.                                           
  181.                     //设置编号默认值 (默认为系统的Baseline Sequence)                   
  182.                     if(number == null || number.equalsIgnoreCase("")){  
  183.                         number = CSCBaseline.getDefaultBaselineSeqNumber();  
  184.                     }else{  
  185.                         //如果此编号基线已存在,则返回该基线  
  186.                         ManagedBaseline existBaseline = CSCBaseline.getBaseline(number, false);  
  187.                         if(existBaseline != null){  
  188.                             return existBaseline;  
  189.                         }  
  190.                     }             
  191.                                           
  192.                     if(name == null || name.equalsIgnoreCase("")){  
  193.                         return null;  
  194.                     }  
  195.                       
  196.                     if(baselineDesc == null){  
  197.                         baselineDesc = "";  
  198.                     }  
  199.                       
  200.                     //设置默认类型  (默认:wt.vc.baseline.ManagedBaseline)     
  201.                     if(baselineType == null || baselineType.equalsIgnoreCase("")){  
  202.                         baselineType = "wt.vc.baseline.ManagedBaseline";  
  203.                     }  
  204.                       
  205.                     //设置默认文件夹  (默认:/Default)  
  206.                     if(baselineFolder == null || baselineFolder.equalsIgnoreCase("")){  
  207.                         baselineFolder = "/Default";  
  208.                     }else{  
  209.                          if(!baselineFolder.startsWith("/Default")){  
  210.                              baselineFolder = "/Default/" + baselineFolder;  
  211.                          }  
  212.                     }                 
  213.                       
  214.                     baseline = ManagedBaseline.newManagedBaseline();      
  215.                     baseline.setNumber(number);  
  216.                     baseline.setName(name);  
  217.                       
  218.                     //设置基线描述  
  219.                     baseline.setDescription(baselineDesc);  
  220.                       
  221.                     //设置基线类型  
  222.                     if(baselineType != null){  
  223.                         TypeIdentifier id = TypeIdentifierHelper.getTypeIdentifier(baselineType);  
  224.                         baseline = (ManagedBaseline) CoreMetaUtility.setType(baseline, id);  
  225.                     }  
  226.                       
  227.                     //设置上下文  
  228.                     baseline.setContainerReference(containerRef);  
  229.                       
  230.                     //设置文件夹  
  231.                     Folder location = null;   
  232.                         //查询文件夹是否存在  
  233.                     try {  
  234.                         location = FolderHelper.service.getFolder(baselineFolder,containerRef);  
  235.                     } catch (Exception e) {  
  236.                         location = null;  
  237.                     }  
  238.                         //若文件夹不存在,则创建该文件夹  
  239.                     if(location == null)  
  240.                         location = FolderHelper.service.saveFolderPath(baselineFolder, containerRef);  
  241.                         //设置文件夹到基线对象  
  242.                     if (location != null) {  
  243.                         WTValuedHashMap map = new WTValuedHashMap();  
  244.                         map.put(baseline, location);  
  245.                         FolderHelper.assignLocations(map);  
  246.                     }                     
  247.                       
  248.                     baseline = (ManagedBaseline) PersistenceHelper.manager.save(baseline);  
  249.                     baseline = (ManagedBaseline) PersistenceHelper.manager.refresh(baseline);                                             
  250.                 } catch (Exception e) {  
  251.                     // TODO: handle exception  
  252.                     e.printStackTrace();  
  253.                 }  
  254.   
  255.                 return baseline;  
  256.             }  
  257.         } catch (Exception e) {  
  258.             e.printStackTrace();  
  259.         }  
  260.         return null;  
  261.     }  
  262.       
  263.     /** 
  264.      * 通过基线得到基线内容 
  265.      * @param baseline  条件基线 
  266.      * @return  基线内容对象集 
  267.      */  
  268.     public static ArrayList<Baselineable> getBaselineItems(ManagedBaseline baseline){  
  269.         ArrayList<Baselineable> results = new ArrayList<Baselineable>();  
  270.           
  271.         try {  
  272.             if (!RemoteMethodServer.ServerFlag) {  
  273.                 return (ArrayList<Baselineable>) RemoteMethodServer.getDefault().invoke("getBaselineItems", CSCBaseline.class.getName(), null,  
  274.                         new Class[] {ManagedBaseline.class},  
  275.                         new Object[] {baseline});  
  276.             } else {                      
  277.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  278.                 try {  
  279.                     QueryResult qr = BaselineHelper.service.getBaselineItems(baseline);  
  280.                     while(qr.hasMoreElements()){  
  281.                         Object obj = qr.nextElement();  
  282.                         if(obj instanceof Baselineable){  
  283.                             Baselineable baselineable = (Baselineable)obj;  
  284.                             if(!results.contains(baselineable)){  
  285.                                 results.add(baselineable);  
  286.                             }  
  287.                         }                         
  288.                     }  
  289.                 } catch (Exception e) {  
  290.                     // TODO: handle exception  
  291.                     e.printStackTrace();  
  292.                 } finally {  
  293.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  294.                 }  
  295.                 return results;  
  296.             }  
  297.         } catch (Exception e) {  
  298.             e.printStackTrace();  
  299.         }  
  300.         return results;  
  301.     }     
  302.       
  303.       
  304.     /** 
  305.      * 为基线添加内容对象 
  306.      * @param baseline  目标基线 
  307.      * @param baselineable  基线内容对象 
  308.      * @return  添加好的基线对象 
  309.      */  
  310.     public static ManagedBaseline addBaselineable(ManagedBaseline baseline, Baselineable baselineable){       
  311.         try {  
  312.             if (!RemoteMethodServer.ServerFlag) {  
  313.                 return (ManagedBaseline) RemoteMethodServer.getDefault().invoke("addBaselineable", CSCBaseline.class.getName(), null,  
  314.                         new Class[] {ManagedBaseline.class, Baselineable.class},  
  315.                         new Object[] {baseline, baselineable});  
  316.             } else {                      
  317.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  318.                 try {  
  319.                     baseline = (ManagedBaseline) BaselineHelper.service.addToBaseline(baselineable, baseline);  
  320.                     baseline = (ManagedBaseline) PersistenceHelper.manager.refresh(baseline);     
  321.                 } catch (Exception e) {  
  322.                     // TODO: handle exception  
  323.                     e.printStackTrace();  
  324.                 } finally {  
  325.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  326.                 }  
  327.                 return baseline;  
  328.             }  
  329.         } catch (Exception e) {  
  330.             e.printStackTrace();  
  331.         }  
  332.         return baseline;  
  333.     }     
  334.       
  335.       
  336.     /** 
  337.      * 为基线移除内容对象 
  338.      * @param baseline  目标基线 
  339.      * @param baselineable  待移除的基线内容对象 
  340.      * @return  移除好的基线对象 
  341.      */  
  342.     public static ManagedBaseline removeBaselineable(ManagedBaseline baseline, Baselineable baselineable){        
  343.         try {  
  344.             if (!RemoteMethodServer.ServerFlag) {  
  345.                 return (ManagedBaseline) RemoteMethodServer.getDefault().invoke("removeBaselineable", CSCBaseline.class.getName(), null,  
  346.                         new Class[] {ManagedBaseline.class, Baselineable.class},  
  347.                         new Object[] {baseline, baselineable});  
  348.             } else {                      
  349.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  350.                 try {  
  351.                     baseline = (ManagedBaseline) BaselineHelper.service.removeFromBaseline(baselineable, baseline);  
  352.                     baseline = (ManagedBaseline) PersistenceHelper.manager.refresh(baseline);     
  353.                 } catch (Exception e) {  
  354.                     // TODO: handle exception  
  355.                     e.printStackTrace();  
  356.                 } finally {  
  357.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  358.                 }  
  359.                 return baseline;  
  360.             }  
  361.         } catch (Exception e) {  
  362.             e.printStackTrace();  
  363.         }  
  364.         return baseline;  
  365.     }  
  366.       
  367.       
  368.     public static void main(String[] args) throws WTException {  
  369.         //************************ Test of getBaseline ********************************  
  370. /*      ManagedBaseline baseline = CSCBaseline.getBaseline(args[0], Boolean.parseBoolean(args[1]));  
  371.         System.out.println("Result Baseline = " + baseline);*/  
  372.           
  373.         //************************ Test of createBaseline ********************************  
  374. /*      PDMLinkProduct product = CSCContainer.getPDMLinkProduct(args[2], false);  
  375.         ReferenceFactory rf = new ReferenceFactory();  
  376.         WTContainerRef containerRef = (WTContainerRef) rf.getReference(product);  
  377.           
  378.         HashMap<String, String> attributes = new HashMap<String, String>();  
  379.         attributes.put(CSCBaseline.FOLDER, "/Default/TestCreateBaselineFolder");  
  380.         attributes.put(CSCBaseline.TYPE, "TestBaselineType");  
  381.           
  382.         ManagedBaseline baseline = CSCBaseline.createBaseline(args[0], args[1], attributes, containerRef);  
  383.         System.out.println("Result Baseline = " + baseline);*/  
  384.           
  385.         //************************ Test of getBaselineItems ********************************  
  386. /*      ManagedBaseline baseline = CSCBaseline.getBaseline(args[0], false);  
  387.         ArrayList<Baselineable> baselineables = CSCBaseline.getBaselineItems(baseline);  
  388.         for (int i = 0; i < baselineables.size(); i++) {  
  389.             System.out.println("Result Baselineables = " + baselineables.get(i));  
  390.         }*/  
  391.           
  392.         //************************ Test of getBaselineByBaselineable ********************************  
  393. /*      WTPart wtpart = CSCPart.getPart(args[0], false);  
  394.         ArrayList<ManagedBaseline> baselines = CSCBaseline.getBaselineByBaselineable(wtpart);  
  395.         for (int i = 0; i < baselines.size(); i++) {  
  396.             System.out.println("Result Baseline = " + baselines.get(i));  
  397.         }*/  
  398.           
  399.         //************************ Test of addBaselineable ********************************  
  400. /*      WTPart wtpart = CSCPart.getPart(args[0], false);  
  401.         ManagedBaseline baseline = CSCBaseline.getBaseline(args[1], false);  
  402.         baseline = CSCBaseline.addBaselineable(baseline, wtpart);  
  403.         System.out.println("Result Baseline = " + baseline);*/  
  404.           
  405.         //************************ Test of removeBaselineable ********************************  
  406. /*      WTPart wtpart = CSCPart.getPart(args[0], false);  
  407.         ManagedBaseline baseline = CSCBaseline.getBaseline(args[1], false);  
  408.         baseline = CSCBaseline.removeBaselineable(baseline, wtpart);  
  409.         System.out.println("Result Baseline = " + baseline);*/        
  410.     }  
  411. }  
该工具类封装了对于ProblemReport, ChangeRequest, ChangeOrder的一系列底层操作 windchill
Java代码   收藏代码
  1. package ext.csc.util.core;  
  2.   
  3. import java.io.File;  
  4. import java.io.FileOutputStream;  
  5. import java.io.IOException;  
  6. import java.io.InputStream;  
  7. import java.io.Serializable;  
  8. import java.sql.Timestamp;  
  9. import java.text.DecimalFormat;  
  10. import java.text.ParseException;  
  11. import java.text.SimpleDateFormat;  
  12. import java.util.ArrayList;  
  13. import java.util.Date;  
  14. import java.util.HashMap;  
  15. import java.util.Vector;  
  16.   
  17. import wt.change2.AffectedActivityData;  
  18. import wt.change2.Category;  
  19. import wt.change2.ChangeHelper2;  
  20. import wt.change2.ChangeItemIfc;  
  21. import wt.change2.ChangeNoticeComplexity;  
  22. import wt.change2.ChangeRecord2;  
  23. import wt.change2.Changeable2;  
  24. import wt.change2.Complexity;  
  25. import wt.change2.IssuePriority;  
  26. import wt.change2.RelevantRequestData2;  
  27. import wt.change2.ReportedAgainst;  
  28. import wt.change2.RequestPriority;  
  29. import wt.change2.WTChangeActivity2;  
  30. import wt.change2.WTChangeIssue;  
  31. import wt.change2.WTChangeOrder2;  
  32. import wt.change2.WTChangeRequest2;  
  33. import wt.content.ApplicationData;  
  34. import wt.content.ContentHelper;  
  35. import wt.content.ContentHolder;  
  36. import wt.content.ContentRoleType;  
  37. import wt.content.ContentServerHelper;  
  38. import wt.fc.PersistenceHelper;  
  39. import wt.fc.PersistenceServerHelper;  
  40. import wt.fc.QueryResult;  
  41. import wt.fc.collections.WTValuedHashMap;  
  42. import wt.folder.Folder;  
  43. import wt.folder.FolderHelper;  
  44. import wt.inf.container.WTContainerRef;  
  45. import wt.method.RemoteAccess;  
  46. import wt.method.RemoteMethodServer;  
  47. import wt.query.QuerySpec;  
  48. import wt.query.SearchCondition;  
  49. import wt.session.SessionServerHelper;  
  50. import wt.util.WTException;  
  51.   
  52. import com.ptc.core.meta.common.TypeIdentifier;  
  53. import com.ptc.core.meta.common.TypeIdentifierHelper;  
  54. import com.ptc.windchill.enterprise.copy.server.CoreMetaUtility;  
  55.   
  56. import ext.csc.util.common.CSCDebug;  
  57.   
  58. /** 
  59.  * 该工具类封装了对于ProblemReport, ChangeRequest, ChangeOrder的一系列底层操作 
  60.  * @author mliu 
  61.  * 
  62.  */  
  63. public class CSCChange implements RemoteAccess, Serializable{  
  64.     private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCChange.class);          
  65.       
  66.     public static String CATEGORY = "CATEGORY"//类别  
  67.     public static String PRIORITY = "PRIORITY"//优先级  
  68.     public static String DESCRIPTION = "DESCRIPTION"//描述  
  69.     public static String TYPE = "TYPE"//类型  
  70.     public static String FOLDER = "FOLDER"//创建文件夹 (默认:/Default)  
  71.     public static String NEED_DATE = "NEEDDATE";    //需要日期 (yyyy-MM-dd)  
  72.     public static String RESOLUTION_DATE = "RESOLUTION_DATE"//解决方案日期 (yyyy-MM-dd)  
  73.     public static String RECURRING_COST_EST = "RECURRING_COST_EST"//经常性成本  
  74.     public static String NON_RECURRING_COST_EST = "NON_RECURRING_COST_EST"//非经常性成本  
  75.     public static String COMPLEXITY = "COMPLEXITY"//复杂性  
  76.   
  77.     private static final long serialVersionUID = 5091068291906960116L;  
  78.   
  79.     /** 
  80.      * 创建问题报告 
  81.      * @param number    编号 (默认为系统的 WTCHANGEISSUEID_SEQ)  
  82.      * @param name      名称 (必须) 
  83.      * @param requester 请求者(必须) 
  84.      * @param attributes    属性对应表  
  85.      * @param secondaryContents 附件列表 (String FilePath 或者 InputStream) 
  86.      * @param containerRef  上下文 (必须) 
  87.      * @return  如果指定编号的问题报告存在,则返回该问题报告的对象,若不存在,则返回创建后的问题报告 
  88.      */  
  89.     public static WTChangeIssue createProblemReport(String number, String name, String requester, HashMap attributes,   
  90.                                                 ArrayList secondaryContents, WTContainerRef containerRef){  
  91.         try {  
  92.             if (!RemoteMethodServer.ServerFlag) {  
  93.                 return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("createProblemReport", CSCChange.class.getName(), null,  
  94.                         new Class[] {String.class, String.class, String.class, HashMap.class,  
  95.                                         ArrayList.class, WTContainerRef.class},  
  96.                         new Object[] {number, name, requester, attributes,  
  97.                                         secondaryContents, containerRef});  
  98.             } else {  
  99.                 WTChangeIssue pr = null;  
  100.       
  101.                 try {  
  102.                       
  103.                     String prDesc = "";  
  104.                     String prType = "";  
  105.                     String prFolder = "";  
  106.                     String prCategory = "";  
  107.                     String prProirity = "";  
  108.                       
  109.                     if(attributes != null){  
  110.                         prDesc = (String)attributes.get(CSCChange.DESCRIPTION);  
  111.                         prType = (String)attributes.get(CSCChange.TYPE);  
  112.                         prFolder = (String)attributes.get(CSCChange.FOLDER);  
  113.                         prCategory = (String)attributes.get(CSCChange.CATEGORY);  
  114.                         prProirity = (String)attributes.get(CSCChange.PRIORITY);  
  115.                     }  
  116.                       
  117.                     if(containerRef == null){  
  118.                         return null;  
  119.                     }  
  120.                       
  121.                     //设置编号默认值 (默认为系统的WTCHANGEISSUEID_SEQ)                     
  122.                     if(number == null || number.equalsIgnoreCase("")){  
  123.                         number = CSCChange.getDefaultChangeSeqNumber(WTChangeIssue.class);  
  124.                     }else{  
  125.                         //如果此编号问题报告已存在,则返回该问题报告  
  126.                         WTChangeIssue existPR = CSCChange.getProblemReport(number, false);  
  127.                         if(existPR != null){  
  128.                             return existPR;  
  129.                         }  
  130.                     }  
  131.                       
  132.                     if(name == null || name.equalsIgnoreCase("")){  
  133.                         return null;  
  134.                     }  
  135.                       
  136.                     if(requester == null){  
  137.                         return null;  
  138.                     }  
  139.                       
  140.                     if(prDesc == null){  
  141.                         prDesc = "";  
  142.                     }  
  143.                       
  144.                     //设置默认类型  (默认:wt.change2.WTChangeIssue)   
  145.                     if(prType == null || prType.equalsIgnoreCase("")){  
  146.                         prType = "wt.change2.WTChangeIssue";  
  147.                     }  
  148.                                           
  149.                     //设置默认文件夹  (默认:/Default)      
  150.                     if(prFolder == null || prFolder.equalsIgnoreCase("")){  
  151.                         prFolder = "/Default";  
  152.                     }else{  
  153.                          if(!prFolder.startsWith("/Default")){  
  154.                              prFolder = "/Default/" + prFolder;  
  155.                          }  
  156.                     }  
  157.                       
  158.                     pr = WTChangeIssue.newWTChangeIssue();  
  159.                     pr.setNumber(number);  
  160.                     pr.setName(name);  
  161.                     pr.setRequester(requester);  
  162.                       
  163.                     //设置问题报告描述  
  164.                     pr.setDescription(prDesc);  
  165.                       
  166.                     //设置问题报告类型  
  167.                     if(prType != null){  
  168.                         TypeIdentifier id = TypeIdentifierHelper.getTypeIdentifier(prType);  
  169.                         pr = (WTChangeIssue) CoreMetaUtility.setType(pr, id);  
  170.                     }  
  171.                       
  172.                     //设置上下文  
  173.                     pr.setContainerReference(containerRef);  
  174.                       
  175.                     //设置文件夹  
  176.                     Folder location = null;   
  177.                         //查询文件夹是否存在  
  178.                     try {  
  179.                         location = FolderHelper.service.getFolder(prFolder,containerRef);  
  180.                     } catch (Exception e) {  
  181.                         location = null;  
  182.                     }  
  183.                         //若文件夹不存在,则创建该文件夹  
  184.                     if(location == null)  
  185.                         location = FolderHelper.service.saveFolderPath(prFolder, containerRef);  
  186.                         //设置文件夹到Doc对象  
  187.                     if (location != null) {  
  188.                         WTValuedHashMap map = new WTValuedHashMap();  
  189.                         map.put(pr, location);  
  190.                         FolderHelper.assignLocations(map);  
  191.                     }     
  192.                       
  193.                     //设置问题报告类别  
  194.                     Category category = null;  
  195.                     try {  
  196.                         category = Category.toCategory(prCategory);  
  197.                     } catch (Exception e) {  
  198.                         // TODO: handle exception  
  199.                         e.printStackTrace();  
  200.                         category = Category.getCategoryDefault();  
  201.                     }         
  202.                     pr.setCategory(category);  
  203.                       
  204.                     //设置问题报告优先级  
  205.                     IssuePriority priority = null;  
  206.                     try {  
  207.                         priority = IssuePriority.toIssuePriority(prProirity);  
  208.                     } catch (Exception e) {  
  209.                         // TODO: handle exception  
  210.                         e.printStackTrace();  
  211.                         priority = IssuePriority.getIssuePriorityDefault();  
  212.                     }  
  213.                     pr.setIssuePriority(priority);  
  214.                       
  215.                     pr = (WTChangeIssue) PersistenceHelper.manager.save(pr);  
  216.                     pr = (WTChangeIssue) PersistenceHelper.manager.refresh(pr);                       
  217.                       
  218.                     //设置附件  
  219.                     if(secondaryContents != null){  
  220.                         for (int i = 0; i < secondaryContents.size(); i++) {  
  221.                             Object secondaryContent = secondaryContents.get(i);  
  222.                               
  223.                             ApplicationData applicationdata = ApplicationData.newApplicationData(pr);  
  224.                             applicationdata.setRole(ContentRoleType.SECONDARY);               
  225.                             if(secondaryContent instanceof String){  
  226.                                 String filePath = (String)secondaryContent;  
  227.                                 applicationdata = ContentServerHelper.service.updateContent(pr, applicationdata, filePath);       
  228.                             }else if(secondaryContent instanceof InputStream){  
  229.                                 InputStream ins = (InputStream)secondaryContent;  
  230.                                 applicationdata = ContentServerHelper.service.updateContent(pr, applicationdata, ins);        
  231.                             }  
  232.                         }  
  233.                     }  
  234.                       
  235.                     pr = (WTChangeIssue) PersistenceServerHelper.manager.restore(pr);  
  236.                 } catch (Exception e) {  
  237.                     // TODO: handle exception  
  238.                     e.printStackTrace();  
  239.                 }         
  240.                   
  241.                 return pr;  
  242.             }   
  243.         }catch (Exception e) {  
  244.                 e.printStackTrace();  
  245.         }  
  246.         return null;  
  247.     }  
  248.   
  249.   
  250.   
  251.     /** 
  252.      * 通过编号查找问题报告 
  253.      * @param number    查询问题报告编号条件 
  254.      * @param accessControlled  是否受到权限制约 
  255.      * @return  返回结果问题报告 
  256.      */  
  257.     public static WTChangeIssue getProblemReport(String number, boolean accessControlled) {  
  258.         try {  
  259.             number = number.toUpperCase();  
  260.               
  261.             if (!RemoteMethodServer.ServerFlag) {  
  262.                 return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("getProblemReport", CSCChange.class.getName(), null,  
  263.                         new Class[] {String.classboolean.class},  
  264.                         new Object[] {number, accessControlled});  
  265.             } else {  
  266.                 WTChangeIssue pr = null;  
  267.                   
  268.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);  
  269.                 try {  
  270.                     QuerySpec spec = new QuerySpec(WTChangeIssue.class);  
  271.                     spec.appendWhere(  
  272.                             new SearchCondition(WTChangeIssue.class,  
  273.                                     WTChangeIssue.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });  
  274.                       
  275.                     QueryResult qr = PersistenceHelper.manager.find(spec);  
  276.                     if (qr.hasMoreElements()){  
  277.                         pr = (WTChangeIssue)qr.nextElement();  
  278.                     }  
  279.                 } catch (Exception e) {  
  280.                     // TODO: handle exception  
  281.                     e.printStackTrace();  
  282.                 } finally {  
  283.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  284.                 }  
  285.   
  286.                 return pr;  
  287.             }  
  288.         } catch (Exception e) {  
  289.             e.printStackTrace();  
  290.         }  
  291.         return null;  
  292.     }  
  293.           
  294.       
  295.       
  296.     /** 
  297.      * 通过问题报告得到问题报告内容 
  298.      * @param pr    条件问题报告 
  299.      * @return  问题报告内容对象集 
  300.      */  
  301.     public static ArrayList<Changeable2> getProblemReportItems(WTChangeIssue pr){  
  302.         ArrayList<Changeable2> results = new ArrayList<Changeable2>();  
  303.           
  304.         try {  
  305.             if (!RemoteMethodServer.ServerFlag) {  
  306.                 return (ArrayList<Changeable2>) RemoteMethodServer.getDefault().invoke("getProblemReportItems", CSCChange.class.getName(), null,  
  307.                         new Class[] {WTChangeIssue.class},  
  308.                         new Object[] {pr});  
  309.             } else {                      
  310.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  311.                 try {  
  312.                     QueryResult qr = ChangeHelper2.service.getChangeables(pr);  
  313.                     while(qr.hasMoreElements()){  
  314.                         Object obj = qr.nextElement();  
  315.                         if(obj instanceof Changeable2){  
  316.                             Changeable2 changeable = (Changeable2)obj;  
  317.                             if(!results.contains(changeable)){  
  318.                                 results.add(changeable);  
  319.                             }  
  320.                         }                         
  321.                     }  
  322.                 } catch (Exception e) {  
  323.                     // TODO: handle exception  
  324.                     e.printStackTrace();  
  325.                 } finally {  
  326.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  327.                 }  
  328.                 return results;  
  329.             }  
  330.         } catch (Exception e) {  
  331.             e.printStackTrace();  
  332.         }  
  333.         return results;  
  334.     }  
  335.       
  336.       
  337.   
  338.     /** 
  339.      * 通过问题报告内容对象查找问题报告 
  340.      * @param changeable    查询内容对象 
  341.      * @return  返回结果问题报告集 
  342.      */  
  343.     public static ArrayList<WTChangeIssue> getProblemReportByChangeable(Changeable2 changeable) {  
  344.         ArrayList<WTChangeIssue> results = new ArrayList<WTChangeIssue>();  
  345.           
  346.         try {  
  347.             if (!RemoteMethodServer.ServerFlag) {  
  348.                 return (ArrayList<WTChangeIssue>) RemoteMethodServer.getDefault().invoke("getProblemReportByChangeable", CSCChange.class.getName(), null,  
  349.                         new Class[] {Changeable2.class},  
  350.                         new Object[] {changeable});  
  351.             } else {  
  352.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  353.                 try {  
  354.                     QueryResult qr = ChangeHelper2.service.getReportedAgainstChangeIssue(changeable);  
  355.                     while (qr.hasMoreElements()){                 
  356.                         WTChangeIssue pr = (WTChangeIssue)qr.nextElement();   
  357.                         if(!results.contains(pr)){  
  358.                             results.add(pr);  
  359.                         }                         
  360.                     }  
  361.                 } catch (Exception e) {  
  362.                     // TODO: handle exception  
  363.                     e.printStackTrace();  
  364.                 } finally {  
  365.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  366.                 }  
  367.   
  368.                 return results;  
  369.             }  
  370.         } catch (Exception e) {  
  371.             e.printStackTrace();  
  372.         }  
  373.         return null;  
  374.     }     
  375.       
  376.       
  377.     /** 
  378.      * 通过问题报告得到相关联的变更请求 
  379.      * @param pr    条件问题报告 
  380.      * @return  变更请求对象 
  381.      */  
  382.     public static ArrayList<WTChangeRequest2> getChangeRequestByProblemReport(WTChangeIssue pr){  
  383.         ArrayList<WTChangeRequest2> results = new ArrayList<WTChangeRequest2>();  
  384.           
  385.         try {  
  386.             if (!RemoteMethodServer.ServerFlag) {  
  387.                 return (ArrayList<WTChangeRequest2>) RemoteMethodServer.getDefault().invoke("getChangeRequestByProblemReport", CSCChange.class.getName(), null,  
  388.                         new Class[] {WTChangeIssue.class},  
  389.                         new Object[] {pr});  
  390.             } else {                      
  391.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  392.                 try {  
  393.                     QueryResult qr = ChangeHelper2.service.getChangeRequest(pr);  
  394.                     while (qr.hasMoreElements()){                 
  395.                         WTChangeRequest2 cr = (WTChangeRequest2)qr.nextElement();     
  396.                         if(!results.contains(cr)){  
  397.                             results.add(cr);  
  398.                         }                         
  399.                     }  
  400.                 } catch (Exception e) {  
  401.                     // TODO: handle exception  
  402.                     e.printStackTrace();  
  403.                 } finally {  
  404.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  405.                 }  
  406.                 return results;  
  407.             }  
  408.         } catch (Exception e) {  
  409.             e.printStackTrace();  
  410.         }  
  411.         return results;  
  412.     }  
  413.   
  414.       
  415.       
  416.     /** 
  417.      * 为问题报告添加内容对象 
  418.      * @param pr    目标问题报告 
  419.      * @param changeable    问题报告内容对象 
  420.      * @return  添加好的问题报告对象 
  421.      */  
  422.     public static WTChangeIssue addChangeableToProblemReport(WTChangeIssue pr, Changeable2 changeable){       
  423.         try {  
  424.             if (!RemoteMethodServer.ServerFlag) {  
  425.                 return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("addChangeableToProblemReport", CSCChange.class.getName(), null,  
  426.                         new Class[] {WTChangeIssue.class, Changeable2.class},  
  427.                         new Object[] {pr, changeable});  
  428.             } else {                      
  429.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  430.                 try {  
  431.                     Vector changeables = new Vector();  
  432.                     changeables.add(changeable);  
  433.                     ChangeHelper2.service.storeAssociations(ReportedAgainst.class, pr, changeables);  
  434.                     pr = (WTChangeIssue) PersistenceHelper.manager.refresh(pr);   
  435.                 } catch (Exception e) {  
  436.                     // TODO: handle exception  
  437.                     e.printStackTrace();  
  438.                 } finally {  
  439.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  440.                 }  
  441.                 return pr;  
  442.             }  
  443.         } catch (Exception e) {  
  444.             e.printStackTrace();  
  445.         }  
  446.         return pr;  
  447.     }  
  448.   
  449.   
  450.   
  451.     /** 
  452.      * 为问题报告添加变更请求对象 
  453.      * @param pr    目标问题报告 
  454.      * @param cr    变更请求对象 
  455.      * @return  添加好的问题报告对象 
  456.      */  
  457.     public static WTChangeIssue addChangeRequestToProblemReport(WTChangeIssue pr, WTChangeRequest2 cr){       
  458.         try {  
  459.             if (!RemoteMethodServer.ServerFlag) {  
  460.                 return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("addChangeRequestToProblemReport", CSCChange.class.getName(), null,  
  461.                         new Class[] {WTChangeIssue.class, WTChangeRequest2.class},  
  462.                         new Object[] {pr, cr});  
  463.             } else {                      
  464.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  465.                 try {                     
  466.                     ChangeHelper2.service.saveFormalizedBy(cr, pr);  
  467.                     pr = (WTChangeIssue) PersistenceHelper.manager.refresh(pr);   
  468.                 } catch (Exception e) {  
  469.                     // TODO: handle exception  
  470.                     e.printStackTrace();  
  471.                 } finally {  
  472.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  473.                 }  
  474.                 return pr;  
  475.             }  
  476.         } catch (Exception e) {  
  477.             e.printStackTrace();  
  478.         }  
  479.         return pr;  
  480.     }  
  481.   
  482.   
  483.   
  484.     /** 
  485.      * 为问题报告移除内容对象 
  486.      * @param pr    目标问题报告 
  487.      * @param changeable    问题报告内容对象 
  488.      * @return  移除好的问题报告对象 
  489.      */  
  490.     public static WTChangeIssue removeChangeableFromProblemReport(WTChangeIssue pr, Changeable2 changeable){          
  491.         try {  
  492.             if (!RemoteMethodServer.ServerFlag) {  
  493.                 return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("removeChangeableFromProblemReport", CSCChange.class.getName(), null,  
  494.                         new Class[] {WTChangeIssue.class, Changeable2.class},  
  495.                         new Object[] {pr, changeable});  
  496.             } else {                      
  497.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  498.                 try {  
  499.                     ChangeHelper2.service.unattachChangeable(changeable, pr, ReportedAgainst.class, ReportedAgainst.CHANGE_ISSUE_ROLE);  
  500.                     pr = (WTChangeIssue) PersistenceHelper.manager.refresh(pr);   
  501.                 } catch (Exception e) {  
  502.                     // TODO: handle exception  
  503.                     e.printStackTrace();  
  504.                 } finally {  
  505.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  506.                 }  
  507.                 return pr;  
  508.             }  
  509.         } catch (Exception e) {  
  510.             e.printStackTrace();  
  511.         }  
  512.         return pr;  
  513.     }  
  514.   
  515.   
  516.   
  517.     /** 
  518.      * 为问题报告移除变更请求对象 
  519.      * @param pr    目标问题报告 
  520.      * @param cr    变更请求对象 
  521.      * @return  移除好的问题报告对象 
  522.      */  
  523.     public static WTChangeIssue removeChangeRequestFromProblemReport(WTChangeIssue pr, WTChangeRequest2 cr){          
  524.         try {  
  525.             if (!RemoteMethodServer.ServerFlag) {  
  526.                 return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("removeChangeRequestFromProblemReport", CSCChange.class.getName(), null,  
  527.                         new Class[] {WTChangeIssue.class, WTChangeRequest2.class},  
  528.                         new Object[] {pr, cr});  
  529.             } else {                      
  530.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  531.                 try {  
  532.                     ChangeHelper2.service.deleteFormalizedBy(cr, pr);  
  533.                     pr = (WTChangeIssue) PersistenceHelper.manager.refresh(pr);   
  534.                 } catch (Exception e) {  
  535.                     // TODO: handle exception  
  536.                     e.printStackTrace();  
  537.                 } finally {  
  538.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  539.                 }  
  540.                 return pr;  
  541.             }  
  542.         } catch (Exception e) {  
  543.             e.printStackTrace();  
  544.         }  
  545.         return pr;  
  546.     }  
  547.   
  548.   
  549.   
  550.     /** 
  551.      * 创建变更请求 
  552.      * @param number    编号 (默认为系统的 WTCHANGEREQUEST2ID_SEQ)   
  553.      * @param name      名称 (必须) 
  554.      * @param attributes    属性对应表  
  555.      * @param secondaryContent  附件 (String FilePath 或者 InputStream) 
  556.      * @param containerRef  上下文 (必须) 
  557.      * @return  如果指定编号的变更请求存在,则返回该变更请求对象,若不存在,则返回创建后的变更请求 
  558.      */  
  559.     public static WTChangeRequest2 createChangeRequest(String number, String name, HashMap attributes,   
  560.                                                 ArrayList secondaryContents, WTContainerRef containerRef){  
  561.         try {  
  562.             if (!RemoteMethodServer.ServerFlag) {  
  563.                 return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("createChangeRequest", CSCChange.class.getName(), null,  
  564.                         new Class[] {String.class, String.class, HashMap.class,  
  565.                                         ArrayList.class, WTContainerRef.class},  
  566.                         new Object[] {number, name, attributes,  
  567.                                         secondaryContents, containerRef});  
  568.             } else {  
  569.                 WTChangeRequest2 cr = null;  
  570.   
  571.                 try {  
  572.                       
  573.                     String crDesc = "";  
  574.                     String crType = "";  
  575.                     String crFolder = "";  
  576.                     String crCategory = "";  
  577.                     String crProirity = "";  
  578.                     String crNeedDate = "";  
  579.                     String crResolutionDate = "";  
  580.                     String crRecurringCostEst = "";  
  581.                     String crNonRecurringCostEst = "";  
  582.                     String crComplexity = "";  
  583.                       
  584.                     if(attributes != null){  
  585.                         crDesc = (String)attributes.get(CSCChange.DESCRIPTION);  
  586.                         crType = (String)attributes.get(CSCChange.TYPE);  
  587.                         crFolder = (String)attributes.get(CSCChange.FOLDER);  
  588.                         crCategory = (String)attributes.get(CSCChange.CATEGORY);  
  589.                         crProirity = (String)attributes.get(CSCChange.PRIORITY);  
  590.                         crNeedDate = (String)attributes.get(CSCChange.NEED_DATE);  
  591.                         crResolutionDate = (String)attributes.get(CSCChange.RESOLUTION_DATE);  
  592.                         crRecurringCostEst = (String)attributes.get(CSCChange.RECURRING_COST_EST);  
  593.                         crNonRecurringCostEst = (String)attributes.get(CSCChange.NON_RECURRING_COST_EST);  
  594.                         crComplexity = (String)attributes.get(CSCChange.COMPLEXITY);  
  595.                     }  
  596.                       
  597.                     if(containerRef == null){  
  598.                         return null;  
  599.                     }  
  600.                       
  601.                     //设置编号默认值 (默认为系统的WTCHANGEISSUEID_SEQ)                     
  602.                     if(number == null || number.equalsIgnoreCase("")){  
  603.                         number = CSCChange.getDefaultChangeSeqNumber(WTChangeRequest2.class);  
  604.                     }else{  
  605.                         //如果此编号变更请求已存在,则返回该变更请求  
  606.                         WTChangeRequest2 existCR = CSCChange.getChangeRequest(number, false);  
  607.                         if(existCR != null){  
  608.                             return existCR;  
  609.                         }  
  610.                     }  
  611.                       
  612.                     if(name == null || name.equalsIgnoreCase("")){  
  613.                         return null;  
  614.                     }  
  615.                       
  616.                     if(crDesc == null){  
  617.                         crDesc = "";  
  618.                     }  
  619.                       
  620.                     //设置默认类型  (默认:wt.change2.WTChangeRequest2)    
  621.                     if(crType == null || crType.equalsIgnoreCase("")){  
  622.                         crType = "wt.change2.WTChangeRequest2";  
  623.                     }  
  624.                                           
  625.                     //设置默认文件夹  (默认:/Default)      
  626.                     if(crFolder == null || crFolder.equalsIgnoreCase("")){  
  627.                         crFolder = "/Default";  
  628.                     }else{  
  629.                          if(!crFolder.startsWith("/Default")){  
  630.                              crFolder = "/Default/" + crFolder;  
  631.                          }  
  632.                     }  
  633.                       
  634.                     cr = WTChangeRequest2.newWTChangeRequest2();  
  635.                     cr.setNumber(number);  
  636.                     cr.setName(name);  
  637.                       
  638.                     //设置变更请求描述  
  639.                     cr.setDescription(crDesc);  
  640.                       
  641.                     //设置变更请求类型  
  642.                     if(crType != null){  
  643.                         TypeIdentifier id = TypeIdentifierHelper.getTypeIdentifier(crType);  
  644.                         cr = (WTChangeRequest2) CoreMetaUtility.setType(cr, id);  
  645.                     }  
  646.                       
  647.                     //设置上下文  
  648.                     cr.setContainerReference(containerRef);  
  649.                       
  650.                     //设置文件夹  
  651.                     Folder location = null;   
  652.                         //查询文件夹是否存在  
  653.                     try {  
  654.                         location = FolderHelper.service.getFolder(crFolder,containerRef);  
  655.                     } catch (Exception e) {  
  656.                         location = null;  
  657.                     }  
  658.                         //若文件夹不存在,则创建该文件夹  
  659.                     if(location == null)  
  660.                         location = FolderHelper.service.saveFolderPath(crFolder, containerRef);  
  661.                         //设置文件夹到Doc对象  
  662.                     if (location != null) {  
  663.                         WTValuedHashMap map = new WTValuedHashMap();  
  664.                         map.put(cr, location);  
  665.                         FolderHelper.assignLocations(map);  
  666.                     }     
  667.                       
  668.                     //设置变更请求类别  
  669.                     Category category = null;  
  670.                     try {  
  671.                         category = Category.toCategory(crCategory);  
  672.                     } catch (Exception e) {  
  673.                         // TODO: handle exception  
  674.                         e.printStackTrace();  
  675.                         category = Category.getCategoryDefault();  
  676.                     }         
  677.                     cr.setCategory(category);  
  678.                       
  679.                     //设置变更请求优先级  
  680.                     RequestPriority priority = null;  
  681.                     try {  
  682.                         priority = RequestPriority.toRequestPriority(crProirity);  
  683.                     } catch (Exception e) {  
  684.                         // TODO: handle exception  
  685.                         e.printStackTrace();  
  686.                         priority = RequestPriority.getRequestPriorityDefault();  
  687.                     }  
  688.                     cr.setRequestPriority(priority);  
  689.                       
  690.                     //设置需要日期  
  691.                     if(crNeedDate != null && !crNeedDate.equals("")){  
  692.                         try {  
  693.                             SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");  
  694.                             Date date = formatter.parse(crNeedDate);  
  695.                             cr.setNeedDate(new Timestamp(date.getTime()));  
  696.                         } catch (Exception e) {  
  697.                             // TODO: handle exception  
  698.                             e.printStackTrace();  
  699.                         }  
  700.                     }  
  701.                       
  702.                     //设置解决方案日期  
  703.                     if(crResolutionDate != null && !crResolutionDate.equals("")){  
  704.                         try {  
  705.                             SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");  
  706.                             Date date = formatter.parse(crResolutionDate);  
  707.                             cr.setNeedDate(new Timestamp(date.getTime()));  
  708.                         } catch (Exception e) {  
  709.                             // TODO: handle exception  
  710.                         }  
  711.                     }  
  712.                       
  713.                     //设置经常性成本  
  714.                     if(crRecurringCostEst != null && !crRecurringCostEst.equals("")){  
  715.                         try {  
  716.                             cr.setRecurringCostEst(crRecurringCostEst);  
  717.                         } catch (Exception e) {  
  718.                             // TODO: handle exception  
  719.                         }  
  720.                     }  
  721.                       
  722.                       
  723.                     //设置非经常性成本  
  724.                     if(crNonRecurringCostEst != null && !crNonRecurringCostEst.equals("")){  
  725.                         try {  
  726.                             cr.setNonRecurringCostEst(crNonRecurringCostEst);  
  727.                         } catch (Exception e) {  
  728.                             // TODO: handle exception  
  729.                         }  
  730.                     }  
  731.                       
  732.                     //设置复杂性  
  733.                     Complexity complexity = null;  
  734.                     if(crComplexity != null && !crComplexity.equals("")){  
  735.                         try {  
  736.                             complexity = Complexity.toComplexity(crComplexity);  
  737.                             cr.setComplexity(complexity);  
  738.                         } catch (Exception e) {  
  739.                             // TODO: handle exception  
  740.                             complexity = Complexity.getComplexityDefault();  
  741.                             cr.setComplexity(complexity);  
  742.                         }  
  743.                     }  
  744.   
  745.                       
  746.                     cr = (WTChangeRequest2) PersistenceHelper.manager.save(cr);  
  747.                     cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(cr);                        
  748.                       
  749.                     //设置附件  
  750.                     if(secondaryContents != null){  
  751.                         for (int i = 0; i < secondaryContents.size(); i++) {  
  752.                             Object secondaryContent = secondaryContents.get(i);  
  753.                               
  754.                             ApplicationData applicationdata = ApplicationData.newApplicationData(cr);  
  755.                             applicationdata.setRole(ContentRoleType.SECONDARY);               
  756.                             if(secondaryContent instanceof String){  
  757.                                 String filePath = (String)secondaryContent;  
  758.                                 applicationdata = ContentServerHelper.service.updateContent(cr, applicationdata, filePath);       
  759.                             }else if(secondaryContent instanceof InputStream){  
  760.                                 InputStream ins = (InputStream)secondaryContent;  
  761.                                 applicationdata = ContentServerHelper.service.updateContent(cr, applicationdata, ins);        
  762.                             }  
  763.                         }  
  764.                     }  
  765.                       
  766.                     cr = (WTChangeRequest2) PersistenceServerHelper.manager.restore(cr);  
  767.                 } catch (Exception e) {  
  768.                     // TODO: handle exception  
  769.                     e.printStackTrace();  
  770.                 }         
  771.                   
  772.                 return cr;  
  773.             }   
  774.         }catch (Exception e) {  
  775.                 e.printStackTrace();  
  776.         }  
  777.         return null;  
  778.     }     
  779.       
  780.       
  781.     /** 
  782.      * 通过编号查找变更请求 
  783.      * @param number    查询变更请求编号条件 
  784.      * @param accessControlled  是否受到权限制约 
  785.      * @return  返回结果变更请求 
  786.      */  
  787.     public static WTChangeRequest2 getChangeRequest(String number, boolean accessControlled) {  
  788.         try {  
  789.             number = number.toUpperCase();  
  790.               
  791.             if (!RemoteMethodServer.ServerFlag) {  
  792.                 return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("getChangeRequest", CSCChange.class.getName(), null,  
  793.                         new Class[] {String.classboolean.class},  
  794.                         new Object[] {number, accessControlled});  
  795.             } else {  
  796.                 WTChangeRequest2 ecr = null;  
  797.                   
  798.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);  
  799.                 try {  
  800.                     QuerySpec spec = new QuerySpec(WTChangeRequest2.class);  
  801.                     spec.appendWhere(  
  802.                             new SearchCondition(WTChangeRequest2.class,  
  803.                                     WTChangeRequest2.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });  
  804.                       
  805.                     QueryResult qr = PersistenceHelper.manager.find(spec);  
  806.                     if (qr.hasMoreElements()){  
  807.                         ecr = (WTChangeRequest2)qr.nextElement();  
  808.                     }  
  809.                 } catch (Exception e) {  
  810.                     // TODO: handle exception  
  811.                     e.printStackTrace();  
  812.                 } finally {  
  813.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  814.                 }  
  815.   
  816.                 return ecr;  
  817.             }  
  818.         } catch (Exception e) {  
  819.             e.printStackTrace();  
  820.         }  
  821.         return null;  
  822.     }     
  823.       
  824.       
  825.     /** 
  826.      * 通过变更请求得到变更请求内容 
  827.      * @param cr    条件变更请求 
  828.      * @return  变更请求内容对象集 
  829.      */  
  830.     public static ArrayList<Changeable2> getChangeRequestItems(WTChangeRequest2 cr){  
  831.         ArrayList<Changeable2> results = new ArrayList<Changeable2>();  
  832.           
  833.         try {  
  834.             if (!RemoteMethodServer.ServerFlag) {  
  835.                 return (ArrayList<Changeable2>) RemoteMethodServer.getDefault().invoke("getChangeRequestItems", CSCChange.class.getName(), null,  
  836.                         new Class[] {WTChangeRequest2.class},  
  837.                         new Object[] {cr});  
  838.             } else {                      
  839.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  840.                 try {  
  841.                     QueryResult qr = ChangeHelper2.service.getChangeables(cr);  
  842.                     while(qr.hasMoreElements()){  
  843.                         Object obj = qr.nextElement();  
  844.                         if(obj instanceof Changeable2){  
  845.                             Changeable2 changeable = (Changeable2)obj;  
  846.                             if(!results.contains(changeable)){  
  847.                                 results.add(changeable);  
  848.                             }  
  849.                         }                         
  850.                     }  
  851.                 } catch (Exception e) {  
  852.                     // TODO: handle exception  
  853.                     e.printStackTrace();  
  854.                 } finally {  
  855.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  856.                 }  
  857.                 return results;  
  858.             }  
  859.         } catch (Exception e) {  
  860.             e.printStackTrace();  
  861.         }  
  862.         return results;  
  863.     }     
  864.       
  865.   
  866.     /** 
  867.      * 通过变更请求内容对象查找变更请求 
  868.      * @param changeable    查询内容对象 
  869.      * @return  返回结果变更请求集 
  870.      */  
  871.     public static ArrayList<WTChangeRequest2> getChangeRequestByChangeable(Changeable2 changeable) {  
  872.         ArrayList<WTChangeRequest2> results = new ArrayList<WTChangeRequest2>();  
  873.           
  874.         try {  
  875.             if (!RemoteMethodServer.ServerFlag) {  
  876.                 return (ArrayList<WTChangeRequest2>) RemoteMethodServer.getDefault().invoke("getChangeRequestByChangeable", CSCChange.class.getName(), null,  
  877.                         new Class[] {Changeable2.class},  
  878.                         new Object[] {changeable});  
  879.             } else {  
  880.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  881.                 try {  
  882.                     QueryResult qr = ChangeHelper2.service.getRelevantChangeRequests(changeable);  
  883.                     while (qr.hasMoreElements()){                 
  884.                         WTChangeRequest2 cr = (WTChangeRequest2)qr.nextElement();     
  885.                         if(!results.contains(cr)){  
  886.                             results.add(cr);  
  887.                         }                         
  888.                     }  
  889.                 } catch (Exception e) {  
  890.                     // TODO: handle exception  
  891.                     e.printStackTrace();  
  892.                 } finally {  
  893.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  894.                 }  
  895.   
  896.                 return results;  
  897.             }  
  898.         } catch (Exception e) {  
  899.             e.printStackTrace();  
  900.         }  
  901.         return null;  
  902.     }     
  903.       
  904.     /** 
  905.      * 通过变更请求得到相关联的问题报告 
  906.      * @param cr    条件变更请求 
  907.      * @return  问题报告对象集 
  908.      */  
  909.     public static ArrayList<WTChangeIssue> getProblemReportByChangeRequest(WTChangeRequest2 cr){  
  910.         ArrayList<WTChangeIssue> results = new ArrayList<WTChangeIssue>();  
  911.           
  912.         try {  
  913.             if (!RemoteMethodServer.ServerFlag) {  
  914.                 return (ArrayList<WTChangeIssue>) RemoteMethodServer.getDefault().invoke("getProblemReportByChangeRequest", CSCChange.class.getName(), null,  
  915.                         new Class[] {WTChangeRequest2.class},  
  916.                         new Object[] {cr});  
  917.             } else {                      
  918.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  919.                 try {  
  920.                     QueryResult qr = ChangeHelper2.service.getChangeIssues(cr);  
  921.                     while (qr.hasMoreElements()){                 
  922.                         WTChangeIssue pr = (WTChangeIssue)qr.nextElement();   
  923.                         if(!results.contains(pr)){  
  924.                             results.add(pr);  
  925.                         }                         
  926.                     }  
  927.                 } catch (Exception e) {  
  928.                     // TODO: handle exception  
  929.                     e.printStackTrace();  
  930.                 } finally {  
  931.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  932.                 }  
  933.                 return results;  
  934.             }  
  935.         } catch (Exception e) {  
  936.             e.printStackTrace();  
  937.         }  
  938.         return results;  
  939.     }  
  940.       
  941.       
  942.     /** 
  943.      * 通过变更请求得到相关联的变更通告 
  944.      * @param cr    条件变更请求 
  945.      * @return  变更通告对象集 
  946.      */  
  947.     public static ArrayList<WTChangeOrder2> getChangeNoticeByChangeRequest(WTChangeRequest2 cr){  
  948.         ArrayList<WTChangeOrder2> results = new ArrayList<WTChangeOrder2>();  
  949.           
  950.         try {  
  951.             if (!RemoteMethodServer.ServerFlag) {  
  952.                 return (ArrayList<WTChangeOrder2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeByChangeRequest", CSCChange.class.getName(), null,  
  953.                         new Class[] {WTChangeRequest2.class},  
  954.                         new Object[] {cr});  
  955.             } else {                      
  956.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  957.                 try {  
  958.                     QueryResult qr = ChangeHelper2.service.getChangeOrders(cr);  
  959.                     while (qr.hasMoreElements()){                 
  960.                         WTChangeOrder2 cn = (WTChangeOrder2)qr.nextElement();     
  961.                         if(!results.contains(cn)){  
  962.                             results.add(cn);  
  963.                         }                         
  964.                     }  
  965.                 } catch (Exception e) {  
  966.                     // TODO: handle exception  
  967.                     e.printStackTrace();  
  968.                 } finally {  
  969.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  970.                 }  
  971.                 return results;  
  972.             }  
  973.         } catch (Exception e) {  
  974.             e.printStackTrace();  
  975.         }  
  976.         return results;  
  977.     }  
  978.   
  979.       
  980.     /** 
  981.      * 为变更请求添加内容对象 
  982.      * @param cr    目标变更请求 
  983.      * @param changeable    变更请求内容对象 
  984.      * @return  添加好的变更请求对象 
  985.      */  
  986.     public static WTChangeRequest2 addChangeableToChangeRequest(WTChangeRequest2 cr, Changeable2 changeable){         
  987.         try {  
  988.             if (!RemoteMethodServer.ServerFlag) {  
  989.                 return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("addChangeableToChangeRequest", CSCChange.class.getName(), null,  
  990.                         new Class[] {WTChangeRequest2.class, Changeable2.class},  
  991.                         new Object[] {cr, changeable});  
  992.             } else {                      
  993.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  994.                 try {  
  995.                     Vector changeables = new Vector();  
  996.                     changeables.add(changeable);  
  997.                     ChangeHelper2.service.storeAssociations(RelevantRequestData2.class, cr, changeables);  
  998.                     cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(cr);    
  999.                 } catch (Exception e) {  
  1000.                     // TODO: handle exception  
  1001.                     e.printStackTrace();  
  1002.                 } finally {  
  1003.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1004.                 }  
  1005.                 return cr;  
  1006.             }  
  1007.         } catch (Exception e) {  
  1008.             e.printStackTrace();  
  1009.         }  
  1010.         return cr;  
  1011.     }     
  1012.       
  1013.     /** 
  1014.      * 为变更请求添加变更通告对象 
  1015.      * @param cr    目标变更请求 
  1016.      * @param cn    变更通告对象 
  1017.      * @return  添加好的变更请求对象 
  1018.      */  
  1019.     public static WTChangeRequest2 addChangeNoticeToChangeRequest(WTChangeRequest2 cr, WTChangeOrder2 cn){        
  1020.         try {  
  1021.             if (!RemoteMethodServer.ServerFlag) {  
  1022.                 return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("addChangeNoticeToChangeRequest", CSCChange.class.getName(), null,  
  1023.                         new Class[] {WTChangeRequest2.class, WTChangeOrder2.class},  
  1024.                         new Object[] {cr, cn});  
  1025.             } else {                      
  1026.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1027.                 try {  
  1028.                     ChangeHelper2.service.saveAddressedBy(cr, cn);  
  1029.                     cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(cr);    
  1030.                 } catch (Exception e) {  
  1031.                     // TODO: handle exception  
  1032.                     e.printStackTrace();  
  1033.                 } finally {  
  1034.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1035.                 }  
  1036.                 return cr;  
  1037.             }  
  1038.         } catch (Exception e) {  
  1039.             e.printStackTrace();  
  1040.         }  
  1041.         return cr;  
  1042.     }     
  1043.       
  1044.       
  1045.     /** 
  1046.      * 为变更请求移除内容对象 
  1047.      * @param cr    目标变更请求 
  1048.      * @param changeable    变更请求内容对象 
  1049.      * @return  移除好的变更请求对象 
  1050.      */  
  1051.     public static WTChangeRequest2 removeChangeableFromChangeRequest(WTChangeRequest2 cr, Changeable2 changeable){        
  1052.         try {  
  1053.             if (!RemoteMethodServer.ServerFlag) {  
  1054.                 return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("removeChangeableFromChangeRequest", CSCChange.class.getName(), null,  
  1055.                         new Class[] {WTChangeRequest2.class, Changeable2.class},  
  1056.                         new Object[] {cr, changeable});  
  1057.             } else {                      
  1058.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1059.                 try {  
  1060.                     ChangeHelper2.service.unattachChangeable(changeable, cr, RelevantRequestData2.class, RelevantRequestData2.CHANGE_REQUEST2_ROLE);  
  1061.                     cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(cr);    
  1062.                 } catch (Exception e) {  
  1063.                     // TODO: handle exception  
  1064.                     e.printStackTrace();  
  1065.                 } finally {  
  1066.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1067.                 }  
  1068.                 return cr;  
  1069.             }  
  1070.         } catch (Exception e) {  
  1071.             e.printStackTrace();  
  1072.         }  
  1073.         return cr;  
  1074.     }     
  1075.       
  1076.       
  1077.     /** 
  1078.      * 为变更请求移除变更通告对象 
  1079.      * @param cr    目标变更请求 
  1080.      * @param cn    变更通告对象 
  1081.      * @return  移除好的变更请求对象 
  1082.      */  
  1083.     public static WTChangeRequest2 removeChangeNoticeToChangeRequest(WTChangeRequest2 cr, WTChangeOrder2 cn){         
  1084.         try {  
  1085.             if (!RemoteMethodServer.ServerFlag) {  
  1086.                 return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("removeChangeNoticeToChangeRequest", CSCChange.class.getName(), null,  
  1087.                         new Class[] {WTChangeRequest2.class, WTChangeOrder2.class},  
  1088.                         new Object[] {cr, cn});  
  1089.             } else {                      
  1090.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1091.                 try {  
  1092.                     ChangeHelper2.service.deleteAddressedBy(cr, cn);  
  1093.                     cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(cr);    
  1094.                 } catch (Exception e) {  
  1095.                     // TODO: handle exception  
  1096.                     e.printStackTrace();  
  1097.                 } finally {  
  1098.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1099.                 }  
  1100.                 return cr;  
  1101.             }  
  1102.         } catch (Exception e) {  
  1103.             e.printStackTrace();  
  1104.         }  
  1105.         return cr;  
  1106.     }     
  1107.       
  1108.       
  1109.     /** 
  1110.      * 创建变更通告 
  1111.      * @param number    编号 (默认为系统的 WTCHANGEORDER2ID_SEQ)     
  1112.      * @param name      名称 (必须) 
  1113.      * @param attributes    属性对应表  
  1114.      * @param secondaryContents 附件列表 (String FilePath 或者 InputStream) 
  1115.      * @param containerRef  上下文 (必须) 
  1116.      * @return  如果指定编号的变更通告存在,则返回该变更通告对象,若不存在,则返回创建后的变更通告 
  1117.      */  
  1118.     public static WTChangeOrder2 createChangeNotice(String number, String name, HashMap attributes,   
  1119.                                                 ArrayList secondaryContents, WTContainerRef containerRef){  
  1120.         try {  
  1121.             if (!RemoteMethodServer.ServerFlag) {  
  1122.                 return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("createChangeNotice", CSCChange.class.getName(), null,  
  1123.                         new Class[] {String.class, String.class, HashMap.class,  
  1124.                                         ArrayList.class, WTContainerRef.class},  
  1125.                         new Object[] {number, name, attributes,  
  1126.                                         secondaryContents, containerRef});  
  1127.             } else {  
  1128.                 WTChangeOrder2 cn = null;  
  1129.   
  1130.                 try {  
  1131.                       
  1132.                     String cnDesc = "";  
  1133.                     String cnType = "";  
  1134.                     String cnFolder = "";  
  1135.                     String cnNeedDate = "";  
  1136.                     String cnComplexity = "";  
  1137.                       
  1138.                     if(attributes != null){  
  1139.                         cnDesc = (String)attributes.get(CSCChange.DESCRIPTION);  
  1140.                         cnType = (String)attributes.get(CSCChange.TYPE);  
  1141.                         cnFolder = (String)attributes.get(CSCChange.FOLDER);  
  1142.                         cnNeedDate = (String)attributes.get(CSCChange.NEED_DATE);  
  1143.                         cnComplexity = (String)attributes.get(CSCChange.COMPLEXITY);  
  1144.                     }  
  1145.                       
  1146.                     if(containerRef == null){  
  1147.                         return null;  
  1148.                     }  
  1149.                       
  1150.                     //设置编号默认值 (默认为系统的WTCHANGEISSUEID_SEQ)                     
  1151.                     if(number == null || number.equalsIgnoreCase("")){  
  1152.                         number = CSCChange.getDefaultChangeSeqNumber(WTChangeOrder2.class);  
  1153.                     }else{  
  1154.                         //如果此编号变更通告已存在,则返回该变更通告  
  1155.                         WTChangeOrder2 existCN = CSCChange.getChangeNotice(number, false);  
  1156.                         if(existCN != null){  
  1157.                             return existCN;  
  1158.                         }  
  1159.                     }  
  1160.                       
  1161.                     if(name == null || name.equalsIgnoreCase("")){  
  1162.                         return null;  
  1163.                     }  
  1164.                       
  1165.                     if(cnDesc == null){  
  1166.                         cnDesc = "";  
  1167.                     }  
  1168.                       
  1169.                     //设置默认类型  (默认:wt.change2.WTChangeOrder2)      
  1170.                     if(cnType == null || cnType.equalsIgnoreCase("")){  
  1171.                         cnType = "wt.change2.WTChangeOrder2";  
  1172.                     }  
  1173.                                           
  1174.                     //设置默认文件夹  (默认:/Default)      
  1175.                     if(cnFolder == null || cnFolder.equalsIgnoreCase("")){  
  1176.                         cnFolder = "/Default";  
  1177.                     }else{  
  1178.                          if(!cnFolder.startsWith("/Default")){  
  1179.                              cnFolder = "/Default/" + cnFolder;  
  1180.                          }  
  1181.                     }  
  1182.                       
  1183.                     cn = WTChangeOrder2.newWTChangeOrder2();  
  1184.                     cn.setNumber(number);  
  1185.                     cn.setName(name);  
  1186.                       
  1187.                     //设置变更请求描述  
  1188.                     cn.setDescription(cnDesc);  
  1189.                       
  1190.                     //设置变更请求类型  
  1191.                     if(cnType != null){  
  1192.                         TypeIdentifier id = TypeIdentifierHelper.getTypeIdentifier(cnType);  
  1193.                         cn = (WTChangeOrder2) CoreMetaUtility.setType(cn, id);  
  1194.                     }  
  1195.                       
  1196.                     //设置上下文  
  1197.                     cn.setContainerReference(containerRef);  
  1198.                       
  1199.                     //设置文件夹  
  1200.                     Folder location = null;   
  1201.                         //查询文件夹是否存在  
  1202.                     try {  
  1203.                         location = FolderHelper.service.getFolder(cnFolder,containerRef);  
  1204.                     } catch (Exception e) {  
  1205.                         location = null;  
  1206.                     }  
  1207.                         //若文件夹不存在,则创建该文件夹  
  1208.                     if(location == null)  
  1209.                         location = FolderHelper.service.saveFolderPath(cnFolder, containerRef);  
  1210.                         //设置文件夹到Doc对象  
  1211.                     if (location != null) {  
  1212.                         WTValuedHashMap map = new WTValuedHashMap();  
  1213.                         map.put(cn, location);  
  1214.                         FolderHelper.assignLocations(map);  
  1215.                     }     
  1216.   
  1217.                     //设置需要日期  
  1218.                     if(cnNeedDate != null && !cnNeedDate.equals("")){  
  1219.                         try {  
  1220.                             SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");  
  1221.                             Date date = formatter.parse(cnNeedDate);  
  1222.                             cn.setNeedDate(new Timestamp(date.getTime()));  
  1223.                         } catch (Exception e) {  
  1224.                             // TODO: handle exception  
  1225.                             e.printStackTrace();  
  1226.                         }  
  1227.                     }  
  1228.   
  1229.                     //设置复杂性  
  1230.                     ChangeNoticeComplexity complexity = null;  
  1231.                     if(cnComplexity != null && !cnComplexity.equals("")){  
  1232.                         try {  
  1233.                             complexity = ChangeNoticeComplexity.toChangeNoticeComplexity(cnComplexity);  
  1234.                             cn.setChangeNoticeComplexity(complexity);  
  1235.                         } catch (Exception e) {  
  1236.                             // TODO: handle exception  
  1237.                             complexity = ChangeNoticeComplexity.getChangeNoticeComplexityDefault();  
  1238.                             cn.setChangeNoticeComplexity(complexity);  
  1239.                         }  
  1240.                     }  
  1241.   
  1242.                       
  1243.                     cn = (WTChangeOrder2) PersistenceHelper.manager.save(cn);  
  1244.                     cn = (WTChangeOrder2) PersistenceHelper.manager.refresh(cn);                          
  1245.                       
  1246.                     //设置附件  
  1247.                     if(secondaryContents != null){  
  1248.                         for (int i = 0; i < secondaryContents.size(); i++) {  
  1249.                             Object secondaryContent = secondaryContents.get(i);  
  1250.                               
  1251.                             ApplicationData applicationdata = ApplicationData.newApplicationData(cn);  
  1252.                             applicationdata.setRole(ContentRoleType.SECONDARY);               
  1253.                             if(secondaryContent instanceof String){  
  1254.                                 String filePath = (String)secondaryContent;  
  1255.                                 applicationdata = ContentServerHelper.service.updateContent(cn, applicationdata, filePath);       
  1256.                             }else if(secondaryContent instanceof InputStream){  
  1257.                                 InputStream ins = (InputStream)secondaryContent;  
  1258.                                 applicationdata = ContentServerHelper.service.updateContent(cn, applicationdata, ins);        
  1259.                             }  
  1260.                         }  
  1261.                     }  
  1262.                       
  1263.                     cn = (WTChangeOrder2) PersistenceServerHelper.manager.restore(cn);  
  1264.                 } catch (Exception e) {  
  1265.                     // TODO: handle exception  
  1266.                     e.printStackTrace();  
  1267.                 }         
  1268.                   
  1269.                 return cn;  
  1270.             }   
  1271.         }catch (Exception e) {  
  1272.                 e.printStackTrace();  
  1273.         }  
  1274.         return null;  
  1275.     }         
  1276.       
  1277.       
  1278.     /** 
  1279.      * 通过编号查找变更通告 
  1280.      * @param number    查询变更通告编号条件 
  1281.      * @param accessControlled  是否受到权限制约 
  1282.      * @return  返回结果变更通告 
  1283.      */  
  1284.     public static WTChangeOrder2 getChangeNotice(String number, boolean accessControlled) {  
  1285.         try {  
  1286.             number = number.toUpperCase();  
  1287.               
  1288.             if (!RemoteMethodServer.ServerFlag) {  
  1289.                 return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("getChangeNotice", CSCChange.class.getName(), null,  
  1290.                         new Class[] {String.classboolean.class},  
  1291.                         new Object[] {number, accessControlled});  
  1292.             } else {  
  1293.                 WTChangeOrder2 ecn = null;  
  1294.                   
  1295.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);  
  1296.                 try {  
  1297.                     QuerySpec spec = new QuerySpec(WTChangeOrder2.class);  
  1298.                     spec.appendWhere(  
  1299.                             new SearchCondition(WTChangeOrder2.class,  
  1300.                                     WTChangeRequest2.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });  
  1301.                       
  1302.                     QueryResult qr = PersistenceHelper.manager.find(spec);  
  1303.                     if (qr.hasMoreElements()){  
  1304.                         ecn = (WTChangeOrder2)qr.nextElement();  
  1305.                     }  
  1306.                 } catch (Exception e) {  
  1307.                     // TODO: handle exception  
  1308.                     e.printStackTrace();  
  1309.                 } finally {  
  1310.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1311.                 }  
  1312.       
  1313.                 return ecn;  
  1314.             }  
  1315.         } catch (Exception e) {  
  1316.             e.printStackTrace();  
  1317.         }  
  1318.         return null;  
  1319.     }  
  1320.   
  1321.     /** 
  1322.      * 通过变更通告得到变更前内容 
  1323.      * @param cn    条件变更通告 
  1324.      * @return  变更前内容对象集 
  1325.      */  
  1326.     public static ArrayList<Changeable2> getChangeNoticeItemsBefore(WTChangeOrder2 cn){  
  1327.         ArrayList<Changeable2> results = new ArrayList<Changeable2>();  
  1328.           
  1329.         try {  
  1330.             if (!RemoteMethodServer.ServerFlag) {  
  1331.                 return (ArrayList<Changeable2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeItemsBefore", CSCChange.class.getName(), null,  
  1332.                         new Class[] {WTChangeOrder2.class},  
  1333.                         new Object[] {cn});  
  1334.             } else {                      
  1335.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1336.                 try {  
  1337.                     QueryResult qr = ChangeHelper2.service.getChangeablesBefore(cn);  
  1338.                     while(qr.hasMoreElements()){  
  1339.                         Object obj = qr.nextElement();  
  1340.                         if(obj instanceof Changeable2){  
  1341.                             Changeable2 changeable = (Changeable2)obj;  
  1342.                             if(!results.contains(changeable)){  
  1343.                                 results.add(changeable);  
  1344.                             }  
  1345.                         }                         
  1346.                     }  
  1347.                 } catch (Exception e) {  
  1348.                     // TODO: handle exception  
  1349.                     e.printStackTrace();  
  1350.                 } finally {  
  1351.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1352.                 }  
  1353.                 return results;  
  1354.             }  
  1355.         } catch (Exception e) {  
  1356.             e.printStackTrace();  
  1357.         }  
  1358.         return results;  
  1359.     }     
  1360.       
  1361.       
  1362.     /** 
  1363.      * 通过变更通告得到变更后内容 
  1364.      * @param cn    条件变更通告 
  1365.      * @return  变更后内容对象集 
  1366.      */  
  1367.     public static ArrayList<Changeable2> getChangeNoticeItemsAfter(WTChangeOrder2 cn){  
  1368.         ArrayList<Changeable2> results = new ArrayList<Changeable2>();  
  1369.           
  1370.         try {  
  1371.             if (!RemoteMethodServer.ServerFlag) {  
  1372.                 return (ArrayList<Changeable2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeItemsAfter", CSCChange.class.getName(), null,  
  1373.                         new Class[] {WTChangeOrder2.class},  
  1374.                         new Object[] {cn});  
  1375.             } else {                      
  1376.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1377.                 try {  
  1378.                     QueryResult qr = ChangeHelper2.service.getChangeablesAfter(cn);  
  1379.                     while(qr.hasMoreElements()){  
  1380.                         Object obj = qr.nextElement();  
  1381.                         if(obj instanceof Changeable2){  
  1382.                             Changeable2 changeable = (Changeable2)obj;  
  1383.                             if(!results.contains(changeable)){  
  1384.                                 results.add(changeable);  
  1385.                             }  
  1386.                         }                         
  1387.                     }  
  1388.                 } catch (Exception e) {  
  1389.                     // TODO: handle exception  
  1390.                     e.printStackTrace();  
  1391.                 } finally {  
  1392.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1393.                 }  
  1394.                 return results;  
  1395.             }  
  1396.         } catch (Exception e) {  
  1397.             e.printStackTrace();  
  1398.         }  
  1399.         return results;  
  1400.     }  
  1401.       
  1402.     /** 
  1403.      * 通过变更前内容对象查找变更通告 
  1404.      * @param changeable    查询变更前对象 
  1405.      * @return  返回结果变更通告集 
  1406.      */  
  1407.     public static ArrayList<WTChangeOrder2> getChangeNoticeByChangeableBefore(Changeable2 changeable) {  
  1408.         ArrayList<WTChangeOrder2> results = new ArrayList<WTChangeOrder2>();  
  1409.           
  1410.         try {  
  1411.             if (!RemoteMethodServer.ServerFlag) {  
  1412.                 return (ArrayList<WTChangeOrder2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeByChangeableBefore", CSCChange.class.getName(), null,  
  1413.                         new Class[] {Changeable2.class},  
  1414.                         new Object[] {changeable});  
  1415.             } else {  
  1416.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1417.                 try {  
  1418.                     QueryResult qr = ChangeHelper2.service.getUniqueAffectingChangeOrders(changeable);  
  1419.                     while (qr.hasMoreElements()){                 
  1420.                         WTChangeOrder2 cn = (WTChangeOrder2)qr.nextElement();     
  1421.                         if(!results.contains(cn)){  
  1422.                             results.add(cn);  
  1423.                         }                         
  1424.                     }  
  1425.                 } catch (Exception e) {  
  1426.                     // TODO: handle exception  
  1427.                     e.printStackTrace();  
  1428.                 } finally {  
  1429.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1430.                 }  
  1431.   
  1432.                 return results;  
  1433.             }  
  1434.         } catch (Exception e) {  
  1435.             e.printStackTrace();  
  1436.         }  
  1437.         return null;  
  1438.     }     
  1439.       
  1440.       
  1441.     /** 
  1442.      * 通过变更后内容对象查找变更通告 
  1443.      * @param changeable    查询变更后对象 
  1444.      * @return  返回结果变更通告集 
  1445.      */  
  1446.     public static ArrayList<WTChangeOrder2> getChangeNoticeByChangeableAfter(Changeable2 changeable) {  
  1447.         ArrayList<WTChangeOrder2> results = new ArrayList<WTChangeOrder2>();  
  1448.           
  1449.         try {  
  1450.             if (!RemoteMethodServer.ServerFlag) {  
  1451.                 return (ArrayList<WTChangeOrder2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeByChangeableAfter", CSCChange.class.getName(), null,  
  1452.                         new Class[] {Changeable2.class},  
  1453.                         new Object[] {changeable});  
  1454.             } else {  
  1455.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1456.                 try {  
  1457.                     QueryResult qr = ChangeHelper2.service.getUniqueImplementedChangeOrders(changeable);  
  1458.                     while (qr.hasMoreElements()){                 
  1459.                         WTChangeOrder2 cn = (WTChangeOrder2)qr.nextElement();     
  1460.                         if(!results.contains(cn)){  
  1461.                             results.add(cn);  
  1462.                         }                         
  1463.                     }  
  1464.                 } catch (Exception e) {  
  1465.                     // TODO: handle exception  
  1466.                     e.printStackTrace();  
  1467.                 } finally {  
  1468.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1469.                 }  
  1470.   
  1471.                 return results;  
  1472.             }  
  1473.         } catch (Exception e) {  
  1474.             e.printStackTrace();  
  1475.         }  
  1476.         return null;  
  1477.     }         
  1478.       
  1479.     /** 
  1480.      * 通过变更通告得到相关联的变更请求 
  1481.      * @param cn    条件变更通告 
  1482.      * @return  变更请求对象 
  1483.      */  
  1484.     public static ArrayList<WTChangeRequest2> getChangeRequestByChangeNotice(WTChangeOrder2 cn){  
  1485.         ArrayList<WTChangeRequest2> results = new ArrayList<WTChangeRequest2>();  
  1486.           
  1487.         try {  
  1488.             if (!RemoteMethodServer.ServerFlag) {  
  1489.                 return (ArrayList<WTChangeRequest2>) RemoteMethodServer.getDefault().invoke("getChangeRequestByChangeNotice", CSCChange.class.getName(), null,  
  1490.                         new Class[] {WTChangeOrder2.class},  
  1491.                         new Object[] {cn});  
  1492.             } else {                      
  1493.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1494.                 try {  
  1495.                     QueryResult qr = ChangeHelper2.service.getChangeRequest(cn);  
  1496.                     while (qr.hasMoreElements()){                 
  1497.                         WTChangeRequest2 cr = (WTChangeRequest2)qr.nextElement();     
  1498.                         if(!results.contains(cr)){  
  1499.                             results.add(cr);  
  1500.                         }                         
  1501.                     }  
  1502.                 } catch (Exception e) {  
  1503.                     // TODO: handle exception  
  1504.                     e.printStackTrace();  
  1505.                 } finally {  
  1506.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1507.                 }  
  1508.                 return results;  
  1509.             }  
  1510.         } catch (Exception e) {  
  1511.             e.printStackTrace();  
  1512.         }  
  1513.         return results;  
  1514.     }     
  1515.       
  1516.     /** 
  1517.      * 通过变更通告得到相关联的变更任务 
  1518.      * @param cn    条件变更通告 
  1519.      * @return  变更任务对象 
  1520.      */  
  1521.     public static ArrayList<WTChangeActivity2> getChangeActivityByChangeNotice(WTChangeOrder2 cn){  
  1522.         ArrayList<WTChangeActivity2> results = new ArrayList<WTChangeActivity2>();  
  1523.           
  1524.         try {  
  1525.             if (!RemoteMethodServer.ServerFlag) {  
  1526.                 return (ArrayList<WTChangeActivity2>) RemoteMethodServer.getDefault().invoke("getChangeActivityByChangeNotice", CSCChange.class.getName(), null,  
  1527.                         new Class[] {WTChangeOrder2.class},  
  1528.                         new Object[] {cn});  
  1529.             } else {                      
  1530.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1531.                 try {  
  1532.                     QueryResult qr = ChangeHelper2.service.getChangeActivities(cn);  
  1533.                     while (qr.hasMoreElements()){                 
  1534.                         WTChangeActivity2 ca = (WTChangeActivity2)qr.nextElement();   
  1535.                         if(!results.contains(ca)){  
  1536.                             results.add(ca);  
  1537.                         }                         
  1538.                     }  
  1539.                 } catch (Exception e) {  
  1540.                     // TODO: handle exception  
  1541.                     e.printStackTrace();  
  1542.                 } finally {  
  1543.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1544.                 }  
  1545.                 return results;  
  1546.             }  
  1547.         } catch (Exception e) {  
  1548.             e.printStackTrace();  
  1549.         }  
  1550.         return results;  
  1551.     }         
  1552.       
  1553.     /** 
  1554.      * 为变更通告添加变更前对象 
  1555.      * @param cn    目标变更通告 
  1556.      * @param changeable    变更前对象 
  1557.      * @param caName 需要将变更前对象放入的变更活动 
  1558.      * @return  添加好的变更通告对象 
  1559.      */  
  1560.     public static WTChangeOrder2 addChangeableBeforeToChangeNotice(WTChangeOrder2 cn, Changeable2 changeable, String caName){         
  1561.         try {  
  1562.             if (!RemoteMethodServer.ServerFlag) {  
  1563.                 return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("addChangeableBeforeToChangeNotice", CSCChange.class.getName(), null,  
  1564.                         new Class[] {WTChangeOrder2.class, Changeable2.class, String.class},  
  1565.                         new Object[] {cn, changeable, caName});  
  1566.             } else {                      
  1567.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1568.                 try {  
  1569.                     QueryResult qr = ChangeHelper2.service.getChangeActivities(cn);  
  1570.                       
  1571.                     //查找是否有与条件变更活动名相同的变更活动  
  1572.                     WTChangeActivity2 toBeAddedCA = null;  
  1573.                     while(qr.hasMoreElements()){  
  1574.                         WTChangeActivity2 ca = (WTChangeActivity2)qr.nextElement();  
  1575.                         if(caName == null || caName.equals("")){  
  1576.                             //如果条件变更活动名为空,则取第一个变更活动  
  1577.                             toBeAddedCA = ca;  
  1578.                             break;  
  1579.                         }else{  
  1580.                             if(caName.trim().equals(ca.getName())){  
  1581.                                 //如果找到条件变更活动,则准备添加改前数据  
  1582.                                 toBeAddedCA = ca;  
  1583.                                 break;  
  1584.                             }  
  1585.                         }  
  1586.                         //如果未找到条件变更活动,则取最后一个变更活动  
  1587.                         toBeAddedCA = ca;  
  1588.                     }  
  1589.                       
  1590.                     if(toBeAddedCA != null){  
  1591.                         Vector changeables = new Vector();  
  1592.                         changeables.add(changeable);  
  1593.                         ChangeHelper2.service.storeAssociations(AffectedActivityData.class, toBeAddedCA, changeables);  
  1594.                     }  
  1595.                     cn = (WTChangeOrder2) PersistenceHelper.manager.refresh(cn);      
  1596.                 } catch (Exception e) {  
  1597.                     // TODO: handle exception  
  1598.                     e.printStackTrace();  
  1599.                 } finally {  
  1600.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1601.                 }  
  1602.                 return cn;  
  1603.             }  
  1604.         } catch (Exception e) {  
  1605.             e.printStackTrace();  
  1606.         }  
  1607.         return cn;  
  1608.     }     
  1609.       
  1610.     /** 
  1611.      * 为变更通告添加变更后对象 
  1612.      * @param cn    目标变更通告 
  1613.      * @param changeable    变更后对象 
  1614.      * @param caName 需要将变更后对象放入的变更活动 
  1615.      * @return  添加好的变更通告对象 
  1616.      */  
  1617.     public static WTChangeOrder2 addChangeableAfterToChangeNotice(WTChangeOrder2 cn, Changeable2 changeable, String caName){          
  1618.         try {  
  1619.             if (!RemoteMethodServer.ServerFlag) {  
  1620.                 return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("addChangeableAfterToChangeNotice", CSCChange.class.getName(), null,  
  1621.                         new Class[] {WTChangeOrder2.class, Changeable2.class, String.class},  
  1622.                         new Object[] {cn, changeable, caName});  
  1623.             } else {                      
  1624.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1625.                 try {  
  1626.                     QueryResult qr = ChangeHelper2.service.getChangeActivities(cn);  
  1627.                       
  1628.                     //查找是否有与条件变更活动名相同的变更活动  
  1629.                     WTChangeActivity2 toBeAddedCA = null;  
  1630.                     while(qr.hasMoreElements()){  
  1631.                         WTChangeActivity2 ca = (WTChangeActivity2)qr.nextElement();  
  1632.                         if(caName == null || caName.equals("")){  
  1633.                             //如果条件变更活动名为空,则取第一个变更活动  
  1634.                             toBeAddedCA = ca;  
  1635.                             break;  
  1636.                         }else{  
  1637.                             if(caName.trim().equals(ca.getName())){  
  1638.                                 //如果找到条件变更活动,则准备添加改后数据  
  1639.                                 toBeAddedCA = ca;  
  1640.                                 break;  
  1641.                             }  
  1642.                         }  
  1643.                         //如果未找到条件变更活动,则取最后一个变更活动  
  1644.                         toBeAddedCA = ca;  
  1645.                     }  
  1646.                       
  1647.                     if(toBeAddedCA != null){  
  1648.                         Vector changeables = new Vector();  
  1649.                         changeables.add(changeable);  
  1650.                         ChangeHelper2.service.storeAssociations(ChangeRecord2.class, toBeAddedCA, changeables);  
  1651.                     }  
  1652.                     cn = (WTChangeOrder2) PersistenceHelper.manager.refresh(cn);      
  1653.                 } catch (Exception e) {  
  1654.                     // TODO: handle exception  
  1655.                     e.printStackTrace();  
  1656.                 } finally {  
  1657.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1658.                 }  
  1659.                 return cn;  
  1660.             }  
  1661.         } catch (Exception e) {  
  1662.             e.printStackTrace();  
  1663.         }  
  1664.         return cn;  
  1665.     }     
  1666.       
  1667.     /** 
  1668.      * 为变更通告移除变更前对象 
  1669.      * @param cn    目标变更通告 
  1670.      * @param changeable    变更前对象 
  1671.      * @param caName 需要将变更前对象移除的变更活动 
  1672.      * @return  移除好的变更通告对象 
  1673.      */  
  1674.     public static WTChangeOrder2 removeChangeableBeforeToChangeNotice(WTChangeOrder2 cn, Changeable2 changeable, String caName){          
  1675.         try {  
  1676.             if (!RemoteMethodServer.ServerFlag) {  
  1677.                 return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("removeChangeableBeforeToChangeNotice", CSCChange.class.getName(), null,  
  1678.                         new Class[] {WTChangeOrder2.class, Changeable2.class, String.class},  
  1679.                         new Object[] {cn, changeable, caName});  
  1680.             } else {                      
  1681.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1682.                 try {  
  1683.                     QueryResult qr = ChangeHelper2.service.getChangeActivities(cn);  
  1684.                       
  1685.                     //查找是否有与条件变更活动名相同的变更活动  
  1686.                     WTChangeActivity2 toBeRemovedCA = null;  
  1687.                     while(qr.hasMoreElements()){  
  1688.                         WTChangeActivity2 ca = (WTChangeActivity2)qr.nextElement();  
  1689.                         if(caName == null || caName.equals("")){  
  1690.                             //如果条件变更活动名为空,则取第一个变更活动  
  1691.                             toBeRemovedCA = ca;  
  1692.                             break;  
  1693.                         }else{  
  1694.                             if(caName.trim().equals(ca.getName())){  
  1695.                                 //如果找到条件变更活动,则准备移除改前数据  
  1696.                                 toBeRemovedCA = ca;  
  1697.                                 break;  
  1698.                             }  
  1699.                         }  
  1700.                         //如果未找到条件变更活动,则取最后一个变更活动  
  1701.                         toBeRemovedCA = ca;  
  1702.                     }  
  1703.                       
  1704.                     if(toBeRemovedCA != null){  
  1705.                         ChangeHelper2.service.unattachChangeable(changeable, toBeRemovedCA, AffectedActivityData.class, AffectedActivityData.CHANGE_ACTIVITY2_ROLE);  
  1706.                     }  
  1707.                     cn = (WTChangeOrder2) PersistenceHelper.manager.refresh(cn);      
  1708.                 } catch (Exception e) {  
  1709.                     // TODO: handle exception  
  1710.                     e.printStackTrace();  
  1711.                 } finally {  
  1712.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1713.                 }  
  1714.                 return cn;  
  1715.             }  
  1716.         } catch (Exception e) {  
  1717.             e.printStackTrace();  
  1718.         }  
  1719.         return cn;  
  1720.     }         
  1721.       
  1722.     /** 
  1723.      * 为变更通告移除变更后对象 
  1724.      * @param cn    目标变更通告 
  1725.      * @param changeable    变更后对象 
  1726.      * @param caName 需要将变更后对象移除的变更活动 
  1727.      * @return  移除好的变更通告对象 
  1728.      */  
  1729.     public static WTChangeOrder2 removeChangeableAfterToChangeNotice(WTChangeOrder2 cn, Changeable2 changeable, String caName){       
  1730.         try {  
  1731.             if (!RemoteMethodServer.ServerFlag) {  
  1732.                 return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("removeChangeableAfterToChangeNotice", CSCChange.class.getName(), null,  
  1733.                         new Class[] {WTChangeOrder2.class, Changeable2.class, String.class},  
  1734.                         new Object[] {cn, changeable, caName});  
  1735.             } else {                      
  1736.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1737.                 try {  
  1738.                     QueryResult qr = ChangeHelper2.service.getChangeActivities(cn);  
  1739.                       
  1740.                     //查找是否有与条件变更活动名相同的变更活动  
  1741.                     WTChangeActivity2 toBeRemovedCA = null;  
  1742.                     while(qr.hasMoreElements()){  
  1743.                         WTChangeActivity2 ca = (WTChangeActivity2)qr.nextElement();  
  1744.                         if(caName == null || caName.equals("")){  
  1745.                             //如果条件变更活动名为空,则取第一个变更活动  
  1746.                             toBeRemovedCA = ca;  
  1747.                             break;  
  1748.                         }else{  
  1749.                             if(caName.trim().equals(ca.getName())){  
  1750.                                 //如果找到条件变更活动,则准备移除改后数据  
  1751.                                 toBeRemovedCA = ca;  
  1752.                                 break;  
  1753.                             }  
  1754.                         }  
  1755.                         //如果未找到条件变更活动,则取最后一个变更活动  
  1756.                         toBeRemovedCA = ca;  
  1757.                     }  
  1758.                       
  1759.                     if(toBeRemovedCA != null){  
  1760.                         ChangeHelper2.service.unattachChangeable(changeable, toBeRemovedCA, ChangeRecord2.class, ChangeRecord2.CHANGE_ACTIVITY2_ROLE);  
  1761.                     }  
  1762.                     cn = (WTChangeOrder2) PersistenceHelper.manager.refresh(cn);      
  1763.                 } catch (Exception e) {  
  1764.                     // TODO: handle exception  
  1765.                     e.printStackTrace();  
  1766.                 } finally {  
  1767.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1768.                 }  
  1769.                 return cn;  
  1770.             }  
  1771.         } catch (Exception e) {  
  1772.             e.printStackTrace();  
  1773.         }  
  1774.         return cn;  
  1775.     }     
  1776.       
  1777.       
  1778.       
  1779.     /** 
  1780.      * 通过编号查找变更活动 
  1781.      * @param number    查询变更活动编号条件 
  1782.      * @param accessControlled  是否受到权限制约 
  1783.      * @return  返回结果变更活动 
  1784.      */  
  1785.     public static WTChangeActivity2 getChangeActivity(String number, boolean accessControlled) {  
  1786.         try {  
  1787.             number = number.toUpperCase();  
  1788.               
  1789.             if (!RemoteMethodServer.ServerFlag) {  
  1790.                 return (WTChangeActivity2) RemoteMethodServer.getDefault().invoke("getChangeActivity", CSCChange.class.getName(), null,  
  1791.                         new Class[] {String.classboolean.class},  
  1792.                         new Object[] {number, accessControlled});  
  1793.             } else {  
  1794.                 WTChangeActivity2 ca = null;  
  1795.                   
  1796.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);  
  1797.                 try {  
  1798.                     QuerySpec spec = new QuerySpec(WTChangeActivity2.class);  
  1799.                     spec.appendWhere(  
  1800.                             new SearchCondition(WTChangeActivity2.class,  
  1801.                                     WTChangeActivity2.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });  
  1802.                       
  1803.                     QueryResult qr = PersistenceHelper.manager.find(spec);  
  1804.                     if (qr.hasMoreElements()){  
  1805.                         ca = (WTChangeActivity2)qr.nextElement();  
  1806.                     }  
  1807.                 } catch (Exception e) {  
  1808.                     // TODO: handle exception  
  1809.                     e.printStackTrace();  
  1810.                 } finally {  
  1811.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1812.                 }  
  1813.   
  1814.                 return ca;  
  1815.             }  
  1816.         } catch (Exception e) {  
  1817.             e.printStackTrace();  
  1818.         }  
  1819.         return null;  
  1820.     }         
  1821.       
  1822.     /** 
  1823.      * 通过变更任务得到相关联的变更通告 
  1824.      * @param ca    条件变更任务 
  1825.      * @return  变更通告对象集 
  1826.      */  
  1827.     public static ArrayList<WTChangeOrder2> getChangeNoticeByChangeActivity(WTChangeActivity2 ca){  
  1828.         ArrayList<WTChangeOrder2> results = new ArrayList<WTChangeOrder2>();  
  1829.           
  1830.         try {  
  1831.             if (!RemoteMethodServer.ServerFlag) {  
  1832.                 return (ArrayList<WTChangeOrder2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeByChangeActivity", CSCChange.class.getName(), null,  
  1833.                         new Class[] {WTChangeActivity2.class},  
  1834.                         new Object[] {ca});  
  1835.             } else {                      
  1836.                 boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);  
  1837.                 try {  
  1838.                     QueryResult qr = ChangeHelper2.service.getChangeOrder(ca);  
  1839.                     while (qr.hasMoreElements()){                 
  1840.                         WTChangeOrder2 cn = (WTChangeOrder2)qr.nextElement();     
  1841.                         if(!results.contains(cn)){  
  1842.                             results.add(cn);  
  1843.                         }                         
  1844.                     }  
  1845.                 } catch (Exception e) {  
  1846.                     // TODO: handle exception  
  1847.                     e.printStackTrace();  
  1848.                 } finally {  
  1849.                     SessionServerHelper.manager.setAccessEnforced(enforce);  
  1850.                 }  
  1851.                 return results;  
  1852.             }  
  1853.         } catch (Exception e) {  
  1854.             e.printStackTrace();  
  1855.         }  
  1856.         return results;  
  1857.     }     
  1858.       
  1859.     /** 
  1860.      * 创建变更任务 
  1861.      * @param number    编号 (默认为系统的 WTCHANGEACTIVITY22ID_SEQ)     
  1862.      * @param name      名称 (必须) 
  1863.      * @param attributes    属性对应表  
  1864.      * @param cn    所属的变更通告 (必须) 
  1865.      * @return  如果指定编号的变更任务存在,则返回该变更任务对象,若不存在,则返回创建后的变更任务 
  1866.      */  
  1867.     public static WTChangeActivity2 createChangeActivity(String number, String name, HashMap attributes, WTChangeOrder2 cn){  
  1868.         try {  
  1869.             if (!RemoteMethodServer.ServerFlag) {  
  1870.                 return (WTChangeActivity2) RemoteMethodServer.getDefault().invoke("createChangeActivity", CSCChange.class.getName(), null,  
  1871.                         new Class[] {String.class, String.class, HashMap.class,WTChangeOrder2.class},  
  1872.                         new Object[] {number, name, attributes, cn});  
  1873.             } else {  
  1874.                 WTChangeActivity2 ca = null;  
  1875.   
  1876.                 try {  
  1877.                       
  1878.                     String caDesc = "";  
  1879.                     String caNeedDate = "";  
  1880.                       
  1881.                     if(attributes != null){  
  1882.                         caDesc = (String)attributes.get(CSCChange.DESCRIPTION);  
  1883.                         caNeedDate = (String)attributes.get(CSCChange.NEED_DATE);  
  1884.                     }  
  1885.                       
  1886.                     if(cn == null){  
  1887.                         return null;  
  1888.                     }  
  1889.                       
  1890.                     //设置编号默认值     
  1891.                     if(number == null || number.equalsIgnoreCase("")){  
  1892.                         number = CSCChange.getDefaultChangeSeqNumber(WTChangeActivity2.class);  
  1893.                     }else{  
  1894.                         //如果此编号变更任务已存在,则返回该变更任务  
  1895.                         WTChangeActivity2 existCA = CSCChange.getChangeActivity(number, false);  
  1896.                         if(existCA != null){  
  1897.                             return existCA;  
  1898.                         }  
  1899.                     }  
  1900.                       
  1901.                     if(name == null || name.equalsIgnoreCase("")){  
  1902.                         return null;  
  1903.                     }  
  1904.                       
  1905.                     if(caDesc == null){  
  1906.                         caDesc = "";  
  1907.                     }  
  1908.   
  1909.                     ca = WTChangeActivity2.newWTChangeActivity2();  
  1910.                     ca.setNumber(number);  
  1911.                     ca.setName(name);  
  1912.                       
  1913.                     //设置变更任务描述  
  1914.                     cn.setDescription(caDesc);  
  1915.                       
  1916.                     //设置上下文(所属变更通告的上下文)  
  1917.                     ca.setContai  
Excel文件读取 windchill
Java代码   收藏代码
  1. package ext.csc.util.thirdparty;  
  2.   
  3. import java.io.File;  
  4. import java.io.FileInputStream;  
  5. import java.io.FileOutputStream;  
  6. import java.io.IOException;  
  7. import java.io.OutputStream;  
  8. import java.text.SimpleDateFormat;  
  9. import java.util.Date;  
  10.   
  11. import javax.servlet.http.HttpServletResponse;  
  12.   
  13. import org.apache.poi.hssf.usermodel.HSSFCell;  
  14. import org.apache.poi.hssf.usermodel.HSSFDateUtil;  
  15. import org.apache.poi.hssf.usermodel.HSSFRow;  
  16. import org.apache.poi.hssf.usermodel.HSSFSheet;  
  17. import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
  18. import org.apache.poi.hssf.util.Region;  
  19. import org.apache.poi.poifs.filesystem.POIFSFileSystem;  
  20.   
  21. import ext.csc.util.common.CSCDebug;  
  22.   
  23. /** 
  24.  * Excel文件读取 
  25.  * @author xijin 
  26.  * @version 2010/6/29 
  27.  */  
  28. public class CSCExcel {  
  29.     private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCExcel.class);   
  30.       
  31.     /** 实体POI Workbook */  
  32.     private HSSFWorkbook wb = null;  
  33.       
  34.     /** Excel 文件对象 */  
  35.     private File excelFile = null;   
  36.   
  37.     /** 当前Sheet */  
  38.     private HSSFSheet currentSheet = null;  
  39.       
  40.     public CSCExcel() {}  
  41.   
  42.     /** 
  43.      * 初始化构造方法 
  44.      * @param filePathName Excel文件路径和文件名 
  45.      * @throws IOException 文件流例外 
  46.      */  
  47.     public CSCExcel(String filePathName) throws IOException {  
  48.         POIFSFileSystem fs = null;  
  49.         excelFile = new File(filePathName);  
  50.         // 检测指定文件是否存在  
  51.         if (excelFile.exists()) {  
  52.             fs = new POIFSFileSystem(new FileInputStream(excelFile));  
  53.         }  
  54.         if (fs != null) {  
  55.             wb = new HSSFWorkbook(fs);  
  56.             currentSheet = wb.getSheetAt(0);  
  57.         }  
  58.     }  
  59.       
  60.     /** 
  61.      * 初始化构造方法 
  62.      * @param inputStream Excel文件流 
  63.      * @throws IOException 文件流例外 
  64.      */  
  65.     public CSCExcel(FileInputStream inputStream) throws IOException {  
  66.         // 如果文件流不为空,执行初始化  
  67.         if (inputStream != null) {  
  68.             POIFSFileSystem fs = new POIFSFileSystem(inputStream);  
  69.             wb = new HSSFWorkbook(fs);  
  70.             currentSheet = wb.getSheetAt(0);  
  71.         }  
  72.     }  
  73.       
  74.     /** 
  75.      * 判断Workbook是否存在 
  76.      * @return 是否存在 
  77.      */  
  78.     public boolean exists() {  
  79.         return wb != null;  
  80.     }  
  81.       
  82.     /** 
  83.      * 取得路径名称 
  84.      * @return 路径名称 
  85.      */  
  86.     public String getParent() {  
  87.         return excelFile.getParent();  
  88.     }  
  89.       
  90.     /** 
  91.      * 取得文件名称 
  92.      * @return  Excel文件名 
  93.      */  
  94.     public String getFileName() {  
  95.         return excelFile.getName();  
  96.     }  
  97.       
  98.     /** 
  99.      * 创建Excel文件 
  100.      * @return 创建是否成功 
  101.      * @throws IOException 文件流例外 
  102.      */  
  103.     public boolean createNewFile() throws IOException {  
  104.         wb = new HSSFWorkbook();  
  105.           
  106.         if (excelFile != null) {  
  107.             // 创建文件路径  
  108.             boolean dirResult = excelFile.getParentFile().mkdirs();  
  109.               
  110.             if (dirResult || excelFile.getParentFile().exists()) {  
  111.                 FileOutputStream fileOut = new FileOutputStream(getParent() + "\\" + getFileName());  
  112.                 wb.write(fileOut);  
  113.                 fileOut.close();  
  114.             } else {  
  115.                 // 如果文件路径创建不成功返回False;  
  116.                 return false;  
  117.             }  
  118.         }  
  119.         // 文件创建成功  
  120.         return true;  
  121.     }  
  122.       
  123.     /** 
  124.      * 创建新Sheet 
  125.      * @param sheetName Sheet名称 
  126.      * @return 创建是否成功 
  127.      * @throws IOException 文件流例外 
  128.      */  
  129.     public boolean createNewSheet(String sheetName) throws IOException {  
  130.         if (wb == nullreturn false;  
  131.         HSSFSheet sheet = wb.createSheet(sheetName);  
  132.         // 设置为当前Sheet  
  133.         this.currentSheet = sheet;  
  134.           
  135.         if (sheet != null) {  
  136.             return true;  
  137.         } else {  
  138.             return false;  
  139.         }  
  140.     }  
  141.       
  142.     /** 
  143.      * 改变当前Sheet 
  144.      * @param sheetName Excel文件名称 
  145.      */  
  146.     public void switchCurrentSheet(String sheetName) {  
  147.         if (wb == nullreturn ;  
  148.         HSSFSheet sheet = wb.getSheet(sheetName);  
  149.           
  150.         if (sheet != null) {  
  151.             this.currentSheet = sheet;  
  152.         }  
  153.     }  
  154.   
  155.       
  156.     public void switchCurrentSheet(int sheetId) {  
  157.         if (wb == nullreturn ;  
  158.         HSSFSheet sheet = wb.getSheetAt(sheetId);  
  159.           
  160.         if (sheet != null) {  
  161.             this.currentSheet = sheet;  
  162.         }  
  163.     }  
  164.       
  165.       
  166.     public int getSheetRowCount() {  
  167.         return this.currentSheet.getPhysicalNumberOfRows();  
  168.     }  
  169.       
  170.     /** 
  171.      * 判断是否存在指定Sheet 
  172.      * @param sheetName Sheet名称 
  173.      * @return  是否存在标记 
  174.      */  
  175.     public boolean isExistSheet(String sheetName) {  
  176.         if (wb == nullreturn false;  
  177.         HSSFSheet sheet = wb.getSheet(sheetName);  
  178.           
  179.         if (sheet == null) {  
  180.             return false;  
  181.         }  
  182.           
  183.         return true;  
  184.     }  
  185.       
  186.     /** 
  187.      * 对指定位置单元格设置字符串值 
  188.      * @param row 行标 
  189.      * @param col 列标 
  190.      * @param value 值 
  191.      * @return 是否设置成功 
  192.      */  
  193.     @SuppressWarnings("deprecation")  
  194.     public boolean setStringValue(int row, int col, String value) {  
  195.         if (wb == nullreturn false;  
  196.           
  197.         HSSFRow hssfRow = currentSheet.createRow(row);  
  198.         HSSFCell cell = hssfRow.createCell((short)col);  
  199.         cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
  200.         cell.setCellType(HSSFCell.CELL_TYPE_STRING);  
  201.         cell.setCellValue(value);  
  202.           
  203.         return true;  
  204.     }  
  205.       
  206.     /** 
  207.      * 对指定位置单元格设置数字值 
  208.      * @param row 行标 
  209.      * @param col 列标 
  210.      * @param value 值 
  211.      * @return 是否设置成功 
  212.      */  
  213.     @SuppressWarnings("deprecation")  
  214.     public boolean setNumericValue(int row, int col, double value) {  
  215.         if (wb == nullreturn false;  
  216.           
  217.         HSSFRow hssfRow = currentSheet.createRow(row);  
  218.         HSSFCell cell = hssfRow.createCell((short)col);  
  219.         cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
  220.         cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);  
  221.         cell.setCellValue(value);  
  222.           
  223.         return true;  
  224.     }  
  225.       
  226.     /** 
  227.      * 对指定位置单元格设置日期值 
  228.      * @param row 行标 
  229.      * @param col 列标 
  230.      * @param value 值 
  231.      * @return 是否设置成功 
  232.      */  
  233.     @SuppressWarnings("deprecation")  
  234.     public boolean setDateValue(int row, int col, Date value, String fomat) {  
  235.         if (wb == nullreturn false;  
  236.           
  237.         HSSFRow hssfRow = currentSheet.createRow(row);  
  238.         HSSFCell cell = hssfRow.createCell((short)col);  
  239.         cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
  240.         cell.setCellType(HSSFCell.CELL_TYPE_STRING);  
  241.           
  242.         SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(fomat);  
  243.         cell.setCellValue(dateFormat.format(value));  
  244.           
  245.         return true;  
  246.     }  
  247.       
  248.     /** 
  249.      * 对指定位置单元格设置布尔值 
  250.      * @param row 行标 
  251.      * @param col 列标 
  252.      * @param value 值 
  253.      * @return 是否设置成功 
  254.      */  
  255.     @SuppressWarnings("deprecation")  
  256.     public boolean setBooleanValue(int row, int col, boolean value) {  
  257.         if (wb == nullreturn false;  
  258.           
  259.         HSSFRow hssfRow = currentSheet.createRow(row);  
  260.         HSSFCell cell = hssfRow.createCell((short)col);  
  261.         cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
  262.         cell.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);  
  263.         cell.setCellValue(value);  
  264.           
  265.         return true;  
  266.     }  
  267.       
  268.     /** 
  269.      * 合并单元格 
  270.      * @param rowFrom 合并起始行标 
  271.      * @param colFrom 合并起始列标 
  272.      * @param rowTo 合并结尾行标 
  273.      * @param colTo 合并结尾列标 
  274.      * @return 合并结果 
  275.      */  
  276.     public boolean mergeCells(int rowFrom, int colFrom, int rowTo, int colTo) {  
  277.         if (wb == nullreturn false;  
  278.           
  279.         currentSheet.addMergedRegion(new Region(rowFrom,(short)colFrom,rowTo,(short)colTo));  
  280.           
  281.         return true;  
  282.     }  
  283.       
  284.       
  285.       
  286.     /** 
  287.      * 读取指定坐标的值 
  288.      * @param row 行标 
  289.      * @param col 列标 
  290.      * @return 字符串值 
  291.      */  
  292.     @SuppressWarnings("deprecation")  
  293.     public String getValue(int row, int col) {  
  294.         if (wb == nullreturn "";  
  295.         String value = "";  
  296.           
  297.         // 从当前Sheet中读取数据,取得指定行  
  298.         HSSFRow hssfrow = currentSheet.getRow(row);  
  299.         if (hssfrow == null) {  
  300.             return "";  
  301.         }  
  302.         // 根据指定行,取得指定单元格  
  303.         HSSFCell cell = hssfrow.getCell((short)col);  
  304.         if(cell == null){  
  305.             return "";  
  306.         }  
  307.         // 取得单元格类型  
  308.         int type = cell.getCellType();  
  309.           
  310.         if(type == HSSFCell.CELL_TYPE_STRING){  
  311.             // 字符串类型  
  312.             value = cell.getStringCellValue();  
  313.         }else if (HSSFDateUtil.isCellDateFormatted(cell)) {   
  314.             // 日期类型  
  315.             double d = cell.getNumericCellValue();     
  316.             if (d == 0.0) {  
  317.                 value = "";  
  318.             } else {  
  319.                 Date date = HSSFDateUtil.getJavaDate(d);      
  320.                 SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy/MM/dd");  
  321.                 value = dateFormat.format(date);  
  322.             }  
  323.         }else if(type == HSSFCell.CELL_TYPE_NUMERIC){  
  324.             // 数字类型  
  325.             double dvalue = cell.getNumericCellValue();  
  326.             value = String.valueOf(dvalue);  
  327.         }else if(type == HSSFCell.CELL_TYPE_BOOLEAN){  
  328.             // 布尔类型  
  329.             value = cell.getBooleanCellValue() + "";  
  330.         }else if(type == HSSFCell.CELL_TYPE_BLANK){  
  331.             value = "";  
  332.         }else{  
  333.             value = cell.getStringCellValue();  
  334.         }  
  335.   
  336.         if (value == null){  
  337.             return "";  
  338.         }  
  339.           
  340.         return value.trim();  
  341.     }  
  342.       
  343.     /** 
  344.      * 一次性保存之前所有修改. 
  345.      * @return 保存是否成功 
  346.      * @throws IOException 文件流例外 
  347.      */  
  348.     public boolean saveChanges() throws IOException {  
  349.         if (wb == null || excelFile == nullreturn false;  
  350.           
  351.         FileOutputStream fileOut = new FileOutputStream(getParent() + "\\" + getFileName());  
  352.         wb.write(fileOut);  
  353.         fileOut.close();  
  354.           
  355.         return true;  
  356.     }  
  357.       
  358.     /** 
  359.      * 下载Excel文件 
  360.      * @param response 
  361.      * @throws IOException 
  362.      */  
  363.     public void downloadExcel(HttpServletResponse response) throws IOException {  
  364.         OutputStream os = response.getOutputStream();  
  365.         wb.write(os);  
  366.         os.flush();  
  367.         os.close();  
  368.           
  369.         response.setStatus(HttpServletResponse.SC_OK);  
  370.         response.flushBuffer();  
  371.     }  
  372.       
  373.       
  374.     public static void main(String[] args) throws Exception {  
  375.         System.out.println("------ test start ------");  
  376.           
  377.         // 建立CSCExcel对象  
  378.         CSCExcel excel = new CSCExcel("C:\\test\\testtwoa\\test.xls");  
  379.   
  380.         System.out.println(" 路径名称 == " + excel.getParent());  
  381.         System.out.println(" 文件名称 == " + excel.getFileName());  
  382.           
  383.         boolean fileResult = false;  
  384.         // 判断是否存在该 Excel文件,如果不存在并用户继续执行操作,则后续处理返回都是False,即操作不成功。  
  385.         if (!excel.exists()) {  
  386.             // 创建新Excel文件  
  387.             fileResult = excel.createNewFile();  
  388.         }  
  389.         // 创建结果  
  390.         System.out.println(" fileResult == " + fileResult);  
  391.           
  392.           
  393.         // 判断是否存在指定名称的Sheet  
  394.         if (!excel.isExistSheet("jinxin")) {  
  395.             // 如果不存在,创建新Sheet  
  396.             boolean sheetResult = excel.createNewSheet("jinxin");  
  397.             // 创建结果  
  398.             System.out.println(" sheetResult == " + sheetResult);  
  399.         } else {  
  400.             // 如果存在,则把指定Sheet设为当前Sheet,如果不设定,取Workbook的第一个Sheet作为当前Sheet  
  401.             excel.switchCurrentSheet("jinxin");  
  402.         }  
  403.           
  404.         // 取指定位置的值  
  405.         String value = excel.getValue(00);  
  406.         System.out.println(" value == " + value);  
  407.           
  408.         // 设置指定位置的字符串值  
  409.         excel.setStringValue(00"sss");  
  410.         // 设置指定位置的数字值  
  411.         excel.setNumericValue(011234.012);  
  412.         // 设置指定位置的布尔值  
  413.         excel.setBooleanValue(02false);  
  414.           
  415.         if (!excel.isExistSheet("seconds")) {  
  416.             // 创建第二个Sheet  
  417.             excel.createNewSheet("seconds");  
  418.         } else {  
  419.             excel.switchCurrentSheet("seconds");  
  420.         }  
  421.           
  422.         // 设置指定位值的布尔值  
  423.         excel.setBooleanValue(12true);  
  424.         // 设置指定位值的日期值  
  425.         excel.setDateValue(11new Date(), "yyyy-MM-dd");  
  426.           
  427.         // 合并单元格操作  
  428.         excel.setStringValue(21"Test for Merging Cells");  
  429.         excel.mergeCells(2122);  
  430.           
  431.         // 对所有操作进行保存  
  432.         excel.saveChanges();  
  433.           
  434.         System.out.println("------ test end ------");  
  435.     }  
  436.       
  437. }  
该工具类封装了对于Ftp的操作,使用edtftpj.jar windchill
Java代码   收藏代码
  1. package ext.csc.util.thirdparty;  
  2.   
  3. import java.io.File;  
  4. import java.io.IOException;  
  5.   
  6. import wt.util.WTProperties;  
  7.   
  8. import com.enterprisedt.net.ftp.EventAdapter;  
  9. import com.enterprisedt.net.ftp.FTPConnectMode;  
  10. import com.enterprisedt.net.ftp.FTPException;  
  11. import com.enterprisedt.net.ftp.FTPTransferType;  
  12. import com.enterprisedt.net.ftp.FileTransferClient;  
  13.   
  14. import ext.csc.util.common.CSCDebug;  
  15.   
  16. /** 
  17.  * 该工具类封装了对于Ftp的操作,使用edtftpj.jar 
  18.  * @author mliu 
  19.  * 
  20.  */  
  21. public class CSCFtp {  
  22.     private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCFtp.class);         
  23.       
  24.     public static boolean VERBOSE = true;  
  25.   
  26.     static {  
  27. /*      VERBOSE = AliUtil.getSpecPropertiesValue("ext.ali.config.archive", 
  28.                 "ext.ali.archive.verbose", "false").equals("true");*/  
  29.     }  
  30.   
  31.     /** 
  32.      * 传输文件到Ftp服务器 
  33.      * @param ftpserver Ftp服务器IP(Ex: 132.253.220.106) 
  34.      * @param user  Ftp服务器用户名 
  35.      * @param password  Ftp服务器密码 
  36.      * @param fromPathFile  LocalFile - 待传输的文件全路径及文件名 
  37.      * @param toFileName    RemoteFile - 传输目的路径及文件名(Ex: /testZipArrived.zip) 
  38.      * @return  是否成功标记 
  39.      */  
  40.     public static boolean ftpToServer(String ftpserver, String user,  
  41.             String password, String fromPathFile, String toFileName) {  
  42.         if (VERBOSE)  
  43.             System.out.println("=>Enter FtpUtil.ftpToServer(),ftpServer : "  
  44.                     + ftpserver + ",user : " + user + ",password : " + password  
  45.                     + ",fromPathFile : " + fromPathFile + ",toFileName :"  
  46.                     + toFileName);  
  47.         boolean flag = false;  
  48.         int FTPPORT = 21;  
  49.         CSCFtpUploadListener ftpListener = null;  
  50.         long fileSize = 0;  
  51.         FileTransferClient ftp = null;  
  52.         try {  
  53.             ftp = new FileTransferClient();  
  54.             ftp.setUserName(user);  
  55.             ftp.setPassword(password);  
  56.             ftp.setRemoteHost(ftpserver);  
  57.             ftp.setRemotePort(FTPPORT);  
  58.             ftp.getAdvancedSettings().setControlEncoding("GB2312");  
  59.             File fromFile = new File(fromPathFile);  
  60.             fileSize = fromFile.length();  
  61.             if (VERBOSE)  
  62.                 System.out.println("=>the local file is : "  
  63.                         + fromFile.getName() + ", and its size is " + fileSize);  
  64.             ftpListener = new CSCFtpUploadListener(ftp, fileSize);  
  65.             ftp.setEventListener(ftpListener);  
  66.             ftp.getAdvancedSettings().setTransferBufferSize(102400);  
  67.             ftp.getAdvancedSettings().setTransferNotifyInterval(204800);  
  68.             // ftp.getAdvancedFTPSettings().setActivePortRange(61500,61510);  
  69.             // ftp.setTimeout(120);  
  70.             ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.ACTIVE);  
  71.             ftp.setContentType(FTPTransferType.BINARY);  
  72.             ftp.connect();  
  73.             if (VERBOSE)  
  74.                 System.out.println("=>Begin to upload " + fromPathFile);  
  75.             ftp.uploadFile(fromPathFile, toFileName);  
  76.             if (VERBOSE)  
  77.                 System.out.println("=>End to upload " + fromPathFile);  
  78.             if (ftp.isConnected())  
  79.                 ftp.disconnect();  
  80.             // deleteFile(fromPathFile);  
  81.             flag = true;  
  82.         } catch (NumberFormatException e) {  
  83.             // deleteFile(fromPathFile);  
  84.             e.printStackTrace();  
  85.         } catch (IOException e) {  
  86.             // deleteFile(fromPathFile);  
  87.             e.printStackTrace();  
  88.         } catch (FTPException e) {  
  89.             // deleteFile(fromPathFile);  
  90.             e.printStackTrace();  
  91.         } finally {  
  92.             try {  
  93.                 if (ftp.isConnected())  
  94.                     ftp.disconnect();  
  95.             } catch (Exception ex) {  
  96.                 System.out  
  97.                         .println("=>in finally block to close ftp connection, exception ocurred : "  
  98.                                 + ex.getMessage());  
  99.                 ex.printStackTrace();  
  100.             }  
  101.         }  
  102.         if (VERBOSE)  
  103.             System.out.println("=>Exit FtpUtil.ftpToServer()................");  
  104.         return flag;  
  105.     }  
  106.   
  107.     /** 
  108.      * 下载Ftp服务器的内容到本地 
  109.      * @param ftpserver Ftp服务器IP(Ex: 132.253.220.106) 
  110.      * @param user  Ftp服务器用户名 
  111.      * @param password  Ftp服务器密码 
  112.      * @param fromPathFile  LocalFile - 待传输的文件全路径及文件名 
  113.      * @param toFileName    RemoteFile - 传输目的路径及文件名(Ex: /testZipArrived.zip) 
  114.      * @return 成功的标记 
  115.      */  
  116.     public static boolean getFileFromServer(String ftpserver, String user,  
  117.             String password, String fromPathFile, String toFileName) {  
  118.         boolean flag = false;  
  119.         int FTPPORT = 21;  
  120.         CSCFtpUploadListener ftpListener = null;  
  121.         long fileSize = 0;  
  122.         FileTransferClient ftp = null;  
  123.   
  124.         try {  
  125.             ftp = new FileTransferClient();  
  126.             ftp.setUserName(user);  
  127.             ftp.setPassword(password);  
  128.             ftp.setRemoteHost(ftpserver);  
  129.             ftp.setRemotePort(FTPPORT);  
  130.             ftp.getAdvancedSettings().setControlEncoding("GB2312");  
  131.             ftpListener = new CSCFtpUploadListener(ftp, fileSize);  
  132.             ftp.setEventListener(ftpListener);  
  133.             ftp.getAdvancedSettings().setTransferBufferSize(102400);  
  134.             ftp.getAdvancedSettings().setTransferNotifyInterval(204800);  
  135.             ftp.getAdvancedFTPSettings().setActivePortRange(6150061510);  
  136.             // ftp.setTimeout(120);  
  137.             ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.ACTIVE);  
  138.             ftp.setContentType(FTPTransferType.BINARY);  
  139.             ftp.connect();  
  140.             System.out.println("=>Begin to get file " + toFileName  
  141.                     + ",the file exist is " + ftp.exists(toFileName));  
  142.             ftp.downloadFile(fromPathFile, toFileName);  
  143.             // ftp.uploadFile(fromPathFile,toFileName);  
  144.             System.out.println("=>End to get file,the file path is "  
  145.                     + fromPathFile);  
  146.             File localfile = new File(fromPathFile);  
  147.             if (localfile.length() > 0) {  
  148.                 //ftp.deleteFile(toFileName);  
  149.                 flag = true;  
  150.             }  
  151.             if (ftp.isConnected())  
  152.                 ftp.disconnect();  
  153.             // deleteFile(fromPathFile);  
  154.   
  155.         } catch (NumberFormatException e) {  
  156.             // deleteFile(fromPathFile);  
  157.             e.printStackTrace();  
  158.         } catch (IOException e) {  
  159.             // deleteFile(fromPathFile);  
  160.             e.printStackTrace();  
  161.         } catch (FTPException e) {  
  162.             // deleteFile(fromPathFile);  
  163.             e.printStackTrace();  
  164.         } finally {  
  165.             try {  
  166.                 if (ftp.isConnected())  
  167.                     ftp.disconnect();  
  168.             } catch (Exception ex) {  
  169.                 System.out.println("=>in finally block to close ftp connection, exception ocurred : "  
  170.                                 + ex.getMessage());  
  171.                 ex.printStackTrace();  
  172.             }  
  173.         }  
  174.         return flag;  
  175.     }  
  176.   
  177.     public static boolean deleteFile(String pathname) {  
  178.         try {  
  179.             File toBeDeleted = new File(pathname);  
  180.             toBeDeleted.delete();  
  181.             return (true);  
  182.         } catch (Exception ex) {  
  183.             ex.printStackTrace();  
  184.             return (false);  
  185.         }  
  186.     }  
  187.       
  188.     public static void main(String args[]) throws IOException {  
  189.         //************************ Test of ftpToServer ********************************  
  190. /*      String wthome = (String) (WTProperties.getLocalProperties()).getProperty("wt.home""");  
  191.         String zipFilePath = wthome + File.separator + "temp" + File.separator + "testZip.zip";       
  192.           
  193.         String userName = "ftp_user";  
  194.         String password = "cscftp";  
  195.         String ftpServer = "132.253.220.106";  
  196.         String fromFile = zipFilePath;  
  197.         String toFile = "/testZipArrived.zip";  
  198.         CSCFtp.ftpToServer(ftpServer, userName, password, fromFile, toFile);*/  
  199.           
  200.         //************************ Test of getFileFromServer ********************************  
  201.         String wthome = (String) (WTProperties.getLocalProperties()).getProperty("wt.home""");  
  202.         String zipFilePath = wthome + File.separator + "temp" + File.separator + "testZipLocal.zip";          
  203.           
  204.         String userName = "ftp_user";  
  205.         String password = "cscftp";  
  206.         String ftpServer = "132.253.220.106";  
  207.         String fromFile = zipFilePath;          //LocalFile  
  208.         String toFile = "/testZipArrived.zip";  //RemoteFile      
  209.         CSCFtp.getFileFromServer(ftpServer, userName, password, fromFile, toFile);    
  210.     }     
  211. }  
  212.   
  213.   
  214.   
  215. class CSCFtpUploadListener extends EventAdapter {  
  216.   
  217.     private long fileSize = 0;  
  218.   
  219.     private long bytesTransferred = 0;  
  220.   
  221.     private FileTransferClient ftpClient;  
  222.   
  223.     public CSCFtpUploadListener(FileTransferClient ftpClient, long fileSize) {  
  224.         this.ftpClient = ftpClient;  
  225.         this.fileSize = fileSize;  
  226.     }  
  227.   
  228.     public void bytesTransferred(String connId, String remoteFilename,  
  229.             long bytes) {  
  230.         bytesTransferred = bytes;  
  231.         if (bytesTransferred == fileSize) {  
  232.             System.out  
  233.                     .println("=>hi, now the bytesTransferred equals to the fileSize, so the file"  
  234.                             + remoteFilename + " transfer done!!!");  
  235.         }  
  236.     }  
  237.   
  238.     public void uploadCompleted(String connId, String remoteFilename) {  
  239.         System.out.println("=>the file " + remoteFilename  
  240.                 + " Upload Completed !!!");  
  241.     }  
  242.   
  243.     public long getBytesTransferred() {  
  244.         return bytesTransferred;  
  245.     }  
  246. }  
该工具类封装了对于Zip的一些功能 windchill
Java代码   收藏代码
  1. package ext.csc.util.thirdparty;  
  2.   
  3. import java.io.File;  
  4. import java.io.FileInputStream;  
  5. import java.io.FileOutputStream;  
  6. import java.io.InputStream;  
  7. import java.util.ArrayList;  
  8. import java.util.Enumeration;  
  9. import java.util.HashMap;  
  10. import java.util.Iterator;  
  11. import java.util.Set;  
  12. import java.util.zip.ZipInputStream;  
  13.   
  14. import org.apache.tools.zip.ZipEntry;  
  15. import org.apache.tools.zip.ZipFile;  
  16. import org.apache.tools.zip.ZipOutputStream;  
  17.   
  18. import wt.content.ContentRoleType;  
  19. import wt.doc.WTDocument;  
  20. import wt.util.WTProperties;  
  21.   
  22. import ext.csc.util.common.CSCDebug;  
  23. import ext.csc.util.core.CSCDoc;  
  24.   
  25. /** 
  26.  * 该工具类封装了对于Zip的一些功能 
  27.  * @author mliu 
  28.  * 
  29.  */  
  30. public class CSCZip {  
  31.     private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCZip.class);         
  32.       
  33.     /** 
  34.      * 打Zip包 
  35.      * @param fileMap   待打包文件对应表 (Key:待打包文件的InputStream, Value: 打包好的文件名) 
  36.      * @param outZipFilePath    输出的Zip全路径及文件名 
  37.      */  
  38.     public static void zip(HashMap<InputStream, String> fileMap, String outZipFilePath) throws Exception {  
  39.         byte[] buf = new byte[1024];  
  40.           
  41.         //如果目标路径不存在,则创建  
  42.         String[] aFolders;  
  43.         if(outZipFilePath.indexOf("\\") > -1){  
  44.             aFolders = outZipFilePath.split("\\\\");  
  45.         }else{  
  46.             aFolders = outZipFilePath.split("/");  
  47.         }          
  48.         String zipFolder = "";  
  49.         for (int i = 0; i < aFolders.length-1 ; i++) {  
  50.             zipFolder = zipFolder + aFolders[i] + File.separator;  
  51.         }  
  52.         File folder = new File(zipFolder);  
  53.         folder.mkdirs();      
  54.           
  55.         //开始打包  
  56.         File zipFile = new File(outZipFilePath);  
  57.         ZipOutputStream zos = new ZipOutputStream(zipFile);  
  58.           
  59.         Set<InputStream> set = fileMap.keySet();  
  60.         Iterator<InputStream> it = set.iterator();  
  61.         while (it.hasNext()) {  
  62.             InputStream is = it.next();  
  63.             String fileName = fileMap.get(is);  
  64.               
  65.             if (is != null) {  
  66.                 zos.putNextEntry(new ZipEntry(fileName));  
  67.                 int len = 0;  
  68.                 while ((len = is.read(buf)) >= 0){  
  69.                     zos.write(buf, 0, len);  
  70.                 }  
  71.                 is.close();  
  72.             }  
  73.         }  
  74.     }  
  75.       
  76.     /** 
  77.      * 解压缩Zip包 
  78.      * @param localpath Zip包文件路径 
  79.      * @param outpath   输出目录 
  80.      * @throws Exception 
  81.      */  
  82.     public static void unZip(String localpath, String outpath) throws Exception {  
  83.         ZipInputStream in = new ZipInputStream(new FileInputStream(localpath));  
  84.   
  85.         ZipFile zipFile = new ZipFile(localpath);  
  86.         Enumeration e = zipFile.getEntries();  
  87.         ZipEntry z = null;  
  88.   
  89.         //如果目标路径不存在,则创建  
  90.         File file = new File(outpath);  
  91.         file.mkdirs();  
  92.           
  93.         while (e.hasMoreElements()){  
  94.             z = (ZipEntry)e.nextElement();  
  95.   
  96.             System.out.println("unziping " + z.getName());  
  97.             if (z.isDirectory()) {  
  98.                 String name = z.getName();  
  99.                 name = name.substring(0, name.length() - 1);  
  100.                 File f = new java.io.File(outpath + File.separator + name);  
  101.                 f.mkdir();  
  102.             } else {  
  103.                 String filename = z.getName();  
  104.                   
  105.                 //如果解压包内路径不存在,则创建  
  106.                 String[] aFolders;  
  107.                 if(filename.indexOf("\\") > -1){  
  108.                     aFolders = filename.split("\\\\");  
  109.                 }else{  
  110.                     aFolders = filename.split("/");  
  111.                 }                  
  112.                 String zipFolder = "";  
  113.                 for (int i = 0; i < aFolders.length-1 ; i++) {  
  114.                     zipFolder = zipFolder + aFolders[i] + File.separator;  
  115.                 }  
  116.                 zipFolder = outpath + File.separator + zipFolder;  
  117.                 File folder = new File(zipFolder);  
  118.                 folder.mkdirs();  
  119.                   
  120.                 //开始解压  
  121.                 File f = new File(outpath + File.separator + filename);  
  122.                 f.createNewFile();  
  123.                 FileOutputStream output = new FileOutputStream(f);  
  124.                 int b;  
  125.                 while ((b = in.read()) != -1){  
  126.                     output.write(b);  
  127.                 }  
  128.                 output.close();  
  129.             }  
  130.         }  
  131.         in.close();  
  132.     }  
  133.       
  134.     public static void main(String[] args) throws Exception {  
  135.         //************************ Test of Zip ********************************  
  136.         WTDocument doc = CSCDoc.getDoc("0000000041"false);  
  137.         //配置打包文件  
  138.         String wthome = (String) (WTProperties.getLocalProperties()).getProperty("wt.home""");  
  139.         String docDownloadFileFolder = wthome + File.separator + "temp" + File.separator + "downloaded";          
  140.         ArrayList<String> fileDownloaded = CSCDoc.downloadContentFiles(doc, ContentRoleType.SECONDARY, docDownloadFileFolder);  
  141.         HashMap fileMap = new HashMap<InputStream, String>();  
  142.         for (int i = 0; i < fileDownloaded.size(); i++) {  
  143.             //得到文件名  
  144.             String tempFile = fileDownloaded.get(i);  
  145.             String arrayFileName[];  
  146.             if(tempFile.indexOf("\\") > -1){  
  147.                 arrayFileName = tempFile.split("\\\\");  
  148.             }else{  
  149.                 arrayFileName = tempFile.split("/");  
  150.             }       
  151.             String filename = arrayFileName[arrayFileName.length-1];  
  152.               
  153.             File file = new File(tempFile);  
  154.             InputStream fileIs = new FileInputStream(file);  
  155.             fileMap.put(fileIs, doc.getName() + "-" + filename);  
  156.         }  
  157.           
  158.         String docZipPath = wthome + File.separator + "temp" + File.separator + "CSCZip.zip";         
  159.         CSCZip.zip(fileMap, docZipPath);  
  160.           
  161.         //************************ Test of unZip ********************************  
  162. /*      String wthome = (String) (WTProperties.getLocalProperties()).getProperty("wt.home""");  
  163.         String zipFilePath = wthome + File.separator + "temp" + File.separator + "testZip.zip";  
  164.         String zipDestinationPath = wthome + File.separator + "temp" + File.separator + "destination";  
  165.         CSCZip.unZip(zipFilePath, zipDestinationPath);*/  
  166.     }  
  167. }  
action过滤器的写法 windchill
Windchill代码   收藏代码
  1. package ext.maric.audit;  
  2.   
  3. import wt.access.AccessControlHelper;  
  4. import wt.access.AccessPermission;  
  5. import wt.admin.AdminDomainRef;  
  6. import wt.fc.ReferenceFactory;  
  7. import wt.fc.WTReference;  
  8. import wt.folder.Folder;  
  9. import wt.inf.container.WTContained;  
  10. import wt.inf.container.WTContainer;  
  11. import wt.inf.container.WTContainerRef;  
  12. import wt.util.WTException;  
  13.   
  14. import com.ptc.core.ui.validation.DefaultSimpleValidationFilter;  
  15. import com.ptc.core.ui.validation.UIValidationCriteria;  
  16. import com.ptc.core.ui.validation.UIValidationKey;  
  17. import com.ptc.core.ui.validation.UIValidationStatus;  
  18.   
  19.   
  20. public class AnswerExamFilter extends DefaultSimpleValidationFilter {  
  21.   
  22.     /* (non-Javadoc)  
  23.      * @see com.ptc.core.ui.validation.DefaultValidationFilter#preValidateAction(com.ptc.core.ui.validation.UIValidationKey, com.ptc.core.ui.validation.UIValidationCriteria)  
  24.      */  
  25.     public UIValidationStatus preValidateAction(UIValidationKey key, UIValidationCriteria criteria){          
  26.         UIValidationStatus status = UIValidationStatus.HIDDEN;  
  27.         WTReference contextObj = criteria.getContextObject();  
  28.         Object obj = contextObj.getObject();  
  29.         boolean hasCreateAccess = false;  
  30.         WTContainerRef containerRef = null;  
  31.           
  32.         //检查是否处于退审意见答复单文件夹之下  
  33.         if(obj!=null){  
  34.             if(obj instanceof Folder){  
  35.                 Folder folder = (Folder)obj;  
  36.                 String folderName = folder.getFolderPath();  
  37. //              if(folderName.equals("/Default/送退审/退审意见答复单")){  
  38.                 if(folderName.indexOf("退审意见答复单") > -1){  
  39.                     status = UIValidationStatus.ENABLED;      
  40.                 }else{  
  41.                     status = UIValidationStatus.HIDDEN;  
  42.                     return status;  
  43.                 }  
  44.             }else{  
  45.                 status = UIValidationStatus.HIDDEN;  
  46.                 return status;  
  47.             }  
  48.               
  49.             //检查是否有权限创建送审单文档  
  50.             if(obj instanceof WTContainer){  
  51.                 WTContainer container = (WTContainer)obj;  
  52.                 ReferenceFactory rf = new ReferenceFactory();  
  53.                 try {  
  54.                     containerRef = (WTContainerRef)rf.getReference(container);  
  55.                 } catch (WTException e) {  
  56.                     // TODO Auto-generated catch block  
  57.                     status = UIValidationStatus.HIDDEN;  
  58.                     return status;  
  59.                 }             
  60.             }else{  
  61.                 if(obj instanceof WTContained){  
  62.                     WTContained contained = (WTContained)obj;  
  63.                     containerRef = contained.getContainerReference();  
  64.                 }  
  65.             }  
  66.               
  67.             try {  
  68.                 AdminDomainRef adminRef = AdminDomainRef.newAdminDomainRef(((WTContainer)containerRef.getObject()).getSystemDomain());  
  69.                 AccessControlHelper.manager.checkAccess(adminRef, AuditBaseline.class.getName(),AccessPermission.CREATE);                         
  70.               
  71.                 hasCreateAccess = true;  
  72.             } catch (WTException e) {  
  73.                 hasCreateAccess = false;  
  74.             }  
  75.             if(hasCreateAccess){  
  76.                 status = UIValidationStatus.ENABLED;      
  77.             }else{  
  78.                 status = UIValidationStatus.HIDDEN;   
  79.             }  
  80.         }  
  81.         return status;  
  82.     }  
  83.   

你可能感兴趣的:(Windchill Code)