package com.ch.resources;

import static com.ch.service.LoggingService.LoggingLevel.INFO;
import static com.ch.service.LoggingService.tag;

import com.ch.application.FormsServiceApplication;
import com.ch.configuration.CompaniesHouseConfiguration;
import com.ch.helpers.ClientHelper;
import com.ch.service.LoggingService;
import com.codahale.metrics.Timer;
import io.dropwizard.auth.Auth;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * Barcode Resource to make calls for barcodes to the CH Barcode Service.
 */
@Path("/barcode")
public class BarcodeResource {
  public static final int SLEEP_MILLIS = 1000;
  private static final Timer timer = FormsServiceApplication.registry.timer("BarcodeResource");

  private final ClientHelper client;
  private final CompaniesHouseConfiguration configuration;

  public BarcodeResource(ClientHelper client, CompaniesHouseConfiguration configuration) {
    this.client = client;
    this.configuration = configuration;
  }

  /**
   * Retrieves unique barcode from CHIPS.
   *
   * @param dateReceived date received json object.
   * @return response from chips.
   */
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response getBarcode(@Auth
                             String dateReceived) throws InterruptedException {
    final Timer.Context context = timer.time();
    try {
      LoggingService.log(tag, INFO, "Barcode request from Salesforce: " + dateReceived,
        BarcodeResource.class);

      // POST to Barcode Service
      Response response = client.postJson(configuration.getBarcodeServiceUrl(), dateReceived);
      LoggingService.log(tag, INFO, "Response from Barcode Service " + response,
        BarcodeResource.class);
      Thread.sleep(SLEEP_MILLIS);
      return response;

  
    } finally {
      context.stop();
      
    }
  }
}

@@ -696,55 +696,8 @@
 e %7B%0A
-  public static final int SLEEP_MILLIS = 1000;%0A
   pr
@@ -1369,36 +1369,8 @@
 ved)
- throws InterruptedException
  %7B%0A 
@@ -1792,42 +1792,8 @@
 s);%0A
-      Thread.sleep(SLEEP_MILLIS);%0A
     
@@ -1812,19 +1812,16 @@
 ponse;%0A%0A
-  %0A
     %7D fi
@@ -1854,15 +1854,8 @@
 ();%0A
-      %0A
     

Remove timeout from BarcodeResource