You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2007/12/20 10:22:28 UTC
svn commit: r605842 - in /lenya/trunk/src/modules-core/workflow:
java/src/org/apache/lenya/cms/workflow/usecases/Publish.java
usecases/publish.jx
Author: andreas
Date: Thu Dec 20 01:22:27 2007
New Revision: 605842
URL: http://svn.apache.org/viewvc?rev=605842&view=rev
Log:
Don't notify the submitter if a document is published directly from authoring. This fixes bug #44101.
Modified:
lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java
lenya/trunk/src/modules-core/workflow/usecases/publish.jx
Modified: lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java?rev=605842&r1=605841&r2=605842&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java (original)
+++ lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java Thu Dec 20 01:22:27 2007
@@ -76,6 +76,7 @@
protected static final String MESSAGE_DOCUMENT_PUBLISHED = "document-published";
protected static final String SCHEDULE = "schedule";
protected static final String SCHEDULE_TIME = "schedule.time";
+ protected static final String CAN_SEND_NOTIFICATION = "canSendNotification";
protected static final String SEND_NOTIFICATION = "sendNotification";
protected static final String UNPUBLISHED_LINKS = "unpublishedLinks";
@@ -93,12 +94,33 @@
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
setParameter(SCHEDULE_TIME, format.format(now));
- setParameter(SEND_NOTIFICATION, Boolean.TRUE);
+ Boolean canSendNotification = Boolean.valueOf(canNotifySubmitter());
+ setParameter(CAN_SEND_NOTIFICATION, canSendNotification);
+ setParameter(SEND_NOTIFICATION, canSendNotification);
setParameter(UNPUBLISHED_LINKS, new LinkList(this.manager, getSourceDocument()));
}
+ protected boolean canNotifySubmitter() {
+
+ boolean shallNotifySubmitter = false;
+ Workflowable workflowable = WorkflowUtil.getWorkflowable(this.manager, getSession(),
+ getLogger(), getSourceDocument());
+ Version versions[] = workflowable.getVersions();
+
+ // consider the case that there was no submit transition
+ if (versions.length > 0) {
+ Version version = versions[versions.length - 1];
+
+ // we check if the document has been submitted, otherwise we do nothing
+ if (version.getEvent().equals("submit")) {
+ shallNotifySubmitter = true;
+ }
+ }
+ return shallNotifySubmitter;
+ }
+
protected boolean hasBrokenLinks() {
LinkManager linkMgr = null;
LinkResolver resolver = null;
@@ -323,45 +345,58 @@
protected void sendNotification(Document authoringDocument) throws NotificationException,
DocumentException, AccessControlException {
- User sender = getSession().getIdentity().getUser();
+
+ if (!getParameterAsBoolean(CAN_SEND_NOTIFICATION, false)) {
+ getLogger().error("Can't notify submitter of document [" + authoringDocument +
+ "] because it hasn't been submitted.");
+ return;
+ }
Workflowable workflowable = WorkflowUtil.getWorkflowable(this.manager, getSession(),
getLogger(), authoringDocument);
Version versions[] = workflowable.getVersions();
+
+ // obtain submitted version
Version version = versions[versions.length - 2];
+
+ String userId = version.getUserId();
+ User user = PolicyUtil.getUser(this.manager, authoringDocument.getCanonicalWebappURL(),
+ userId, getLogger());
- // we assume that the document has been submitted, otherwise we do
- // nothing
- if (version.getEvent().equals("submit")) {
-
- String userId = version.getUserId();
- User user = PolicyUtil.getUser(this.manager, authoringDocument.getCanonicalWebappURL(),
- userId, getLogger());
-
- Identifiable[] recipients = { user };
-
- Document liveVersion = authoringDocument.getAreaVersion(Publication.LIVE_AREA);
- String url;
-
- Proxy proxy = liveVersion.getPublication().getProxy(liveVersion, false);
- if (proxy != null) {
- url = proxy.getURL(liveVersion);
- } else {
- Request request = ContextHelper.getRequest(this.context);
- final String serverUrl = "http://" + request.getServerName() + ":"
- + request.getServerPort();
- final String webappUrl = liveVersion.getCanonicalWebappURL();
- url = serverUrl + request.getContextPath() + webappUrl;
- }
- String[] params = { url };
- Message message = new Message(MESSAGE_SUBJECT, new String[0],
- MESSAGE_DOCUMENT_PUBLISHED, params, sender, recipients);
-
- NotificationEventDescriptor descriptor = new NotificationEventDescriptor(message);
- RepositoryEvent event = RepositoryEventFactory.createEvent(this.manager, getSession(),
- getLogger(), descriptor);
- getSession().enqueueEvent(event);
+ Identifiable[] recipients = { user };
+
+ Document liveVersion = authoringDocument.getAreaVersion(Publication.LIVE_AREA);
+ String url;
+
+ url = getWebUrl(liveVersion);
+ User sender = getSession().getIdentity().getUser();
+ String[] params = { url };
+ Message message = new Message(MESSAGE_SUBJECT, new String[0],
+ MESSAGE_DOCUMENT_PUBLISHED, params, sender, recipients);
+
+ NotificationEventDescriptor descriptor = new NotificationEventDescriptor(message);
+ RepositoryEvent event = RepositoryEventFactory.createEvent(this.manager, getSession(),
+ getLogger(), descriptor);
+ getSession().enqueueEvent(event);
+ }
+
+ /**
+ * @param document A document.
+ * @return The complete HTTP URL of the document when requested via the web.
+ */
+ protected String getWebUrl(Document document) {
+ String url;
+ Proxy proxy = document.getPublication().getProxy(document, false);
+ if (proxy != null) {
+ url = proxy.getURL(document);
+ } else {
+ Request request = ContextHelper.getRequest(this.context);
+ final String serverUrl = "http://" + request.getServerName() + ":"
+ + request.getServerPort();
+ final String webappUrl = document.getCanonicalWebappURL();
+ url = serverUrl + request.getContextPath() + webappUrl;
}
+ return url;
}
protected void createAncestorNodes(Document document) throws PublicationException,
Modified: lenya/trunk/src/modules-core/workflow/usecases/publish.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/workflow/usecases/publish.jx?rev=605842&r1=605841&r2=605842&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/workflow/usecases/publish.jx (original)
+++ lenya/trunk/src/modules-core/workflow/usecases/publish.jx Thu Dec 20 01:22:27 2007
@@ -102,21 +102,23 @@
</td>
</tr>
</jx:if>
- <tr>
- <td class="lenya-entry-caption">
- <i18n:text>notify-submitter</i18n:text>:
- </td>
- <td>
- <jx:choose>
- <jx:when test="${usecase.getBooleanCheckboxParameter('sendNotification').equals('true')}">
- <input name="sendNotification" type="checkbox" checked="checked"/>
- </jx:when>
- <jx:otherwise>
- <input name="sendNotification" type="checkbox"/>
- </jx:otherwise>
- </jx:choose>
- </td>
- </tr>
+ <jx:if test="${usecase.getParameter('canSendNotification').booleanValue()}">
+ <tr>
+ <td class="lenya-entry-caption">
+ <i18n:text>notify-submitter</i18n:text>:
+ </td>
+ <td>
+ <jx:choose>
+ <jx:when test="${usecase.getBooleanCheckboxParameter('sendNotification').equals('true')}">
+ <input name="sendNotification" type="checkbox" checked="checked"/>
+ </jx:when>
+ <jx:otherwise>
+ <input name="sendNotification" type="checkbox"/>
+ </jx:otherwise>
+ </jx:choose>
+ </td>
+ </tr>
+ </jx:if>
<tr>
<td class="lenya-entry-caption"><i18n:text>Schedule</i18n:text>:</td>
<td>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org