/*
* Manage the metadata for each possible lifecycle state in turn...
*/
Date now = new Date(); // Will be entered as the timestamp for states that we trigger
PortletLifecycleState selectedLifecycleState = form.getLifecycleState();
/*
* APPROVED
*/
if (selectedLifecycleState.isEqualToOrAfter(PortletLifecycleState.APPROVED)) {
// We are the 'approver' if it isn't previously approved...
if (portletDef.getApprovalDate() == null) {
portletDef.setApproverId(publisher.getID());
portletDef.setApprovalDate(now);
}
if (selectedLifecycleState.equals(PortletLifecycleState.APPROVED)
&& form.getPublishDate() != null
// Permissions check required (of course) to use the auto-publish feature
&& hasLifecyclePermission(publisher, PortletLifecycleState.PUBLISHED, form.getCategories())) {
// We are also the 'publisher' if we scheduled the portlet for (future) publication...
portletDef.setPublishDate(form.getPublishDateTime());
portletDef.setPublisherId(publisher.getID());
}
} else {
// Clear previous approval fields, if present...
portletDef.setApprovalDate(null);
portletDef.setApproverId(-1);
}
/*
* PUBLISHED
*/
if (selectedLifecycleState.isEqualToOrAfter(PortletLifecycleState.PUBLISHED)) {
// We are the 'publisher' if it isn't previously published...
if (portletDef.getPublishDate() == null) {
portletDef.setPublisherId(publisher.getID());
portletDef.setPublishDate(now);
}
if (selectedLifecycleState.equals(PortletLifecycleState.PUBLISHED)
&& form.getExpirationDate() != null
// Permissions check required (of course) to use the auto-expire feature
&& hasLifecyclePermission(publisher, PortletLifecycleState.EXPIRED, form.getCategories())) {
// We are also the 'expirer' if we scheduled the portlet for (future) expiration...
portletDef.setExpirationDate(form.getExpirationDateTime());
portletDef.setExpirerId(publisher.getID());
}
} else {
// Clear previous publishing fields, if present...
portletDef.setPublishDate(null);
portletDef.setPublisherId(-1);
}
/*
* EXPIRED
*/
if (selectedLifecycleState.equals(PortletLifecycleState.EXPIRED)) {
// We are only the 'expirer' if we specifically choose EXPIRED
// (MAINTENANCE mode is not considered expired)
portletDef.setExpirerId(publisher.getID());
portletDef.setExpirationDate(now);
} else {
// Clear previous expiration fields, if present...
portletDef.setExpirationDate(null);
portletDef.setExpirerId(-1);
}
/*
* MAINTENANCE
*/
if (selectedLifecycleState.equals(PortletLifecycleState.MAINTENANCE)) {
// We are placing the portlet into MAINTENANCE mode;
// an admin will restore it (manually) when available
portletDef.addParameter(PortletLifecycleState.MAINTENANCE_MODE_PARAMETER_NAME, "true");
} else {
// Otherwise we must remove the MAINTENANCE flag, if present