Friday, July 3, 2015

Sample code for auditing tasks

Sometimes we need to check info on certain attribute, content, templates, etc. for their existence or shared/unshared  or status, etc. For such cases, you can write your own utility to do batch audit operations. I am listing sample code for few cases:

1. Any asset of a particular asset type with a name exists or not?
%><asset:list type="<%=asset_type%>" list="myList"><%
%><asset:argument name="name" value="<%=asset_name%>"/><%
%></asset:list><%
IList myList = ics.GetList("myList");
if (myList != null && myList.hasData()) {
ics.SetVar(outputVar,"true");
}else{
ics.SetVar(outputVar,"false");
}

2. If a particular asset is present in site or not?
String siteId = ics.GetVar("pubidCS");
if(Utilities.goodString(siteId)){
%><asset:sites type="<%= asset_type %>" objectid="<%= asset_id%>" list="isinPub" pubid='<%= siteId%>' />
<% if (ics.GetErrno()==0 && ics.GetList("isinPub")!=null && ics.GetList("isinPub").hasData()){
ics.SetVar(outputVar,"true");
}
}%>
3. Check all variables of a particular asset
<asset:load name = "theAsset" type = '<%=ics.GetVar("assettype")%>' objectid = '<%=ics.GetVar("assetid")%>' / > <%
if (ics.GetErrno() == 0) { %>
<asset:scatter name = "theAsset" prefix = "myAsset" /><br/><br/>
<h3>Asset Variables( <%= ics.GetVar("assettype") %> : <%= ics.GetVar("assetid") %> ) < /h3>
<table><%
Set<String> vars = new TreeSet<String>();
for (Enumeration e = ics.GetVars(); e.hasMoreElements();) {
String sVarName = (String)e.nextElement();
vars.add(sVarName);
}
for (String var:vars){
String sVarValue = ics.GetVar( var );
%><tr><td><%= var %></td>
<td> <%= sVarValue %></tr>
<%}%>
</table><%
} else {
%> Error Loading <%= ics.GetVar("assettype") %> : <%= ics.GetVar("assetid") %> ! < br / > <%
}%>
Disclaimer: Any sample code on this blog is not officially recommended, use at your own risk.

No comments:

Post a Comment

A simple code compare functionality

One of the most important aspect of any development cycle is deployment and while deployment, it is very important to note the changes don...