X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fweb%2Fmvc%2Fprocess%2FNewSlcExecutionController.java;fp=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fweb%2Fmvc%2Fprocess%2FNewSlcExecutionController.java;h=5f225bff54ba0f09066d8ebb7ebffad8480f8a81;hb=2e5b26763f0e44d4be7c302aebcb759726de4d1f;hp=d4a67b19d91ed51f1cdcb061b8bf692b73a3dd22;hpb=75d76f02dc7524ebee6c1996f87222eee991f4e6;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/NewSlcExecutionController.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/NewSlcExecutionController.java index d4a67b19d..5f225bff5 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/NewSlcExecutionController.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/NewSlcExecutionController.java @@ -1,13 +1,19 @@ package org.argeo.slc.web.mvc.process; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.slc.core.attachment.Attachment; +import org.argeo.slc.core.attachment.AttachmentsStorage; +import org.argeo.slc.core.attachment.SimpleAttachment; import org.argeo.slc.msg.MsgConstants; import org.argeo.slc.msg.ObjectList; import org.argeo.slc.process.SlcExecution; @@ -33,6 +39,8 @@ public class NewSlcExecutionController extends AbstractServiceController { private Marshaller marshaller; private SlcExecutionService slcExecutionService; + private AttachmentsStorage attachmentsStorage; + @Override protected void handleServiceRequest(HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView) @@ -76,10 +84,11 @@ public class NewSlcExecutionController extends AbstractServiceController { new SlcExecutionStep(SlcExecutionStep.TYPE_START, "Process started from the Web UI")); - ObjectList ol = new ObjectList(slcExecution.getRealizedFlows()); - StringResult result = new StringResult(); - marshaller.marshal(ol, result); - slcExecution.setRealizedFlowsXml(result.toString()); + // ObjectList ol = new ObjectList(slcExecution.getRealizedFlows()); + // StringResult result = new StringResult(); + // marshaller.marshal(ol, result); + // slcExecution.setRealizedFlowsXml(result.toString()); + storeRealizedFlows(slcExecution); slcExecutionService.newExecution(slcExecution); @@ -87,6 +96,29 @@ public class NewSlcExecutionController extends AbstractServiceController { agent.runSlcExecution(slcExecution); } + protected void storeRealizedFlows(SlcExecution slcExecution) { + Attachment attachment = realizedFlowsAttachment(UUID.randomUUID() + .toString(), slcExecution); + InputStream in = null; + try { + + ObjectList ol = new ObjectList(slcExecution.getRealizedFlows()); + StringResult result = new StringResult(); + marshaller.marshal(ol, result); + + in = new ByteArrayInputStream(result.toString().getBytes()); + attachmentsStorage.storeAttachment(attachment, in); + + slcExecution.setRealizedFlowsXml(attachment.getUuid()); + + } catch (Exception e) { + log.error("Could not store realized flows as attachment #" + + attachment.getUuid(), e); + } finally { + IOUtils.closeQuietly(in); + } + } + public void setUnmarshaller(Unmarshaller unmarshaller) { this.unmarshaller = unmarshaller; } @@ -103,4 +135,15 @@ public class NewSlcExecutionController extends AbstractServiceController { this.marshaller = marshaller; } + public void setAttachmentsStorage(AttachmentsStorage attachmentsStorage) { + this.attachmentsStorage = attachmentsStorage; + } + + /** Unify labelling in the package */ + static Attachment realizedFlowsAttachment(String attachmentUuid, + SlcExecution slcExecution) { + return new SimpleAttachment(attachmentUuid, + "RealizedFlows of SlcExecution #" + slcExecution.getUuid(), + "text/xml"); + } }