Index: modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/StatsServiceImpl.java
===================================================================
--- modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/StatsServiceImpl.java	(revision 54744)
+++ modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/StatsServiceImpl.java	(revision 54745)
@@ -1,12 +1,15 @@
 package eu.dnetlib.repo.manager.service;
 
+import eu.dnetlib.repo.manager.controllers.RestTemplateResponseErrorHandler;
 import eu.dnetlib.repo.manager.exception.EndPointException;
 import org.apache.log4j.Logger;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
@@ -17,6 +20,7 @@
 
 import javax.annotation.PostConstruct;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @Service("statsService")
@@ -37,13 +41,15 @@
     @Value("${search.api.usageEvents}")
     private String usagestatsEvents;
 
+    @Autowired
+    RestTemplateResponseErrorHandler restTemplateResponseErrorHandler;
+
     @PostConstruct
     private void init() {
         LOGGER.debug("Initialization method of statistics api!");
-
         restTemplate = new RestTemplate();
+        restTemplate.setErrorHandler(restTemplateResponseErrorHandler);
         restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
-
         httpHeaders = new HttpHeaders();
         httpHeaders.set("Content-Type", "application/json");
     }
@@ -52,86 +58,35 @@
     @Override
     public Map<String, Object> getStatistics() throws JSONException {
 
-        String aggregators = null;
-        try {
-            aggregators = getTotalByType("datasource",baseAddress+"/resources",
+        String aggregators =  getTotalByType("datasource",baseAddress+"/resources",
                     "?query= " +
                     " oaftype exact datasource and " +
                     " ( datasourcetypename exact Institutional Repository Aggregator " +
                     "     or datasourcetypename exact Publication Repository Aggregator )");
-        } catch (EndPointException e) {
-            LOGGER.debug(e);
-            aggregators = "N/A";
-        }
 
-        String dataRepositories = null;
-        try {
-            dataRepositories = getTotalByType("datasource",baseAddress+"/resources",
+        String dataRepositories =  getTotalByType("datasource",baseAddress+"/resources",
                     "?query= " +
                     " oaftype exact datasource and " +
                     " datasourcetypename exact Data Repository " );
-        } catch (EndPointException e) {
-            LOGGER.debug(e);
-            dataRepositories = "N/A";
-        }
 
-        String literature = null;
-        try {
-            literature = getTotalByType("datasource",baseAddress+"/resources",
+        String literature = getTotalByType("datasource",baseAddress+"/resources",
                     "?query= " +
                     " oaftype exact datasource and " +
                     " ( datasourcetypename exact Institutional Repository  " +
                     "     or datasourcetypename exact Publication Repository )");
-        } catch (EndPointException e) {
-            LOGGER.debug(e);
-            literature = "N/A";
-        }
 
-        String journal = null;
-        try {
-            journal = getTotalByType("datasource",baseAddress+"/resources",
+        String journal =  getTotalByType("datasource",baseAddress+"/resources",
                     "?query= " +
                     " oaftype exact datasource and " +
                     " datasourcetypename exact Journal");
-        } catch (EndPointException e) {
-            LOGGER.debug(e);
-            journal = "N/A";
-        }
 
-        String publications = null;
-        try {
-            publications = getTotalByType("other",baseAddress,"/publications/count");
-        } catch (EndPointException e) {
-            LOGGER.debug(e);
-            publications = "N/A";
-        }
+        String publications = getTotalByType("other",baseAddress,"/publications/count");
+        String datasets =  getTotalByType("other",baseAddress,"/datasets/count");
+        String software = getTotalByType("other",baseAddress,"/software/count");
 
-        String datasets = null;
-        try {
-            datasets = getTotalByType("other",baseAddress,"/datasets/count");
-        } catch (EndPointException e) {
-            LOGGER.debug(e);
-            datasets = "N/A";
-        }
 
-        String software = null;
-        try {
-            software = getTotalByType("other",baseAddress,"/software/count");
-        } catch (EndPointException e) {
-            LOGGER.debug(e);
-            software = "N/A";
-        }
-
-        JSONObject lastYearUsagestats = null;
-        try {
-            lastYearUsagestats = getLastYearUsageStatsTotal();
-        } catch (EndPointException e) {
-            LOGGER.debug(e);
-            lastYearUsagestats = null;
-        }
-
-        Integer usagestats = getUsageStatsTotal();
-        HashMap<String,Object> stats = new HashMap<>();
+        Map lastYearUsagestats =  getLastYearUsageStatsTotal();
+        Map<String,Object> stats = new HashMap<>();
         stats.put("aggregators",aggregators);
         stats.put("dataRepositories",dataRepositories);
         stats.put("literature",literature);
@@ -140,12 +95,14 @@
         stats.put("datasets",datasets);
         stats.put("software",software);
         stats.put("lastYearUsagestats", lastYearUsagestats != null ? lastYearUsagestats.toString() : null);
-        stats.put("usagestats",usagestats.toString());
+
+        Integer usagestats = getUsageStatsTotal();
+        stats.put("usagestats",usagestats);
         return stats;
     }
 
 
-    private String getTotalByType(String type,String url,String query) throws JSONException, EndPointException {
+    private String getTotalByType(String type,String url,String query) {
         UriComponents uriComponents = UriComponentsBuilder
                 .fromHttpUrl(url + query)
                 .queryParam("page",0)
@@ -153,44 +110,42 @@
                 .queryParam("format","json")
                 .build().encode();
 
-        ResponseEntity rs = restTemplate.getForObject(uriComponents.toUri(), ResponseEntity.class);
+        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
 
-        if(rs.getStatusCode().equals(HttpStatus.OK)){
+       // if(rs.getStatusCode().equals(HttpStatus.OK)){
             if(type.equalsIgnoreCase("datasource")){
-                JSONObject metadata = (JSONObject) new JSONObject(rs.getBody()).get("meta");
+               Map metadata = (Map) ((Map)rs.getBody()).get("meta");
                 return String.valueOf(metadata.get("total"));
-            }else
-                return String.valueOf(new JSONObject(rs.getBody()).get("total"));
-        }else
-            throw new EndPointException(uriComponents.toUri().toString());
+            }else {
+                Map metadata = (Map) (rs.getBody());
+                return String.valueOf(metadata.get("total"));
+            }
+        //}
+       // return null;
     }
 
-    private JSONObject getLastYearUsageStatsTotal() throws JSONException, EndPointException {
+    private Map getLastYearUsageStatsTotal()  {
 
         UriComponents uriComponents = UriComponentsBuilder
                 .fromHttpUrl(usagestatsBaseAddress + "/totals")
                 .build().encode();
 
-        ResponseEntity rs = restTemplate.getForObject(uriComponents.toUri(), ResponseEntity.class);
+        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
 
-        if(rs.getStatusCode().equals(HttpStatus.OK)){
-            JSONArray resultSet = (JSONArray) new JSONObject(rs.getBody()).getJSONArray("yearly_stats");
-            JSONObject lastYear = resultSet.getJSONObject(resultSet.length()-1);
+       // if(rs.getStatusCode().equals(HttpStatus.OK)){
 
-            Integer downloads = lastYear.getInt("downloads");
-            Integer views = lastYear.getInt("views");
-            String year = lastYear.getString("year");
+            List yearly_stats = (List) ((Map)rs.getBody()).get("yearly_stats");
+            Map lastYear = (Map) yearly_stats.get(yearly_stats.size()-1);
+            Integer downloads = (Integer) lastYear.get("downloads");
+            Integer views = (Integer) lastYear.get("views");
+            Integer year = (Integer) lastYear.get("year");
 
-            JSONObject usagestats = new JSONObject();
+            Map<String,Object> usagestats = new HashMap<>();
             usagestats.put("number",String.valueOf(downloads+views));
             usagestats.put("year",year);
 
             return usagestats;
-        }else
-            throw new EndPointException(uriComponents.toUri().toString());
-
-
-
+        //}
     }
 
     private Integer getUsageStatsTotal() throws JSONException {
@@ -198,6 +153,7 @@
                 .fromHttpUrl(usagestatsEvents)
                 .build().encode();
 
+//        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
         String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
         JSONObject resultSet = new JSONObject(rs);
         JSONObject totals = resultSet.getJSONObject("totals");
Index: modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java
===================================================================
--- modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java	(revision 54744)
+++ modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java	(revision 54745)
@@ -281,6 +281,9 @@
         try {
             String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
             JSONObject repository = new JSONObject(rs);
+
+            if(repository.getJSONArray("datasourceInfo").length() == 0)
+                return aggregationHistory;
             aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
             return aggregationHistory.size() == 0? aggregationHistory : aggregationHistory.stream()
                                                     .sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
@@ -306,6 +309,10 @@
         try {
             String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
             JSONObject repository = new JSONObject(rs);
+
+            if(repository.getJSONArray("datasourceInfo").length() == 0)
+                return aggregationByYear;
+
             aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
             return aggregationHistory.size() == 0? aggregationByYear:createYearMap(aggregationHistory);
 
Index: modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/controllers/RestTemplateResponseErrorHandler.java
===================================================================
--- modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/controllers/RestTemplateResponseErrorHandler.java	(nonexistent)
+++ modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/controllers/RestTemplateResponseErrorHandler.java	(revision 54745)
@@ -0,0 +1,34 @@
+package eu.dnetlib.repo.manager.controllers;
+
+import eu.dnetlib.repo.manager.exception.EndPointException;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.ResponseErrorHandler;
+
+import java.io.IOException;
+
+import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR;
+import static org.springframework.http.HttpStatus.Series.SERVER_ERROR;
+
+@Component
+public class RestTemplateResponseErrorHandler implements ResponseErrorHandler {
+
+    @Override
+    public boolean hasError(ClientHttpResponse httpResponse) throws IOException {
+        return (httpResponse.getStatusCode().series() == CLIENT_ERROR
+                || httpResponse.getStatusCode().series() == SERVER_ERROR);
+    }
+
+    @Override
+    public void handleError(ClientHttpResponse httpResponse) throws IOException {
+
+        if (httpResponse.getStatusCode().series() == HttpStatus.Series.SERVER_ERROR) {
+            throw new EndPointException();
+        } else if (httpResponse.getStatusCode().series() == HttpStatus.Series.CLIENT_ERROR) {
+            if (httpResponse.getStatusCode() == HttpStatus.NOT_FOUND) {
+                throw new IOException();
+            }
+        }
+    }
+}
Index: modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/controllers/MonitorController.java
===================================================================
--- modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/controllers/MonitorController.java	(revision 54744)
+++ modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/controllers/MonitorController.java	(revision 54745)
@@ -52,8 +52,8 @@
 
     @RequestMapping(value = "/getJobSummary" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
     @ResponseBody
-    public StoredJob getJobSummary(@RequestBody String jobId,
-                                   @RequestBody String groupBy) throws JSONException {
+    public StoredJob getJobSummary(@RequestParam String jobId,
+                                   @RequestParam String groupBy) throws JSONException {
         return monitorService.getJobSummary(jobId, groupBy);
     }
 
Index: modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/exception/EndPointException.java
===================================================================
--- modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/exception/EndPointException.java	(revision 54744)
+++ modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/exception/EndPointException.java	(revision 54745)
@@ -3,9 +3,11 @@
 import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.ResponseStatus;
 
-@ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
-public class EndPointException extends Exception{
+import java.io.IOException;
 
+//@ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
+public class EndPointException extends IOException {
+
     public EndPointException() {
             super("Endpoint not responding!");
         }
Index: modules/uoa-repository-manager-service/branches/dev-api/src/main/resources/application.properties
===================================================================
--- modules/uoa-repository-manager-service/branches/dev-api/src/main/resources/application.properties	(revision 54744)
+++ modules/uoa-repository-manager-service/branches/dev-api/src/main/resources/application.properties	(revision 54745)
@@ -80,5 +80,5 @@
 
 ##SEARCH API
 search.api.baseAddress=https://beta.services.openaire.eu/search/v2/api
-search.api.usagestats=https://services.openaire.eu/usagestats
-search.api.usageEvents=http://beta.lbs.openaire.eu:8080/ajax/summary
\ No newline at end of file
+search.api.usagestats=https://services.openaire.eu/usagestatsl
+search.api.usageEvents=http://beta.lbs.openaire.eu:8080/ajax/summary
