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

Java Code to add Windchill IBA Values to WTPart Object

Newbie

Java Code to add Windchill IBA Values to WTPart Object

Hi, I have written java code using Windchill API to create WTPart. Object is getting created but added IBA values are NOT getting displayed on info page of the WTPart object in UI. IBA values are getting added to attribute container but not getting associted with created WTPart object. Can anyone help me out please? Thanks, Rekha Bhosale
12 REPLIES 12

RE: Java Code to add Windchill IBA Values to WTPart Object

http://www.datajett.com/windchill/wc_dev/ext_tools/src/ext/tools/UpdateIBAs.java

Got The Solution!!!

Hi Sergey - Thanks for the link. I have got the solution. Now I am able to create WTPart Object along with IBA values set. Thanks, Rekha

IBA values updation without check out/check in

Hi Rekha, Is there a way to update the IBA values of an object with the use of code()APIs, without increasing its iteration? i.e without check out/check in operation.

RE: IBA values updation without check out/check in

Hi Suthya, I think we can NOT update IBA values without checking out part. Because we need to seperate working copy and original copy of Part. Windchill will NOT allow to modify original copy of object. So we have to check out and check in part while updating IBA values. Thanks, Rekha

RE: IBA values updation without check out/check in

hi, Thanks for the reply. Is it advisable to update the IBA values directly in the database, thro'jdbc code? Regards, Sathya.

Re: IBA values updation without check out/check in

It is not advisable to update IBA's without checking the objects out & then back in, but it can be done with a java method shown below:

