X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fweb%2Fmvc%2Fcontrollers%2FSlcExecutionManager.java;fp=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fweb%2Fmvc%2Fcontrollers%2FSlcExecutionManager.java;h=0000000000000000000000000000000000000000;hb=651d33e13bfa9a7b46464be412023ee747e612e8;hp=3a07b79960c39df8ada3d9512d5b1412192bcc01;hpb=868102c0f0220e12eca836b6ec9b3a2b9a3441e4;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/SlcExecutionManager.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/SlcExecutionManager.java deleted file mode 100644 index 3a07b7996..000000000 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/controllers/SlcExecutionManager.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.slc.web.mvc.controllers; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.util.UUID; - -import javax.xml.transform.stream.StreamSource; - -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.ObjectList; -import org.argeo.slc.process.SlcExecution; -import org.springframework.oxm.Marshaller; -import org.springframework.oxm.Unmarshaller; -import org.springframework.xml.transform.StringResult; - -public class SlcExecutionManager { - private final static Log log = LogFactory.getLog(SlcExecutionManager.class); - - private Unmarshaller unmarshaller; - private Marshaller marshaller; - private AttachmentsStorage attachmentsStorage; - - public SlcExecutionManager(Unmarshaller unmarshaller, - Marshaller marshaller, AttachmentsStorage attachmentsStorage) { - - this.unmarshaller = unmarshaller; - this.marshaller = marshaller; - this.attachmentsStorage = attachmentsStorage; - } - - 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); - } - } - - void retrieveRealizedFlows(SlcExecution slcExecution) { - Attachment attachment = realizedFlowsAttachment(slcExecution - .getRealizedFlowsXml(), slcExecution); - - ByteArrayOutputStream out = null; - ByteArrayInputStream in = null; - try { - // TODO: optimize with piped streams - out = new ByteArrayOutputStream(); - attachmentsStorage.retrieveAttachment(attachment, out); - - byte[] arr = out.toByteArray(); - in = new ByteArrayInputStream(arr); - StreamSource source = new StreamSource(in); - ObjectList ol = (ObjectList) unmarshaller.unmarshal(source); - ol.fill(slcExecution.getRealizedFlows()); - } catch (Exception e) { - log.error("Could not retrieve realized flows from attachment #" - + attachment.getUuid(), e); - } finally { - IOUtils.closeQuietly(in); - IOUtils.closeQuietly(out); - } - } - - /** Unify labeling in the package */ - static Attachment realizedFlowsAttachment(String attachmentUuid, - SlcExecution slcExecution) { - return new SimpleAttachment(attachmentUuid, - "RealizedFlows of SlcExecution #" + slcExecution.getUuid(), - "text/xml"); - } -}