You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by tk...@apache.org on 2013/05/16 12:31:33 UTC

[03/14] git commit: MARMOTTA-233: extends module configuration

MARMOTTA-233: extends module configuration


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/80345190
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/80345190
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/80345190

Branch: refs/heads/MARMOTTA-228
Commit: 8034519030d8568bec53e31ff7caf888affb6748
Parents: 924630e
Author: tkurz <tk...@apache.org>
Authored: Mon May 6 12:34:03 2013 +0200
Committer: tkurz <tk...@apache.org>
Committed: Mon May 6 12:34:03 2013 +0200

----------------------------------------------------------------------
 .../platform/core/api/modules/ModuleService.java   |   24 ++++
 .../platform/core/services/modules/AdminPage.java  |  101 ++++++++++++++
 .../core/services/modules/AdminPageContainer.java  |   56 ++++++++
 .../core/services/modules/ModuleServiceImpl.java   |  106 ++++++++++++++-
 .../src/main/resources/config-defaults.properties  |    6 +
 .../main/resources/config-descriptions.properties  |    6 +
 .../src/main/resources/kiwi-module.properties      |   44 +++++--
 .../src/main/resources/templates/admin.ftl         |    2 +-
 8 files changed, 327 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/80345190/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/modules/ModuleService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/modules/ModuleService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/modules/ModuleService.java
index 0739abe..b099921 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/modules/ModuleService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/modules/ModuleService.java
@@ -17,7 +17,10 @@
  */
 package org.apache.marmotta.platform.core.api.modules;
 
+import org.apache.commons.configuration.Configuration;
 import org.apache.marmotta.platform.core.model.module.ModuleConfiguration;
+import org.apache.marmotta.platform.core.services.modules.AdminPage;
+import org.apache.marmotta.platform.core.services.modules.AdminPageContainer;
 
 import javax.enterprise.inject.spi.InjectionPoint;
 import java.net.URL;
