- Add error-checking and improve exceptions handling.
- Code polishing.
This commit is contained in:
parent
f720446bdf
commit
deae3b8b54
|
@ -22,8 +22,7 @@ public class FrontEndLinkURIAuthenticationSuccessHandler implements Authenticati
|
||||||
|
|
||||||
private String frontEndURI;
|
private String frontEndURI;
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger
|
private static final Logger LOGGER = Logger.getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class);
|
||||||
.getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class);
|
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
LOGGER.debug("Front end uri : " + frontEndURI);
|
LOGGER.debug("Front end uri : " + frontEndURI);
|
||||||
|
|
|
@ -33,8 +33,7 @@ import java.util.List;
|
||||||
@Api(description = "Piwik API", tags = {"piwik"})
|
@Api(description = "Piwik API", tags = {"piwik"})
|
||||||
public class PiWikController {
|
public class PiWikController {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger
|
private static final Logger LOGGER = Logger.getLogger(PiWikController.class);
|
||||||
.getLogger(PiWikController.class);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PiWikServiceImpl piWikService;
|
private PiWikServiceImpl piWikService;
|
||||||
|
|
|
@ -19,8 +19,7 @@ public class StatsController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private StatsServiceImpl statsService;
|
private StatsServiceImpl statsService;
|
||||||
|
|
||||||
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET,
|
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Map getStatistics(){
|
public Map getStatistics(){
|
||||||
return statsService.getStatistics();
|
return statsService.getStatistics();
|
||||||
|
|
|
@ -426,8 +426,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
public List<AggregationInfo> getRepositoryAggregations(String id, int from, int size) {
|
public List<AggregationInfo> getRepositoryAggregations(String id, int from, int size) {
|
||||||
|
|
||||||
List<AggregationInfo> res = getRepositoryAggregations(id);
|
List<AggregationInfo> res = getRepositoryAggregations(id);
|
||||||
|
return (res != null) ? res.subList(from, Math.min(from + size, res.size())) : null;
|
||||||
return res.subList(from, Math.min(from + size, res.size()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -435,9 +434,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
LOGGER.debug("Retrieving aggregations (by year) for repository with id : " + id);
|
LOGGER.debug("Retrieving aggregations (by year) for repository with id : " + id);
|
||||||
|
|
||||||
List<AggregationInfo> aggregationHistory = getRepositoryAggregations(id);
|
List<AggregationInfo> aggregationHistory = getRepositoryAggregations(id);
|
||||||
Map<String, List<AggregationInfo>> aggregationByYear = new HashMap<>();
|
if ( aggregationHistory != null ) {
|
||||||
|
Map<String, List<AggregationInfo>> aggregationByYear = new HashMap<>();
|
||||||
return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory);
|
return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory);
|
||||||
|
} else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, List<AggregationInfo>> createYearMap(List<AggregationInfo> aggregationHistory) {
|
private Map<String, List<AggregationInfo>> createYearMap(List<AggregationInfo> aggregationHistory) {
|
||||||
|
@ -479,15 +480,19 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
||||||
ApiDetailsResponse rs = restTemplate.getForObject(uriComponents.toUri(), ApiDetailsResponse.class);
|
ApiDetailsResponse rs = restTemplate.getForObject(uriComponents.toUri(), ApiDetailsResponse.class);
|
||||||
|
if ( rs == null ) {
|
||||||
|
LOGGER.error("The ApiDetailsResponse was null!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO STOP FILTERING OUT "sword", "rest" AND FIX UI!
|
// TODO STOP FILTERING OUT "sword", "rest" AND FIX UI!
|
||||||
List<ApiDetails> res = new ArrayList<>();
|
List<ApiDetails> res = new ArrayList<>();
|
||||||
|
|
||||||
for (ApiDetails det: rs.getApi()) {
|
for (ApiDetails det: rs.getApi()) {
|
||||||
if (!det.getProtocol().equals("sword") &&
|
String protocol = det.getProtocol();
|
||||||
!det.getProtocol().equals("rest") &&
|
if ( !protocol.equals("sword") &&
|
||||||
!det.getProtocol().equals("ftp")) {
|
!protocol.equals("rest") &&
|
||||||
|
!protocol.equals("ftp")) {
|
||||||
res.add(det);
|
res.add(det);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -560,7 +565,6 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,8 +589,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error sending email", e);
|
LOGGER.error("Error sending email", e);
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
LOGGER.error("Error storing repository: " + responseEntity.getBody().toString());
|
Object responseBody = responseEntity.getBody();
|
||||||
|
if ( responseBody != null )
|
||||||
|
LOGGER.error("Error updating repository: " + responseBody);
|
||||||
|
}
|
||||||
|
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
@ -603,8 +610,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
// LOGGER.debug("JSON to update -> " + json_repository);
|
// LOGGER.debug("JSON to update -> " + json_repository);
|
||||||
|
|
||||||
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
||||||
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity
|
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
||||||
, ResponseEntity.class);
|
|
||||||
|
|
||||||
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
||||||
try {
|
try {
|
||||||
|
@ -613,8 +619,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error sending emails: " + e);
|
LOGGER.error("Error sending emails: " + e);
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
LOGGER.debug(responseEntity.getBody().toString());
|
Object responseBody = responseEntity.getBody();
|
||||||
|
if ( responseBody != null )
|
||||||
|
LOGGER.error("Error updating repository: " + responseBody);
|
||||||
|
}
|
||||||
|
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
@ -643,7 +652,9 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
LOGGER.error("Error sending emails: " + e);
|
LOGGER.error("Error sending emails: " + e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOGGER.debug(responseEntity.getBody().toString());
|
Object responseBody = responseEntity.getBody();
|
||||||
|
if ( responseBody != null )
|
||||||
|
LOGGER.error("Error storing repository: " + responseBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -804,7 +815,8 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
RequestFilter requestFilter = new RequestFilter();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
requestFilter.setRegisteredby(userEmail);
|
requestFilter.setRegisteredby(userEmail);
|
||||||
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class));
|
Object result = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class);
|
||||||
|
return (result != null) ? Collections.singletonList(result.toString()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vocabulary getVocabulary(String vocName) {
|
private Vocabulary getVocabulary(String vocName) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.dnetlib.repo.manager.service;
|
package eu.dnetlib.repo.manager.service;
|
||||||
|
|
||||||
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.mitre.openid.connect.model.UserInfo;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
@ -25,12 +25,16 @@ public class UserServiceImpl implements UserService {
|
||||||
LOGGER.debug("User authentication : " + authentication);
|
LOGGER.debug("User authentication : " + authentication);
|
||||||
Map<String,Object> body = new HashMap<>();
|
Map<String,Object> body = new HashMap<>();
|
||||||
body.put("sub",authentication.getSub());
|
body.put("sub",authentication.getSub());
|
||||||
if(authentication.getUserInfo().getName() == null || authentication.getUserInfo().getName().equals(""))
|
|
||||||
body.put("name",authentication.getUserInfo().getGivenName() + " " + authentication.getUserInfo().getFamilyName());
|
|
||||||
else
|
|
||||||
body.put("name",authentication.getUserInfo().getName());
|
|
||||||
|
|
||||||
body.put("email",authentication.getUserInfo().getEmail());
|
UserInfo userInfo = authentication.getUserInfo();
|
||||||
|
String userName = userInfo.getName();
|
||||||
|
|
||||||
|
if ( userName == null || userName.isEmpty() )
|
||||||
|
body.put("name", userInfo.getGivenName() + " " + userInfo.getFamilyName());
|
||||||
|
else
|
||||||
|
body.put("name", userName);
|
||||||
|
|
||||||
|
body.put("email",userInfo.getEmail());
|
||||||
List<String> roles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
|
List<String> roles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
|
||||||
body.put("role",roles);
|
body.put("role",roles);
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,7 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
|
|
||||||
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
|
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger
|
private static final Logger LOGGER = Logger.getLogger(ValidatorServiceImpl.class);
|
||||||
.getLogger(ValidatorServiceImpl.class);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmailUtils emailUtils;
|
private EmailUtils emailUtils;
|
||||||
|
|
|
@ -12,7 +12,6 @@ import org.json.JSONObject;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -87,17 +86,17 @@ public class Converter {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
//InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
|
//InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
|
||||||
InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename);
|
InputStream in = Converter.class.getResourceAsStream("/eu/**/" + filename);
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(in)); // It may throw an NPE.
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
list.add(line.trim());
|
list.add(line.trim());
|
||||||
}
|
}
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
LOGGER.debug("Error opening file!");
|
LOGGER.debug("Error opening file!");
|
||||||
LOGGER.error(e);
|
LOGGER.error(e);
|
||||||
}
|
}
|
||||||
return list;
|
return list; // It may be empty.
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AggregationInfo> toAggregationHistory(String aggregationHistoryResponse) throws JSONException {
|
public List<AggregationInfo> toAggregationHistory(String aggregationHistoryResponse) throws JSONException {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.springframework.http.*;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@ -78,8 +78,7 @@ public class HttpUtils {
|
||||||
private HttpHeaders createHeaders(String username, String password) {
|
private HttpHeaders createHeaders(String username, String password) {
|
||||||
return new HttpHeaders() {{
|
return new HttpHeaders() {{
|
||||||
String auth = username + ":" + password;
|
String auth = username + ":" + password;
|
||||||
byte[] encodedAuth = Base64.encodeBase64(
|
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.US_ASCII));
|
||||||
auth.getBytes(Charset.forName("US-ASCII")));
|
|
||||||
String authHeader = "Basic " + new String(encodedAuth);
|
String authHeader = "Basic " + new String(encodedAuth);
|
||||||
set("Authorization", authHeader);
|
set("Authorization", authHeader);
|
||||||
}};
|
}};
|
||||||
|
|
|
@ -32,8 +32,7 @@ public class OaiTools {
|
||||||
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
|
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
|
||||||
SetsList setList = harvester.listSets();
|
SetsList setList = harvester.listSets();
|
||||||
ResumptionToken token = setList.getResumptionToken();
|
ResumptionToken token = setList.getResumptionToken();
|
||||||
List<Set> sets = new ArrayList<Set>();
|
List<Set> sets = new ArrayList<>(setList.asList());
|
||||||
sets.addAll(setList.asList());
|
|
||||||
while (token != null) {
|
while (token != null) {
|
||||||
setList = harvester.listSets(token);
|
setList = harvester.listSets(token);
|
||||||
token = setList.getResumptionToken();
|
token = setList.getResumptionToken();
|
||||||
|
|
Loading…
Reference in New Issue