From: Bruno Sinou Date: Tue, 13 Jul 2010 15:26:28 +0000 (+0000) Subject: clean org.argeo.slc.server project: X-Git-Tag: argeo-slc-2.1.7~1243 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=41a706c58c65015800bbc66a4f86f16195bb886f;hp=f49d8d8dccff9dcd196ac3e89f0cbd0dc4881ba2;p=gpl%2Fargeo-slc.git clean org.argeo.slc.server project: + removing empty packages + gather all controller in mvc.controllers package + remove unused controllers. + re-organize controllers by job + clean annotation handling for doc-servlet git-svn-id: https://svn.argeo.org/slc/trunk@3676 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/modules/server/org.argeo.slc.webapp.war/META-INF/MANIFEST.MF b/modules/server/org.argeo.slc.webapp.war/META-INF/MANIFEST.MF index c7d1117d0..396c89871 100644 --- a/modules/server/org.argeo.slc.webapp.war/META-INF/MANIFEST.MF +++ b/modules/server/org.argeo.slc.webapp.war/META-INF/MANIFEST.MF @@ -27,8 +27,7 @@ Import-Package: javax.jcr;specification-version="1.0.0", 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, diff --git a/modules/server/org.argeo.slc.webapp.war/WEB-INF/doc-servlet.xml b/modules/server/org.argeo.slc.webapp.war/WEB-INF/doc-servlet.xml index ae5bfea03..5528640f3 100644 --- a/modules/server/org.argeo.slc.webapp.war/WEB-INF/doc-servlet.xml +++ b/modules/server/org.argeo.slc.webapp.war/WEB-INF/doc-servlet.xml @@ -3,24 +3,26 @@ 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"> - - - - - + + + + - - - + + - + + @@ -28,10 +30,8 @@ - - \ No newline at end of file diff --git a/modules/server/org.argeo.slc.webapp.war/WEB-INF/slc-service-servlet.xml b/modules/server/org.argeo.slc.webapp.war/WEB-INF/slc-service-servlet.xml index cce50ea25..8fcd3d19b 100644 --- a/modules/server/org.argeo.slc.webapp.war/WEB-INF/slc-service-servlet.xml +++ b/modules/server/org.argeo.slc.webapp.war/WEB-INF/slc-service-servlet.xml @@ -7,10 +7,15 @@ 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"> - + + + + + + - + @@ -20,33 +25,28 @@ - + - - - - - - - + + + + + + - - + + + - - - - - - - - + + + - - - - - - - - - org.argeo.slc.web.mvc.XsltMarshallerView @@ -44,5 +34,13 @@ + + + + + + + \ No newline at end of file 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 deleted file mode 100644 index 9c95d75f5..000000000 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/EventController.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2010 Mathieu Baudier - * - * 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 org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.msg.ExecutionAnswer; -import org.argeo.slc.msg.event.SlcEvent; -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.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -@Controller -public class EventController { - - private final static Log log = LogFactory.getLog(EventController.class); - - public final static String KEY_ANSWER = "__answer"; - private Long defaultTimeout = 10000l; - - // IoC - private SlcEventListenerRegister eventListenerRegister; - private SlcEventListener eventListener = null; - - public EventController() { - } - - // Business Methods - - @RequestMapping("/addEventListener.service") - public ExecutionAnswer addEventListener( - @RequestParam(SlcEvent.EVENT_TYPE) String eventType, - @RequestParam(value = SlcEvent.EVENT_FILTER, required = false) String eventFilter) { - - eventListenerRegister - .addEventListenerDescriptor(new SlcEventListenerDescriptor( - eventType, eventFilter)); - if (log.isTraceEnabled()) - log.trace("Registered listener on register " - + eventListenerRegister.getId() + " for type " + eventType - + ", filter=" + eventFilter); - return ExecutionAnswer.ok("Execution completed properly"); - - } - - @RequestMapping("/removeEventListener.service") - public ExecutionAnswer removeEventListener( - @RequestParam(SlcEvent.EVENT_TYPE) String eventType, - @RequestParam(value = SlcEvent.EVENT_FILTER, required = false) String eventFilter) { - - eventListenerRegister - .removeEventListenerDescriptor(new SlcEventListenerDescriptor( - eventType, eventFilter)); - if (log.isTraceEnabled()) - log.trace("Removed listener from register " - + eventListenerRegister.getId() + " for type " + eventType - + ", filter=" + eventFilter); - return ExecutionAnswer.ok("Execution completed properly"); - } - - @RequestMapping("/pollEvent.service") - public Object pollEvent( - @RequestParam(value = "timeout", required = false) String timeoutStr) { - final Long timeout; - if (timeoutStr != null) - timeout = Long.parseLong(timeoutStr); - else - timeout = defaultTimeout; - - SlcEvent event = eventListener.listen(eventListenerRegister.getId(), - eventListenerRegister.getDescriptorsCopy(), timeout); - if (event != null) { - return event; - } else { - return ExecutionAnswer.ok("Execution completed properly"); - } - } - - public void setEventListenerRegister( - SlcEventListenerRegister eventListenerRegister) { - this.eventListenerRegister = eventListenerRegister; - } - - public void setDefaultTimeout(Long defaultTimeout) { - this.defaultTimeout = defaultTimeout; - } - - public void setEventListener(SlcEventListener eventListener) { - this.eventListener = eventListener; - } -} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/ExecutionServiceController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/ExecutionServiceController.java deleted file mode 100644 index 738b0e248..000000000 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/ExecutionServiceController.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2010 Mathieu Baudier - * - * 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.io.BufferedReader; -import java.util.Comparator; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.UUID; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.core.attachment.AttachmentsStorage; -import org.argeo.slc.dao.process.SlcExecutionDao; -import org.argeo.slc.execution.ExecutionModuleDescriptor; -import org.argeo.slc.msg.ExecutionAnswer; -import org.argeo.slc.msg.MsgConstants; -import org.argeo.slc.msg.ObjectList; -import org.argeo.slc.process.SlcExecution; -import org.argeo.slc.process.SlcExecutionStep; -import org.argeo.slc.runtime.SlcAgent; -import org.argeo.slc.runtime.SlcAgentFactory; -import org.argeo.slc.services.SlcExecutionService; -import org.argeo.slc.web.mvc.process.SlcExecutionManager; -import org.springframework.oxm.Marshaller; -import org.springframework.oxm.Unmarshaller; -import org.springframework.stereotype.Controller; -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.xml.transform.StringSource; - -@Controller -public class ExecutionServiceController { - - public final static String KEY_ANSWER = "__answer"; - private final static Log log = LogFactory - .getLog(ExecutionServiceController.class); - - private SlcExecutionDao slcExecutionDao; - private SlcAgentFactory agentFactory; - private Unmarshaller unmarshaller; - private Marshaller marshaller; - private SlcExecutionService slcExecutionService; - private AttachmentsStorage attachmentsStorage; - - private SlcExecutionManager slcExecutionManager; - - @RequestMapping("/listSlcExecutions.service") - protected ObjectList listSlcExecutions() { - List list = slcExecutionDao.listSlcExecutions(); - return new ObjectList(list); - } - - @RequestMapping("/getExecutionDescriptor.service") - protected ExecutionModuleDescriptor getExecutionDescriptor( - @RequestParam String agentId, @RequestParam String moduleName, - @RequestParam String version) { - - SlcAgent slcAgent = agentFactory.getAgent(agentId); - - ExecutionModuleDescriptor md = slcAgent.getExecutionModuleDescriptor( - moduleName, version); - return md; - } - - @RequestMapping("/listModulesDescriptors.service") - protected ObjectList listModulesDescriptors(@RequestParam String agentId) { - // TODO: use centralized agentId property (from MsgConstants)? - SlcAgent slcAgent = agentFactory.getAgent(agentId); - - List descriptors = slcAgent - .listExecutionModuleDescriptors(); - SortedSet set = new TreeSet( - new Comparator() { - - public int compare(ExecutionModuleDescriptor md1, - ExecutionModuleDescriptor md2) { - String str1 = md1.getLabel() != null ? md1.getLabel() - : md1.getName(); - String str2 = md2.getLabel() != null ? md2.getLabel() - : md2.getName(); - return str1.compareTo(str2); - } - }); - set.addAll(descriptors); - return new ObjectList(set); - } - - @RequestMapping("/getSlcExecution.service") - protected SlcExecution getSlcExecution(@RequestParam String uuid) { - SlcExecution slcExecution = slcExecutionDao.getSlcExecution(uuid); - initializeSEM(); - slcExecutionManager.retrieveRealizedFlows(slcExecution); - return slcExecution; - } - - @RequestMapping("/newSlcExecution.service") - protected ExecutionAnswer newSlcExecution(HttpServletRequest request, - Model model) throws Exception { - - String agentId = request - .getParameter(MsgConstants.PROPERTY_SLC_AGENT_ID); - Assert.notNull(agentId, "agent id"); - - String answer = request.getParameter("body"); - if (answer == null) { - // lets read the message body instead - BufferedReader reader = request.getReader(); - StringBuffer buffer = new StringBuffer(); - String line = null; - while (((line = reader.readLine()) != null)) { - buffer.append(line); - } - answer = buffer.toString(); - } - - if (log.isTraceEnabled()) - log.debug("Received message:\n" + answer); - - StringSource source = new StringSource(answer); - SlcExecution slcExecution = (SlcExecution) unmarshaller - .unmarshal(source); - - // Workaround for https://www.argeo.org/bugzilla/show_bug.cgi?id=86 - if (slcExecution.getUuid() == null - || slcExecution.getUuid().length() < 8) - slcExecution.setUuid(UUID.randomUUID().toString()); - - slcExecution.setStatus(SlcExecution.STATUS_SCHEDULED); - slcExecution.getSteps().add( - new SlcExecutionStep(SlcExecutionStep.TYPE_START, - "Process started from the Web UI")); - - initializeSEM(); - slcExecutionManager.storeRealizedFlows(slcExecution); - slcExecutionService.newExecution(slcExecution); - SlcAgent agent = agentFactory.getAgent(agentId); - agent.runSlcExecution(slcExecution); - - return ExecutionAnswer.ok("Execution completed properly"); - } - - private void initializeSEM() { - slcExecutionManager = new SlcExecutionManager(agentFactory, - unmarshaller, marshaller, slcExecutionService, - attachmentsStorage); - - } - - public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao) { - this.slcExecutionDao = slcExecutionDao; - } - - public void setSlcExecutionService(SlcExecutionService slcExecutionService) { - this.slcExecutionService = slcExecutionService; - } - - public void setUnmarshaller(Unmarshaller unmarshaller) { - this.unmarshaller = unmarshaller; - } - - public void setMarshaller(Marshaller marshaller) { - this.marshaller = marshaller; - } - - public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) { - this.attachmentsStorage = attachmentsStorage; - } - - public void setAgentFactory(SlcAgentFactory agentFactory) { - this.agentFactory = agentFactory; - } - -} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/MarshallerView.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/MarshallerView.java deleted file mode 100644 index 3701d1cfd..000000000 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/MarshallerView.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2010 Mathieu Baudier - * - * 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; - } - -} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/MarshallerViewResolver.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/MarshallerViewResolver.java deleted file mode 100644 index 013701498..000000000 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/MarshallerViewResolver.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2010 Mathieu Baudier - * - * 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); - } - -} 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 deleted file mode 100644 index 42a0f5f5d..000000000 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/ServiceController.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (C) 2010 Mathieu Baudier - * - * 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.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.Vector; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.FilenameUtils; -import org.argeo.slc.SlcException; -import org.argeo.slc.core.attachment.AttachmentsStorage; -import org.argeo.slc.core.attachment.SimpleAttachment; -import org.argeo.slc.core.test.tree.ResultAttributes; -import org.argeo.slc.core.test.tree.TreeTestResult; -import org.argeo.slc.core.test.tree.TreeTestResultCollection; -import org.argeo.slc.dao.runtime.SlcAgentDescriptorDao; -import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao; -import org.argeo.slc.dao.test.tree.TreeTestResultDao; -import org.argeo.slc.deploy.DynamicRuntime; -import org.argeo.slc.msg.ExecutionAnswer; -import org.argeo.slc.msg.ObjectList; -import org.argeo.slc.msg.ReferenceList; -import org.argeo.slc.runtime.SlcAgentDescriptor; -import org.argeo.slc.services.TestManagerService; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.util.PatternMatchUtils; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -@Controller -public class ServiceController { - -// private final static Log log = LogFactory.getLog(ServiceController.class); - - // Constants - public final static String KEY_ANSWER = "__answer"; - protected final String FORCE_DOWNLOAD = "Content-Type: application/force-download"; - - // IoC - // FIXME : why must this be final ?? - private final TreeTestResultDao treeTestResultDao; - private final TestManagerService testManagerService; - private final TreeTestResultCollectionDao testResultCollectionDao; - private final SlcAgentDescriptorDao slcAgentDescriptorDao; - private AttachmentsStorage attachmentsStorage; - private DynamicRuntime dynamicRuntime; - - public ServiceController(TreeTestResultDao treeTestResultDao, - TreeTestResultCollectionDao testResultCollectionDao, - TestManagerService testManagerService, - SlcAgentDescriptorDao slcAgentDescriptorDao) { - - this.testManagerService = testManagerService; - this.treeTestResultDao = treeTestResultDao; - this.testResultCollectionDao = testResultCollectionDao; - this.slcAgentDescriptorDao = slcAgentDescriptorDao; - } - - // Business Methods - @RequestMapping("/isServerReady.service") - protected ExecutionAnswer isServerReady(Model model) { - // Does nothing for now, it will return an OK answer. - return ExecutionAnswer.ok("Execution completed properly"); - } - - @RequestMapping("/shutdownRuntime.service") - protected ExecutionAnswer shutdownRuntime(Model model) { - new Thread() { - public void run() { - // wait in order to let call return - try { - Thread.sleep(3000); - } catch (InterruptedException e) { - // silent - } - dynamicRuntime.shutdown(); - } - }.start(); - return ExecutionAnswer.ok("Server shutting down..."); - } - - @RequestMapping("/getResult.service") - 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); - return result; - } - - @RequestMapping("/addResultToCollection.service") - protected ExecutionAnswer addResultToCollection( - @RequestParam String collectionId, @RequestParam String resultUuid) { - testManagerService.addResultToCollection(collectionId, resultUuid); - return ExecutionAnswer.ok("Execution completed properly"); - } - - @RequestMapping("/removeResultFromCollection.service") - protected ExecutionAnswer removeResultFromCollection( - HttpServletRequest request) { - String collectionId = request.getParameter("collectionId"); - String[] resultUuids = request.getParameterValues("resultUuid"); - String[] attrNames = request.getParameterValues("attrName"); - String[] attrPatterns = request.getParameterValues("attrPattern"); - - // Checks - if (collectionId == null) - throw new SlcException("A collection id must be specified"); - if (attrNames != null - && (attrPatterns == null || attrNames.length != attrPatterns.length)) - throw new SlcException( - "There must be as many attrName as attrPatterns"); - - // Remove specified results - if (resultUuids != null) - for (String resultUuid : resultUuids) - testManagerService.removeResultFromCollection(collectionId, - resultUuid); - - if (attrNames != null) { - TreeTestResultCollection sourceCollection = testResultCollectionDao - .getTestResultCollection(collectionId); - - int index = 0; - for (String attrName : attrNames) { - String attrPattern = attrPatterns[index];// safe: checked above - - List results = new ArrayList( - sourceCollection.getResults()); - for (TreeTestResult treeTestResult : results) { - if (PatternMatchUtils.simpleMatch(attrPattern, - treeTestResult.getAttributes().get(attrName))) { - testManagerService.removeResultFromCollection( - collectionId, treeTestResult.getUuid()); - } - } - index++; - } - } else { - if (resultUuids == null) {// no specs - // remove all - // TODO: optimize - TreeTestResultCollection sourceCollection = testResultCollectionDao - .getTestResultCollection(collectionId); - List results = new ArrayList( - sourceCollection.getResults()); - for (TreeTestResult treeTestResult : results) { - testManagerService.removeResultFromCollection(collectionId, - treeTestResult.getUuid()); - } - - } - } - return ExecutionAnswer.ok("Execution completed properly"); - } - - @RequestMapping("/listCollectionRefs.service") - protected ReferenceList listCollectionRefs(HttpServletRequest request, - HttpServletResponse response) { - - SortedSet results = testResultCollectionDao - .listCollections(); - - ReferenceList referenceList = new ReferenceList(); - for (TreeTestResultCollection collection : results) { - referenceList.getReferences().add(collection.getId()); - } - return referenceList; - } - - @RequestMapping("/listResultAttributes.service") - protected ObjectList listResultAttributes(@RequestParam String id, Model model) { - - List resultAttributes = testResultCollectionDao - .listResultAttributes(id); - return new ObjectList( - resultAttributes); - } - - @RequestMapping("/listResults.service") - @SuppressWarnings(value = { "unchecked" }) - protected ObjectList listResults( - @RequestParam(value = "collectionId", required = false) String collectionId, - HttpServletRequest request) { - Map parameterMap = request.getParameterMap(); - Map attributes = new HashMap(); - for (String parameter : parameterMap.keySet()) { - if (parameter.startsWith("attr.")) { - String key = parameter.substring("attr.".length()); - attributes.put(key, parameterMap.get(parameter)[0]); - } - } - - List resultAttributes = testResultCollectionDao - .listResults(collectionId, attributes); - return new ObjectList(resultAttributes); - } - - @RequestMapping("/copyCollectionToCollection.service") - protected ExecutionAnswer copyCollectionToCollection( - @RequestParam String sourceCollectionId, - @RequestParam String targetCollectionId, - HttpServletRequest request) { - - String[] attrNames = request.getParameterValues("attrName"); - String[] attrPatterns = request.getParameterValues("attrPattern"); - - // Checks - if (sourceCollectionId == null || targetCollectionId == null) - throw new SlcException( - "Source and target collection ids must be specified"); - if (attrNames != null - && (attrPatterns == null || attrNames.length != attrPatterns.length)) - throw new SlcException( - "There must be as many attrName as attrPatterns"); - - TreeTestResultCollection sourceCollection = testResultCollectionDao - .getTestResultCollection(sourceCollectionId); - if (attrNames != null) { - int index = 0; - for (String attrName : attrNames) { - String attrPattern = attrPatterns[index];// safe: checked above - - for (TreeTestResult treeTestResult : sourceCollection - .getResults()) { - if (PatternMatchUtils.simpleMatch(attrPattern, - treeTestResult.getAttributes().get(attrName))) { - testManagerService.addResultToCollection( - targetCollectionId, treeTestResult.getUuid()); - } - } - index++; - } - } else { - // remove all - // TODO: optimize - for (TreeTestResult treeTestResult : sourceCollection.getResults()) { - testManagerService.addResultToCollection(targetCollectionId, - treeTestResult.getUuid()); - } - } - return ExecutionAnswer.ok("Execution completed properly"); - } - - @RequestMapping("/listAgents.service") - protected ObjectList listAgents() { - List list = slcAgentDescriptorDao - .listSlcAgentDescriptors(); - return new ObjectList(list); - } - - @RequestMapping("/cleanAgents.service") - protected ExecutionAnswer cleanAgents() { - - List list = slcAgentDescriptorDao - .listSlcAgentDescriptors(); - for (SlcAgentDescriptor t : new Vector(list)) { - slcAgentDescriptorDao.delete(t); - } - return ExecutionAnswer.ok("Execution completed properly"); - } - - @RequestMapping("/getAttachment.service") - protected void getAttachment(@RequestParam String uuid, - @RequestParam String contentType, @RequestParam String name, - HttpServletResponse response) throws Exception { - if (contentType == null || "".equals(contentType.trim())) { - if (name != null) { - contentType = FORCE_DOWNLOAD; - String ext = FilenameUtils.getExtension(name); - // cf. http://en.wikipedia.org/wiki/Internet_media_type - if ("csv".equals(ext)) - contentType = "text/csv"; - else if ("pdf".equals(ext)) - contentType = "application/pdf"; - else if ("zip".equals(ext)) - contentType = "application/zip"; - else if ("html".equals(ext)) - contentType = "application/html"; - else if ("txt".equals(ext)) - contentType = "text/plain"; - else if ("doc".equals(ext) || "docx".equals(ext)) - contentType = "application/msword"; - else if ("xls".equals(ext) || "xlsx".equals(ext)) - contentType = "application/vnd.ms-excel"; - else if ("xml".equals(ext)) - contentType = "text/xml"; - } - } - - if (name != null) { - contentType = contentType + ";name=\"" + name + "\""; - response.setHeader("Content-Disposition", "attachment; filename=\"" - + name + "\""); - } - response.setHeader("Expires", "0"); - response.setHeader("Cache-Control", "no-cache, must-revalidate"); - response.setHeader("Pragma", "no-cache"); - - SimpleAttachment resourceDescriptor = new SimpleAttachment(); - resourceDescriptor.setUuid(uuid); - resourceDescriptor.setContentType(contentType); - - response.setContentType(contentType); - ServletOutputStream outputStream = response.getOutputStream(); - attachmentsStorage.retrieveAttachment(resourceDescriptor, outputStream); - } - - // IoC - - public void setDynamicRuntime(DynamicRuntime dynamicRuntime) { - this.dynamicRuntime = dynamicRuntime; - } - - public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) { - this.attachmentsStorage = attachmentsStorage; - } -} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/AgentController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/AgentController.java new file mode 100644 index 000000000..b4f2bb67c --- /dev/null +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/AgentController.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * 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.controllers; + +import java.util.List; +import java.util.Vector; + +import org.argeo.slc.dao.runtime.SlcAgentDescriptorDao; +import org.argeo.slc.msg.ExecutionAnswer; +import org.argeo.slc.msg.ObjectList; +import org.argeo.slc.runtime.SlcAgentDescriptor; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * Controle and information about the agents. + */ + +@Controller +public class AgentController { + + // IoC + private SlcAgentDescriptorDao slcAgentDescriptorDao; + + @RequestMapping("/listAgents.service") + protected ObjectList listAgents() { + List list = slcAgentDescriptorDao + .listSlcAgentDescriptors(); + return new ObjectList(list); + } + + @RequestMapping("/cleanAgents.service") + protected ExecutionAnswer cleanAgents() { + + List list = slcAgentDescriptorDao + .listSlcAgentDescriptors(); + for (SlcAgentDescriptor t : new Vector(list)) { + slcAgentDescriptorDao.delete(t); + } + return ExecutionAnswer.ok("Execution completed properly"); + } + + // IoC + public void setSlcAgentDescriptorDao( + SlcAgentDescriptorDao slcAgentDescriptorDao) { + this.slcAgentDescriptorDao = slcAgentDescriptorDao; + } + +} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/EventController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/EventController.java new file mode 100644 index 000000000..2020a0b5b --- /dev/null +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/EventController.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * 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.controllers; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.msg.ExecutionAnswer; +import org.argeo.slc.msg.event.SlcEvent; +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.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +public class EventController { + + private final static Log log = LogFactory.getLog(EventController.class); + + public final static String KEY_ANSWER = "__answer"; + private Long defaultTimeout = 10000l; + + // IoC + private SlcEventListenerRegister eventListenerRegister; + private SlcEventListener eventListener = null; + + // Business Methods + @RequestMapping("/addEventListener.service") + public ExecutionAnswer addEventListener( + @RequestParam(SlcEvent.EVENT_TYPE) String eventType, + @RequestParam(value = SlcEvent.EVENT_FILTER, required = false) String eventFilter) { + + eventListenerRegister + .addEventListenerDescriptor(new SlcEventListenerDescriptor( + eventType, eventFilter)); + if (log.isTraceEnabled()) + log.trace("Registered listener on register " + + eventListenerRegister.getId() + " for type " + eventType + + ", filter=" + eventFilter); + return ExecutionAnswer.ok("Execution completed properly"); + + } + + @RequestMapping("/removeEventListener.service") + public ExecutionAnswer removeEventListener( + @RequestParam(SlcEvent.EVENT_TYPE) String eventType, + @RequestParam(value = SlcEvent.EVENT_FILTER, required = false) String eventFilter) { + + eventListenerRegister + .removeEventListenerDescriptor(new SlcEventListenerDescriptor( + eventType, eventFilter)); + if (log.isTraceEnabled()) + log.trace("Removed listener from register " + + eventListenerRegister.getId() + " for type " + eventType + + ", filter=" + eventFilter); + return ExecutionAnswer.ok("Execution completed properly"); + } + + @RequestMapping("/pollEvent.service") + public Object pollEvent( + @RequestParam(value = "timeout", required = false) String timeoutStr) { + final Long timeout; + if (timeoutStr != null) + timeout = Long.parseLong(timeoutStr); + else + timeout = defaultTimeout; + + SlcEvent event = eventListener.listen(eventListenerRegister.getId(), + eventListenerRegister.getDescriptorsCopy(), timeout); + if (event != null) { + return event; + } else { + return ExecutionAnswer.ok("Execution completed properly"); + } + } + + public void setEventListenerRegister( + SlcEventListenerRegister eventListenerRegister) { + this.eventListenerRegister = eventListenerRegister; + } + + public void setDefaultTimeout(Long defaultTimeout) { + this.defaultTimeout = defaultTimeout; + } + + public void setEventListener(SlcEventListener eventListener) { + this.eventListener = eventListener; + } +} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/ProcessController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/ProcessController.java new file mode 100644 index 000000000..8fedc47da --- /dev/null +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/ProcessController.java @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * 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.controllers; + +import java.io.BufferedReader; +import java.util.Comparator; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.core.attachment.AttachmentsStorage; +import org.argeo.slc.dao.process.SlcExecutionDao; +import org.argeo.slc.execution.ExecutionModuleDescriptor; +import org.argeo.slc.msg.ExecutionAnswer; +import org.argeo.slc.msg.MsgConstants; +import org.argeo.slc.msg.ObjectList; +import org.argeo.slc.process.SlcExecution; +import org.argeo.slc.process.SlcExecutionStep; +import org.argeo.slc.runtime.SlcAgent; +import org.argeo.slc.runtime.SlcAgentFactory; +import org.argeo.slc.services.SlcExecutionService; +import org.springframework.oxm.Marshaller; +import org.springframework.oxm.Unmarshaller; +import org.springframework.stereotype.Controller; +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.xml.transform.StringSource; + +@Controller +public class ProcessController { + + public final static String KEY_ANSWER = "__answer"; + private final static Log log = LogFactory.getLog(ProcessController.class); + + private SlcExecutionDao slcExecutionDao; + private SlcAgentFactory agentFactory; + private Unmarshaller unmarshaller; + private Marshaller marshaller; + private SlcExecutionService slcExecutionService; + private AttachmentsStorage attachmentsStorage; + + private SlcExecutionManager slcExecutionManager; + + @RequestMapping("/listSlcExecutions.service") + protected ObjectList listSlcExecutions() { + List list = slcExecutionDao.listSlcExecutions(); + return new ObjectList(list); + } + + @RequestMapping("/getExecutionDescriptor.service") + protected ExecutionModuleDescriptor getExecutionDescriptor( + @RequestParam String agentId, @RequestParam String moduleName, + @RequestParam String version) { + + SlcAgent slcAgent = agentFactory.getAgent(agentId); + + ExecutionModuleDescriptor md = slcAgent.getExecutionModuleDescriptor( + moduleName, version); + return md; + } + + @RequestMapping("/listModulesDescriptors.service") + protected ObjectList listModulesDescriptors(@RequestParam String agentId) { + // TODO: use centralized agentId property (from MsgConstants)? + SlcAgent slcAgent = agentFactory.getAgent(agentId); + + List descriptors = slcAgent + .listExecutionModuleDescriptors(); + SortedSet set = new TreeSet( + new Comparator() { + + public int compare(ExecutionModuleDescriptor md1, + ExecutionModuleDescriptor md2) { + String str1 = md1.getLabel() != null ? md1.getLabel() + : md1.getName(); + String str2 = md2.getLabel() != null ? md2.getLabel() + : md2.getName(); + return str1.compareTo(str2); + } + }); + set.addAll(descriptors); + return new ObjectList(set); + } + + @RequestMapping("/getSlcExecution.service") + protected SlcExecution getSlcExecution(@RequestParam String uuid) { + SlcExecution slcExecution = slcExecutionDao.getSlcExecution(uuid); + initializeSEM(); + slcExecutionManager.retrieveRealizedFlows(slcExecution); + return slcExecution; + } + + @RequestMapping("/newSlcExecution.service") + protected ExecutionAnswer newSlcExecution(HttpServletRequest request, + Model model) throws Exception { + + String agentId = request + .getParameter(MsgConstants.PROPERTY_SLC_AGENT_ID); + Assert.notNull(agentId, "agent id"); + + String answer = request.getParameter("body"); + if (answer == null) { + // lets read the message body instead + BufferedReader reader = request.getReader(); + StringBuffer buffer = new StringBuffer(); + String line = null; + while (((line = reader.readLine()) != null)) { + buffer.append(line); + } + answer = buffer.toString(); + } + + if (log.isTraceEnabled()) + log.debug("Received message:\n" + answer); + + StringSource source = new StringSource(answer); + SlcExecution slcExecution = (SlcExecution) unmarshaller + .unmarshal(source); + + // Workaround for https://www.argeo.org/bugzilla/show_bug.cgi?id=86 + if (slcExecution.getUuid() == null + || slcExecution.getUuid().length() < 8) + slcExecution.setUuid(UUID.randomUUID().toString()); + + slcExecution.setStatus(SlcExecution.STATUS_SCHEDULED); + slcExecution.getSteps().add( + new SlcExecutionStep(SlcExecutionStep.TYPE_START, + "Process started from the Web UI")); + + initializeSEM(); + slcExecutionManager.storeRealizedFlows(slcExecution); + slcExecutionService.newExecution(slcExecution); + SlcAgent agent = agentFactory.getAgent(agentId); + agent.runSlcExecution(slcExecution); + + return ExecutionAnswer.ok("Execution completed properly"); + } + + private void initializeSEM() { + slcExecutionManager = new SlcExecutionManager(unmarshaller, marshaller, + attachmentsStorage); + } + + public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao) { + this.slcExecutionDao = slcExecutionDao; + } + + public void setSlcExecutionService(SlcExecutionService slcExecutionService) { + this.slcExecutionService = slcExecutionService; + } + + public void setUnmarshaller(Unmarshaller unmarshaller) { + this.unmarshaller = unmarshaller; + } + + public void setMarshaller(Marshaller marshaller) { + this.marshaller = marshaller; + } + + public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) { + this.attachmentsStorage = attachmentsStorage; + } + + public void setAgentFactory(SlcAgentFactory agentFactory) { + this.agentFactory = agentFactory; + } + +} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/RenderingResultController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/RenderingResultController.java new file mode 100644 index 000000000..175243aeb --- /dev/null +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/RenderingResultController.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * 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.controllers; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.SlcException; +import org.argeo.slc.core.test.tree.TreeTestResult; +import org.argeo.slc.dao.test.tree.TreeTestResultDao; +import org.argeo.slc.web.mvc.result.ResultExcelView; +import org.argeo.slc.web.mvc.result.ResultPdfView; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +/** + * Sends back the results, rendered or as collection. + */ + +@Controller +public class RenderingResultController { + private final static Log log = LogFactory.getLog(RenderingResultController.class); + + public final static String KEY_ANSWER = "__answer"; + public final static String MODELKEY_RESULT = "result"; + + // IoC + private TreeTestResultDao testResultDao; + private ResultExcelView resultExcelView; + private ResultPdfView resultPdfView; + + @RequestMapping("/resultView.pdf") + public void getPdfResultView(@RequestParam(value = "uuid") String uuid, + ModelAndView modelAndView) { + TreeTestResult result = testResultDao.getTestResult(uuid); + if (result == null) + throw new SlcException("No result found for uuid " + uuid); + modelAndView.getModelMap().addAttribute(MODELKEY_RESULT, result); + modelAndView.setView(resultPdfView); + } + + @RequestMapping("/resultView.xls") + public void getXlsResultView(@RequestParam(value = "uuid") String uuid, + ModelAndView modelAndView) { + TreeTestResult result = testResultDao.getTestResult(uuid); + if (result == null) + throw new SlcException("No result found for uuid " + uuid); + modelAndView.getModelMap().addAttribute(MODELKEY_RESULT, result); + modelAndView.setView(resultExcelView); + } + + public void setResultExcelView(ResultExcelView resultExcelView) { + this.resultExcelView = resultExcelView; + } + + public void setResultPdfView(ResultPdfView resultPdfView) { + this.resultPdfView = resultPdfView; + } + +} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/ResultController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/ResultController.java new file mode 100644 index 000000000..5bf12b6a5 --- /dev/null +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/ResultController.java @@ -0,0 +1,292 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * 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.controllers; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedSet; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.FilenameUtils; +import org.argeo.slc.SlcException; +import org.argeo.slc.core.attachment.AttachmentsStorage; +import org.argeo.slc.core.attachment.SimpleAttachment; +import org.argeo.slc.core.test.tree.ResultAttributes; +import org.argeo.slc.core.test.tree.TreeTestResult; +import org.argeo.slc.core.test.tree.TreeTestResultCollection; +import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao; +import org.argeo.slc.dao.test.tree.TreeTestResultDao; +import org.argeo.slc.msg.ExecutionAnswer; +import org.argeo.slc.msg.ObjectList; +import org.argeo.slc.msg.ReferenceList; +import org.argeo.slc.services.TestManagerService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.util.PatternMatchUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +public class ResultController { + + // private final static Log log = + // LogFactory.getLog(ServiceController.class); + + // Constants + public final static String KEY_ANSWER = "__answer"; + protected final String FORCE_DOWNLOAD = "Content-Type: application/force-download"; + + // IoC + private TreeTestResultDao treeTestResultDao; + private TreeTestResultCollectionDao treeTestResultCollectionDao; + private TestManagerService testManagerService; + private AttachmentsStorage attachmentsStorage; + + // Business Methods + @RequestMapping("/getResult.service") + 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); + return result; + } + + @RequestMapping("/addResultToCollection.service") + protected ExecutionAnswer addResultToCollection( + @RequestParam String collectionId, @RequestParam String resultUuid) { + testManagerService.addResultToCollection(collectionId, resultUuid); + return ExecutionAnswer.ok("Execution completed properly"); + } + + @RequestMapping("/removeResultFromCollection.service") + protected ExecutionAnswer removeResultFromCollection( + HttpServletRequest request) { + String collectionId = request.getParameter("collectionId"); + String[] resultUuids = request.getParameterValues("resultUuid"); + String[] attrNames = request.getParameterValues("attrName"); + String[] attrPatterns = request.getParameterValues("attrPattern"); + + // Checks + if (collectionId == null) + throw new SlcException("A collection id must be specified"); + if (attrNames != null + && (attrPatterns == null || attrNames.length != attrPatterns.length)) + throw new SlcException( + "There must be as many attrName as attrPatterns"); + + // Remove specified results + if (resultUuids != null) + for (String resultUuid : resultUuids) + testManagerService.removeResultFromCollection(collectionId, + resultUuid); + + if (attrNames != null) { + TreeTestResultCollection sourceCollection = treeTestResultCollectionDao + .getTestResultCollection(collectionId); + + int index = 0; + for (String attrName : attrNames) { + String attrPattern = attrPatterns[index];// safe: checked above + + List results = new ArrayList( + sourceCollection.getResults()); + for (TreeTestResult treeTestResult : results) { + if (PatternMatchUtils.simpleMatch(attrPattern, + treeTestResult.getAttributes().get(attrName))) { + testManagerService.removeResultFromCollection( + collectionId, treeTestResult.getUuid()); + } + } + index++; + } + } else { + if (resultUuids == null) {// no specs + // remove all + // TODO: optimize + TreeTestResultCollection sourceCollection = treeTestResultCollectionDao + .getTestResultCollection(collectionId); + List results = new ArrayList( + sourceCollection.getResults()); + for (TreeTestResult treeTestResult : results) { + testManagerService.removeResultFromCollection(collectionId, + treeTestResult.getUuid()); + } + + } + } + return ExecutionAnswer.ok("Execution completed properly"); + } + + @RequestMapping("/listCollectionRefs.service") + protected ReferenceList listCollectionRefs(HttpServletRequest request, + HttpServletResponse response) { + + SortedSet results = treeTestResultCollectionDao + .listCollections(); + + ReferenceList referenceList = new ReferenceList(); + for (TreeTestResultCollection collection : results) { + referenceList.getReferences().add(collection.getId()); + } + return referenceList; + } + + @RequestMapping("/listResultAttributes.service") + protected ObjectList listResultAttributes(@RequestParam String id, + Model model) { + + List resultAttributes = treeTestResultCollectionDao + .listResultAttributes(id); + return new ObjectList(resultAttributes); + } + + @RequestMapping("/listResults.service") + @SuppressWarnings(value = { "unchecked" }) + protected ObjectList listResults( + @RequestParam(value = "collectionId", required = false) String collectionId, + HttpServletRequest request) { + Map parameterMap = request.getParameterMap(); + Map attributes = new HashMap(); + for (String parameter : parameterMap.keySet()) { + if (parameter.startsWith("attr.")) { + String key = parameter.substring("attr.".length()); + attributes.put(key, parameterMap.get(parameter)[0]); + } + } + + List resultAttributes = treeTestResultCollectionDao + .listResults(collectionId, attributes); + return new ObjectList(resultAttributes); + } + + @RequestMapping("/copyCollectionToCollection.service") + protected ExecutionAnswer copyCollectionToCollection( + @RequestParam String sourceCollectionId, + @RequestParam String targetCollectionId, HttpServletRequest request) { + + String[] attrNames = request.getParameterValues("attrName"); + String[] attrPatterns = request.getParameterValues("attrPattern"); + + // Checks + if (sourceCollectionId == null || targetCollectionId == null) + throw new SlcException( + "Source and target collection ids must be specified"); + if (attrNames != null + && (attrPatterns == null || attrNames.length != attrPatterns.length)) + throw new SlcException( + "There must be as many attrName as attrPatterns"); + + TreeTestResultCollection sourceCollection = treeTestResultCollectionDao + .getTestResultCollection(sourceCollectionId); + if (attrNames != null) { + int index = 0; + for (String attrName : attrNames) { + String attrPattern = attrPatterns[index];// safe: checked above + + for (TreeTestResult treeTestResult : sourceCollection + .getResults()) { + if (PatternMatchUtils.simpleMatch(attrPattern, + treeTestResult.getAttributes().get(attrName))) { + testManagerService.addResultToCollection( + targetCollectionId, treeTestResult.getUuid()); + } + } + index++; + } + } else { + // remove all + // TODO: optimize + for (TreeTestResult treeTestResult : sourceCollection.getResults()) { + testManagerService.addResultToCollection(targetCollectionId, + treeTestResult.getUuid()); + } + } + return ExecutionAnswer.ok("Execution completed properly"); + } + + @RequestMapping("/getAttachment.service") + protected void getAttachment(@RequestParam String uuid, + @RequestParam String contentType, @RequestParam String name, + HttpServletResponse response) throws Exception { + if (contentType == null || "".equals(contentType.trim())) { + if (name != null) { + contentType = FORCE_DOWNLOAD; + String ext = FilenameUtils.getExtension(name); + // cf. http://en.wikipedia.org/wikServicei/Internet_media_type + if ("csv".equals(ext)) + contentType = "text/csv"; + else if ("pdf".equals(ext)) + contentType = "application/pdf"; + else if ("zip".equals(ext)) + contentType = "application/zip"; + else if ("html".equals(ext)) + contentType = "application/html"; + else if ("txt".equals(ext)) + contentType = "text/plain"; + else if ("doc".equals(ext) || "docx".equals(ext)) + contentType = "application/msword"; + else if ("xls".equals(ext) || "xlsx".equals(ext)) + contentType = "application/vnd.ms-excel"; + else if ("xml".equals(ext)) + contentType = "text/xml"; + } + } + + if (name != null) { + contentType = contentType + ";name=\"" + name + "\""; + response.setHeader("Content-Disposition", "attachment; filename=\"" + + name + "\""); + } + response.setHeader("Expires", "0"); + response.setHeader("Cache-Control", "no-cache, must-revalidate"); + response.setHeader("Pragma", "no-cache"); + + SimpleAttachment resourceDescriptor = new SimpleAttachment(); + resourceDescriptor.setUuid(uuid); + resourceDescriptor.setContentType(contentType); + + response.setContentType(contentType); + ServletOutputStream outputStream = response.getOutputStream(); + attachmentsStorage.retrieveAttachment(resourceDescriptor, outputStream); + } + + // IoC + + public void setTreeTestResultDao(TreeTestResultDao treeTestResultDao) { + this.treeTestResultDao = treeTestResultDao; + } + + public void setTestManagerService(TestManagerService testManagerService) { + this.testManagerService = testManagerService; + } + + public void setTreeTestResultCollectionDao( + TreeTestResultCollectionDao treeTestResultCollectionDao) { + this.treeTestResultCollectionDao = treeTestResultCollectionDao; + } + + public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) { + this.attachmentsStorage = attachmentsStorage; + } +} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/ServerController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/ServerController.java new file mode 100644 index 000000000..b23927807 --- /dev/null +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/ServerController.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * 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.controllers; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +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.build.BasicNameVersion; +import org.argeo.slc.build.NameVersion; +import org.argeo.slc.core.build.ResourceDistribution; +import org.argeo.slc.deploy.DynamicRuntime; +import org.argeo.slc.deploy.Module; +import org.argeo.slc.msg.ExecutionAnswer; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * Sends back the results, rendered or as collection. + */ + +@Controller +public class ServerController { + public final static String KEY_ANSWER = "__answer"; + + // IoC + 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); + + // SERVER HANDLING + + @RequestMapping("/isServerReady.service") + protected ExecutionAnswer isServerReady(Model model) { + // Does nothing for now, it will return an OK answer. + return ExecutionAnswer.ok("Execution completed properly"); + } + + @RequestMapping("/shutdownRuntime.service") + protected ExecutionAnswer shutdownRuntime(Model model) { + new Thread() { + public void run() { + // wait in order to let call return + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + // silent + } + dynamicRuntime.shutdown(); + } + }.start(); + return ExecutionAnswer.ok("Server shutting down..."); + } + + // MODULE HANDLING + + @SuppressWarnings("unchecked") + @RequestMapping("/installModule.service") + public void installModule(HttpServletRequest request) throws Exception { + + // TODO : handle the exception better + + // Parse the request + List 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); + } + + @RequestMapping("/uninstallModule.service") + public void uninstallModule(@RequestParam(value = "name") String name, + @RequestParam(value = "version") String version) { + NameVersion nameVersion = new BasicNameVersion(name, version); + dynamicRuntime.uninstallModule(nameVersion); + } + + // IoC + public void setDynamicRuntime(DynamicRuntime dynamicRuntime) { + this.dynamicRuntime = dynamicRuntime; + } + +} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/SlcExecutionManager.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/SlcExecutionManager.java new file mode 100644 index 000000000..cc8e52219 --- /dev/null +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/SlcExecutionManager.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * 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.controllers; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.UUID; + +import javax.xml.transform.stream.StreamSource; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.core.attachment.Attachment; +import org.argeo.slc.core.attachment.AttachmentsStorage; +import org.argeo.slc.core.attachment.SimpleAttachment; +import org.argeo.slc.msg.ObjectList; +import org.argeo.slc.process.SlcExecution; +import org.springframework.oxm.Marshaller; +import org.springframework.oxm.Unmarshaller; +import org.springframework.xml.transform.StringResult; + +public class SlcExecutionManager { + private final static Log log = LogFactory.getLog(SlcExecutionManager.class); + + private Unmarshaller unmarshaller; + private Marshaller marshaller; + private AttachmentsStorage attachmentsStorage; + + public SlcExecutionManager(Unmarshaller unmarshaller, + Marshaller marshaller, AttachmentsStorage attachmentsStorage) { + + this.unmarshaller = unmarshaller; + this.marshaller = marshaller; + this.attachmentsStorage = attachmentsStorage; + } + + void storeRealizedFlows(SlcExecution slcExecution) { + + Attachment attachment = realizedFlowsAttachment(UUID.randomUUID() + .toString(), slcExecution); + InputStream in = null; + try { + ObjectList ol = new ObjectList(slcExecution.getRealizedFlows()); + StringResult result = new StringResult(); + marshaller.marshal(ol, result); + in = new ByteArrayInputStream(result.toString().getBytes()); + attachmentsStorage.storeAttachment(attachment, in); + + slcExecution.setRealizedFlowsXml(attachment.getUuid()); + } catch (Exception e) { + log.error("Could not store realized flows as attachment #" + + attachment.getUuid(), e); + } finally { + IOUtils.closeQuietly(in); + } + } + + void retrieveRealizedFlows(SlcExecution slcExecution) { + Attachment attachment = realizedFlowsAttachment(slcExecution + .getRealizedFlowsXml(), slcExecution); + + ByteArrayOutputStream out = null; + ByteArrayInputStream in = null; + try { + // TODO: optimize with piped streams + out = new ByteArrayOutputStream(); + attachmentsStorage.retrieveAttachment(attachment, out); + + byte[] arr = out.toByteArray(); + in = new ByteArrayInputStream(arr); + StreamSource source = new StreamSource(in); + ObjectList ol = (ObjectList) unmarshaller.unmarshal(source); + ol.fill(slcExecution.getRealizedFlows()); + } catch (Exception e) { + log.error("Could not retrieve realized flows from attachment #" + + attachment.getUuid(), e); + } finally { + IOUtils.closeQuietly(in); + IOUtils.closeQuietly(out); + } + } + + /** Unify labeling in the package */ + static Attachment realizedFlowsAttachment(String attachmentUuid, + SlcExecution slcExecution) { + return new SimpleAttachment(attachmentUuid, + "RealizedFlows of SlcExecution #" + slcExecution.getUuid(), + "text/xml"); + } +} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/management/InstallModule.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/management/InstallModule.java deleted file mode 100644 index e3c60b532..000000000 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/management/InstallModule.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2010 Mathieu Baudier - * - * 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 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; - } - -} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/management/UninstallModule.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/management/UninstallModule.java deleted file mode 100644 index f4333b239..000000000 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/management/UninstallModule.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2010 Mathieu Baudier - * - * 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 javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.argeo.slc.build.BasicNameVersion; -import org.argeo.slc.build.NameVersion; -import org.argeo.slc.deploy.DynamicRuntime; -import org.argeo.slc.web.mvc.AbstractServiceController; -import org.springframework.web.servlet.ModelAndView; - -/** . */ -public class UninstallModule extends AbstractServiceController { - private DynamicRuntime dynamicRuntime; - - @Override - protected void handleServiceRequest(HttpServletRequest request, - HttpServletResponse response, ModelAndView modelAndView) - throws Exception { - String name = request.getParameter("name"); - String version = request.getParameter("version"); - NameVersion nameVersion = new BasicNameVersion(name, version); - dynamicRuntime.uninstallModule(nameVersion); - } - - public void setDynamicRuntime(DynamicRuntime dynamicRuntime) { - this.dynamicRuntime = dynamicRuntime; - } - -} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/SlcExecutionManager.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/SlcExecutionManager.java deleted file mode 100644 index 3dec00f79..000000000 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/SlcExecutionManager.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2010 Mathieu Baudier - * - * 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.process; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.util.UUID; - -import javax.xml.transform.stream.StreamSource; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.core.attachment.Attachment; -import org.argeo.slc.core.attachment.AttachmentsStorage; -import org.argeo.slc.core.attachment.SimpleAttachment; -import org.argeo.slc.msg.ObjectList; -import org.argeo.slc.process.SlcExecution; -import org.argeo.slc.runtime.SlcAgentFactory; -import org.argeo.slc.services.SlcExecutionService; -import org.springframework.oxm.Marshaller; -import org.springframework.oxm.Unmarshaller; -import org.springframework.xml.transform.StringResult; - -public class SlcExecutionManager { - private final static Log log = LogFactory.getLog(SlcExecutionManager.class); - - private SlcAgentFactory agentFactory; - private Unmarshaller unmarshaller; - private Marshaller marshaller; - private SlcExecutionService slcExecutionService; - private AttachmentsStorage attachmentsStorage; - - public SlcExecutionManager(SlcAgentFactory agentFactory, - Unmarshaller unmarshaller, Marshaller marshaller, - SlcExecutionService slcExecutionService, - AttachmentsStorage attachmentsStorage) { - - this.agentFactory = agentFactory; - this.unmarshaller = unmarshaller; - this.marshaller = marshaller; - this.slcExecutionService = slcExecutionService; - this.attachmentsStorage = attachmentsStorage; - } - - public void storeRealizedFlows(SlcExecution slcExecution) { - - Attachment attachment = realizedFlowsAttachment(UUID.randomUUID() - .toString(), slcExecution); - InputStream in = null; - try { - ObjectList ol = new ObjectList(slcExecution.getRealizedFlows()); - StringResult result = new StringResult(); - marshaller.marshal(ol, result); - in = new ByteArrayInputStream(result.toString().getBytes()); - attachmentsStorage.storeAttachment(attachment, in); - - slcExecution.setRealizedFlowsXml(attachment.getUuid()); - } catch (Exception e) { - log.error("Could not store realized flows as attachment #" - + attachment.getUuid(), e); - } finally { - IOUtils.closeQuietly(in); - } - } - - public void retrieveRealizedFlows(SlcExecution slcExecution) { - Attachment attachment = realizedFlowsAttachment(slcExecution - .getRealizedFlowsXml(), slcExecution); - - ByteArrayOutputStream out = null; - ByteArrayInputStream in = null; - try { - // TODO: optimize with piped streams - out = new ByteArrayOutputStream(); - attachmentsStorage.retrieveAttachment(attachment, out); - - byte[] arr = out.toByteArray(); - in = new ByteArrayInputStream(arr); - StreamSource source = new StreamSource(in); - ObjectList ol = (ObjectList) unmarshaller.unmarshal(source); - ol.fill(slcExecution.getRealizedFlows()); - } catch (Exception e) { - log.error("Could not retrieve realized flows from attachment #" - + attachment.getUuid(), e); - } finally { - IOUtils.closeQuietly(in); - IOUtils.closeQuietly(out); - } - } - - /** Unify labeling in the package */ - static Attachment realizedFlowsAttachment(String attachmentUuid, - SlcExecution slcExecution) { - return new SimpleAttachment(attachmentUuid, - "RealizedFlows of SlcExecution #" + slcExecution.getUuid(), - "text/xml"); - } -} diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/result/ResultExcelView.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/result/ResultExcelView.java index 15b6220cc..b44107d37 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/result/ResultExcelView.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/result/ResultExcelView.java @@ -34,7 +34,10 @@ import org.argeo.slc.test.TestResultPart; 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 { @@ -44,7 +47,7 @@ public class ResultExcelView extends AbstractJExcelView { 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())); diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/result/ResultPdfView.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/result/ResultPdfView.java index 677bcb2e7..6393e3bcf 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/result/ResultPdfView.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/result/ResultPdfView.java @@ -37,14 +37,14 @@ import com.lowagie.text.Table; 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()));