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 2006/12/18 11:33:01 UTC

svn commit: r488206 - in /lenya/trunk/src: pubs/default/lenya/resources/i18n/ pubs/default/lenya/usecases/workflow/ pubs/default/modules/defaultusecases/config/cocoon-xconf/ pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/...

Author: andreas
Date: Mon Dec 18 02:33:00 2006
New Revision: 488206

URL: http://svn.apache.org/viewvc?view=rev&rev=488206
Log:
Added notififaction to submit + reject usecases. Thanks to Richard Frovarp for the patch,

Added:
    lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Reject.java
    lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Submit.java
Modified:
    lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui.xml
    lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui_de.xml
    lenya/trunk/src/pubs/default/lenya/usecases/workflow/reject.jx
    lenya/trunk/src/pubs/default/lenya/usecases/workflow/submit.jx
    lenya/trunk/src/pubs/default/modules/defaultusecases/config/cocoon-xconf/usecases-workflow-reject.xconf
    lenya/trunk/src/pubs/default/modules/defaultusecases/config/cocoon-xconf/usecases-workflow-submit.xconf
    lenya/trunk/src/webapp/lenya/resources/i18n/cmsui.xml

Modified: lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui.xml?view=diff&rev=488206&r1=488205&r2=488206
==============================================================================
--- lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui.xml (original)
+++ lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui.xml Mon Dec 18 02:33:00 2006
@@ -35,4 +35,6 @@
   
   <message key="unpublished-links">Links to unpublished documents:</message>
   <message key="links-to-document">Links from other documents:</message>
+  
+  <message key="notify-reviewers">Notify reviewers</message>
 </catalogue>

Modified: lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui_de.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui_de.xml?view=diff&rev=488206&r1=488205&r2=488206
==============================================================================
--- lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui_de.xml (original)
+++ lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui_de.xml Mon Dec 18 02:33:00 2006
@@ -33,5 +33,7 @@
   <message key="last-published">Diese Seite wurde zuletzt publiziert am {0} von {1}.</message>
   <message key="never-published">Diese Seite wurde noch nicht publiziert.</message>
   
+  <message key="notify-reviewers">Prüfer benachrichtigen</message>
+  
 </catalogue>
 

Modified: lenya/trunk/src/pubs/default/lenya/usecases/workflow/reject.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/lenya/usecases/workflow/reject.jx?view=diff&rev=488206&r1=488205&r2=488206
==============================================================================
--- lenya/trunk/src/pubs/default/lenya/usecases/workflow/reject.jx (original)
+++ lenya/trunk/src/pubs/default/lenya/usecases/workflow/reject.jx Mon Dec 18 02:33:00 2006
@@ -6,9 +6,9 @@
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,10 +19,10 @@
 <!-- $Id$ -->
 
 <page:page xmlns:jx="http://apache.org/cocoon/templates/jx/1.0" 
-           xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" 
-           xmlns="http://www.w3.org/1999/xhtml" 
-           xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
-
+  xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" 
+  xmlns="http://www.w3.org/1999/xhtml" 
+  xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
+  
   <page:title><i18n:text>Reject Document</i18n:text></page:title>
   <page:body>
     <div class="lenya-box">
@@ -38,30 +38,61 @@
           <i18n:param><jx:out value="${title}"/></i18n:param>
         </i18n:translate>      
       </div>
-
+      
       <jx:import uri="fallback://lenya/usecases/templates/messages.jx"/>
-
+      
       <div class="lenya-box-body">
-        <form id="form-reject">
+        <form id="formReject">
           <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
           <input type="hidden" name="lenya.usecase" value="${request.getParameter('lenya.usecase')}"/>
           <table class="lenya-table-noborder">
