There are times when we need to inspect all the fields of asset or either to perform other tasks. One can find all the details of any asset using the following method:
Using Tag:
Using Asset API
Disclaimer: Any sample code on this blog is not officially recommended, use at your own risk.
Using Tag:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<asset:load name="thisAsset" objectid='<%= ics.GetVar("cid")%>' type='<%= ics.GetVar("type")%>'/> | |
<asset:scatter name="thisAsset" prefix="thisAsset"/> | |
<% | |
for (Enumeration e = ics.GetVars(); e.hasMoreElements();) { | |
String varName = (String)e.nextElement(); | |
if (varName.startsWith("thisAsset:")){ | |
out.println("VarName: " + varName + " = " + ics.GetVar(varName)); | |
} | |
} | |
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
Session sess = SessionFactory.getSession(ics); | |
long assetid = Long.parseLong(ics.GetVar("cid")); | |
String assettype = ics.GetVar("c"); | |
out.println("reading asset " + assetid + " of type " + assettype + "<p/>"); | |
AssetId aid = new AssetIdImpl(assettype, assetid); | |
AssetDataManager adm = (AssetDataManager) sess.getManager(AssetDataManager.class.getName()); | |
Iterable <AssetData > assets = adm.read(Collections.singletonList(aid)); | |
for (AssetData a: assets) { | |
out.println("found " + a.getAssetId() + " of type " + a.getAssetTypeDef().getName() + "<br/>"); | |
// get all core field + attributes | |
for (AttributeData attr : a.getAttributeData()) { | |
out.println(" found attribute: " + attr.getAttributeName() + " = " + attr.getData() + "<br/>"); | |
} | |
// get immediate parents | |
for (AssetId imparents : a.getImmediateParents()) { | |
out.println(" found immediate parent: " + imparents.getType() + ":" + imparents.getId() + "<br/>"); | |
} | |
// get parents | |
for (AssetId parents : a.getParents()) { | |
out.println(" found parent: " + parents.getType() + ":" + parents.getId() + "<br/>"); | |
} | |
// get associations | |
for (AssetAssociationDef assoc : a.getAssetTypeDef().getAssociations()) { | |
out.println(" found assoc: " + assoc.getName() + " child=" + assoc.getChildAssetType() + "<br/>"); | |
for (AssetId assocAsset : a.getAssociatedAssets(assoc.getName())) { | |
out.println(" found associated asset: " + assocAsset.getType() + ":" + assocAsset.getId() + "<br/>"); | |
} | |
} | |
} | |
%> |
Disclaimer: Any sample code on this blog is not officially recommended, use at your own risk.