1 13 package info.magnolia.module.workflow.commands; 14 15 import info.magnolia.cms.beans.config.ContentRepository; 16 import info.magnolia.cms.core.Content; 17 import info.magnolia.cms.util.DateUtil; 18 import info.magnolia.context.Context; 19 import info.magnolia.module.workflow.WorkflowConstants; 20 21 import java.text.SimpleDateFormat ; 22 import java.util.Calendar ; 23 import java.util.Date ; 24 25 import javax.jcr.RepositoryException; 26 27 import openwfe.org.engine.workitem.LaunchItem; 28 29 import org.slf4j.Logger; 30 import org.slf4j.LoggerFactory; 31 32 33 37 public class ActivationFlowCommand extends FlowCommand { 38 39 private static final Logger log = LoggerFactory.getLogger(ActivationFlowCommand.class); 40 41 44 public void prepareLaunchItem(Context context, LaunchItem launchItem) { 45 super.prepareLaunchItem(context, launchItem); 46 47 String repository = (String ) context.get(Context.ATTRIBUTE_REPOSITORY); 48 String path = (String ) context.get(Context.ATTRIBUTE_PATH); 49 50 try { 51 Content node = ContentRepository.getHierarchyManager(repository).getContent(path); 52 updateDateAttribute(node, launchItem, WorkflowConstants.ATTRIBUTE_START_DATE); 53 updateDateAttribute(node, launchItem, WorkflowConstants.ATTRIBUTE_END_DATE); 54 } 55 catch (RepositoryException e) { 56 log.error("can't find node for path [" + path + "]", e); 57 } 58 59 } 60 61 70 private void updateDateAttribute(Content node, LaunchItem launchItem, String attributeName) { 71 final SimpleDateFormat sdf = new SimpleDateFormat (WorkflowConstants.OPENWFE_DATE_FORMAT); 72 try { 73 if (node.hasNodeData(attributeName)) { 74 Calendar cd = node.getNodeData(attributeName).getDate(); Calendar now = DateUtil.getCurrentUTCCalendar(); 76 if (cd.before(now) && isActivationDate(attributeName)) { 77 log.info("Ignoring past activation date:" + attributeName + " from node:" + node.getHandle()); 78 } 79 else { 80 String date = sdf.format(new Date (DateUtil.getLocalCalendarFromUTC(cd).getTimeInMillis())); 81 launchItem.getAttributes().puts(attributeName, date); 82 } 83 } 84 } 85 catch (Exception e) { 86 log.warn("cannot set date:" + attributeName + " for node" + node.getHandle(), e); 87 } 88 } 89 90 private boolean isActivationDate(String attributeName) { 91 return ((attributeName.equals(WorkflowConstants.ATTRIBUTE_START_DATE)) || (attributeName 92 .equals(WorkflowConstants.ATTRIBUTE_END_DATE))); 93 } 94 95 } 96 | Popular Tags |