@@ -111,6 +114,7 @@ public interface ModuleService {
      * @param moduleName
      * @return
      */
+    @Deprecated
     public List<String> getAdminPages(String moduleName);
 
     /**
@@ -129,4 +133,24 @@ public interface ModuleService {
      */
     public int getWeight(String moduleName);
 
+    /**
+     * returns the icon (if set), null otherwise
+     * @param moduleName
+     * @return
+     */
+    public String getIcon(String moduleName);
+
+    /**
+     * Returns a list of AdminPage Objects
+     * @param moduleName
+     * @return
+     */
+    public List<AdminPage> getAdminPageList(String moduleName);
+
+    /**
+     * Lists containers and underlying modules
+     * @return
+     */
+    public List<AdminPageContainer> listContainers();
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/80345190/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/AdminPage.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/AdminPage.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/AdminPage.java
new file mode 100644
index 0000000..4ab3295
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/AdminPage.java
@@ -0,0 +1,101 @@
+/*
+ * 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.marmotta.platform.core.services.modules;
+
+import org.apache.marmotta.platform.core.exception.MarmottaException;
+import org.apache.marmotta.platform.core.exception.TemplatingException;
+
+import java.util.List;
+
+/**
+ * This class is used for more complex AdminPage information (e.g. for Templating).
+ * <p/>
+ * Author: Thomas Kurz (tkurz@apache.org)
+ */
+public class AdminPage implements Comparable<AdminPage> {
+
+    private String name;
+    private String path;
+    private boolean important = false;
+    private int number = 0;
+
+    /**
+     * create AdminPage object
+     * @param number for sorting
+     * @param path path to page
+     * @param name name (e.g. in the menu display)
+     * @param important if true, the page can appear in a 'special link' section
+     * @throws MarmottaException
+     */
+    AdminPage(int number, String path, String name, boolean important) throws MarmottaException {
+        if(path==null) throw new MarmottaException("path for admin page must be defined");
+        this.path = path;
+
+        if(name != null) this.name = name;
+        else this.name = getNameFromPath(path);
+
+        this.important = important;
+    }
+
+    /**
+     * Creates and AdminPage just from path
+     * @param path
+     */
+    AdminPage(String path) {
+        this.path= path;
+        this.name = getNameFromPath(path);
+    }
+
+    /**
+     * returns a 'useful' name from path
+     * @param path
+     * @return
+     */
+    private String getNameFromPath(String path) {
+        return path.substring(path.lastIndexOf("/")).replaceAll("/"," ").replaceAll("_"," ").replaceAll(".html","").replaceAll(".jsp","");
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    /**
+     * if numbers are used, the sorting is based on numbers, otherwise on alphabetical order of names
+     * @param adminPage
+     * @return
+     */
+    @Override
+    public int compareTo(AdminPage adminPage) {
+        if(number != adminPage.number) {
+            return name.compareTo(adminPage.name);
+        } else return ((Integer)number).compareTo(adminPage.number);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/80345190/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/AdminPageContainer.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/AdminPageContainer.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/AdminPageContainer.java
new file mode 100644
index 0000000..438707b
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/AdminPageContainer.java
@@ -0,0 +1,56 @@
+/*
+ * 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.marmotta.platform.core.services.modules;
+
+import java.util.List;
+
+/**
+ * ...
+ * <p/>
+ * Author: Thomas Kurz (tkurz@apache.org)
+ */
+public class AdminPageContainer implements Comparable<AdminPageContainer> {
+
+    private int number = 0;
+    private String name;
+    private List<String> modules;
+
+    public AdminPageContainer(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public int compareTo(AdminPageContainer adminPageContainer) {
+        if(number != adminPageContainer.number) return ((Integer)number).compareTo(adminPageContainer.number);
+        return name.compareTo(adminPageContainer.name);
+    }
+
+    public boolean equals(String s) {
+        return name.equals(s);
+    }
+
+    public void addModule(String module) {
+        modules.add(module);
+    }
+
+    public void setNumber(int number) {
+        this.number = number;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/80345190/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/ModuleServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/ModuleServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/ModuleServiceImpl.java
index b7e4d63..9dbfca9 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/ModuleServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/ModuleServiceImpl.java
@@ -18,7 +18,9 @@
 package org.apache.marmotta.platform.core.services.modules;
 
 import com.google.common.collect.ImmutableList;
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
 import org.apache.marmotta.platform.core.api.modules.ModuleService;
+import org.apache.marmotta.platform.core.exception.MarmottaException;
 import org.apache.marmotta.platform.core.model.module.ModuleConfiguration;
 import org.apache.commons.configuration.CompositeConfiguration;
 import org.apache.commons.configuration.Configuration;
@@ -32,18 +34,13 @@ import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
 import java.io.IOException;
 import java.net.JarURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * Add file description here!
@@ -53,16 +50,29 @@ import java.util.Set;
 @ApplicationScoped
 public class ModuleServiceImpl implements ModuleService {
 
+    private String default_container_name = "Others";
+    private int default_container_number = 100;
+
     private Logger log = LoggerFactory.getLogger(ModuleServiceImpl.class);
 
     private Set<String> modules;
 
+    private List<AdminPageContainer> containers;
+
     private Map<String,Configuration> configurationMap;
     private Map<String, Configuration> jarURLs;
 
+    @Inject
+    ConfigurationService configurationService;
+
     @PostConstruct
     public void initialize() {
+
+        default_container_name = configurationService.getStringConfiguration("kiwi.pages.default_container.name",default_container_name);
+        default_container_number = configurationService.getIntConfiguration("kiwi.pages.default_container.number",default_container_number);
+
         modules = new HashSet<String>();
+        containers = new ArrayList<AdminPageContainer>();
         configurationMap = new HashMap<String, Configuration>();
         jarURLs = new HashMap<String, Configuration>();
 
@@ -84,6 +94,14 @@ public class ModuleServiceImpl implements ModuleService {
                     modules.add(moduleName);
 
 
+
+                    if(moduleProperties.getString("container") != null) {
+                        addContainerModule(moduleProperties.getString("container"),moduleName,moduleProperties.getInt("container.weight",-1));
+                    } else {
+                        addContainerModule(default_container_name,moduleName,default_container_number);
+                    }
+
+
                     URLConnection urlConnection = moduleUrl.openConnection();
                     URL jarUrl;
                     if(urlConnection instanceof JarURLConnection) {
@@ -135,6 +153,21 @@ public class ModuleServiceImpl implements ModuleService {
         }
     }
 
+    private void addContainerModule(String container, String module, int number) {
+        AdminPageContainer c;
+        int i = containers.indexOf(container);
+        if(i>=0) {
+            c = containers.get(i);
+            c.addModule(module);
+        }
+        else {
+            c = new AdminPageContainer(container);
+            containers.add(c);
+            c.addModule(module);
+        }
+        if(number>0) c.setNumber(number);
+    }
+
     /**
      * Provide the current module configuration to the service injecting it
      *
@@ -173,6 +206,7 @@ public class ModuleServiceImpl implements ModuleService {
      * @param moduleName
      * @return
      */
+    @Deprecated
     @Override
     public Collection<String> getEntities(String moduleName) {
         Configuration config = getModuleConfiguration(moduleName).getConfiguration();
@@ -192,6 +226,14 @@ public class ModuleServiceImpl implements ModuleService {
     }
 
     /**
+     * Lists containers and underlying modules
+     * @return
+     */
+    public List<AdminPageContainer> listContainers() {
+        return containers;
+    }
+
+    /**
      * Return the configuration for the module identified by the name given as argument. Returns an
      * immutable Apache Commons Configuration object, or null if the module is not found.
      *
@@ -269,11 +311,25 @@ public class ModuleServiceImpl implements ModuleService {
     }
 
     /**
+     * returns the icon (if set), null otherwise
+     * @param moduleName
+     * @return
+     */
+    @Override
+    public String getIcon(String moduleName) {
+        Configuration config = getModuleConfiguration(moduleName).getConfiguration();
+        if(config != null) return config.getString("icon");
+        else
+            return null;
+    }
+
+    /**
      * Return a list of admin pages (paths)
      * @param moduleName
      * @return
      */
     @Override
+    @Deprecated
     public List<String> getAdminPages(String moduleName) {
         Configuration config = getModuleConfiguration(moduleName).getConfiguration();
         if(config != null) return ImmutableList.copyOf(config.getStringArray("adminpages"));
@@ -281,6 +337,42 @@ public class ModuleServiceImpl implements ModuleService {
             return null;
     }
 
+    /**
+     * Returns a list of AdminPage Objects
+     * @param moduleName
+     * @return
+     */
+    @Override
+    public List<AdminPage> getAdminPageList(String moduleName) {
+        ArrayList<AdminPage> l = new ArrayList<AdminPage>();
+        Configuration config = getModuleConfiguration(moduleName).getConfiguration();
+
+        if(config==null) return null;
+
+        //test if there are names and order for admin pages
+        if(config.getString("adminpages.0") != null) {
+            int i=0;
+            while(config.getString("adminpages."+i) != null) {
+                try {
+                    l.add(new AdminPage(
+                            i,
+                            config.getString("adminpages." + i + ".path", null),
+                            config.getString("adminpages."+i+".title",null),
+                            config.getBoolean("adminpages."+i+".important",false)
+                    ));
+                } catch (MarmottaException e) {
+                    log.error("admin page cannot be added for module "+moduleName);
+                }
+            }
+        } else {
+            for(String path : getAdminPages(moduleName)) {
+                l.add(new AdminPage(path));
+            }
+        }
+        Collections.sort(l);
+        return l;
+    }
+
     @Override
     public int getWeight(String moduleName) {
         Configuration config = getModuleConfiguration(moduleName).getConfiguration();

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/80345190/platform/marmotta-core/src/main/resources/config-defaults.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/config-defaults.properties b/platform/marmotta-core/src/main/resources/config-defaults.properties
index 6a5dcc8..32911a2 100644
--- a/platform/marmotta-core/src/main/resources/config-defaults.properties
+++ b/platform/marmotta-core/src/main/resources/config-defaults.properties
@@ -62,6 +62,12 @@ kiwi.pages.project.custom.footer = Your Footer powered by <a href="http://marmot
 # supported styles
 kiwi.pages.style_path = core/public/style/blue/
 
+# name for default container
+kiwi.pages.default_container.name = Others
+
+# ordering number for default container
+kiwi.pages.default_container.number = 100
+
 # enable or disable the logging of debugging messages for the whole system
 debug.enabled = false
 

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/80345190/platform/marmotta-core/src/main/resources/config-descriptions.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/config-descriptions.properties b/platform/marmotta-core/src/main/resources/config-descriptions.properties
index 913ba5b..607e1d6 100644
--- a/platform/marmotta-core/src/main/resources/config-descriptions.properties
+++ b/platform/marmotta-core/src/main/resources/config-descriptions.properties
@@ -50,6 +50,12 @@ kiwi.pages.project.type = java.lang.Enum("marmotta"|"custom")
 kiwi.pages.style_path.description = path to stylesheets for LMF Admin page
 kiwi.pages.style.type = java.lang.String
 
+kiwi.pages.default_container.name.description = name for default container
+kiwi.pages.default_container.name.type = java.lang.String
+
+kiwi.pages.default_container.number.description = ordering number for default container
+kiwi.pages.default_container.number.type = java.lang.String
+
 debug.enabled.description = enable or disable the logging of debugging messages for the whole system
 debug.enabled.type = java.lang.Boolean
 

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/80345190/platform/marmotta-core/src/main/resources/kiwi-module.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/kiwi-module.properties b/platform/marmotta-core/src/main/resources/kiwi-module.properties
index 30703e7..adce8f8 100644
--- a/platform/marmotta-core/src/main/resources/kiwi-module.properties
+++ b/platform/marmotta-core/src/main/resources/kiwi-module.properties
@@ -18,6 +18,11 @@
 
 name=Core Services
 
+icon=icon-beaker
+
+container=My Core Container
+container.weight = 10
+
 subtitle = Configure LMF Core
 weight = 10
 
@@ -26,16 +31,35 @@ icon_small = /admin/img/config_small.png
 #do not change!!!
 baseurl=/core
 
-adminpages=/admin/about.html,\
-  /admin/configuration.html,\
-  /admin/tasks.html,\
-  /admin/import.html,\
-  /admin/export.html,\
-  /admin/dataview.html,\
-  /admin/contexts.html,\
-  /admin/prefixes.html,\
-  /admin/system.html,\
-  /admin/database.html,
+adminpages.0.title=About
+adminpages.0.link=/admin/about.html
+
+adminpages.1.title=Core Configuration
+adminpages.1.link=/admin/configuration.html
+
+adminpages.2.title=Tasks
+adminpages.2.link=/admin/tasks.html
+
+adminpages.3.title=Import
+adminpages.3.link=/admin/import.html
+
+adminpages.4.title=Export
+adminpages.4.link=/admin/export.html
+
+adminpages.5.title=Data Views
+adminpages.5.link=/admin/dataview.html
+
+adminpages.6.title=Context Manager
+adminpages.6.link=/admin/contexts.html
+
+adminpages.7.title=Prefix Manager
+adminpages.7.link=/admin/prefixes.html
+
+adminpages.8.title=System
+adminpages.8.link=/admin/system.html
+
+adminpages.9.title=Database
+adminpages.9.link=/admin/database.html
 
 webservices=org.apache.marmotta.platform.core.webservices.config.ConfigurationWebService,\
   org.apache.marmotta.platform.core.webservices.config.DependenciesWebService,\

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/80345190/platform/marmotta-core/src/main/resources/templates/admin.ftl
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/templates/admin.ftl b/platform/marmotta-core/src/main/resources/templates/admin.ftl
index 14b83a5..370c415 100644
--- a/platform/marmotta-core/src/main/resources/templates/admin.ftl
+++ b/platform/marmotta-core/src/main/resources/templates/admin.ftl
@@ -138,7 +138,7 @@
             <div class="span4">
                 <div class="hero-unit">
                     <form>
-                        <fieldset>
+                    <fieldset>
                             <legend>Legend</legend>
                             <div class="field-box">
                                 <label>Format</label>