svn commit: r564527 - in /lenya/trunk/src: java/org/apache/lenya/cms/rc/ java/org/apache/lenya/cms/repository/ modules-core/sitemanagement/config/cocoon-xconf/site/ modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ modules-core/s...

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Fri Aug 10 02:27:41 2007
New Revision: 564527

URL: http://svn.apache.org/viewvc?view=rev&rev=564527
Log:
Added usecase to force the check-in of documents.

Added:
    lenya/trunk/src/modules-core/sitemanagement/config/cocoon-xconf/site/usecase-site-forceCheckIn.xconf
    lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ForceCheckIn.java
    lenya/trunk/src/modules-core/sitemanagement/usecases/site/forceCheckIn.jx
Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/rc/RCML.java
    lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java
    lenya/trunk/src/modules-core/sitemanagement/resources/i18n/cmsui.xml
    lenya/trunk/src/modules-core/sitemanagement/resources/i18n/cmsui_de.xml
    lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
    lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java
    lenya/trunk/src/pubs/default/config/access-control/usecase-policies.xml
    lenya/trunk/src/pubs/default/config/menus/generic.xsp

Modified: lenya/trunk/src/java/org/apache/lenya/cms/rc/RCML.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/rc/RCML.java?view=diff&rev=564527&r1=564526&r2=564527
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/rc/RCML.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/rc/RCML.java Fri Aug 10 02:27:41 2007
@@ -170,4 +170,5 @@
      * @throws RevisionControlException if an error occurs.
      */
     boolean isCheckedOutBySession(Session session) throws RevisionControlException;
+
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java?view=diff&rev=564527&r1=564526&r2=564527
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java Fri Aug 10 02:27:41 2007
@@ -26,7 +26,7 @@
  * @version $Id$
  */
 public interface Node extends RepositoryItem, ContentHolder {
-    
+
     /**
      * @return The session this node belongs to.
      */
@@ -65,7 +65,7 @@
      * @throws RepositoryException if the node does not exist.
      */
     OutputStream getOutputStream() throws RepositoryException;
-    
+
     /**
      * Locks the node.
      * @throws RepositoryException if an error occurs.
@@ -80,17 +80,24 @@
 
     /**
      * Checks out the node.
-     * @throws RepositoryException if an error occurs. 
+     * @throws RepositoryException if an error occurs.
      */
     void checkout() throws RepositoryException;
 
     /**
      * Checks in the node.
-     * @throws RepositoryException if an error occurs. 
+     * @throws RepositoryException if the node is not checked out or is checked
+     *         out by a different session.
      */
     void checkin() throws RepositoryException;
 
     /**
+     * Checks in the node even if it is checked out by a different session.
+     * @throws RepositoryException if the node is not checked out.
+     */
+    void forceCheckIn() throws RepositoryException;
+
+    /**
      * Registers the node as dirty.
      * @throws RepositoryException if an error occurs.
      */
@@ -103,7 +110,7 @@
     boolean isCheckedOut() throws RepositoryException;
 
     /**
-     * @return The ID of the user who has checked out this node. 
+     * @return The ID of the user who has checked out this node.
      * @throws RepositoryException if the node is not checked out.
      */
     String getCheckoutUserId() throws RepositoryException;
@@ -113,13 +120,13 @@
      * @throws RepositoryException if an error occurs.
      */
     boolean isCheckedOutBySession() throws RepositoryException;
-    
+
     /**
      * @param source The node to copy the revisions from.
      * @throws RepositoryException if an error occurs.
      */
     void copyRevisionsFrom(Node source) throws RepositoryException;
-    
+
     /**
      * @param revisionNumber The revision number to roll back.
      * @throws RepositoryException if this revision doesn't exist.
@@ -137,7 +144,7 @@
      * @throws RepositoryException if an error occurs.
      */
     void registerRemoved() throws RepositoryException;
-    
+
     /**
      * @return The revision history.
      */
@@ -148,5 +155,5 @@
      * @throws RepositoryException if an error occurs.
      */
     void delete() throws RepositoryException;
-    
+
 }

