cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are happy to announce the new Windchill Customization board! Learn more.

API to get List of Attributes from WTPart

vuchekar
9-Granite

API to get List of Attributes from WTPart

Hi All,

I am using below code to fetch IBA values for WTpart,

but in this program i have to give input as IBA name.

i want all IBA for that part which having any value or null,

as shown here fig.

11-5-2015 2-16-06 PM.jpg

Please check my code and let me know where i am did wrong.

Regards,

Vivek

package test;

import java.util.Locale;

import wt.util.WTContext;

import wt.util.WTException;

import com.ptc.core.lwc.server.LWCNormalizedObject;

import wt.method.RemoteMethodServer;

import wt.part.WTPart;

import wt.fc.ObjectIdentifier;

import com.ptc.core.meta.common.UpdateOperationIdentifier;

import com.ptc.windchill.uwgm.common.folder.FolderHelper;

import wt.vc.wip.WorkInProgressHelper;

import wt.fc.PersistenceHelper;

import wt.fc.ReferenceFactory;

import wt.fc.WTReference;

import wt.fc.Persistable;

import wt.httpgw.WTContextBeanHandler;

import wt.method.MethodContext;

import wt.session.SessionContext;

import java.io.Serializable;

import wt.method.RemoteAccess;

public class IBAHandler3 implements RemoteAccess{

@SuppressWarnings("deprecation")

public static void main(String[] args) {

   try {

  RemoteMethodServer myServer = RemoteMethodServer.getDefault();

  myServer.setUserName("wcadmin");

  myServer.setPassword("ts");

  Class aClass[] = {};

   Object aObj[] = {};

  myServer.invoke("change", IBAHandler3.class.getName(), null, aClass,aObj);

  }catch (Exception e) {

   //Handle exceptione.printStackTrace();

  }

}

public static void change(){

   try {

  ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.part.WTPart:215486");

  WTPart part = (WTPart) PersistenceHelper.manager.refresh(oid);

  System.out.println(part.getName());

  LWCNormalizedObject obj = new LWCNormalizedObject(part,null, null, null);

  System.out.println(obj);

  obj.load("FURNACE TYPE");//Logical Identifier

   Object str = obj.get("FURNACE TYPE");//Logical Identifier

  System.out.println("-------PTC TEST-------------"+str);

  }catch (Exception e) {

   //Handle exception

  e.printStackTrace();

  }

  }

}

8 REPLIES 8
RandyJones
19-Tanzanite
(To:vuchekar)

According to the java docs this is only supported on the server side and it appears you are trying this from a client.

Supported API: true

Note: This is only supported on the server side.

The general usage pattern is to construct a PersistableAdapter by passing a Persistable or the name of a type, identifying the list of attributes that will be subsequently accessed, accessing the values of those attributes, and then applying any changes.

Note: In order for constraints to be enforced the correct locale *and* operation identifier *must* be provided when constructing the persistable adapter instance.

kpritchard
4-Participant
(To:vuchekar)

I don't think there is a way to get a return of all of the IBAs without knowing them by name.  I'm assuming that's not the problem though...

If I understand what you're trying to do, you want to get all of the IBAs and process (print) values for each.  So you'll want to include all of the IBAs you want to process in a single load i.e. adapter.load("iba1", "iba2", "iba3" etc.).  Then you'll want to test for null values before you attempt to process the value...  I like to use

if(adapter.get("iba1") != null) {

     String iba1String = (String) adapter.get("iba1");// so you need to know the data type for each IBA and cast on the get

     // do whatever to process IBA value

} else {

     // do whatever if null... maybe iba1String = "";

}

rmk
1-Newbie
1-Newbie
(To:vuchekar)

HI vivek,

Use the following method to list all the IBA's id and Value,

import wt.iba.definition.litedefinition.AttributeDefDefaultView;

import wt.iba.value.DefaultAttributeContainer;

import wt.iba.value.IBAHolder;

import wt.iba.value.IBAValueUtility;

import wt.iba.value.litevalue.AbstractValueView;

import wt.iba.value.service.IBAValueHelper;

