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 2005/03/31 17:31:56 UTC

svn commit: r159605 - in lenya/trunk/src/java/org/apache/lenya: cms/publication/DefaultDocument.java cms/usecase/AbstractUsecase.java transaction/UnitOfWork.java transaction/UnitOfWorkImpl.java

Author: andreas
Date: Thu Mar 31 07:31:55 2005
New Revision: 159605

URL: http://svn.apache.org/viewcvs?view=rev&rev=159605
Log:
add identity to UnitOfWork

Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
    lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java
    lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWork.java
    lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java?view=diff&r1=159604&r2=159605
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java Thu Mar 31 07:31:55 2005
@@ -32,9 +32,12 @@
 import org.apache.excalibur.source.ModifiableSource;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.ac.User;
 import org.apache.lenya.cms.metadata.dublincore.DublinCore;
 import org.apache.lenya.cms.metadata.dublincore.DublinCoreProxy;
 import org.apache.lenya.cms.publication.util.DocumentVisitor;
+import org.apache.lenya.cms.rc.RCEnvironment;
+import org.apache.lenya.cms.rc.RevisionController;
 import org.apache.lenya.cms.site.SiteManager;
 import org.apache.lenya.cms.workflow.CMSHistory;
 import org.apache.lenya.cms.workflow.History;
@@ -501,40 +504,69 @@
      * @see org.apache.lenya.transaction.Transactionable#checkin()
      */
     public void checkin() throws TransactionException {
-        // TODO Auto-generated method stub
+        checkin(true);
+    }
+    
+    protected void checkin(boolean backup) throws TransactionException {
+        try {
+            String fileName = getFile().getCanonicalPath();
+            String userName = getUserName();
+            getRevisionController().reservedCheckIn(fileName, userName, backup);
+        } catch (Exception e) {
+            throw new TransactionException(e);
+        }
+    }
 
+    /**
+     * @return The username of the unit of work's identity.
+     */
+    protected String getUserName() {
+        String userName = null;
+        User user = getIdentityMap().getUnitOfWork().getIdentity().getUser();
+        if (user != null) {
+            userName = user.getName();
+        }
+        return userName;
     }
 
     /**
      * @see org.apache.lenya.transaction.Transactionable#checkout()
      */
     public void checkout() throws TransactionException {
-        // TODO Auto-generated method stub
-
+        try {
+            String fileName = getFile().getCanonicalPath();
+            String userName = getUserName();
+            getRevisionController().reservedCheckOut(fileName, userName);
+        } catch (Exception e) {
+            throw new TransactionException(e);
+        }
     }
 
     /**
      * @see org.apache.lenya.transaction.Transactionable#isCheckedOut()
      */
     public boolean isCheckedOut() throws TransactionException {
-        // TODO Auto-generated method stub
-        return false;
+        try {
+            String fileName = getFile().getCanonicalPath();
+            String userName = getUserName();
+            return !getRevisionController().canCheckOut(fileName, userName);
+        } catch (Exception e) {
+            throw new TransactionException(e);
+        }
     }
 
     /**
      * @see org.apache.lenya.transaction.Transactionable#lock()
      */
     public void lock() throws TransactionException {
-        // TODO Auto-generated method stub
-
+        checkout();
     }
 
     /**
      * @see org.apache.lenya.transaction.Transactionable#unlock()
      */
     public void unlock() throws TransactionException {
-        // TODO Auto-generated method stub
-
+        checkin(false);
     }
 
     /**
@@ -578,6 +610,28 @@
      * @see org.apache.lenya.transaction.Transactionable#create()
      */
     public void create() throws TransactionException {
+    }
+
+    private RevisionController revisionController;
+
+    protected RevisionController getRevisionController() throws TransactionException {
+        if (this.revisionController == null) {
+            try {
+                String publicationPath = getPublication().getDirectory().getCanonicalPath();
+                RCEnvironment rcEnvironment = RCEnvironment.getInstance(getPublication()
+                        .getServletContext().getCanonicalPath());
+                String rcmlDirectory = publicationPath + File.separator
+                        + rcEnvironment.getRCMLDirectory();
+                String backupDirectory = publicationPath + File.separator
+                        + rcEnvironment.getBackupDirectory();
+
+                this.revisionController = new RevisionController(rcmlDirectory, backupDirectory,
+                        publicationPath);
+            } catch (IOException e) {
+                throw new TransactionException(e);
+            }
+        }
+        return this.revisionController;
     }
 
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java?view=diff&r1=159604&r2=159605
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/usecase/AbstractUsecase.java Thu Mar 31 07:31:55 2005
@@ -29,7 +29,11 @@
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
 import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.lenya.ac.Identity;
 import org.apache.lenya.cms.publication.DocumentIdentityMap;
 import org.apache.lenya.transaction.AbstractOperation;
 
@@ -414,6 +418,10 @@
         super.initialize();
         this.documentIdentityMap = new DocumentIdentityMap(this.manager, getLogger());
         getUnitOfWork().addIdentityMap(this.documentIdentityMap);
+        Request request = ContextHelper.getRequest(this.context);
+        Session session = request.getSession(true);
+        Identity identity = (Identity) session.getAttribute(Identity.class.getName());
+        getUnitOfWork().setIdentity(identity);
     }
 
     /**

Modified: lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWork.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWork.java?view=diff&r1=159604&r2=159605
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWork.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWork.java Thu Mar 31 07:31:55 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.lenya.transaction;
 
+import org.apache.lenya.ac.Identity;
+
 /**
  * This is a "Unit of Work" object (see "Unit of Work" pattern by Martin Fowler, 
  * <a href="http://www.martinfowler.com/eaaCatalog/unitOfWork.html">
@@ -70,4 +72,14 @@
      * @throws TransactionException if an error occurs.
      */
     void commit() throws TransactionException;
+    
+    /**
+     * @return The identity.
+     */
+    Identity getIdentity();
+    
+    /**
+     * @param identity The identity.
+     */
+    void setIdentity(Identity identity);
 }

Modified: lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java?view=diff&r1=159604&r2=159605
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java Thu Mar 31 07:31:55 2005
@@ -23,6 +23,7 @@
 import java.util.Set;
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.lenya.ac.Identity;
 
 /**
  * Default implementation of a unit of work.
@@ -103,6 +104,22 @@
             Transactionable t = (Transactionable) i.next();
             t.delete();
         }
+    }
+    
+    private Identity identity;
+
+    /**
+     * @see org.apache.lenya.transaction.UnitOfWork#getIdentity()
+     */
+    public Identity getIdentity() {
+        return this.identity;
+    }
+
+    /**
+     * @see org.apache.lenya.transaction.UnitOfWork#setIdentity(org.apache.lenya.ac.Identity)
+     */
+    public void setIdentity(Identity identity) {
+        this.identity = identity;
     }
 
 }



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