This Subversion repository is deprecated; projects are migrated to Git.

As of April 2012, parts of this repository have migrated to Git.

Please see details and status on the following pages:

All contents from this repository will remain available.

All migrated projects (and only migrated projects) will be switched to a read-only mode, and will not be maintained on Subversion any further.

Nothing changes for projects which do not get migrated.

If you would like a particular project to be migrated, please contact gregory dot joseph at magnolia-cms dot com.

/[main]/community/magnolia/trunk/magnolia-module-workflow/src/main/java/info/magnolia/module/workflow/commands/ActivationFlowCommand.java

Contents of /community/magnolia/trunk/magnolia-module-workflow/src/main/java/info/magnolia/module/workflow/commands/ActivationFlowCommand.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44899 - (show annotations) (download)
Tue May 10 08:56:45 2011 UTC (12 months, 1 week ago) by dlipp
File size: 5419 byte(s)
SCRUM-69: generated @override annotations via Source -> Clean Up  (now for second set of modules)
1 /**
2 * This file Copyright (c) 2003-2011 Magnolia International
3 * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4 *
5 *
6 * This file is dual-licensed under both the Magnolia
7 * Network Agreement and the GNU General Public License.
8 * You may elect to use one or the other of these licenses.
9 *
10 * This file is distributed in the hope that it will be
11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14 * Redistribution, except as permitted by whichever of the GPL
15 * or MNA you select, is prohibited.
16 *
17 * 1. For the GPL license (GPL), you can redistribute and/or
18 * modify this file under the terms of the GNU General
19 * Public License, Version 3, as published by the Free Software
20 * Foundation. You should have received a copy of the GNU
21 * General Public License, Version 3 along with this program;
22 * if not, write to the Free Software Foundation, Inc., 51
23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24 *
25 * 2. For the Magnolia Network Agreement (MNA), this file
26 * and the accompanying materials are made available under the
27 * terms of the MNA which accompanies this distribution, and
28 * is available at http://www.magnolia-cms.com/mna.html
29 *
30 * Any modifications to this file must keep this entire header
31 * intact.
32 *
33 */
34 package info.magnolia.module.workflow.commands;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.cms.util.DateUtil;
38 import info.magnolia.context.Context;
39 import info.magnolia.context.MgnlContext;
40 import info.magnolia.module.workflow.WorkflowConstants;
41
42 import java.text.SimpleDateFormat;
43 import java.util.Calendar;
44 import java.util.Date;
45
46 import javax.jcr.RepositoryException;
47 import openwfe.org.engine.workitem.LaunchItem;
48
49 import org.apache.commons.lang.StringUtils;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52
53
54 /**
55 * The activation command which will launch a flow to do scheduled activation by "sleep" functionality of owfe.
56 * @author jackie
57 */
58 public class ActivationFlowCommand extends PathMappedFlowCommand {
59
60 private static final Logger log = LoggerFactory.getLogger(ActivationFlowCommand.class);
61
62 private boolean recursive;
63
64 /**
65 * Set the start and end date for this page.
66 */
67 @Override
68 public void prepareLaunchItem(Context context, LaunchItem launchItem) {
69 super.prepareLaunchItem(context, launchItem);
70
71 try {
72 Content node = MgnlContext.getSystemContext().getHierarchyManager(getRepository()).getContent(getPath());
73 updateDateAttribute(node, launchItem, WorkflowConstants.ATTRIBUTE_START_DATE);
74 updateDateAttribute(node, launchItem, WorkflowConstants.ATTRIBUTE_END_DATE);
75 }
76 catch (RepositoryException e) {
77 log.error("can't find node for path [" + getRepository() + ":" + getPath() + "]", e);
78 }
79
80 }
81
82 /**
83 * Set a date stored in the repository into the list of attributes of the launch item. Ignore past activation dates
84 * <ul>
85 * <li>get utc calendar from repository</li>
86 * <li>convert utc to local calendar</li>
87 * <li>get string time for open wfe from local calendar</li>
88 * <li>set string attribute of the launch item</li>
89 * </ul>
90 */
91 private void updateDateAttribute(Content node, LaunchItem launchItem, String attributeName) {
92 final SimpleDateFormat sdf = new SimpleDateFormat(WorkflowConstants.OPENWFE_DATE_FORMAT);
93 try {
94 if (node.hasNodeData(attributeName)) {
95 Calendar cd = node.getNodeData(attributeName).getDate(); // utc calendar from repository
96 Calendar now = DateUtil.getCurrentUTCCalendar();
97 if (cd.before(now) && isActivationDate(attributeName)) {
98 log.info("Ignoring past activation date:" + attributeName + " from node:" + node.getHandle());
99 }
100 else {
101 String date = sdf.format(new Date(DateUtil.getLocalCalendarFromUTC(cd).getTimeInMillis()));
102 launchItem.getAttributes().puts(attributeName, date);
103 }
104 }
105 }
106 catch (Exception e) {
107 log.warn("cannot set date:" + attributeName + " for node" + node.getHandle(), e);
108 }
109 }
110
111 private boolean isActivationDate(String attributeName) {
112 return ((attributeName.equals(WorkflowConstants.ATTRIBUTE_START_DATE)) || (attributeName.equals(WorkflowConstants.ATTRIBUTE_END_DATE)));
113 }
114
115 @Override
116 public String getDialogName() {
117 String dialogName = super.getDialogName();
118 if(StringUtils.isEmpty(WorkflowConstants.DEFAULT_EDIT_DIALOG)){
119 return WorkflowConstants.DEFAULT_ACTIVATION_EDIT_DIALOG;
120 }
121 return dialogName;
122 }
123
124 public boolean isRecursive() {
125 return this.recursive;
126 }
127
128 public void setRecursive(boolean recursive) {
129 this.recursive = recursive;
130 }
131
132 @Override
133 public String getWorkflowName() {
134 String workflowName = super.getWorkflowName();
135 if(super.getWorkflowName().equals(WorkflowConstants.DEFAULT_WORKFLOW)){
136 workflowName = WorkflowConstants.DEFAULT_ACTIVATION_WORKFLOW;
137 }
138 return workflowName;
139 }
140
141 @Override
142 public void release() {
143 super.release();
144 this.recursive = false;
145 }
146 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Revision Id

Please contact the developer's list in case of issues or questions.

ViewVC Help
Powered by ViewVC 1.1.13