WebService Client
- public class RmRemoteDelegate {
- private RMItemService query = null;
-
- private static String ACCOUNTINFOFILEPATH = "";
- // private static File configFile = null; //配置文件
- static {
- //读取配置文件
- try {
- WTProperties wtproperties = WTProperties.getLocalProperties();
- ACCOUNTINFOFILEPATH = new StringBuffer().append(wtproperties.getProperty("wt.home"))
- .append(System.getProperty("file.separator")).append("config").append(
- System.getProperty("file.separator")).append(
- "SystemIntegrationAccounts.properties").toString();
- // configFile = new File(ACCOUNTINFOFILEPATH);
- } catch (IOException e) {
- System.out.println("读取配置文件SystemIntegrationAccounts.properties失败!下面是异常信息:");
- e.printStackTrace();
- }
- }
- public RmRemoteDelegate() {
- try {
-
- // Properties rmProperty = new Properties();
- // FileInputStream sysConfInput = null;
- String userName = null;
- String passWord = null;
- try {
- // sysConfInput = new FileInputStream(configFile);
- // rmProperty.load(sysConfInput);
- String server = PropertiesUtil.getProperty(ACCOUNTINFOFILEPATH, "rm.url"); //rmProperty.getProperty("rm.url");
- String accounts = PropertiesUtil.getProperty(ACCOUNTINFOFILEPATH,"rmServiceAccount");//rmProperty.getProperty("rmserviceAccount");
- String dECstrDenc = DESEncoding.DeCode(accounts);
- userName = dECstrDenc.substring(0, dECstrDenc.indexOf("="));
- passWord = dECstrDenc.substring(dECstrDenc.indexOf("=") + 1);
- RMItemServiceServiceLocator cws = new RMItemServiceServiceLocator();
- cws.setRMItemEndpointAddress(server);
- try {
- query = cws.getRMItem();
- } catch (ServiceException e) {
- System.out.println("连接RM失败!");
- throw new WTException(e);
- }
- RMItemSoapBindingStub stub = (RMItemSoapBindingStub) query;
- stub.setUsername(userName);
- stub.setPassword(passWord);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- /*RMItemServiceServiceLocator cws = new RMItemServiceServiceLocator();
- try {
- query = cws.getRMItem();
- } catch (Exception e) {
- e.printStackTrace();
- }
- RMItemSoapBindingStub stub = (RMItemSoapBindingStub) query;
- // stub.setHeader(setSoapHeader(USERNAME, PASSWORD));
- ((org.apache.axis.client.Stub)stub).setUsername(USERNAME);
- ((org.apache.axis.client.Stub)stub).setPassword(PASSWORD);*/
-
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private static SOAPHeaderElement setSoapHeader(String wsUserName,
- String wsPassword) {
-
- SOAPHeaderElement soapHeaderElement = null;
- try {
- soapHeaderElement = new org.apache.axis.message.SOAPHeaderElement(
- "wsse", "Security");
- soapHeaderElement.setMustUnderstand(true);
- soapHeaderElement
- .setNamespaceURI("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
- SOAPElement token = soapHeaderElement
- .addChildElement("UsernameToken");
- SOAPElement userName = token
- .addChildElement(
- "Username",
- "wsse",
- "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
- userName.setValue(wsUserName);
- SOAPElement password = token
- .addChildElement(
- "Password",
- "wsse",
- "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
- password.setValue(wsPassword);
-
- } catch (Exception err) {
- err.printStackTrace();
- }
- return soapHeaderElement;
- }
-
- public TreeNodeBean[] getItemTree(ext.huawei.integration.rm.client.GetItemTreeParamBean[] getItemTreePrarmBean) throws RemoteException {
- return query.getItemTree(getItemTreePrarmBean);
- }
-
- }
|
windchill |
|
获取容器对象下得角色与指定角色的成员 |
windchill |
|
Java代码
- package ext.csc.util.core;
-
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.Enumeration;
- import java.util.Vector;
-
- import wt.fc.PersistenceHelper;
- import wt.fc.QueryResult;
- import wt.inf.container.OrgContainer;
- import wt.inf.library.WTLibrary;
- import wt.inf.team.ContainerTeam;
- import wt.inf.team.ContainerTeamHelper;
- import wt.inf.team.ContainerTeamManaged;
- import wt.inf.team.StandardContainerTeamService;
- import wt.method.RemoteAccess;
- import wt.method.RemoteMethodServer;
- import wt.org.OrganizationServicesHelper;
- import wt.org.WTGroup;
- import wt.org.WTPrincipal;
- import wt.org.WTPrincipalReference;
- import wt.pdmlink.PDMLinkProduct;
- import wt.project.Role;
- import wt.projmgmt.admin.Project2;
- import wt.query.QuerySpec;
- import wt.query.SearchCondition;
- import wt.session.SessionServerHelper;
- import wt.team.TeamException;
- import wt.util.WTException;
- import ext.csc.util.common.CSCDebug;
-
- /**
- * 该工具类封装了对于Container的一系列底层操作
- * @author mliu
- *
- */
- public class CSCContainer implements RemoteAccess, Serializable{
- private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCContainer.class);
-
- private static final long serialVersionUID = 5458003848567223542L;
-
- /**
- * 通过名称查找PDMLinkProduct
- * @param name 查询PDMLinkProduct名称条件
- * @param accessControlled 是否受到权限制约
- * @return 返回查询到的PDMLinkProduct对象
- */
- public static PDMLinkProduct getPDMLinkProduct(String name, boolean accessControlled){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (PDMLinkProduct) RemoteMethodServer.getDefault().invoke("getPDMLinkProduct", CSCContainer.class.getName(), null,
- new Class[] {String.class, boolean.class},
- new Object[] {name, accessControlled});
- } else {
- PDMLinkProduct product = null;
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);
- try {
- QuerySpec qs = new QuerySpec(PDMLinkProduct.class);
- SearchCondition sc = new
- SearchCondition(PDMLinkProduct.class, PDMLinkProduct.NAME, SearchCondition.EQUAL, name, false);
- qs.appendSearchCondition(sc);
-
- QueryResult qr = PersistenceHelper.manager.find(qs);
-
- if (qr.hasMoreElements()){
- product = (PDMLinkProduct)qr.nextElement();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return product;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * 通过名称查找WTLibrary
- * @param name 查询WTLibrary名称条件
- * @param accessControlled 是否受到权限制约
- * @return 返回查询到的WTLibrary对象
- */
- public static WTLibrary getLibrary(String name, boolean accessControlled){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTLibrary) RemoteMethodServer.getDefault().invoke("getLibrary", CSCContainer.class.getName(), null,
- new Class[] {String.class, boolean.class},
- new Object[] {name, accessControlled});
- } else {
- WTLibrary library = null;
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);
- try {
- QuerySpec qs = new QuerySpec(WTLibrary.class);
- SearchCondition sc = new
- SearchCondition(WTLibrary.class, WTLibrary.NAME, SearchCondition.EQUAL, name, false);
- qs.appendSearchCondition(sc);
-
- QueryResult qr = PersistenceHelper.manager.find(qs);
-
- if (qr.hasMoreElements()){
- library = (WTLibrary)qr.nextElement();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return library;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 通过名称查找Project2
- * @param name 查询Project2名称条件
- * @param accessControlled 是否受到权限制约
- * @return 返回查询到的Project2对象
- */
- public static Project2 getProject(String name, boolean accessControlled){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (Project2) RemoteMethodServer.getDefault().invoke("getProject", CSCContainer.class.getName(), null,
- new Class[] {String.class, boolean.class},
- new Object[] {name, accessControlled});
- } else {
- Project2 project = null;
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);
- try {
- QuerySpec qs = new QuerySpec(Project2.class);
- SearchCondition sc = new
- SearchCondition(Project2.class, Project2.NAME, SearchCondition.EQUAL, name, false);
- qs.appendSearchCondition(sc);
-
- QueryResult qr = PersistenceHelper.manager.find(qs);
-
- if (qr.hasMoreElements()){
- project = (Project2)qr.nextElement();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return project;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 通过编号查找Project2
- * @param number 查询Project2编号条件
- * @param accessControlled 是否受到权限制约
- * @return 返回查询到的Project2对象
- */
- public static Project2 getProjectByNumber(String number, boolean accessControlled){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (Project2) RemoteMethodServer.getDefault().invoke("getProjectByNumber", CSCContainer.class.getName(), null,
- new Class[] {String.class, boolean.class},
- new Object[] {number, accessControlled});
- } else {
- Project2 project = null;
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);
- try {
- QuerySpec qs = new QuerySpec(Project2.class);
- SearchCondition sc = new
- SearchCondition(Project2.class, Project2.PROJECT_NUMBER, SearchCondition.EQUAL, number, false);
- qs.appendSearchCondition(sc);
-
- QueryResult qr = PersistenceHelper.manager.find(qs);
-
- if (qr.hasMoreElements()){
- project = (Project2)qr.nextElement();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return project;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * 通过名称查找OrgContainer组织对象
- * @param name 查询OrgContainer名称条件
- * @param accessControlled 是否受到权限制约
- * @return 返回查询到的OrgContainer对象
- */
- public static OrgContainer getOrgContainer(String name, boolean accessControlled) throws WTException{
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (OrgContainer) RemoteMethodServer.getDefault().invoke("getOrgContainer", CSCContainer.class.getName(), null,
- new Class[] {String.class, boolean.class},
- new Object[] {name, accessControlled});
- } else {
- OrgContainer org = null;
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);
- try {
- QuerySpec criteria = new QuerySpec(OrgContainer.class);
- criteria.appendWhere(new SearchCondition(OrgContainer.class,OrgContainer.NAME,SearchCondition.EQUAL,name,false));
- QueryResult results = PersistenceHelper.manager.find(criteria);
-
- if(results.hasMoreElements()) {
- org = (OrgContainer)results.nextElement();
- }else{
- return null;
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return org;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 得到Container对象的团队角色列表
- * @param teammanaged 可包含团队的Container对象
- * @return Container团队角色列表
- */
- public static ArrayList<Role> getContainerTeamRoles(ContainerTeamManaged teammanaged){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<Role>) RemoteMethodServer.getDefault().invoke("getContainerTeamRoles", CSCContainer.class.getName(), null,
- new Class[] {ContainerTeamManaged.class},
- new Object[] {teammanaged});
- } else {
- ArrayList<Role> result = new ArrayList<Role>();
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- try {
- ContainerTeam team = ContainerTeamHelper.service.getContainerTeam(teammanaged);
- Vector v = team.getRoles();
-
- if(v == null){
- return result;
- }
- for (int i = 0; i < v.size(); i++) {
- Object obj = v.get(i);
- if(obj instanceof Role){
- Role role = (Role)obj;
- if(!result.contains(role))
- result.add(role);
- }
- }
- } catch (TeamException e) {
- e.printStackTrace();
- } catch (WTException e) {
- e.printStackTrace();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return result;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return new ArrayList<Role>();
- }
-
- /**
- * 得到Container对象的指定角色的成员列表
- * @param teammanaged 可包含团队的Container对象
- * @param role 指定的团队角色
- * @return Container的指定Role的成员列表(WTPrincipalReference)
- */
- public static ArrayList<WTPrincipalReference> getContainerPrincipalByRole(ContainerTeamManaged teammanaged, Role role){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTPrincipalReference>) RemoteMethodServer.getDefault().invoke("getContainerPrincipalByRole", CSCContainer.class.getName(), null,
- new Class[] {ContainerTeamManaged.class, Role.class},
- new Object[] {teammanaged, role});
- } else {
- ArrayList<WTPrincipalReference> result = new ArrayList<WTPrincipalReference>();
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- try {
- ContainerTeam team = ContainerTeamHelper.service.getContainerTeam(teammanaged);
- StandardContainerTeamService scts = StandardContainerTeamService.newStandardContainerTeamService();
-
- WTGroup wtgroup = scts.findContainerTeamGroup(team, ContainerTeamHelper.ROLE_GROUPS, role.toString());
- if (wtgroup != null) {
- Enumeration enumeration = OrganizationServicesHelper.manager.members(wtgroup, false, true);
- while(enumeration.hasMoreElements()){
- WTPrincipalReference wtprincipalreference = WTPrincipalReference
- .newWTPrincipalReference((WTPrincipal) enumeration
- .nextElement());
- if(!result.contains(wtprincipalreference)){
- result.add(wtprincipalreference);
- }
- }
- }
- } catch (TeamException e) {
- e.printStackTrace();
- } catch (WTException e) {
- e.printStackTrace();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return result;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return new ArrayList<WTPrincipalReference>();
- }
-
- public static void main(String[] args) throws WTException {
- //************************ Test of getPDMLinkProduct ********************************
- PDMLinkProduct product = CSCContainer.getPDMLinkProduct("GOLF_CART", false);
- System.out.println("Find Product = " + product.getContainerName());
-
- //************************ Test of getLibrary ********************************
- /* WTLibrary library = CSCContainer.getLibrary(args[0], Boolean.parseBoolean(args[1]));
- System.out.println("Find Library = " + library);*/
-
- //************************ Test of getProject ********************************
- /* Project2 project = CSCContainer.getProject(args[0], Boolean.parseBoolean(args[1]));
- System.out.println("Find Project = " + project); */
-
- //************************ Test of getProjectByNumber ********************************
- /* Project2 project = CSCContainer.getProjectByNumber(args[0], Boolean.parseBoolean(args[1]));
- System.out.println("Find Project = " + project);*/
-
- //************************ Test of getProjectByNumber ********************************
- /* OrgContainer org = CSCContainer.getOrgContainer(args[0], Boolean.parseBoolean(args[1]));
- System.out.println("Find OrgContainer = " + org); */
-
- //************************ Test of getContainerTeamRoles ********************************
- /*//PDMLinkProduct product = CSCContainer.getPDMLinkProduct(args[0], false);
- ArrayList<Role> roles = CSCContainer.getContainerTeamRoles(product);
- for (int i = 0; i < roles.size(); i++) {
- System.out.println("Find Role = " + roles.get(i));
- }*/
-
- //************************ Test of getContainerPrincipalByRole ********************************
- //PDMLinkProduct product = CSCContainer.getPDMLinkProduct(args[0], false);
- ArrayList<Role> roles = CSCContainer.getContainerTeamRoles(product);
- for (int i = 0; i < roles.size(); i++) {
- System.out.println("Find Role = " + (roles.get(i)).getDisplay());
- ArrayList<WTPrincipalReference> principals = CSCContainer.getContainerPrincipalByRole(product, roles.get(i));
- for (int j = 0; j < principals.size(); j++) {
- System.out.println("--> " + (principals.get(j)).getDisplayName());
- }
- }
- }
- }
|
乱码问题 |
乱码问题, windchill |
|
Java代码
- http://wenku.baidu.com/view/a99291c458f5f61fb736667e.html
-
-
- 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代码
- package ext.ts.part;
-
- import java.io.Serializable;
-
- import com.google.gwt.i18n.client.LocalizableResource.GeneratedFrom;
- import com.ptc.windchill.annotations.metadata.DerivedProperty;
- import com.ptc.windchill.annotations.metadata.ForeignKeyRole;
- import com.ptc.windchill.annotations.metadata.GenAsPersistable;
- import com.ptc.windchill.annotations.metadata.GeneratedForeignKey;
- import com.ptc.windchill.annotations.metadata.GeneratedProperty;
- import com.ptc.windchill.annotations.metadata.MyRole;
- import com.ptc.windchill.annotations.metadata.PropertyConstraints;
-
- import com.ptc.windchill.annotations.metadata.SupportedAPI;
-
- import wt.part.WTPart;
- import wt.util.WTException;
- @GenAsPersistable(superClass=WTPart.class,properties={@GeneratedProperty(name="attrString",
- type=String.class,constraints=@PropertyConstraints(required=false))
- },
- foreignKeys={
- @GeneratedForeignKey(foreignKeyRole=@ForeignKeyRole(name="master",type=ext.ts.part.TSPart.class,cascade=false,
- constraints=@PropertyConstraints(required=true)),myRole=@MyRole(name="iteration",supportedAPI=SupportedAPI.PUBLIC,cascade=false))
- },derivedProperties={
- @DerivedProperty(name="masterAttrString",derivedFrom="master>masterAttrString")
- }
- )
- public class TSPart extends _TSPart {
- static final long SerialVersionUID=1;
- public static TSPart newTSPart() throws WTException{
- final TSPart instance=new TSPart();
- instance.initialize();
- return instance;
- }
- }
|
该工具类封装了对于ManagedBaseline的一系列底层操作 |
windchill |
|
Java代码
- package ext.csc.util.core;
-
- import java.io.Serializable;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.HashMap;
-
- import wt.fc.PersistenceHelper;
- import wt.fc.QueryResult;
- import wt.fc.collections.WTValuedHashMap;
- import wt.folder.Folder;
- import wt.folder.FolderHelper;
- import wt.inf.container.WTContainerRef;
- import wt.method.RemoteAccess;
- import wt.method.RemoteMethodServer;
- import wt.query.QuerySpec;
- import wt.query.SearchCondition;
- import wt.session.SessionServerHelper;
- import wt.util.WTException;
- import wt.vc.baseline.BaselineHelper;
- import wt.vc.baseline.Baselineable;
- import wt.vc.baseline.ManagedBaseline;
-
- import com.ptc.core.meta.common.TypeIdentifier;
- import com.ptc.core.meta.common.TypeIdentifierHelper;
- import com.ptc.windchill.enterprise.copy.server.CoreMetaUtility;
-
- import ext.csc.util.common.CSCDebug;
-
- /**
- * 该工具类封装了对于ManagedBaseline的一系列底层操作
- * @author mliu
- *
- */
- public class CSCBaseline implements RemoteAccess, Serializable{
- private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCBaseline.class);
-
- public static String FOLDER = "FOLDER"; //创建文件夹 (默认:/Default)
- public static String DESCRIPTION = "DESCRIPTION"; //描述
- public static String TYPE = "TYPE"; //类型 (默认:wt.vc.baseline.ManagedBaseline)
-
- private static final long serialVersionUID = -8423672460519840395L;
-
- /**
- * 通过编号查找基线
- * @param number 查询基线编号条件
- * @param accessControlled 是否受到权限制约
- * @return 返回结果基线
- */
- public static ManagedBaseline getBaseline(String number, boolean accessControlled) {
- try {
- number = number.toUpperCase();
-
- if (!RemoteMethodServer.ServerFlag) {
- return (ManagedBaseline) RemoteMethodServer.getDefault().invoke("getBaseline", CSCBaseline.class.getName(), null,
- new Class[] {String.class, boolean.class},
- new Object[] {number, accessControlled});
- } else {
- ManagedBaseline baseline = null;
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);
- try {
- QuerySpec spec = new QuerySpec(ManagedBaseline.class);
- spec.appendWhere(
- new SearchCondition(ManagedBaseline.class,
- ManagedBaseline.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });
-
- QueryResult qr = PersistenceHelper.manager.find(spec);
- if (qr.hasMoreElements()){
- baseline = (ManagedBaseline)qr.nextElement();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return baseline;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 通过基线内容对象查找基线
- * @param baselineable 查询内容对象
- * @return 返回结果基线集
- */
- public static ArrayList<ManagedBaseline> getBaselineByBaselineable(Baselineable baselineable) {
- ArrayList<ManagedBaseline> results = new ArrayList<ManagedBaseline>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<ManagedBaseline>) RemoteMethodServer.getDefault().invoke("getBaselineByBaselineable", CSCBaseline.class.getName(), null,
- new Class[] {Baselineable.class},
- new Object[] {baselineable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = BaselineHelper.service.getBaselines(baselineable);
- while (qr.hasMoreElements()){
- ManagedBaseline baseline = (ManagedBaseline)qr.nextElement();
- if(!results.contains(baseline)){
- results.add(baseline);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 得到默认的基线序列号
- * @return 10位的序列号字符串
- */
- public static String getDefaultBaselineSeqNumber(){
- String bitFormat = "";
-
- try{
- for (int i = 0; i < 10; i++) {
- bitFormat = bitFormat + "0";
- }
-
- int seq = Integer.parseInt(PersistenceHelper.manager.getNextSequence(ManagedBaseline.class));
- DecimalFormat format = new DecimalFormat(bitFormat);
- return format.format(seq);
- }catch(Exception ex){
- ex.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 创建基线
- * @param number 编号 (默认为系统的Baseline Sequence)
- * @param name 名称 (必须)
- * @param attributes 固定属性对应表 (必须)
- * @param containerRef 上下文
- * @return 如果指定编号的基线存在,则返回该基线
- */
- public static ManagedBaseline createBaseline(String number, String name, HashMap attributes, WTContainerRef containerRef){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ManagedBaseline) RemoteMethodServer.getDefault().invoke("createBaseline", CSCBaseline.class.getName(), null,
- new Class[] {String.class, String.class, HashMap.class, WTContainerRef.class},
- new Object[] {number, name, attributes, containerRef});
- } else {
- ManagedBaseline baseline = null;
-
- try {
- String baselineDesc = "";
- String baselineType = "";
- String baselineFolder = "";
-
- if(attributes != null){
- baselineDesc = (String)attributes.get(CSCBaseline.DESCRIPTION);
- baselineType = (String)attributes.get(CSCBaseline.TYPE);
- baselineFolder = (String)attributes.get(CSCBaseline.FOLDER);
- }
-
- if(containerRef == null){
- return null;
- }
-
- //设置编号默认值 (默认为系统的Baseline Sequence)
- if(number == null || number.equalsIgnoreCase("")){
- number = CSCBaseline.getDefaultBaselineSeqNumber();
- }else{
- //如果此编号基线已存在,则返回该基线
- ManagedBaseline existBaseline = CSCBaseline.getBaseline(number, false);
- if(existBaseline != null){
- return existBaseline;
- }
- }
-
- if(name == null || name.equalsIgnoreCase("")){
- return null;
- }
-
- if(baselineDesc == null){
- baselineDesc = "";
- }
-
- //设置默认类型 (默认:wt.vc.baseline.ManagedBaseline)
- if(baselineType == null || baselineType.equalsIgnoreCase("")){
- baselineType = "wt.vc.baseline.ManagedBaseline";
- }
-
- //设置默认文件夹 (默认:/Default)
- if(baselineFolder == null || baselineFolder.equalsIgnoreCase("")){
- baselineFolder = "/Default";
- }else{
- if(!baselineFolder.startsWith("/Default")){
- baselineFolder = "/Default/" + baselineFolder;
- }
- }
-
- baseline = ManagedBaseline.newManagedBaseline();
- baseline.setNumber(number);
- baseline.setName(name);
-
- //设置基线描述
- baseline.setDescription(baselineDesc);
-
- //设置基线类型
- if(baselineType != null){
- TypeIdentifier id = TypeIdentifierHelper.getTypeIdentifier(baselineType);
- baseline = (ManagedBaseline) CoreMetaUtility.setType(baseline, id);
- }
-
- //设置上下文
- baseline.setContainerReference(containerRef);
-
- //设置文件夹
- Folder location = null;
- //查询文件夹是否存在
- try {
- location = FolderHelper.service.getFolder(baselineFolder,containerRef);
- } catch (Exception e) {
- location = null;
- }
- //若文件夹不存在,则创建该文件夹
- if(location == null)
- location = FolderHelper.service.saveFolderPath(baselineFolder, containerRef);
- //设置文件夹到基线对象
- if (location != null) {
- WTValuedHashMap map = new WTValuedHashMap();
- map.put(baseline, location);
- FolderHelper.assignLocations(map);
- }
-
- baseline = (ManagedBaseline) PersistenceHelper.manager.save(baseline);
- baseline = (ManagedBaseline) PersistenceHelper.manager.refresh(baseline);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
-
- return baseline;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * 通过基线得到基线内容
- * @param baseline 条件基线
- * @return 基线内容对象集
- */
- public static ArrayList<Baselineable> getBaselineItems(ManagedBaseline baseline){
- ArrayList<Baselineable> results = new ArrayList<Baselineable>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<Baselineable>) RemoteMethodServer.getDefault().invoke("getBaselineItems", CSCBaseline.class.getName(), null,
- new Class[] {ManagedBaseline.class},
- new Object[] {baseline});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = BaselineHelper.service.getBaselineItems(baseline);
- while(qr.hasMoreElements()){
- Object obj = qr.nextElement();
- if(obj instanceof Baselineable){
- Baselineable baselineable = (Baselineable)obj;
- if(!results.contains(baselineable)){
- results.add(baselineable);
- }
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
-
- /**
- * 为基线添加内容对象
- * @param baseline 目标基线
- * @param baselineable 基线内容对象
- * @return 添加好的基线对象
- */
- public static ManagedBaseline addBaselineable(ManagedBaseline baseline, Baselineable baselineable){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ManagedBaseline) RemoteMethodServer.getDefault().invoke("addBaselineable", CSCBaseline.class.getName(), null,
- new Class[] {ManagedBaseline.class, Baselineable.class},
- new Object[] {baseline, baselineable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- baseline = (ManagedBaseline) BaselineHelper.service.addToBaseline(baselineable, baseline);
- baseline = (ManagedBaseline) PersistenceHelper.manager.refresh(baseline);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return baseline;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return baseline;
- }
-
-
- /**
- * 为基线移除内容对象
- * @param baseline 目标基线
- * @param baselineable 待移除的基线内容对象
- * @return 移除好的基线对象
- */
- public static ManagedBaseline removeBaselineable(ManagedBaseline baseline, Baselineable baselineable){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ManagedBaseline) RemoteMethodServer.getDefault().invoke("removeBaselineable", CSCBaseline.class.getName(), null,
- new Class[] {ManagedBaseline.class, Baselineable.class},
- new Object[] {baseline, baselineable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- baseline = (ManagedBaseline) BaselineHelper.service.removeFromBaseline(baselineable, baseline);
- baseline = (ManagedBaseline) PersistenceHelper.manager.refresh(baseline);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return baseline;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return baseline;
- }
-
-
- public static void main(String[] args) throws WTException {
- //************************ Test of getBaseline ********************************
- /* ManagedBaseline baseline = CSCBaseline.getBaseline(args[0], Boolean.parseBoolean(args[1]));
- System.out.println("Result Baseline = " + baseline);*/
-
- //************************ Test of createBaseline ********************************
- /* PDMLinkProduct product = CSCContainer.getPDMLinkProduct(args[2], false);
- ReferenceFactory rf = new ReferenceFactory();
- WTContainerRef containerRef = (WTContainerRef) rf.getReference(product);
-
- HashMap<String, String> attributes = new HashMap<String, String>();
- attributes.put(CSCBaseline.FOLDER, "/Default/TestCreateBaselineFolder");
- attributes.put(CSCBaseline.TYPE, "TestBaselineType");
-
- ManagedBaseline baseline = CSCBaseline.createBaseline(args[0], args[1], attributes, containerRef);
- System.out.println("Result Baseline = " + baseline);*/
-
- //************************ Test of getBaselineItems ********************************
- /* ManagedBaseline baseline = CSCBaseline.getBaseline(args[0], false);
- ArrayList<Baselineable> baselineables = CSCBaseline.getBaselineItems(baseline);
- for (int i = 0; i < baselineables.size(); i++) {
- System.out.println("Result Baselineables = " + baselineables.get(i));
- }*/
-
- //************************ Test of getBaselineByBaselineable ********************************
- /* WTPart wtpart = CSCPart.getPart(args[0], false);
- ArrayList<ManagedBaseline> baselines = CSCBaseline.getBaselineByBaselineable(wtpart);
- for (int i = 0; i < baselines.size(); i++) {
- System.out.println("Result Baseline = " + baselines.get(i));
- }*/
-
- //************************ Test of addBaselineable ********************************
- /* WTPart wtpart = CSCPart.getPart(args[0], false);
- ManagedBaseline baseline = CSCBaseline.getBaseline(args[1], false);
- baseline = CSCBaseline.addBaselineable(baseline, wtpart);
- System.out.println("Result Baseline = " + baseline);*/
-
- //************************ Test of removeBaselineable ********************************
- /* WTPart wtpart = CSCPart.getPart(args[0], false);
- ManagedBaseline baseline = CSCBaseline.getBaseline(args[1], false);
- baseline = CSCBaseline.removeBaselineable(baseline, wtpart);
- System.out.println("Result Baseline = " + baseline);*/
- }
- }
|
该工具类封装了对于ProblemReport, ChangeRequest, ChangeOrder的一系列底层操作 |
windchill |
|
Java代码
- package ext.csc.util.core;
-
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.Serializable;
- import java.sql.Timestamp;
- import java.text.DecimalFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Vector;
-
- import wt.change2.AffectedActivityData;
- import wt.change2.Category;
- import wt.change2.ChangeHelper2;
- import wt.change2.ChangeItemIfc;
- import wt.change2.ChangeNoticeComplexity;
- import wt.change2.ChangeRecord2;
- import wt.change2.Changeable2;
- import wt.change2.Complexity;
- import wt.change2.IssuePriority;
- import wt.change2.RelevantRequestData2;
- import wt.change2.ReportedAgainst;
- import wt.change2.RequestPriority;
- import wt.change2.WTChangeActivity2;
- import wt.change2.WTChangeIssue;
- import wt.change2.WTChangeOrder2;
- import wt.change2.WTChangeRequest2;
- import wt.content.ApplicationData;
- import wt.content.ContentHelper;
- import wt.content.ContentHolder;
- import wt.content.ContentRoleType;
- import wt.content.ContentServerHelper;
- import wt.fc.PersistenceHelper;
- import wt.fc.PersistenceServerHelper;
- import wt.fc.QueryResult;
- import wt.fc.collections.WTValuedHashMap;
- import wt.folder.Folder;
- import wt.folder.FolderHelper;
- import wt.inf.container.WTContainerRef;
- import wt.method.RemoteAccess;
- import wt.method.RemoteMethodServer;
- import wt.query.QuerySpec;
- import wt.query.SearchCondition;
- import wt.session.SessionServerHelper;
- import wt.util.WTException;
-
- import com.ptc.core.meta.common.TypeIdentifier;
- import com.ptc.core.meta.common.TypeIdentifierHelper;
- import com.ptc.windchill.enterprise.copy.server.CoreMetaUtility;
-
- import ext.csc.util.common.CSCDebug;
-
- /**
- * 该工具类封装了对于ProblemReport, ChangeRequest, ChangeOrder的一系列底层操作
- * @author mliu
- *
- */
- public class CSCChange implements RemoteAccess, Serializable{
- private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCChange.class);
-
- public static String CATEGORY = "CATEGORY"; //类别
- public static String PRIORITY = "PRIORITY"; //优先级
- public static String DESCRIPTION = "DESCRIPTION"; //描述
- public static String TYPE = "TYPE"; //类型
- public static String FOLDER = "FOLDER"; //创建文件夹 (默认:/Default)
- public static String NEED_DATE = "NEEDDATE"; //需要日期 (yyyy-MM-dd)
- public static String RESOLUTION_DATE = "RESOLUTION_DATE"; //解决方案日期 (yyyy-MM-dd)
- public static String RECURRING_COST_EST = "RECURRING_COST_EST"; //经常性成本
- public static String NON_RECURRING_COST_EST = "NON_RECURRING_COST_EST"; //非经常性成本
- public static String COMPLEXITY = "COMPLEXITY"; //复杂性
-
- private static final long serialVersionUID = 5091068291906960116L;
-
- /**
- * 创建问题报告
- * @param number 编号 (默认为系统的 WTCHANGEISSUEID_SEQ)
- * @param name 名称 (必须)
- * @param requester 请求者(必须)
- * @param attributes 属性对应表
- * @param secondaryContents 附件列表 (String FilePath 或者 InputStream)
- * @param containerRef 上下文 (必须)
- * @return 如果指定编号的问题报告存在,则返回该问题报告的对象,若不存在,则返回创建后的问题报告
- */
- public static WTChangeIssue createProblemReport(String number, String name, String requester, HashMap attributes,
- ArrayList secondaryContents, WTContainerRef containerRef){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("createProblemReport", CSCChange.class.getName(), null,
- new Class[] {String.class, String.class, String.class, HashMap.class,
- ArrayList.class, WTContainerRef.class},
- new Object[] {number, name, requester, attributes,
- secondaryContents, containerRef});
- } else {
- WTChangeIssue pr = null;
-
- try {
-
- String prDesc = "";
- String prType = "";
- String prFolder = "";
- String prCategory = "";
- String prProirity = "";
-
- if(attributes != null){
- prDesc = (String)attributes.get(CSCChange.DESCRIPTION);
- prType = (String)attributes.get(CSCChange.TYPE);
- prFolder = (String)attributes.get(CSCChange.FOLDER);
- prCategory = (String)attributes.get(CSCChange.CATEGORY);
- prProirity = (String)attributes.get(CSCChange.PRIORITY);
- }
-
- if(containerRef == null){
- return null;
- }
-
- //设置编号默认值 (默认为系统的WTCHANGEISSUEID_SEQ)
- if(number == null || number.equalsIgnoreCase("")){
- number = CSCChange.getDefaultChangeSeqNumber(WTChangeIssue.class);
- }else{
- //如果此编号问题报告已存在,则返回该问题报告
- WTChangeIssue existPR = CSCChange.getProblemReport(number, false);
- if(existPR != null){
- return existPR;
- }
- }
-
- if(name == null || name.equalsIgnoreCase("")){
- return null;
- }
-
- if(requester == null){
- return null;
- }
-
- if(prDesc == null){
- prDesc = "";
- }
-
- //设置默认类型 (默认:wt.change2.WTChangeIssue)
- if(prType == null || prType.equalsIgnoreCase("")){
- prType = "wt.change2.WTChangeIssue";
- }
-
- //设置默认文件夹 (默认:/Default)
- if(prFolder == null || prFolder.equalsIgnoreCase("")){
- prFolder = "/Default";
- }else{
- if(!prFolder.startsWith("/Default")){
- prFolder = "/Default/" + prFolder;
- }
- }
-
- pr = WTChangeIssue.newWTChangeIssue();
- pr.setNumber(number);
- pr.setName(name);
- pr.setRequester(requester);
-
- //设置问题报告描述
- pr.setDescription(prDesc);
-
- //设置问题报告类型
- if(prType != null){
- TypeIdentifier id = TypeIdentifierHelper.getTypeIdentifier(prType);
- pr = (WTChangeIssue) CoreMetaUtility.setType(pr, id);
- }
-
- //设置上下文
- pr.setContainerReference(containerRef);
-
- //设置文件夹
- Folder location = null;
- //查询文件夹是否存在
- try {
- location = FolderHelper.service.getFolder(prFolder,containerRef);
- } catch (Exception e) {
- location = null;
- }
- //若文件夹不存在,则创建该文件夹
- if(location == null)
- location = FolderHelper.service.saveFolderPath(prFolder, containerRef);
- //设置文件夹到Doc对象
- if (location != null) {
- WTValuedHashMap map = new WTValuedHashMap();
- map.put(pr, location);
- FolderHelper.assignLocations(map);
- }
-
- //设置问题报告类别
- Category category = null;
- try {
- category = Category.toCategory(prCategory);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- category = Category.getCategoryDefault();
- }
- pr.setCategory(category);
-
- //设置问题报告优先级
- IssuePriority priority = null;
- try {
- priority = IssuePriority.toIssuePriority(prProirity);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- priority = IssuePriority.getIssuePriorityDefault();
- }
- pr.setIssuePriority(priority);
-
- pr = (WTChangeIssue) PersistenceHelper.manager.save(pr);
- pr = (WTChangeIssue) PersistenceHelper.manager.refresh(pr);
-
- //设置附件
- if(secondaryContents != null){
- for (int i = 0; i < secondaryContents.size(); i++) {
- Object secondaryContent = secondaryContents.get(i);
-
- ApplicationData applicationdata = ApplicationData.newApplicationData(pr);
- applicationdata.setRole(ContentRoleType.SECONDARY);
- if(secondaryContent instanceof String){
- String filePath = (String)secondaryContent;
- applicationdata = ContentServerHelper.service.updateContent(pr, applicationdata, filePath);
- }else if(secondaryContent instanceof InputStream){
- InputStream ins = (InputStream)secondaryContent;
- applicationdata = ContentServerHelper.service.updateContent(pr, applicationdata, ins);
- }
- }
- }
-
- pr = (WTChangeIssue) PersistenceServerHelper.manager.restore(pr);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
-
- return pr;
- }
- }catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
-
- /**
- * 通过编号查找问题报告
- * @param number 查询问题报告编号条件
- * @param accessControlled 是否受到权限制约
- * @return 返回结果问题报告
- */
- public static WTChangeIssue getProblemReport(String number, boolean accessControlled) {
- try {
- number = number.toUpperCase();
-
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("getProblemReport", CSCChange.class.getName(), null,
- new Class[] {String.class, boolean.class},
- new Object[] {number, accessControlled});
- } else {
- WTChangeIssue pr = null;
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);
- try {
- QuerySpec spec = new QuerySpec(WTChangeIssue.class);
- spec.appendWhere(
- new SearchCondition(WTChangeIssue.class,
- WTChangeIssue.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });
-
- QueryResult qr = PersistenceHelper.manager.find(spec);
- if (qr.hasMoreElements()){
- pr = (WTChangeIssue)qr.nextElement();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return pr;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
-
- /**
- * 通过问题报告得到问题报告内容
- * @param pr 条件问题报告
- * @return 问题报告内容对象集
- */
- public static ArrayList<Changeable2> getProblemReportItems(WTChangeIssue pr){
- ArrayList<Changeable2> results = new ArrayList<Changeable2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<Changeable2>) RemoteMethodServer.getDefault().invoke("getProblemReportItems", CSCChange.class.getName(), null,
- new Class[] {WTChangeIssue.class},
- new Object[] {pr});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeables(pr);
- while(qr.hasMoreElements()){
- Object obj = qr.nextElement();
- if(obj instanceof Changeable2){
- Changeable2 changeable = (Changeable2)obj;
- if(!results.contains(changeable)){
- results.add(changeable);
- }
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
-
-
- /**
- * 通过问题报告内容对象查找问题报告
- * @param changeable 查询内容对象
- * @return 返回结果问题报告集
- */
- public static ArrayList<WTChangeIssue> getProblemReportByChangeable(Changeable2 changeable) {
- ArrayList<WTChangeIssue> results = new ArrayList<WTChangeIssue>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTChangeIssue>) RemoteMethodServer.getDefault().invoke("getProblemReportByChangeable", CSCChange.class.getName(), null,
- new Class[] {Changeable2.class},
- new Object[] {changeable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getReportedAgainstChangeIssue(changeable);
- while (qr.hasMoreElements()){
- WTChangeIssue pr = (WTChangeIssue)qr.nextElement();
- if(!results.contains(pr)){
- results.add(pr);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 通过问题报告得到相关联的变更请求
- * @param pr 条件问题报告
- * @return 变更请求对象
- */
- public static ArrayList<WTChangeRequest2> getChangeRequestByProblemReport(WTChangeIssue pr){
- ArrayList<WTChangeRequest2> results = new ArrayList<WTChangeRequest2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTChangeRequest2>) RemoteMethodServer.getDefault().invoke("getChangeRequestByProblemReport", CSCChange.class.getName(), null,
- new Class[] {WTChangeIssue.class},
- new Object[] {pr});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeRequest(pr);
- while (qr.hasMoreElements()){
- WTChangeRequest2 cr = (WTChangeRequest2)qr.nextElement();
- if(!results.contains(cr)){
- results.add(cr);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
-
-
- /**
- * 为问题报告添加内容对象
- * @param pr 目标问题报告
- * @param changeable 问题报告内容对象
- * @return 添加好的问题报告对象
- */
- public static WTChangeIssue addChangeableToProblemReport(WTChangeIssue pr, Changeable2 changeable){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("addChangeableToProblemReport", CSCChange.class.getName(), null,
- new Class[] {WTChangeIssue.class, Changeable2.class},
- new Object[] {pr, changeable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- Vector changeables = new Vector();
- changeables.add(changeable);
- ChangeHelper2.service.storeAssociations(ReportedAgainst.class, pr, changeables);
- pr = (WTChangeIssue) PersistenceHelper.manager.refresh(pr);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return pr;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return pr;
- }
-
-
-
- /**
- * 为问题报告添加变更请求对象
- * @param pr 目标问题报告
- * @param cr 变更请求对象
- * @return 添加好的问题报告对象
- */
- public static WTChangeIssue addChangeRequestToProblemReport(WTChangeIssue pr, WTChangeRequest2 cr){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("addChangeRequestToProblemReport", CSCChange.class.getName(), null,
- new Class[] {WTChangeIssue.class, WTChangeRequest2.class},
- new Object[] {pr, cr});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- ChangeHelper2.service.saveFormalizedBy(cr, pr);
- pr = (WTChangeIssue) PersistenceHelper.manager.refresh(pr);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return pr;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return pr;
- }
-
-
-
- /**
- * 为问题报告移除内容对象
- * @param pr 目标问题报告
- * @param changeable 问题报告内容对象
- * @return 移除好的问题报告对象
- */
- public static WTChangeIssue removeChangeableFromProblemReport(WTChangeIssue pr, Changeable2 changeable){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("removeChangeableFromProblemReport", CSCChange.class.getName(), null,
- new Class[] {WTChangeIssue.class, Changeable2.class},
- new Object[] {pr, changeable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- ChangeHelper2.service.unattachChangeable(changeable, pr, ReportedAgainst.class, ReportedAgainst.CHANGE_ISSUE_ROLE);
- pr = (WTChangeIssue) PersistenceHelper.manager.refresh(pr);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return pr;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return pr;
- }
-
-
-
- /**
- * 为问题报告移除变更请求对象
- * @param pr 目标问题报告
- * @param cr 变更请求对象
- * @return 移除好的问题报告对象
- */
- public static WTChangeIssue removeChangeRequestFromProblemReport(WTChangeIssue pr, WTChangeRequest2 cr){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeIssue) RemoteMethodServer.getDefault().invoke("removeChangeRequestFromProblemReport", CSCChange.class.getName(), null,
- new Class[] {WTChangeIssue.class, WTChangeRequest2.class},
- new Object[] {pr, cr});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- ChangeHelper2.service.deleteFormalizedBy(cr, pr);
- pr = (WTChangeIssue) PersistenceHelper.manager.refresh(pr);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return pr;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return pr;
- }
-
-
-
- /**
- * 创建变更请求
- * @param number 编号 (默认为系统的 WTCHANGEREQUEST2ID_SEQ)
- * @param name 名称 (必须)
- * @param attributes 属性对应表
- * @param secondaryContent 附件 (String FilePath 或者 InputStream)
- * @param containerRef 上下文 (必须)
- * @return 如果指定编号的变更请求存在,则返回该变更请求对象,若不存在,则返回创建后的变更请求
- */
- public static WTChangeRequest2 createChangeRequest(String number, String name, HashMap attributes,
- ArrayList secondaryContents, WTContainerRef containerRef){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("createChangeRequest", CSCChange.class.getName(), null,
- new Class[] {String.class, String.class, HashMap.class,
- ArrayList.class, WTContainerRef.class},
- new Object[] {number, name, attributes,
- secondaryContents, containerRef});
- } else {
- WTChangeRequest2 cr = null;
-
- try {
-
- String crDesc = "";
- String crType = "";
- String crFolder = "";
- String crCategory = "";
- String crProirity = "";
- String crNeedDate = "";
- String crResolutionDate = "";
- String crRecurringCostEst = "";
- String crNonRecurringCostEst = "";
- String crComplexity = "";
-
- if(attributes != null){
- crDesc = (String)attributes.get(CSCChange.DESCRIPTION);
- crType = (String)attributes.get(CSCChange.TYPE);
- crFolder = (String)attributes.get(CSCChange.FOLDER);
- crCategory = (String)attributes.get(CSCChange.CATEGORY);
- crProirity = (String)attributes.get(CSCChange.PRIORITY);
- crNeedDate = (String)attributes.get(CSCChange.NEED_DATE);
- crResolutionDate = (String)attributes.get(CSCChange.RESOLUTION_DATE);
- crRecurringCostEst = (String)attributes.get(CSCChange.RECURRING_COST_EST);
- crNonRecurringCostEst = (String)attributes.get(CSCChange.NON_RECURRING_COST_EST);
- crComplexity = (String)attributes.get(CSCChange.COMPLEXITY);
- }
-
- if(containerRef == null){
- return null;
- }
-
- //设置编号默认值 (默认为系统的WTCHANGEISSUEID_SEQ)
- if(number == null || number.equalsIgnoreCase("")){
- number = CSCChange.getDefaultChangeSeqNumber(WTChangeRequest2.class);
- }else{
- //如果此编号变更请求已存在,则返回该变更请求
- WTChangeRequest2 existCR = CSCChange.getChangeRequest(number, false);
- if(existCR != null){
- return existCR;
- }
- }
-
- if(name == null || name.equalsIgnoreCase("")){
- return null;
- }
-
- if(crDesc == null){
- crDesc = "";
- }
-
- //设置默认类型 (默认:wt.change2.WTChangeRequest2)
- if(crType == null || crType.equalsIgnoreCase("")){
- crType = "wt.change2.WTChangeRequest2";
- }
-
- //设置默认文件夹 (默认:/Default)
- if(crFolder == null || crFolder.equalsIgnoreCase("")){
- crFolder = "/Default";
- }else{
- if(!crFolder.startsWith("/Default")){
- crFolder = "/Default/" + crFolder;
- }
- }
-
- cr = WTChangeRequest2.newWTChangeRequest2();
- cr.setNumber(number);
- cr.setName(name);
-
- //设置变更请求描述
- cr.setDescription(crDesc);
-
- //设置变更请求类型
- if(crType != null){
- TypeIdentifier id = TypeIdentifierHelper.getTypeIdentifier(crType);
- cr = (WTChangeRequest2) CoreMetaUtility.setType(cr, id);
- }
-
- //设置上下文
- cr.setContainerReference(containerRef);
-
- //设置文件夹
- Folder location = null;
- //查询文件夹是否存在
- try {
- location = FolderHelper.service.getFolder(crFolder,containerRef);
- } catch (Exception e) {
- location = null;
- }
- //若文件夹不存在,则创建该文件夹
- if(location == null)
- location = FolderHelper.service.saveFolderPath(crFolder, containerRef);
- //设置文件夹到Doc对象
- if (location != null) {
- WTValuedHashMap map = new WTValuedHashMap();
- map.put(cr, location);
- FolderHelper.assignLocations(map);
- }
-
- //设置变更请求类别
- Category category = null;
- try {
- category = Category.toCategory(crCategory);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- category = Category.getCategoryDefault();
- }
- cr.setCategory(category);
-
- //设置变更请求优先级
- RequestPriority priority = null;
- try {
- priority = RequestPriority.toRequestPriority(crProirity);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- priority = RequestPriority.getRequestPriorityDefault();
- }
- cr.setRequestPriority(priority);
-
- //设置需要日期
- if(crNeedDate != null && !crNeedDate.equals("")){
- try {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
- Date date = formatter.parse(crNeedDate);
- cr.setNeedDate(new Timestamp(date.getTime()));
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- }
-
- //设置解决方案日期
- if(crResolutionDate != null && !crResolutionDate.equals("")){
- try {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
- Date date = formatter.parse(crResolutionDate);
- cr.setNeedDate(new Timestamp(date.getTime()));
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
-
- //设置经常性成本
- if(crRecurringCostEst != null && !crRecurringCostEst.equals("")){
- try {
- cr.setRecurringCostEst(crRecurringCostEst);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
-
-
- //设置非经常性成本
- if(crNonRecurringCostEst != null && !crNonRecurringCostEst.equals("")){
- try {
- cr.setNonRecurringCostEst(crNonRecurringCostEst);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
-
- //设置复杂性
- Complexity complexity = null;
- if(crComplexity != null && !crComplexity.equals("")){
- try {
- complexity = Complexity.toComplexity(crComplexity);
- cr.setComplexity(complexity);
- } catch (Exception e) {
- // TODO: handle exception
- complexity = Complexity.getComplexityDefault();
- cr.setComplexity(complexity);
- }
- }
-
-
- cr = (WTChangeRequest2) PersistenceHelper.manager.save(cr);
- cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(cr);
-
- //设置附件
- if(secondaryContents != null){
- for (int i = 0; i < secondaryContents.size(); i++) {
- Object secondaryContent = secondaryContents.get(i);
-
- ApplicationData applicationdata = ApplicationData.newApplicationData(cr);
- applicationdata.setRole(ContentRoleType.SECONDARY);
- if(secondaryContent instanceof String){
- String filePath = (String)secondaryContent;
- applicationdata = ContentServerHelper.service.updateContent(cr, applicationdata, filePath);
- }else if(secondaryContent instanceof InputStream){
- InputStream ins = (InputStream)secondaryContent;
- applicationdata = ContentServerHelper.service.updateContent(cr, applicationdata, ins);
- }
- }
- }
-
- cr = (WTChangeRequest2) PersistenceServerHelper.manager.restore(cr);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
-
- return cr;
- }
- }catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 通过编号查找变更请求
- * @param number 查询变更请求编号条件
- * @param accessControlled 是否受到权限制约
- * @return 返回结果变更请求
- */
- public static WTChangeRequest2 getChangeRequest(String number, boolean accessControlled) {
- try {
- number = number.toUpperCase();
-
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("getChangeRequest", CSCChange.class.getName(), null,
- new Class[] {String.class, boolean.class},
- new Object[] {number, accessControlled});
- } else {
- WTChangeRequest2 ecr = null;
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);
- try {
- QuerySpec spec = new QuerySpec(WTChangeRequest2.class);
- spec.appendWhere(
- new SearchCondition(WTChangeRequest2.class,
- WTChangeRequest2.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });
-
- QueryResult qr = PersistenceHelper.manager.find(spec);
- if (qr.hasMoreElements()){
- ecr = (WTChangeRequest2)qr.nextElement();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return ecr;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 通过变更请求得到变更请求内容
- * @param cr 条件变更请求
- * @return 变更请求内容对象集
- */
- public static ArrayList<Changeable2> getChangeRequestItems(WTChangeRequest2 cr){
- ArrayList<Changeable2> results = new ArrayList<Changeable2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<Changeable2>) RemoteMethodServer.getDefault().invoke("getChangeRequestItems", CSCChange.class.getName(), null,
- new Class[] {WTChangeRequest2.class},
- new Object[] {cr});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeables(cr);
- while(qr.hasMoreElements()){
- Object obj = qr.nextElement();
- if(obj instanceof Changeable2){
- Changeable2 changeable = (Changeable2)obj;
- if(!results.contains(changeable)){
- results.add(changeable);
- }
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
-
- /**
- * 通过变更请求内容对象查找变更请求
- * @param changeable 查询内容对象
- * @return 返回结果变更请求集
- */
- public static ArrayList<WTChangeRequest2> getChangeRequestByChangeable(Changeable2 changeable) {
- ArrayList<WTChangeRequest2> results = new ArrayList<WTChangeRequest2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTChangeRequest2>) RemoteMethodServer.getDefault().invoke("getChangeRequestByChangeable", CSCChange.class.getName(), null,
- new Class[] {Changeable2.class},
- new Object[] {changeable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getRelevantChangeRequests(changeable);
- while (qr.hasMoreElements()){
- WTChangeRequest2 cr = (WTChangeRequest2)qr.nextElement();
- if(!results.contains(cr)){
- results.add(cr);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * 通过变更请求得到相关联的问题报告
- * @param cr 条件变更请求
- * @return 问题报告对象集
- */
- public static ArrayList<WTChangeIssue> getProblemReportByChangeRequest(WTChangeRequest2 cr){
- ArrayList<WTChangeIssue> results = new ArrayList<WTChangeIssue>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTChangeIssue>) RemoteMethodServer.getDefault().invoke("getProblemReportByChangeRequest", CSCChange.class.getName(), null,
- new Class[] {WTChangeRequest2.class},
- new Object[] {cr});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeIssues(cr);
- while (qr.hasMoreElements()){
- WTChangeIssue pr = (WTChangeIssue)qr.nextElement();
- if(!results.contains(pr)){
- results.add(pr);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
-
- /**
- * 通过变更请求得到相关联的变更通告
- * @param cr 条件变更请求
- * @return 变更通告对象集
- */
- public static ArrayList<WTChangeOrder2> getChangeNoticeByChangeRequest(WTChangeRequest2 cr){
- ArrayList<WTChangeOrder2> results = new ArrayList<WTChangeOrder2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTChangeOrder2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeByChangeRequest", CSCChange.class.getName(), null,
- new Class[] {WTChangeRequest2.class},
- new Object[] {cr});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeOrders(cr);
- while (qr.hasMoreElements()){
- WTChangeOrder2 cn = (WTChangeOrder2)qr.nextElement();
- if(!results.contains(cn)){
- results.add(cn);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
-
- /**
- * 为变更请求添加内容对象
- * @param cr 目标变更请求
- * @param changeable 变更请求内容对象
- * @return 添加好的变更请求对象
- */
- public static WTChangeRequest2 addChangeableToChangeRequest(WTChangeRequest2 cr, Changeable2 changeable){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("addChangeableToChangeRequest", CSCChange.class.getName(), null,
- new Class[] {WTChangeRequest2.class, Changeable2.class},
- new Object[] {cr, changeable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- Vector changeables = new Vector();
- changeables.add(changeable);
- ChangeHelper2.service.storeAssociations(RelevantRequestData2.class, cr, changeables);
- cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(cr);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return cr;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return cr;
- }
-
- /**
- * 为变更请求添加变更通告对象
- * @param cr 目标变更请求
- * @param cn 变更通告对象
- * @return 添加好的变更请求对象
- */
- public static WTChangeRequest2 addChangeNoticeToChangeRequest(WTChangeRequest2 cr, WTChangeOrder2 cn){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("addChangeNoticeToChangeRequest", CSCChange.class.getName(), null,
- new Class[] {WTChangeRequest2.class, WTChangeOrder2.class},
- new Object[] {cr, cn});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- ChangeHelper2.service.saveAddressedBy(cr, cn);
- cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(cr);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return cr;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return cr;
- }
-
-
- /**
- * 为变更请求移除内容对象
- * @param cr 目标变更请求
- * @param changeable 变更请求内容对象
- * @return 移除好的变更请求对象
- */
- public static WTChangeRequest2 removeChangeableFromChangeRequest(WTChangeRequest2 cr, Changeable2 changeable){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("removeChangeableFromChangeRequest", CSCChange.class.getName(), null,
- new Class[] {WTChangeRequest2.class, Changeable2.class},
- new Object[] {cr, changeable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- ChangeHelper2.service.unattachChangeable(changeable, cr, RelevantRequestData2.class, RelevantRequestData2.CHANGE_REQUEST2_ROLE);
- cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(cr);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return cr;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return cr;
- }
-
-
- /**
- * 为变更请求移除变更通告对象
- * @param cr 目标变更请求
- * @param cn 变更通告对象
- * @return 移除好的变更请求对象
- */
- public static WTChangeRequest2 removeChangeNoticeToChangeRequest(WTChangeRequest2 cr, WTChangeOrder2 cn){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeRequest2) RemoteMethodServer.getDefault().invoke("removeChangeNoticeToChangeRequest", CSCChange.class.getName(), null,
- new Class[] {WTChangeRequest2.class, WTChangeOrder2.class},
- new Object[] {cr, cn});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- ChangeHelper2.service.deleteAddressedBy(cr, cn);
- cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(cr);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return cr;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return cr;
- }
-
-
- /**
- * 创建变更通告
- * @param number 编号 (默认为系统的 WTCHANGEORDER2ID_SEQ)
- * @param name 名称 (必须)
- * @param attributes 属性对应表
- * @param secondaryContents 附件列表 (String FilePath 或者 InputStream)
- * @param containerRef 上下文 (必须)
- * @return 如果指定编号的变更通告存在,则返回该变更通告对象,若不存在,则返回创建后的变更通告
- */
- public static WTChangeOrder2 createChangeNotice(String number, String name, HashMap attributes,
- ArrayList secondaryContents, WTContainerRef containerRef){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("createChangeNotice", CSCChange.class.getName(), null,
- new Class[] {String.class, String.class, HashMap.class,
- ArrayList.class, WTContainerRef.class},
- new Object[] {number, name, attributes,
- secondaryContents, containerRef});
- } else {
- WTChangeOrder2 cn = null;
-
- try {
-
- String cnDesc = "";
- String cnType = "";
- String cnFolder = "";
- String cnNeedDate = "";
- String cnComplexity = "";
-
- if(attributes != null){
- cnDesc = (String)attributes.get(CSCChange.DESCRIPTION);
- cnType = (String)attributes.get(CSCChange.TYPE);
- cnFolder = (String)attributes.get(CSCChange.FOLDER);
- cnNeedDate = (String)attributes.get(CSCChange.NEED_DATE);
- cnComplexity = (String)attributes.get(CSCChange.COMPLEXITY);
- }
-
- if(containerRef == null){
- return null;
- }
-
- //设置编号默认值 (默认为系统的WTCHANGEISSUEID_SEQ)
- if(number == null || number.equalsIgnoreCase("")){
- number = CSCChange.getDefaultChangeSeqNumber(WTChangeOrder2.class);
- }else{
- //如果此编号变更通告已存在,则返回该变更通告
- WTChangeOrder2 existCN = CSCChange.getChangeNotice(number, false);
- if(existCN != null){
- return existCN;
- }
- }
-
- if(name == null || name.equalsIgnoreCase("")){
- return null;
- }
-
- if(cnDesc == null){
- cnDesc = "";
- }
-
- //设置默认类型 (默认:wt.change2.WTChangeOrder2)
- if(cnType == null || cnType.equalsIgnoreCase("")){
- cnType = "wt.change2.WTChangeOrder2";
- }
-
- //设置默认文件夹 (默认:/Default)
- if(cnFolder == null || cnFolder.equalsIgnoreCase("")){
- cnFolder = "/Default";
- }else{
- if(!cnFolder.startsWith("/Default")){
- cnFolder = "/Default/" + cnFolder;
- }
- }
-
- cn = WTChangeOrder2.newWTChangeOrder2();
- cn.setNumber(number);
- cn.setName(name);
-
- //设置变更请求描述
- cn.setDescription(cnDesc);
-
- //设置变更请求类型
- if(cnType != null){
- TypeIdentifier id = TypeIdentifierHelper.getTypeIdentifier(cnType);
- cn = (WTChangeOrder2) CoreMetaUtility.setType(cn, id);
- }
-
- //设置上下文
- cn.setContainerReference(containerRef);
-
- //设置文件夹
- Folder location = null;
- //查询文件夹是否存在
- try {
- location = FolderHelper.service.getFolder(cnFolder,containerRef);
- } catch (Exception e) {
- location = null;
- }
- //若文件夹不存在,则创建该文件夹
- if(location == null)
- location = FolderHelper.service.saveFolderPath(cnFolder, containerRef);
- //设置文件夹到Doc对象
- if (location != null) {
- WTValuedHashMap map = new WTValuedHashMap();
- map.put(cn, location);
- FolderHelper.assignLocations(map);
- }
-
- //设置需要日期
- if(cnNeedDate != null && !cnNeedDate.equals("")){
- try {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
- Date date = formatter.parse(cnNeedDate);
- cn.setNeedDate(new Timestamp(date.getTime()));
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- }
-
- //设置复杂性
- ChangeNoticeComplexity complexity = null;
- if(cnComplexity != null && !cnComplexity.equals("")){
- try {
- complexity = ChangeNoticeComplexity.toChangeNoticeComplexity(cnComplexity);
- cn.setChangeNoticeComplexity(complexity);
- } catch (Exception e) {
- // TODO: handle exception
- complexity = ChangeNoticeComplexity.getChangeNoticeComplexityDefault();
- cn.setChangeNoticeComplexity(complexity);
- }
- }
-
-
- cn = (WTChangeOrder2) PersistenceHelper.manager.save(cn);
- cn = (WTChangeOrder2) PersistenceHelper.manager.refresh(cn);
-
- //设置附件
- if(secondaryContents != null){
- for (int i = 0; i < secondaryContents.size(); i++) {
- Object secondaryContent = secondaryContents.get(i);
-
- ApplicationData applicationdata = ApplicationData.newApplicationData(cn);
- applicationdata.setRole(ContentRoleType.SECONDARY);
- if(secondaryContent instanceof String){
- String filePath = (String)secondaryContent;
- applicationdata = ContentServerHelper.service.updateContent(cn, applicationdata, filePath);
- }else if(secondaryContent instanceof InputStream){
- InputStream ins = (InputStream)secondaryContent;
- applicationdata = ContentServerHelper.service.updateContent(cn, applicationdata, ins);
- }
- }
- }
-
- cn = (WTChangeOrder2) PersistenceServerHelper.manager.restore(cn);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
-
- return cn;
- }
- }catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 通过编号查找变更通告
- * @param number 查询变更通告编号条件
- * @param accessControlled 是否受到权限制约
- * @return 返回结果变更通告
- */
- public static WTChangeOrder2 getChangeNotice(String number, boolean accessControlled) {
- try {
- number = number.toUpperCase();
-
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("getChangeNotice", CSCChange.class.getName(), null,
- new Class[] {String.class, boolean.class},
- new Object[] {number, accessControlled});
- } else {
- WTChangeOrder2 ecn = null;
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);
- try {
- QuerySpec spec = new QuerySpec(WTChangeOrder2.class);
- spec.appendWhere(
- new SearchCondition(WTChangeOrder2.class,
- WTChangeRequest2.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });
-
- QueryResult qr = PersistenceHelper.manager.find(spec);
- if (qr.hasMoreElements()){
- ecn = (WTChangeOrder2)qr.nextElement();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return ecn;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * 通过变更通告得到变更前内容
- * @param cn 条件变更通告
- * @return 变更前内容对象集
- */
- public static ArrayList<Changeable2> getChangeNoticeItemsBefore(WTChangeOrder2 cn){
- ArrayList<Changeable2> results = new ArrayList<Changeable2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<Changeable2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeItemsBefore", CSCChange.class.getName(), null,
- new Class[] {WTChangeOrder2.class},
- new Object[] {cn});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeablesBefore(cn);
- while(qr.hasMoreElements()){
- Object obj = qr.nextElement();
- if(obj instanceof Changeable2){
- Changeable2 changeable = (Changeable2)obj;
- if(!results.contains(changeable)){
- results.add(changeable);
- }
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
-
- /**
- * 通过变更通告得到变更后内容
- * @param cn 条件变更通告
- * @return 变更后内容对象集
- */
- public static ArrayList<Changeable2> getChangeNoticeItemsAfter(WTChangeOrder2 cn){
- ArrayList<Changeable2> results = new ArrayList<Changeable2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<Changeable2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeItemsAfter", CSCChange.class.getName(), null,
- new Class[] {WTChangeOrder2.class},
- new Object[] {cn});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeablesAfter(cn);
- while(qr.hasMoreElements()){
- Object obj = qr.nextElement();
- if(obj instanceof Changeable2){
- Changeable2 changeable = (Changeable2)obj;
- if(!results.contains(changeable)){
- results.add(changeable);
- }
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
- /**
- * 通过变更前内容对象查找变更通告
- * @param changeable 查询变更前对象
- * @return 返回结果变更通告集
- */
- public static ArrayList<WTChangeOrder2> getChangeNoticeByChangeableBefore(Changeable2 changeable) {
- ArrayList<WTChangeOrder2> results = new ArrayList<WTChangeOrder2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTChangeOrder2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeByChangeableBefore", CSCChange.class.getName(), null,
- new Class[] {Changeable2.class},
- new Object[] {changeable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getUniqueAffectingChangeOrders(changeable);
- while (qr.hasMoreElements()){
- WTChangeOrder2 cn = (WTChangeOrder2)qr.nextElement();
- if(!results.contains(cn)){
- results.add(cn);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * 通过变更后内容对象查找变更通告
- * @param changeable 查询变更后对象
- * @return 返回结果变更通告集
- */
- public static ArrayList<WTChangeOrder2> getChangeNoticeByChangeableAfter(Changeable2 changeable) {
- ArrayList<WTChangeOrder2> results = new ArrayList<WTChangeOrder2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTChangeOrder2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeByChangeableAfter", CSCChange.class.getName(), null,
- new Class[] {Changeable2.class},
- new Object[] {changeable});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getUniqueImplementedChangeOrders(changeable);
- while (qr.hasMoreElements()){
- WTChangeOrder2 cn = (WTChangeOrder2)qr.nextElement();
- if(!results.contains(cn)){
- results.add(cn);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * 通过变更通告得到相关联的变更请求
- * @param cn 条件变更通告
- * @return 变更请求对象
- */
- public static ArrayList<WTChangeRequest2> getChangeRequestByChangeNotice(WTChangeOrder2 cn){
- ArrayList<WTChangeRequest2> results = new ArrayList<WTChangeRequest2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTChangeRequest2>) RemoteMethodServer.getDefault().invoke("getChangeRequestByChangeNotice", CSCChange.class.getName(), null,
- new Class[] {WTChangeOrder2.class},
- new Object[] {cn});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeRequest(cn);
- while (qr.hasMoreElements()){
- WTChangeRequest2 cr = (WTChangeRequest2)qr.nextElement();
- if(!results.contains(cr)){
- results.add(cr);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
- /**
- * 通过变更通告得到相关联的变更任务
- * @param cn 条件变更通告
- * @return 变更任务对象
- */
- public static ArrayList<WTChangeActivity2> getChangeActivityByChangeNotice(WTChangeOrder2 cn){
- ArrayList<WTChangeActivity2> results = new ArrayList<WTChangeActivity2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTChangeActivity2>) RemoteMethodServer.getDefault().invoke("getChangeActivityByChangeNotice", CSCChange.class.getName(), null,
- new Class[] {WTChangeOrder2.class},
- new Object[] {cn});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeActivities(cn);
- while (qr.hasMoreElements()){
- WTChangeActivity2 ca = (WTChangeActivity2)qr.nextElement();
- if(!results.contains(ca)){
- results.add(ca);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
- /**
- * 为变更通告添加变更前对象
- * @param cn 目标变更通告
- * @param changeable 变更前对象
- * @param caName 需要将变更前对象放入的变更活动
- * @return 添加好的变更通告对象
- */
- public static WTChangeOrder2 addChangeableBeforeToChangeNotice(WTChangeOrder2 cn, Changeable2 changeable, String caName){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("addChangeableBeforeToChangeNotice", CSCChange.class.getName(), null,
- new Class[] {WTChangeOrder2.class, Changeable2.class, String.class},
- new Object[] {cn, changeable, caName});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeActivities(cn);
-
- //查找是否有与条件变更活动名相同的变更活动
- WTChangeActivity2 toBeAddedCA = null;
- while(qr.hasMoreElements()){
- WTChangeActivity2 ca = (WTChangeActivity2)qr.nextElement();
- if(caName == null || caName.equals("")){
- //如果条件变更活动名为空,则取第一个变更活动
- toBeAddedCA = ca;
- break;
- }else{
- if(caName.trim().equals(ca.getName())){
- //如果找到条件变更活动,则准备添加改前数据
- toBeAddedCA = ca;
- break;
- }
- }
- //如果未找到条件变更活动,则取最后一个变更活动
- toBeAddedCA = ca;
- }
-
- if(toBeAddedCA != null){
- Vector changeables = new Vector();
- changeables.add(changeable);
- ChangeHelper2.service.storeAssociations(AffectedActivityData.class, toBeAddedCA, changeables);
- }
- cn = (WTChangeOrder2) PersistenceHelper.manager.refresh(cn);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return cn;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return cn;
- }
-
- /**
- * 为变更通告添加变更后对象
- * @param cn 目标变更通告
- * @param changeable 变更后对象
- * @param caName 需要将变更后对象放入的变更活动
- * @return 添加好的变更通告对象
- */
- public static WTChangeOrder2 addChangeableAfterToChangeNotice(WTChangeOrder2 cn, Changeable2 changeable, String caName){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("addChangeableAfterToChangeNotice", CSCChange.class.getName(), null,
- new Class[] {WTChangeOrder2.class, Changeable2.class, String.class},
- new Object[] {cn, changeable, caName});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeActivities(cn);
-
- //查找是否有与条件变更活动名相同的变更活动
- WTChangeActivity2 toBeAddedCA = null;
- while(qr.hasMoreElements()){
- WTChangeActivity2 ca = (WTChangeActivity2)qr.nextElement();
- if(caName == null || caName.equals("")){
- //如果条件变更活动名为空,则取第一个变更活动
- toBeAddedCA = ca;
- break;
- }else{
- if(caName.trim().equals(ca.getName())){
- //如果找到条件变更活动,则准备添加改后数据
- toBeAddedCA = ca;
- break;
- }
- }
- //如果未找到条件变更活动,则取最后一个变更活动
- toBeAddedCA = ca;
- }
-
- if(toBeAddedCA != null){
- Vector changeables = new Vector();
- changeables.add(changeable);
- ChangeHelper2.service.storeAssociations(ChangeRecord2.class, toBeAddedCA, changeables);
- }
- cn = (WTChangeOrder2) PersistenceHelper.manager.refresh(cn);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return cn;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return cn;
- }
-
- /**
- * 为变更通告移除变更前对象
- * @param cn 目标变更通告
- * @param changeable 变更前对象
- * @param caName 需要将变更前对象移除的变更活动
- * @return 移除好的变更通告对象
- */
- public static WTChangeOrder2 removeChangeableBeforeToChangeNotice(WTChangeOrder2 cn, Changeable2 changeable, String caName){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("removeChangeableBeforeToChangeNotice", CSCChange.class.getName(), null,
- new Class[] {WTChangeOrder2.class, Changeable2.class, String.class},
- new Object[] {cn, changeable, caName});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeActivities(cn);
-
- //查找是否有与条件变更活动名相同的变更活动
- WTChangeActivity2 toBeRemovedCA = null;
- while(qr.hasMoreElements()){
- WTChangeActivity2 ca = (WTChangeActivity2)qr.nextElement();
- if(caName == null || caName.equals("")){
- //如果条件变更活动名为空,则取第一个变更活动
- toBeRemovedCA = ca;
- break;
- }else{
- if(caName.trim().equals(ca.getName())){
- //如果找到条件变更活动,则准备移除改前数据
- toBeRemovedCA = ca;
- break;
- }
- }
- //如果未找到条件变更活动,则取最后一个变更活动
- toBeRemovedCA = ca;
- }
-
- if(toBeRemovedCA != null){
- ChangeHelper2.service.unattachChangeable(changeable, toBeRemovedCA, AffectedActivityData.class, AffectedActivityData.CHANGE_ACTIVITY2_ROLE);
- }
- cn = (WTChangeOrder2) PersistenceHelper.manager.refresh(cn);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return cn;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return cn;
- }
-
- /**
- * 为变更通告移除变更后对象
- * @param cn 目标变更通告
- * @param changeable 变更后对象
- * @param caName 需要将变更后对象移除的变更活动
- * @return 移除好的变更通告对象
- */
- public static WTChangeOrder2 removeChangeableAfterToChangeNotice(WTChangeOrder2 cn, Changeable2 changeable, String caName){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeOrder2) RemoteMethodServer.getDefault().invoke("removeChangeableAfterToChangeNotice", CSCChange.class.getName(), null,
- new Class[] {WTChangeOrder2.class, Changeable2.class, String.class},
- new Object[] {cn, changeable, caName});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeActivities(cn);
-
- //查找是否有与条件变更活动名相同的变更活动
- WTChangeActivity2 toBeRemovedCA = null;
- while(qr.hasMoreElements()){
- WTChangeActivity2 ca = (WTChangeActivity2)qr.nextElement();
- if(caName == null || caName.equals("")){
- //如果条件变更活动名为空,则取第一个变更活动
- toBeRemovedCA = ca;
- break;
- }else{
- if(caName.trim().equals(ca.getName())){
- //如果找到条件变更活动,则准备移除改后数据
- toBeRemovedCA = ca;
- break;
- }
- }
- //如果未找到条件变更活动,则取最后一个变更活动
- toBeRemovedCA = ca;
- }
-
- if(toBeRemovedCA != null){
- ChangeHelper2.service.unattachChangeable(changeable, toBeRemovedCA, ChangeRecord2.class, ChangeRecord2.CHANGE_ACTIVITY2_ROLE);
- }
- cn = (WTChangeOrder2) PersistenceHelper.manager.refresh(cn);
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return cn;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return cn;
- }
-
-
-
- /**
- * 通过编号查找变更活动
- * @param number 查询变更活动编号条件
- * @param accessControlled 是否受到权限制约
- * @return 返回结果变更活动
- */
- public static WTChangeActivity2 getChangeActivity(String number, boolean accessControlled) {
- try {
- number = number.toUpperCase();
-
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeActivity2) RemoteMethodServer.getDefault().invoke("getChangeActivity", CSCChange.class.getName(), null,
- new Class[] {String.class, boolean.class},
- new Object[] {number, accessControlled});
- } else {
- WTChangeActivity2 ca = null;
-
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(accessControlled);
- try {
- QuerySpec spec = new QuerySpec(WTChangeActivity2.class);
- spec.appendWhere(
- new SearchCondition(WTChangeActivity2.class,
- WTChangeActivity2.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });
-
- QueryResult qr = PersistenceHelper.manager.find(spec);
- if (qr.hasMoreElements()){
- ca = (WTChangeActivity2)qr.nextElement();
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
-
- return ca;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * 通过变更任务得到相关联的变更通告
- * @param ca 条件变更任务
- * @return 变更通告对象集
- */
- public static ArrayList<WTChangeOrder2> getChangeNoticeByChangeActivity(WTChangeActivity2 ca){
- ArrayList<WTChangeOrder2> results = new ArrayList<WTChangeOrder2>();
-
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (ArrayList<WTChangeOrder2>) RemoteMethodServer.getDefault().invoke("getChangeNoticeByChangeActivity", CSCChange.class.getName(), null,
- new Class[] {WTChangeActivity2.class},
- new Object[] {ca});
- } else {
- boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
- try {
- QueryResult qr = ChangeHelper2.service.getChangeOrder(ca);
- while (qr.hasMoreElements()){
- WTChangeOrder2 cn = (WTChangeOrder2)qr.nextElement();
- if(!results.contains(cn)){
- results.add(cn);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- SessionServerHelper.manager.setAccessEnforced(enforce);
- }
- return results;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
-
- /**
- * 创建变更任务
- * @param number 编号 (默认为系统的 WTCHANGEACTIVITY22ID_SEQ)
- * @param name 名称 (必须)
- * @param attributes 属性对应表
- * @param cn 所属的变更通告 (必须)
- * @return 如果指定编号的变更任务存在,则返回该变更任务对象,若不存在,则返回创建后的变更任务
- */
- public static WTChangeActivity2 createChangeActivity(String number, String name, HashMap attributes, WTChangeOrder2 cn){
- try {
- if (!RemoteMethodServer.ServerFlag) {
- return (WTChangeActivity2) RemoteMethodServer.getDefault().invoke("createChangeActivity", CSCChange.class.getName(), null,
- new Class[] {String.class, String.class, HashMap.class,WTChangeOrder2.class},
- new Object[] {number, name, attributes, cn});
- } else {
- WTChangeActivity2 ca = null;
-
- try {
-
- String caDesc = "";
- String caNeedDate = "";
-
- if(attributes != null){
- caDesc = (String)attributes.get(CSCChange.DESCRIPTION);
- caNeedDate = (String)attributes.get(CSCChange.NEED_DATE);
- }
-
- if(cn == null){
- return null;
- }
-
- //设置编号默认值
- if(number == null || number.equalsIgnoreCase("")){
- number = CSCChange.getDefaultChangeSeqNumber(WTChangeActivity2.class);
- }else{
- //如果此编号变更任务已存在,则返回该变更任务
- WTChangeActivity2 existCA = CSCChange.getChangeActivity(number, false);
- if(existCA != null){
- return existCA;
- }
- }
-
- if(name == null || name.equalsIgnoreCase("")){
- return null;
- }
-
- if(caDesc == null){
- caDesc = "";
- }
-
- ca = WTChangeActivity2.newWTChangeActivity2();
- ca.setNumber(number);
- ca.setName(name);
-
- //设置变更任务描述
- cn.setDescription(caDesc);
-
- //设置上下文(所属变更通告的上下文)
- ca.setContai
|
Excel文件读取 |
windchill |
|
Java代码
- package ext.csc.util.thirdparty;
-
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.text.SimpleDateFormat;
- import java.util.Date;
-
- import javax.servlet.http.HttpServletResponse;
-
- import org.apache.poi.hssf.usermodel.HSSFCell;
- import org.apache.poi.hssf.usermodel.HSSFDateUtil;
- import org.apache.poi.hssf.usermodel.HSSFRow;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.hssf.util.Region;
- import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-
- import ext.csc.util.common.CSCDebug;
-
- /**
- * Excel文件读取
- * @author xijin
- * @version 2010/6/29
- */
- public class CSCExcel {
- private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCExcel.class);
-
- /** 实体POI Workbook */
- private HSSFWorkbook wb = null;
-
- /** Excel 文件对象 */
- private File excelFile = null;
-
- /** 当前Sheet */
- private HSSFSheet currentSheet = null;
-
- public CSCExcel() {}
-
- /**
- * 初始化构造方法
- * @param filePathName Excel文件路径和文件名
- * @throws IOException 文件流例外
- */
- public CSCExcel(String filePathName) throws IOException {
- POIFSFileSystem fs = null;
- excelFile = new File(filePathName);
- // 检测指定文件是否存在
- if (excelFile.exists()) {
- fs = new POIFSFileSystem(new FileInputStream(excelFile));
- }
- if (fs != null) {
- wb = new HSSFWorkbook(fs);
- currentSheet = wb.getSheetAt(0);
- }
- }
-
- /**
- * 初始化构造方法
- * @param inputStream Excel文件流
- * @throws IOException 文件流例外
- */
- public CSCExcel(FileInputStream inputStream) throws IOException {
- // 如果文件流不为空,执行初始化
- if (inputStream != null) {
- POIFSFileSystem fs = new POIFSFileSystem(inputStream);
- wb = new HSSFWorkbook(fs);
- currentSheet = wb.getSheetAt(0);
- }
- }
-
- /**
- * 判断Workbook是否存在
- * @return 是否存在
- */
- public boolean exists() {
- return wb != null;
- }
-
- /**
- * 取得路径名称
- * @return 路径名称
- */
- public String getParent() {
- return excelFile.getParent();
- }
-
- /**
- * 取得文件名称
- * @return Excel文件名
- */
- public String getFileName() {
- return excelFile.getName();
- }
-
- /**
- * 创建Excel文件
- * @return 创建是否成功
- * @throws IOException 文件流例外
- */
- public boolean createNewFile() throws IOException {
- wb = new HSSFWorkbook();
-
- if (excelFile != null) {
- // 创建文件路径
- boolean dirResult = excelFile.getParentFile().mkdirs();
-
- if (dirResult || excelFile.getParentFile().exists()) {
- FileOutputStream fileOut = new FileOutputStream(getParent() + "\\" + getFileName());
- wb.write(fileOut);
- fileOut.close();
- } else {
- // 如果文件路径创建不成功返回False;
- return false;
- }
- }
- // 文件创建成功
- return true;
- }
-
- /**
- * 创建新Sheet
- * @param sheetName Sheet名称
- * @return 创建是否成功
- * @throws IOException 文件流例外
- */
- public boolean createNewSheet(String sheetName) throws IOException {
- if (wb == null) return false;
- HSSFSheet sheet = wb.createSheet(sheetName);
- // 设置为当前Sheet
- this.currentSheet = sheet;
-
- if (sheet != null) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * 改变当前Sheet
- * @param sheetName Excel文件名称
- */
- public void switchCurrentSheet(String sheetName) {
- if (wb == null) return ;
- HSSFSheet sheet = wb.getSheet(sheetName);
-
- if (sheet != null) {
- this.currentSheet = sheet;
- }
- }
-
-
- public void switchCurrentSheet(int sheetId) {
- if (wb == null) return ;
- HSSFSheet sheet = wb.getSheetAt(sheetId);
-
- if (sheet != null) {
- this.currentSheet = sheet;
- }
- }
-
-
- public int getSheetRowCount() {
- return this.currentSheet.getPhysicalNumberOfRows();
- }
-
- /**
- * 判断是否存在指定Sheet
- * @param sheetName Sheet名称
- * @return 是否存在标记
- */
- public boolean isExistSheet(String sheetName) {
- if (wb == null) return false;
- HSSFSheet sheet = wb.getSheet(sheetName);
-
- if (sheet == null) {
- return false;
- }
-
- return true;
- }
-
- /**
- * 对指定位置单元格设置字符串值
- * @param row 行标
- * @param col 列标
- * @param value 值
- * @return 是否设置成功
- */
- @SuppressWarnings("deprecation")
- public boolean setStringValue(int row, int col, String value) {
- if (wb == null) return false;
-
- HSSFRow hssfRow = currentSheet.createRow(row);
- HSSFCell cell = hssfRow.createCell((short)col);
- cell.setEncoding(HSSFCell.ENCODING_UTF_16);
- cell.setCellType(HSSFCell.CELL_TYPE_STRING);
- cell.setCellValue(value);
-
- return true;
- }
-
- /**
- * 对指定位置单元格设置数字值
- * @param row 行标
- * @param col 列标
- * @param value 值
- * @return 是否设置成功
- */
- @SuppressWarnings("deprecation")
- public boolean setNumericValue(int row, int col, double value) {
- if (wb == null) return false;
-
- HSSFRow hssfRow = currentSheet.createRow(row);
- HSSFCell cell = hssfRow.createCell((short)col);
- cell.setEncoding(HSSFCell.ENCODING_UTF_16);
- cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
- cell.setCellValue(value);
-
- return true;
- }
-
- /**
- * 对指定位置单元格设置日期值
- * @param row 行标
- * @param col 列标
- * @param value 值
- * @return 是否设置成功
- */
- @SuppressWarnings("deprecation")
- public boolean setDateValue(int row, int col, Date value, String fomat) {
- if (wb == null) return false;
-
- HSSFRow hssfRow = currentSheet.createRow(row);
- HSSFCell cell = hssfRow.createCell((short)col);
- cell.setEncoding(HSSFCell.ENCODING_UTF_16);
- cell.setCellType(HSSFCell.CELL_TYPE_STRING);
-
- SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(fomat);
- cell.setCellValue(dateFormat.format(value));
-
- return true;
- }
-
- /**
- * 对指定位置单元格设置布尔值
- * @param row 行标
- * @param col 列标
- * @param value 值
- * @return 是否设置成功
- */
- @SuppressWarnings("deprecation")
- public boolean setBooleanValue(int row, int col, boolean value) {
- if (wb == null) return false;
-
- HSSFRow hssfRow = currentSheet.createRow(row);
- HSSFCell cell = hssfRow.createCell((short)col);
- cell.setEncoding(HSSFCell.ENCODING_UTF_16);
- cell.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
- cell.setCellValue(value);
-
- return true;
- }
-
- /**
- * 合并单元格
- * @param rowFrom 合并起始行标
- * @param colFrom 合并起始列标
- * @param rowTo 合并结尾行标
- * @param colTo 合并结尾列标
- * @return 合并结果
- */
- public boolean mergeCells(int rowFrom, int colFrom, int rowTo, int colTo) {
- if (wb == null) return false;
-
- currentSheet.addMergedRegion(new Region(rowFrom,(short)colFrom,rowTo,(short)colTo));
-
- return true;
- }
-
-
-
- /**
- * 读取指定坐标的值
- * @param row 行标
- * @param col 列标
- * @return 字符串值
- */
- @SuppressWarnings("deprecation")
- public String getValue(int row, int col) {
- if (wb == null) return "";
- String value = "";
-
- // 从当前Sheet中读取数据,取得指定行
- HSSFRow hssfrow = currentSheet.getRow(row);
- if (hssfrow == null) {
- return "";
- }
- // 根据指定行,取得指定单元格
- HSSFCell cell = hssfrow.getCell((short)col);
- if(cell == null){
- return "";
- }
- // 取得单元格类型
- int type = cell.getCellType();
-
- if(type == HSSFCell.CELL_TYPE_STRING){
- // 字符串类型
- value = cell.getStringCellValue();
- }else if (HSSFDateUtil.isCellDateFormatted(cell)) {
- // 日期类型
- double d = cell.getNumericCellValue();
- if (d == 0.0) {
- value = "";
- } else {
- Date date = HSSFDateUtil.getJavaDate(d);
- SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy/MM/dd");
- value = dateFormat.format(date);
- }
- }else if(type == HSSFCell.CELL_TYPE_NUMERIC){
- // 数字类型
- double dvalue = cell.getNumericCellValue();
- value = String.valueOf(dvalue);
- }else if(type == HSSFCell.CELL_TYPE_BOOLEAN){
- // 布尔类型
- value = cell.getBooleanCellValue() + "";
- }else if(type == HSSFCell.CELL_TYPE_BLANK){
- value = "";
- }else{
- value = cell.getStringCellValue();
- }
-
- if (value == null){
- return "";
- }
-
- return value.trim();
- }
-
- /**
- * 一次性保存之前所有修改.
- * @return 保存是否成功
- * @throws IOException 文件流例外
- */
- public boolean saveChanges() throws IOException {
- if (wb == null || excelFile == null) return false;
-
- FileOutputStream fileOut = new FileOutputStream(getParent() + "\\" + getFileName());
- wb.write(fileOut);
- fileOut.close();
-
- return true;
- }
-
- /**
- * 下载Excel文件
- * @param response
- * @throws IOException
- */
- public void downloadExcel(HttpServletResponse response) throws IOException {
- OutputStream os = response.getOutputStream();
- wb.write(os);
- os.flush();
- os.close();
-
- response.setStatus(HttpServletResponse.SC_OK);
- response.flushBuffer();
- }
-
-
- public static void main(String[] args) throws Exception {
- System.out.println("------ test start ------");
-
- // 建立CSCExcel对象
- CSCExcel excel = new CSCExcel("C:\\test\\testtwoa\\test.xls");
-
- System.out.println(" 路径名称 == " + excel.getParent());
- System.out.println(" 文件名称 == " + excel.getFileName());
-
- boolean fileResult = false;
- // 判断是否存在该 Excel文件,如果不存在并用户继续执行操作,则后续处理返回都是False,即操作不成功。
- if (!excel.exists()) {
- // 创建新Excel文件
- fileResult = excel.createNewFile();
- }
- // 创建结果
- System.out.println(" fileResult == " + fileResult);
-
-
- // 判断是否存在指定名称的Sheet
- if (!excel.isExistSheet("jinxin")) {
- // 如果不存在,创建新Sheet
- boolean sheetResult = excel.createNewSheet("jinxin");
- // 创建结果
- System.out.println(" sheetResult == " + sheetResult);
- } else {
- // 如果存在,则把指定Sheet设为当前Sheet,如果不设定,取Workbook的第一个Sheet作为当前Sheet
- excel.switchCurrentSheet("jinxin");
- }
-
- // 取指定位置的值
- String value = excel.getValue(0, 0);
- System.out.println(" value == " + value);
-
- // 设置指定位置的字符串值
- excel.setStringValue(0, 0, "sss");
- // 设置指定位置的数字值
- excel.setNumericValue(0, 1, 1234.012);
- // 设置指定位置的布尔值
- excel.setBooleanValue(0, 2, false);
-
- if (!excel.isExistSheet("seconds")) {
- // 创建第二个Sheet
- excel.createNewSheet("seconds");
- } else {
- excel.switchCurrentSheet("seconds");
- }
-
- // 设置指定位值的布尔值
- excel.setBooleanValue(1, 2, true);
- // 设置指定位值的日期值
- excel.setDateValue(1, 1, new Date(), "yyyy-MM-dd");
-
- // 合并单元格操作
- excel.setStringValue(2, 1, "Test for Merging Cells");
- excel.mergeCells(2, 1, 2, 2);
-
- // 对所有操作进行保存
- excel.saveChanges();
-
- System.out.println("------ test end ------");
- }
-
- }
|
该工具类封装了对于Ftp的操作,使用edtftpj.jar |
windchill |
|
Java代码
- package ext.csc.util.thirdparty;
-
- import java.io.File;
- import java.io.IOException;
-
- import wt.util.WTProperties;
-
- import com.enterprisedt.net.ftp.EventAdapter;
- import com.enterprisedt.net.ftp.FTPConnectMode;
- import com.enterprisedt.net.ftp.FTPException;
- import com.enterprisedt.net.ftp.FTPTransferType;
- import com.enterprisedt.net.ftp.FileTransferClient;
-
- import ext.csc.util.common.CSCDebug;
-
- /**
- * 该工具类封装了对于Ftp的操作,使用edtftpj.jar
- * @author mliu
- *
- */
- public class CSCFtp {
- private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCFtp.class);
-
- public static boolean VERBOSE = true;
-
- static {
- /* VERBOSE = AliUtil.getSpecPropertiesValue("ext.ali.config.archive",
- "ext.ali.archive.verbose", "false").equals("true");*/
- }
-
- /**
- * 传输文件到Ftp服务器
- * @param ftpserver Ftp服务器IP(Ex: 132.253.220.106)
- * @param user Ftp服务器用户名
- * @param password Ftp服务器密码
- * @param fromPathFile LocalFile - 待传输的文件全路径及文件名
- * @param toFileName RemoteFile - 传输目的路径及文件名(Ex: /testZipArrived.zip)
- * @return 是否成功标记
- */
- public static boolean ftpToServer(String ftpserver, String user,
- String password, String fromPathFile, String toFileName) {
- if (VERBOSE)
- System.out.println("=>Enter FtpUtil.ftpToServer(),ftpServer : "
- + ftpserver + ",user : " + user + ",password : " + password
- + ",fromPathFile : " + fromPathFile + ",toFileName :"
- + toFileName);
- boolean flag = false;
- int FTPPORT = 21;
- CSCFtpUploadListener ftpListener = null;
- long fileSize = 0;
- FileTransferClient ftp = null;
- try {
- ftp = new FileTransferClient();
- ftp.setUserName(user);
- ftp.setPassword(password);
- ftp.setRemoteHost(ftpserver);
- ftp.setRemotePort(FTPPORT);
- ftp.getAdvancedSettings().setControlEncoding("GB2312");
- File fromFile = new File(fromPathFile);
- fileSize = fromFile.length();
- if (VERBOSE)
- System.out.println("=>the local file is : "
- + fromFile.getName() + ", and its size is " + fileSize);
- ftpListener = new CSCFtpUploadListener(ftp, fileSize);
- ftp.setEventListener(ftpListener);
- ftp.getAdvancedSettings().setTransferBufferSize(102400);
- ftp.getAdvancedSettings().setTransferNotifyInterval(204800);
- // ftp.getAdvancedFTPSettings().setActivePortRange(61500,61510);
- // ftp.setTimeout(120);
- ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.ACTIVE);
- ftp.setContentType(FTPTransferType.BINARY);
- ftp.connect();
- if (VERBOSE)
- System.out.println("=>Begin to upload " + fromPathFile);
- ftp.uploadFile(fromPathFile, toFileName);
- if (VERBOSE)
- System.out.println("=>End to upload " + fromPathFile);
- if (ftp.isConnected())
- ftp.disconnect();
- // deleteFile(fromPathFile);
- flag = true;
- } catch (NumberFormatException e) {
- // deleteFile(fromPathFile);
- e.printStackTrace();
- } catch (IOException e) {
- // deleteFile(fromPathFile);
- e.printStackTrace();
- } catch (FTPException e) {
- // deleteFile(fromPathFile);
- e.printStackTrace();
- } finally {
- try {
- if (ftp.isConnected())
- ftp.disconnect();
- } catch (Exception ex) {
- System.out
- .println("=>in finally block to close ftp connection, exception ocurred : "
- + ex.getMessage());
- ex.printStackTrace();
- }
- }
- if (VERBOSE)
- System.out.println("=>Exit FtpUtil.ftpToServer()................");
- return flag;
- }
-
- /**
- * 下载Ftp服务器的内容到本地
- * @param ftpserver Ftp服务器IP(Ex: 132.253.220.106)
- * @param user Ftp服务器用户名
- * @param password Ftp服务器密码
- * @param fromPathFile LocalFile - 待传输的文件全路径及文件名
- * @param toFileName RemoteFile - 传输目的路径及文件名(Ex: /testZipArrived.zip)
- * @return 成功的标记
- */
- public static boolean getFileFromServer(String ftpserver, String user,
- String password, String fromPathFile, String toFileName) {
- boolean flag = false;
- int FTPPORT = 21;
- CSCFtpUploadListener ftpListener = null;
- long fileSize = 0;
- FileTransferClient ftp = null;
-
- try {
- ftp = new FileTransferClient();
- ftp.setUserName(user);
- ftp.setPassword(password);
- ftp.setRemoteHost(ftpserver);
- ftp.setRemotePort(FTPPORT);
- ftp.getAdvancedSettings().setControlEncoding("GB2312");
- ftpListener = new CSCFtpUploadListener(ftp, fileSize);
- ftp.setEventListener(ftpListener);
- ftp.getAdvancedSettings().setTransferBufferSize(102400);
- ftp.getAdvancedSettings().setTransferNotifyInterval(204800);
- ftp.getAdvancedFTPSettings().setActivePortRange(61500, 61510);
- // ftp.setTimeout(120);
- ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.ACTIVE);
- ftp.setContentType(FTPTransferType.BINARY);
- ftp.connect();
- System.out.println("=>Begin to get file " + toFileName
- + ",the file exist is " + ftp.exists(toFileName));
- ftp.downloadFile(fromPathFile, toFileName);
- // ftp.uploadFile(fromPathFile,toFileName);
- System.out.println("=>End to get file,the file path is "
- + fromPathFile);
- File localfile = new File(fromPathFile);
- if (localfile.length() > 0) {
- //ftp.deleteFile(toFileName);
- flag = true;
- }
- if (ftp.isConnected())
- ftp.disconnect();
- // deleteFile(fromPathFile);
-
- } catch (NumberFormatException e) {
- // deleteFile(fromPathFile);
- e.printStackTrace();
- } catch (IOException e) {
- // deleteFile(fromPathFile);
- e.printStackTrace();
- } catch (FTPException e) {
- // deleteFile(fromPathFile);
- e.printStackTrace();
- } finally {
- try {
- if (ftp.isConnected())
- ftp.disconnect();
- } catch (Exception ex) {
- System.out.println("=>in finally block to close ftp connection, exception ocurred : "
- + ex.getMessage());
- ex.printStackTrace();
- }
- }
- return flag;
- }
-
- public static boolean deleteFile(String pathname) {
- try {
- File toBeDeleted = new File(pathname);
- toBeDeleted.delete();
- return (true);
- } catch (Exception ex) {
- ex.printStackTrace();
- return (false);
- }
- }
-
- public static void main(String args[]) throws IOException {
- //************************ Test of ftpToServer ********************************
- /* String wthome = (String) (WTProperties.getLocalProperties()).getProperty("wt.home", "");
- String zipFilePath = wthome + File.separator + "temp" + File.separator + "testZip.zip";
-
- String userName = "ftp_user";
- String password = "cscftp";
- String ftpServer = "132.253.220.106";
- String fromFile = zipFilePath;
- String toFile = "/testZipArrived.zip";
- CSCFtp.ftpToServer(ftpServer, userName, password, fromFile, toFile);*/
-
- //************************ Test of getFileFromServer ********************************
- String wthome = (String) (WTProperties.getLocalProperties()).getProperty("wt.home", "");
- String zipFilePath = wthome + File.separator + "temp" + File.separator + "testZipLocal.zip";
-
- String userName = "ftp_user";
- String password = "cscftp";
- String ftpServer = "132.253.220.106";
- String fromFile = zipFilePath; //LocalFile
- String toFile = "/testZipArrived.zip"; //RemoteFile
- CSCFtp.getFileFromServer(ftpServer, userName, password, fromFile, toFile);
- }
- }
-
-
-
- class CSCFtpUploadListener extends EventAdapter {
-
- private long fileSize = 0;
-
- private long bytesTransferred = 0;
-
- private FileTransferClient ftpClient;
-
- public CSCFtpUploadListener(FileTransferClient ftpClient, long fileSize) {
- this.ftpClient = ftpClient;
- this.fileSize = fileSize;
- }
-
- public void bytesTransferred(String connId, String remoteFilename,
- long bytes) {
- bytesTransferred = bytes;
- if (bytesTransferred == fileSize) {
- System.out
- .println("=>hi, now the bytesTransferred equals to the fileSize, so the file"
- + remoteFilename + " transfer done!!!");
- }
- }
-
- public void uploadCompleted(String connId, String remoteFilename) {
- System.out.println("=>the file " + remoteFilename
- + " Upload Completed !!!");
- }
-
- public long getBytesTransferred() {
- return bytesTransferred;
- }
- }
|
该工具类封装了对于Zip的一些功能 |
windchill |
|
Java代码
- package ext.csc.util.thirdparty;
-
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.Enumeration;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Set;
- import java.util.zip.ZipInputStream;
-
- import org.apache.tools.zip.ZipEntry;
- import org.apache.tools.zip.ZipFile;
- import org.apache.tools.zip.ZipOutputStream;
-
- import wt.content.ContentRoleType;
- import wt.doc.WTDocument;
- import wt.util.WTProperties;
-
- import ext.csc.util.common.CSCDebug;
- import ext.csc.util.core.CSCDoc;
-
- /**
- * 该工具类封装了对于Zip的一些功能
- * @author mliu
- *
- */
- public class CSCZip {
- private static final CSCDebug cscDebug = CSCDebug.getDebug(CSCZip.class);
-
- /**
- * 打Zip包
- * @param fileMap 待打包文件对应表 (Key:待打包文件的InputStream, Value: 打包好的文件名)
- * @param outZipFilePath 输出的Zip全路径及文件名
- */
- public static void zip(HashMap<InputStream, String> fileMap, String outZipFilePath) throws Exception {
- byte[] buf = new byte[1024];
-
- //如果目标路径不存在,则创建
- String[] aFolders;
- if(outZipFilePath.indexOf("\\") > -1){
- aFolders = outZipFilePath.split("\\\\");
- }else{
- aFolders = outZipFilePath.split("/");
- }
- String zipFolder = "";
- for (int i = 0; i < aFolders.length-1 ; i++) {
- zipFolder = zipFolder + aFolders[i] + File.separator;
- }
- File folder = new File(zipFolder);
- folder.mkdirs();
-
- //开始打包
- File zipFile = new File(outZipFilePath);
- ZipOutputStream zos = new ZipOutputStream(zipFile);
-
- Set<InputStream> set = fileMap.keySet();
- Iterator<InputStream> it = set.iterator();
- while (it.hasNext()) {
- InputStream is = it.next();
- String fileName = fileMap.get(is);
-
- if (is != null) {
- zos.putNextEntry(new ZipEntry(fileName));
- int len = 0;
- while ((len = is.read(buf)) >= 0){
- zos.write(buf, 0, len);
- }
- is.close();
- }
- }
- }
-
- /**
- * 解压缩Zip包
- * @param localpath Zip包文件路径
- * @param outpath 输出目录
- * @throws Exception
- */
- public static void unZip(String localpath, String outpath) throws Exception {
- ZipInputStream in = new ZipInputStream(new FileInputStream(localpath));
-
- ZipFile zipFile = new ZipFile(localpath);
- Enumeration e = zipFile.getEntries();
- ZipEntry z = null;
-
- //如果目标路径不存在,则创建
- File file = new File(outpath);
- file.mkdirs();
-
- while (e.hasMoreElements()){
- z = (ZipEntry)e.nextElement();
-
- System.out.println("unziping " + z.getName());
- if (z.isDirectory()) {
- String name = z.getName();
- name = name.substring(0, name.length() - 1);
- File f = new java.io.File(outpath + File.separator + name);
- f.mkdir();
- } else {
- String filename = z.getName();
-
- //如果解压包内路径不存在,则创建
- String[] aFolders;
- if(filename.indexOf("\\") > -1){
- aFolders = filename.split("\\\\");
- }else{
- aFolders = filename.split("/");
- }
- String zipFolder = "";
- for (int i = 0; i < aFolders.length-1 ; i++) {
- zipFolder = zipFolder + aFolders[i] + File.separator;
- }
- zipFolder = outpath + File.separator + zipFolder;
- File folder = new File(zipFolder);
- folder.mkdirs();
-
- //开始解压
- File f = new File(outpath + File.separator + filename);
- f.createNewFile();
- FileOutputStream output = new FileOutputStream(f);
- int b;
- while ((b = in.read()) != -1){
- output.write(b);
- }
- output.close();
- }
- }
- in.close();
- }
-
- public static void main(String[] args) throws Exception {
- //************************ Test of Zip ********************************
- WTDocument doc = CSCDoc.getDoc("0000000041", false);
- //配置打包文件
- String wthome = (String) (WTProperties.getLocalProperties()).getProperty("wt.home", "");
- String docDownloadFileFolder = wthome + File.separator + "temp" + File.separator + "downloaded";
- ArrayList<String> fileDownloaded = CSCDoc.downloadContentFiles(doc, ContentRoleType.SECONDARY, docDownloadFileFolder);
- HashMap fileMap = new HashMap<InputStream, String>();
- for (int i = 0; i < fileDownloaded.size(); i++) {
- //得到文件名
- String tempFile = fileDownloaded.get(i);
- String arrayFileName[];
- if(tempFile.indexOf("\\") > -1){
- arrayFileName = tempFile.split("\\\\");
- }else{
- arrayFileName = tempFile.split("/");
- }
- String filename = arrayFileName[arrayFileName.length-1];
-
- File file = new File(tempFile);
- InputStream fileIs = new FileInputStream(file);
- fileMap.put(fileIs, doc.getName() + "-" + filename);
- }
-
- String docZipPath = wthome + File.separator + "temp" + File.separator + "CSCZip.zip";
- CSCZip.zip(fileMap, docZipPath);
-
- //************************ Test of unZip ********************************
- /* String wthome = (String) (WTProperties.getLocalProperties()).getProperty("wt.home", "");
- String zipFilePath = wthome + File.separator + "temp" + File.separator + "testZip.zip";
- String zipDestinationPath = wthome + File.separator + "temp" + File.separator + "destination";
- CSCZip.unZip(zipFilePath, zipDestinationPath);*/
- }
- }
|
action过滤器的写法 |
windchill |
|
Windchill代码
- package ext.maric.audit;
-
- import wt.access.AccessControlHelper;
- import wt.access.AccessPermission;
- import wt.admin.AdminDomainRef;
- import wt.fc.ReferenceFactory;
- import wt.fc.WTReference;
- import wt.folder.Folder;
- import wt.inf.container.WTContained;
- import wt.inf.container.WTContainer;
- import wt.inf.container.WTContainerRef;
- import wt.util.WTException;
-
- import com.ptc.core.ui.validation.DefaultSimpleValidationFilter;
- import com.ptc.core.ui.validation.UIValidationCriteria;
- import com.ptc.core.ui.validation.UIValidationKey;
- import com.ptc.core.ui.validation.UIValidationStatus;
-
-
- public class AnswerExamFilter extends DefaultSimpleValidationFilter {
-
- /* (non-Javadoc)
- * @see com.ptc.core.ui.validation.DefaultValidationFilter#preValidateAction(com.ptc.core.ui.validation.UIValidationKey, com.ptc.core.ui.validation.UIValidationCriteria)
- */
- public UIValidationStatus preValidateAction(UIValidationKey key, UIValidationCriteria criteria){
- UIValidationStatus status = UIValidationStatus.HIDDEN;
- WTReference contextObj = criteria.getContextObject();
- Object obj = contextObj.getObject();
- boolean hasCreateAccess = false;
- WTContainerRef containerRef = null;
-
- //检查是否处于退审意见答复单文件夹之下
- if(obj!=null){
- if(obj instanceof Folder){
- Folder folder = (Folder)obj;
- String folderName = folder.getFolderPath();
- // if(folderName.equals("/Default/送退审/退审意见答复单")){
- if(folderName.indexOf("退审意见答复单") > -1){
- status = UIValidationStatus.ENABLED;
- }else{
- status = UIValidationStatus.HIDDEN;
- return status;
- }
- }else{
- status = UIValidationStatus.HIDDEN;
- return status;
- }
-
- //检查是否有权限创建送审单文档
- if(obj instanceof WTContainer){
- WTContainer container = (WTContainer)obj;
- ReferenceFactory rf = new ReferenceFactory();
- try {
- containerRef = (WTContainerRef)rf.getReference(container);
- } catch (WTException e) {
- // TODO Auto-generated catch block
- status = UIValidationStatus.HIDDEN;
- return status;
- }
- }else{
- if(obj instanceof WTContained){
- WTContained contained = (WTContained)obj;
- containerRef = contained.getContainerReference();
- }
- }
-
- try {
- AdminDomainRef adminRef = AdminDomainRef.newAdminDomainRef(((WTContainer)containerRef.getObject()).getSystemDomain());
- AccessControlHelper.manager.checkAccess(adminRef, AuditBaseline.class.getName(),AccessPermission.CREATE);
-
- hasCreateAccess = true;
- } catch (WTException e) {
- hasCreateAccess = false;
- }
- if(hasCreateAccess){
- status = UIValidationStatus.ENABLED;
- }else{
- status = UIValidationStatus.HIDDEN;
- }
- }
- return status;
- }
-
- }
|