// @SuppressWarnings("deprecation")
  @Transactional
  @Override
  public Collection statusByCollection(Collection collection, Long accountId) throws Exception {
    if (collection != null) {
      try {
        /** Make a call to fetcher Status Rest API */
        Client client = ClientBuilder.newBuilder().register(JacksonFeature.class).build();

        String path = "";
        if (CollectionType.Twitter.equals(collection.getProvider())
            || CollectionType.Facebook.equals(collection.getProvider())) {
          path = "/" + collection.getProvider().toString().toLowerCase() + "/status?id=";
        } else if (CollectionType.SMS.equals(collection.getProvider())) {
          path = "/sms/status?collection_code=";
        }

        WebTarget webResource =
            client.target(fetchMainUrl + path + URLEncoder.encode(collection.getCode(), "UTF-8"));
        Response clientResponse = webResource.request(MediaType.APPLICATION_JSON).get();

        String jsonString = clientResponse.readEntity(String.class);
        JSONParser parser = new JSONParser();
        JSONObject jsonResponse = (JSONObject) parser.parse(jsonString);
        collection =
            updateStatusCollection(jsonResponse.get("entity").toString(), collection, accountId);
        return collection;
      } catch (Exception e) {
        String msg = "Error while getting status for collection from Remote FetchMain Collection";
        logger.error(msg, e);
        throw new Exception(msg);
      }
    }
    return null;
  }
  @Override
  @Transactional(readOnly = false)
  public Collection startFetcher(FetcherRequestDTO fetcherRequest, Collection collection) {
    try {
      /** Rest call to Fetcher */
      Client client = ClientBuilder.newBuilder().register(JacksonFeature.class).build();

      if (CollectionType.Twitter.equals(collection.getProvider())
          || CollectionType.Facebook.equals(collection.getProvider())) {
        WebTarget webResource =
            client.target(
                fetchMainUrl + "/" + collection.getProvider().toString().toLowerCase() + "/start");

        ObjectMapper objectMapper = JacksonWrapper.getObjectMapper();

        Response clientResponse =
            webResource
                .request(MediaType.APPLICATION_JSON)
                .post(Entity.json(objectMapper.writeValueAsString(fetcherRequest)), Response.class);

        // logger.info("ObjectMapper: " + objectMapper.writeValueAsString(fetcherRequest));
        String jsonString = clientResponse.readEntity(String.class);
        JSONParser parser = new JSONParser();
        JSONObject jsonResponse = (JSONObject) parser.parse(jsonString);
        // logger.info("NEW STRING: " + jsonResponse);
        FetcheResponseDTO response =
            objectMapper.readValue(jsonResponse.get("entity").toString(), FetcheResponseDTO.class);
        logger.info("start Response from fetchMain " + objectMapper.writeValueAsString(response));
        collection.setStatus(CollectionStatus.getByStatus(response.getStatusCode()));
      } else if (CollectionType.SMS.equals(collection.getProvider())) {
        WebTarget webResource =
            client.target(
                fetchMainUrl
                    + "/sms/start?collection_code="
                    + URLEncoder.encode(collection.getCode(), "UTF-8"));
        Response response = webResource.request(MediaType.APPLICATION_JSON).get();
        if (response.getStatus() == 200) collection.setStatus(CollectionStatus.INITIALIZING);
      }
      /** Update Status To database */
      collectionRepository.update(collection);
      return collection;
    } catch (Exception e) {
      logger.error("Error while starting Remote FetchMain Collection", e);
    }
    return null;
  }