Home
SetExpiry.jsp.html
<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*,javax.servlet.jsp.JspWriter,java.io.*,java.text.*"%>
<%@ page import="com.ibm.workplace.wcm.api.query.*"%>
<%@ page import="java.time.LocalDateTime"%>
<%@ page import="java.util.Calendar"%>
<%
try {
out.println("<h3>Set new Expiry date for content using the News Authoring Template</h3>");
out.println("Sets an Expiry date to 5 years after publish date for content using the News Authoring Template, where Content has Expiry date of null <p>");
Workspace myworkspace = WCM_API.getRepository().getSystemWorkspace();
myworkspace.login();
Library mylib = myworkspace.getDocumentLibrary("My Content Library");
QueryService queryService = myworkspace.getQueryService();
Query query = queryService.createQuery();
query.addSelector(Selectors.libraryEquals(mylib));
query.addSelector(Selectors.typeEquals(AuthoringTemplate.class));
query.addSelector(Selectors.nameLike("News Authoring Template"));
ResultIterator results = queryService.execute(query);
Identity atid = ((AuthoringTemplate)results.next()).getIdentity();
Query query2 = queryService.createQuery(Content.class);
query2.addSelector(Selectors.libraryEquals(mylib));
query2.addSelector(Selectors.authoringTemplateEquals(atid));
ResultIterator results2 = queryService.execute(query2);
java.util.Date expiryDate;
java.util.Date publishedDate;
// Limit number of items to iterate through.
int x;
x=0;
//while (results2.hasNext())
while (results2.hasNext() && x < 1360)
{
x=x+1;
Content content = (Content) results2.next();
//out.println("<p>Content without filter: " + content.getName());
if (content.getExpiryDate() == null ) {
//out.println("<br>content: " + content.getName() + " publishedDate: " + content.getPublishedDate() + " Expiry: " + content.getExpiryDate());
publishedDate = content.getPublishedDate();
//out.println("<br>Published Date: " + publishedDate);
if (publishedDate == null) {
out.println("<p>Skipping content: " + content.getName() + ". <br>Published Date is null: ");
}
else
{
Calendar c = Calendar.getInstance();
c.setTime(publishedDate);
c.add(Calendar.YEAR, 5);
expiryDate = c.getTime();
out.println("<p>Content \"" + content.getName() + "\" <br> Published Date: " + publishedDate + "<br>Old Expiry Date: " + content.getExpiryDate() + "<br>New Expiry Date: " + expiryDate);
// Save results
content.setExpiryDate(expiryDate);
String[] save = myworkspace.save((Document) content);
if (0 == save.length) {
out.println("<p>Successfully saved Expiry date for " + content.getName());
}
}
}
}
out.println("<p>Number of records processed:" + x);
myworkspace.logout();
}
catch (Exception e) {
out.println("Exception " + e.getMessage());
e.printStackTrace();
}