Get the asset details – Fatwire / WebCenter Sites

There are times when we need to inspect all the fields of the asset or either to perform other tasks. One can find all the details of any asset using the following method:

Using Tag:

<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));
}
}

%>

Using Asset API:

<%
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/>”);
}
}

}
%>

Leave a comment