jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1782901 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/fs/impl/io/ test/java/org/apache/jackrabbit/vault/packaging/integration/ test/resources/org/apache/jackrabbit/vault/packaging/integratio...
Date Tue, 14 Feb 2017 01:57:01 GMT
Author: tripod
Date: Tue Feb 14 01:57:00 2017
New Revision: 1782901

URL: http://svn.apache.org/viewvc?rev=1782901&view=rev
Log:
JCRVLT-157 Package import does not handle "Atomic Counter"

Added:
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestAtomicCounter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/atomic-counter-test.zip
Modified:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java?rev=1782901&r1=1782900&r2=1782901&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
Tue Feb 14 01:57:00 2017
@@ -125,6 +125,7 @@ public class DocViewSAXImporter extends
         props.add(JcrConstants.JCR_PREDECESSORS);
         props.add(JcrConstants.JCR_SUCCESSORS);
         props.add(JcrConstants.JCR_VERSIONHISTORY);
+        props.add("oak:counter");
         PROTECTED_PROPERTIES = Collections.unmodifiableSet(props);
     }
 
@@ -760,7 +761,7 @@ public class DocViewSAXImporter extends
         // find old node
         Node oldNode = null;
         Node node = null;
-        if (ni.label.equals("")) {
+        if ("".equals(ni.label)) {
             // special case for root node update
             node = currentNode;
         } else if (ni.uuid == null) {
@@ -886,12 +887,17 @@ public class DocViewSAXImporter extends
 
             // adjust mixins
             Set<String> newMixins = new HashSet<String>();
+            boolean isAtomicCounter = false;
             if (ni.mixins != null) {
                 for (String mixin : ni.mixins) {
                     // omit name if mix:AccessControllable and CLEAR
                     if (!aclManagement.isAccessControllableMixin(mixin)
                             || aclHandling != AccessControlHandling.CLEAR) {
                         newMixins.add(mixin);
+
+                        if ("mix:atomicCounter".equals(mixin)) {
+                            isAtomicCounter = true;
+                        }
                     }
                 }
             }
@@ -950,6 +956,22 @@ public class DocViewSAXImporter extends
                     }
                 }
             }
+            // adjust oak atomic counter
+            if (isAtomicCounter) {
+                long previous = 0;
+                if (node.hasProperty("oak:counter")) {
+                    previous = node.getProperty("oak:counter").getLong();
+                }
+                long counter = 0;
+                try {
+                    counter = Long.valueOf(ni.getValue("oak:counter"));
+                } catch (NumberFormatException e) {
+                    // ignore
+                }
+                node.setProperty("oak:increment", counter - previous);
+                modified = true;
+            }
+
             if (modified) {
                 if (node.isNodeType(JcrConstants.NT_RESOURCE)) {
                     if (!node.hasProperty(JcrConstants.JCR_DATA)) {
@@ -1057,6 +1079,7 @@ public class DocViewSAXImporter extends
                     throw e;
                 }
             }
+
             // handle non protected properties
             for (DocViewProperty p : ni.props.values()) {
                 if (p != null && p.values != null) {
@@ -1069,6 +1092,20 @@ public class DocViewSAXImporter extends
                     }
                 }
             }
+
+            // check for atomic counter
+            if (ni.mixins != null) {
+                for (String mixin : ni.mixins) {
+                    if ("mix:atomicCounter".equals(mixin)) {
+                        String counter = ni.getValue("oak:counter");
+                        if (counter != null) {
+                            node.setProperty("oak:increment", counter, PropertyType.LONG);
+                        }
+                        break;
+                    }
+                }
+            }
+
             // remove mix referenceable if it was temporarily added
             if (addMixRef) {
                 node.removeMixin(JcrConstants.MIX_REFERENCEABLE);

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java?rev=1782901&r1=1782900&r2=1782901&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java
Tue Feb 14 01:57:00 2017
@@ -163,6 +163,7 @@ public class IntegrationTestBase  {
 
             repository = jcr
                     .with(new SecurityProviderImpl(ConfigurationParameters.of(securityProps)))
+                    .withAtomicCounter()
                     .createRepository();
 
             // setup default read ACL for everyone

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestAtomicCounter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestAtomicCounter.java?rev=1782901&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestAtomicCounter.java
(added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestAtomicCounter.java
Tue Feb 14 01:57:00 2017
@@ -0,0 +1,99 @@
+/*
+ * 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.jackrabbit.vault.packaging.integration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.core.security.principal.PrincipalImpl;
+import org.apache.jackrabbit.vault.fs.api.ImportMode;
+import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf;
+import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.io.AccessControlHandling;
+import org.apache.jackrabbit.vault.fs.io.ImportOptions;
+import org.apache.jackrabbit.vault.packaging.ExportOptions;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.apache.jackrabbit.vault.packaging.VaultPackage;
+import org.apache.jackrabbit.vault.util.Text;
+import org.junit.Assume;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * {@code TestEmptyPackage}...
+ */
+public class TestAtomicCounter extends IntegrationTestBase {
+
+    /**
+     * Tests if installing a package with a mix:atomicCounter works
+     */
+    @Test
+    public void installAtomicCounter() throws RepositoryException, IOException, PackageException
{
+        Assume.assumeTrue(isOak());
+
+        JcrPackage pack = packMgr.upload(getStream("testpackages/atomic-counter-test.zip"),
false);
+        assertNotNull(pack);
+        ImportOptions opts = getDefaultOptions();
+        pack.install(opts);
+
+        assertProperty("/tmp/testroot/oak:counter", "42");
+    }
+
+    /**
+     * Tests if installing a package with a mix:atomicCounter works (update)
+     */
+    @Test
+    public void updateAtomicCounter() throws RepositoryException, IOException, PackageException
{
+        Assume.assumeTrue(isOak());
+
+        Node tmp = JcrUtils.getOrAddNode(admin.getRootNode(), "tmp", NodeType.NT_UNSTRUCTURED);
+        Node testroot = JcrUtils.getOrAddNode(tmp, "testroot", NodeType.NT_UNSTRUCTURED);
+        testroot.addMixin("mix:atomicCounter");
+        testroot.setProperty("oak:increment", 5);
+        admin.save();
+        assertEquals(5L, testroot.getProperty("oak:counter").getLong());
+
+        JcrPackage pack = packMgr.upload(getStream("testpackages/atomic-counter-test.zip"),
false);
+        assertNotNull(pack);
+        ImportOptions opts = getDefaultOptions();
+        pack.install(opts);
+
+        assertProperty("/tmp/testroot/oak:counter", "42");
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/atomic-counter-test.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/atomic-counter-test.zip?rev=1782901&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/atomic-counter-test.zip
(added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/atomic-counter-test.zip
Tue Feb 14 01:57:00 2017 differ



Mime
View raw message