public static String getAllIBAValues(IBAHolder ibaHolder) {

  String ibaValue = new String();

  String ibaLogicalId = new String();

  String lv_result = new String();

  try {

  ibaHolder = IBAValueHelper.service.refreshAttributeContainer(

  ibaHolder, null, SessionHelper.manager.getLocale(), null);

  DefaultAttributeContainer theContainer = (DefaultAttributeContainer) ibaHolder

  .getAttributeContainer();

  if (theContainer != null) {

  AttributeDefDefaultView[] theAtts = theContainer

  .getAttributeDefinitions();

  for (int i = 0; i < theAtts.length; i++) {

  ibaLogicalId = theAtts[i].getLogicalIdentifier().toString();

  AbstractValueView[] theValues = theContainer

  .getAttributeValues(theAtts[i]);

  for (int j = 0; j < theValues.length; j++) {

  if (ibaValue == null) {

  ibaValue = IBAValueUtility

  .getLocalizedIBAValueDisplayString(

  theValues[j], SessionHelper.manager

  .getLocale().ENGLISH);

  } else {

  ibaValue = IBAValueUtility

  .getLocalizedIBAValueDisplayString(

  theValues[j], SessionHelper.manager

  .getLocale().ENGLISH);

  }

  }

  if (ibaValue.trim().length() == 0)

  ibaValue = "-";

  if (!ibaValue.equalsIgnoreCase("-"))

  lv_result += ibaLogicalId + "=" + ibaValue + "|";

  }

  }

  } catch (Exception e) {

  e.printStackTrace();

  }

  return lv_result;

}

BR

Ramanathan MK

vuchekar
9-Granite
(To:rmk)

Hi Ramanathan,

Thanks for your response.

we are able to fetch attributes which having values, but issue with attributes which having null values.

here from below image, we are able to fetch only two attributes which having values.

here is program output

--------------------------------------------------------------------------------

GOB_WEIGHT=45|OI_BUSINESS_TYPE=Tableware|

--------------------------------------------------------------------------------

we need to print all three attributes which are present on below snap.

Please let us know, where i have to make correction in above code.

rama1.jpg

Regards,

Vivek

rmk
1-Newbie
1-Newbie
(To:vuchekar)

Hi Vivek,

Windchill doesn't capture NULL values for IBA, but check for logical attributes(ibaLogicalId) is printing and made your business logic such way and assign Null to that ibaLogicalId. In your case it's TABLEWARE_HEIGHT.

Good Luck !!!

BR

MKR

vuchekar
9-Granite
(To:rmk)

Hi Ram,

I tried to Print ibaLogicalId, and it gives me only two attributes i.e. GOB_WEIGHT and OI_BUSINESS_TYPE.

also i checked array size also of AttributeDefDefaultView[] theAtts. getting size=2.

from this i am not able to find all three attributes irrespective of its values.

Please if you find such api, please inform me.

It will be great help.

Thanks for your response.

Regards,

Vivek

Would using a DBquery be an acceptable method to get this data? I have created one that pulls all of the custom IBAs even if they have a NULL value.

Vivek,

To properly do what you want, you need to go at definitions first, then values.  The values tables in Oracle or SQLServer only persist rows for values that are not NULL or EMPTY.  Default values will be stored.  Additional rows get added if value is altered on any useage regardless if object is or is not revisable or iterated.

The best way to accomplish what you want, especially from the client side is to use the PersistenceHelper.manager service interface and pass a QuerySpec to return all "nnnDefinitionObjects" defined for the typed object's OBID, joined by the WTTypeDefinition and WTTypeDefinitionMaster.  I do not have source code readily to paste, but the tables with definitions are FloatDefinition, IntegerDefinition, StringDefinition, BooleanDefinition, and URLDefinition. May be one or two more.

Your values will be, should they exist in tables like BooleanValue or StringValue, etc.  You'll need object identifiers of type definition as well as IBAHolder object identifier.

This has been discussed before and should be in the migrated discussions on from PTC User.

Free free to try to write the code, and paste here for tuning or error issues.

Step 1:  Query IBAHolder for type definition assigned

Step 2:  Use result to get definitions

Step 3: Use definitions to get values

Step 4, Check for count returned, use unsupported / undocumented API of Persistables returned to get Value1() and Value 2() .

I have had to write this code before, so I know it works.  You just have to pay close attention to what is returned, I highly recommend using Log4J to print out class.getName, and value, or no value. You also may find it easier as you get the definitions returned, to put those obids or definition names as a HashMap key and create your own Abstracted JavaBean, SomeValueBean class with setters and getters that holds the value(s), definition info. on attribute, definition on / of soft type, and container accessible within. This makes it easier to print them or display in the UI.

NOTE: LWCNormalized object is awesome class, but it is extreme heavy code as it also allows you to CREATE, not just RETRIEVE, new persistables and assign them attributes.

Good luck.

Top Tags