package fr.synchrotron.soleil.ica.msvervice.vertx.verticle.pomexporter;

import fr.synchrotron.soleil.ica.ci.lib.mongodb.pomexporter.repository.POMDocumentRepository;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.pomexporter.service.POMExportService;
import fr.synchrotron.soleil.ica.ci.lib.mongodb.util.BasicMongoDBDataSource;
import org.vertx.java.core.Handler;
import org.vertx.java.core.eventbus.EventBus;
import org.vertx.java.core.eventbus.Message;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.platform.Verticle;

import java.io.StringWriter;

/**
 * @author Gregory Boissinot
 */
public class POMExporterWorkerVerticle extends Verticle {

    @Override
    public void start() {

        final JsonObject config = container.config();

        final EventBus eventBus = vertx.eventBus();
        eventBus.registerHandler("pom.exporter", new Handler<Message>() {
            @Override
            public void handle(Message message) {

                JsonObject pomIdObject = (JsonObject) message.body();

                String org = pomIdObject.getString("org");
                String name = pomIdObject.getString("name");
                String version = pomIdObject.getString("version");
                String status = pomIdObject.getString("status");

                POMExportService pomExportService = new POMExportService(new POMDocumentRepository(getBasicMongoDBDataSource(config)));
                StringWriter stringWriter = new StringWriter();
                pomExportService.exportPomFile(stringWriter, org, name, version, status);
                message.reply(stringWriter.toString());
            }
        });
    }

    private BasicMongoDBDataSource getBasicMongoDBDataSource(JsonObject config) {
        return new BasicMongoDBDataSource(
                config.getString("mongo.host"),
                Integer.parseInt(config.getString("mongo.port")),
                config.getString("mongo.dbname"));
    }

}

@@ -953,24 +953,50 @@
 message) %7B%0A%0A
+                try %7B%0A    
             
@@ -1049,25 +1049,28 @@
 age.body();%0A
-%0A
+    
             
@@ -1128,24 +1128,28 @@
             
+  
+  
 String name 
@@ -1177,24 +1177,28 @@
 ng(%22name%22);%0A
+    
             
@@ -1248,24 +1248,28 @@
 %22version%22);%0A
+    
             
@@ -1321,17 +1321,20 @@
 atus%22);%0A
-%0A
+    
         
@@ -1473,24 +1473,28 @@
             
+    
 StringWriter
@@ -1545,16 +1545,20 @@
         
+  
+  
 pomExpor
@@ -1639,16 +1639,20 @@
         
+    
 message.
@@ -1679,24 +1679,133 @@
 oString());%0A
+                %7D catch (Throwable e) %7B%0A                    message.reply(e.getMessage());%0A                %7D%0A
             

Add exception management