Author: angelo.vandersijpt at luminis.eu
Date: Thu Oct 14 16:59:41 2010
New Revision: 169

Log:
AMDATU-103 Refactored GadgetManagementService so it doesn't need a 
configuration anymore.

Modified:
   
trunk/application-bundles/gadget-management/src/main/java/org/amdatu/application/gadgetmanagement/osgi/Activator.java
   
trunk/application-bundles/gadget-management/src/main/java/org/amdatu/application/gadgetmanagement/service/GadgetManagementServiceImpl.java

Modified: 
trunk/application-bundles/gadget-management/src/main/java/org/amdatu/application/gadgetmanagement/osgi/Activator.java
==============================================================================
--- 
trunk/application-bundles/gadget-management/src/main/java/org/amdatu/application/gadgetmanagement/osgi/Activator.java
       (original)
+++ 
trunk/application-bundles/gadget-management/src/main/java/org/amdatu/application/gadgetmanagement/osgi/Activator.java
       Thu Oct 14 16:59:41 2010
@@ -55,7 +55,6 @@
                 .setImplementation(GadgetManagementServiceImpl.class)
                 
.add(createServiceDependency().setService(LogService.class).setRequired(true))
                 
.add(createServiceDependency().setService(UserAdmin.class).setRequired(true))
-                
.add(createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true))
                 
.add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
                 
.add(createServiceDependency().setService(ColumnFamilyAvailable.class, 
gadgetFilter).setRequired(true))
                 
.add(createServiceDependency().setService(GadgetStore.class).setRequired(true))

Modified: 
trunk/application-bundles/gadget-management/src/main/java/org/amdatu/application/gadgetmanagement/service/GadgetManagementServiceImpl.java
==============================================================================
--- 
trunk/application-bundles/gadget-management/src/main/java/org/amdatu/application/gadgetmanagement/service/GadgetManagementServiceImpl.java
  (original)
+++ 
trunk/application-bundles/gadget-management/src/main/java/org/amdatu/application/gadgetmanagement/service/GadgetManagementServiceImpl.java
  Thu Oct 14 16:59:41 2010
@@ -95,11 +95,6 @@
 
     private Component m_httpContextComponent;
 
-    // The PID of this bundle
-    private static final String PID = 
"org.amdatu.application.gadgetmanagement";
-    private static final String INITIALIZED_KEY = "initialized";
-
-
     /**
      * The init() method is invoked by the Felix dependency manager.
      */
