package org.argeo.slc.web.mvc.process;\r
\r
import java.io.BufferedReader;\r
+import java.io.ByteArrayInputStream;\r
+import java.io.InputStream;\r
import java.util.UUID;\r
\r
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
+import org.apache.commons.io.IOUtils;\r
import org.apache.commons.logging.Log;\r
import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.core.attachment.Attachment;\r
+import org.argeo.slc.core.attachment.AttachmentsStorage;\r
+import org.argeo.slc.core.attachment.SimpleAttachment;\r
import org.argeo.slc.msg.MsgConstants;\r
import org.argeo.slc.msg.ObjectList;\r
import org.argeo.slc.process.SlcExecution;\r
private Marshaller marshaller;\r
private SlcExecutionService slcExecutionService;\r
\r
+ private AttachmentsStorage attachmentsStorage;\r
+\r
@Override\r
protected void handleServiceRequest(HttpServletRequest request,\r
HttpServletResponse response, ModelAndView modelAndView)\r
new SlcExecutionStep(SlcExecutionStep.TYPE_START,\r
"Process started from the Web UI"));\r
\r
- ObjectList ol = new ObjectList(slcExecution.getRealizedFlows());\r
- StringResult result = new StringResult();\r
- marshaller.marshal(ol, result);\r
- slcExecution.setRealizedFlowsXml(result.toString());\r
+ // ObjectList ol = new ObjectList(slcExecution.getRealizedFlows());\r
+ // StringResult result = new StringResult();\r
+ // marshaller.marshal(ol, result);\r
+ // slcExecution.setRealizedFlowsXml(result.toString());\r
+ storeRealizedFlows(slcExecution);\r
\r
slcExecutionService.newExecution(slcExecution);\r
\r
agent.runSlcExecution(slcExecution);\r
}\r
\r
+ protected void storeRealizedFlows(SlcExecution slcExecution) {\r
+ Attachment attachment = realizedFlowsAttachment(UUID.randomUUID()\r
+ .toString(), slcExecution);\r
+ InputStream in = null;\r
+ try {\r
+\r
+ ObjectList ol = new ObjectList(slcExecution.getRealizedFlows());\r
+ StringResult result = new StringResult();\r
+ marshaller.marshal(ol, result);\r
+\r
+ in = new ByteArrayInputStream(result.toString().getBytes());\r
+ attachmentsStorage.storeAttachment(attachment, in);\r
+\r
+ slcExecution.setRealizedFlowsXml(attachment.getUuid());\r
+\r
+ } catch (Exception e) {\r
+ log.error("Could not store realized flows as attachment #"\r
+ + attachment.getUuid(), e);\r
+ } finally {\r
+ IOUtils.closeQuietly(in);\r
+ }\r
+ }\r
+\r
public void setUnmarshaller(Unmarshaller unmarshaller) {\r
this.unmarshaller = unmarshaller;\r
}\r
this.marshaller = marshaller;\r
}\r
\r
+ public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) {\r
+ this.attachmentsStorage = attachmentsStorage;\r
+ }\r
+\r
+ /** Unify labelling in the package */\r
+ static Attachment realizedFlowsAttachment(String attachmentUuid,\r
+ SlcExecution slcExecution) {\r
+ return new SimpleAttachment(attachmentUuid,\r
+ "RealizedFlows of SlcExecution #" + slcExecution.getUuid(),\r
+ "text/xml");\r
+ }\r
}\r