Author: sshyrkov
Date: Tue Sep 25 12:20:40 2007
New Revision: 18639

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18639&repname=
=3Djahia
Log:
DOC-215: SP3: Lock on files which are waiting for validation or validated c=
ould be removed if there was a prior lock on this file by an author =

http://www.jahia.net/jira/browse/DOC-215
Resolution:
1) pass also the user information to set the lock owner properly
2) added transactional templates for WebDAV operations

Added:
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/We=
bDAVCallback.java
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/We=
bDAVTemplate.java
Modified:
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/fields/Co=
ntentFileField.java

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/fie=
lds/ContentFileField.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/services/fields/ContentFileField.java&rev=
=3D18639&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/fields/Co=
ntentFileField.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/fields/Co=
ntentFileField.java Tue Sep 25 12:20:40 2007
@@ -24,6 +24,8 @@
 import org.jahia.services.version.*;
 import org.jahia.services.webdav.DAVFileAccess;
 import org.jahia.services.webdav.JahiaWebdavBaseService;
+import org.jahia.services.webdav.WebDAVCallback;
+import org.jahia.services.webdav.WebDAVTemplate;
 import org.jahia.utils.xml.XMLSerializationOptions;
 import org.jahia.utils.xml.XmlWriter;
 =

@@ -117,8 +119,8 @@
                                                    ProcessingContext jPara=
ms,
                                                    StateModificationContex=
t stateModifContext)
             throws JahiaException {
-        DAVFileAccess file =3D JahiaWebdavBaseService.getInstance ().getDA=
VFileAccess (ServicesRegistry.getInstance().getJahiaSitesService().getSite(=
getSiteID()),
-                this.getValue (fromEntryState));
+        DAVFileAccess file =3D JahiaWebdavBaseService.getInstance ().getDA=
VFileAccess (jParams, ServicesRegistry.getInstance().getJahiaSitesService()=
.getSite(getSiteID()),
+                jParams.getUser(), this.getValue (fromEntryState));
 =

         if (file.isValid () && file.hasRevisions ()) {
 //            String fieldPrefix =3D getID()+";";
@@ -140,7 +142,11 @@
 //                }
 //                if (list.length()=3D=3D0) {
                 if (usages.size () <=3D 1) {
-                    file.unlockFile (true);
+                    new WebDAVTemplate(file).transactionalCall(new WebDAVC=
allback(){
+                        public boolean doInWebDAV(DAVFileAccess file) {
+                            return file.unlockFile (true);
+                        }
+                    });
                 }
 //                }
 //                file.setProperty("http://www.jahia.org/";, "publishedfiel=
dsinuse", list, true);
@@ -150,8 +156,12 @@
 //                }
 //                if (list.length()=3D=3D0) {
                 if (usages.size () =3D=3D 0) {
-                    file.unlockFile (true);
-                    file.lockFile (true);
+                    new WebDAVTemplate(file).transactionalCall(new WebDAVC=
allback(){
+                        public boolean doInWebDAV(DAVFileAccess file) {
+                            file.unlockFile (true);
+                            return file.lockFile (true);
+                        }
+                    });
                 }
 //                }
 //                if (!list.startsWith(fieldPrefix) && list.indexOf(";"+fi=
eldPrefix)=3D=3D-1) {
@@ -242,18 +252,6 @@
                                           ProcessingContext processingCont=
ext) throws java.io.IOException {
 =

         try {
-            int fileID =3D -1;
-            try {
-                fileID =3D Integer.parseInt (getDBValue (entryState));
-            } catch (Throwable t) {
-                // this can fail if we are using a default value or if we
-                // have a reference to a WebDAV file field
-            }
-
-            JahiaFileField fileField =3D JahiaWebdavBaseService.getInstanc=
e ().getJahiaFileField (
-                    processingContext, (processingContext!=3Dnull)?process=
ingContext.getSite():null, (processingContext!=3Dnull)?processingContext.ge=
tUser():null, getDBValue (entryState));
-            // JahiaFileField fileField =3D JahiaFileFieldsManager.getInst=
ance().getJahiaFileField(fileID);
-
             if (xmlSerializationOptions.isEmbeddingBinary ()) {
             } else {
                 // let's only build a reference to the file's content, usi=
ng an
@@ -278,34 +276,6 @@
         }
     }
 =

-    /**
-     * Method copyStream<br>
-     *
-     * @param ins        An InputStream.
-     * @param outs       An OutputStream.
-     * @param bufferSize an integer specifying the buffer size to use to s=
peed
-     *                   up operations.
-     *
-     * @throws IOException.
-     */
-    private void copyStream (InputStream ins,
-                             OutputStream outs, int bufferSize)
-            throws IOException {
-        byte[] m_WriteBuffer =3D new byte[bufferSize];
-        BufferedInputStream bis =3D
-                new BufferedInputStream (ins, bufferSize);
-        BufferedOutputStream bos =3D
-                new BufferedOutputStream (outs, bufferSize);
-        int bufread;
-        while ((bufread =3D bis.read (m_WriteBuffer)) !=3D -1) {
-            bos.write (m_WriteBuffer, 0, bufread);
-        }
-        bos.flush ();
-        bos.close ();
-        bis.close ();
-        //outs.close();
-    }
-
     protected void purgeContent ()
             throws JahiaException {
         /** @todo FIXME : to be implemented. */

Added: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav=
/WebDAVCallback.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/WebDAVCallback.java&=
rev=3D18639&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/We=
bDAVCallback.java (added)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/We=
bDAVCallback.java Tue Sep 25 12:20:40 2007
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2002-2007 Jahia Ltd
+ *
+ * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL), =

+ * Version 1.0 (the "License"), or (at your option) any later version; you=
 may =

+ * not use this file except in compliance with the License. You should hav=
e =

+ * received a copy of the License along with this program; if not, you may=
 obtain =

+ * a copy of the License at =

+ *
+ *  http://www.jahia.org/license/
+ *
+ * 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.jahia.services.webdav;
+
+/**
+ * Action callback for performing WebDAV operations.
+ * =

+ * @author Sergiy Shyrkov
+ */
+public interface WebDAVCallback {
+
+    /**
+     * This action will be executed by [EMAIL PROTECTED] WebDAVTemplate} in 
order to =
add
+     * additional functionality, like transaction support.
+     * =

+     * @param file
+     *            the WebDAV resource to perform the action on
+     * @return <code>true</code> if the action was successfull and the com=
mit
+     *         should be made; <code>false</code> - to perform rollback
+     */
+    boolean doInWebDAV(DAVFileAccess file);
+
+}

Added: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav=
/WebDAVTemplate.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/WebDAVTemplate.java&=
rev=3D18639&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/We=
bDAVTemplate.java (added)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/webdav/We=
bDAVTemplate.java Tue Sep 25 12:20:40 2007
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2002-2007 Jahia Ltd
+ *
+ * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL), =

