TomRed.net

  • Increase font size
  • Default font size
  • Decrease font size
Subscribe Bookmark and Share
Home Tutorials FatWire FatWire Get the Attributes of an Asset Dynamically

FatWire Get the Attributes of an Asset Dynamically

PDF
User Rating: / 1
PoorBest 

It has often proven useful to gain access to the asset definition so as to access all the attributes of an asset.  In the example below I am looking for the attributes of asset of type MyAddressAsset which has an asset definition called MyAddressDefinition.

I create and instance of the AssetTypeDefManager called assetDefManager and pass it a reference to ics which is the same ics used in ics.GetVar("").   This allows us to create an instance of AssetTypeDef called assetDef.  To create an AssetTypeDef instance we need to specify the asset type and asset definition.  I have called these fatAssetType, fatAssetDefinition respectively.

Using the getAttributeDefs() method of the AssetTypeDef instance assetDef, we retrieve a Java List of all the attributes associate with that asset.

This list can then be iterated (here we use a for loop for clarity but a list iterator is just as valid) and the attributes retrieved. In the example below we print the attribute name each on a new line.  What you do with this is up to you.

String fatAssetType = "MyAddressAsset";
String fatAssetDefinition = "MyAddressDefinition";

//Gets instance of the asset definition manager
AssetTypeDefManager assetDefManager = new AssetTypeDefManagerImpl(ics);  
//Gets fatwire asset type by asset name and definition
AssetTypeDef assetDef = assetDefManager.findByName(fatAssetType, fatAssetDefinition); 

List attrDefsList = assetDef.getAttributeDefs();     
         
for (int i=0; i<attrDefsList.size(); i++) {
	AttributeDef def = (AttributeDef)attrDefsList.get(i);
	out.println("<br />" + ics.GetVar(def.getName()));
}

You may notice that some of the common attributes are returned along with the custom attributes of the FatWire asset definition.  These can be filtered out using the isMetaDataAttribute() method of the returned attribute.  The updated for loop is below.

for (int i=0; i<attrDefsList.size(); i++) {
	AttributeDef def = (AttributeDef)attrDefsList.get(i);
	if (!def.isMetaDataAttribute()) { //only show user created attributes
		out.println("<br />" + ics.GetVar(def.getName()));
	}
}