]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsTreeTestResultListener.java
Attachments management
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.activemq / src / main / java / org / argeo / slc / jms / JmsTreeTestResultListener.java
index b315c0143ba4dad07d3ce299c12614d6e0705ce9..7da976a4de3d7bbe9f222ab4b9409f3ba9f48a72 100644 (file)
@@ -5,7 +5,11 @@ import javax.jms.Destination;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.SlcException;
+import org.argeo.slc.core.attachment.Attachment;
+import org.argeo.slc.core.attachment.SimpleAttachment;
 import org.argeo.slc.core.test.tree.TreeTestResult;
+import org.argeo.slc.core.test.tree.TreeTestResultListener;
+import org.argeo.slc.msg.test.tree.AddTreeTestResultAttachmentRequest;
 import org.argeo.slc.msg.test.tree.CloseTreeTestResultRequest;
 import org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest;
 import org.argeo.slc.msg.test.tree.ResultPartRequest;
@@ -13,16 +17,17 @@ import org.argeo.slc.test.TestResultListener;
 import org.argeo.slc.test.TestResultPart;
 import org.springframework.jms.core.JmsTemplate;
 
-public class JmsTreeTestResultListener implements
-               TestResultListener<TreeTestResult> {
+public class JmsTreeTestResultListener implements TreeTestResultListener {
        private final Log log = LogFactory.getLog(getClass());
 
        private Boolean onlyOnClose = false;
        private JmsTemplate jmsTemplate;
 
-       private Destination createDestination;
-       private Destination addResultPartDestination;
-       private Destination closeDestination;
+       private Destination executionEventDestination;
+
+       // private Destination createDestination;
+       // private Destination addResultPartDestination;
+       // private Destination closeDestination;
 
        public void resultPartAdded(TreeTestResult testResult,
                        TestResultPart testResultPart) {
@@ -40,7 +45,7 @@ public class JmsTreeTestResultListener implements
                                        log.debug("Send create result request for result "
                                                        + testResult.getUuid());
 
-                               jmsTemplate.convertAndSend(createDestination, req);
+                               jmsTemplate.convertAndSend(executionEventDestination, req);
                        } else {
                                ResultPartRequest req = new ResultPartRequest(testResult);
 
@@ -48,7 +53,7 @@ public class JmsTreeTestResultListener implements
                                        log.debug("Send result parts for result "
                                                        + testResult.getUuid());
 
-                               jmsTemplate.convertAndSend(addResultPartDestination, req);
+                               jmsTemplate.convertAndSend(executionEventDestination, req);
                        }
                } catch (Exception e) {
                        throw new SlcException("Could not notify to JMS", e);
@@ -65,7 +70,7 @@ public class JmsTreeTestResultListener implements
                                        log.debug("Send create result request for result "
                                                        + testResult.getUuid());
 
-                               jmsTemplate.convertAndSend(createDestination, req);
+                               jmsTemplate.convertAndSend(executionEventDestination, req);
                        } else {
                                CloseTreeTestResultRequest req = new CloseTreeTestResultRequest(
                                                testResult);
@@ -74,7 +79,7 @@ public class JmsTreeTestResultListener implements
                                        log.debug("Send close result request for result "
                                                        + testResult.getUuid());
 
-                               jmsTemplate.convertAndSend(closeDestination, req);
+                               jmsTemplate.convertAndSend(executionEventDestination, req);
 
                        }
                } catch (Exception e) {
@@ -82,6 +87,19 @@ public class JmsTreeTestResultListener implements
                }
        }
 
+       public void addAttachment(TreeTestResult testResult, Attachment attachment) {
+               try {
+                       AddTreeTestResultAttachmentRequest req = new AddTreeTestResultAttachmentRequest();
+                       req.setResultUuid(testResult.getUuid());
+                       req.setAttachment((SimpleAttachment) attachment);
+                       jmsTemplate.convertAndSend(executionEventDestination, req);
+
+               } catch (Exception e) {
+                       throw new SlcException("Could not notify to JMS", e);
+               }
+
+       }
+
        public void setOnlyOnClose(Boolean onlyOnClose) {
                this.onlyOnClose = onlyOnClose;
        }
@@ -90,16 +108,9 @@ public class JmsTreeTestResultListener implements
                this.jmsTemplate = jmsTemplate;
        }
 
-       public void setCreateDestination(Destination createDestination) {
-               this.createDestination = createDestination;
-       }
-
-       public void setAddResultPartDestination(Destination addResultPartDestination) {
-               this.addResultPartDestination = addResultPartDestination;
-       }
-
-       public void setCloseDestination(Destination closeDestination) {
-               this.closeDestination = closeDestination;
+       public void setExecutionEventDestination(
+                       Destination executionEventDestination) {
+               this.executionEventDestination = executionEventDestination;
        }
 
 }