logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

svn commit: r279858 - in /lenya/trunk/src: java/org/apache/lenya/cms/site/u: msg#00024

Subject: svn commit: r279858 - in /lenya/trunk/src: java/org/apache/lenya/cms/site/usecases/Rollback.java webapp/WEB-INF/cocoon-xconf.xsl webapp/lenya/usecase.xmap webapp/lenya/usecases/tab/revisions.jx
Author: chestnut
Date: Fri Sep  9 12:42:10 2005
New Revision: 279858

URL: http://svn.apache.org/viewcvs?rev=279858&view=rev
Log:
new rollback usecase

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Rollback.java   
(with props)
Modified:
    lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
    lenya/trunk/src/webapp/lenya/usecase.xmap
    lenya/trunk/src/webapp/lenya/usecases/tab/revisions.jx

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Rollback.java
URL: 
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Rollback.java?rev=279858&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Rollback.java 
(added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Rollback.java Fri 
Sep  9 12:42:10 2005
@@ -0,0 +1,124 @@
+/*
+ * Copyright  1999-2005 The Apache Software Foundation
+ *
+ *  Licensed 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.cms.site.usecases;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Map;
+
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.ac.Identity;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.rc.RCEnvironment;
+import org.apache.lenya.cms.rc.RevisionController;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+import org.apache.lenya.cms.workflow.WorkflowUtil;
+
+/**
+ * Rollback.
+ */
+public class Rollback extends DocumentUsecase {
+       
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
+     */
+    protected org.apache.lenya.cms.repository.Node[] getNodesToLock() throws 
UsecaseException {
+        org.apache.lenya.cms.repository.Node[] objects = { 
getSourceDocument().getRepositoryNode() };
+        return objects;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
+     */
+    protected void doCheckPreconditions() throws Exception {
+        super.doCheckPreconditions();
+        if (!WorkflowUtil.canInvoke(this.manager,
+                getSession(),
+                getLogger(),
+                getSourceDocument(),
+                getEvent())) {
+            addErrorMessage("error-workflow-document", new String[] { 
getEvent(),
+                    getSourceDocument().getId() });
+        }
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+     */
+    protected void doExecute() throws Exception {
+        super.doExecute();
+
+        // Get parameters                                                      
                                                                 
+        String rollbackTime = getParameterAsString("rollbackTime");
+            
+        // Do the rollback to an earlier version
+        long newtime = 0;
+        
+        Document document = getSourceDocument();
+        Publication publication = document.getPublication(); 
+        
+        // get Parameters for RC
+        String publicationPath = publication.getDirectory().getCanonicalPath();
+        RCEnvironment rcEnvironment = 
RCEnvironment.getInstance(publication.getServletContext()
+                .getCanonicalPath());
+        String rcmlDirectory = rcEnvironment.getRCMLDirectory();
+        rcmlDirectory = publicationPath + File.separator + rcmlDirectory;
+        String backupDirectory = rcEnvironment.getBackupDirectory();
+        backupDirectory = publicationPath + File.separator + backupDirectory;
+
+        // Initialize Revision Controller
+        RevisionController rc = new RevisionController(rcmlDirectory, 
backupDirectory, publicationPath);
+        getLogger().debug("revision controller" + rc);
+        
+        String filename = document.getFile().getCanonicalPath();
+        filename = filename.substring(publicationPath.length());
+
+        Map objectModel = ContextHelper.getObjectModel(getContext());
+        Request request = ObjectModelHelper.getRequest(objectModel);
+        Session session = request.getSession(false);
+        Identity identity = (Identity) 
session.getAttribute(Identity.class.getName());
+        User user = identity.getUser();
+        
+        try {
+            newtime = rc.rollback(filename, user.getId(), true, new 
Long(rollbackTime).longValue());
+            WorkflowUtil.invoke(this.manager,
+                getSession(),
+                getLogger(),
+                getSourceDocument(),
+                getEvent());
+        } catch (FileNotFoundException e) {
+            addErrorMessage("Unable to roll back!" + e);
+        } catch (Exception e) {
+            addErrorMessage("Unable to roll back!" + e);
+        }
+            
+        getLogger().debug("rollback complete, old (and now current) time was " 
+ rollbackTime +
+              " backup time is " + newtime);
+                
+    }
+
+    protected String getEvent() {
+        return "edit";
+    }
+
+}

Propchange: 
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Rollback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
URL: 
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl?rev=279858&r1=279857&r2=279858&view=diff
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl (original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl Fri Sep  9 12:42:10 2005
@@ -542,6 +542,11 @@
       <transaction policy="pessimistic"/>
       <view template="usecases/edit/kupu/kupu.jx" menu="false"/>
     </component-instance>
+    
+    <component-instance name="rollback" logger="lenya.publication"
+                        class="org.apache.lenya.cms.site.usecases.Rollback">
+      <transaction policy="pessimistic"/>
+    </component-instance>
   </usecases>
   
   <resource-types/>

Modified: lenya/trunk/src/webapp/lenya/usecase.xmap
URL: 
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecase.xmap?rev=279858&r1=279857&r2=279858&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecase.xmap (original)
+++ lenya/trunk/src/webapp/lenya/usecase.xmap Fri Sep  9 12:42:10 2005
@@ -210,29 +210,6 @@
         <!-- ********  /Xopus Editor ************************************** -->
         <!-- ************************************************************** -->
         
-        <!--Rollback-->
-        <map:match pattern="rollback" type="usecase">
-          
-          <map:match pattern="view" type="step">
-            <map:redirect-to session="true" 
uri="{page-envelope:context-prefix}/{../../1}/authoring/{../../3}?lenya.step=view-revision&amp;rollbackTime={request-param:rollbackTime}"/>
-          </map:match>
-          
-          <map:match pattern="rollback" type="step">
-            <map:act type="rollback">
-              <map:act type="workflow">
-                <map:parameter name="area" value="{page-envelope:area}"/>
-                <map:parameter name="document-id" 
value="{page-envelope:document-id}"/>
-                <map:parameter name="language" 
value="{page-envelope:document-language}"/>
-                <map:parameter name="event" value="edit"/>
-              </map:act>
-              <map:redirect-to session="true" uri="{location}"/>
-            </map:act>
-            <map:redirect-to session="true" uri="{request:requestURI}"/>
-          </map:match>
-          
-        </map:match>
-        
-        
         <!-- CheckOut -->
         <map:match pattern="checkout" type="usecase">
           

Modified: lenya/trunk/src/webapp/lenya/usecases/tab/revisions.jx
URL: 
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/tab/revisions.jx?rev=279858&r1=279857&r2=279858&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/tab/revisions.jx (original)
+++ lenya/trunk/src/webapp/lenya/usecases/tab/revisions.jx Fri Sep  9 12:42:10 
2005
@@ -39,7 +39,7 @@
       <jx:forEach var="item" items="${usecase.getParameter('entries')}" 
begin="1">
           <tr>
             <td>
-              <a 
href="?lenya.usecase=rollback&amp;lenya.step=rollback&amp;rollbackTime=${item.time}">
+              <a 
href="?lenya.usecase=rollback&amp;rollbackTime=${item.time}&amp;lenya.exitUsecase=tab.revisions">
                 <i18n:text>Rollback to this version</i18n:text>
               </a>
             </td>


<Prev in Thread] Current Thread [Next in Thread>