]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/execution/ListModulesDescriptors.java
Add license headers
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / web / mvc / execution / ListModulesDescriptors.java
index 32cf1383ef40f929f855bc35d5a409d1e43f3489..f012fc2b12f236e81ab034d2c77e4d393c925234 100644 (file)
@@ -1,42 +1,71 @@
+/*\r
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *         http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
 package org.argeo.slc.web.mvc.execution;\r
 \r
-import java.util.ArrayList;\r
+import java.util.Comparator;\r
 import java.util.List;\r
+import java.util.SortedSet;\r
+import java.util.TreeSet;\r
 \r
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
-import org.argeo.slc.execution.ExecutionModule;\r
 import org.argeo.slc.execution.ExecutionModuleDescriptor;\r
-import org.argeo.slc.execution.ExecutionModulesManager;\r
 import org.argeo.slc.msg.ObjectList;\r
+import org.argeo.slc.runtime.SlcAgent;\r
+import org.argeo.slc.runtime.SlcAgentFactory;\r
 import org.argeo.slc.web.mvc.AbstractServiceController;\r
 import org.springframework.web.servlet.ModelAndView;\r
 \r
 /** . */\r
 public class ListModulesDescriptors extends AbstractServiceController {\r
-       private ExecutionModulesManager modulesManager;\r
+       private SlcAgentFactory agentFactory;\r
 \r
        @Override\r
        protected void handleServiceRequest(HttpServletRequest request,\r
                        HttpServletResponse response, ModelAndView modelAndView)\r
                        throws Exception {\r
 \r
-               List<ExecutionModule> modules = modulesManager.listExecutionModules();\r
+               // TODO: use centralized agentId property (from MsgConstants)?\r
+               String agentId = request.getParameter("agentId");\r
+\r
+               SlcAgent slcAgent = agentFactory.getAgent(agentId);\r
+\r
+               List<ExecutionModuleDescriptor> descriptors = slcAgent\r
+                               .listExecutionModuleDescriptors();\r
+               SortedSet<ExecutionModuleDescriptor> set = new TreeSet<ExecutionModuleDescriptor>(\r
+                               new Comparator<ExecutionModuleDescriptor>() {\r
 \r
-               List<ExecutionModuleDescriptor> descriptors = new ArrayList<ExecutionModuleDescriptor>();\r
-               for (ExecutionModule module : modules) {\r
-                       ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();\r
-                       md.setName(module.getName());\r
-                       md.setVersion(module.getVersion());\r
-                       descriptors.add(md);\r
-               }\r
+                                       public int compare(ExecutionModuleDescriptor md1,\r
+                                                       ExecutionModuleDescriptor md2) {\r
+                                               String str1 = md1.getLabel() != null ? md1.getLabel()\r
+                                                               : md1.getName();\r
+                                               String str2 = md2.getLabel() != null ? md2.getLabel()\r
+                                                               : md2.getName();\r
+                                               return str1.compareTo(str2);\r
+                                       }\r
+                               });\r
+               set.addAll(descriptors);\r
 \r
-               modelAndView.addObject(new ObjectList(descriptors));\r
+               modelAndView.addObject(new ObjectList(set));\r
        }\r
 \r
-       public void setModulesManager(ExecutionModulesManager modulesManager) {\r
-               this.modulesManager = modulesManager;\r
+       public void setAgentFactory(SlcAgentFactory agentFactory) {\r
+               this.agentFactory = agentFactory;\r
        }\r
 \r
 }\r