-              <tr>
-                <td colspan="2" class="lenya-entry-caption">
-                  <i18n:translate>
-                    <i18n:text i18n:key="reject-doc?"/>
-                    <i18n:param><jx:out value="${title}"/></i18n:param>
-                  </i18n:translate>
-                </td>
-              </tr>
-              <tr>
-                <td/>
-                <td>
-                  <input i18n:attr="value" type="submit" name="submit" value="Reject"/>
-                  &#160;
-                  <input i18n:attr="value" type="submit" name="cancel" value="Cancel"/>
-                </td>
-              </tr>
+            <tr>
+              <td colspan="2" class="lenya-entry-caption">
+                <i18n:translate>
+                  <i18n:text i18n:key="reject-doc?"/>
+                  <i18n:param><jx:out value="${title}"/></i18n:param>
+                </i18n:translate>
+              </td>
+            </tr>
+            <tr>
+              <td class="lenya-entry-caption">
+                <i18n:text>notify-submitter</i18n:text>:
+              </td>
+              <td>
+                <jx:choose>
+                  <jx:when test="${usecase.getParameter('sendNotification').equals('true')}">
+                    <input name="sendNotification" type="checkbox" checked="checked"
+                      onclick="javascript:formReject.rejectReason.disabled = false"/>
+                  </jx:when>
+                  <jx:otherwise>
+                    <input name="sendNotification" type="checkbox"
+                      onclick="javascript:formReject.rejectReason.disabled = true"/>
+                  </jx:otherwise>
+                </jx:choose>
+              </td>
+            </tr>
+            <tr>
+              <td class="lenya-entry-caption"><i18n:text>Reason</i18n:text>:</td>
+              <td>
+                <jx:choose>
+                  <jx:when test="${usecase.getParameter('sendNotification').equals('true')}">
+                    <input class="lenya-form-element" type="text" name="rejectReason" value="${usecase.getParameter('rejectReason')}"/>
+                  </jx:when>
+                  <jx:otherwise>
+                    <input class="lenya-form-element" type="text" name="rejectReason" value="${usecase.getParameter('rejectReason')}"
+                      disabled="true"/>
+                  </jx:otherwise>  
+                </jx:choose>
+              </td>
+            </tr>
+            <tr>
+              <td/>
+              <td>
+                <input i18n:attr="value" type="submit" name="submit" value="Reject"/>
+                &#160;
+                <input i18n:attr="value" type="submit" name="cancel" value="Cancel"/>
+              </td>
+            </tr>
           </table>
         </form>
       </div>

Modified: lenya/trunk/src/pubs/default/lenya/usecases/workflow/submit.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/lenya/usecases/workflow/submit.jx?view=diff&rev=488206&r1=488205&r2=488206
==============================================================================
--- lenya/trunk/src/pubs/default/lenya/usecases/workflow/submit.jx (original)
+++ lenya/trunk/src/pubs/default/lenya/usecases/workflow/submit.jx Mon Dec 18 02:33:00 2006
@@ -6,9 +6,9 @@
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,10 +19,10 @@
 <!-- $Id$ -->
 
 <page:page xmlns:jx="http://apache.org/cocoon/templates/jx/1.0" 
-           xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" 
-           xmlns="http://www.w3.org/1999/xhtml" 
-           xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
-
+  xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" 
+  xmlns="http://www.w3.org/1999/xhtml" 
+  xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
+  
   <page:title><i18n:text>Submit Document</i18n:text></page:title>
   <page:body>
     <div class="lenya-box">
@@ -37,30 +37,45 @@
           <i18n:param><jx:out value="${title}"/></i18n:param>
         </i18n:translate>      
       </div>
-
+      
       <jx:import uri="fallback://lenya/usecases/templates/messages.jx"/>
-
+      
       <div class="lenya-box-body">
         <form id="form-submit">
           <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
           <input type="hidden" name="lenya.usecase" value="${request.getParameter('lenya.usecase')}"/>
           <table class="lenya-table-noborder">
