/**
* 获取文档主要内容
*
* @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;
}