Use a computed attribute to display an attribute of a related asset

Hello all,

I have one small (but probably complex) question:
How can I see inside one instance A of an asset the value defined in one attribute of other asset instance B that is linked via some relationship?

Imagine the scenario:
I have a MyProject asset type, and a “P123” project instance, that has a relationship “Managed by” to a user “John”.

The user as the email defined and I want to have a “Contacts” profile in the Project asset where I show there the manager email.

Can I define a computed attribute to achieve it, or must I use a computed profile?
Any ideas?

This can be achieved via a computed attribute.
ControlUI/EclipseUI corrently passes the current asset as the first object in the init method invoked. Using the asset and the relationship you can retrieve the value of the other asset.
Sample Code Snippet

public class CustomComputedAttributeImpl extends implements ComputedAttribute {
private CentraSiteRegistryObject csRo;
public AttributeDescriptor getAttributeDescriptor() {
CustomComputedAttributeDescriptorImpl attrDesc = new CustomComputedAttributeDescriptorImpl();
attrDesc.setDataType(Constants.DATA_TYPE_STRING);
attrDesc.setMaxOccurs(ProfileAttribute.MAXOCCURS_UNBOUNDED);
attrDesc.setMinOccurs(ProfileAttribute.MINOCCURS_0);
attrDesc.setReadOnly(true);
return attrDesc;
}

public void init(Collection objects, Locale locale) {
if (objects != null) {
Iterator iterator = objects.iterator();
csRo = (CentraSiteRegistryObject) iterator.next();
}
}

public Collection getValue() throws JAXRException {
  Collection<String> values = getRelatedAssetAttributeValues();    
	return values;
}

public Collection getValue() throws JAXRException {
//Fetching value logic shouldbe handled here. The following two lines are sample code snippet.
// CentraSiteRegistryObject relatedAsset = getRelateadAsset(AssociationType.Managed_by);
// Collection value = relatedAsset.getSlot(“UserEmail”)
}

}
Kindly let me know if you need more info.

Thanks and Regards,
Malligarjunan S.

1 Like

Hello Malligarjunan,

I think you gave me exactly what I needed.
I’ll try it out and will post more about it as soon as I can.

Thanks,
Frederico