Added: lenya/trunk/src/modules-core/sitemanagement/config/cocoon-xconf/site/usecase-site-forceCheckIn.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/config/cocoon-xconf/site/usecase-site-forceCheckIn.xconf?view=auto&rev=564527
==============================================================================
--- lenya/trunk/src/modules-core/sitemanagement/config/cocoon-xconf/site/usecase-site-forceCheckIn.xconf (added)
+++ lenya/trunk/src/modules-core/sitemanagement/config/cocoon-xconf/site/usecase-site-forceCheckIn.xconf Fri Aug 10 02:27:41 2007
@@ -0,0 +1,29 @@
+<?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: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+<!--
+    This file defines the publication specific use-cases
+-->
+
+<xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'sitemanagement.forceCheckIn']">
+  <component-instance name="sitemanagement.forceCheckIn" logger="lenya.site"
+    class="org.apache.lenya.cms.site.usecases.ForceCheckIn">
+    <view template="modules/sitemanagement/usecases/site/forceCheckIn.jx"/>
+  </component-instance>
+</xconf>

Added: lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ForceCheckIn.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ForceCheckIn.java?view=auto&rev=564527
==============================================================================
--- lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ForceCheckIn.java (added)
+++ lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ForceCheckIn.java Fri Aug 10 02:27:41 2007
@@ -0,0 +1,112 @@
+/*
+ * 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.cms.site.usecases;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Vector;
+import java.util.WeakHashMap;
+
+import javax.servlet.http.HttpSession;
+
+import org.apache.lenya.ac.Identity;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.cms.metadata.dublincore.DublinCoreHelper;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.util.SessionListener;
+
+/**
+ * Force a document to be checked in (override a checkout).
+ */
+public class ForceCheckIn extends DocumentUsecase {
+
+    private static final String IDENTITY = Identity.class.getName();
+    private static final String HISTORY = "org.apache.lenya.cms.cocoon.acting.History";
+
+    protected void doCheckPreconditions() throws Exception {
+        super.doCheckPreconditions();
+
+        Document doc = getSourceDocument();
+
+        Node node = doc.getRepositoryNode();
+        if (!node.isCheckedOut()) {
+            String[] params = { DublinCoreHelper.getTitle(doc) };
+            addErrorMessage("not-checked-out", params);
+        }
+
+        else {
+            String userId = node.getCheckoutUserId();
+            String[] params = { userId };
+            if (isLoggedIn(userId)) {
+                addInfoMessage("user-logged-in", params);
+            }
+            else {
+                addInfoMessage("user-not-logged-in", params);
+            }
+        }
+    }
+
+    protected boolean isLoggedIn(String userId) {
+        String pubId = getSourceDocument().getPublication().getId();
+        SessionListener sessions = new SessionListener();
+        WeakHashMap allSessions = sessions.getAllSessions();
+        
+        boolean loggedIn = false;
+        Iterator userit = allSessions.entrySet().iterator();
+        while (userit.hasNext()) {
+            Map.Entry entry = (Map.Entry) userit.next();
+            HttpSession nextsession = (HttpSession) entry.getValue();
+
+            Identity identity = (Identity) nextsession.getAttribute(IDENTITY);
+
+            User user = identity.getUser();
+            Vector history = (Vector) nextsession.getAttribute(HISTORY);
+            String publicationID = getPublicationIDfromHistory(history);
+            if (publicationID.equals(pubId) && user != null && user.getId().equals(userId)) {
+                loggedIn = true;
+            }
+        }
+        return loggedIn;
+    }
+
+    protected void doExecute() throws Exception {
+        super.doExecute();
+
+        Document doc = getSourceDocument();
+        Node node = doc.getRepositoryNode();
+
+        node.forceCheckIn();
+    }
+
+    /**
+     * Extract the publicationID from the history information stored in the
+     * session
+     * 
+     * @param history The history stored in the session.. An entry looks like \/
+     *        <publication-id>/authoring/index.html
+     * @return A publication ID.
+     */
+    private String getPublicationIDfromHistory(Vector history) {
+        String firstElement = history.firstElement().toString();
+        String publicationID = firstElement.substring(1, firstElement.indexOf("/", 1));
+        return publicationID;
+    }
+
+}

