svn commit: r719109 - in /lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases: Publish.java Reject.java Submit.java

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Wed Nov 19 14:44:15 2008
New Revision: 719109

URL: http://svn.apache.org/viewvc?rev=719109&view=rev
Log:
Committing changes to workflow module.

Modified:
    lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java
    lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Reject.java
    lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Submit.java

Modified: lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java?rev=719109&r1=719108&r2=719109&view=diff
==============================================================================
--- lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java (original)
+++ lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java Wed Nov 19 14:44:15 2008
@@ -33,7 +33,6 @@
 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.linking.LinkManager;
@@ -59,10 +58,12 @@
 import org.apache.lenya.cms.usecase.scheduling.UsecaseScheduler;
 import org.apache.lenya.cms.workflow.WorkflowUtil;
 import org.apache.lenya.cms.workflow.usecases.InvokeWorkflow;
+import org.apache.lenya.notification.Address;
 import org.apache.lenya.notification.Message;
 import org.apache.lenya.notification.NotificationEventDescriptor;
 import org.apache.lenya.notification.NotificationException;
 import org.apache.lenya.notification.Text;
+import org.apache.lenya.notification.UserAddress;
 import org.apache.lenya.workflow.Version;
 import org.apache.lenya.workflow.Workflowable;
 
@@ -98,22 +99,22 @@
         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;
@@ -121,7 +122,7 @@
         }
         return shallNotifySubmitter;
     }
-    
+
     protected boolean hasBrokenLinks() {
         LinkManager linkMgr = null;
         LinkResolver resolver = null;
@@ -147,7 +148,7 @@
         }
         return false;
     }
-    
+
     /**
      * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
      */
@@ -156,15 +157,16 @@
             List nodes = new ArrayList();
 
             Document doc = getSourceDocument();
-            if(doc != null) {
+            if (doc != null) {
                 nodes.add(doc.getRepositoryNode());
-                
+
                 // lock the authoring site to avoid having live nodes for which no corresponding
                 // authoring node exists
                 nodes.add(doc.area().getSite().getRepositoryNode());
-                
+
                 // lock the live site to avoid overriding changes made by others
-                SiteStructure liveSite = doc.getPublication().getArea(Publication.LIVE_AREA).getSite();
+                SiteStructure liveSite = doc.getPublication().getArea(Publication.LIVE_AREA)
+                        .getSite();
                 nodes.add(liveSite.getRepositoryNode());
             }
 
@@ -177,8 +179,8 @@
     }
 
     /**
-     * Checks if the workflow event is supported and the parent of the document
-     * exists in the live area.
+     * Checks if the workflow event is supported and the parent of the document exists in the live
+     * area.
      * 
      * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
      */
@@ -237,17 +239,16 @@
                 for (Iterator i = missingDocuments.iterator(); i.hasNext();) {
                     Document doc = (Document) i.next();
                     /*
-                     * This doesn't work yet, see
-                     * https://issues.apache.org/jira/browse/COCOON-2057
-                     * String[] params = { doc.getCanonicalWebappURL(),
-                     * doc.getPath() + " (" + doc.getLanguage() + ")" };
+                     * This doesn't work yet, see https://issues.apache.org/jira/browse/COCOON-2057
+                     * String[] params = { doc.getCanonicalWebappURL(), doc.getPath() + " (" +
+                     * doc.getLanguage() + ")" };
                      */
                     String[] params = { doc.getPath() + ":" + doc.getLanguage(),
                             DublinCoreHelper.getTitle(doc, true) };
                     addErrorMessage("missing-document", params);
                 }
             }
-            
+
             if (hasBrokenLinks()) {
                 addInfoMessage("publish-broken-links");
             }
@@ -255,8 +256,8 @@
     }
 
     /**
-     * Returns a link of a certain node, preferably in the document's language,
-     * or <code>null</code> if the node has no links.
+     * Returns a link of a certain node, preferably in the document's language, or <code>null</code>
+     * if the node has no links.
      * @param path The path of the node.
      * @param document The document.
      * @return A link or <code>null</code>.
@@ -346,32 +347,34 @@
 
     protected void sendNotification(Document authoringDocument) throws NotificationException,
             DocumentException, AccessControlException {
-        
+
         if (!getParameterAsBoolean(CAN_SEND_NOTIFICATION, false)) {
-            getLogger().error("Can't notify submitter of document [" + authoringDocument +
-                    "] because it hasn't been submitted.");
+            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());
 
-        Identifiable[] recipients = { user };
+        Address[] recipients = { new UserAddress(user) };
 
         Document liveVersion = authoringDocument.getAreaVersion(Publication.LIVE_AREA);
-        String url;
+        String url = getWebUrl(liveVersion);
+        String loggedInUserId = getSession().getIdentity().getUserReference().getId();
+        User loggedInUser = PolicyUtil.getUser(this.manager, getSourceURL(), loggedInUserId,
+                getLogger());
+        Address sender = new UserAddress(loggedInUser);
 
-        url = getWebUrl(liveVersion);
-        User sender = getSession().getIdentity().getUser();
-        
         Text[] subjectParams = { new Text(getEvent(), true) };
         Text[] params = { new Text(url, false) };
         Text subject = new Text(MESSAGE_SUBJECT, subjectParams);
@@ -417,16 +420,16 @@
             s++;
         }
     }
-    
+
     /**
      * A list of links originating from a document. Allows lazy loading rom the usecase view.
      */
     public static class LinkList {
-        
+
         private Document document;
         private Document[] documents;
         private ServiceManager manager;
-        
+
         /**
          * @param manager The manager.
          * @param doc The document to resolve the links from.
@@ -435,7 +438,7 @@
             this.manager = manager;
             this.document = doc;
         }
-        
+
         /**
          * @return The link documents.
          */
@@ -445,7 +448,7 @@
             }
             return this.documents;
         }