+ * Version 1.0 (the "License"), or (at your option) any later version; you=
 may =

+ * not use this file except in compliance with the License. You should hav=
e =

+ * received a copy of the License along with this program; if not, you may=
 obtain =

+ * a copy of the License at =

+ *
+ *  http://www.jahia.org/license/
+ *
+ * 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.jahia.services.webdav;
+
+import javax.transaction.Status;
+
+/**
+ * Adds support for transactional operation on the WebDAV resources.
+ * =

+ * @author Sergiy Shyrkov
+ */
+public class WebDAVTemplate {
+
+    private DAVFileAccess davFile;
+
+    /**
+     * Initializes an instance of this class.
+     * =

+     * @param davFile
+     *            the WebDAV file to perform actions
+     */
+    public WebDAVTemplate(DAVFileAccess davFile) {
+        super();
+        this.davFile =3D davFile;
+    }
+
+    /**
+     * Executes the specified action within the transaction scope.
+     * =

+     * @param action
+     *            an action to be performed on the WebDAV resource
+     */
+    public void transactionalCall(WebDAVCallback action) {
+        boolean transactionOpenedHere =3D davFile.beginTransaction();
+        try {
+            boolean ok =3D action.doInWebDAV(davFile);
+            if (ok && transactionOpenedHere) {
+                davFile.commitTransaction();
+            }
+        } finally {
+            if (transactionOpenedHere
+                    && davFile.getTransactionStatus() =3D=3D Status.STATUS=
_ACTIVE) {
+                davFile.rollbackTransaction();
+            }
+        }
+    }
+}

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to