-              <tr>
-                <td colspan="2" class="lenya-entry-caption">
-                  <i18n:translate>
-                    <i18n:text i18n:key="submit-for-approval?"/>
-                    <i18n:param><jx:out value="${title}"/></i18n:param>
-                  </i18n:translate>
-                </td>
-              </tr>
-              <tr>
-                <td/>
-                <td>
-                  <input i18n:attr="value" type="submit" name="submit" value="Submit"/>
-                  &#160;
-                  <input i18n:attr="value" type="submit" name="cancel" value="Cancel"/>
-                </td>
-              </tr>
+            <tr>
+              <td colspan="2" class="lenya-entry-caption">
+                <i18n:translate>
+                  <i18n:text i18n:key="submit-for-approval?"/>
+                  <i18n:param><jx:out value="${title}"/></i18n:param>
+                </i18n:translate>
+              </td>
+            </tr>
+            <tr>
+              <td class="lenya-entry-caption">
+                <i18n:text>notify-reviewers</i18n:text>:
+              </td>
+              <td>
+                <jx:choose>
+                  <jx:when test="${usecase.getParameter('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>
+            <tr>
+              <td/>
+              <td>
+                <input i18n:attr="value" type="submit" name="submit" value="Submit"/>
+                &#160;
+                <input i18n:attr="value" type="submit" name="cancel" value="Cancel"/>
+              </td>
+            </tr>
           </table>
         </form>
       </div>

Modified: lenya/trunk/src/pubs/default/modules/defaultusecases/config/cocoon-xconf/usecases-workflow-reject.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/modules/defaultusecases/config/cocoon-xconf/usecases-workflow-reject.xconf?view=diff&rev=488206&r1=488205&r2=488206
==============================================================================
--- lenya/trunk/src/pubs/default/modules/defaultusecases/config/cocoon-xconf/usecases-workflow-reject.xconf (original)
+++ lenya/trunk/src/pubs/default/modules/defaultusecases/config/cocoon-xconf/usecases-workflow-reject.xconf Mon Dec 18 02:33:00 2006
@@ -1,33 +1,33 @@
-<?xml version="1.0"?>
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-
-<!-- $Id$ -->
-<!--
-    This file defines the publication specific use-cases
--->
-
-  <xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'default/workflow.reject']">
-                        
-    <component-instance name="default/workflow.reject"
-                        logger="lenya.usecases.workflow"
-                        class="org.apache.lenya.cms.workflow.usecases.InvokeWorkflow">
-      <event id="reject"/>
-      <view template="usecases/workflow/reject.jx"/>
-    </component-instance>
-
-  </xconf>
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- $Id$ -->
+<!--
+    This file defines the publication specific use-cases
+-->
+
+  <xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'default/workflow.reject']">
+                        
+    <component-instance name="default/workflow.reject"
+                        logger="lenya.usecases.workflow"
+                        class="org.apache.lenya.defaultpub.cms.usecases.Reject">
+      <event id="reject"/>
+      <view template="usecases/workflow/reject.jx"/>
+    </component-instance>
+
+  </xconf>

Modified: lenya/trunk/src/pubs/default/modules/defaultusecases/config/cocoon-xconf/usecases-workflow-submit.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/modules/defaultusecases/config/cocoon-xconf/usecases-workflow-submit.xconf?view=diff&rev=488206&r1=488205&r2=488206
==============================================================================
--- lenya/trunk/src/pubs/default/modules/defaultusecases/config/cocoon-xconf/usecases-workflow-submit.xconf (original)
+++ lenya/trunk/src/pubs/default/modules/defaultusecases/config/cocoon-xconf/usecases-workflow-submit.xconf Mon Dec 18 02:33:00 2006
@@ -1,33 +1,33 @@
-<?xml version="1.0"?>
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-
-<!-- $Id$ -->
-<!--
-    This file defines the publication specific use-cases
--->
-
-  <xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'default/workflow.submit']">
-
-    <component-instance name="default/workflow.submit"
-                        logger="lenya.usecases.workflow"
-                        class="org.apache.lenya.cms.workflow.usecases.InvokeWorkflow">
-      <event id="submit"/>
-      <view template="usecases/workflow/submit.jx"/>
-    </component-instance>
-
-  </xconf>
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- $Id$ -->
+<!--
+    This file defines the publication specific use-cases
+-->
+
+  <xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'default/workflow.submit']">
+
+    <component-instance name="default/workflow.submit"
+                        logger="lenya.usecases.workflow"
+                        class="org.apache.lenya.defaultpub.cms.usecases.Submit">
+      <event id="submit"/>
+      <view template="usecases/workflow/submit.jx"/>
+    </component-instance>
+
+  </xconf>

