package de.predic8.controller;

import de.predic8.model.ArchivedFile;
import de.predic8.routes.DailyMailNotification;
import de.predic8.routes.VerifyRoutes;
import de.predic8.service.ArchiveService;
import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

@RestController
@EnableGlobalMethodSecurity
public class ArchiveController {

    @Autowired
    private ProducerTemplate producerTemplate;

    @Autowired
    ArchiveService service;

    @RequestMapping(value = "/archive", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    ResponseEntity<Collection<ArchivedFile>> getArchive() {
        Collection<ArchivedFile> archived = service.findAll();
        return new ResponseEntity<Collection<ArchivedFile>>(archived, HttpStatus.OK);
    }

    @RequestMapping(value = "/archive/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    ResponseEntity<ArchivedFile> getFile(@PathVariable("id") long id) {
        ArchivedFile file = service.findOne(id);
        return file == null ? new ResponseEntity<ArchivedFile>(HttpStatus.NOT_FOUND) : new ResponseEntity<ArchivedFile>(file, HttpStatus.OK);
    }

    /*@RequestMapping(value = "/archive/verify", method = RequestMethod.GET)
    public ResponseEntity<Map<String, Boolean>> runVerify() throws Exception {
        System.out.println(producerTemplate.getCamelContext().getRoutes());
        //producerTemplate.sendBody("direct:test", VerifyRoutes.class);

        //return verify.isValid() ? new ResponseEntity<>(Collections.singletonMap("success", true), HttpStatus.OK)
        //        : new ResponseEntity<>(Collections.singletonMap("success", false), HttpStatus.OK);
        *//*if (verify.isValid()) {
            return new ResponseEntity<>(Collections.singletonMap("success", true), HttpStatus.OK);
        } else {
            Map<String, Boolean> map = new HashMap<>();
            map.put("success", false);

            return new ResponseEntity<Map<String, Boolean>>(map, HttpStatus.OK);
        }
        return null;*//*
        return null;
    }*/

    @RequestMapping(value = "/archive/mail", method = RequestMethod.GET)
    public ResponseEntity<Map<String, Boolean>> runMail() throws Exception {
        DailyMailNotification notify = new DailyMailNotification();
        notify.start();
        return new ResponseEntity<>(Collections.singletonMap("success", true), HttpStatus.OK);
    }
}

@@ -88,37 +88,28 @@
 .routes.
-DailyMailNotification
+VerifyHelper
 ;%0Aimport
@@ -187,50 +187,8 @@
 ce;%0A
-import org.apache.camel.ProducerTemplate;%0A
 impo
@@ -594,16 +594,42 @@
 ctions;%0A
+import java.util.HashMap;%0A
 import j
@@ -725,71 +725,8 @@
  %7B%0A%0A
-    @Autowired%0A    private ProducerTemplate producerTemplate;%0A%0A
     
@@ -1486,18 +1486,16 @@
  %7D%0A%0A    
-/*
 @Request
@@ -1591,31 +1591,30 @@
 Map%3CString, 
-Boolean
+Object
 %3E%3E runVerify
@@ -1647,126 +1647,77 @@
     
-System.out.println(producerTemplate.getCamelContext().getRoutes());%0A        //producerTemplate.sendBody(%22direct:test%22,
+VerifyHelper.getInstance().reset();%0A        VerifyRoutes verify = new
  Ver
@@ -1729,26 +1729,20 @@
 utes
-.class
+(
 );%0A
-%0A
         
 //re
@@ -1741,114 +1741,80 @@
     
-//return verify.isValid() ? new ResponseEntity%3C%3E(Collections.singletonMap(%22success%22, true), HttpStatus.OK)
+verify.start();%0A        while (VerifyHelper.getInstance().isBlocked()) %7B
 %0A   
@@ -1822,100 +1822,40 @@
     
-//
     
-    : new ResponseEntity%3C%3E(Collections.singletonMap(%22success%22, false), HttpStatus.OK);
+Thread.sleep(500);%0A        %7D
 %0A   
@@ -1863,22 +1863,38 @@
     
-*//*
 if (
-v
+V
 erify
+Helper.getInstance()
 .isV
@@ -2043,23 +2043,22 @@
 String, 
-Boolean
+Object
 %3E map = 
@@ -2113,17 +2113,16 @@
 false);%0A
-%0A
         
@@ -2129,461 +2129,129 @@
     
-return new ResponseEntity%3CMap%3CString, Boolean%3E%3E(map, HttpStatus.OK);%0A        %7D%0A        return null;*//*%0A        return null;%0A    %7D*/%0A%0A    @RequestMapping(value = %22/archive/ma
+map.put(%22f
 il
+e
 %22, 
-method = RequestMethod.GET)%0A    public ResponseEntity%3CMap%3CString, Boolean%3E%3E runMail() throws Exception %7B%0A        DailyMailNotification notify = new DailyMailNotification();%0A        notify.start();%0A        return new ResponseEntity%3C%3E(Collections.singletonMap(%22success%22, true)
+VerifyHelper.getInstance().getFilename());%0A            return new ResponseEntity%3CMap%3CString, Object%3E%3E(map
 , Ht
@@ -2260,20 +2260,30 @@
 Status.OK);%0A
+        %7D%0A
     %7D%0A%7D%0A

add verify route