package com.khoubyari.example.service;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.khoubyari.example.domain.Endpoint;
import com.khoubyari.example.domain.EndpointStatus;
import com.khoubyari.example.domain.Script;
import com.khoubyari.example.domain.Status;

/**
 * Created by ann on 5/20/15.
 */

@Service
public class StatusService {

  private static final Logger log = LoggerFactory.getLogger(StatusService.class);

  @Autowired
  private EndpointService endpointService;

  public StatusService() {

  }

  public Status getStatus(EndpointStatus endpointStatus) {

    if (endpointStatus == null) {
      return null;
    }

    Endpoint endpoint = endpointService.getEndpoint(endpointStatus.getId(),
        endpointStatus.getApiKey());

    // Integer dateInt =
    // Integer.parseInt(endpointStatus.getLastUpdatedScripts());
    // Date lastUpdatedScriptsOnEndpoint = new Date(dateInt);
    Date lastUpdatedScriptsOnEndpoint = endpointStatus.getLastUpdatedScripts();
    Status status = null;

    if (endpoint != null) {
      for (Script script : endpoint.getScripts()) {
        if (script.getScriptLastUpdated().after(lastUpdatedScriptsOnEndpoint)) {
          status = new Status(Boolean.TRUE);
        }
      }
    }

    if (status == null) {
      status = new Status(Boolean.FALSE);
    }
    return status;
  }
}

@@ -900,140 +900,106 @@
 ));%0A
-%0A
     
-// Integer dateInt =%0A    // Integer.parseInt(endpointStatus.getLastUpdatedScripts());%0A    // Date lastUpdatedScriptsOnE
+log.error(%22**********************%5Cn%22 + endpoint);%0A    Status status = null;%0A%0A    if (e
 ndpoint 
 = ne
@@ -998,29 +998,21 @@
 int 
+!
 = n
-ew Date(dateInt);%0A
+ull) %7B%0A  
     
@@ -1091,62 +1091,8 @@
 ();%0A
-    Status status = null;%0A%0A    if (endpoint != null) %7B
 %0A   

put me on the slow list, I need the method requring a request body to be a POST, not a GET.