Friday, July 3, 2015

Batch edit and save assets

Sometimes its required to achieve some task which requires just mass editing and saving assets (no content update) within FatWire/Oracle WCS.

A simple use case can be like this: Suddenly there is a requirement of adding Flex Filter to certain flex definition to perform certain tasks like extracting file info from BLOB attached. In such cases, you will have to edit and save asset as filters only work after assets are SAVED. Hence, if there are many assets (even if  ~ 20-30 assets), its better to have simple program which can help.

Sample code:

//get list of assets in form of IList (you should know which columns are retrieved, I am assuming I will get values in assetid and assettype as column names)
<ics:listloop name="editSaveList">
<ics:listget listname="editSaveList" name="assetid"/>
<ics:listget listname="editSaveList" name="assettype"/>
<%
String assetType = ics.GetVar("assettype");
String assetid = ics.GetVar("assetid");

// Check if the asset is editable or not
%><asset:canedit type="<%=assetType %>" objectid="<%=assetid %>"/><%
//if ics.GetErrno == 0 proceed else show the reason
if(ics.GetErrno == 0) {

//2 cases to consider
//Revision tracking on or off for the asset type

// if asset type is revision tracked
<asset:checkout objectid="<%=assetid %>" type="<%=assetType %>"/>
//if checkout successful ( i.e. ics.GetErrno == 0) proceed else show error
<asset:load name="assetToEdit" type="<%=assetType %>" objectid='<%=assetid%>' option="editable" />
<asset:save name="assetToEdit" />
//if save successful ( i.e. ics.GetErrno == 0) proceed else show error
<asset:checkin name="assetToEdit" annotation="Edited and saved using EditSaveAsset utility" flush="true"/>
//if checkin successful ( i.e. ics.GetErrno == 0) proceed else show error

// else if asset type is NOT revision tracked
<asset:load name="assetToEdit" type="<%=assetType %>" objectid='<%=assetid%>' option="editable" />
<asset:save name="assetToEdit" />

}  else {
//print or log error
}%>
</ics:listloop>

Thus, implementing above code with proper improvements (check at every step for any errors) can be useful in certain scenarios. It is better to test your utility in Test environment or JSK to avoid unexpected results on management environment.

One question I often get is how to run this utility. There are many ways, I am listing few:
1, Just create one template, add your logic to it and make its usage as "Can be called from External browser". Now call this template via browser in following format:

http://<hostname>:<portnum>/<context>/ContentServer?pagename=<SiteCatalog name of Template>&assetid=<AssetId>&assettype=<AssetType>

E.g. http://localhost:8080/cs/ContentServer?pagename=AviSports/EditSaveAsset&assetid=1234567&assettype=AVIArticle

Additionally, you can code satellite:form within which shows form and you can enter values within this form and submit this form to call the same template and then run this utility. In form, you can pass assetids in list or pass query to get the asset ids and then build your list using <ics:listobject> tag

If you are using form, then simple call like following is enough:
http://localhost:8080/cs/ContentServer?pagename=AviSports/EditSaveAsset

2. Create CSElement and add legal parameters like assettype, assetids, query, etc. and then add you logic to "Element" tab. These params which you added are now available to CSElement and can be retrieved using ics.GetVar(""). So basically you can get single valued assettype, list of assetids OR assetids by performing query, then create your IList and perform batch edit&save. To run this CSElement, save it and then scroll down till you see "Preview", click on it, a form will load up in either new window or new tab. Enter values and submit to run this utility.

Tag info: http://docs.oracle.com/cd/E29542_01/apirefs.1111/e39371/JSP/asset-checkout.html
http://docs.oracle.com/cd/E29542_01/apirefs.1111/e39371/JSP/asset-checkin.html

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...