]> git.argeo.org Git - gpl/argeo-slc.git/blob - GetSlcExecution.java
7a6fac1d3d6986e58aebddc45a8b57e594919caf
[gpl/argeo-slc.git] / GetSlcExecution.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package org.argeo.slc.web.mvc.process;
18
19 import java.io.ByteArrayInputStream;
20 import java.io.ByteArrayOutputStream;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24 import javax.xml.transform.stream.StreamSource;
25
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;
37
38 /** Lists SLC executions possibly filtering them. */
39 public class GetSlcExecution extends AbstractServiceController {
40 private final static Log log = LogFactory.getLog(GetSlcExecution.class);
41
42 private SlcExecutionDao slcExecutionDao;
43 private Unmarshaller unmarshaller;
44
45 private AttachmentsStorage attachmentsStorage;
46
47 @Override
48 protected void handleServiceRequest(HttpServletRequest request,
49 HttpServletResponse response, ModelAndView modelAndView)
50 throws Exception {
51 String uuid = request.getParameter("uuid");
52 SlcExecution slcExecution = slcExecutionDao.getSlcExecution(uuid);
53
54 // StringSource source = new StringSource(slcExecution
55 // .getRealizedFlowsXml());
56 // ObjectList ol2 = (ObjectList) unmarshaller.unmarshal(source);
57 // ol2.fill(slcExecution.getRealizedFlows());
58 retrieveRealizedFlows(slcExecution);
59
60 modelAndView.addObject(slcExecution);
61 }
62
63 protected void retrieveRealizedFlows(SlcExecution slcExecution) {
64 Attachment attachment = NewSlcExecutionController
65 .realizedFlowsAttachment(slcExecution.getRealizedFlowsXml(),
66 slcExecution);
67
68 ByteArrayOutputStream out = null;
69 ByteArrayInputStream in = null;
70 try {
71 // TODO: optimize with piped streams
72 out = new ByteArrayOutputStream();
73 attachmentsStorage.retrieveAttachment(attachment, out);
74
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);
83 } finally {
84 IOUtils.closeQuietly(in);
85 IOUtils.closeQuietly(out);
86 }
87 }
88
89 public void setSlcExecutionDao(SlcExecutionDao slcExecutionDao) {
90 this.slcExecutionDao = slcExecutionDao;
91 }
92
93 public void setUnmarshaller(Unmarshaller unmarshaller) {
94 this.unmarshaller = unmarshaller;
95 }
96
97 public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) {
98 this.attachmentsStorage = attachmentsStorage;
99 }
100
101 }