You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by un...@apache.org on 2012/06/23 18:29:42 UTC

svn commit: r1353157 - in /rave/sandbox/content-services/rave-jcr-config/src: main/java/org/apache/rave/jcr/bootstrapping/ test/java/org/apache/rave/jcr/bootstrapping/

Author: unico
Date: Sat Jun 23 16:29:41 2012
New Revision: 1353157

URL: http://svn.apache.org/viewvc?rev=1353157&view=rev
Log:
RAVE-603 add test case and fix bug for reload items registration

Modified:
    rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/Module.java
    rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleImporter.java
    rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleRegistry.java
    rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java

Modified: rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/Module.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/Module.java?rev=1353157&r1=1353156&r2=1353157&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/Module.java (original)
+++ rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/Module.java Sat Jun 23 16:29:41 2012
@@ -21,8 +21,11 @@ package org.apache.rave.jcr.bootstrappin
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.rave.jcr.importing.ImportBehavior;
 
@@ -94,10 +97,10 @@ public final class Module {
     private final String workspace;
 
     private List<String> dependencies;
-    private List<Namespace> namespaces;
-    private List<Cnd> cnds;
-    private List<Content> contents;
-    private List<Resource> resources;
+    private Map<String, Namespace> namespaces;
+    private Map<String, Cnd> cnds;
+    private Map<String, Content> contents;
+    private Map<String, Resource> resources;
 
     public Module(final String name, final String baseUrl, final String version, final String workspace) {
         this.name = name;
@@ -136,60 +139,68 @@ public final class Module {
         dependencies.add(dependency);
     }
 
-    public List<Namespace> getNamespaces() {
+    public Collection<Namespace> getNamespaces() {
         if (namespaces == null) {
             return Collections.emptyList();
         }
-        return namespaces;
+        return namespaces.values();
     }
 
     void addNamespace(String prefix, String uri, Status status) {
         if (namespaces == null) {
-            namespaces = new ArrayList<Namespace>();
+            namespaces = new LinkedHashMap<String, Namespace>();
         }
-        namespaces.add(new Namespace(prefix, uri, status));
+        namespaces.put(prefix, new Namespace(prefix, uri, status));
     }
 
     public List<Cnd> getCnds() {
         if (cnds == null) {
             return Collections.emptyList();
         }
-        return cnds;
+        return new ArrayList<Cnd>(cnds.values());
     }
 
     void addCnd(String name, String file, boolean reload, Status status, String version) {
         if (cnds == null) {
-            cnds = new ArrayList<Cnd>();
+            cnds = new LinkedHashMap<String, Cnd>();
         }
-        cnds.add(new Cnd(name, file, reload, status, version));
+        cnds.put(name, new Cnd(name, file, reload, status, version));
+    }
+
+    Cnd getCnd(String name) {
+        return cnds.get(name);
     }
 
     public List<Content> getContents() {
         if (contents == null) {
             return Collections.emptyList();
         }
-        return contents;
+        return new ArrayList<Content>(contents.values());
     }
 
     void addContent(String name, String file, String parent, boolean reload, String workspace, ImportBehavior importBehavior, Status status, String version) {
         if (contents == null) {
-            contents = new ArrayList<Content>();
+            contents = new LinkedHashMap<String, Content>();
         }
-        contents.add(new Content(name, file, parent, reload, workspace, importBehavior, status, version));
+        contents.put(name, new Content(name, file, parent, reload, workspace, importBehavior, status, version));
+    }
+
+    Content getContent(String name) {
+        return contents.get(name);
     }
 
-    public List<Resource> getResources() {
+    public Collection<Resource> getResources() {
         if (resources == null) {
             return Collections.emptyList();
         }
-        return resources;
+        return resources.values();
     }
 
     void addResource(String name, String path, String parent, String workspace, ImportBehavior importBehavior, Status status) {
         if (resources == null) {
-            resources = new ArrayList<Resource>();
+            resources = new LinkedHashMap<String, Resource>();
         }
-        resources.add(new Resource(name, path, parent, workspace, importBehavior, status));
+        resources.put(name, new Resource(name, path, parent, workspace, importBehavior, status));
     }
 
     @Override
@@ -237,7 +248,7 @@ public final class Module {
     public abstract class ReloadableItem extends Item {
 
         private final boolean reload;
-        private final String version;
+        private String version;
 
         private ReloadableItem(String name, Status status, boolean reload, String version) {
             super(name, status);
@@ -253,6 +264,9 @@ public final class Module {
             return version;
         }
 
+        void setVersion(String version) {
+            this.version = version;
+        }
     }
 
     public final class Namespace extends Item {

Modified: rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleImporter.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleImporter.java?rev=1353157&r1=1353156&r2=1353157&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleImporter.java (original)
+++ rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleImporter.java Sat Jun 23 16:29:41 2012
@@ -222,7 +222,7 @@ public final class ModuleImporter {
         final Session session = sessionProvider.getSession(null);
         for (Module.Cnd cnd : cnds) {
             final Module module = cnd.getModule();
-            final boolean reregister = cnd.getStatus() != Module.Status.PENDING;
+            final boolean reregister = cnd.getStatus() == Module.Status.RELOAD;
             log.info((reregister ? "Rer" : "R") + "egistering node types from " + cnd.getFile() + " in module " + module.getName());
             try {
                 CndImporter.registerNodeTypes(new InputStreamReader(cnd.getURL().openStream()), session, reregister);

Modified: rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleRegistry.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleRegistry.java?rev=1353157&r1=1353156&r2=1353157&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleRegistry.java (original)
+++ rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleRegistry.java Sat Jun 23 16:29:41 2012
@@ -118,7 +118,7 @@ public final class ModuleRegistry {
                 setDependencies(node, current);
             }
 
-            final Collection<Module.Namespace> addedNamespaces = getAdded(current.getNamespaces(), previous.getNamespaces());
+            final Collection<Module.Namespace> addedNamespaces = getAddedItems(current.getNamespaces(), previous.getNamespaces());
             if (!addedNamespaces.isEmpty()) {
                 final Node namespacesNode = JcrUtils.getOrCreateNode(node, NAMESPACES);
                 for (Module.Namespace namespace : addedNamespaces) {
@@ -129,7 +129,7 @@ public final class ModuleRegistry {
                 }
             }
 
-            final Collection<Module.Cnd> addedCnds = getAdded(current.getCnds(), previous.getCnds());
+            final Collection<Module.Cnd> addedCnds = getAddedItems(current.getCnds(), previous.getCnds());
             if (!addedCnds.isEmpty()) {
                 final Node cndsNode = JcrUtils.getOrCreateNode(node, CNDS);
                 for (Module.Cnd cnd : addedCnds) {
@@ -144,12 +144,13 @@ public final class ModuleRegistry {
                 final Node cndsNode = node.getNode(CNDS);
                 for (Module.Cnd cnd : reloadCnds) {
                     final Node cndNode = cndsNode.getNode(cnd.getName());
+                    setCndProperties(cndNode, cnd);
                     setStatusProperty(cndNode, Module.Status.RELOAD);
                     cnd.setStatus(Module.Status.RELOAD);
                 }
             }
 
-            final Collection<Module.Content> addedContents = getAdded(current.getContents(), previous.getContents());
+            final Collection<Module.Content> addedContents = getAddedItems(current.getContents(), previous.getContents());
             if (!addedContents.isEmpty()) {
                 final Node contentsNode = JcrUtils.getOrCreateNode(node, CONTENTS);
                 for (Module.Content content : addedContents) {
@@ -164,12 +165,13 @@ public final class ModuleRegistry {
                 final Node contentsNode = node.getNode(CONTENTS);
                 for (Module.Content content : reloadContents) {
                     final Node contentNode = contentsNode.getNode(content.getName());
+                    setContentProperties(contentNode, content);
                     setStatusProperty(contentNode, Module.Status.RELOAD);
                     content.setStatus(Module.Status.RELOAD);
                 }
             }
 
-            final Collection<Module.Resource> addedResources = getAdded(current.getResources(), previous.getResources());
+            final Collection<Module.Resource> addedResources = getAddedItems(current.getResources(), previous.getResources());
             if (!addedResources.isEmpty()) {
                 final Node resourcesNode = JcrUtils.getOrCreateNode(node, RESOURCES);
                 for (Module.Resource resource : addedResources) {
@@ -449,7 +451,7 @@ public final class ModuleRegistry {
                 if (previousItem != null) {
                     String currentVersion = currentItem.getVersion() != null ? currentItem.getVersion() : currentItem.getModule().getVersion();
                     String previousVersion = previousItem.getVersion() != null ? previousItem.getVersion() : previousItem.getModule().getVersion();
-                    if (currentVersion != null ? currentVersion.equals(previousVersion) : previousVersion != null) {
+                    if (currentVersion != null ? !currentVersion.equals(previousVersion) : previousVersion != null) {
                         reload.add(currentItem);
                     }
                 }
@@ -458,7 +460,7 @@ public final class ModuleRegistry {
         return reload;
     }
 
-    private <T extends Module.Item> Collection<T> getAdded(Collection<T> current, Collection<T> previous) {
+    private <T extends Module.Item> Collection<T> getAddedItems(Collection<T> current, Collection<T> previous) {
         Collection<T> added = new ArrayList<T>(current.size());
         for (T currentItem : current) {
             if (getItem(currentItem.getName(), previous) == null) {

Modified: rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java?rev=1353157&r1=1353156&r2=1353157&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java (original)
+++ rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java Sat Jun 23 16:29:41 2012
@@ -141,7 +141,7 @@ public class ModuleRegistryTest extends 
         assertFalse(session.nodeExists("/rave:system/modules/foo"));
     }
 
-    public void testUpdateModule() throws Exception {
+    public void testUpdateModuleAddItem() throws Exception {
         final ModuleRegistry moduleRegistry = new ModuleRegistry(session, "/rave:system");
         final ModuleScanner moduleScanner = new ModuleScanner("rave");
         Module module = moduleScanner.parse(getClass().getResource("/META-INF/rave/module.json"));
@@ -153,4 +153,16 @@ public class ModuleRegistryTest extends 
         module = moduleRegistry.readModule(module.getName());
         assertEquals(2, module.getNamespaces().size());
     }
+
+    public void testUpdateModuleReloadItem() throws Exception {
+        final ModuleRegistry moduleRegistry = new ModuleRegistry(session, "/rave:system");
+        final ModuleScanner moduleScanner = new ModuleScanner("rave");
+        Module module = moduleScanner.parse(getClass().getResource("/META-INF/rave/module.json"));
+        moduleRegistry.writeModule(module);
+
+        module.getContent("bar").setVersion("v3");
+        moduleRegistry.updateModule(module, moduleRegistry.readModule(module.getName()));
+
+        assertEquals(Module.Status.RELOAD, module.getContent("bar").getStatus());
+    }
 }