[UI] Support UI partial control
[validation.git] / ui / src / main / java / org / akraino / validation / ui / client / nexus / NexusExecutorClient.java
index 7ee7239..30206bf 100644 (file)
@@ -22,20 +22,24 @@ import java.net.Proxy;
 import java.net.URL;
 import java.security.KeyManagementException;
 import java.security.NoSuchAlgorithmException;
-import java.security.cert.X509Certificate;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
+import java.util.Locale;
 
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
+import javax.annotation.Nonnull;
 
 import org.akraino.validation.ui.client.nexus.resources.RobotTestResult;
-import org.akraino.validation.ui.client.nexus.resources.WrapperRobotTestResult;
+import org.akraino.validation.ui.client.nexus.resources.Status;
+import org.akraino.validation.ui.client.nexus.resources.TestInfoYaml;
+import org.akraino.validation.ui.client.nexus.resources.ValidationNexusTestResult;
+import org.akraino.validation.ui.client.nexus.resources.WRobotNexusTestResult;
 import org.akraino.validation.ui.data.BlueprintLayer;
 import org.apache.commons.httpclient.HttpException;
 import org.json.JSONObject;
@@ -44,12 +48,16 @@ import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.springframework.stereotype.Service;
 
 import com.fasterxml.jackson.annotation.JsonInclude.Include;
 import com.fasterxml.jackson.core.JsonParseException;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
 import com.sun.jersey.api.client.Client;
 import com.sun.jersey.api.client.ClientHandlerException;
 import com.sun.jersey.api.client.ClientResponse;
@@ -58,21 +66,19 @@ import com.sun.jersey.api.client.WebResource;
 import com.sun.jersey.api.client.config.ClientConfig;
 import com.sun.jersey.api.client.config.DefaultClientConfig;
 import com.sun.jersey.api.json.JSONConfiguration;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
 import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;
 import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
 