@@ -112,28 +107,14 @@
 
     @SuppressWarnings("unchecked")
     public void start() {
-        try {
-            // Remember if we did already add the default gadgets or not
-            Configuration config = m_configurationAdmin.getConfiguration(PID);
-            Dictionary properties = config.getProperties();
-            if (properties == null || 
!"true".equals(properties.get(INITIALIZED_KEY).toString())) {
-                // First create the categories
-                addCategory(GadgetCategory.AMDATU_PLATFORM);
-                addCategory(GadgetCategory.AMDATU_EXAMPLES);
-                addCategory(GadgetCategory.THIRDPARTY);
-                
-                for (String gadgetUrl : 
DefaultGadgetRepository.DEFAULT_GADGETS) {
-                    GadgetDefinition gadget = new GadgetDefinition(gadgetUrl, 
GadgetCategory.THIRDPARTY, false);
-                    addGadget(gadget);
-                }
-
-                // Remember we initialized the service
-                properties = new Hashtable<String, String>();
-                properties.put(INITIALIZED_KEY, "true");
-                config.update(properties);
-            }
-        } catch (IOException e) {
-            m_logService.log(LogService.LOG_ERROR, "Failed to read 
configuration file", e);
+        // initialize the default gadget categories.
+        addCategory(GadgetCategory.AMDATU_PLATFORM);
+        addCategory(GadgetCategory.AMDATU_EXAMPLES);
+        addCategory(GadgetCategory.THIRDPARTY);
+
+        for (String gadgetUrl : DefaultGadgetRepository.DEFAULT_GADGETS) {
+            GadgetDefinition gadget = new GadgetDefinition(gadgetUrl, 
GadgetCategory.THIRDPARTY, false);
+            addGadget(gadget);
         }
     }
 
@@ -146,7 +127,7 @@
     }
 
     /**
-     * @see GadgetManagement#addGadget(String)
+     * @see GadgetManagement#addGadget(GadgetDefinition) 
      */
     public boolean addGadget(GadgetDefinition gadget) {
         return m_gadgetStore.addGadget(gadget);
@@ -193,7 +174,7 @@
 
     /**
      * Returns gadgets available in the gadget store. URL to this resource:
-     * http://localhost:3737/rest/services/gadgetstore/gadgetstore/allgadgets
+     * http://localhost:3737/rest/services/gadgetstore/gadgetstore/gadgets/all
      * @return All available gadgets.
      */
     @GET
@@ -245,7 +226,7 @@
 
     /**
      * Returns gadgets registered for the current user. URL to this resource:
-     * http://localhost:3737/rest/services/gadgetstore/gadgetstore/mygadgets
+     * http://localhost:3737/rest/services/gadgetstore/gadgetstore/gadgets/mine
      * @return Gadgets registered for the current user.
      */
     @SuppressWarnings("unchecked")
@@ -310,21 +291,19 @@
                 JSONObject gadget = retrieveGadget(gadgetUrl);
                 if (gadget != null) {
                     addSecurityToken(gadgetUrl, gadget, request);
-                    if (gadget != null) {
-                        // FIXME: for now handle layout here
-                        if (column == 1) {
-                            gadget.put("column", "first");
-                            column++;
-                        } else if (column == 2) {
-                            gadget.put("column", "second");
-                            column++;
-                        } else if (column == 3) {
-                            gadget.put("column", "third");
-                            column = 1;
-                        }
-
-                        gadgets.add(gadget);
+                    // FIXME: for now handle layout here
+                    if (column == 1) {
+                        gadget.put("column", "first");
+                        column++;
+                    } else if (column == 2) {
+                        gadget.put("column", "second");
+                        column++;
+                    } else if (column == 3) {
+                        gadget.put("column", "third");
+                        column = 1;
                     }
+
+                    gadgets.add(gadget);
                 }
             }
 
@@ -370,7 +349,7 @@
                 substituter.addSubstitutions(Substitutions.Type.MESSAGE, 
bundle.getMessages());
                 spec = spec.substitute(substituter);
 
-                // Replace the remaining mesasges with 'all' messages
+                // Replace the remaining messages with 'all' messages
                 locale = getPreferredLocale(new Locale("all", "all"), locales);
                 messageXML = loadXML(new 
URL(locales.get(locale).getMessages().toString()));
                 bundle = new MessageBundle(locales.get(locale), messageXML);
@@ -414,9 +393,7 @@
                 String xml = "";
                 URLConnection inputConnection = url.openConnection();
                 // TODO: assuming here it is UTF-8
-                reader =
-                        new BufferedReader(new 
InputStreamReader(inputConnection.getInputStream(), Charset
-                                .forName("UTF-8")));
+                reader = new BufferedReader(new 
InputStreamReader(inputConnection.getInputStream(), Charset.forName("UTF-8")));
                 String inputLine;
                 while ((inputLine = reader.readLine()) != null) {
                     xml += inputLine;
@@ -428,8 +405,7 @@
                 }
             }
         } catch (IOException e) {
-            m_logService
-                    .log(LogService.LOG_ERROR, "Could not retrieve gadget XML 
from url '" + url.toString() + "'", e);
+            m_logService.log(LogService.LOG_ERROR, "Could not retrieve gadget 
XML from url '" + url.toString() + "'", e);
         }
         return null;
     }
@@ -558,10 +534,11 @@
         return gadgetUrls;
     }
 
-    
-
     public boolean addCategory(GadgetCategory category) {
-        return m_gadgetStore.addCategory(category);
+        if (m_gadgetStore.getCategory(category.getId()) == null) {
+            return m_gadgetStore.addCategory(category);
+        }
+        return false;
     }
     
     public GadgetCategory getCategory(String categoryId) {

Reply via email to