org.argeo.slc.runtime,
org.argeo.slc.services,
org.argeo.slc.web.mvc,
- org.argeo.slc.web.mvc.management,
- org.argeo.slc.web.mvc.process,
+ org.argeo.slc.web.mvc.controllers,
org.argeo.slc.web.mvc.provisioning,
org.argeo.slc.web.mvc.result,
org.hibernate.hql.ast;resolution:=optional,
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
- <bean name="/resultView.xls" class="org.argeo.slc.web.mvc.result.GetResultController">
- <constructor-arg ref="testResultDao" />
- <property name="viewName" value="resultExcelView" />
- </bean>
- <bean name="resultExcelView" class="org.argeo.slc.web.mvc.result.ResultExcelView">
+ <bean class="org.argeo.slc.web.mvc.controllers.RenderingResultController">
+ <property name="testResultDao" ref="testResultDao" />
+ <property name="resultExcelView" ref="resultExcelView" />
+ <property name="resultPdfView" ref="resultPdfView" />
</bean>
- <bean name="/resultView.pdf" class="org.argeo.slc.web.mvc.result.GetResultController">
- <constructor-arg ref="testResultDao" />
- <property name="viewName" value="resultPdfView" />
+
+ <bean name="resultExcelView" class="org.argeo.slc.web.mvc.result.ResultExcelView">
</bean>
<bean name="resultPdfView" class="org.argeo.slc.web.mvc.result.ResultPdfView">
</bean>
- <bean
- class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
+ <!--
+ bean
+ class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"
+ -->
+ <bean id="handlerMapping"
+ class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<ref bean="osivInterceptor" />
</property>
</bean>
-
<bean id="viewResolverXls"
class="org.springframework.web.servlet.view.BeanNameViewResolver">
</bean>
-
</beans>
\ No newline at end of file
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
- <context:component-scan base-package="org.argeo.slc.web.mvc" />
+ <context:component-scan base-package="org.argeo.slc.web.mvc.controllers" />
+
+ <!-- Server Handling -->
+ <bean class="org.argeo.slc.web.mvc.controllers.ServerController">
+ <property name="dynamicRuntime" ref="dynamicRuntime" />
+ </bean>
<!-- Execution -->
- <bean name="/*Execution*.service, /*Modules*.service" class="org.argeo.slc.web.mvc.ExecutionServiceController">
+ <bean class="org.argeo.slc.web.mvc.controllers.ProcessController">
<property name="agentFactory" ref="agentFactory" />
<property name="slcExecutionDao" ref="slcExecutionDao" />
<property name="slcExecutionService" ref="slcExecutionService" />
</bean>
<!-- Events -->
- <bean name="/*Event*.service" class="org.argeo.slc.web.mvc.EventController">
+ <bean class="org.argeo.slc.web.mvc.controllers.EventController">
<property name="eventListenerRegister" ref="eventListenerRegister" />
<property name="eventListener" ref="eventListener" />
</bean>
- <!-- Provisioning -->
- <bean name="/listModularDistributions.service"
- class="org.argeo.slc.web.mvc.provisioning.ListModularDistributions">
- <property name="modularDistributions" ref="modularDistributions" />
- </bean>
-
- <bean name="/installModule.service" class="org.argeo.slc.web.mvc.management.InstallModule">
- <property name="dynamicRuntime" ref="dynamicRuntime" />
+ <!-- Results Handling -->
+ <bean class="org.argeo.slc.web.mvc.controllers.ResultController">
+ <property name="treeTestResultDao" ref="testResultDao" />
+ <property name="treeTestResultCollectionDao" ref="testResultCollectionDao" />
+ <property name="testManagerService" ref="testManagerService" />
+ <property name="attachmentsStorage" ref="attachmentsStorage" />
</bean>
- <bean name="/uninstallModule.service" class="org.argeo.slc.web.mvc.management.UninstallModule">
- <property name="dynamicRuntime" ref="dynamicRuntime" />
+ <!-- Agent Handling -->
+ <bean class="org.argeo.slc.web.mvc.controllers.AgentController">
+ <property name="slcAgentDescriptorDao" ref="slcAgentDescriptorDao" />
</bean>
- <!-- All that remains -->
- <bean name="/*.service" class="org.argeo.slc.web.mvc.ServiceController">
- <constructor-arg ref="testResultDao" />
- <constructor-arg ref="testResultCollectionDao" />
- <constructor-arg ref="testManagerService" />
- <constructor-arg ref="slcAgentDescriptorDao" />
- <property name="dynamicRuntime" ref="dynamicRuntime" />
- <property name="attachmentsStorage" ref="attachmentsStorage" />
+ <!-- Provisioning -->
+ <bean name="/listModularDistributions.service"
+ class="org.argeo.slc.web.mvc.provisioning.ListModularDistributions">
+ <property name="modularDistributions" ref="modularDistributions" />
</bean>
<bean name="eventListenerRegister" class="org.argeo.slc.web.mvc.WebSlcEventListenerRegister"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
- <bean
- class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
- <property name="interceptors">
- <list>
- <ref bean="osivInterceptor" />
- </list>
- </property>
- </bean>
-
-
<bean id="viewResolverXslt" class="org.argeo.slc.web.mvc.XsltMarshallerViewResolver">
<property name="viewClass">
<value>org.argeo.slc.web.mvc.XsltMarshallerView
<property name="viewName" value="viewXml" />
</bean>
+ <bean
+ class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
+ <property name="interceptors">
+ <list>
+ <ref bean="osivInterceptor" />
+ </list>
+ </property>
+ </bean>
</beans>
\ No newline at end of file
+++ /dev/null
-/*\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;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.msg.ExecutionAnswer;\r
-import org.argeo.slc.msg.event.SlcEvent;\r
-import org.argeo.slc.msg.event.SlcEventListener;\r
-import org.argeo.slc.msg.event.SlcEventListenerDescriptor;\r
-import org.argeo.slc.msg.event.SlcEventListenerRegister;\r
-import org.springframework.stereotype.Controller;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RequestParam;\r
-\r
-@Controller\r
-public class EventController {\r
-\r
- private final static Log log = LogFactory.getLog(EventController.class);\r
-\r
- public final static String KEY_ANSWER = "__answer";\r
- private Long defaultTimeout = 10000l;\r
-\r
- // IoC\r
- private SlcEventListenerRegister eventListenerRegister;\r
- private SlcEventListener eventListener = null;\r
-\r
- public EventController() {\r
- }\r
-\r
- // Business Methods\r
-\r
- @RequestMapping("/addEventListener.service")\r
- public ExecutionAnswer addEventListener(\r
- @RequestParam(SlcEvent.EVENT_TYPE) String eventType,\r
- @RequestParam(value = SlcEvent.EVENT_FILTER, required = false) String eventFilter) {\r
-\r
- eventListenerRegister\r
- .addEventListenerDescriptor(new SlcEventListenerDescriptor(\r
- eventType, eventFilter));\r
- if (log.isTraceEnabled())\r
- log.trace("Registered listener on register "\r
- + eventListenerRegister.getId() + " for type " + eventType\r
- + ", filter=" + eventFilter);\r
- return ExecutionAnswer.ok("Execution completed properly");\r
-\r
- }\r
-\r
- @RequestMapping("/removeEventListener.service")\r
- public ExecutionAnswer removeEventListener(\r
- @RequestParam(SlcEvent.EVENT_TYPE) String eventType,\r
- @RequestParam(value = SlcEvent.EVENT_FILTER, required = false) String eventFilter) {\r
-\r
- eventListenerRegister\r
- .removeEventListenerDescriptor(new SlcEventListenerDescriptor(\r
- eventType, eventFilter));\r
- if (log.isTraceEnabled())\r
- log.trace("Removed listener from register "\r
- + eventListenerRegister.getId() + " for type " + eventType\r
- + ", filter=" + eventFilter);\r
- return ExecutionAnswer.ok("Execution completed properly");\r
- }\r
-\r
- @RequestMapping("/pollEvent.service")\r
- public Object pollEvent(\r
- @RequestParam(value = "timeout", required = false) String timeoutStr) {\r
- final Long timeout;\r
- if (timeoutStr != null)\r
- timeout = Long.parseLong(timeoutStr);\r
- else\r
- timeout = defaultTimeout;\r
-\r
- SlcEvent event = eventListener.listen(eventListenerRegister.getId(),\r
- eventListenerRegister.getDescriptorsCopy(), timeout);\r
- if (event != null) {\r
- return event;\r
- } else {\r
- return ExecutionAnswer.ok("Execution completed properly");\r
- }\r
- }\r
-\r
- public void setEventListenerRegister(\r
- SlcEventListenerRegister eventListenerRegister) {\r
- this.eventListenerRegister = eventListenerRegister;\r
- }\r
-\r
- public void setDefaultTimeout(Long defaultTimeout) {\r
- this.defaultTimeout = defaultTimeout;\r
- }\r
-\r
- public void setEventListener(SlcEventListener eventListener) {\r
- this.eventListener = eventListener;\r
- }\r
-}\r
+++ /dev/null
-/*\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;\r
-\r
-import java.io.BufferedReader;\r
-import java.util.Comparator;\r
-import java.util.List;\r
-import java.util.SortedSet;\r
-import java.util.TreeSet;\r
-import java.util.UUID;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.core.attachment.AttachmentsStorage;\r
-import org.argeo.slc.dao.process.SlcExecutionDao;\r
-import org.argeo.slc.execution.ExecutionModuleDescriptor;\r
-import org.argeo.slc.msg.ExecutionAnswer;\r
-import org.argeo.slc.msg.MsgConstants;\r
-import org.argeo.slc.msg.ObjectList;\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-import org.argeo.slc.runtime.SlcAgent;\r
-import org.argeo.slc.runtime.SlcAgentFactory;\r
-import org.argeo.slc.services.SlcExecutionService;\r
-import org.argeo.slc.web.mvc.process.SlcExecutionManager;\r
-import org.springframework.oxm.Marshaller;\r
-import org.springframework.oxm.Unmarshaller;\r
-import org.springframework.stereotype.Controller;\r
-import org.springframework.ui.Model;\r
-import org.springframework.util.Assert;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RequestParam;\r
-import org.springframework.xml.transform.StringSource;\r
-\r
-@Controller\r
-public class ExecutionServiceController {\r
-\r
- public final static String KEY_ANSWER = "__answer";\r
- private final static Log log = LogFactory\r
- .getLog(ExecutionServiceController.class);\r
-\r
- private SlcExecutionDao slcExecutionDao;\r
- private SlcAgentFactory agentFactory;\r
- private Unmarshaller unmarshaller;\r
- private Marshaller marshaller;\r
- private SlcExecutionService slcExecutionService;\r
- private AttachmentsStorage attachmentsStorage;\r
-\r
- private SlcExecutionManager slcExecutionManager;\r
-\r
- @RequestMapping("/listSlcExecutions.service")\r
- protected ObjectList listSlcExecutions() {\r
- List<SlcExecution> list = slcExecutionDao.listSlcExecutions();\r
- return new ObjectList(list);\r
- }\r
-\r
- @RequestMapping("/getExecutionDescriptor.service")\r
- protected ExecutionModuleDescriptor getExecutionDescriptor(\r
- @RequestParam String agentId, @RequestParam String moduleName,\r
- @RequestParam String version) {\r
-\r
- SlcAgent slcAgent = agentFactory.getAgent(agentId);\r
-\r
- ExecutionModuleDescriptor md = slcAgent.getExecutionModuleDescriptor(\r
- moduleName, version);\r
- return md;\r
- }\r
-\r
- @RequestMapping("/listModulesDescriptors.service")\r
- protected ObjectList listModulesDescriptors(@RequestParam String agentId) {\r
- // TODO: use centralized agentId property (from MsgConstants)?\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
- 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
- return new ObjectList(set);\r
- }\r
-\r
- @RequestMapping("/getSlcExecution.service")\r
- protected SlcExecution getSlcExecution(@RequestParam String uuid) {\r
- SlcExecution slcExecution = slcExecutionDao.getSlcExecution(uuid);\r
- initializeSEM();\r
- slcExecutionManager.retrieveRealizedFlows(slcExecution);\r
- return slcExecution;\r
- }\r
-\r
- @RequestMapping("/newSlcExecution.service")\r
- protected ExecutionAnswer newSlcExecution(HttpServletRequest request,\r
- Model model) throws Exception {\r
-\r
- String agentId = request\r
- .getParameter(MsgConstants.PROPERTY_SLC_AGENT_ID);\r
- Assert.notNull(agentId, "agent id");\r
-\r
- String answer = request.getParameter("body");\r
- if (answer == null) {\r
- // lets read the message body instead\r
- BufferedReader reader = request.getReader();\r
- StringBuffer buffer = new StringBuffer();\r
- String line = null;\r
- while (((line = reader.readLine()) != null)) {\r
- buffer.append(line);\r
- }\r
- answer = buffer.toString();\r
- }\r
-\r
- if (log.isTraceEnabled())\r
- log.debug("Received message:\n" + answer);\r
-\r
- StringSource source = new StringSource(answer);\r
- SlcExecution slcExecution = (SlcExecution) unmarshaller\r
- .unmarshal(source);\r
-\r
- // Workaround for https://www.argeo.org/bugzilla/show_bug.cgi?id=86\r
- if (slcExecution.getUuid() == null\r
- || slcExecution.getUuid().length() < 8)\r
- slcExecution.setUuid(UUID.randomUUID().toString());\r
-\r
- slcExecution.setStatus(SlcExecution.STATUS_SCHEDULED);\r
- slcExecution.getSteps().add(\r
- new SlcExecutionStep(SlcExecutionStep.TYPE_START,\r
- "Process started from the Web UI"));\r
-\r
- initializeSEM();\r
- slcExecutionManager.storeRealizedFlows(slcExecution);\r
- slcExecutionService.newExecution(slcExecution);\r
- SlcAgent agent = agentFactory.getAgent(agentId);\r
- agent.runSlcExecution(slcExecution);\r
-\r
- return ExecutionAnswer.ok("Execution completed properly");\r
- }\r
-\r
- private void initializeSEM() {\r
- slcExecutionManager = new SlcExecutionManager(agentFactory,\r
- unmarshaller, marshaller, slcExecutionService,\r
- attachmentsStorage);\r
-\r
- }\r
-\r
- public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao) {\r
- this.slcExecutionDao = slcExecutionDao;\r
- }\r
-\r
- public void setSlcExecutionService(SlcExecutionService slcExecutionService) {\r
- this.slcExecutionService = slcExecutionService;\r
- }\r
-\r
- public void setUnmarshaller(Unmarshaller unmarshaller) {\r
- this.unmarshaller = unmarshaller;\r
- }\r
-\r
- public void setMarshaller(Marshaller marshaller) {\r
- this.marshaller = marshaller;\r
- }\r
-\r
- public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) {\r
- this.attachmentsStorage = attachmentsStorage;\r
- }\r
-\r
- public void setAgentFactory(SlcAgentFactory agentFactory) {\r
- this.agentFactory = agentFactory;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * Licensed 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.argeo.slc.web.mvc;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.xml.transform.stream.StreamResult;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.SlcException;
-import org.springframework.oxm.Marshaller;
-import org.springframework.web.servlet.view.AbstractView;
-
-/** Marshal one of the object of the map to the output. */
-public class MarshallerView extends AbstractView {
-
- private final static Log log = LogFactory
- .getLog(MarshallerView.class);
-
-
- private String modelKey = null;
- private final Marshaller marshaller;
-
- public MarshallerView(Marshaller marshaller) {
- this.marshaller = marshaller;
- }
-
- public MarshallerView(Marshaller marshaller, String modelKey) {
- this(marshaller);
- this.modelKey = modelKey;
- }
-
- @Override
- @SuppressWarnings(value={"unchecked"})
- protected void renderMergedOutputModel(Map model,
- HttpServletRequest request, HttpServletResponse response)
- throws Exception {
- final Object answer;
-
- if (log.isDebugEnabled()){
- //log.debug("In MarshallerView :: renderMergedOutputModel");
- if (modelKey != null )
- log.debug("Model key : ["+modelKey+"]");
- else log.debug("ModelKey is null");
- }
-
- //TODO : remove this loop
- if (log.isDebugEnabled()){
- Iterator it = model.keySet().iterator();
- int i = 0;
- while (it.hasNext())
- log.debug(i++ + " [" + it.next().toString()+ "]");
- }
-
- if (modelKey != null) {
- if (!model.containsKey(modelKey)){
- /** //TODO : remove this loop
- if (log.isDebugEnabled()){
- log.debug("Key not found in Model. Available keys are : ");
- for (Object key : model.keySet()){
- log.debug(key.toString());
- }
- }
- **/
- throw new SlcException("Key " + modelKey
- + " not found in model.");
- }
- answer = model.get(modelKey);
- } else {
- if (model.size() != 1)
- throw new SlcException(
- "Model has a size different from 1. Specify a modelKey.");
- answer = model.values().iterator().next();
- }
-
- StreamResult streamResult = new StreamResult(response.getOutputStream());
- marshaller.marshal(answer, streamResult);
- }
-
- public void setModelKey(String modelKey) {
- this.modelKey = modelKey;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * Licensed 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.argeo.slc.web.mvc;
-
-import java.util.Locale;
-
-import org.springframework.oxm.Marshaller;
-import org.springframework.web.servlet.View;
-import org.springframework.web.servlet.view.AbstractCachingViewResolver;
-
-/**
- * Returns a MarshallerView based on the underlying marshaller. View name is the
- * model key of the marshaller view.
- */
-public class MarshallerViewResolver extends AbstractCachingViewResolver {
- private final Marshaller marshaller;
-
- public MarshallerViewResolver(Marshaller marshaller) {
- super();
- this.marshaller = marshaller;
- }
-
- /**
- * Caches a marshaller view.
- *
- * @param viewName
- * can be null, default marshaller view behavior is then used
- */
- @Override
- protected View loadView(String viewName, Locale locale) throws Exception {
- return new MarshallerView(marshaller, viewName);
- }
-
-}
+++ /dev/null
-/*\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;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.SortedSet;\r
-import java.util.Vector;\r
-\r
-import javax.servlet.ServletOutputStream;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import org.apache.commons.io.FilenameUtils;\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.core.attachment.AttachmentsStorage;\r
-import org.argeo.slc.core.attachment.SimpleAttachment;\r
-import org.argeo.slc.core.test.tree.ResultAttributes;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.core.test.tree.TreeTestResultCollection;\r
-import org.argeo.slc.dao.runtime.SlcAgentDescriptorDao;\r
-import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;\r
-import org.argeo.slc.dao.test.tree.TreeTestResultDao;\r
-import org.argeo.slc.deploy.DynamicRuntime;\r
-import org.argeo.slc.msg.ExecutionAnswer;\r
-import org.argeo.slc.msg.ObjectList;\r
-import org.argeo.slc.msg.ReferenceList;\r
-import org.argeo.slc.runtime.SlcAgentDescriptor;\r
-import org.argeo.slc.services.TestManagerService;\r
-import org.springframework.stereotype.Controller;\r
-import org.springframework.ui.Model;\r
-import org.springframework.util.PatternMatchUtils;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RequestParam;\r
-\r
-@Controller\r
-public class ServiceController {\r
-\r
-// private final static Log log = LogFactory.getLog(ServiceController.class);\r
-\r
- // Constants\r
- public final static String KEY_ANSWER = "__answer";\r
- protected final String FORCE_DOWNLOAD = "Content-Type: application/force-download";\r
-\r
- // IoC\r
- // FIXME : why must this be final ??\r
- private final TreeTestResultDao treeTestResultDao;\r
- private final TestManagerService testManagerService;\r
- private final TreeTestResultCollectionDao testResultCollectionDao;\r
- private final SlcAgentDescriptorDao slcAgentDescriptorDao;\r
- private AttachmentsStorage attachmentsStorage;\r
- private DynamicRuntime<?> dynamicRuntime;\r
-\r
- public ServiceController(TreeTestResultDao treeTestResultDao,\r
- TreeTestResultCollectionDao testResultCollectionDao,\r
- TestManagerService testManagerService,\r
- SlcAgentDescriptorDao slcAgentDescriptorDao) {\r
-\r
- this.testManagerService = testManagerService;\r
- this.treeTestResultDao = treeTestResultDao;\r
- this.testResultCollectionDao = testResultCollectionDao;\r
- this.slcAgentDescriptorDao = slcAgentDescriptorDao;\r
- }\r
-\r
- // Business Methods\r
- @RequestMapping("/isServerReady.service")\r
- protected ExecutionAnswer isServerReady(Model model) {\r
- // Does nothing for now, it will return an OK answer.\r
- return ExecutionAnswer.ok("Execution completed properly");\r
- }\r
-\r
- @RequestMapping("/shutdownRuntime.service")\r
- protected ExecutionAnswer shutdownRuntime(Model model) {\r
- new Thread() {\r
- public void run() {\r
- // wait in order to let call return\r
- try {\r
- Thread.sleep(3000);\r
- } catch (InterruptedException e) {\r
- // silent\r
- }\r
- dynamicRuntime.shutdown();\r
- }\r
- }.start();\r
- return ExecutionAnswer.ok("Server shutting down...");\r
- }\r
-\r
- @RequestMapping("/getResult.service")\r
- protected TreeTestResult getResult(\r
- @RequestParam(value = "uuid", required = false) String uuid) {\r
-\r
- TreeTestResult result = treeTestResultDao.getTestResult(uuid);\r
- if (result == null)\r
- throw new SlcException("No result found for uuid " + uuid);\r
- return result;\r
- }\r
-\r
- @RequestMapping("/addResultToCollection.service")\r
- protected ExecutionAnswer addResultToCollection(\r
- @RequestParam String collectionId, @RequestParam String resultUuid) {\r
- testManagerService.addResultToCollection(collectionId, resultUuid);\r
- return ExecutionAnswer.ok("Execution completed properly");\r
- }\r
-\r
- @RequestMapping("/removeResultFromCollection.service")\r
- protected ExecutionAnswer removeResultFromCollection(\r
- HttpServletRequest request) {\r
- String collectionId = request.getParameter("collectionId");\r
- String[] resultUuids = request.getParameterValues("resultUuid");\r
- String[] attrNames = request.getParameterValues("attrName");\r
- String[] attrPatterns = request.getParameterValues("attrPattern");\r
-\r
- // Checks\r
- if (collectionId == null)\r
- throw new SlcException("A collection id must be specified");\r
- if (attrNames != null\r
- && (attrPatterns == null || attrNames.length != attrPatterns.length))\r
- throw new SlcException(\r
- "There must be as many attrName as attrPatterns");\r
-\r
- // Remove specified results\r
- if (resultUuids != null)\r
- for (String resultUuid : resultUuids)\r
- testManagerService.removeResultFromCollection(collectionId,\r
- resultUuid);\r
-\r
- if (attrNames != null) {\r
- TreeTestResultCollection sourceCollection = testResultCollectionDao\r
- .getTestResultCollection(collectionId);\r
-\r
- int index = 0;\r
- for (String attrName : attrNames) {\r
- String attrPattern = attrPatterns[index];// safe: checked above\r
-\r
- List<TreeTestResult> results = new ArrayList<TreeTestResult>(\r
- sourceCollection.getResults());\r
- for (TreeTestResult treeTestResult : results) {\r
- if (PatternMatchUtils.simpleMatch(attrPattern,\r
- treeTestResult.getAttributes().get(attrName))) {\r
- testManagerService.removeResultFromCollection(\r
- collectionId, treeTestResult.getUuid());\r
- }\r
- }\r
- index++;\r
- }\r
- } else {\r
- if (resultUuids == null) {// no specs\r
- // remove all\r
- // TODO: optimize\r
- TreeTestResultCollection sourceCollection = testResultCollectionDao\r
- .getTestResultCollection(collectionId);\r
- List<TreeTestResult> results = new ArrayList<TreeTestResult>(\r
- sourceCollection.getResults());\r
- for (TreeTestResult treeTestResult : results) {\r
- testManagerService.removeResultFromCollection(collectionId,\r
- treeTestResult.getUuid());\r
- }\r
-\r
- }\r
- }\r
- return ExecutionAnswer.ok("Execution completed properly");\r
- }\r
-\r
- @RequestMapping("/listCollectionRefs.service")\r
- protected ReferenceList listCollectionRefs(HttpServletRequest request,\r
- HttpServletResponse response) {\r
-\r
- SortedSet<TreeTestResultCollection> results = testResultCollectionDao\r
- .listCollections();\r
-\r
- ReferenceList referenceList = new ReferenceList();\r
- for (TreeTestResultCollection collection : results) {\r
- referenceList.getReferences().add(collection.getId());\r
- }\r
- return referenceList;\r
- }\r
-\r
- @RequestMapping("/listResultAttributes.service")\r
- protected ObjectList listResultAttributes(@RequestParam String id, Model model) {\r
-\r
- List<ResultAttributes> resultAttributes = testResultCollectionDao\r
- .listResultAttributes(id);\r
- return new ObjectList(\r
- resultAttributes);\r
- }\r
-\r
- @RequestMapping("/listResults.service")\r
- @SuppressWarnings(value = { "unchecked" })\r
- protected ObjectList listResults(\r
- @RequestParam(value = "collectionId", required = false) String collectionId,\r
- HttpServletRequest request) {\r
- Map<String, String[]> parameterMap = request.getParameterMap();\r
- Map<String, String> attributes = new HashMap<String, String>();\r
- for (String parameter : parameterMap.keySet()) {\r
- if (parameter.startsWith("attr.")) {\r
- String key = parameter.substring("attr.".length());\r
- attributes.put(key, parameterMap.get(parameter)[0]);\r
- }\r
- }\r
-\r
- List<TreeTestResult> resultAttributes = testResultCollectionDao\r
- .listResults(collectionId, attributes);\r
- return new ObjectList(resultAttributes);\r
- }\r
-\r
- @RequestMapping("/copyCollectionToCollection.service")\r
- protected ExecutionAnswer copyCollectionToCollection(\r
- @RequestParam String sourceCollectionId,\r
- @RequestParam String targetCollectionId,\r
- HttpServletRequest request) {\r
-\r
- String[] attrNames = request.getParameterValues("attrName");\r
- String[] attrPatterns = request.getParameterValues("attrPattern");\r
-\r
- // Checks\r
- if (sourceCollectionId == null || targetCollectionId == null)\r
- throw new SlcException(\r
- "Source and target collection ids must be specified");\r
- if (attrNames != null\r
- && (attrPatterns == null || attrNames.length != attrPatterns.length))\r
- throw new SlcException(\r
- "There must be as many attrName as attrPatterns");\r
-\r
- TreeTestResultCollection sourceCollection = testResultCollectionDao\r
- .getTestResultCollection(sourceCollectionId);\r
- if (attrNames != null) {\r
- int index = 0;\r
- for (String attrName : attrNames) {\r
- String attrPattern = attrPatterns[index];// safe: checked above\r
-\r
- for (TreeTestResult treeTestResult : sourceCollection\r
- .getResults()) {\r
- if (PatternMatchUtils.simpleMatch(attrPattern,\r
- treeTestResult.getAttributes().get(attrName))) {\r
- testManagerService.addResultToCollection(\r
- targetCollectionId, treeTestResult.getUuid());\r
- }\r
- }\r
- index++;\r
- }\r
- } else {\r
- // remove all\r
- // TODO: optimize\r
- for (TreeTestResult treeTestResult : sourceCollection.getResults()) {\r
- testManagerService.addResultToCollection(targetCollectionId,\r
- treeTestResult.getUuid());\r
- }\r
- }\r
- return ExecutionAnswer.ok("Execution completed properly");\r
- }\r
-\r
- @RequestMapping("/listAgents.service")\r
- protected ObjectList listAgents() {\r
- List<SlcAgentDescriptor> list = slcAgentDescriptorDao\r
- .listSlcAgentDescriptors();\r
- return new ObjectList(list);\r
- }\r
-\r
- @RequestMapping("/cleanAgents.service")\r
- protected ExecutionAnswer cleanAgents() {\r
-\r
- List<SlcAgentDescriptor> list = slcAgentDescriptorDao\r
- .listSlcAgentDescriptors();\r
- for (SlcAgentDescriptor t : new Vector<SlcAgentDescriptor>(list)) {\r
- slcAgentDescriptorDao.delete(t);\r
- }\r
- return ExecutionAnswer.ok("Execution completed properly");\r
- }\r
-\r
- @RequestMapping("/getAttachment.service")\r
- protected void getAttachment(@RequestParam String uuid,\r
- @RequestParam String contentType, @RequestParam String name,\r
- HttpServletResponse response) throws Exception {\r
- if (contentType == null || "".equals(contentType.trim())) {\r
- if (name != null) {\r
- contentType = FORCE_DOWNLOAD;\r
- String ext = FilenameUtils.getExtension(name);\r
- // cf. http://en.wikipedia.org/wiki/Internet_media_type\r
- if ("csv".equals(ext))\r
- contentType = "text/csv";\r
- else if ("pdf".equals(ext))\r
- contentType = "application/pdf";\r
- else if ("zip".equals(ext))\r
- contentType = "application/zip";\r
- else if ("html".equals(ext))\r
- contentType = "application/html";\r
- else if ("txt".equals(ext))\r
- contentType = "text/plain";\r
- else if ("doc".equals(ext) || "docx".equals(ext))\r
- contentType = "application/msword";\r
- else if ("xls".equals(ext) || "xlsx".equals(ext))\r
- contentType = "application/vnd.ms-excel";\r
- else if ("xml".equals(ext))\r
- contentType = "text/xml";\r
- }\r
- }\r
-\r
- if (name != null) {\r
- contentType = contentType + ";name=\"" + name + "\"";\r
- response.setHeader("Content-Disposition", "attachment; filename=\""\r
- + name + "\"");\r
- }\r
- response.setHeader("Expires", "0");\r
- response.setHeader("Cache-Control", "no-cache, must-revalidate");\r
- response.setHeader("Pragma", "no-cache");\r
-\r
- SimpleAttachment resourceDescriptor = new SimpleAttachment();\r
- resourceDescriptor.setUuid(uuid);\r
- resourceDescriptor.setContentType(contentType);\r
-\r
- response.setContentType(contentType);\r
- ServletOutputStream outputStream = response.getOutputStream();\r
- attachmentsStorage.retrieveAttachment(resourceDescriptor, outputStream);\r
- }\r
-\r
- // IoC\r
-\r
- public void setDynamicRuntime(DynamicRuntime<?> dynamicRuntime) {\r
- this.dynamicRuntime = dynamicRuntime;\r
- }\r
-\r
- public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) {\r
- this.attachmentsStorage = attachmentsStorage;\r
- }\r
-}\r
--- /dev/null
+/*\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.controllers;\r
+\r
+import java.util.List;\r
+import java.util.Vector;\r
+\r
+import org.argeo.slc.dao.runtime.SlcAgentDescriptorDao;\r
+import org.argeo.slc.msg.ExecutionAnswer;\r
+import org.argeo.slc.msg.ObjectList;\r
+import org.argeo.slc.runtime.SlcAgentDescriptor;\r
+import org.springframework.stereotype.Controller;\r
+import org.springframework.web.bind.annotation.RequestMapping;\r
+\r
+/**\r
+ * Controle and information about the agents.\r
+ */\r
+\r
+@Controller\r
+public class AgentController {\r
+\r
+ // IoC\r
+ private SlcAgentDescriptorDao slcAgentDescriptorDao;\r
+\r
+ @RequestMapping("/listAgents.service")\r
+ protected ObjectList listAgents() {\r
+ List<SlcAgentDescriptor> list = slcAgentDescriptorDao\r
+ .listSlcAgentDescriptors();\r
+ return new ObjectList(list);\r
+ }\r
+\r
+ @RequestMapping("/cleanAgents.service")\r
+ protected ExecutionAnswer cleanAgents() {\r
+\r
+ List<SlcAgentDescriptor> list = slcAgentDescriptorDao\r
+ .listSlcAgentDescriptors();\r
+ for (SlcAgentDescriptor t : new Vector<SlcAgentDescriptor>(list)) {\r
+ slcAgentDescriptorDao.delete(t);\r
+ }\r
+ return ExecutionAnswer.ok("Execution completed properly");\r
+ }\r
+\r
+ // IoC\r
+ public void setSlcAgentDescriptorDao(\r
+ SlcAgentDescriptorDao slcAgentDescriptorDao) {\r
+ this.slcAgentDescriptorDao = slcAgentDescriptorDao;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\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.controllers;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.msg.ExecutionAnswer;\r
+import org.argeo.slc.msg.event.SlcEvent;\r
+import org.argeo.slc.msg.event.SlcEventListener;\r
+import org.argeo.slc.msg.event.SlcEventListenerDescriptor;\r
+import org.argeo.slc.msg.event.SlcEventListenerRegister;\r
+import org.springframework.stereotype.Controller;\r
+import org.springframework.web.bind.annotation.RequestMapping;\r
+import org.springframework.web.bind.annotation.RequestParam;\r
+\r
+@Controller\r
+public class EventController {\r
+\r
+ private final static Log log = LogFactory.getLog(EventController.class);\r
+\r
+ public final static String KEY_ANSWER = "__answer";\r
+ private Long defaultTimeout = 10000l;\r
+\r
+ // IoC\r
+ private SlcEventListenerRegister eventListenerRegister;\r
+ private SlcEventListener eventListener = null;\r
+\r
+ // Business Methods\r
+ @RequestMapping("/addEventListener.service")\r
+ public ExecutionAnswer addEventListener(\r
+ @RequestParam(SlcEvent.EVENT_TYPE) String eventType,\r
+ @RequestParam(value = SlcEvent.EVENT_FILTER, required = false) String eventFilter) {\r
+\r
+ eventListenerRegister\r
+ .addEventListenerDescriptor(new SlcEventListenerDescriptor(\r
+ eventType, eventFilter));\r
+ if (log.isTraceEnabled())\r
+ log.trace("Registered listener on register "\r
+ + eventListenerRegister.getId() + " for type " + eventType\r
+ + ", filter=" + eventFilter);\r
+ return ExecutionAnswer.ok("Execution completed properly");\r
+\r
+ }\r
+\r
+ @RequestMapping("/removeEventListener.service")\r
+ public ExecutionAnswer removeEventListener(\r
+ @RequestParam(SlcEvent.EVENT_TYPE) String eventType,\r
+ @RequestParam(value = SlcEvent.EVENT_FILTER, required = false) String eventFilter) {\r
+\r
+ eventListenerRegister\r
+ .removeEventListenerDescriptor(new SlcEventListenerDescriptor(\r
+ eventType, eventFilter));\r
+ if (log.isTraceEnabled())\r
+ log.trace("Removed listener from register "\r
+ + eventListenerRegister.getId() + " for type " + eventType\r
+ + ", filter=" + eventFilter);\r
+ return ExecutionAnswer.ok("Execution completed properly");\r
+ }\r
+\r
+ @RequestMapping("/pollEvent.service")\r
+ public Object pollEvent(\r
+ @RequestParam(value = "timeout", required = false) String timeoutStr) {\r
+ final Long timeout;\r
+ if (timeoutStr != null)\r
+ timeout = Long.parseLong(timeoutStr);\r
+ else\r
+ timeout = defaultTimeout;\r
+\r
+ SlcEvent event = eventListener.listen(eventListenerRegister.getId(),\r
+ eventListenerRegister.getDescriptorsCopy(), timeout);\r
+ if (event != null) {\r
+ return event;\r
+ } else {\r
+ return ExecutionAnswer.ok("Execution completed properly");\r
+ }\r
+ }\r
+\r
+ public void setEventListenerRegister(\r
+ SlcEventListenerRegister eventListenerRegister) {\r
+ this.eventListenerRegister = eventListenerRegister;\r
+ }\r
+\r
+ public void setDefaultTimeout(Long defaultTimeout) {\r
+ this.defaultTimeout = defaultTimeout;\r
+ }\r
+\r
+ public void setEventListener(SlcEventListener eventListener) {\r
+ this.eventListener = eventListener;\r
+ }\r
+}\r
--- /dev/null
+/*\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.controllers;\r
+\r
+import java.io.BufferedReader;\r
+import java.util.Comparator;\r
+import java.util.List;\r
+import java.util.SortedSet;\r
+import java.util.TreeSet;\r
+import java.util.UUID;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.core.attachment.AttachmentsStorage;\r
+import org.argeo.slc.dao.process.SlcExecutionDao;\r
+import org.argeo.slc.execution.ExecutionModuleDescriptor;\r
+import org.argeo.slc.msg.ExecutionAnswer;\r
+import org.argeo.slc.msg.MsgConstants;\r
+import org.argeo.slc.msg.ObjectList;\r
+import org.argeo.slc.process.SlcExecution;\r
+import org.argeo.slc.process.SlcExecutionStep;\r
+import org.argeo.slc.runtime.SlcAgent;\r
+import org.argeo.slc.runtime.SlcAgentFactory;\r
+import org.argeo.slc.services.SlcExecutionService;\r
+import org.springframework.oxm.Marshaller;\r
+import org.springframework.oxm.Unmarshaller;\r
+import org.springframework.stereotype.Controller;\r
+import org.springframework.ui.Model;\r
+import org.springframework.util.Assert;\r
+import org.springframework.web.bind.annotation.RequestMapping;\r
+import org.springframework.web.bind.annotation.RequestParam;\r
+import org.springframework.xml.transform.StringSource;\r
+\r
+@Controller\r
+public class ProcessController {\r
+\r
+ public final static String KEY_ANSWER = "__answer";\r
+ private final static Log log = LogFactory.getLog(ProcessController.class);\r
+\r
+ private SlcExecutionDao slcExecutionDao;\r
+ private SlcAgentFactory agentFactory;\r
+ private Unmarshaller unmarshaller;\r
+ private Marshaller marshaller;\r
+ private SlcExecutionService slcExecutionService;\r
+ private AttachmentsStorage attachmentsStorage;\r
+\r
+ private SlcExecutionManager slcExecutionManager;\r
+\r
+ @RequestMapping("/listSlcExecutions.service")\r
+ protected ObjectList listSlcExecutions() {\r
+ List<SlcExecution> list = slcExecutionDao.listSlcExecutions();\r
+ return new ObjectList(list);\r
+ }\r
+\r
+ @RequestMapping("/getExecutionDescriptor.service")\r
+ protected ExecutionModuleDescriptor getExecutionDescriptor(\r
+ @RequestParam String agentId, @RequestParam String moduleName,\r
+ @RequestParam String version) {\r
+\r
+ SlcAgent slcAgent = agentFactory.getAgent(agentId);\r
+\r
+ ExecutionModuleDescriptor md = slcAgent.getExecutionModuleDescriptor(\r
+ moduleName, version);\r
+ return md;\r
+ }\r
+\r
+ @RequestMapping("/listModulesDescriptors.service")\r
+ protected ObjectList listModulesDescriptors(@RequestParam String agentId) {\r
+ // TODO: use centralized agentId property (from MsgConstants)?\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
+ 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
+ return new ObjectList(set);\r
+ }\r
+\r
+ @RequestMapping("/getSlcExecution.service")\r
+ protected SlcExecution getSlcExecution(@RequestParam String uuid) {\r
+ SlcExecution slcExecution = slcExecutionDao.getSlcExecution(uuid);\r
+ initializeSEM();\r
+ slcExecutionManager.retrieveRealizedFlows(slcExecution);\r
+ return slcExecution;\r
+ }\r
+\r
+ @RequestMapping("/newSlcExecution.service")\r
+ protected ExecutionAnswer newSlcExecution(HttpServletRequest request,\r
+ Model model) throws Exception {\r
+\r
+ String agentId = request\r
+ .getParameter(MsgConstants.PROPERTY_SLC_AGENT_ID);\r
+ Assert.notNull(agentId, "agent id");\r
+\r
+ String answer = request.getParameter("body");\r
+ if (answer == null) {\r
+ // lets read the message body instead\r
+ BufferedReader reader = request.getReader();\r
+ StringBuffer buffer = new StringBuffer();\r
+ String line = null;\r
+ while (((line = reader.readLine()) != null)) {\r
+ buffer.append(line);\r
+ }\r
+ answer = buffer.toString();\r
+ }\r
+\r
+ if (log.isTraceEnabled())\r
+ log.debug("Received message:\n" + answer);\r
+\r
+ StringSource source = new StringSource(answer);\r
+ SlcExecution slcExecution = (SlcExecution) unmarshaller\r
+ .unmarshal(source);\r
+\r
+ // Workaround for https://www.argeo.org/bugzilla/show_bug.cgi?id=86\r
+ if (slcExecution.getUuid() == null\r
+ || slcExecution.getUuid().length() < 8)\r
+ slcExecution.setUuid(UUID.randomUUID().toString());\r
+\r
+ slcExecution.setStatus(SlcExecution.STATUS_SCHEDULED);\r
+ slcExecution.getSteps().add(\r
+ new SlcExecutionStep(SlcExecutionStep.TYPE_START,\r
+ "Process started from the Web UI"));\r
+\r
+ initializeSEM();\r
+ slcExecutionManager.storeRealizedFlows(slcExecution);\r
+ slcExecutionService.newExecution(slcExecution);\r
+ SlcAgent agent = agentFactory.getAgent(agentId);\r
+ agent.runSlcExecution(slcExecution);\r
+\r
+ return ExecutionAnswer.ok("Execution completed properly");\r
+ }\r
+\r
+ private void initializeSEM() {\r
+ slcExecutionManager = new SlcExecutionManager(unmarshaller, marshaller,\r
+ attachmentsStorage);\r
+ }\r
+\r
+ public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao) {\r
+ this.slcExecutionDao = slcExecutionDao;\r
+ }\r
+\r
+ public void setSlcExecutionService(SlcExecutionService slcExecutionService) {\r
+ this.slcExecutionService = slcExecutionService;\r
+ }\r
+\r
+ public void setUnmarshaller(Unmarshaller unmarshaller) {\r
+ this.unmarshaller = unmarshaller;\r
+ }\r
+\r
+ public void setMarshaller(Marshaller marshaller) {\r
+ this.marshaller = marshaller;\r
+ }\r
+\r
+ public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) {\r
+ this.attachmentsStorage = attachmentsStorage;\r
+ }\r
+\r
+ public void setAgentFactory(SlcAgentFactory agentFactory) {\r
+ this.agentFactory = agentFactory;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\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.controllers;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.SlcException;\r
+import org.argeo.slc.core.test.tree.TreeTestResult;\r
+import org.argeo.slc.dao.test.tree.TreeTestResultDao;\r
+import org.argeo.slc.web.mvc.result.ResultExcelView;\r
+import org.argeo.slc.web.mvc.result.ResultPdfView;\r
+import org.springframework.stereotype.Controller;\r
+import org.springframework.web.bind.annotation.RequestMapping;\r
+import org.springframework.web.bind.annotation.RequestParam;\r
+import org.springframework.web.servlet.ModelAndView;\r
+\r
+/**\r
+ * Sends back the results, rendered or as collection.\r
+ */\r
+\r
+@Controller\r
+public class RenderingResultController {\r
+ private final static Log log = LogFactory.getLog(RenderingResultController.class);\r
+\r
+ public final static String KEY_ANSWER = "__answer";\r
+ public final static String MODELKEY_RESULT = "result";\r
+\r
+ // IoC\r
+ private TreeTestResultDao testResultDao;\r
+ private ResultExcelView resultExcelView;\r
+ private ResultPdfView resultPdfView;\r
+\r
+ @RequestMapping("/resultView.pdf")\r
+ public void getPdfResultView(@RequestParam(value = "uuid") String uuid,\r
+ ModelAndView modelAndView) {\r
+ TreeTestResult result = testResultDao.getTestResult(uuid);\r
+ if (result == null)\r
+ throw new SlcException("No result found for uuid " + uuid);\r
+ modelAndView.getModelMap().addAttribute(MODELKEY_RESULT, result);\r
+ modelAndView.setView(resultPdfView);\r
+ }\r
+\r
+ @RequestMapping("/resultView.xls")\r
+ public void getXlsResultView(@RequestParam(value = "uuid") String uuid,\r
+ ModelAndView modelAndView) {\r
+ TreeTestResult result = testResultDao.getTestResult(uuid);\r
+ if (result == null)\r
+ throw new SlcException("No result found for uuid " + uuid);\r
+ modelAndView.getModelMap().addAttribute(MODELKEY_RESULT, result);\r
+ modelAndView.setView(resultExcelView);\r
+ }\r
+\r
+ public void setResultExcelView(ResultExcelView resultExcelView) {\r
+ this.resultExcelView = resultExcelView;\r
+ }\r
+\r
+ public void setResultPdfView(ResultPdfView resultPdfView) {\r
+ this.resultPdfView = resultPdfView;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\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.controllers;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.SortedSet;\r
+\r
+import javax.servlet.ServletOutputStream;\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+import org.apache.commons.io.FilenameUtils;\r
+import org.argeo.slc.SlcException;\r
+import org.argeo.slc.core.attachment.AttachmentsStorage;\r
+import org.argeo.slc.core.attachment.SimpleAttachment;\r
+import org.argeo.slc.core.test.tree.ResultAttributes;\r
+import org.argeo.slc.core.test.tree.TreeTestResult;\r
+import org.argeo.slc.core.test.tree.TreeTestResultCollection;\r
+import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;\r
+import org.argeo.slc.dao.test.tree.TreeTestResultDao;\r
+import org.argeo.slc.msg.ExecutionAnswer;\r
+import org.argeo.slc.msg.ObjectList;\r
+import org.argeo.slc.msg.ReferenceList;\r
+import org.argeo.slc.services.TestManagerService;\r
+import org.springframework.stereotype.Controller;\r
+import org.springframework.ui.Model;\r
+import org.springframework.util.PatternMatchUtils;\r
+import org.springframework.web.bind.annotation.RequestMapping;\r
+import org.springframework.web.bind.annotation.RequestParam;\r
+\r
+@Controller\r
+public class ResultController {\r
+\r
+ // private final static Log log =\r
+ // LogFactory.getLog(ServiceController.class);\r
+\r
+ // Constants\r
+ public final static String KEY_ANSWER = "__answer";\r
+ protected final String FORCE_DOWNLOAD = "Content-Type: application/force-download";\r
+\r
+ // IoC\r
+ private TreeTestResultDao treeTestResultDao;\r
+ private TreeTestResultCollectionDao treeTestResultCollectionDao;\r
+ private TestManagerService testManagerService;\r
+ private AttachmentsStorage attachmentsStorage;\r
+\r
+ // Business Methods\r
+ @RequestMapping("/getResult.service")\r
+ protected TreeTestResult getResult(\r
+ @RequestParam(value = "uuid", required = false) String uuid) {\r
+\r
+ TreeTestResult result = treeTestResultDao.getTestResult(uuid);\r
+ if (result == null)\r
+ throw new SlcException("No result found for uuid " + uuid);\r
+ return result;\r
+ }\r
+\r
+ @RequestMapping("/addResultToCollection.service")\r
+ protected ExecutionAnswer addResultToCollection(\r
+ @RequestParam String collectionId, @RequestParam String resultUuid) {\r
+ testManagerService.addResultToCollection(collectionId, resultUuid);\r
+ return ExecutionAnswer.ok("Execution completed properly");\r
+ }\r
+\r
+ @RequestMapping("/removeResultFromCollection.service")\r
+ protected ExecutionAnswer removeResultFromCollection(\r
+ HttpServletRequest request) {\r
+ String collectionId = request.getParameter("collectionId");\r
+ String[] resultUuids = request.getParameterValues("resultUuid");\r
+ String[] attrNames = request.getParameterValues("attrName");\r
+ String[] attrPatterns = request.getParameterValues("attrPattern");\r
+\r
+ // Checks\r
+ if (collectionId == null)\r
+ throw new SlcException("A collection id must be specified");\r
+ if (attrNames != null\r
+ && (attrPatterns == null || attrNames.length != attrPatterns.length))\r
+ throw new SlcException(\r
+ "There must be as many attrName as attrPatterns");\r
+\r
+ // Remove specified results\r
+ if (resultUuids != null)\r
+ for (String resultUuid : resultUuids)\r
+ testManagerService.removeResultFromCollection(collectionId,\r
+ resultUuid);\r
+\r
+ if (attrNames != null) {\r
+ TreeTestResultCollection sourceCollection = treeTestResultCollectionDao\r
+ .getTestResultCollection(collectionId);\r
+\r
+ int index = 0;\r
+ for (String attrName : attrNames) {\r
+ String attrPattern = attrPatterns[index];// safe: checked above\r
+\r
+ List<TreeTestResult> results = new ArrayList<TreeTestResult>(\r
+ sourceCollection.getResults());\r
+ for (TreeTestResult treeTestResult : results) {\r
+ if (PatternMatchUtils.simpleMatch(attrPattern,\r
+ treeTestResult.getAttributes().get(attrName))) {\r
+ testManagerService.removeResultFromCollection(\r
+ collectionId, treeTestResult.getUuid());\r
+ }\r
+ }\r
+ index++;\r
+ }\r
+ } else {\r
+ if (resultUuids == null) {// no specs\r
+ // remove all\r
+ // TODO: optimize\r
+ TreeTestResultCollection sourceCollection = treeTestResultCollectionDao\r
+ .getTestResultCollection(collectionId);\r
+ List<TreeTestResult> results = new ArrayList<TreeTestResult>(\r
+ sourceCollection.getResults());\r
+ for (TreeTestResult treeTestResult : results) {\r
+ testManagerService.removeResultFromCollection(collectionId,\r
+ treeTestResult.getUuid());\r
+ }\r
+\r
+ }\r
+ }\r
+ return ExecutionAnswer.ok("Execution completed properly");\r
+ }\r
+\r
+ @RequestMapping("/listCollectionRefs.service")\r
+ protected ReferenceList listCollectionRefs(HttpServletRequest request,\r
+ HttpServletResponse response) {\r
+\r
+ SortedSet<TreeTestResultCollection> results = treeTestResultCollectionDao\r
+ .listCollections();\r
+\r
+ ReferenceList referenceList = new ReferenceList();\r
+ for (TreeTestResultCollection collection : results) {\r
+ referenceList.getReferences().add(collection.getId());\r
+ }\r
+ return referenceList;\r
+ }\r
+\r
+ @RequestMapping("/listResultAttributes.service")\r
+ protected ObjectList listResultAttributes(@RequestParam String id,\r
+ Model model) {\r
+\r
+ List<ResultAttributes> resultAttributes = treeTestResultCollectionDao\r
+ .listResultAttributes(id);\r
+ return new ObjectList(resultAttributes);\r
+ }\r
+\r
+ @RequestMapping("/listResults.service")\r
+ @SuppressWarnings(value = { "unchecked" })\r
+ protected ObjectList listResults(\r
+ @RequestParam(value = "collectionId", required = false) String collectionId,\r
+ HttpServletRequest request) {\r
+ Map<String, String[]> parameterMap = request.getParameterMap();\r
+ Map<String, String> attributes = new HashMap<String, String>();\r
+ for (String parameter : parameterMap.keySet()) {\r
+ if (parameter.startsWith("attr.")) {\r
+ String key = parameter.substring("attr.".length());\r
+ attributes.put(key, parameterMap.get(parameter)[0]);\r
+ }\r
+ }\r
+\r
+ List<TreeTestResult> resultAttributes = treeTestResultCollectionDao\r
+ .listResults(collectionId, attributes);\r
+ return new ObjectList(resultAttributes);\r
+ }\r
+\r
+ @RequestMapping("/copyCollectionToCollection.service")\r
+ protected ExecutionAnswer copyCollectionToCollection(\r
+ @RequestParam String sourceCollectionId,\r
+ @RequestParam String targetCollectionId, HttpServletRequest request) {\r
+\r
+ String[] attrNames = request.getParameterValues("attrName");\r
+ String[] attrPatterns = request.getParameterValues("attrPattern");\r
+\r
+ // Checks\r
+ if (sourceCollectionId == null || targetCollectionId == null)\r
+ throw new SlcException(\r
+ "Source and target collection ids must be specified");\r
+ if (attrNames != null\r
+ && (attrPatterns == null || attrNames.length != attrPatterns.length))\r
+ throw new SlcException(\r
+ "There must be as many attrName as attrPatterns");\r
+\r
+ TreeTestResultCollection sourceCollection = treeTestResultCollectionDao\r
+ .getTestResultCollection(sourceCollectionId);\r
+ if (attrNames != null) {\r
+ int index = 0;\r
+ for (String attrName : attrNames) {\r
+ String attrPattern = attrPatterns[index];// safe: checked above\r
+\r
+ for (TreeTestResult treeTestResult : sourceCollection\r
+ .getResults()) {\r
+ if (PatternMatchUtils.simpleMatch(attrPattern,\r
+ treeTestResult.getAttributes().get(attrName))) {\r
+ testManagerService.addResultToCollection(\r
+ targetCollectionId, treeTestResult.getUuid());\r
+ }\r
+ }\r
+ index++;\r
+ }\r
+ } else {\r
+ // remove all\r
+ // TODO: optimize\r
+ for (TreeTestResult treeTestResult : sourceCollection.getResults()) {\r
+ testManagerService.addResultToCollection(targetCollectionId,\r
+ treeTestResult.getUuid());\r
+ }\r
+ }\r
+ return ExecutionAnswer.ok("Execution completed properly");\r
+ }\r
+\r
+ @RequestMapping("/getAttachment.service")\r
+ protected void getAttachment(@RequestParam String uuid,\r
+ @RequestParam String contentType, @RequestParam String name,\r
+ HttpServletResponse response) throws Exception {\r
+ if (contentType == null || "".equals(contentType.trim())) {\r
+ if (name != null) {\r
+ contentType = FORCE_DOWNLOAD;\r
+ String ext = FilenameUtils.getExtension(name);\r
+ // cf. http://en.wikipedia.org/wikServicei/Internet_media_type\r
+ if ("csv".equals(ext))\r
+ contentType = "text/csv";\r
+ else if ("pdf".equals(ext))\r
+ contentType = "application/pdf";\r
+ else if ("zip".equals(ext))\r
+ contentType = "application/zip";\r
+ else if ("html".equals(ext))\r
+ contentType = "application/html";\r
+ else if ("txt".equals(ext))\r
+ contentType = "text/plain";\r
+ else if ("doc".equals(ext) || "docx".equals(ext))\r
+ contentType = "application/msword";\r
+ else if ("xls".equals(ext) || "xlsx".equals(ext))\r
+ contentType = "application/vnd.ms-excel";\r
+ else if ("xml".equals(ext))\r
+ contentType = "text/xml";\r
+ }\r
+ }\r
+\r
+ if (name != null) {\r
+ contentType = contentType + ";name=\"" + name + "\"";\r
+ response.setHeader("Content-Disposition", "attachment; filename=\""\r
+ + name + "\"");\r
+ }\r
+ response.setHeader("Expires", "0");\r
+ response.setHeader("Cache-Control", "no-cache, must-revalidate");\r
+ response.setHeader("Pragma", "no-cache");\r
+\r
+ SimpleAttachment resourceDescriptor = new SimpleAttachment();\r
+ resourceDescriptor.setUuid(uuid);\r
+ resourceDescriptor.setContentType(contentType);\r
+\r
+ response.setContentType(contentType);\r
+ ServletOutputStream outputStream = response.getOutputStream();\r
+ attachmentsStorage.retrieveAttachment(resourceDescriptor, outputStream);\r
+ }\r
+\r
+ // IoC\r
+\r
+ public void setTreeTestResultDao(TreeTestResultDao treeTestResultDao) {\r
+ this.treeTestResultDao = treeTestResultDao;\r
+ }\r
+\r
+ public void setTestManagerService(TestManagerService testManagerService) {\r
+ this.testManagerService = testManagerService;\r
+ }\r
+\r
+ public void setTreeTestResultCollectionDao(\r
+ TreeTestResultCollectionDao treeTestResultCollectionDao) {\r
+ this.treeTestResultCollectionDao = treeTestResultCollectionDao;\r
+ }\r
+\r
+ public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) {\r
+ this.attachmentsStorage = attachmentsStorage;\r
+ }\r
+}\r
--- /dev/null
+/*\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.controllers;\r
+\r
+import java.util.List;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+\r
+import org.apache.commons.fileupload.FileItem;\r
+import org.apache.commons.fileupload.FileItemFactory;\r
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;\r
+import org.apache.commons.fileupload.servlet.ServletFileUpload;\r
+import org.argeo.slc.build.BasicNameVersion;\r
+import org.argeo.slc.build.NameVersion;\r
+import org.argeo.slc.core.build.ResourceDistribution;\r
+import org.argeo.slc.deploy.DynamicRuntime;\r
+import org.argeo.slc.deploy.Module;\r
+import org.argeo.slc.msg.ExecutionAnswer;\r
+import org.springframework.core.io.ByteArrayResource;\r
+import org.springframework.stereotype.Controller;\r
+import org.springframework.ui.Model;\r
+import org.springframework.web.bind.annotation.RequestMapping;\r
+import org.springframework.web.bind.annotation.RequestParam;\r
+\r
+/**\r
+ * Sends back the results, rendered or as collection.\r
+ */\r
+\r
+@Controller\r
+public class ServerController {\r
+ public final static String KEY_ANSWER = "__answer";\r
+\r
+ // IoC\r
+ private DynamicRuntime<?> dynamicRuntime;\r
+\r
+ // Create a factory for disk-based file items\r
+ private FileItemFactory factory = new DiskFileItemFactory();\r
+ // Create a new file upload handler\r
+ private ServletFileUpload upload = new ServletFileUpload(factory);\r
+\r
+ // SERVER HANDLING\r
+\r
+ @RequestMapping("/isServerReady.service")\r
+ protected ExecutionAnswer isServerReady(Model model) {\r
+ // Does nothing for now, it will return an OK answer.\r
+ return ExecutionAnswer.ok("Execution completed properly");\r
+ }\r
+\r
+ @RequestMapping("/shutdownRuntime.service")\r
+ protected ExecutionAnswer shutdownRuntime(Model model) {\r
+ new Thread() {\r
+ public void run() {\r
+ // wait in order to let call return\r
+ try {\r
+ Thread.sleep(3000);\r
+ } catch (InterruptedException e) {\r
+ // silent\r
+ }\r
+ dynamicRuntime.shutdown();\r
+ }\r
+ }.start();\r
+ return ExecutionAnswer.ok("Server shutting down...");\r
+ }\r
+\r
+ // MODULE HANDLING\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @RequestMapping("/installModule.service")\r
+ public void installModule(HttpServletRequest request) throws Exception {\r
+\r
+ // TODO : handle the exception better\r
+\r
+ // Parse the request\r
+ List<FileItem> items = upload.parseRequest(request);\r
+\r
+ byte[] arr = null;\r
+ for (FileItem item : items) {\r
+ if (!item.isFormField()) {\r
+ arr = item.get();\r
+ break;\r
+ }\r
+ }\r
+\r
+ ByteArrayResource res = new ByteArrayResource(arr);\r
+ Module module = dynamicRuntime.installModule(new ResourceDistribution(\r
+ res));\r
+ // TODO: customize whether the module is started or not\r
+ dynamicRuntime.startModule(module);\r
+ }\r
+\r
+ @RequestMapping("/uninstallModule.service")\r
+ public void uninstallModule(@RequestParam(value = "name") String name,\r
+ @RequestParam(value = "version") String version) {\r
+ NameVersion nameVersion = new BasicNameVersion(name, version);\r
+ dynamicRuntime.uninstallModule(nameVersion);\r
+ }\r
+\r
+ // IoC\r
+ public void setDynamicRuntime(DynamicRuntime<?> dynamicRuntime) {\r
+ this.dynamicRuntime = dynamicRuntime;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\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.controllers;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.InputStream;\r
+import java.util.UUID;\r
+\r
+import javax.xml.transform.stream.StreamSource;\r
+\r
+import org.apache.commons.io.IOUtils;\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.core.attachment.Attachment;\r
+import org.argeo.slc.core.attachment.AttachmentsStorage;\r
+import org.argeo.slc.core.attachment.SimpleAttachment;\r
+import org.argeo.slc.msg.ObjectList;\r
+import org.argeo.slc.process.SlcExecution;\r
+import org.springframework.oxm.Marshaller;\r
+import org.springframework.oxm.Unmarshaller;\r
+import org.springframework.xml.transform.StringResult;\r
+\r
+public class SlcExecutionManager {\r
+ private final static Log log = LogFactory.getLog(SlcExecutionManager.class);\r
+\r
+ private Unmarshaller unmarshaller;\r
+ private Marshaller marshaller;\r
+ private AttachmentsStorage attachmentsStorage;\r
+\r
+ public SlcExecutionManager(Unmarshaller unmarshaller,\r
+ Marshaller marshaller, AttachmentsStorage attachmentsStorage) {\r
+\r
+ this.unmarshaller = unmarshaller;\r
+ this.marshaller = marshaller;\r
+ this.attachmentsStorage = attachmentsStorage;\r
+ }\r
+\r
+ void storeRealizedFlows(SlcExecution slcExecution) {\r
+\r
+ Attachment attachment = realizedFlowsAttachment(UUID.randomUUID()\r
+ .toString(), slcExecution);\r
+ InputStream in = null;\r
+ try {\r
+ ObjectList ol = new ObjectList(slcExecution.getRealizedFlows());\r
+ StringResult result = new StringResult();\r
+ marshaller.marshal(ol, result);\r
+ in = new ByteArrayInputStream(result.toString().getBytes());\r
+ attachmentsStorage.storeAttachment(attachment, in);\r
+\r
+ slcExecution.setRealizedFlowsXml(attachment.getUuid());\r
+ } catch (Exception e) {\r
+ log.error("Could not store realized flows as attachment #"\r
+ + attachment.getUuid(), e);\r
+ } finally {\r
+ IOUtils.closeQuietly(in);\r
+ }\r
+ }\r
+\r
+ void retrieveRealizedFlows(SlcExecution slcExecution) {\r
+ Attachment attachment = realizedFlowsAttachment(slcExecution\r
+ .getRealizedFlowsXml(), slcExecution);\r
+\r
+ ByteArrayOutputStream out = null;\r
+ ByteArrayInputStream in = null;\r
+ try {\r
+ // TODO: optimize with piped streams\r
+ out = new ByteArrayOutputStream();\r
+ attachmentsStorage.retrieveAttachment(attachment, out);\r
+\r
+ byte[] arr = out.toByteArray();\r
+ in = new ByteArrayInputStream(arr);\r
+ StreamSource source = new StreamSource(in);\r
+ ObjectList ol = (ObjectList) unmarshaller.unmarshal(source);\r
+ ol.fill(slcExecution.getRealizedFlows());\r
+ } catch (Exception e) {\r
+ log.error("Could not retrieve realized flows from attachment #"\r
+ + attachment.getUuid(), e);\r
+ } finally {\r
+ IOUtils.closeQuietly(in);\r
+ IOUtils.closeQuietly(out);\r
+ }\r
+ }\r
+\r
+ /** Unify labeling in the package */\r
+ static Attachment realizedFlowsAttachment(String attachmentUuid,\r
+ SlcExecution slcExecution) {\r
+ return new SimpleAttachment(attachmentUuid,\r
+ "RealizedFlows of SlcExecution #" + slcExecution.getUuid(),\r
+ "text/xml");\r
+ }\r
+}\r
+++ /dev/null
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * Licensed 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.argeo.slc.web.mvc.management;
-
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.fileupload.FileItem;
-import org.apache.commons.fileupload.FileItemFactory;
-import org.apache.commons.fileupload.disk.DiskFileItemFactory;
-import org.apache.commons.fileupload.servlet.ServletFileUpload;
-import org.argeo.slc.core.build.ResourceDistribution;
-import org.argeo.slc.deploy.DynamicRuntime;
-import org.argeo.slc.deploy.Module;
-import org.argeo.slc.web.mvc.AbstractServiceController;
-import org.springframework.core.io.ByteArrayResource;
-import org.springframework.web.servlet.ModelAndView;
-
-public class InstallModule extends AbstractServiceController {// extends
- private DynamicRuntime<?> dynamicRuntime;
-
- // Create a factory for disk-based file items
- private FileItemFactory factory = new DiskFileItemFactory();
-
- // Create a new file upload handler
- private ServletFileUpload upload = new ServletFileUpload(factory);
-
- @Override
- @SuppressWarnings(value = { "unchecked" })
- protected void handleServiceRequest(HttpServletRequest request,
- HttpServletResponse response, ModelAndView modelAndView)
- throws Exception {
- // Parse the request
- List<FileItem> items = upload.parseRequest(request);
-
- byte[] arr = null;
- for (FileItem item : items) {
- if (!item.isFormField()) {
- arr = item.get();
- break;
- }
- }
-
- ByteArrayResource res = new ByteArrayResource(arr);
- Module module = dynamicRuntime.installModule(new ResourceDistribution(
- res));
-
- // TODO: customize whether the module is started or not
- dynamicRuntime.startModule(module);
- }
-
- // protected ModelAndView onSubmit(HttpServletRequest request,
- // HttpServletResponse response, Object command, BindException errors)
- // throws Exception {
- // FileUploadBean bean = (FileUploadBean) command;
- //
- // byte[] file = bean.getFile();
- // if (file == null) {
- // throw new SlcException("Upload is empty.");
- // }
- //
- // ByteArrayResource res = new ByteArrayResource(file);
- // dynamicRuntime.installModule(new ResourceDistribution(res));
- //
- // return super.onSubmit(request, response, command, errors);
- // }
- //
- // protected void initBinder(HttpServletRequest request,
- // ServletRequestDataBinder binder) throws ServletException {
- // // to actually be able to convert Multipart instance to byte[]
- // // we have to register a custom editor
- // binder.registerCustomEditor(byte[].class,
- // new ByteArrayMultipartFileEditor());
- // // now Spring knows how to handle multipart object and convert them
- // }
-
- public void setDynamicRuntime(DynamicRuntime<?> dynamicRuntime) {
- this.dynamicRuntime = dynamicRuntime;
- }
-
-}
+++ /dev/null
-/*\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.management;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import org.argeo.slc.build.BasicNameVersion;\r
-import org.argeo.slc.build.NameVersion;\r
-import org.argeo.slc.deploy.DynamicRuntime;\r
-import org.argeo.slc.web.mvc.AbstractServiceController;\r
-import org.springframework.web.servlet.ModelAndView;\r
-\r
-/** . */\r
-public class UninstallModule extends AbstractServiceController {\r
- private DynamicRuntime<?> dynamicRuntime;\r
-\r
- @Override\r
- protected void handleServiceRequest(HttpServletRequest request,\r
- HttpServletResponse response, ModelAndView modelAndView)\r
- throws Exception {\r
- String name = request.getParameter("name");\r
- String version = request.getParameter("version");\r
- NameVersion nameVersion = new BasicNameVersion(name, version);\r
- dynamicRuntime.uninstallModule(nameVersion);\r
- }\r
-\r
- public void setDynamicRuntime(DynamicRuntime<?> dynamicRuntime) {\r
- this.dynamicRuntime = dynamicRuntime;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\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.process;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.InputStream;\r
-import java.util.UUID;\r
-\r
-import javax.xml.transform.stream.StreamSource;\r
-\r
-import org.apache.commons.io.IOUtils;\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.core.attachment.Attachment;\r
-import org.argeo.slc.core.attachment.AttachmentsStorage;\r
-import org.argeo.slc.core.attachment.SimpleAttachment;\r
-import org.argeo.slc.msg.ObjectList;\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.runtime.SlcAgentFactory;\r
-import org.argeo.slc.services.SlcExecutionService;\r
-import org.springframework.oxm.Marshaller;\r
-import org.springframework.oxm.Unmarshaller;\r
-import org.springframework.xml.transform.StringResult;\r
-\r
-public class SlcExecutionManager {\r
- private final static Log log = LogFactory.getLog(SlcExecutionManager.class);\r
-\r
- private SlcAgentFactory agentFactory;\r
- private Unmarshaller unmarshaller;\r
- private Marshaller marshaller;\r
- private SlcExecutionService slcExecutionService;\r
- private AttachmentsStorage attachmentsStorage;\r
-\r
- public SlcExecutionManager(SlcAgentFactory agentFactory,\r
- Unmarshaller unmarshaller, Marshaller marshaller,\r
- SlcExecutionService slcExecutionService,\r
- AttachmentsStorage attachmentsStorage) {\r
-\r
- this.agentFactory = agentFactory;\r
- this.unmarshaller = unmarshaller;\r
- this.marshaller = marshaller;\r
- this.slcExecutionService = slcExecutionService;\r
- this.attachmentsStorage = attachmentsStorage;\r
- }\r
-\r
- public void storeRealizedFlows(SlcExecution slcExecution) {\r
-\r
- Attachment attachment = realizedFlowsAttachment(UUID.randomUUID()\r
- .toString(), slcExecution);\r
- InputStream in = null;\r
- try {\r
- ObjectList ol = new ObjectList(slcExecution.getRealizedFlows());\r
- StringResult result = new StringResult();\r
- marshaller.marshal(ol, result);\r
- in = new ByteArrayInputStream(result.toString().getBytes());\r
- attachmentsStorage.storeAttachment(attachment, in);\r
-\r
- slcExecution.setRealizedFlowsXml(attachment.getUuid());\r
- } catch (Exception e) {\r
- log.error("Could not store realized flows as attachment #"\r
- + attachment.getUuid(), e);\r
- } finally {\r
- IOUtils.closeQuietly(in);\r
- }\r
- }\r
-\r
- public void retrieveRealizedFlows(SlcExecution slcExecution) {\r
- Attachment attachment = realizedFlowsAttachment(slcExecution\r
- .getRealizedFlowsXml(), slcExecution);\r
-\r
- ByteArrayOutputStream out = null;\r
- ByteArrayInputStream in = null;\r
- try {\r
- // TODO: optimize with piped streams\r
- out = new ByteArrayOutputStream();\r
- attachmentsStorage.retrieveAttachment(attachment, out);\r
-\r
- byte[] arr = out.toByteArray();\r
- in = new ByteArrayInputStream(arr);\r
- StreamSource source = new StreamSource(in);\r
- ObjectList ol = (ObjectList) unmarshaller.unmarshal(source);\r
- ol.fill(slcExecution.getRealizedFlows());\r
- } catch (Exception e) {\r
- log.error("Could not retrieve realized flows from attachment #"\r
- + attachment.getUuid(), e);\r
- } finally {\r
- IOUtils.closeQuietly(in);\r
- IOUtils.closeQuietly(out);\r
- }\r
- }\r
-\r
- /** Unify labeling in the package */\r
- static Attachment realizedFlowsAttachment(String attachmentUuid,\r
- SlcExecution slcExecution) {\r
- return new SimpleAttachment(attachmentUuid,\r
- "RealizedFlows of SlcExecution #" + slcExecution.getUuid(),\r
- "text/xml");\r
- }\r
-}\r
import org.springframework.web.servlet.view.document.AbstractJExcelView;
public class ResultExcelView extends AbstractJExcelView {
- @SuppressWarnings(value={"unchecked"})
+ public final static String MODELKEY_RESULT = "result";
+
+
+ @SuppressWarnings(value = { "unchecked" })
protected void buildExcelDocument(Map model, WritableWorkbook workbook,
HttpServletRequest request, HttpServletResponse response) {
try {
WritableSheet sheet = workbook.getSheet("SLC");
TreeTestResult ttr = (TreeTestResult) model
- .get(GetResultController.MODELKEY_RESULT);
+ .get(MODELKEY_RESULT);
sheet.addCell(new Label(0, 0, "Result " + ttr.getUuid()));
import com.lowagie.text.pdf.PdfWriter;
public class ResultPdfView extends AbstractPdfView {
+ public final static String MODELKEY_RESULT = "result";
@Override
- @SuppressWarnings(value={"unchecked"})
+ @SuppressWarnings(value = { "unchecked" })
protected void buildPdfDocument(Map model, Document document,
PdfWriter writer, HttpServletRequest request,
HttpServletResponse response) throws Exception {
- TreeTestResult ttr = (TreeTestResult) model
- .get(GetResultController.MODELKEY_RESULT);
+ TreeTestResult ttr = (TreeTestResult) model.get(MODELKEY_RESULT);
document.addTitle("Result " + ttr.getUuid());
document.add(new Paragraph("Result " + ttr.getUuid()));