package org.microhackaton.fraudDetection;

import com.netflix.hystrix.HystrixCommand.Setter;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.nurkiewicz.asyncretry.AsyncRetryExecutor;
import com.ofg.infrastructure.web.resttemplate.fluent.ServiceRestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
@Async
public class FraudDetectionService {

    private final ServiceRestClient serviceRestClient;
    private final AsyncRetryExecutor asyncRetryExecutor;
    private Logger logger = LoggerFactory.getLogger(FraudDetectionService.class);

    @Autowired
    public FraudDetectionService(ServiceRestClient serviceRestClient, AsyncRetryExecutor asyncRetryExecutor) {
        this.serviceRestClient = serviceRestClient;
        this.asyncRetryExecutor = asyncRetryExecutor;
    }

    public void verifyStatus(String id, FraudVerification fraudVerification){
        String result = serviceRestClient.forService("decisionMaker")
                .retryUsing(asyncRetryExecutor.withMaxRetries(5))
                .put()
                .withCircuitBreaker(
                        Setter
                        .withGroupKey(HystrixCommandGroupKey.Factory.asKey("fraudDetection"))
                        .andCommandKey(HystrixCommandKey.Factory.asKey("notifyDecisionMaker"))
                )
                .onUrl("/api/loanApplication/"+id)
                .body(fraudVerification)
                .withHeaders()
                    .contentTypeJson()
                .andExecuteFor()
                    .anObject()
                    .ofType(String.class);
        logger.info("result = " + result);
    }

}

@@ -309,16 +309,44 @@
 Client;%0A
+import groovy.lang.Closure;%0A
 import o
@@ -1374,24 +1374,32 @@
             
+        
 .withGroupKe
@@ -1452,24 +1452,32 @@
 etection%22))%0A
+        
             
@@ -1555,24 +1555,530 @@
 ionMaker%22))%0A
+                        , new Closure(this) %7B%0A                            @Override%0A                            public Object call(Object... args) %7B%0A                                logger.info(%22test close circut%22);%0A                                return %22test%22;%0A                            %7D%0A                            @Override%0A                            public void run() %7B%0A                                logger.info(%22test close circut - run%22);%0A                            %7D%0A                        %7D%0A
             
@@ -2127,16 +2127,20 @@
 lication
+_del
 /%22+id)%0A 

Test Hystrix closure