develop #1

Merged
antonis.lempesis merged 36 commits from develop into master 2023-01-19 12:41:45 +01:00
26 changed files with 286 additions and 295 deletions
Showing only changes of commit 87f610b06b - Show all commits

View File

@ -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`

View File

@ -1,8 +1,8 @@
package eu.dnetlib.repo.manager.config;
import com.google.gson.JsonParser;
import org.slf4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
@ -33,14 +33,16 @@ public class FrontEndLinkURIAuthenticationSuccessHandler implements Authenticati
@Value("${services.provide.aai.oidc.domain}")
private String domain;
private static final Pattern AUTH_REGEX = Pattern.compile("^([A-Za-z0-9-_=]+)\\.([A-Za-z0-9-_=]+)\\.?([A-Za-z0-9-_.+=]*)$");
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
request.getSession().setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, authOIDC.getUserInfo().getSub());
Cookie accessToken = new Cookie("AccessToken", authOIDC.getAccessTokenValue());
String regex = "^([A-Za-z0-9-_=]+)\\.([A-Za-z0-9-_=]+)\\.?([A-Za-z0-9-_.+=]*)$";
Matcher matcher = Pattern.compile(regex).matcher(authOIDC.getAccessTokenValue());
Matcher matcher = AUTH_REGEX.matcher(authOIDC.getAccessTokenValue());
if (matcher.find()) {
long exp = new JsonParser().parse(new String(Base64.getDecoder().decode(matcher.group(2)))).getAsJsonObject().get("exp").getAsLong();
accessToken.setMaxAge((int) (exp - (new Date().getTime() / 1000)));

View File

@ -3,9 +3,9 @@ package eu.dnetlib.repo.manager.config;
import com.google.gson.JsonArray;
import com.nimbusds.jwt.JWT;
import eu.dnetlib.repo.manager.service.security.AuthoritiesMapper;
import org.slf4j.Logger;
import org.mitre.openid.connect.client.OIDCAuthoritiesMapper;
import org.mitre.openid.connect.model.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.GrantedAuthority;

View File

@ -94,5 +94,4 @@ public class DashboardController {
return new BrokerSummary(brokerService.getSimpleSubscriptionsOfUser(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail()), brokerService.getTopicsForDatasource(datasourceName));
}
}

View File

@ -6,8 +6,8 @@ import eu.dnetlib.repo.manager.exception.BrokerException;
import eu.dnetlib.repo.manager.exception.EndPointException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.exception.ServerError;
import org.slf4j.Logger;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

View File

@ -6,9 +6,9 @@ import eu.dnetlib.repo.manager.domain.JobsOfUser;
import eu.dnetlib.repo.manager.service.MonitorServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;

View File

@ -76,6 +76,7 @@ public class PiWikController {
results.setResults(returning);
return results;
}
@ApiImplicitParams({
@ApiImplicitParam(name = "from", dataType = "number", paramType = "query"),
@ApiImplicitParam(name = "quantity", dataType = "number", paramType = "query"),
@ -103,20 +104,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());
@ -141,7 +139,6 @@ public class PiWikController {
strDate);
response.setHeader(headerKey, headerValue);
return new FileSystemResource(p.toFile());
}

View File

@ -11,9 +11,9 @@ import eu.dnetlib.repo.manager.service.RepositoryService;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import eu.dnetlib.repo.manager.utils.JsonUtils;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

View File

@ -1,13 +1,11 @@
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;

View File

@ -28,7 +28,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 {
@ -49,7 +52,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() {
@ -122,7 +125,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}";
@ -157,7 +160,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());
}
@ -166,12 +169,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 ");

View File

@ -6,8 +6,8 @@ import eu.dnetlib.repo.manager.domain.Repository;
import eu.dnetlib.repo.manager.domain.RepositoryInterface;
import eu.dnetlib.repo.manager.exception.ValidationServiceException;
import eu.dnetlib.utils.MailLibrary;
import org.slf4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -745,6 +745,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?
}
}

View File

@ -7,10 +7,10 @@ import eu.dnetlib.repo.manager.domain.Constants;
import eu.dnetlib.repo.manager.domain.JobsOfUser;
import eu.dnetlib.repo.manager.utils.CrisValidatorUtils;
import gr.uoa.di.driver.util.ServiceLocator;
import org.slf4j.Logger;
import org.eurocris.openaire.cris.validator.model.Job;
import org.eurocris.openaire.cris.validator.service.MapJobDao;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@ -5,8 +5,6 @@ import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import org.json.JSONException;
import org.springframework.security.core.Authentication;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.io.IOException;
import java.util.List;

View File

@ -149,8 +149,6 @@ public class RepositoryServiceImpl implements RepositoryService {
countriesMap.put(c.getName(), c.getCode());
inverseCountriesMap.put(c.getCode(), c.getName());
}
}
@Override
@ -181,11 +179,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;
@ -215,6 +215,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)));
@ -258,6 +262,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) {
@ -266,6 +275,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;
@ -309,7 +323,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")
@ -373,6 +387,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)
@ -395,7 +414,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();
@ -530,7 +554,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)) {
emailUtils.sendUserRegistrationEmail(repository, authentication);
@ -556,7 +580,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)) {
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
@ -584,7 +608,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)) {
emailUtils.sendUserRegistrationEmail(repository, authentication);
@ -776,7 +800,7 @@ public class RepositoryServiceImpl implements RepositoryService {
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_ALL))
return compatibilityClasses;
else if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) {
if (entry.getKey().matches("^openaire[1-9].0_data$")) {
if ( ValidatorServiceImpl.OPENAIRE_DATA_REGEX.matcher(entry.getKey()).matches() ) {
retMap.put(entry.getKey(), entry.getValue());
foundData = true;
}
@ -787,7 +811,7 @@ public class RepositoryServiceImpl implements RepositoryService {
foundData = true;
}
} else {
if (entry.getKey().matches("^openaire[1-9].0$") || entry.getKey().equals("driver"))
if ( ValidatorServiceImpl.OPENAIRE_OR_DRIVER_REGEX.matcher(entry.getKey()).matches() )
retMap.put(entry.getKey(), entry.getValue());
}
}

View File

@ -84,28 +84,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);
}
@ -117,28 +96,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);
}
@ -149,28 +107,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);
}
@ -178,28 +115,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);
}
@ -207,28 +123,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);
}
@ -236,28 +131,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);
}
@ -298,17 +172,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;

View File

@ -1,5 +1,6 @@
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.slf4j.Logger;
@ -7,10 +8,12 @@ import org.slf4j.LoggerFactory;
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;
@ -42,62 +45,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;
}
}

View File

@ -12,11 +12,11 @@ import eu.dnetlib.repo.manager.exception.ValidationServiceException;
import eu.dnetlib.repo.manager.utils.CrisValidatorUtils;
import eu.dnetlib.repo.manager.utils.OaiTools;
import gr.uoa.di.driver.util.ServiceLocator;
import org.slf4j.Logger;
import org.eurocris.openaire.cris.validator.model.Job;
import org.eurocris.openaire.cris.validator.service.JobExecutor;
import org.eurocris.openaire.cris.validator.service.MapJobDao;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@ -29,6 +29,7 @@ import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -69,6 +70,12 @@ public class ValidatorServiceImpl implements ValidatorService {
@Autowired
private MapJobDao crisJobs;
public static final Pattern OPENAIRE_DATA_REGEX = Pattern.compile("^openaire[1-9].0_data$");
public static final Pattern OPENAIRE_OR_DRIVER_REGEX = Pattern.compile("^(?:openaire[1-9].0|driver)$");
public static final Pattern OPENAIRE_CRIS_REGEX = Pattern.compile("^openaire[1-9].0_cris$");
public static final Pattern FAIR_REGEX = Pattern.compile(".*fair$");
@PostConstruct
private void loadRules(){
logger.debug("PostConstruct method! Load rules!");
@ -76,13 +83,14 @@ public class ValidatorServiceImpl implements ValidatorService {
for (RuleSet ruleSet : getValidationService().getRuleSets()) {
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) {
String key = "";
if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_data$"))
String guidelinesAcronym = ruleSet.getGuidelinesAcronym();
if ( OPENAIRE_DATA_REGEX.matcher(guidelinesAcronym).matches() )
key = Constants.VALIDATION_MODE_DATA;
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0$") || ruleSet.getGuidelinesAcronym().equals("driver"))
else if ( OPENAIRE_OR_DRIVER_REGEX.matcher(guidelinesAcronym).matches() )
key = Constants.VALIDATION_MODE_LITERATURE;
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_cris$"))
else if ( OPENAIRE_CRIS_REGEX.matcher(guidelinesAcronym).matches() )
key = Constants.VALIDATION_MODE_CRIS;
else if (ruleSet.getGuidelinesAcronym().matches(".*fair$"))
else if ( FAIR_REGEX.matcher(guidelinesAcronym).matches() )
key = Constants.VALIDATION_MODE_FAIR;
if (rulesetMap.containsKey(key))
@ -140,7 +148,7 @@ public class ValidatorServiceImpl implements ValidatorService {
/////////////////////////////////////////////////////////////////////////////////////////
if (jobForValidation.getSelectedContentRules()!=null && jobForValidation.getSelectedContentRules().size() == 1 &&
jobForValidation.getSelectedContentRules().contains(-1000)
|| jobForValidation.getDesiredCompatibilityLevel().matches("openaire-cris_1.1")) {
|| jobForValidation.getDesiredCompatibilityLevel().equals("openaire-cris_1.1")) {
crisValidatorExecutor.submit(jobForValidation.getBaseUrl(), jobForValidation.getUserEmail());
} else {
this.getValidationService().submitValidationJob(jobForValidation);
@ -194,7 +202,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public List<RuleSet> getRuleSets(String mode) {
logger.info("Getting rulesets for mode: {}", mode);
logger.info("Getting ruleSets for mode: {}", mode);
return rulesetMap.get(mode);
}

View File

@ -7,8 +7,8 @@ import eu.dnetlib.repo.manager.domain.dto.Role;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.service.aai.registry.utils.RegistryUtils;
import eu.dnetlib.repo.manager.utils.HttpUtils;
import org.slf4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -99,11 +99,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;
@ -297,9 +293,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);
});
@ -317,9 +315,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;
@ -336,9 +335,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;
@ -381,7 +381,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
@ -428,8 +432,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 {

View File

@ -2,11 +2,13 @@ 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
@ -15,7 +17,7 @@ import java.util.regex.Pattern;
public class AuthoritiesMapper {
private static final Logger logger = LoggerFactory.getLogger(AuthoritiesMapper.class);
private static final String ENTITLEMENT_REGEX = "urn:geant:openaire[.]eu:group:([^:]*):?(.*)?:role=member#aai[.]openaire[.]eu";
private static final Pattern ENTITLEMENT_REGEX = Pattern.compile("urn:geant:openaire[.]eu:group:([^:]*):?(.*)?:role=member#aai[.]openaire[.]eu");
private AuthoritiesMapper() {
}
@ -26,22 +28,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 = Pattern.compile(ENTITLEMENT_REGEX).matcher(obj.getAsString());
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()));
}
}
}
@ -51,18 +55,20 @@ public class AuthoritiesMapper {
private static void entityRoles(JsonArray entitlements, Set<GrantedAuthority> authorities) {
if (entitlements != null) {
for (JsonElement obj : entitlements) {
Matcher matcher = Pattern.compile(ENTITLEMENT_REGEX).matcher(obj.getAsString());
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()));

View File

@ -1,7 +1,7 @@
package eu.dnetlib.repo.manager.service.security;
import org.slf4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
@ -29,10 +29,10 @@ 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) {
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);

View File

@ -4,9 +4,9 @@ import com.google.gson.JsonElement;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
import org.slf4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.mitre.openid.connect.model.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;

View File

@ -1,15 +1,13 @@
package eu.dnetlib.repo.manager.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.repo.manager.domain.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@ -53,7 +51,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<>();

View File

@ -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);

View File

@ -86,12 +86,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;

View File

@ -1,7 +1,7 @@
package eu.dnetlib.repo.manager.utils;
import org.slf4j.Logger;
import org.dom4j.io.DOMWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import se.kb.oai.pmh.*;
@ -29,7 +29,7 @@ public class OaiTools {
public static List<String> getSetsOfRepo(String baseUrl) throws Exception {
try {
logger.debug("Getting sets of repository " + baseUrl);
logger.debug("Getting sets of repository: {}", baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
SetsList setList = harvester.listSets();
ResumptionToken token = setList.getResumptionToken();
@ -56,7 +56,7 @@ public class OaiTools {
}
public static boolean identifyRepository(String baseUrl) throws Exception {
logger.debug("sending identify request to repo " + baseUrl);
logger.debug("sending identify request to repo: {}", baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl);

View File

@ -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;