Added: lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Reject.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Reject.java?view=auto&rev=488206
==============================================================================
--- lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Reject.java (added)
+++ lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Reject.java Mon Dec 18 02:33:00 2006
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.defaultpub.cms.usecases;
+
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.ac.AccessControlException;
+import org.apache.lenya.ac.Identifiable;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.cms.ac.PolicyUtil;
+import org.apache.lenya.cms.observation.RepositoryEvent;
+import org.apache.lenya.cms.observation.RepositoryEventFactory;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.publication.Proxy;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.workflow.WorkflowUtil;
+import org.apache.lenya.cms.workflow.usecases.InvokeWorkflow;
+import org.apache.lenya.notification.Message;
+import org.apache.lenya.notification.NotificationException;
+import org.apache.lenya.notification.NotificationEventDescriptor;
+import org.apache.lenya.workflow.Version;
+import org.apache.lenya.workflow.Workflowable;
+
+/**
+ * Reject usecase handler.
+ */
+public class Reject extends InvokeWorkflow {
+
+    protected static final String MESSAGE_SUBJECT = "notification-message";
+    protected static final String MESSAGE_DOCUMENT_REJECTED = "document-rejected";
+    protected static final String REJECT_REASON = "rejectReason";
+    protected static final String SEND_NOTIFICATION = "sendNotification";
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+     */
+    protected void doExecute() throws Exception {
+
+        super.doExecute();
+
+        boolean notify = Boolean.valueOf(getBooleanCheckboxParameter(SEND_NOTIFICATION))
+                .booleanValue();
+        if (notify) {
+            sendNotification(getSourceDocument());
+        }
+    }
+
+    protected void sendNotification(Document authoringDocument) throws NotificationException,
+            DocumentException, AccessControlException {
+
+        User sender = getSession().getIdentity().getUser();
+
+        String reason = getParameterAsString(REJECT_REASON);
+        Workflowable workflowable = WorkflowUtil.getWorkflowable(this.manager, getSession(),
+                getLogger(), authoringDocument);
+        Version versions[] = workflowable.getVersions();
+        // current version is reject, want originating submit
+        Version version = versions[versions.length - 2];
+
+        // 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 authoringVersion = authoringDocument
+                    .getAreaVersion(Publication.AUTHORING_AREA);
+            String url;
+
+            Proxy proxy = authoringVersion.getPublication().getProxy(authoringVersion, false);
+            if (proxy != null) {
+                url = proxy.getURL(authoringVersion);
+            } else {
+                Request request = ContextHelper.getRequest(this.context);
+                final String serverUrl = "http://" + request.getServerName() + ":"
+                        + request.getServerPort();
+                final String webappUrl = authoringVersion.getCanonicalWebappURL();
+                url = serverUrl + request.getContextPath() + webappUrl;
+            }
+            String[] params = { reason, url };
+            Message message = new Message(MESSAGE_SUBJECT, new String[0],
+                    MESSAGE_DOCUMENT_REJECTED, params, sender, recipients);
+
+            NotificationEventDescriptor descriptor = new NotificationEventDescriptor(message);
+            RepositoryEvent event = RepositoryEventFactory.createEvent(this.manager, getSession(),
+                    getLogger(), descriptor);
+            getSession().enqueueEvent(event);
+        }
+    }
+}

