]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/GetSlcExecution.java
Introduction of annotation to handle MVC flows // Class cleaning
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / web / mvc / process / GetSlcExecution.java
1 package org.argeo.slc.web.mvc.process;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.ByteArrayOutputStream;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8 import javax.xml.transform.stream.StreamSource;
9
10 import org.apache.commons.io.IOUtils;
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13 import org.argeo.slc.core.attachment.Attachment;
14 import org.argeo.slc.core.attachment.AttachmentsStorage;
15 import org.argeo.slc.dao.process.SlcExecutionDao;
16 import org.argeo.slc.msg.ObjectList;
17 import org.argeo.slc.process.SlcExecution;
18 import org.argeo.slc.web.mvc.AbstractServiceController;
19 import org.springframework.oxm.Unmarshaller;
20 import org.springframework.web.servlet.ModelAndView;
21
22 /** Lists SLC executions possibly filtering them. */
23 public class GetSlcExecution extends AbstractServiceController {
24 private final static Log log = LogFactory.getLog(GetSlcExecution.class);
25
26 private SlcExecutionDao slcExecutionDao;
27 private Unmarshaller unmarshaller;
28
29 private AttachmentsStorage attachmentsStorage;
30
31 @Override
32 protected void handleServiceRequest(HttpServletRequest request,
33 HttpServletResponse response, ModelAndView modelAndView)
34 throws Exception {
35 String uuid = request.getParameter("uuid");
36 SlcExecution slcExecution = slcExecutionDao.getSlcExecution(uuid);
37
38 // StringSource source = new StringSource(slcExecution
39 // .getRealizedFlowsXml());
40 // ObjectList ol2 = (ObjectList) unmarshaller.unmarshal(source);
41 // ol2.fill(slcExecution.getRealizedFlows());
42 retrieveRealizedFlows(slcExecution);
43
44 modelAndView.addObject(slcExecution);
45 }
46
47 protected void retrieveRealizedFlows(SlcExecution slcExecution) {
48 Attachment attachment = NewSlcExecutionController
49 .realizedFlowsAttachment(slcExecution.getRealizedFlowsXml(),
50 slcExecution);
51
52 ByteArrayOutputStream out = null;
53 ByteArrayInputStream in = null;
54 try {
55 // TODO: optimize with piped streams
56 out = new ByteArrayOutputStream();
57 attachmentsStorage.retrieveAttachment(attachment, out);
58
59 byte[] arr = out.toByteArray();
60 in = new ByteArrayInputStream(arr);
61 StreamSource source = new StreamSource(in);
62 ObjectList ol = (ObjectList) unmarshaller.unmarshal(source);
63 ol.fill(slcExecution.getRealizedFlows());
64 } catch (Exception e) {
65 log.error("Could not retrieve realized flows from attachment #"
66 + attachment.getUuid(), e);
67 } finally {
68 IOUtils.closeQuietly(in);
69 IOUtils.closeQuietly(out);
70 }
71 }
72
73 public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao) {
74 this.slcExecutionDao = slcExecutionDao;
75 }
76
77 public void setUnmarshaller(Unmarshaller unmarshaller) {
78 this.unmarshaller = unmarshaller;
79 }
80
81 public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) {
82 this.attachmentsStorage = attachmentsStorage;
83 }
84
85 }