public static void getIBA_WTP_Attr(WTPart wtp, String attrName, String newValue){
try{
Locale locale = Locale.getDefault();

wt.iba.value.IBAHolder ibaHolder=wt.iba.value.service.IBAValueHelper.service.refreshAttributeContainer((wt.iba.value.IBAHolder)wtp, null, null, null);
wt.iba.definition.service.StandardIBADefinitionService defService=new wt.iba.definition.service.StandardIBADefinitionService();
wt.iba.value.DefaultAttributeContainer attributeContainer=(wt.iba.value.DefaultAttributeContainer)ibaHolder.getAttributeContainer();

wt.iba.definition.litedefinition.AttributeDefDefaultView attributeDefinition=defService.getAttributeDefDefaultViewByPath(attrName);
System.out.println("Size:"+attributeContainer.getAttributeValues(attributeDefinition).length);

wt.iba.value.litevalue.StringValueDefaultView attValue= (wt.iba.value.litevalue.StringValueDefaultView)attributeContainer.getAttributeValues(attributeDefinition)[0];

System.out.println("Attribute Name: "+ attrName);

System.out.println("Value WAS: "+ attValue.getValue());
attValue.setValue(newValue);
System.out.println("Value IS: "+ attValue.getValue());

attributeContainer.updateAttributeValue(attValue);
wt.iba.value.service.StandardIBAValueService.theIBAValueDBService.updateAttributeContainer(ibaHolder, null, null, null);
wt.fc.PersistenceHelper.manager.save(wtp);
}
catch(WTException ew){
ew.printStackTrace();
}
catch (RemoteException er){
er.printStackTrace();
}
catch (ArrayIndexOutOfBoundsException ea){
ea.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
}


This sequence allows it:

attributeContainer.updateAttributeValue(attValue);
wt.iba.value.service.StandardIBAValueService.theIBAValueDBService.updateAttributeContainer(ibaHolder, null, null, null);
wt.fc.PersistenceHelper.manager.save(wtp);

L Jett (cadjett@aol.com;datajett@aol.com)

Re: IBA values updation without check out/check in

But it might still iterate it. Dont recall.

Re: Java Code to add Windchill IBA Values to WTPart Object

does anybody have idea how to modify iba value without iteration. with or without checkin check out

Thanks

Highlighted

Re: Java Code to add Windchill IBA Values to WTPart Object

Hello Anurag,

As it has been said earlier, it is not advisable to update IBA without iterating the object.

But, having said that you can use below snippet to do so.

public static Persistable updateIBAValue(IBAHolder ibaHolder, String ibaName, Object ibaValue)
throws RemoteException, WTException, WTPropertyVetoException
{
logger.debug("...Inside updateIBAValue...");
ibaHolder = IBAValueHelper.service.refreshAttributeContainer(ibaHolder, null, null, null);
StandardIBADefinitionService defService = new StandardIBADefinitionService();
DefaultAttributeContainer attributeContainer = (DefaultAttributeContainer) ibaHolder.getAttributeContainer();
AttributeDefDefaultView attributeDefinition = defService.getAttributeDefDefaultViewByPath(ibaName);

AbstractContextualValueDefaultView attrValue = null;
AbstractValueView abstractValueView[] = attributeContainer.getAttributeValues(attributeDefinition);
logger.debug("abstractValueView.length..."+abstractValueView.length);
if ((abstractValueView.length == 0))
{ // No existing value, needs to be created if approvedDate argument has a value

if (null != ibaValue)
{

if (attributeDefinition instanceof TimestampDefView && ibaValue instanceof Timestamp)
{
logger.debug("attributeDefinition is TimestampDefView...");
attrValue = new TimestampValueDefaultView((TimestampDefView) attributeDefinition,
(Timestamp) ibaValue);

}
else if (attributeDefinition instanceof StringDefView)
{
logger.debug("attributeDefinition is StringDefView...");
attrValue = new StringValueDefaultView((StringDefView) attributeDefinition, ibaValue.toString());

}
else if (attributeDefinition instanceof FloatDefView)
{
logger.debug("attributeDefinition is FloatDefView...");
if(ibaValue instanceof FloatingPoint){
logger.debug("ibaValue is FloatingPoint..."+ibaValue);
ibaValue = ((FloatingPoint)ibaValue).getValue();
logger.debug("ibaValue..."+ibaValue);
}

attrValue = new FloatValueDefaultView((FloatDefView) attributeDefinition, (Double) ibaValue, 5);

}

else if (attributeDefinition instanceof IntegerDefView)
{
logger.debug("attributeDefinition is IntegerDefView...");
attrValue = new IntegerValueDefaultView((IntegerDefView) attributeDefinition, (Long) ibaValue);

}
attributeContainer.addAttributeValue(attrValue);
}
else
{
System.out.println("ibaValue is null...");
return (Persistable)ibaHolder;
}
}
else
{ // Has existing value, needs to be updated/resetted
AbstractValueView avv = abstractValueView[0];
if (null == ibaValue)
{// Reset case

attributeContainer.deleteAttributeValue(avv);

}
else
{ // Update case

logger.debug("Update Case...");
if (avv instanceof TimestampValueDefaultView)
{
logger.debug("avv is TimestampValueDefaultView...");
((TimestampValueDefaultView) avv).setValue((Timestamp) ibaValue);

}
else if (avv instanceof StringValueDefaultView)
{
logger.debug("avv is StringValueDefaultView...");
((StringValueDefaultView) avv).setValue(ibaValue.toString());

}
else if (avv instanceof FloatValueDefaultView)
{
logger.debug("avv is FloatValueDefaultView...");
if(ibaValue instanceof FloatingPoint){
logger.debug("ibaValue is FloatingPoint for Update case..."+ibaValue);
ibaValue = ((FloatingPoint)ibaValue).getValue();
logger.debug("ibaValue..."+ibaValue);
}
((FloatValueDefaultView) avv).setValue((Double) ibaValue);

}
else if (avv instanceof IntegerValueDefaultView)
{
logger.debug("avv is IntegerValueDefaultView...");
((IntegerValueDefaultView) avv).setValue((Long) ibaValue);
}
attributeContainer.updateAttributeValue(avv);

}

}
ibaHolder.setAttributeContainer(attributeContainer);
StandardIBAValueService.theIBAValueDBService.updateAttributeContainer(ibaHolder, null, null, null);
WTCollection byPassIterationModifierSet = new WTHashSet();
byPassIterationModifierSet.add(ibaHolder);
WorkInProgressServerHelper.putInTxMapForValidateModifiable(byPassIterationModifierSet);
Persistable persObject = PersistenceHelper.manager.save((Persistable) ibaHolder);
// PersistenceServerHelper.manager.insert((Persistable)ibaHolder);
return persObject;
}

Please let me know, if you need any further info.