windchill 文档 & 图纸操作

windchill 文档 & 图纸
 /**
     * 获取文档主要内容
     *
     * @param oid
     * @return
     */
    public static ContentItem findPrimary(String oid) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{String.class};
            Object[] param = new Class[]{String.class};
            try {
                return (ContentItem) RemoteMethodServer.getDefault().invoke("findPrimary", CLASSNAME, WindchillDocumentApi.class, classArray, param);
            } catch (RemoteException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        } else {
            ContentItem primarycontent = null;
            WTDocument doc = null;
            try {
                NmOid nmOid = NmOid.newNmOid(oid);
                Object obj = nmOid.getRefObject();
                if (obj != null && obj instanceof WTDocument) {
                    doc = (WTDocument) obj;
                    //初始化:现将文件内容列表加载到内存中
                    ContentHolder contentHolder = ContentHelper.service.getContents(doc);
                    //然后获取主文件
                    QueryResult qr = ContentHelper.service.getContentsByRole(contentHolder, ContentRoleType.PRIMARY);
                    if (qr != null && qr.hasMoreElements()) {
                        primarycontent = (ContentItem) qr.nextElement();
                    }
                }
            } catch (WTException e) {
                e.printStackTrace();
            } catch (PropertyVetoException e) {
                e.printStackTrace();
            }

            return primarycontent;
        }
        return null;
    }
    /**
     * 下载主要内容——服务器文件夹
     *
     * @param oid
     * @param directory
     * @return
     */
    public static File downloadPrimary(String oid, String directory) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{String.class, String.class};
            Object[] objs = new Object[]{oid, directory};
            try {
                return (File) RemoteMethodServer.getDefault().invoke("downloadPrimary", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            File file = null;
            ContentItem primaryContent = findPrimary(oid);
            if (primaryContent != null && primaryContent instanceof ApplicationData) {
                ApplicationData applicationData = (ApplicationData) primaryContent;
                file = new File(directory + applicationData.getFileName());

                InputStream instream = null;
                BufferedInputStream buffInStream = null;
                FileOutputStream outstream = null;
                try {
                    instream = ContentServerHelper.service.findContentStream(applicationData);
                    buffInStream = new BufferedInputStream(instream);
                    byte[] buf = new byte[ONE_KB];
                    outstream = new FileOutputStream(file);
                    int readBytes = 0;
                    while ((readBytes = buffInStream.read(buf, 0, ONE_KB)) != -1) {
                        outstream.write(buf, 0, readBytes);
                    }
                } catch (WTException | IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        outstream.close();
                        buffInStream.close();
                        instream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return file;
        }
        return null;
    }
     /**
     * 删除文档主内容
     *
     * @param oid
     * @param filepath
     * @return
     */
    public static WTDocument updatePrimary(String oid, String filepath) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{String.class, String.class};
            Object[] objs = new Object[]{oid, filepath};
            try {
                return (WTDocument) RemoteMethodServer.getDefault().invoke("updatePrimary", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTDocument doc = null;
            Transaction tx = null;
            FileInputStream instream = null;
            try {
                NmOid nmoid = NmOid.newNmOid(oid);
                Object refobject = nmoid.getRefObject();
                if (refobject != null && refobject instanceof WTDocument) {
                    doc = (WTDocument) refobject;
                    if (!PersistentObjectManager.getPom().isTransactionActive()) {
                        tx = new Transaction();
                        tx.start();
                    }
                    ContentItem theContent = findPrimary(oid);
                    if (theContent != null) {
                        ContentServerHelper.service.deleteContent(doc, theContent);
                    }
                    File newFile = new File(filepath);
                    ApplicationData newContent = ApplicationData.newApplicationData(doc);
                    newContent.setFileName(newFile.getName());
                    newContent.setFileSize(newFile.length());
                    instream = new FileInputStream(newFile);
                    ContentServerHelper.service.updatePrimary(doc, newContent, instream);
                    tx.commit();
                    tx = null;
                    doc = (WTDocument) PersistenceHelper.manager.refresh(doc, true, true);
                }
            } catch (WTException | PropertyVetoException | IOException e) {
                e.printStackTrace();
            } finally {
                if (tx != null) {
                    tx.rollback();
                    tx = null;
                }
                try {
                    instream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return doc;
        }
        return null;
    }
    /**
     * 获取文档的附件
     *
     * @param oid
     * @return
     */
    public static List<ContentItem> findContents(String oid) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{String.class};
            Object[] objs = new Object[]{oid};
            try {
                return (List<ContentItem>) RemoteMethodServer.getDefault().invoke("findContents", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            List<ContentItem> contentList = new ArrayList<>();
            WTDocument doc = null;
            try {
                NmOid nmoid = NmOid.newNmOid(oid);
                Object refobject = nmoid.getRefObject();
                if (refobject != null && refobject instanceof WTDocument) {
                    doc = (WTDocument) refobject;
                    //初始化:现将文件内容列表加载到内存中
                    doc = (WTDocument) ContentHelper.service.getContents(doc);
                    //然后获取附件
                    QueryResult qr = ContentHelper.service.getContentsByRole(doc, ContentRoleType.SECONDARY);
                    if (qr != null) {
                        while (qr.hasMoreElements()) {
                            contentList.add((ContentItem) qr.nextElement());
                        }
                    }
                }
                return contentList;
            } catch (PropertyVetoException | WTException e) {
                e.printStackTrace();
            }

        }
        return null;
    }
    /**
     * 压缩包下载
     *
     * @param oid
     * @param directory
     * @return
     */
    public static File downloadAllcontents(String oid, String directory) throws RemoteException, InvocationTargetException {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{String.class, String.class};
            Object[] objs = new Object[]{oid, directory};
            return (File) RemoteMethodServer.getDefault().invoke("downloadAllcontents", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
        } else {
            WTDocument doc = null;
            ZipOutputStream zipout = null;
            File zipFile = null;
            try {
                NmOid nmoid = NmOid.newNmOid(oid);
                Object refObject = nmoid.getRefObject();
                if (refObject != null && refObject instanceof WTDocument) {
                    doc = (WTDocument) refObject;
                }
                if (doc == null) {
                    return null;
                }
                String zipFilePath = directory + IdentityFactory.getDisplayIdentifier(doc) + ".zip";
                zipFile = new File(zipFilePath);
                zipout = new ZipOutputStream(new FileOutputStream(zipFile));
                List<ContentItem> contents = findContents(oid);
                if (contents != null) {
                    for (ContentItem contentItem : contents) {
                        InputStream instream = null;
                        try {
                            if (contentItem != null && contentItem instanceof ApplicationData) {
                                ApplicationData applicationData = (ApplicationData) contentItem;
                                ZipEntry entry = new ZipEntry(applicationData.getFileName());
                                zipout.putNextEntry(entry);
                                instream = ContentServerHelper.service.findContentStream(applicationData);
                                byte[] buf = new byte[ONE_KB];
                                int len;
                                while ((len = instream.read(buf)) > 0) {
                                    zipout.write(buf, 0, len);
                                }
                                zipout.flush();
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        } finally {
                            if (instream != null) {
                                instream.close();
                            }
                        }
                    }
                }
                zipout.finish();
            } catch (IOException | WTException e) {
                e.printStackTrace();
            } finally {
                if (zipout != null) {
                    try {
                        zipout.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return zipFile;
        }

    }
    /**
     * 更新文档的附件
     *
     * @param oid
     * @param newFilepath
     * @param oldContentFileName
     * @return
     */
    public static WTDocument updateContent(String oid, String newFilepath, String oldContentFileName) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{String.class, String.class, String.class};
            Object[] objs = new Object[]{oid, newFilepath, oldContentFileName};
            try {
                return (WTDocument) RemoteMethodServer.getDefault().invoke("updateContent", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTDocument doc = null;
            FileInputStream instream = null;
            Transaction tx = null;
            try {
                NmOid nmOid = NmOid.newNmOid(oid);
                Object refobject = nmOid.getRefObject();
                if (refobject != null && refobject instanceof WTDocument) {
                    doc = (WTDocument) refobject;
                    if (!PersistentObjectManager.getPom().isTransactionActive()) {
                        tx = new Transaction();
                        tx.start();
                        List<ContentItem> contents = findContents(oid);
                        if (contents != null) {
                            for (ContentItem contentItem : contents) {
                                if (contentItem instanceof ApplicationData) {
                                    ApplicationData applicationData = (ApplicationData) contentItem;
                                    if (applicationData.getFileName().equals(oldContentFileName)) {
                                        ContentServerHelper.service.deleteContent(doc, applicationData);
                                        File newFile = new File(newFilepath);
                                        ApplicationData newContent = ApplicationData.newApplicationData(doc);
                                        newContent.setFileName(newFile.getName());
                                        newContent.setFileSize(newFile.length());
                                        instream = new FileInputStream(newFile);
                                        ContentServerHelper.service.updateContent(doc, newContent, instream);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    tx.commit();
                    tx = null;
                    doc = (WTDocument) PersistenceHelper.manager.refresh(doc, true, true);
                }
            } catch (PropertyVetoException | WTException | IOException e) {
                e.printStackTrace();
            } finally {
                if (tx != null) {
                    tx.rollback();
                    tx = null;
                }
                try {
                    instream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            return doc;
        }
        return null;
    }
    /**
     * 删除文档的附件
     *
     * @param oid
     * @param deletedFileName
     * @return
     */
    public static WTDocument deleteContent(String oid, String deletedFileName) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{String.class, String.class};
            Object[] objs = new Object[]{oid, deletedFileName};
            try {
                return (WTDocument) RemoteMethodServer.getDefault().invoke("deleteContent", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTDocument doc = null;
            Transaction tx = null;
            try {
                NmOid nmoid = NmOid.newNmOid(oid);
                Object refobject = nmoid.getRefObject();
                doc = (WTDocument) refobject;
                if (refobject != null && refobject instanceof WTDocument) {
                    if (!PersistentObjectManager.getPom().isTransactionActive()) {
                        tx = new Transaction();
                        tx.start();
                    }
                    List<ContentItem> contents = findContents(oid);
                    if (contents != null) {
                        for (ContentItem contentItem : contents) {
                            if (contentItem instanceof ApplicationData) {
                                ApplicationData applicationData = (ApplicationData) contentItem;
                                if (applicationData.getFileName().equals(deletedFileName)) {
                                    ContentServerHelper.service.deleteContent(doc, applicationData);
                                    break;
                                }
                            }
                        }
                    }
                    tx.commit();
                    tx = null;
                    doc = (WTDocument) PersistenceHelper.manager.refresh(doc, true, true);
                }
            } catch (PropertyVetoException | WTException e) {
                e.printStackTrace();
            } finally {
                if (tx != null) {
                    tx.rollback();
                    tx = null;
                }
            }

            return doc;
        }
        return null;
    }
    /**
     * 重设文档的附件
     *
     * @param oid
     * @param filePaths
     * @return
     */
    public static WTDocument resetContents(String oid, List<String> filePaths) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{String.class, List.class};
            Object[] objs = new Object[]{oid, filePaths};
            try {
                return (WTDocument) RemoteMethodServer.getDefault().invoke("resetContents", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTDocument doc = null;
            Transaction tx = null;
            FileInputStream instream = null;
            try {
                NmOid nmoid = NmOid.newNmOid(oid);
                Object refobject = nmoid.getRefObject();
                if (refobject != null && refobject instanceof WTDocument) {
                    doc = (WTDocument) refobject;
                    if (!PersistentObjectManager.getPom().isTransactionActive()) {
                        tx = new Transaction();
                        tx.start();
                    }
                    List<ContentItem> contents = findContents(oid);
                    if (contents != null) {
                        WTSet wtset = new WTHashSet();
                        for (ContentItem contentItem : contents) {
                            if (contentItem instanceof ApplicationData) {
                                wtset.add(contentItem);
                                ContentServerHelper.service.deleteContent(wtset);
                            }
                        }
                    }
                    if (filePaths != null) {
                        for (String filepath : filePaths) {
                            File newFile = new File(filepath);
                            ApplicationData newContent = ApplicationData.newApplicationData(doc);
                            newContent.setFileName(newFile.getName());
                            newContent.setFileSize(newFile.length());
                            instream = new FileInputStream(newFile);
                            ContentServerHelper.service.updateContent(doc, newContent, instream);
                        }
                    }
                    tx.commit();
                    tx = null;
                    doc = (WTDocument) PersistenceHelper.manager.refresh(doc, true, true);
                }
            } catch (PropertyVetoException e) {
                e.printStackTrace();
            } catch (WTException | IOException e) {
                e.printStackTrace();
            } finally {
                if (tx != null) {
                    tx.rollback();
                    tx = null;
                }
                try {
                    instream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            return doc;
        }
        return null;
    }
    /**
     * 根据WTPart获取WTPartReferenceLink
     *
     * @param wtpart
     * @return
     */
    public static WTCollection findWTPartReferenceLink(WTPart wtpart) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTPart.class};
            Object[] objs = new Object[]{wtpart};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findWTPartReferenceLink", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            QuerySpec qs = null;
            try {
                qs = new QuerySpec(WTPartReferenceLink.class);
                String roleAObjectRefKeyId = BinaryLink.ROLE_BOBJECT_REF + "." + ObjectReference.KEY + "." + ObjectIdentifier.ID;
                long objectIdentifierId = PersistenceHelper.getObjectIdentifier(wtpart).getId();
                //根据WTDocument获取WTPartReferenceLink
//            WTDocument doc;
//            long objectIdentifierId = PersistenceHelper.getObjectIdentifier(doc.getMaster()).getId() ;
                SearchCondition sc = new SearchCondition(WTPartReferenceLink.class, roleAObjectRefKeyId, SearchCondition.EQUAL, objectIdentifierId);
                qs.appendWhere(sc, new int[]{0});
                QueryResult qr = PersistenceHelper.manager.find(qs);
                wtcollection.addAll(qr);
                return wtcollection;
            } catch (WTException e) {
                e.printStackTrace();
            }

        }
        return null;
    }
 /**
     * 获取WTPartReferenceLink
     *
     * @param wtpart
     * @param docMaster
     * @return
     */
    public static WTCollection findWTPartReferenceLink(WTPart wtpart, WTDocumentMaster docMaster) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTPart.class, WTDocumentMaster.class};
            Object[] objs = new Object[]{wtpart, docMaster};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findWTPartReferenceLink", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            QuerySpec qs = null;
            try {
                qs = new QuerySpec(WTPartReferenceLink.class);
                qs.appendWhere(new SearchCondition(WTPartReferenceLink.class, "roleAObjectRef.key ", "=", PersistenceHelper.getObjectIdentifier(wtpart)), new int[]{0});
                qs.appendAnd();
                qs.appendWhere(new SearchCondition(WTPartReferenceLink.class, "roleBObjectRef.key ", "=", PersistenceHelper.getObjectIdentifier(docMaster)), new int[]{0});
                QueryResult qr = PersistenceHelper.manager.find(qs);
                wtcollection.addAll(qr);
            } catch (WTException e) {
                e.printStackTrace();
            }
            return wtcollection;
        }
        return null;
    }

 /**
     * 获取参考文档关联的所有零部件
     *
     * @param wtdoc
     * @return
     */
    public static WTCollection findReferenceParts(WTDocument wtdoc) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTDocument.class};
            Object[] objs = new Object[]{wtdoc};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findReferenceParts", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            try {
                return PartDocServiceCommand.getAssociatedRefParts(wtdoc);
            } catch (WTException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
    /**
     * 获取零部件关联的所有参考文档
     *
     * @param wtpart
     * @return
     */
    public static WTCollection findReferenceDocuments(WTPart wtpart) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTPart.class};
            Object[] objs = new Object[]{wtpart};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findReferenceDocuments", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection docs = new WTArrayList();
            QueryResult qr = null;
            try {
                qr = PartDocServiceCommand.getAssociatedReferenceDocuments(wtpart);
            } catch (WTException e) {
                e.printStackTrace();
            }
            docs.addAll(qr);
            return docs;
        }
        return null;
    }
    /**
     * 根据WTPart获取WTPartDescribeLink
     *
     * @param wtpart
     * @return
     */
    public static WTCollection findWTPartDescribeLink(WTPart wtpart) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTPart.class};
            Object[] objs = new Object[]{wtpart};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findWTPartDescribeLink", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            QuerySpec qs = null;
            try {
                qs = new QuerySpec(WTPartDescribeLink.class);
                String roleAObjectRefReyId = BinaryLink.ROLE_BOBJECT_REF + "." + ObjectReference.KEY + "." + ObjectIdentifier.ID;
                //根据WTDocument获取WTPartDescribeLink
                // long objectIdentifierId = PersistenceHelper.getObjectIdentifier(doc).getId();
                long objectIdentifierId = PersistenceHelper.getObjectIdentifier(wtpart).getId();
                SearchCondition sc = new SearchCondition(WTPartDescribeLink.class, roleAObjectRefReyId, SearchCondition.EQUAL, objectIdentifierId);
                qs.appendWhere(sc, new int[]{0});

                QueryResult qr = PersistenceHelper.manager.find(qs);
                wtcollection.addAll(qr);
            } catch (WTException e) {
                e.printStackTrace();
            }
            return wtcollection;
        }
        return null;
    }
    /**
     * 获取WTPartDescribeLink
     *
     * @param wtpart
     * @param wtdoc
     * @return
     */
    public static WTCollection findWTPartDescribeLink(WTPart wtpart, WTDocument wtdoc) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTPart.class, WTDocument.class};
            Object[] objs = new Object[]{wtpart, wtdoc};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findWTPartDescribeLink", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            QuerySpec qs = null;
            try {
                qs = new QuerySpec(WTPartDescribeLink.class);
                qs.appendWhere(new SearchCondition(WTPartDescribeLink.class, "roleAObjectRef.key ", "=", PersistenceHelper.getObjectIdentifier(wtpart)), new int[]{0});
                qs.appendAnd();

                qs.appendWhere(new SearchCondition(WTPartDescribeLink.class, "roleBObjectRef.key ", "=", PersistenceHelper.getObjectIdentifier(wtdoc)), new int[]{0});
                QueryResult qr = PersistenceHelper.manager.find(qs);
                wtcollection.addAll(qr);
            } catch (WTException e) {
                e.printStackTrace();
            }

            return wtcollection;
        }
        return null;
    }
    /**
     * 获取说明文档关联的所有零部件
     *
     * @param wtdoc
     * @return
     */
    public static WTCollection findDescribeParts(WTDocument wtdoc) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTDocument.class};
            Object[] objs = new Object[]{wtdoc};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findDescribeParts", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            //获取零部件关联的所有说明文档  WTPart wtpart
            //QueryResult qr = PartDocServiceCommand.getAssociatedDescParts (wtpart) ;
            QueryResult qr = null;
            try {
                qr = PartDocServiceCommand.getAssociatedDescParts(wtdoc);
            } catch (WTException e) {
                e.printStackTrace();
            }
            wtcollection.addAll(qr);
            return wtcollection;
        }
        return null;
    }
    /**
     * 根据roleA获取WTDocumentDependencyLink
     *
     * @param wtdoc
     * @return
     */
    public static WTCollection findWTDocumentDependencyLinkByRoleA(WTDocument wtdoc) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTDocument.class};
            Object[] objs = new Object[]{wtdoc};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findWTDocumentDependencyLinkByRoleA", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            QuerySpec qs = null;
            try {
                qs = new QuerySpec(WTDocumentDependencyLink.class);
                //ROLE_AOBJECT_REF可编辑 ROLE_BOBJECT_REF只能查看
                String roleAObjectRefKeyId = BinaryLink.ROLE_AOBJECT_REF + "." + ObjectReference.KEY + "." + ObjectIdentifier.ID;
                long objectIdentifierId = PersistenceHelper.getObjectIdentifier(wtdoc).getId();
                SearchCondition sc = new SearchCondition(WTDocumentDependencyLink.class, roleAObjectRefKeyId, SearchCondition.EQUAL, objectIdentifierId);
                qs.appendWhere(sc, new int[]{0});
                QueryResult qr = PersistenceHelper.manager.find(qs);
                wtcollection.addAll(qr);
            } catch (WTException e) {
                e.printStackTrace();
            }
            return wtcollection;
        }
        return null;
    }
    /**
     * 获取文档的参考文档
     *
     * @param wtdoc
     * @return
     */
    public static WTCollection findDependsOnWTDocuments(WTDocument wtdoc) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTDocument.class};
            Object[] objs = new Object[]{wtdoc};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findDependsOnWTDocuments", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            QueryResult qr = null;
            try {
                qr = WTDocumentHelper.service.getDependsOnWTDocuments(wtdoc);
            } catch (WTException e) {
                e.printStackTrace();
            }
            wtcollection.addAll(qr);
            return wtcollection;
        }
        return null;
    }
    /**
     * 获取文档所参考的文档
     *
     * @param wtdoc
     * @return
     */
    public static WTCollection findDependentWTDocuments(WTDocument wtdoc) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTDocument.class};
            Object[] objs = new Object[]{wtdoc};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findDependentWTDocuments", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            QueryResult qr = null;
            try {
                qr = WTDocumentHelper.service.getHasDependentWTDocuments(wtdoc);
            } catch (WTException e) {
                e.printStackTrace();
            }
            wtcollection.addAll(qr);
            return wtcollection;
        }
        return null;
    }
    /**
     * 通过EPMDocument获取EPMBuildRule
     *
     * @param epm
     * @return
     * @throws RemoteException
     * @throws InvocationTargetException
     * @throws WTException
     */
    public static WTCollection findEPMBuildRules(EPMDocument epm) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{EPMDocument.class};
            Object[] objs = new Object[]{epm};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findEPMBuildRules", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTArrayList arrayList = new WTArrayList();
            arrayList.add(epm);
            AssociatedItemsInfo associatedItemsInfo = new AssociatedItemsInfo();
            associatedItemsInfo.setTraceModelItems(false);
            WTCollection links = null;
            try {
                links = AssociationTracer.getAssociatedLinks(arrayList, associatedItemsInfo, AssociationTracer.Type.getAll());
            } catch (WTException e) {
                e.printStackTrace();
            }
            return links;
        }
        return null;
    }
    /**
     * 通过WTPart获取EPMBuildRule
     *
     * @param wtpart
     * @return
     * @throws RemoteException
     * @throws InvocationTargetException
     * @throws WTException
     */
    public static WTCollection findEPMBuildRules(WTPart wtpart) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTPart.class};
            Object[] objs = new Object[]{wtpart};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findEPMBuildRules", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection links = new WTArrayList();
            Collection<AssociationLinkObject> epmAndLinks = null;
            try {
                epmAndLinks = PartDocServiceCommand.getAssociatedCADDocumentsAndLinks(wtpart);
            } catch (WTException e) {
                e.printStackTrace();
            }
            if (epmAndLinks != null) {
                for (AssociationLinkObject associationLinkobject : epmAndLinks) {
                    BinaryLink link = associationLinkobject.getLink();
                    links.add(link);
                }
            }
            return links;
        }
        return null;
    }
    /**
     * 获取EPMBuildRule
     *
     * @param epm
     * @param wtpart
     * @return
     */
    public static WTCollection findEPMBuildRules(EPMDocument epm, WTPart wtpart) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{EPMDocument.class, WTPart.class};
            Object[] objs = new Object[]{epm, wtpart};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findEPMBuildRules", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            QuerySpec qs = null;
            try {
                qs = new QuerySpec(EPMBuildRule.class);
                long roleABranchId = epm.getBranchIdentifier();
                SearchCondition sc = new SearchCondition(EPMBuildRule.class, "roleAObjectRef.key.branchId", "=", roleABranchId);
                qs.appendWhere(sc, new int[]{0});
                qs.appendAnd();
                long roleBBranchid = wtpart.getBranchIdentifier();
                sc = new SearchCondition(EPMBuildRule.class, "roleBobjectRef.key.branchid", "=", roleBBranchid);
                qs.appendWhere(sc, new int[]{0});
                QueryResult qr = PersistenceHelper.manager.find(qs);
                wtcollection.addAll(qr);
            } catch (WTException e) {
                e.printStackTrace();
            }
            return wtcollection;
        }
        return null;
    }
    /**
     * 获取关联的EPMDocument
     *
     * @param wtpart
     * @return
     */
    public static WTCollection findAssociatedCADDocuments(WTPart wtpart) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{WTPart.class};
            Object[] objs = new Object[]{wtpart};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findAssociatedCADDocuments", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            QueryResult epmAndLinks = null;
            try {
                epmAndLinks = PartDocServiceCommand.getAssociatedCADDocuments(wtpart);
            } catch (WTException e) {
                e.printStackTrace();
            }
            wtcollection.addAll(epmAndLinks);
            return wtcollection;
        }
        return null;
    }
 /**
     * 根据CAB图档获取关联的零部件
     *
     * @param epm
     * @return
     */
    public static WTCollection findAssociatedParts(EPMDocument epm) {
        if (!RemoteMethodServer.ServerFlag) {
            Class<?>[] classArray = new Class[]{EPMDocument.class};
            Object[] objs = new Object[]{epm};
            try {
                return (WTCollection) RemoteMethodServer.getDefault().invoke("findAssociatedParts", CLASSNAME, WindchillDocumentApi.class, classArray, objs);
            } catch (InvocationTargetException | RemoteException e) {
                e.printStackTrace();
            }
        } else {
            WTCollection wtcollection = new WTArrayList();
            wtcollection.add(epm);
            AssociatedItemsInfo associatedItemsInfo = new AssociatedItemsInfo();
            associatedItemsInfo.setTraceModelItems(false);
            WTCollection parts = null;
            try {
                parts = AssociationTracer.getAssociatedWTParts(wtcollection, associatedItemsInfo, AssociationTracer.Type.getAll());
            } catch (WTException e) {
                e.printStackTrace();
            }
            return parts;
        }
        return null;
    }
  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Windchill文档数据库中,有许多字段名用于描述和管理各种文档的信息。以下是一些常见的字段名及其功能: 1. 名称(Name):用于记录文档的名称或标题。该字段通常是必填字段,用于标识文档的唯一性。 2. 文档编号(Document Number):用于唯一标识文档,并可以作为文档的快速检索标识。该字段通常是自动递增的。 3. 状态(Status):用于跟踪和记录文档的当前状态,如草稿、审批中、发布等。 4. 文件类型(File Type):用于记录文档的文件类型,如Word文档、Excel电子表格、PDF文件等。 5. 版本(Version):用于记录文档的不同版本。每次修改文档时,版本号会递增,以便跟踪文档的历史记录。 6. 所有者(Owner):用于记录文档的所有者或责任人。该字段通常与用户或用户组关联。 7. 创建日期(Creation Date):用于记录文档的创建日期。 8. 修改日期(Modification Date):用于记录文档的最后一次修改日期。 9. 关键字(Keywords):用于记录描述文档内容的关键词或标签,以便更好地进行检索和分类。 10. 审批人(Approver):用于记录需要审批文档的相关人员或角色。 这些字段名的使用可以有效地帮助用户对Windchill文档数据库中的文档进行管理、检索和跟踪。通过填写和利用这些字段,用户可以更轻松地维护和组织文档资源,并从中快速找到所需的文档

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值