From 43f284a9b05260113630dfa3175038631c1c09f4 Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Mon, 15 Feb 2010 15:04:47 +0000 Subject: [PATCH] Introduction of annotation to handle MVC flows // Class cleaning git-svn-id: https://svn.argeo.org/slc/trunk@3352 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../argeo/slc/web/mvc/EventController.java | 33 ++--- .../argeo/slc/web/mvc/ServiceController.java | 125 +++++------------- .../process/ExecutionServiceController.java | 55 ++------ 3 files changed, 57 insertions(+), 156 deletions(-) diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/EventController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/EventController.java index a245b08d3..50c532be3 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/EventController.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/EventController.java @@ -8,7 +8,6 @@ import org.argeo.slc.msg.event.SlcEventListener; import org.argeo.slc.msg.event.SlcEventListenerDescriptor; import org.argeo.slc.msg.event.SlcEventListenerRegister; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -25,16 +24,14 @@ public class EventController { private SlcEventListener eventListener = null; public EventController() { - if (log.isDebugEnabled()) - log.debug("In EventController Constructor"); } // Business Methods @RequestMapping("/addEventListener.service") - public String addEventListener( + public ExecutionAnswer addEventListener( @RequestParam(SlcEvent.EVENT_TYPE) String eventType, - @RequestParam(value=SlcEvent.EVENT_FILTER, required=false) String eventFilter, Model model) { + @RequestParam(value = SlcEvent.EVENT_FILTER, required = false) String eventFilter) { eventListenerRegister .addEventListenerDescriptor(new SlcEventListenerDescriptor( @@ -43,16 +40,14 @@ public class EventController { log.trace("Registered listener on register " + eventListenerRegister.getId() + " for type " + eventType + ", filter=" + eventFilter); - model.addAttribute(KEY_ANSWER, ExecutionAnswer - .ok("Execution completed properly")); - return KEY_ANSWER; + return ExecutionAnswer.ok("Execution completed properly"); } @RequestMapping("/removeEventListener.service") - public String removeEventListener( + public ExecutionAnswer removeEventListener( @RequestParam(SlcEvent.EVENT_TYPE) String eventType, - @RequestParam(value=SlcEvent.EVENT_FILTER, required=false) String eventFilter, Model model) { + @RequestParam(value = SlcEvent.EVENT_FILTER, required = false) String eventFilter) { eventListenerRegister .removeEventListenerDescriptor(new SlcEventListenerDescriptor( @@ -61,14 +56,12 @@ public class EventController { log.trace("Removed listener from register " + eventListenerRegister.getId() + " for type " + eventType + ", filter=" + eventFilter); - model.addAttribute(KEY_ANSWER, ExecutionAnswer - .ok("Execution completed properly")); - return KEY_ANSWER; + return ExecutionAnswer.ok("Execution completed properly"); } @RequestMapping("/pollEvent.service") - public String pollEvent(@RequestParam("timeout") String timeoutStr, - Model model) { + public Object pollEvent( + @RequestParam(value = "timeout", required = false) String timeoutStr) { final Long timeout; if (timeoutStr != null) timeout = Long.parseLong(timeoutStr); @@ -78,14 +71,10 @@ public class EventController { SlcEvent event = eventListener.listen(eventListenerRegister.getId(), eventListenerRegister.getDescriptorsCopy(), timeout); if (event != null) { - model.addAttribute("event", event); - if (log.isTraceEnabled()) - log.debug("Received event: " - + event.getHeaders().get(SlcEvent.EVENT_TYPE)); + return event; + } else { + return ExecutionAnswer.ok("Execution completed properly"); } - model.addAttribute(KEY_ANSWER, ExecutionAnswer - .ok("Execution completed properly")); - return KEY_ANSWER; } public void setEventListenerRegister( diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/ServiceController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/ServiceController.java index 26a59c642..4d74a9fb9 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/ServiceController.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/ServiceController.java @@ -57,8 +57,6 @@ public class ServiceController { TreeTestResultCollectionDao testResultCollectionDao, TestManagerService testManagerService, SlcAgentDescriptorDao slcAgentDescriptorDao) { - if (log.isDebugEnabled()) - log.debug("In SlcServiceController Constructor"); this.testManagerService = testManagerService; this.treeTestResultDao = treeTestResultDao; @@ -67,22 +65,14 @@ public class ServiceController { } // Business Methods - @RequestMapping("/isServerReady.service") - protected String isServerReady(Model model) { - if (log.isDebugEnabled()) - log.debug("SlcServiceController :: isServerReady "); + protected ExecutionAnswer isServerReady(Model model) { // Does nothing for now, it will return an OK answer. - model.addAttribute(KEY_ANSWER, ExecutionAnswer - .ok("Execution completed properly")); - return KEY_ANSWER; + return ExecutionAnswer.ok("Execution completed properly"); } @RequestMapping("/shutdownRuntime.service") - protected String shutdownRuntime(Model model) { - if (log.isDebugEnabled()) - log.debug("SlcServiceController :: shutdownRuntime"); - + protected ExecutionAnswer shutdownRuntime(Model model) { new Thread() { public void run() { // wait in order to let call return @@ -94,44 +84,29 @@ public class ServiceController { dynamicRuntime.shutdown(); } }.start(); - ExecutionAnswer answer = ExecutionAnswer.ok("Server shutting down..."); - model.addAttribute(answer); - return KEY_ANSWER; + return ExecutionAnswer.ok("Server shutting down..."); } @RequestMapping("/getResult.service") - protected String getResult( - @RequestParam(value = "uuid", required = false) String uuid, - Model model) { - if (log.isDebugEnabled()) - log.debug("In SlcServiceController In GetResultMethod"); + protected TreeTestResult getResult( + @RequestParam(value = "uuid", required = false) String uuid) { TreeTestResult result = treeTestResultDao.getTestResult(uuid); if (result == null) throw new SlcException("No result found for uuid " + uuid); - model.addAttribute("result", result); - return "result"; + return result; } @RequestMapping("/addResultToCollection.service") - protected String addResultToCollection(@RequestParam String collectionId, - @RequestParam String resultUuid, Model model) { - if (log.isDebugEnabled()) - log.debug("In SlcServiceController :: addResultToCollection"); - + protected ExecutionAnswer addResultToCollection( + @RequestParam String collectionId, @RequestParam String resultUuid) { testManagerService.addResultToCollection(collectionId, resultUuid); - model.addAttribute(KEY_ANSWER, ExecutionAnswer - .ok("Execution completed properly")); - return KEY_ANSWER; + return ExecutionAnswer.ok("Execution completed properly"); } @RequestMapping("/removeResultFromCollection.service") - protected String removeResultFromCollection(HttpServletRequest request, - Model model) { - if (log.isDebugEnabled()) - log - .debug("In SlcServiceController :: removeResultFromCollection.service"); - + protected ExecutionAnswer removeResultFromCollection( + HttpServletRequest request) { String collectionId = request.getParameter("collectionId"); String[] resultUuids = request.getParameterValues("resultUuid"); String[] attrNames = request.getParameterValues("attrName"); @@ -185,17 +160,12 @@ public class ServiceController { } } - model.addAttribute(KEY_ANSWER, ExecutionAnswer - .ok("Execution completed properly")); - return KEY_ANSWER; + return ExecutionAnswer.ok("Execution completed properly"); } @RequestMapping("/listCollectionRefs.service") - protected String listCollectionRefs(HttpServletRequest request, - HttpServletResponse response, Model model) { - - if (log.isDebugEnabled()) - log.debug("In SlcServiceController :: listCollectionRefs.service"); + protected ReferenceList listCollectionRefs(HttpServletRequest request, + HttpServletResponse response) { SortedSet results = testResultCollectionDao .listCollections(); @@ -204,36 +174,28 @@ public class ServiceController { for (TreeTestResultCollection collection : results) { referenceList.getReferences().add(collection.getId()); } - - model.addAttribute("referenceList", referenceList); - return "referenceList"; + return referenceList; } @RequestMapping("/listResultAttributes.service") - protected String listResultAttributes(@RequestParam String id, Model model) { - - if (log.isDebugEnabled()) - log - .debug("In SlcServiceController :: listResultAttributes.service"); + protected ObjectList listResultAttributes(@RequestParam String id, Model model) { List resultAttributes = testResultCollectionDao .listResultAttributes(id); - - model.addAttribute("resultAttributesList", new ObjectList( - resultAttributes)); - return "resultAttributesList"; + return new ObjectList( + resultAttributes); } @RequestMapping("/listResults.service") @SuppressWarnings(value = { "unchecked" }) - protected String listResults(@RequestParam (value = "collectionId", required = false)String collectionId, - HttpServletRequest request, Model model) { + protected ObjectList listResults( + @RequestParam(value = "collectionId", required = false) String collectionId, + HttpServletRequest request) { if (log.isDebugEnabled()) - log.debug("In SlcServiceController :: listResults.service"); + log.debug("In ServiceController :: listResults.service"); Map parameterMap = request.getParameterMap(); - Map attributes = new HashMap(); for (String parameter : parameterMap.keySet()) { if (parameter.startsWith("attr.")) { @@ -244,20 +206,14 @@ public class ServiceController { List resultAttributes = testResultCollectionDao .listResults(collectionId, attributes); - - model.addAttribute("resultList", new ObjectList(resultAttributes)); - return "resultList"; + return new ObjectList(resultAttributes); } @RequestMapping("/copyCollectionToCollection.service") - protected String copyCollectionToCollection( + protected ExecutionAnswer copyCollectionToCollection( @RequestParam String sourceCollectionId, @RequestParam String targetCollectionId, - HttpServletRequest request, Model model) { - - if (log.isDebugEnabled()) - log - .debug("In SlcServiceController :: copyCollectionToCollection.service"); + HttpServletRequest request) { String[] attrNames = request.getParameterValues("attrName"); String[] attrPatterns = request.getParameterValues("attrPattern"); @@ -296,45 +252,33 @@ public class ServiceController { treeTestResult.getUuid()); } } - model.addAttribute(KEY_ANSWER, ExecutionAnswer - .ok("Execution completed properly")); - return KEY_ANSWER; + return ExecutionAnswer.ok("Execution completed properly"); } @RequestMapping("/listAgents.service") - protected String listAgents(Model model) { + protected ObjectList listAgents() { if (log.isDebugEnabled()) - log.debug("In SlcServiceController :: listAgents.service"); - + log.debug("In ServiceController :: listAgents.service"); List list = slcAgentDescriptorDao .listSlcAgentDescriptors(); - model.addAttribute("list", new ObjectList(list)); - return "list"; + return new ObjectList(list); } @RequestMapping("/cleanAgents.service") - protected String cleanAgents(Model model) { - - if (log.isDebugEnabled()) - log.debug("In SlcServiceController :: cleanAgents.service"); + protected ExecutionAnswer cleanAgents() { List list = slcAgentDescriptorDao .listSlcAgentDescriptors(); for (SlcAgentDescriptor t : new Vector(list)) { slcAgentDescriptorDao.delete(t); } - model.addAttribute(KEY_ANSWER, ExecutionAnswer - .ok("Execution completed properly")); - return KEY_ANSWER; + return ExecutionAnswer.ok("Execution completed properly"); } @RequestMapping("/getAttachment.service") - protected String getAttachment(@RequestParam String uuid, + protected void getAttachment(@RequestParam String uuid, @RequestParam String contentType, @RequestParam String name, - HttpServletResponse response, Model model) throws Exception { - if (log.isDebugEnabled()) - log.debug("In SlcServiceController :: getAttachment"); - + HttpServletResponse response) throws Exception { if (contentType == null || "".equals(contentType.trim())) { if (name != null) { contentType = FORCE_DOWNLOAD; @@ -375,7 +319,6 @@ public class ServiceController { response.setContentType(contentType); ServletOutputStream outputStream = response.getOutputStream(); attachmentsStorage.retrieveAttachment(resourceDescriptor, outputStream); - return null; } // IoC diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/ExecutionServiceController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/ExecutionServiceController.java index 8aa2b5ad9..1c8e41bb2 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/ExecutionServiceController.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/ExecutionServiceController.java @@ -29,7 +29,6 @@ import org.springframework.ui.Model; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.ModelAndView; import org.springframework.xml.transform.StringSource; @Controller @@ -49,39 +48,25 @@ public class ExecutionServiceController { private SlcExecutionManager slcExecutionManager; @RequestMapping("/listSlcExecutions.service") - protected String listSlcExecutions(Model model) { - - if (log.isDebugEnabled()) - log.debug("In SlcServiceController :: listSlcExecutions.service"); - + protected ObjectList listSlcExecutions() { List list = slcExecutionDao.listSlcExecutions(); - model.addAttribute("list", new ObjectList(list)); - return "list"; + return new ObjectList(list); } @RequestMapping("/getExecutionDescriptor.service") - protected String getExecutionDescriptor(@RequestParam String agentId, - @RequestParam String moduleName, @RequestParam String version, - Model model) { + protected ExecutionModuleDescriptor getExecutionDescriptor( + @RequestParam String agentId, @RequestParam String moduleName, + @RequestParam String version) { - if (log.isDebugEnabled()) - log.debug(":: SlcServiceController :: getExecutionDescriptor"); - SlcAgent slcAgent = agentFactory.getAgent(agentId); ExecutionModuleDescriptor md = slcAgent.getExecutionModuleDescriptor( moduleName, version); - model.addAttribute(md); - return "executionModuleDescriptor"; + return md; } @RequestMapping("/listModulesDescriptors.service") - protected String listModulesDescriptors(@RequestParam String agentId, - Model model) { - - if (log.isDebugEnabled()) - log.debug(":: SlcServiceController :: listModulesDescriptors"); - + protected ObjectList listModulesDescriptors(@RequestParam String agentId) { // TODO: use centralized agentId property (from MsgConstants)? SlcAgent slcAgent = agentFactory.getAgent(agentId); @@ -100,33 +85,21 @@ public class ExecutionServiceController { } }); set.addAll(descriptors); - - model.addAttribute(new ObjectList(set)); - return "objectList"; + return new ObjectList(set); } @RequestMapping("/getSlcExecution.service") - protected void getSlcExecution(@RequestParam String uuid, - ModelAndView modelAndView) { - if (log.isDebugEnabled()) - log.debug("In ExecutionServiceController :: getSlcExecution.service"); - + protected SlcExecution getSlcExecution(@RequestParam String uuid) { SlcExecution slcExecution = slcExecutionDao.getSlcExecution(uuid); - initializeSEM(); slcExecutionManager.retrieveRealizedFlows(slcExecution); - modelAndView.addObject(slcExecution); - modelAndView.addObject(KEY_ANSWER, ExecutionAnswer - .ok("Execution completed properly")); + return slcExecution; } @RequestMapping("/newSlcExecution.service") - protected String newSlcExecution(HttpServletRequest request, + protected ExecutionAnswer newSlcExecution(HttpServletRequest request, Model model) throws Exception { - if (log.isDebugEnabled()) - log.debug("In ExecutionServiceController :: newSlcExecution.service"); - String agentId = request .getParameter(MsgConstants.PROPERTY_SLC_AGENT_ID); Assert.notNull(agentId, "agent id"); @@ -166,11 +139,7 @@ public class ExecutionServiceController { SlcAgent agent = agentFactory.getAgent(agentId); agent.runSlcExecution(slcExecution); - log.debug("After Everything has been done !"); - - model.addAttribute(KEY_ANSWER, ExecutionAnswer - .ok("Execution completed properly")); - return KEY_ANSWER; + return ExecutionAnswer.ok("Execution completed properly"); } private void initializeSEM() { -- 2.39.5