+@Service
 public final class NexusExecutorClient {
 
     private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(NexusExecutorClient.class);
 
     private final Client client;
     private final String baseurl;
-    private final HostnameVerifier hostnameVerifier;
-    private final TrustManager[] trustAll;
 
-    public NexusExecutorClient(String newBaseurl) {
-        this.baseurl = newBaseurl;
+    public NexusExecutorClient() {
+        this.baseurl = PortalApiProperties.getProperty("nexus_url");
         ClientConfig clientConfig = new DefaultClientConfig();
         clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
         this.client = new Client(new URLConnectionClientHandler(new HttpURLConnectionFactory() {
@@ -81,10 +87,10 @@ public final class NexusExecutorClient {
             @Override
             public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
                 try {
-                    String proxyIp =
-                            System.getenv("NEXUS_PROXY").substring(0, System.getenv("NEXUS_PROXY").lastIndexOf(":"));
-                    String proxyPort =
-                            System.getenv("NEXUS_PROXY").substring(System.getenv("NEXUS_PROXY").lastIndexOf(":") + 1);
+                    String proxyIp = System.getenv("NEXUS_PROXY").substring(0,
+                            System.getenv("NEXUS_PROXY").lastIndexOf(":"));
+                    String proxyPort = System.getenv("NEXUS_PROXY")
+                            .substring(System.getenv("NEXUS_PROXY").lastIndexOf(":") + 1);
                     proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyIp, Integer.parseInt(proxyPort)));
                     return (HttpURLConnection) url.openConnection(proxy);
                 } catch (Exception ex) {
@@ -92,42 +98,289 @@ public final class NexusExecutorClient {
                 }
             }
         }), clientConfig);
-        // Create all-trusting host name verifier
-        hostnameVerifier = new HostnameVerifier() {
-            @Override
-            public boolean verify(String hostname, SSLSession session) {
-                return true;
+    }
+
+    public String getBaseUrl() {
+        return this.baseurl;
+    }
+
+    public List<String> getResource(String endpoint)
+            throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
+            IOException, KeyManagementException, NoSuchAlgorithmException, ParseException {
+        List<String> resources = new ArrayList<String>();
+        String nexusUrl = this.baseurl;
+        if (endpoint != null) {
+            nexusUrl = this.baseurl + "/" + endpoint;
+        }
+        LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get nexus resource: " + nexusUrl);
+        WebResource webResource = this.client.resource(nexusUrl + "/");
+        LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
+        ClientResponse response = webResource.get(ClientResponse.class);
+        if (response.getStatus() != 200) {
+            throw new HttpException("Could not retrieve nexus resource " + nexusUrl + ". HTTP error code : "
+                    + response.getStatus() + " and message: " + response.getEntity(String.class));
+        }
+        Document document = Jsoup.parse(response.getEntity(String.class));
+        List<Element> elements = document.getElementsByTag("body").get(0).getElementsByTag("table").get(0)
+                .getElementsByTag("tbody").get(0).getElementsByTag("tr");
+        for (int i = 2; i < elements.size(); i++) {
+            String resource = elements.get(i).getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
+            resource = resource.substring(0, resource.length() - 1);
+            resources.add(resource);
+        }
+        return resources;
+    }
+
+    public List<String> getResource(@Nonnull String endpoint1, @Nonnull String endpoint2)
+            throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
+            IOException, KeyManagementException, NoSuchAlgorithmException, ParseException {
+        String endpoint = endpoint1 + "/" + endpoint2;
+        return this.getResource(endpoint);
+    }
+
+    public List<String> getResource(@Nonnull String endpoint1, @Nonnull String endpoint2, @Nonnull String endpoint3)
+            throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
+            IOException, KeyManagementException, NoSuchAlgorithmException, ParseException {
+        String endpoint = endpoint1 + "/" + endpoint2 + "/" + endpoint3;
+        return this.getResource(endpoint);
+    }
+
+    public ValidationNexusTestResult getResult(@Nonnull String name, @Nonnull String version, @Nonnull String siloText,
+            @Nonnull String timestamp)
+                    throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
+                    IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException {
+        String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version;
+        LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get validation nexus test result");
+        WebResource webResource = this.client.resource(nexusUrl + "/");
+        LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
+        ClientResponse response = webResource.get(ClientResponse.class);
+        if (response.getStatus() != 200) {
+            throw new HttpException("Could not retrieve validation nexus test result. HTTP error code : "
+                    + response.getStatus() + " and message: " + response.getEntity(String.class));
+        }
+        Document document = Jsoup.parse(response.getEntity(String.class));
+        List<Element> elements = document.getElementsByTag("body").get(0).getElementsByTag("table").get(0)
+                .getElementsByTag("tbody").get(0).getElementsByTag("tr");
+        Element element = findElementByTimestamp(elements.subList(2, elements.size()), timestamp);
+        if (element == null) {
+            return null;
+        }
+        ValidationNexusTestResult vNexusResult = new ValidationNexusTestResult();
+        vNexusResult.setBlueprintName(name);
+        vNexusResult.setSilo(siloText);
+        vNexusResult.setVersion(version);
+        vNexusResult.setTimestamp(timestamp);
+        String lastModified = element.getElementsByTag("td").get(1).text();
+        vNexusResult.setDateOfStorage(lastModified);
+        TestInfoYaml testInfo = getTestInfo(webResource.getURI().toString() + timestamp);
+        if (testInfo != null) {
+            if (testInfo.gettest_info().getLayer().equals("all")) {
+                vNexusResult.setAllLayers(true);
+            } else {
+                vNexusResult.setAllLayers(false);
             }
-        };
-        // Create a trust manager that does not validate certificate chains
-        trustAll = new TrustManager[] {new X509TrustManager() {
-            @Override
-            public X509Certificate[] getAcceptedIssuers() {
-                return null; // Not relevant.
+            vNexusResult.setOptional(testInfo.gettest_info().getOptional());
+        }
+        List<WRobotNexusTestResult> wTestResults = getWRobotTestResults(name, version, siloText, timestamp);
+        vNexusResult.setwRobotNexusTestResults(wTestResults);
+        vNexusResult.setResult(determineResult(wTestResults));
+        return vNexusResult;
+    }
+
+    public List<ValidationNexusTestResult> getResults(@Nonnull String name, @Nonnull String version,
+            @Nonnull String siloText, int noOfLastElements)
+                    throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
+                    IOException, KeyManagementException, NoSuchAlgorithmException, ParseException {
+        String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version;
+        LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get validation Nexus test results");
+        WebResource webResource = this.client.resource(nexusUrl + "/");
+        LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
+        ClientResponse response = webResource.get(ClientResponse.class);
+        if (response.getStatus() != 200) {
+            throw new HttpException("Could not retrieve validation Nexus test results. HTTP error code : "
+                    + response.getStatus() + " and message: " + response.getEntity(String.class));
+        }
+        List<ValidationNexusTestResult> vNexusResults = new ArrayList<ValidationNexusTestResult>();
+        Document document = Jsoup.parse(response.getEntity(String.class));
+        List<Element> elements = document.getElementsByTag("body").get(0).getElementsByTag("table").get(0)
+                .getElementsByTag("tbody").get(0).getElementsByTag("tr");
+        elements = findLastElementsByDate(elements.subList(2, elements.size()), noOfLastElements);
+        for (int i = 0; i < elements.size(); i++) {
+            try {
+                String timestamp = elements.get(i).getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
+                timestamp = timestamp.substring(0, timestamp.length() - 1);
+                ValidationNexusTestResult vNexusResult = this.getResult(name, version, siloText, timestamp);
+                vNexusResults.add(vNexusResult);
+            } catch (HttpException ex) {
+                LOGGER.warn(EELFLoggerDelegate.auditLogger, "Exception occured while retrieving timestamp results");
+                continue;
             }
+        }
+        return vNexusResults;
+    }
 
-            @Override
-            public void checkClientTrusted(X509Certificate[] certs, String authType) {
-                // Do nothing. Just allow them all.
+    public List<ValidationNexusTestResult> getResults(@Nonnull String name, @Nonnull String version,
+            @Nonnull String siloText, @Nonnull Date date)
+                    throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
+                    IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException {
+        String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version;
+        LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get validation Nexus results based on date");
+        WebResource webResource = this.client.resource(nexusUrl + "/");
+        LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
+        ClientResponse response = webResource.get(ClientResponse.class);
+        if (response.getStatus() != 200) {
+            throw new HttpException("Could not retrieve validation Nexus results based on date. HTTP error code : "
+                    + response.getStatus() + " and message: " + response.getEntity(String.class));
+        }
+        List<ValidationNexusTestResult> vNexusResults = new ArrayList<ValidationNexusTestResult>();
+        Document document = Jsoup.parse(response.getEntity(String.class));
+        List<Element> elements = document.getElementsByTag("body").get(0).getElementsByTag("table").get(0)
+                .getElementsByTag("tbody").get(0).getElementsByTag("tr");
+        elements = findElementsBasedOnDate(elements.subList(2, elements.size()), date);
+        for (int i = 0; i < elements.size(); i++) {
+            try {
+                String timestamp = elements.get(i).getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
+                timestamp = timestamp.substring(0, timestamp.length() - 1);
+                ValidationNexusTestResult vNexusResult = this.getResult(name, version, siloText, timestamp);
+                vNexusResults.add(vNexusResult);
+            } catch (HttpException ex) {
+                LOGGER.warn(EELFLoggerDelegate.auditLogger, "Exception occured while retrieving timestamp results");
+                continue;
             }
+        }
+        return vNexusResults;
+    }
 
+    public ValidationNexusTestResult getLastResultBasedOnOutcome(@Nonnull String name, @Nonnull String version,
+            @Nonnull String siloText, List<BlueprintLayer> layers, Boolean optional, boolean outcome)
+                    throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
+                    IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException {
+        String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version;
+        LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get last result based on outcome");
+        WebResource webResource = this.client.resource(nexusUrl + "/");
+        LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
+        ClientResponse response = webResource.get(ClientResponse.class);
+        if (response.getStatus() != 200) {
+            throw new HttpException("Could not retrieve last result based on outcome from Nexus. HTTP error code : "
+                    + response.getStatus() + " and message: " + response.getEntity(String.class));
+        }
+        Document document = Jsoup.parse(response.getEntity(String.class));
+        List<Element> elements = document.getElementsByTag("body").get(0).getElementsByTag("table").get(0)
+                .getElementsByTag("tbody").get(0).getElementsByTag("tr");
+        elements = elements.subList(2, elements.size());
+        if (elements.size() < 1) {
+            return null;
+        }
+        DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
+        Collections.sort(elements, new Comparator<Element>() {
             @Override
-            public void checkServerTrusted(X509Certificate[] certs, String authType) {
-                // Do nothing. Just allow them all.
+            public int compare(Element element1, Element element2) {
+                try {
+                    return dateFormat.parse(element2.getElementsByTag("td").get(1).text())
+                            .compareTo(dateFormat.parse(element1.getElementsByTag("td").get(1).text()));
+                } catch (ParseException e) {
+                    LOGGER.error(EELFLoggerDelegate.errorLogger,
+                            "Error when parsing date. " + UserUtils.getStackTrace(e));
+                    return 0;
+                }
+            }
+        });
+        for (Element element : elements) {
+            try {
+                String elementTimestamp = element.getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
+                elementTimestamp = elementTimestamp.substring(0, elementTimestamp.length() - 1);
+                ValidationNexusTestResult vNexusResult = this.getResult(name, version, siloText, elementTimestamp);
+                if (vNexusResult.getResult() != outcome) {
+                    continue;
+                }
+                if (optional != null && vNexusResult.getOptional() != optional) {
+                    continue;
+                }
+                if (layers != null) {
+                    List<BlueprintLayer> storedLayers = new ArrayList<BlueprintLayer>();
+                    for (WRobotNexusTestResult wRobot : vNexusResult.getwRobotNexusTestResults()) {
+                        storedLayers.add(wRobot.getBlueprintLayer());
+                    }
+                    if (!new HashSet<>(storedLayers).equals(new HashSet<>(layers))) {
+                        continue;
+                    }
+                }
+                return vNexusResult;
+            } catch (HttpException ex) {
+                LOGGER.warn(EELFLoggerDelegate.auditLogger,
+                        "Error when trying to retrieve results. " + UserUtils.getStackTrace(ex));
+                continue;
             }
-        }};
+        }
+        return null;
     }
 
-    public String getBaseUrl() {
-        return this.baseurl;
+    public ValidationNexusTestResult getLastResultBasedOnOutcome(@Nonnull String name, @Nonnull String version,
+            @Nonnull String siloText, Boolean allLayers, Boolean optional, boolean outcome)
+                    throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
+                    IOException, KeyManagementException, NoSuchAlgorithmException, ParseException, NullPointerException {
+        String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version;
+        LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get last result based on outcome");
+        WebResource webResource = this.client.resource(nexusUrl + "/");
+        LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
+        ClientResponse response = webResource.get(ClientResponse.class);
+        if (response.getStatus() != 200) {
+            throw new HttpException("Could not retrieve last result based on outcome from Nexus. HTTP error code : "
+                    + response.getStatus() + " and message: " + response.getEntity(String.class));
+        }
+        Document document = Jsoup.parse(response.getEntity(String.class));
+        List<Element> elements = document.getElementsByTag("body").get(0).getElementsByTag("table").get(0)
+                .getElementsByTag("tbody").get(0).getElementsByTag("tr");
+        elements = elements.subList(2, elements.size());
+        if (elements.size() < 1) {
+            return null;
+        }
+        DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
+        Collections.sort(elements, new Comparator<Element>() {
+            @Override
+            public int compare(Element element1, Element element2) {
+                try {
+                    return dateFormat.parse(element2.getElementsByTag("td").get(1).text())
+                            .compareTo(dateFormat.parse(element1.getElementsByTag("td").get(1).text()));
+                } catch (ParseException e) {
+                    LOGGER.error(EELFLoggerDelegate.errorLogger,
+                            "Error when parsing date. " + UserUtils.getStackTrace(e));
+                    return 0;
+                }
+            }
+        });
+        for (Element element : elements) {
+            try {
+                String elementTimestamp = element.getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
+                elementTimestamp = elementTimestamp.substring(0, elementTimestamp.length() - 1);
+                ValidationNexusTestResult vNexusResult = this.getResult(name, version, siloText, elementTimestamp);
+                if (vNexusResult.getResult() != outcome) {
+                    continue;
+                }
+                if (optional != null && vNexusResult.getOptional() != optional) {
+                    continue;
+                }
+                if (allLayers != null && vNexusResult.getAllLayers() != allLayers) {
+                    continue;
+                }
+                return vNexusResult;
+            } catch (HttpException ex) {
+                LOGGER.warn(EELFLoggerDelegate.auditLogger,
+                        "Error when trying to retrieve results. " + UserUtils.getStackTrace(ex));
+                continue;
+            }
+        }
+        return null;
     }
 
-    public List<WrapperRobotTestResult> getRobotTestResults() throws ClientHandlerException, UniformInterfaceException,
-            JsonParseException, JsonMappingException, IOException, KeyManagementException, NoSuchAlgorithmException {
-        List<WrapperRobotTestResult> listOfwrappers = new ArrayList<WrapperRobotTestResult>();
+    public List<WRobotNexusTestResult> getWRobotTestResults(@Nonnull String name, @Nonnull String version,
+            @Nonnull String siloText, @Nonnull String timestamp)
+                    throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
+                    IOException, KeyManagementException, NoSuchAlgorithmException {
+        String nexusUrl = this.baseurl + "/" + siloText + "/" + name + "/" + version + "/" + timestamp + "/results";
+        List<WRobotNexusTestResult> listOfwrappers = new ArrayList<WRobotNexusTestResult>();
         LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get the blueprint layers");
-        setProperties();
-        WebResource webResource = this.client.resource(this.baseurl + "/");
+        WebResource webResource = this.client.resource(nexusUrl + "/");
         LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
         ClientResponse response = webResource.get(ClientResponse.class);
         if (response.getStatus() != 200) {
@@ -135,31 +388,38 @@ public final class NexusExecutorClient {
                     + response.getStatus() + " and message: " + response.getEntity(String.class));
         }
         Document document = Jsoup.parse(response.getEntity(String.class));
-        List<Element> elements =
-                document.getElementsByTag("body").get(0).getElementsByTag("table").get(0).getElementsByTag("tr");
+        List<Element> elements = document.getElementsByTag("body").get(0).getElementsByTag("table").get(0)
+                .getElementsByTag("tr");
         for (int i = 2; i < elements.size(); i++) {
-            String layer = elements.get(i).getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
-            layer = layer.substring(0, layer.length() - 1);
-            List<RobotTestResult> robotTestResults = getResultsOfALayer(this.baseurl + "/" + layer);
-            WrapperRobotTestResult wrapper = new WrapperRobotTestResult();
-            wrapper.setBlueprintLayer(BlueprintLayer.valueOf(layer.substring(0, 1).toUpperCase() + layer.substring(1)));
-            wrapper.setRobotTestResults(robotTestResults);
-            listOfwrappers.add(wrapper);
+            try {
+                String layer = elements.get(i).getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
+                layer = layer.substring(0, layer.length() - 1);
+                if (layer.contains("test")) {
+                    continue;
+                }
+                List<RobotTestResult> robotTestResults = getRobotTestResults(nexusUrl + "/" + layer);
+                WRobotNexusTestResult wrapper = new WRobotNexusTestResult();
+                wrapper.setBlueprintLayer(BlueprintLayer.valueOf(layer));
+                wrapper.setRobotTestResults(robotTestResults);
+                listOfwrappers.add(wrapper);
+            } catch (HttpException | IllegalArgumentException ex) {
+                LOGGER.warn(EELFLoggerDelegate.auditLogger, "Exception occured while retrieving robot results");
+                continue;
+            }
         }
         return listOfwrappers;
     }
 
-    private List<RobotTestResult> getResultsOfALayer(String resultsUrl)
+    private List<RobotTestResult> getRobotTestResults(String resultsUrl)
             throws ClientHandlerException, UniformInterfaceException, JsonParseException, JsonMappingException,
             IOException, KeyManagementException, NoSuchAlgorithmException {
-        List<RobotTestResult> robotTestResults = new ArrayList<RobotTestResult>();
-        LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get Robot Test Results");
-        setProperties();
+        List<RobotTestResult> rTestResults = new ArrayList<RobotTestResult>();
+        LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get test suites results");
         WebResource webResource = this.client.resource(resultsUrl + "/");
         LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
         ClientResponse response = webResource.get(ClientResponse.class);
         if (response.getStatus() != 200) {
-            throw new HttpException("Could not retrieve robot test results from Nexus. HTTP error code : "
+            throw new HttpException("Could not retrieve test suites results from Nexus. HTTP error code : "
                     + response.getStatus() + " and message: " + response.getEntity(String.class));
         }
         Document document = Jsoup.parse(response.getEntity(String.class));
@@ -172,7 +432,7 @@ public final class NexusExecutorClient {
             LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
             response = webResource.get(ClientResponse.class);
             if (response.getStatus() != 200) {
-                throw new HttpException("Could not retrieve robot test result from Nexus. HTTP error code : "
+                throw new HttpException("Could not retrieve test suite result from Nexus. HTTP error code : "
                         + response.getStatus() + " and message: " + response.getEntity(String.class));
             }
             String result = response.getEntity(String.class);
@@ -183,21 +443,86 @@ public final class NexusExecutorClient {
             mapper.setSerializationInclusion(Include.NON_NULL);
             RobotTestResult robotTestResult = mapper.readValue(xmlJSONObj.toString(), RobotTestResult.class);
             robotTestResult.setName(testSuiteName);
-            robotTestResults.add(robotTestResult);
+            rTestResults.add(robotTestResult);
+        }
+        return rTestResults;
+    }
+
+    private boolean determineResult(List<WRobotNexusTestResult> wTestResults) {
+        boolean result = true;
+        for (WRobotNexusTestResult wTestResult : wTestResults) {
+            for (RobotTestResult robotTestResult : wTestResult.getRobotTestResults()) {
+                for (Status status : robotTestResult.getRobot().getStatistics().getTotal().getStat()) {
+                    if (status.getContent().trim().equals("All Tests") && status.getFail() > 0) {
+                        result = false;
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
+    private List<Element> findLastElementsByDate(List<Element> elements, int noOfLastElements) {
+        if (elements.size() <= noOfLastElements) {
+            return elements;
         }
-        return robotTestResults;
+        DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
+        Collections.sort(elements, new Comparator<Element>() {
+            @Override
+            public int compare(Element element1, Element element2) {
+                try {
+                    return dateFormat.parse(element2.getElementsByTag("td").get(1).text())
+                            .compareTo(dateFormat.parse(element1.getElementsByTag("td").get(1).text()));
+                } catch (ParseException e) {
+                    LOGGER.error(EELFLoggerDelegate.errorLogger,
+                            "Error when parsing date. " + UserUtils.getStackTrace(e));
+                    return 0;
+                }
+            }
+        });
+        return elements.subList(0, noOfLastElements);
     }
 
-    private void setProperties() throws NoSuchAlgorithmException, KeyManagementException {
-        SSLContext sslContext = SSLContext.getInstance("SSL");
-        sslContext.init(null, this.trustAll, new java.security.SecureRandom());
-        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
-        // Install the all-trusting host verifier
-        HttpsURLConnection.setDefaultHostnameVerifier(this.hostnameVerifier);
-        DefaultClientConfig config = new DefaultClientConfig();
-        Map<String, Object> properties = config.getProperties();
-        HTTPSProperties httpsProperties = new HTTPSProperties((str, sslSession) -> true, sslContext);
-        properties.put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, httpsProperties);
+    private Element findElementByTimestamp(List<Element> elements, String timestamp) {
+        for (Element element : elements) {
+            String elementTimestamp = element.getElementsByTag("td").get(0).getElementsByTag("a").get(0).text();
+            elementTimestamp = elementTimestamp.substring(0, elementTimestamp.length() - 1);
+            if (elementTimestamp.equals(timestamp)) {
+                return element;
+            }
+        }
+        return null;
     }
 
+    private List<Element> findElementsBasedOnDate(List<Element> elements, Date date) throws ParseException {
+        DateFormat formatTime = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
+        DateFormat formatNoTime = new SimpleDateFormat("EEE MMM dd zzz yyyy", Locale.US);
+        List<Element> desiredElements = new ArrayList<Element>();
+        for (Element element : elements) {
+            String lastModified = element.getElementsByTag("td").get(1).text();
+            if (formatNoTime.format(formatTime.parse(lastModified)).compareTo(formatNoTime.format(date)) == 0) {
+                desiredElements.add(element);
+            }
+        }
+        return desiredElements;
+    }
+
+    private TestInfoYaml getTestInfo(String timestampUrl) throws JsonParseException, JsonMappingException, IOException {
+        LOGGER.info(EELFLoggerDelegate.applicationLogger, "Trying to get test info");
+        WebResource webResource = this.client.resource(timestampUrl + "/results/test_info.yaml");
+        LOGGER.debug(EELFLoggerDelegate.debugLogger, "Request URI of get: " + webResource.getURI().toString());
+        ClientResponse response = webResource.get(ClientResponse.class);
+        if (response.getStatus() != 200) {
+            return null;
+        }
+        String testInfo = response.getEntity(String.class);
+        ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
+        Object obj = yamlReader.readValue(testInfo, Object.class);
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+        mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
+        mapper.setSerializationInclusion(Include.NON_NULL);
+        ObjectMapper jsonWriter = new ObjectMapper();
+        return mapper.readValue(jsonWriter.writeValueAsString(obj), TestInfoYaml.class);
+    }
 }