Added: lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Submit.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Submit.java?view=auto&rev=488206
==============================================================================
--- lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Submit.java (added)
+++ lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Submit.java Mon Dec 18 02:33:00 2006
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.defaultpub.cms.usecases;
+
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.ac.AccessControlException;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.cms.ac.PolicyUtil;
+import org.apache.lenya.cms.observation.RepositoryEvent;
+import org.apache.lenya.cms.observation.RepositoryEventFactory;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.publication.Proxy;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.notification.NotificationException;
+import org.apache.lenya.cms.workflow.usecases.InvokeWorkflow;
+import org.apache.lenya.notification.Message;
+import org.apache.lenya.notification.NotificationEventDescriptor;
+
+/**
+ * Submit usecase handler.
+ */
+public class Submit extends InvokeWorkflow {
+
+    protected static final String MESSAGE_SUBJECT = "notification-message";
+    protected static final String MESSAGE_DOCUMENT_SUBMITTED = "document-submitted";
+    protected static final String SEND_NOTIFICATION = "sendNotification";
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+     */
+    protected void doExecute() throws Exception {
+
+        super.doExecute();
+        
+        if (Boolean.valueOf(getBooleanCheckboxParameter(SEND_NOTIFICATION)).booleanValue()) {
+            sendNotification(getSourceDocument());
+        }
+    }
+
+    protected void sendNotification(Document authoringDocument) throws NotificationException,
+            DocumentException, AccessControlException {
+
+        User sender = getSession().getIdentity().getUser();
+
+        User[] recipients = PolicyUtil.getUsersWithRole(this.manager, authoringDocument
+                .getCanonicalWebappURL(), "review", getLogger());
+
+        // check to see if current user can review their own submission
+        for (int i = 0; i < recipients.length; i++) {
+            if (recipients[i].equals(sender))
+                return;
+        }
+
+        String url;
+        Document authoringVersion = authoringDocument.getAreaVersion(Publication.AUTHORING_AREA);
+        Proxy proxy = authoringVersion.getPublication().getProxy(authoringVersion, false);
+
+        if (proxy != null) {
+            url = proxy.getURL(authoringVersion);
+        } else {
+            Request request = ContextHelper.getRequest(this.context);
+            final String serverUrl = "http://" + request.getServerName() + ":"
+                    + request.getServerPort();
+            final String webappUrl = authoringVersion.getCanonicalWebappURL();
+            url = serverUrl + request.getContextPath() + webappUrl;
+        }
+
+        String[] params = { url };
+
+        Message message = new Message(MESSAGE_SUBJECT, new String[0], MESSAGE_DOCUMENT_SUBMITTED,
+                params, sender, recipients);
+        NotificationEventDescriptor descriptor = new NotificationEventDescriptor(message);
+        RepositoryEvent event = RepositoryEventFactory.createEvent(this.manager, getSession(),
+                getLogger(), descriptor);
+        getSession().enqueueEvent(event);
+    }
+}

Modified: lenya/trunk/src/webapp/lenya/resources/i18n/cmsui.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/webapp/lenya/resources/i18n/cmsui.xml?view=diff&rev=488206&r1=488205&r2=488206
==============================================================================
--- lenya/trunk/src/webapp/lenya/resources/i18n/cmsui.xml (original)
+++ lenya/trunk/src/webapp/lenya/resources/i18n/cmsui.xml Mon Dec 18 02:33:00 2006
@@ -324,6 +324,8 @@
   <message key="notification-message">Lenya Notification</message>
   <message key="notify-submitter">notify the submitter</message>
   <message key="document-published">A document you submitted was published: {0}</message>
+  <message key="document-submitted">A document has been submitted for you to review: {0}</message>
+  <message key="document-rejected">A document you submitted was rejected for the following reason: {0}, {1}</message>
 
   <!-- Info asset  --> 
   <message key="New Asset">New Asset</message>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org