2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.web
.mvc
.process
;
19 import java
.io
.ByteArrayInputStream
;
20 import java
.io
.ByteArrayOutputStream
;
22 import javax
.servlet
.http
.HttpServletRequest
;
23 import javax
.servlet
.http
.HttpServletResponse
;
24 import javax
.xml
.transform
.stream
.StreamSource
;
26 import org
.apache
.commons
.io
.IOUtils
;
27 import org
.apache
.commons
.logging
.Log
;
28 import org
.apache
.commons
.logging
.LogFactory
;
29 import org
.argeo
.slc
.core
.attachment
.Attachment
;
30 import org
.argeo
.slc
.core
.attachment
.AttachmentsStorage
;
31 import org
.argeo
.slc
.dao
.process
.SlcExecutionDao
;
32 import org
.argeo
.slc
.msg
.ObjectList
;
33 import org
.argeo
.slc
.process
.SlcExecution
;
34 import org
.argeo
.slc
.web
.mvc
.AbstractServiceController
;
35 import org
.springframework
.oxm
.Unmarshaller
;
36 import org
.springframework
.web
.servlet
.ModelAndView
;
38 /** Lists SLC executions possibly filtering them. */
39 public class GetSlcExecution
extends AbstractServiceController
{
40 private final static Log log
= LogFactory
.getLog(GetSlcExecution
.class);
42 private SlcExecutionDao slcExecutionDao
;
43 private Unmarshaller unmarshaller
;
45 private AttachmentsStorage attachmentsStorage
;
48 protected void handleServiceRequest(HttpServletRequest request
,
49 HttpServletResponse response
, ModelAndView modelAndView
)
51 String uuid
= request
.getParameter("uuid");
52 SlcExecution slcExecution
= slcExecutionDao
.getSlcExecution(uuid
);
54 // StringSource source = new StringSource(slcExecution
55 // .getRealizedFlowsXml());
56 // ObjectList ol2 = (ObjectList) unmarshaller.unmarshal(source);
57 // ol2.fill(slcExecution.getRealizedFlows());
58 retrieveRealizedFlows(slcExecution
);
60 modelAndView
.addObject(slcExecution
);
63 protected void retrieveRealizedFlows(SlcExecution slcExecution
) {
64 Attachment attachment
= NewSlcExecutionController
65 .realizedFlowsAttachment(slcExecution
.getRealizedFlowsXml(),
68 ByteArrayOutputStream out
= null;
69 ByteArrayInputStream in
= null;
71 // TODO: optimize with piped streams
72 out
= new ByteArrayOutputStream();
73 attachmentsStorage
.retrieveAttachment(attachment
, out
);
75 byte[] arr
= out
.toByteArray();
76 in
= new ByteArrayInputStream(arr
);
77 StreamSource source
= new StreamSource(in
);
78 ObjectList ol
= (ObjectList
) unmarshaller
.unmarshal(source
);
79 ol
.fill(slcExecution
.getRealizedFlows());
80 } catch (Exception e
) {
81 log
.error("Could not retrieve realized flows from attachment #"
82 + attachment
.getUuid(), e
);
84 IOUtils
.closeQuietly(in
);
85 IOUtils
.closeQuietly(out
);
89 public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao
) {
90 this.slcExecutionDao
= slcExecutionDao
;
93 public void setUnmarshaller(Unmarshaller unmarshaller
) {
94 this.unmarshaller
= unmarshaller
;
97 public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage
) {
98 this.attachmentsStorage
= attachmentsStorage
;