Modified: lenya/trunk/src/modules-core/sitemanagement/resources/i18n/cmsui.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/resources/i18n/cmsui.xml?view=diff&rev=564527&r1=564526&r2=564527
==============================================================================
--- lenya/trunk/src/modules-core/sitemanagement/resources/i18n/cmsui.xml (original)
+++ lenya/trunk/src/modules-core/sitemanagement/resources/i18n/cmsui.xml Fri Aug 10 02:27:41 2007
@@ -69,5 +69,12 @@
   <message key="no-rollback-in-review">Rollback disabled. Document is in
   review state.</message>
   <message key="no-rollback-no-privileges">Rollback disabled. You do not
-  have sufficient privileges.</message>
+  have sufficient privileges.</message>
+  
+  <!-- force check-in -->
+  <message key="force-checkin">Force Check-In</message>
+  <message key="force-checkin-question">Do you really want to check-in the document '{0}'?</message>
+  <message key="user-logged-in">The user '{0}' is still logged in.</message>
+  <message key="user-not-logged-in">The user '{0}' is not logged in anymore.</message>
+  <message key="not-checked-out">The document '{0}' is not checked out.</message>
 </catalogue>

Modified: lenya/trunk/src/modules-core/sitemanagement/resources/i18n/cmsui_de.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/resources/i18n/cmsui_de.xml?view=diff&rev=564527&r1=564526&r2=564527
==============================================================================
--- lenya/trunk/src/modules-core/sitemanagement/resources/i18n/cmsui_de.xml (original)
+++ lenya/trunk/src/modules-core/sitemanagement/resources/i18n/cmsui_de.xml Fri Aug 10 02:27:41 2007
@@ -70,5 +70,11 @@
   keine Wiederherstellung möglich.</message>
   <message key="no-rollback-no-privileges">Keine ausreichenden Rechte zum Wiederherstellen.</message>
                    
+  <!-- force check-in -->
+  <message key="force-checkin">Check-In erzwingen</message>
+  <message key="force-checkin-question">Wollen Sie das Dokument "{0}" wirklich einchecken?</message>
+  <message key="user-logged-in">Der Nutzer "{0}" ist noch eingeloggt.</message>
+  <message key="user-not-logged-in">Der Nutzer "{0}" ist nicht mehr eingeloggt.</message>
+  <message key="not-checked-out">Das Dokument "{0}" ist nicht ausgecheckt.</message>
 </catalogue>
 

