1 package org
.argeo
.slc
.web
.mvc
.process
;
3 import java
.io
.ByteArrayInputStream
;
4 import java
.io
.ByteArrayOutputStream
;
6 import javax
.servlet
.http
.HttpServletRequest
;
7 import javax
.servlet
.http
.HttpServletResponse
;
8 import javax
.xml
.transform
.stream
.StreamSource
;
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
;
22 /** Lists SLC executions possibly filtering them. */
23 public class GetSlcExecution
extends AbstractServiceController
{
24 private final static Log log
= LogFactory
.getLog(GetSlcExecution
.class);
26 private SlcExecutionDao slcExecutionDao
;
27 private Unmarshaller unmarshaller
;
29 private AttachmentsStorage attachmentsStorage
;
32 protected void handleServiceRequest(HttpServletRequest request
,
33 HttpServletResponse response
, ModelAndView modelAndView
)
35 String uuid
= request
.getParameter("uuid");
36 SlcExecution slcExecution
= slcExecutionDao
.getSlcExecution(uuid
);
38 // StringSource source = new StringSource(slcExecution
39 // .getRealizedFlowsXml());
40 // ObjectList ol2 = (ObjectList) unmarshaller.unmarshal(source);
41 // ol2.fill(slcExecution.getRealizedFlows());
42 retrieveRealizedFlows(slcExecution
);
44 modelAndView
.addObject(slcExecution
);
47 protected void retrieveRealizedFlows(SlcExecution slcExecution
) {
48 Attachment attachment
= NewSlcExecutionController
49 .realizedFlowsAttachment(slcExecution
.getRealizedFlowsXml(),
52 ByteArrayOutputStream out
= null;
53 ByteArrayInputStream in
= null;
55 // TODO: optimize with piped streams
56 out
= new ByteArrayOutputStream();
57 attachmentsStorage
.retrieveAttachment(attachment
, out
);
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
);
68 IOUtils
.closeQuietly(in
);
69 IOUtils
.closeQuietly(out
);
73 public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao
) {
74 this.slcExecutionDao
= slcExecutionDao
;
77 public void setUnmarshaller(Unmarshaller unmarshaller
) {
78 this.unmarshaller
= unmarshaller
;
81 public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage
) {
82 this.attachmentsStorage
= attachmentsStorage
;