- Code optimization and polishing.
- Improve error-checking and exception-handling.
This commit is contained in:
parent
f136488b0e
commit
eaa4083b04
|
@ -5,6 +5,5 @@
|
|||
## Install and run:
|
||||
- Run **git clone** and then **cd uoa-repository-manager-service**.
|
||||
- Provide all not-set or redacted configurations, inside the **src/main/resources/application.properties** file.
|
||||
- Execute the **installAndRun.sh** script which installs and runs the app.
|
||||
- If you want to just run the app, then run the script with the argument "1": **./installAndRun.sh 1**
|
||||
- If you want to just install the app, then run the script with the argument "2": **./installAndRun.sh 2**
|
||||
- Build the app with: `mvn clean install -s <settings-file>`
|
||||
- Run the app with: `java -jar ./target/uoa-repository-manager-service.jar`
|
||||
|
|
|
@ -94,5 +94,4 @@ public class DashboardController {
|
|||
return new BrokerSummary(brokerService.getSimpleSubscriptionsOfUser(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail()), brokerService.getTopicsForDatasource(datasourceName));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ public class PiWikController {
|
|||
results.setResults(returning);
|
||||
return results;
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "from", dataType = "number", paramType = "query"),
|
||||
@ApiImplicitParam(name = "quantity", dataType = "number", paramType = "query"),
|
||||
|
@ -102,20 +103,17 @@ public class PiWikController {
|
|||
sb.append(" Repository ID , Repository name, Country, Site ID, Authentication token, Creation date, Requestor full name, Requestor email, Validated, Validation date, Comment \n");
|
||||
|
||||
for(PiwikInfo piwikInfo : returning){
|
||||
sb.append(
|
||||
(piwikInfo.getRepositoryId() == null ? "," : piwikInfo.getRepositoryId()+ ",")+
|
||||
(piwikInfo.getRepositoryName() == null ? "," : piwikInfo.getRepositoryName()+ ",")+
|
||||
(piwikInfo.getCountry() == null ? "," : piwikInfo.getCountry()+ ",")+
|
||||
(piwikInfo.getSiteId() == null ? "," : piwikInfo.getSiteId()+ ",") +
|
||||
(piwikInfo.getAuthenticationToken() == null ? "," : piwikInfo.getAuthenticationToken()+ ",")+
|
||||
(piwikInfo.getCreationDate() == null ? "," : piwikInfo.getCreationDate().toString()+ ",") +
|
||||
(piwikInfo.getRequestorName() == null ? "," : piwikInfo.getRequestorName()+ ",") +
|
||||
(piwikInfo.getRequestorEmail() == null ? "," : piwikInfo.getRequestorEmail()+ ",")+
|
||||
piwikInfo.isValidated() + "," +
|
||||
(piwikInfo.getValidationDate() == null ? "," : piwikInfo.getValidationDate().toString()+ ",") +
|
||||
(piwikInfo.getComment() == null ? "\n" : piwikInfo.getComment()+ "\n")
|
||||
|
||||
);
|
||||
sb.append(piwikInfo.getRepositoryId() == null ? "," : piwikInfo.getRepositoryId() + ",")
|
||||
.append(piwikInfo.getRepositoryName() == null ? "," : piwikInfo.getRepositoryName() + ",")
|
||||
.append(piwikInfo.getCountry() == null ? "," : piwikInfo.getCountry() + ",")
|
||||
.append(piwikInfo.getSiteId() == null ? "," : piwikInfo.getSiteId() + ",")
|
||||
.append(piwikInfo.getAuthenticationToken() == null ? "," : piwikInfo.getAuthenticationToken() + ",")
|
||||
.append(piwikInfo.getCreationDate() == null ? "," : piwikInfo.getCreationDate().toString() + ",")
|
||||
.append(piwikInfo.getRequestorName() == null ? "," : piwikInfo.getRequestorName() + ",")
|
||||
.append(piwikInfo.getRequestorEmail() == null ? "," : piwikInfo.getRequestorEmail() + ",")
|
||||
.append(piwikInfo.isValidated()).append(",")
|
||||
.append(piwikInfo.getValidationDate() == null ? "," : piwikInfo.getValidationDate().toString() + ",")
|
||||
.append(piwikInfo.getComment() == null ? "\n" : piwikInfo.getComment() + "\n");
|
||||
}
|
||||
writer.write(sb.toString());
|
||||
|
||||
|
@ -140,7 +138,6 @@ public class PiWikController {
|
|||
strDate);
|
||||
response.setHeader(headerKey, headerValue);
|
||||
|
||||
|
||||
return new FileSystemResource(p.toFile());
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package eu.dnetlib.repo.manager.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
|
||||
import eu.dnetlib.repo.manager.domain.AggregationHistoryResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
|
|
@ -26,7 +26,10 @@ import javax.annotation.PostConstruct;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("brokerService")
|
||||
public class BrokerServiceImpl implements BrokerService {
|
||||
|
@ -47,7 +50,7 @@ public class BrokerServiceImpl implements BrokerService {
|
|||
|
||||
private HttpHeaders httpHeaders;
|
||||
|
||||
private HashMap<String, Term> topics = new HashMap<String, Term>();
|
||||
private HashMap<String, Term> topics = new HashMap<>();
|
||||
|
||||
@PostConstruct
|
||||
private void initDnetTopicsMap() {
|
||||
|
@ -120,7 +123,7 @@ public class BrokerServiceImpl implements BrokerService {
|
|||
@Override
|
||||
public EventsPage advancedShowEvents(String page,
|
||||
String size,
|
||||
AdvQueryObject advQueryObject) throws BrokerException, JSONException, IOException {
|
||||
AdvQueryObject advQueryObject) throws BrokerException {
|
||||
|
||||
final String service = "/events/{page}/{pageSize}";
|
||||
|
||||
|
@ -155,7 +158,7 @@ public class BrokerServiceImpl implements BrokerService {
|
|||
for (RepositorySnippet repo : repositories) {
|
||||
BrowseEntry temp = new BrowseEntry();
|
||||
temp.setValue(repo.getOfficialname());
|
||||
temp.setSize(new Long(0));
|
||||
temp.setSize(0L);
|
||||
for (BrowseEntry e : getTopicsForDatasource(repo.getOfficialname())) {
|
||||
temp.setSize(temp.getSize() + e.getSize());
|
||||
}
|
||||
|
@ -164,12 +167,7 @@ public class BrokerServiceImpl implements BrokerService {
|
|||
}
|
||||
|
||||
// sort the collection by the second field of the tuple which is size
|
||||
Collections.sort(entries, new Comparator<Tuple<BrowseEntry, String>>() {
|
||||
@Override
|
||||
public int compare(Tuple<BrowseEntry, String> e1, Tuple<BrowseEntry, String> e2) {
|
||||
return (int) (e2.getFirst().getSize().longValue() - e1.getFirst().getSize().longValue());
|
||||
}
|
||||
});
|
||||
entries.sort((e1, e2) -> (int) (e2.getFirst().getSize() - e1.getFirst().getSize()));
|
||||
long stop = System.currentTimeMillis();
|
||||
System.out.println("getDatasourcesOfUserType returned in " + (stop - start) + "ms ");
|
||||
|
||||
|
|
|
@ -769,6 +769,6 @@ public class EmailUtilsImpl implements EmailUtils {
|
|||
user = ((OIDCAuthenticationToken) authentication).getUserInfo().getName();
|
||||
} catch (NullPointerException ex) {}
|
||||
}
|
||||
return user;
|
||||
return user; // It may be just "user". TODO - Wouldn't be better if it was null?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package eu.dnetlib.repo.manager.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
|
||||
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
@ -12,7 +8,6 @@ import eu.dnetlib.api.functionality.ValidatorServiceException;
|
|||
import eu.dnetlib.domain.enabling.Vocabulary;
|
||||
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
||||
import eu.dnetlib.repo.manager.domain.*;
|
||||
import eu.dnetlib.repo.manager.domain.broker.BrowseEntry;
|
||||
import eu.dnetlib.repo.manager.domain.dto.Role;
|
||||
import eu.dnetlib.repo.manager.domain.dto.User;
|
||||
import eu.dnetlib.repo.manager.exception.BrokerException;
|
||||
|
@ -153,8 +148,6 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
countriesMap.put(c.getName(), c.getCode());
|
||||
inverseCountriesMap.put(c.getCode(), c.getName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -185,11 +178,13 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
|
||||
for (String repoId : ids) {
|
||||
requestFilter.setId(repoId);
|
||||
List<Repository> rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, List.class);
|
||||
List rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, List.class);
|
||||
|
||||
// repos.addAll(converter.toRepositoryList(new JSONObject(rs)));
|
||||
}
|
||||
|
||||
// TODO - "repos" is EMPTY!!
|
||||
|
||||
for (Repository r : repos)
|
||||
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
||||
return repos;
|
||||
|
@ -219,6 +214,10 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
requestFilter.setId(repoId);
|
||||
|
||||
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
||||
if ( rs == null ) {
|
||||
logger.error("The \"DatasourceResponse\" is null!");
|
||||
return null;
|
||||
}
|
||||
|
||||
resultSet.addAll(objectMapper.readValue(objectMapper.writeValueAsString(rs.getDatasourceInfo()),
|
||||
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
||||
|
@ -262,6 +261,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
requestFilter.setEoscDatasourceType(filterKey);
|
||||
|
||||
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
||||
if ( rs == null ) {
|
||||
logger.error("The result is null!");
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
||||
while (jsonArray.length() > 0) {
|
||||
|
||||
|
@ -270,6 +274,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
page += 1;
|
||||
uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
||||
rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
||||
if ( rs == null ) {
|
||||
logger.error("The result is null!");
|
||||
break;
|
||||
}
|
||||
|
||||
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
||||
}
|
||||
return resultSet;
|
||||
|
@ -313,7 +322,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getTotalRegisteredRepositories() {
|
||||
public int getTotalRegisteredRepositories() throws NullPointerException {
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(baseAddress + "/ds/countregistered")
|
||||
.queryParam("fromDate", "1900-01-01")
|
||||
|
@ -377,6 +386,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
requestFilter.setId(id);
|
||||
|
||||
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
||||
if ( rs == null ) {
|
||||
logger.error("The result is null!");
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
||||
|
||||
if (jsonArray.length() == 0)
|
||||
|
@ -399,7 +413,12 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
// JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
||||
|
||||
DatasourceResponse response;
|
||||
response = (DatasourceResponse) restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
||||
response = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
||||
if ( response == null ) {
|
||||
logger.error("The response is null!");
|
||||
return null;
|
||||
}
|
||||
|
||||
List<DatasourceDetails> datasources = response.getDatasourceInfo();
|
||||
if (datasources.size() == 0)
|
||||
throw new ResourceNotFoundException();
|
||||
|
@ -540,7 +559,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
// logger.debug("JSON to add(update) -> " + json_repository);
|
||||
|
||||
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders); // TODO: check if it works (Repository contains extra fields)
|
||||
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
||||
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
||||
|
||||
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
||||
try {
|
||||
|
@ -570,7 +589,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
// logger.debug("JSON to update -> " + json_repository);
|
||||
|
||||
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
||||
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
||||
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
||||
|
||||
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
||||
try {
|
||||
|
@ -602,7 +621,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
.encode();
|
||||
// String json_repository = converter.toJson(repository);
|
||||
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
||||
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
||||
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
||||
|
||||
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
||||
try {
|
||||
|
|
|
@ -83,28 +83,7 @@ public class StatsServiceImpl implements StatsService {
|
|||
" oaftype exact datasource and " +
|
||||
" datasourcetypename exact Data Repository ";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page",0)
|
||||
.queryParam("size",0)
|
||||
.queryParam("format","json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||
if ( metadata == null ) {
|
||||
logger.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
logger.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
logger.error("", e);
|
||||
return null;
|
||||
}
|
||||
return getMetadataTotals(url);
|
||||
}
|
||||
|
||||
|
||||
|
@ -116,28 +95,7 @@ public class StatsServiceImpl implements StatsService {
|
|||
" ( datasourcetypename exact Institutional Repository " +
|
||||
" or datasourcetypename exact Publication Repository )";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||
if ( metadata == null ) {
|
||||
logger.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
logger.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
logger.error("", e);
|
||||
return null;
|
||||
}
|
||||
return getMetadataTotals(url);
|
||||
}
|
||||
|
||||
|
||||
|
@ -148,28 +106,7 @@ public class StatsServiceImpl implements StatsService {
|
|||
" oaftype exact datasource and " +
|
||||
" datasourcetypename exact Journal";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||
if ( metadata == null ) {
|
||||
logger.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
logger.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
logger.error("", e);
|
||||
return null;
|
||||
}
|
||||
return getMetadataTotals(url);
|
||||
}
|
||||
|
||||
|
||||
|
@ -177,28 +114,7 @@ public class StatsServiceImpl implements StatsService {
|
|||
{
|
||||
String url = baseAddress + "/publications/count";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map<?, ?>) rs.getBody();
|
||||
if ( metadata == null ) {
|
||||
logger.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
logger.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
logger.error("", e);
|
||||
return null;
|
||||
}
|
||||
return getCommonStats(url);
|
||||
}
|
||||
|
||||
|
||||
|
@ -206,28 +122,7 @@ public class StatsServiceImpl implements StatsService {
|
|||
{
|
||||
String url = baseAddress + "/datasets/count";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map<?, ?>) rs.getBody();
|
||||
if ( metadata == null ) {
|
||||
logger.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
logger.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
logger.error("", e);
|
||||
return null;
|
||||
}
|
||||
return getCommonStats(url);
|
||||
}
|
||||
|
||||
|
||||
|
@ -235,28 +130,7 @@ public class StatsServiceImpl implements StatsService {
|
|||
{
|
||||
String url = baseAddress + "/software/count";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map<?, ?>) rs.getBody();
|
||||
if ( metadata == null ) {
|
||||
logger.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
logger.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
logger.error("", e);
|
||||
return null;
|
||||
}
|
||||
return getCommonStats(url);
|
||||
}
|
||||
|
||||
|
||||
|
@ -297,17 +171,70 @@ public class StatsServiceImpl implements StatsService {
|
|||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("totals");
|
||||
if ( metadata == null ) {
|
||||
logger.error("The metadata was null!");
|
||||
Map statsTotals = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("totals");
|
||||
if ( statsTotals == null ) {
|
||||
logger.error("The statsTotals was null!");
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO - Will we ever need the following lines?
|
||||
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
||||
// JSONObject resultSet = new JSONObject(rs);
|
||||
// JSONObject totals = resultSet.getJSONObject("totals");
|
||||
|
||||
return (Integer) metadata.get("events");
|
||||
return (Integer) statsTotals.get("events");
|
||||
} catch ( RestClientException rce ) {
|
||||
logger.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
logger.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getMetadataTotals(String url) {
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||
if ( metadata == null ) {
|
||||
logger.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
logger.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
logger.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getCommonStats(String url) {
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map stats = (Map<?, ?>) rs.getBody();
|
||||
if ( stats == null ) {
|
||||
logger.error("The stats was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(stats.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
logger.error(rce.getMessage());
|
||||
return null;
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
package eu.dnetlib.repo.manager.service;
|
||||
|
||||
import eu.dnetlib.usagestats.sushilite.domain.Customer;
|
||||
import eu.dnetlib.usagestats.sushilite.domain.ReportItem;
|
||||
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
|
@ -40,62 +43,79 @@ public class SushiliteServiceImpl implements SushiliteService {
|
|||
String Granularity,
|
||||
String Pretty) {
|
||||
|
||||
//build the uri params
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usagestatsSushiliteEndpoint + "GetReport/")
|
||||
.queryParam("Report", Report)
|
||||
.queryParam("Release", Release)
|
||||
.queryParam("RequestorID", RequestorID)
|
||||
.queryParam("BeginDate", BeginDate)
|
||||
.queryParam("EndDate", EndDate)
|
||||
.queryParam("RepositoryIdentifier", RepositoryIdentifier)
|
||||
.queryParam("ItemIdentifier", ItemIdentifier)
|
||||
.queryParam("ItemDataType", ItemDataType)
|
||||
.queryParam("Granularity", Granularity)
|
||||
.queryParam("Pretty", Pretty);
|
||||
//build the uri params
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usagestatsSushiliteEndpoint + "GetReport/")
|
||||
.queryParam("Report", Report)
|
||||
.queryParam("Release", Release)
|
||||
.queryParam("RequestorID", RequestorID)
|
||||
.queryParam("BeginDate", BeginDate)
|
||||
.queryParam("EndDate", EndDate)
|
||||
.queryParam("RepositoryIdentifier", RepositoryIdentifier)
|
||||
.queryParam("ItemIdentifier", ItemIdentifier)
|
||||
.queryParam("ItemDataType", ItemDataType)
|
||||
.queryParam("Granularity", Granularity)
|
||||
.queryParam("Pretty", Pretty);
|
||||
|
||||
//create new template engine
|
||||
RestTemplate template = new RestTemplate();
|
||||
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
||||
//create new restTemplate engine
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
||||
|
||||
ResponseEntity<ReportResponseWrapper> resp;
|
||||
ResponseEntity<ReportResponseWrapper> resp;
|
||||
|
||||
try {
|
||||
//communicate with endpoint
|
||||
resp = template.exchange(
|
||||
resp = restTemplate.exchange(
|
||||
builder.build().encode().toUri(),
|
||||
HttpMethod.GET,
|
||||
null,
|
||||
new ParameterizedTypeReference<ReportResponseWrapper>() {
|
||||
});
|
||||
new ParameterizedTypeReference<ReportResponseWrapper>() {});
|
||||
} catch (RestClientException rce) {
|
||||
logger.error("", rce);
|
||||
return null;
|
||||
}
|
||||
|
||||
// check remote api's response
|
||||
System.out.println("sushi responded status " + resp.getStatusCode());
|
||||
// check remote api's response
|
||||
HttpStatus httpStatus = resp.getStatusCode();
|
||||
if ( httpStatus != HttpStatus.OK ) {
|
||||
logger.warn("Sushi cannot give us data! Responded status: " + httpStatus);
|
||||
return null;
|
||||
}
|
||||
|
||||
// get the items corresponding to the requested page
|
||||
List<ReportItem> requestedItemList = new ArrayList<>();
|
||||
if (resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems() != null) {
|
||||
try {
|
||||
int totalItems = resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems().size();
|
||||
int size = Integer.parseInt(pageSize);
|
||||
int offset = Integer.parseInt(page)*size;
|
||||
ReportResponseWrapper reportResponseWrapper = resp.getBody();
|
||||
if ( reportResponseWrapper == null ) {
|
||||
logger.error("The \"reportResponseWrapper\" for sushi was null!");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (offset < totalItems ) {
|
||||
int upperIndex = offset+size;
|
||||
if (upperIndex > totalItems) {
|
||||
upperIndex = totalItems;
|
||||
}
|
||||
requestedItemList = resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems().subList(offset,upperIndex);
|
||||
// get the items corresponding to the requested page
|
||||
List<ReportItem> requestedItemList = new ArrayList<>();
|
||||
|
||||
Customer customer = reportResponseWrapper.getReportResponse().getReportWrapper().getReport().getCustomer();
|
||||
List<ReportItem> allReportItems = customer.getReportItems();
|
||||
|
||||
if ( allReportItems != null) {
|
||||
try {
|
||||
int totalItems = allReportItems.size();
|
||||
int size = Integer.parseInt(pageSize);
|
||||
int offset = (Integer.parseInt(page) * size);
|
||||
|
||||
if (offset < totalItems ) {
|
||||
int upperIndex = (offset + size);
|
||||
if (upperIndex > totalItems) {
|
||||
upperIndex = totalItems;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
logger.debug("Exception on getReportResults - trying to cast strings to integers", e);
|
||||
//emailUtils.reportException(e);
|
||||
throw e;
|
||||
requestedItemList = allReportItems.subList(offset, upperIndex);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
logger.debug("Exception on getReportResults - trying to cast strings to integers", e);
|
||||
//emailUtils.reportException(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
ReportResponseWrapper newReportResponse = resp.getBody();
|
||||
newReportResponse.getReportResponse().getReportWrapper().getReport().getCustomer().setReportItems(requestedItemList);
|
||||
customer.setReportItems(requestedItemList); // Setting the reportItems to the "customer"-reference, updates the "reportResponseWrapper" object.
|
||||
|
||||
return newReportResponse;
|
||||
return reportResponseWrapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -98,11 +98,7 @@ public class RegistryCalls implements AaiRegistryService {
|
|||
try {
|
||||
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
String sub = authentication.getUserInfo().getSub();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("coid", coid);
|
||||
params.put("search.identifier", sub);
|
||||
JsonElement response = httpUtils.get("co_people.json", params);
|
||||
return (response != null) ? response.getAsJsonObject().get("CoPeople").getAsJsonArray().get(0).getAsJsonObject().get("Id").getAsInt() : null;
|
||||
return getCoPersonIdByIdentifier(sub);
|
||||
} catch (Exception e) {
|
||||
logger.error("Get User info: An error occurred ", e);
|
||||
return null;
|
||||
|
@ -296,9 +292,11 @@ public class RegistryCalls implements AaiRegistryService {
|
|||
JsonArray infos = getUserEmailByCouId(couId, false);
|
||||
|
||||
infos.forEach(info -> {
|
||||
JsonObject jsonInfo = info.getAsJsonObject();
|
||||
|
||||
User user = new User();
|
||||
user.setEmail(jsonInfo.get("email").getAsString());
|
||||
// TODO: should add firstname and lastname and sub of user
|
||||
user.setEmail(info.getAsJsonObject().get("email").getAsString());
|
||||
|
||||
users.add(user);
|
||||
});
|
||||
|
@ -316,9 +314,10 @@ public class RegistryCalls implements AaiRegistryService {
|
|||
JsonArray infos = (response != null) ? response.getAsJsonObject().get("Names").getAsJsonArray() : new JsonArray();
|
||||
JsonArray names = new JsonArray();
|
||||
infos.forEach(info -> {
|
||||
JsonObject jsonInfo = info.getAsJsonObject();
|
||||
JsonObject user = new JsonObject();
|
||||
user.addProperty("name", info.getAsJsonObject().get("Given").getAsString() + " " + info.getAsJsonObject().get("Family").getAsString());
|
||||
user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString());
|
||||
user.addProperty("name", jsonInfo.get("Given").getAsString() + " " + jsonInfo.get("Family").getAsString());
|
||||
user.addProperty("memberSince", jsonInfo.get("Created").getAsString());
|
||||
names.add(user);
|
||||
});
|
||||
return names;
|
||||
|
@ -335,9 +334,10 @@ public class RegistryCalls implements AaiRegistryService {
|
|||
JsonArray infos = (response != null) ? response.getAsJsonObject().get("Identifiers").getAsJsonArray() : new JsonArray();
|
||||
JsonArray emails = new JsonArray();
|
||||
infos.forEach(info -> {
|
||||
JsonObject jsonInfo = info.getAsJsonObject();
|
||||
JsonObject user = new JsonObject();
|
||||
user.addProperty("id", info.getAsJsonObject().get("Identifier").getAsString());
|
||||
user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString());
|
||||
user.addProperty("id", jsonInfo.get("Identifier").getAsString());
|
||||
user.addProperty("memberSince", jsonInfo.get("Created").getAsString());
|
||||
emails.add(user);
|
||||
});
|
||||
return emails;
|
||||
|
@ -380,7 +380,11 @@ public class RegistryCalls implements AaiRegistryService {
|
|||
params.put("copersonid", coPersonId.toString());
|
||||
JsonElement response = httpUtils.get("names.json", params);
|
||||
JsonObject info = (response != null) ? response.getAsJsonObject().get("Names").getAsJsonArray().get(0).getAsJsonObject() : null;
|
||||
return (info != null) ? info.getAsJsonObject().get("Given").getAsString() + " " + info.getAsJsonObject().get("Family").getAsString() : null;
|
||||
if ( info != null ) {
|
||||
JsonObject jsonInfo = info.getAsJsonObject();
|
||||
return jsonInfo.get("Given").getAsString() + " " + jsonInfo.get("Family").getAsString();
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -427,8 +431,9 @@ public class RegistryCalls implements AaiRegistryService {
|
|||
int total = couIds.size();
|
||||
for (JsonElement cou : cous) {
|
||||
if (count < total) {
|
||||
if (idNameMap.containsKey(cou.getAsJsonObject().get("Id").getAsInt())) {
|
||||
idNameMap.put(cou.getAsJsonObject().get("Id").getAsInt(), cou.getAsJsonObject().get("Name").getAsString());
|
||||
JsonObject jsonCou = cou.getAsJsonObject();
|
||||
if (idNameMap.containsKey(jsonCou.get("Id").getAsInt())) {
|
||||
idNameMap.put(jsonCou.get("Id").getAsInt(), jsonCou.get("Name").getAsString());
|
||||
count++;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -2,10 +2,12 @@ package eu.dnetlib.repo.manager.service.security;
|
|||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.nimbusds.jose.util.StandardCharset;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -25,22 +27,24 @@ public class AuthoritiesMapper {
|
|||
return authorities;
|
||||
}
|
||||
|
||||
public static List<String> entitlementRoles(JsonArray entitlements) {
|
||||
public static List<String> entitlementRoles(JsonArray entitlements) throws UnsupportedEncodingException {
|
||||
List<String> roles = new ArrayList<>();
|
||||
if (entitlements != null) {
|
||||
for (JsonElement obj : entitlements) {
|
||||
Matcher matcher = ENTITLEMENT_REGEX.matcher(obj.getAsString());
|
||||
if (matcher.find()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (matcher.group(1) != null && matcher.group(1).length() > 0) {
|
||||
sb.append(matcher.group(1));
|
||||
String group1 = matcher.group(1);
|
||||
if (group1 != null && group1.length() > 0) {
|
||||
sb.append(group1);
|
||||
}
|
||||
if (matcher.group(2).length() > 0) {
|
||||
String group2 = matcher.group(2);
|
||||
if (group2.length() > 0) {
|
||||
sb.append(":");
|
||||
sb.append(matcher.group(2));
|
||||
sb.append(group2);
|
||||
}
|
||||
String role = sb.toString().replace("+", " ");
|
||||
roles.add(URLDecoder.decode(role));
|
||||
roles.add(URLDecoder.decode(role, StandardCharset.UTF_8.name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,15 +57,17 @@ public class AuthoritiesMapper {
|
|||
Matcher matcher = ENTITLEMENT_REGEX.matcher(obj.getAsString());
|
||||
if (matcher.find()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (matcher.group(1) != null && matcher.group(1).length() > 0) {
|
||||
sb.append(matcher.group(1).replace("+-+", "_").replaceAll("[+.]", "_").toUpperCase());
|
||||
String group1 = matcher.group(1);
|
||||
if (group1 != null && group1.length() > 0) {
|
||||
sb.append(group1.replace("+-+", "_").replaceAll("[+.]", "_").toUpperCase());
|
||||
}
|
||||
if (matcher.group(2).length() > 0) {
|
||||
String group2 = matcher.group(2);
|
||||
if (group2.length() > 0) {
|
||||
sb.append("_");
|
||||
if (matcher.group(2).equals("admins")) {
|
||||
if (group2.equals("admins")) {
|
||||
sb.append("MANAGER");
|
||||
} else {
|
||||
sb.append(matcher.group(2).toUpperCase());
|
||||
sb.append(group2.toUpperCase());
|
||||
}
|
||||
}
|
||||
authorities.add(new SimpleGrantedAuthority(sb.toString()));
|
||||
|
|
|
@ -28,11 +28,11 @@ public class AuthoritiesUpdater extends HttpSessionSecurityContextRepository {
|
|||
|
||||
public void update(String id, Update update) {
|
||||
if (sessions != null) {
|
||||
Map<String, Session> map = sessions.
|
||||
findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, id);
|
||||
Map map = sessions.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, id);
|
||||
if (map != null) {
|
||||
logger.debug(map.values().toArray().length);
|
||||
for (Session session : map.values()) {
|
||||
for ( Object sessionObject : map.values()) {
|
||||
Session session = (Session) sessionObject;
|
||||
logger.debug(session.getId());
|
||||
if (!session.isExpired()) {
|
||||
SecurityContext securityContext = session.getAttribute(SPRING_SECURITY_CONTEXT_KEY);
|
||||
|
|
|
@ -50,7 +50,7 @@ public class Converter {
|
|||
return resultSet;
|
||||
}
|
||||
|
||||
public List<RepositoryInterface> toRepositoryInterfaceList(List<ApiDetails> apiDetailsList) throws JSONException {
|
||||
public List<RepositoryInterface> toRepositoryInterfaceList(List<ApiDetails> apiDetailsList) {
|
||||
|
||||
List<RepositoryInterface> resultSet = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.dnetlib.repo.manager.utils;
|
|||
import eu.dnetlib.domain.functionality.validator.JobResultEntry;
|
||||
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
||||
import org.eurocris.openaire.cris.validator.model.Job;
|
||||
import org.eurocris.openaire.cris.validator.model.Rule;
|
||||
import org.eurocris.openaire.cris.validator.model.RuleResults;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
@ -20,14 +21,17 @@ public class CrisValidatorUtils {
|
|||
StoredJob sj = new StoredJob();
|
||||
sj.setId(job.getId().hashCode());
|
||||
sj.setValidationStatus(job.getStatus());
|
||||
if (job.getDateFinished() != null) {
|
||||
sj.setEnded(DATE_FORMATTER.format(job.getDateFinished()));
|
||||
sj.setDuration(DURATION_FORMATTER.format(new Date(job.getDateFinished().getTime() - job.getDateStarted().getTime())));
|
||||
|
||||
Date dateFinished = job.getDateFinished();
|
||||
Date dateStarted = job.getDateStarted();
|
||||
if ( dateFinished != null ) {
|
||||
sj.setEnded(DATE_FORMATTER.format(dateFinished));
|
||||
sj.setDuration(DURATION_FORMATTER.format(new Date(dateFinished.getTime() - dateStarted.getTime())));
|
||||
} else {
|
||||
sj.setEnded("-");
|
||||
sj.setDuration("-");
|
||||
}
|
||||
sj.setStarted(DATE_FORMATTER.format(job.getDateStarted()));
|
||||
sj.setStarted(DATE_FORMATTER.format(dateStarted));
|
||||
|
||||
sj.setUserEmail(job.getUser());
|
||||
sj.setCris(true);
|
||||
|
@ -56,21 +60,24 @@ public class CrisValidatorUtils {
|
|||
public static List<JobResultEntry> crisResultsToJobEntries(Job crisJob) {
|
||||
List<JobResultEntry> jobResultEntries = new ArrayList<>();
|
||||
for (RuleResults ruleResults : crisJob.getRuleResults()) {
|
||||
Rule rule = ruleResults.getRule();
|
||||
JobResultEntry jobResultEntry = new JobResultEntry();
|
||||
jobResultEntry.setName(ruleResults.getRule().getName());
|
||||
jobResultEntry.setRuleId(ruleResults.getRule().getId());
|
||||
jobResultEntry.setDescription(ruleResults.getRule().getDescription());
|
||||
jobResultEntry.setName(rule.getName());
|
||||
jobResultEntry.setRuleId(rule.getId());
|
||||
jobResultEntry.setDescription(rule.getDescription());
|
||||
jobResultEntry.setMandatory(true);
|
||||
jobResultEntry.setWeight(Math.round(ruleResults.getRule().getWeight()));
|
||||
jobResultEntry.setType(ruleResults.getRule().getType());
|
||||
jobResultEntry.setWeight(Math.round(rule.getWeight()));
|
||||
jobResultEntry.setType(rule.getType());
|
||||
jobResultEntry.setHasErrors(false);
|
||||
if (ruleResults.getCount() == 0) {
|
||||
long countRuleResults = ruleResults.getCount();
|
||||
if (countRuleResults == 0) {
|
||||
jobResultEntry.setSuccesses("-");
|
||||
} else {
|
||||
jobResultEntry.setSuccesses(ruleResults.getCount() - ruleResults.getFailed() + "/" + ruleResults.getCount());
|
||||
jobResultEntry.setSuccesses(countRuleResults - ruleResults.getFailed() + "/" + countRuleResults);
|
||||
}
|
||||
if (ruleResults.getErrorMessages() != null && !ruleResults.getErrorMessages().isEmpty()) {
|
||||
jobResultEntry.setErrors(ruleResults.getErrorMessages());
|
||||
List<String> errorMessages = ruleResults.getErrorMessages();
|
||||
if (errorMessages != null && !errorMessages.isEmpty()) {
|
||||
jobResultEntry.setErrors(errorMessages);
|
||||
jobResultEntry.setHasErrors(true);
|
||||
}
|
||||
jobResultEntries.add(jobResultEntry);
|
||||
|
|
|
@ -85,12 +85,17 @@ public class HttpUtils {
|
|||
}
|
||||
|
||||
private JsonElement getResponseEntityAsJsonElement(ResponseEntity<String> responseEntity) {
|
||||
if (responseEntity != null && responseEntity.getBody() != null) {
|
||||
logger.debug(responseEntity.getBody());
|
||||
|
||||
if ( responseEntity == null )
|
||||
return null;
|
||||
|
||||
String responseBody = responseEntity.getBody();
|
||||
if ( responseBody != null ) {
|
||||
logger.debug(responseBody);
|
||||
try {
|
||||
return new JsonParser().parse(responseEntity.getBody());
|
||||
return new JsonParser().parse(responseBody);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Could not parse response body", e);
|
||||
logger.warn("Could not parse response body", e); // Will return null.
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package eu.dnetlib.repo.manager.controllers;
|
||||
package eu.dnetlib.repo.manager.utils;
|
||||
|
||||
import eu.dnetlib.repo.manager.exception.EndPointException;
|
||||
import org.springframework.http.HttpStatus;
|
Loading…
Reference in New Issue