-        
+
         protected Document[] getUnpublishedLinks() {
             Set docs = new HashSet();
             LinkManager linkMgr = null;

Modified: lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Reject.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Reject.java?rev=719109&r1=719108&r2=719109&view=diff
==============================================================================
--- lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Reject.java (original)
+++ lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Reject.java Wed Nov 19 14:44:15 2008
@@ -20,7 +20,6 @@
 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;
@@ -31,10 +30,12 @@
 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.Address;
 import org.apache.lenya.notification.Message;
 import org.apache.lenya.notification.NotificationException;
 import org.apache.lenya.notification.NotificationEventDescriptor;
 import org.apache.lenya.notification.Text;
+import org.apache.lenya.notification.UserAddress;
 import org.apache.lenya.workflow.Version;
 import org.apache.lenya.workflow.Workflowable;
 
@@ -65,7 +66,9 @@
     protected void sendNotification(Document authoringDocument) throws NotificationException,
             DocumentException, AccessControlException {
 
-        User sender = getSession().getIdentity().getUser();
+        String loggedInUserId = getSession().getIdentity().getUserReference().getId();
+        User loggedInUser = PolicyUtil.getUser(this.manager, getSourceURL(), loggedInUserId, getLogger());
+        Address sender = new UserAddress(loggedInUser);
 
         String reason = getParameterAsString(REJECT_REASON);
         Workflowable workflowable = WorkflowUtil.getWorkflowable(this.manager, getSession(),
@@ -82,7 +85,7 @@
             User user = PolicyUtil.getUser(this.manager, authoringDocument.getCanonicalWebappURL(),
                     userId, getLogger());
 
-            Identifiable[] recipients = { user };
+            Address[] recipients = { new UserAddress(user) };
 
             Document authoringVersion = authoringDocument
                     .getAreaVersion(Publication.AUTHORING_AREA);

Modified: lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Submit.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Submit.java?rev=719109&r1=719108&r2=719109&view=diff
==============================================================================
--- lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Submit.java (original)
+++ lenya/sandbox/access_control_redesign/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Submit.java Wed Nov 19 14:44:15 2008
@@ -30,9 +30,11 @@
 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.Address;
 import org.apache.lenya.notification.Message;
 import org.apache.lenya.notification.NotificationEventDescriptor;
 import org.apache.lenya.notification.Text;
+import org.apache.lenya.notification.UserAddress;
 
 /**
  * Submit usecase handler.
@@ -58,16 +60,23 @@
     protected void sendNotification(Document authoringDocument) throws NotificationException,
             DocumentException, AccessControlException {
 
-        User sender = getSession().getIdentity().getUser();
+        String loggedInUserId = getSession().getIdentity().getUserReference().getId();
+        User loggedInUser = PolicyUtil.getUser(this.manager, getSourceURL(), loggedInUserId, getLogger());
+        Address sender = new UserAddress(loggedInUser);
 
         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;
         }
+        
+        Address[] recipientAddresses = new UserAddress[recipients.length];
+        for (int i = 0; i < recipients.length; i++) {
+            recipientAddresses[i] = new UserAddress(recipients[i]);
+        }
 
         String url;
         Document authoringVersion = authoringDocument.getAreaVersion(Publication.AUTHORING_AREA);
@@ -87,7 +96,7 @@
         Text[] params = { new Text(url, false) };
         Text subject = new Text(MESSAGE_SUBJECT, subjectParams);
         Text body = new Text(MESSAGE_DOCUMENT_SUBMITTED, params);
-        Message message = new Message(subject, body, sender, recipients);
+        Message message = new Message(subject, body, sender, recipientAddresses);
 
 
         NotificationEventDescriptor descriptor = new NotificationEventDescriptor(message);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.