Added: lenya/trunk/src/modules-core/sitemanagement/usecases/site/forceCheckIn.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/usecases/site/forceCheckIn.jx?view=auto&rev=564527
==============================================================================
--- lenya/trunk/src/modules-core/sitemanagement/usecases/site/forceCheckIn.jx (added)
+++ lenya/trunk/src/modules-core/sitemanagement/usecases/site/forceCheckIn.jx Fri Aug 10 02:27:41 2007
@@ -0,0 +1,51 @@
+<?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: delete.jx 499060 2007-01-23 15:50:56Z andreas $ -->
+
+<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" >
+  
+  <page:title><i18n:text>force-checkin</i18n:text></page:title>
+  <page:body>
+    <p>
+      <i18n:translate>
+        <i18n:text key="force-checkin-question"/>
+        <jx:set var="document" value="${usecase.getParameter('document')}"/>
+        <i18n:param><jx:out value="${document.getMetaData('http://purl.org/dc/elements/1.1/').getFirstValue('title')}"/></i18n:param>
+      </i18n:translate>
+    </p>
+    
+    <jx:import uri="fallback://lenya/modules/usecase/templates/messages.jx"/>
+    
+    <form method="get" action="" id="form-force_checkin">
+      <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+      <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
+      
+      <p>
+        <jx:if test="${!usecase.hasErrors()}">
+          <input i18n:attr="value" type="submit" name="submit" value="Submit"/>
+          &#160;
+        </jx:if>
+        <input i18n:attr="value" type="submit" name="cancel" value="Cancel"/>
+      </p>
+    </form>
+  </page:body>
+</page:page>
\ No newline at end of file

Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java?view=diff&rev=564527&r1=564526&r2=564527
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java Fri Aug 10 02:27:41 2007
@@ -105,12 +105,27 @@
         RCML rcml = getRcml();
         synchronized (rcml) {
             try {
-                if (!rcml.isCheckedOut()) {
+                if (!rcml.isCheckedOutBySession(getSession())) {
                     throw new RepositoryException("Cannot check in node [" + getSourceURI()
-                            + "]: not checked out!");
+                            + "]: not checked out by this session!");
                 }
                 boolean newVersion = getSession().isDirty(this);
                 rcml.checkIn(this, exists(), newVersion);
+            } catch (Exception e) {
+                throw new RepositoryException(e);
+            }
+        }
+    }
+    
+    public void forceCheckIn() throws RepositoryException {
+        RCML rcml = getRcml();
+        synchronized (rcml) {
+            try {
+                if (!rcml.isCheckedOut()) {
+                    throw new RepositoryException("Cannot check in node [" + getSourceURI()
+                            + "]: not checked out!");
+                }
+                rcml.checkIn(this, false, false);
             } catch (Exception e) {
                 throw new RepositoryException(e);
             }

Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java?view=diff&rev=564527&r1=564526&r2=564527
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java Fri Aug 10 02:27:41 2007
@@ -584,7 +584,6 @@
 
     public synchronized void checkIn(Node node, boolean backup, boolean newVersion)
             throws RevisionControlException {
-
         long time = new Date().getTime();
 
         if (backup) {
@@ -608,7 +607,8 @@
         Vector entries = getEntries();
         if (entries.size() > 0) {
             RCMLEntry entry = (RCMLEntry) entries.get(0);
-            return entry.getType() == co && entry.getSessionId().equals(session.getId());
+            String otherSessionId = entry.getSessionId();
+            return entry.getType() == co && otherSessionId.equals(session.getId());
         }
         return false;
     }

Modified: lenya/trunk/src/pubs/default/config/access-control/usecase-policies.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/config/access-control/usecase-policies.xml?view=diff&rev=564527&r1=564526&r2=564527
==============================================================================
--- lenya/trunk/src/pubs/default/config/access-control/usecase-policies.xml (original)
+++ lenya/trunk/src/pubs/default/config/access-control/usecase-policies.xml Fri Aug 10 02:27:41 2007
@@ -114,6 +114,10 @@
     <role id="admin" method="grant"/>
     <role id="edit" method="grant"/>
   </usecase>  
+  <usecase id="sitemanagement.forceCheckIn">
+    <role id="admin" method="grant"/>
+    <role id="edit" method="grant"/>
+  </usecase>  
   <usecase id="tab.acArchive">
     <role id="admin" method="grant"/>
     <role id="edit" method="grant"/>

Modified: lenya/trunk/src/pubs/default/config/menus/generic.xsp
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/config/menus/generic.xsp?view=diff&rev=564527&r1=564526&r2=564527
==============================================================================
--- lenya/trunk/src/pubs/default/config/menus/generic.xsp (original)
+++ lenya/trunk/src/pubs/default/config/menus/generic.xsp Fri Aug 10 02:27:41 2007
@@ -70,6 +70,9 @@
           <item uc:usecase="sitemanagement.createLanguage" href="?"><i18n:text>New Language Version</i18n:text></item>
           <item uc:usecase="sitemanagement.deleteLanguage" href="?"><i18n:text>Remove Language Version</i18n:text></item>
         </block>
+        <block area="authoring">
+          <item uc:usecase="sitemanagement.forceCheckIn" href="?"><i18n:text>force-checkin</i18n:text></item>
+        </block>
         <block areas="authoring site admin">
           <item uc:usecase="admin.changePassword" href="?"><i18n:text>Change Password</i18n:text></item>
           <item uc:usecase="ac.logout" href="?"><i18n:text>Logout</i18n:text></item>
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.