Version: Windchill 12.0
Use Case: i was try to collect the Association type between part and epm document like "owner " or "content" or "image" but it but the value is not coming properly, (ex.) For assembly if association type with a part in UI is "Owner" but while extracting it is showing as "image" some time totally opposite like that .
Description:
HI All,
i was try to collect the Association type between part and epm document like "owner " or "content" or "image" but it but the value is not coming properly,
(ex.) For assembly if association type with a part in UI is "Owner" but while extracting it is showing as "image" some time totally opposite like that .
the code i was using is below:
public static String getAssociationType(EPMDocument epmDoc, WTPart part) {
String associationType = "";
System.out.println("getAssociationType start: "+epmDoc.getNumber());
try {
BinaryLink[] links = findLinks(part, epmDoc);
if (links != null) {
for (BinaryLink link : links) {
AssociationType type = AssociationType.getAssociationType(link);
associationType = type.getLocalizedName(null);
System.out.println("AssociationType: "+associationType);
if (associationType.equalsIgnoreCase("Owner") || associationType.equalsIgnoreCase("Image") || associationType.equalsIgnoreCase("Content")) {
System.out.println("getAssociationType end: "+associationType);
return associationType;
}
}
}
} catch (Exception e) {
System.out.println("Exception in getAssociationType: "+e);
}
System.out.println("associationType "+associationType);
return associationType;
}
/***********************************************************************************************************/
public static BinaryLink[] findLinks(Object object1, Object object2) {
EPMDocument epmDoc = null;
WTPart wtPart = null;
if (object1 instanceof EPMDocument && object2 instanceof WTPart) {
epmDoc = (EPMDocument)object1;
wtPart = (WTPart)object2;
} else if (object1 instanceof WTPart && object2 instanceof EPMDocument) {
wtPart = (WTPart)object1;
epmDoc = (EPMDocument)object2;
}
if (wtPart != null && epmDoc != null) {
BinaryLink[] activebinaryLinks = null;
activebinaryLinks = getEPMBuildRules(wtPart, epmDoc);
if (activebinaryLinks != null) {
return activebinaryLinks;
}
BinaryLink describedBinaryLink = getEPMDescribeLink(wtPart, epmDoc);
if (describedBinaryLink != null) {
return new BinaryLink[] { describedBinaryLink };
}
}
return null;
}
/***********************************************************************************************************/
private static BinaryLink[] getEPMBuildRules(WTPart part, EPMDocument epmDoc) {
try {
if (VersionControlHelper.isLatestIteration((Iterated)part)) {
EPMBuildRule[] epmBuildRule = null;
QueryResult queryResult = PersistenceHelper.manager.navigate((Persistable)part, "buildSource", EPMBuildRule.class, false);
if (queryResult != null && queryResult.size() > 0) {
epmBuildRule = new EPMBuildRule[queryResult.size()];
byte b = 0;
boolean flag = false;
ObjectIdentifier objectIdentifier = PersistenceHelper.getObjectIdentifier((Persistable)epmDoc);
while (queryResult.hasMoreElements()) {
EPMBuildRule rule = (EPMBuildRule)queryResult.nextElement();
if (!flag) {
flag = PersistenceHelper.getObjectIdentifier((Persistable)rule.getBuildSource()).equals(objectIdentifier);
}
epmBuildRule[b++] = rule;
}
if (flag) {
return (BinaryLink[])epmBuildRule;
}
}
}
} catch (Exception e) {
LOGGER.error("Error in getEPMBuildRules method :"+e);
}
return null;
}
/***********************************************************************************************************/
private static BinaryLink getEPMDescribeLink(WTPart part, EPMDocument epmDoc) {
try {
ObjectReference objectReference = ObjectReference.newObjectReference((Persistable)part);
QueryResult qr = StructHelper.service.navigateDescribes((Iterated)epmDoc, false);
// QueryResult qs = PersistenceHelper.manager.find(EPMDescribeLink.class, epmDoc, EPMDescribeLink.DESCRIBED_BY_ROLE, part);
while (qr.hasMoreElements()) {
EPMDescribeLink epmLink = (EPMDescribeLink)qr.nextElement();
WTReference wTReference = epmLink.getRoleAObjectRef();
if (objectReference.equals(wTReference)) {
return (BinaryLink)epmLink;
}
}
} catch (Exception e) {
LOGGER.error("Error in findEPMDescribeLink method :"+e);
}
return null;
}
/***********************************************************************************************************/
kindly see my code and tell me what misstake im doing, if you have any other method please share with me
thanks,
Mathivanan