develop #1
|
@ -0,0 +1,10 @@
|
||||||
|
# Provide
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
|
## 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**
|
|
@ -1,7 +1,7 @@
|
||||||
# This script can create the local "dnet-repository" and copy the "settings-dnet.xml" file there.
|
# This script can create the local "dnet-repository" and copy the "settings-dnet.xml" file there.
|
||||||
# It also builds the project, using the aforementioned settings file.
|
# It also builds the project, using the aforementioned settings file.
|
||||||
# Then it can run the project locally.
|
# Then it can run the project locally.
|
||||||
# By giving different options, the user can either install and run locally, just install or just run the project.
|
# By giving different options, the user can either install and run locally, just install (arg: 2) or just run (arg: 1) the project.
|
||||||
|
|
||||||
|
|
||||||
# For error-handling, we cannot use the "set -e" since: it has problems https://mywiki.wooledge.org/BashFAQ/105
|
# For error-handling, we cannot use the "set -e" since: it has problems https://mywiki.wooledge.org/BashFAQ/105
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
public class DatasourceConfiguration {
|
public class DatasourceConfiguration {
|
||||||
|
|
||||||
private static Logger LOGGER = Logger.getLogger(DatasourceConfiguration.class);
|
private static Logger logger = Logger.getLogger(DatasourceConfiguration.class);
|
||||||
|
|
||||||
@Value("${services.provide.db.driverClassName}")
|
@Value("${services.provide.db.driverClassName}")
|
||||||
private String driverClassname;
|
private String driverClassname;
|
||||||
|
|
|
@ -22,11 +22,10 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import javax.annotation.PostConstruct;
|
||||||
@EnableRedisHttpSession
|
@EnableRedisHttpSession
|
||||||
public class RedisConfiguration {
|
public class RedisConfiguration {
|
||||||
|
|
||||||
private static Logger LOGGER = Logger.getLogger(RedisConfiguration.class);
|
private static Logger logger = Logger.getLogger(RedisConfiguration.class);
|
||||||
|
|
||||||
@Value("${services.provide.redis.host}")
|
@Value("${services.provide.redis.host}")
|
||||||
private String host;
|
private String host;
|
||||||
|
@ -31,12 +31,12 @@ public class RedisConfiguration {
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void init() {
|
private void init() {
|
||||||
LOGGER.info(String.format("Redis : %s Port : %s Password : %s", host, port, password));
|
logger.info(String.format("Redis : %s Port : %s Password : %s", host, port, password));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JedisConnectionFactory connectionFactory() {
|
public JedisConnectionFactory connectionFactory() {
|
||||||
LOGGER.info(String.format("Redis : %s Port : %s Password : %s", host, port, password));
|
logger.info(String.format("Redis : %s Port : %s Password : %s", host, port, password));
|
||||||
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
|
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
|
||||||
jedisConnectionFactory.setHostName(host);
|
jedisConnectionFactory.setHostName(host);
|
||||||
jedisConnectionFactory.setPort(Integer.parseInt(port));
|
jedisConnectionFactory.setPort(Integer.parseInt(port));
|
||||||
|
@ -51,7 +51,7 @@ public class RedisConfiguration {
|
||||||
serializer.setCookieName("openAIRESession");
|
serializer.setCookieName("openAIRESession");
|
||||||
serializer.setCookiePath("/");
|
serializer.setCookiePath("/");
|
||||||
serializer.setDomainName(domain);
|
serializer.setDomainName(domain);
|
||||||
LOGGER.info("Serializer : " + serializer);
|
logger.info("Serializer : " + serializer);
|
||||||
return serializer;
|
return serializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,7 @@ import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
|
||||||
import eu.dnetlib.repo.manager.domain.UsageSummary;
|
import eu.dnetlib.repo.manager.domain.UsageSummary;
|
||||||
import eu.dnetlib.repo.manager.exception.BrokerException;
|
import eu.dnetlib.repo.manager.exception.BrokerException;
|
||||||
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
||||||
import eu.dnetlib.repo.manager.service.BrokerService;
|
import eu.dnetlib.repo.manager.service.*;
|
||||||
import eu.dnetlib.repo.manager.service.DashboardService;
|
|
||||||
import eu.dnetlib.repo.manager.service.PiWikService;
|
|
||||||
import eu.dnetlib.repo.manager.service.RepositoryService;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
||||||
|
@ -33,6 +30,9 @@ public class DashboardController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RepositoryService repositoryService;
|
private RepositoryService repositoryService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AggregationService aggregationService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private BrokerService brokerService;
|
private BrokerService brokerService;
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ public class DashboardController {
|
||||||
@PathVariable("repoId") String repoId,
|
@PathVariable("repoId") String repoId,
|
||||||
@RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException {
|
@RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException {
|
||||||
|
|
||||||
List<AggregationInfo> aggregationInfo = repositoryService.getRepositoryAggregations(repoId, 0, size);
|
List<AggregationInfo> aggregationInfo = aggregationService.getRepositoryAggregations(repoId, 0, size);
|
||||||
CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary();
|
CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary();
|
||||||
collectionMonitorSummary.setAggregationInfo(aggregationInfo);
|
collectionMonitorSummary.setAggregationInfo(aggregationInfo);
|
||||||
size = 0;
|
size = 0;
|
||||||
do {
|
do {
|
||||||
aggregationInfo = repositoryService.getRepositoryAggregations(repoId, size, size + 50);
|
aggregationInfo = aggregationService.getRepositoryAggregations(repoId, size, size + 50);
|
||||||
for (AggregationInfo aggregationDetail : aggregationInfo) {
|
for (AggregationInfo aggregationDetail : aggregationInfo) {
|
||||||
if (aggregationDetail.isIndexedVersion()) {
|
if (aggregationDetail.isIndexedVersion()) {
|
||||||
collectionMonitorSummary.setLastIndexedVersion(aggregationDetail);
|
collectionMonitorSummary.setLastIndexedVersion(aggregationDetail);
|
||||||
|
|
|
@ -20,8 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
@Api(description = "Monitor API", tags = {"monitor"})
|
@Api(description = "Monitor API", tags = {"monitor"})
|
||||||
public class MonitorController {
|
public class MonitorController {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger
|
private static final Logger logger = Logger.getLogger(MonitorController.class);
|
||||||
.getLogger(MonitorController.class);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MonitorServiceImpl monitorService;
|
private MonitorServiceImpl monitorService;
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -121,7 +120,7 @@ public class PiWikController {
|
||||||
writer.write(sb.toString());
|
writer.write(sb.toString());
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
LOGGER.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import java.io.File;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/actuator/prometheus")
|
@RequestMapping("/actuator/prometheus")
|
||||||
public class PrometheusController { // TODO: remove this with migration to Spring Boot 2
|
public class PrometheusController { // TODO: remove this with migration to Spring Boot 2
|
||||||
private static final Logger LOGGER = Logger.getLogger(PrometheusController.class);
|
private static final Logger logger = Logger.getLogger(PrometheusController.class);
|
||||||
|
|
||||||
private final PiWikService piWikService;
|
private final PiWikService piWikService;
|
||||||
private final RepositoryService repositoryService;
|
private final RepositoryService repositoryService;
|
||||||
|
@ -52,7 +52,7 @@ public class PrometheusController { // TODO: remove this with migration to Sprin
|
||||||
try (JvmGcMetrics jvmGcMetrics = new JvmGcMetrics() ) {
|
try (JvmGcMetrics jvmGcMetrics = new JvmGcMetrics() ) {
|
||||||
jvmGcMetrics.bindTo(registry);
|
jvmGcMetrics.bindTo(registry);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
new JvmMemoryMetrics().bindTo(registry);
|
new JvmMemoryMetrics().bindTo(registry);
|
||||||
new DiskSpaceMetrics(new File("/")).bindTo(registry);
|
new DiskSpaceMetrics(new File("/")).bindTo(registry);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import eu.dnetlib.repo.manager.domain.dto.RepositoryTerms;
|
||||||
import eu.dnetlib.repo.manager.domain.dto.User;
|
import eu.dnetlib.repo.manager.domain.dto.User;
|
||||||
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
||||||
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
||||||
|
import eu.dnetlib.repo.manager.service.AggregationService;
|
||||||
import eu.dnetlib.repo.manager.service.RepositoryService;
|
import eu.dnetlib.repo.manager.service.RepositoryService;
|
||||||
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
|
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
|
||||||
import eu.dnetlib.repo.manager.utils.JsonUtils;
|
import eu.dnetlib.repo.manager.utils.JsonUtils;
|
||||||
|
@ -37,12 +38,16 @@ public class RepositoryController {
|
||||||
private static final Logger logger = Logger.getLogger(RepositoryController.class);
|
private static final Logger logger = Logger.getLogger(RepositoryController.class);
|
||||||
|
|
||||||
private final RepositoryService repositoryService;
|
private final RepositoryService repositoryService;
|
||||||
|
|
||||||
|
private final AggregationService aggregationService;
|
||||||
|
|
||||||
private final AuthorizationService authorizationService;
|
private final AuthorizationService authorizationService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RepositoryController(RepositoryService repositoryService,
|
RepositoryController(RepositoryService repositoryService,
|
||||||
AuthorizationService authorizationService) {
|
AggregationService aggregationService, AuthorizationService authorizationService) {
|
||||||
this.repositoryService = repositoryService;
|
this.repositoryService = repositoryService;
|
||||||
|
this.aggregationService = aggregationService;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,14 +126,14 @@ public class RepositoryController {
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<AggregationInfo> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
|
public List<AggregationInfo> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
|
||||||
return repositoryService.getRepositoryAggregations(id, 0, 20);
|
return aggregationService.getRepositoryAggregations(id, 0, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/getRepositoryAggregationsByYear/{id}", method = RequestMethod.GET,
|
@RequestMapping(value = "/getRepositoryAggregationsByYear/{id}", method = RequestMethod.GET,
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Map<String, List<AggregationInfo>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException {
|
public Map<String, List<AggregationInfo>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException {
|
||||||
return repositoryService.getRepositoryAggregationsByYear(id);
|
return aggregationService.getRepositoryAggregationsByYear(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/getRepositoriesByName/{name:.+}/{page}/{size}/", method = RequestMethod.GET,
|
@RequestMapping(value = "/getRepositoriesByName/{name:.+}/{page}/{size}/", method = RequestMethod.GET,
|
||||||
|
|
|
@ -16,19 +16,17 @@ public class RestTemplateResponseErrorHandler implements ResponseErrorHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasError(ClientHttpResponse httpResponse) throws IOException {
|
public boolean hasError(ClientHttpResponse httpResponse) throws IOException {
|
||||||
return (httpResponse.getStatusCode().series() == CLIENT_ERROR
|
HttpStatus.Series seriesError = httpResponse.getStatusCode().series();
|
||||||
|| httpResponse.getStatusCode().series() == SERVER_ERROR);
|
return ( (seriesError == CLIENT_ERROR) || (seriesError == SERVER_ERROR) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleError(ClientHttpResponse httpResponse) throws IOException {
|
public void handleError(ClientHttpResponse httpResponse) throws IOException {
|
||||||
|
|
||||||
if (httpResponse.getStatusCode().series() == HttpStatus.Series.SERVER_ERROR) {
|
HttpStatus statusCode = httpResponse.getStatusCode();
|
||||||
|
if ( statusCode == HttpStatus.NOT_FOUND )
|
||||||
|
throw new IOException();
|
||||||
|
else if (statusCode.series() == SERVER_ERROR)
|
||||||
throw new EndPointException();
|
throw new EndPointException();
|
||||||
} else if (httpResponse.getStatusCode().series() == HttpStatus.Series.CLIENT_ERROR) {
|
|
||||||
if (httpResponse.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package eu.dnetlib.repo.manager.service;
|
||||||
|
|
||||||
|
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface AggregationService {
|
||||||
|
|
||||||
|
<T extends AggregationInfo> List<T> getRepositoryAggregations(String id) throws JSONException;
|
||||||
|
|
||||||
|
<T extends AggregationInfo> List<T> getRepositoryAggregations(String id, int from, int size) throws JSONException;
|
||||||
|
|
||||||
|
<T extends AggregationInfo> Map<String, List<T>> getRepositoryAggregationsByYear(String id) throws JSONException;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static eu.dnetlib.repo.manager.utils.DateUtils.getYear;
|
||||||
|
|
||||||
|
@Service("aggregationService")
|
||||||
|
public class AggregationServiceImpl implements AggregationService {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(AggregationServiceImpl.class);
|
||||||
|
|
||||||
|
|
||||||
|
@Value("${services.provide.clients.dsm}")
|
||||||
|
private String baseAddress;
|
||||||
|
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
|
||||||
|
public AggregationServiceImpl(RestTemplate restTemplate) {
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T extends AggregationInfo> List<T> getRepositoryAggregations(String id) {
|
||||||
|
|
||||||
|
logger.debug("Retrieving aggregations for repository with id : " + id);
|
||||||
|
UriComponents uriComponents = getAggregationHistory(id);
|
||||||
|
|
||||||
|
AggregationHistoryResponse rs = restTemplate.getForObject(uriComponents.toUri(), AggregationHistoryResponse.class);
|
||||||
|
|
||||||
|
return rs != null ? (List<T>) rs.getAggregationInfo() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T extends AggregationInfo> List<T> getRepositoryAggregations(String id, int from, int size) {
|
||||||
|
|
||||||
|
List<T> res = getRepositoryAggregations(id);
|
||||||
|
|
||||||
|
return res.subList(from, Math.min(from + size, res.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T extends AggregationInfo> Map<String, List<T>> getRepositoryAggregationsByYear(String id) {
|
||||||
|
logger.debug("Retrieving aggregations (by year) for repository with id : " + id);
|
||||||
|
|
||||||
|
List<T> aggregationHistory = getRepositoryAggregations(id);
|
||||||
|
|
||||||
|
return aggregationHistory.isEmpty() ? new HashMap<>() : createYearMap(aggregationHistory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends AggregationInfo> Map<String, List<T>> createYearMap(List<T> aggregationHistory) {
|
||||||
|
|
||||||
|
aggregationHistory = aggregationHistory.stream()
|
||||||
|
.sorted(Comparator.comparing(AggregationInfo::getDate).reversed())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return aggregationHistory.stream()
|
||||||
|
.collect(Collectors.groupingBy(item -> getYear(item.getDate())));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private UriComponents getAggregationHistory(String repoId) {
|
||||||
|
return UriComponentsBuilder
|
||||||
|
.fromHttpUrl(baseAddress + "/ds/aggregationhistory/")
|
||||||
|
.path(repoId)
|
||||||
|
.build().expand(repoId).encode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -40,8 +40,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
@Value("${services.provide.topic_types.url}")
|
@Value("${services.provide.topic_types.url}")
|
||||||
private String topicsURL;
|
private String topicsURL;
|
||||||
|
|
||||||
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
|
private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(BrokerServiceImpl.class);
|
||||||
.getLogger(BrokerServiceImpl.class);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RestTemplate restTemplate;
|
RestTemplate restTemplate;
|
||||||
|
@ -56,14 +55,14 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
httpHeaders = new HttpHeaders();
|
httpHeaders = new HttpHeaders();
|
||||||
httpHeaders.set("Content-Type", "application/json");
|
httpHeaders.set("Content-Type", "application/json");
|
||||||
|
|
||||||
LOGGER.debug("Init dnet topics!");
|
logger.debug("Init dnet topics!");
|
||||||
try (InputStream is = new URL(topicsURL).openStream()) {
|
try (InputStream is = new URL(topicsURL).openStream()) {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JsonNode root = mapper.readTree(is);
|
JsonNode root = mapper.readTree(is);
|
||||||
for (JsonNode term : root.path("terms"))
|
for (JsonNode term : root.path("terms"))
|
||||||
topics.put(term.path("code").textValue(), parseTerm(term));
|
topics.put(term.path("code").textValue(), parseTerm(term));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("Exception on initDnetTopicsMap", e);
|
logger.error("Exception on initDnetTopicsMap", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +88,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
// ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
|
// ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
|
||||||
// }
|
// }
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Exception on getDatasourcesOfUser", e);
|
logger.error("Exception on getDatasourcesOfUser", e);
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
System.out.println("Getting datasources of user in " + (end - start) + "ms");
|
System.out.println("Getting datasources of user in " + (end - start) + "ms");
|
||||||
|
@ -213,7 +212,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
|
||||||
.queryParam("email", userEmail);
|
.queryParam("email", userEmail);
|
||||||
|
|
||||||
LOGGER.debug(builder.build().encode().toUri());
|
logger.debug(builder.build().encode().toUri());
|
||||||
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
|
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
|
||||||
try {
|
try {
|
||||||
resp = restTemplate.exchange(
|
resp = restTemplate.exchange(
|
||||||
|
|
|
@ -23,6 +23,9 @@ public class DashboardServiceImpl implements DashboardService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RepositoryService repositoryService;
|
private RepositoryService repositoryService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AggregationService aggregationService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private BrokerService brokerService;
|
private BrokerService brokerService;
|
||||||
|
|
||||||
|
@ -34,7 +37,6 @@ public class DashboardServiceImpl implements DashboardService {
|
||||||
List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>();
|
List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
List<RepositorySnippet> repositoriesOfUser = repositoryService.getRepositoriesSnippetsOfUser(userEmail, page, size);
|
List<RepositorySnippet> repositoriesOfUser = repositoryService.getRepositoriesSnippetsOfUser(userEmail, page, size);
|
||||||
for (RepositorySnippet repository : repositoriesOfUser) {
|
for (RepositorySnippet repository : repositoriesOfUser) {
|
||||||
RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo();
|
RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo();
|
||||||
|
@ -44,7 +46,7 @@ public class DashboardServiceImpl implements DashboardService {
|
||||||
|
|
||||||
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
|
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
List<AggregationInfo> aggregationInfoList = repositoryService.getRepositoryAggregations(repository.getId(), 0, 20);
|
List<AggregationInfo> aggregationInfoList = aggregationService.getRepositoryAggregations(repository.getId(), 0, 20);
|
||||||
for (AggregationInfo aggregationInfo : aggregationInfoList) {
|
for (AggregationInfo aggregationInfo : aggregationInfoList) {
|
||||||
if (aggregationInfo.isIndexedVersion()) {
|
if (aggregationInfo.isIndexedVersion()) {
|
||||||
repositorySummaryInfo.setRecordsCollected(aggregationInfo.getNumberOfRecords());
|
repositorySummaryInfo.setRecordsCollected(aggregationInfo.getNumberOfRecords());
|
||||||
|
@ -53,35 +55,28 @@ public class DashboardServiceImpl implements DashboardService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
|
|
||||||
System.out.println("Got repo aggregations in " + (end - start) + "ms");
|
System.out.println("Got repo aggregations in " + (end - start) + "ms");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId());
|
MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId());
|
||||||
repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads());
|
repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads());
|
||||||
repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews());
|
repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews());
|
||||||
|
|
||||||
} catch (RepositoryServiceException e) {
|
} catch (RepositoryServiceException e) {
|
||||||
logger.error("Exception getting metrics info for repository: " + repository.getId(), e);
|
logger.error("Exception getting metrics info for repository: " + repository.getId(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
List<BrowseEntry> events = brokerService.getTopicsForDatasource(repository.getOfficialname());
|
List<BrowseEntry> events = brokerService.getTopicsForDatasource(repository.getOfficialname());
|
||||||
Long totalEvents = 0L;
|
Long totalEvents = 0L;
|
||||||
for (BrowseEntry browseEntry : events)
|
for (BrowseEntry browseEntry : events)
|
||||||
totalEvents += browseEntry.getSize();
|
totalEvents += browseEntry.getSize();
|
||||||
repositorySummaryInfo.setEnrichmentEvents(totalEvents);
|
repositorySummaryInfo.setEnrichmentEvents(totalEvents);
|
||||||
|
|
||||||
|
|
||||||
} catch (BrokerException e) {
|
} catch (BrokerException e) {
|
||||||
logger.error("Exception getting broker events for repository: " + repository.getId(), e);
|
logger.error("Exception getting broker events for repository: " + repository.getId(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
repositorySummaryInfoList.add(repositorySummaryInfo);
|
repositorySummaryInfoList.add(repositorySummaryInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Something baad happened!", e);
|
logger.error("Something baad happened!", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.util.stream.Collectors;
|
||||||
@Component("emailUtils")
|
@Component("emailUtils")
|
||||||
public class EmailUtilsImpl implements EmailUtils {
|
public class EmailUtilsImpl implements EmailUtils {
|
||||||
|
|
||||||
private final static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class);
|
private final static Logger logger = Logger.getLogger(EmailUtilsImpl.class);
|
||||||
|
|
||||||
private final MailLibrary mailLibrary;
|
private final MailLibrary mailLibrary;
|
||||||
private final RepositoryService repositoryService;
|
private final RepositoryService repositoryService;
|
||||||
|
@ -65,7 +65,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.usageStatsAdminEmail, subject, message);
|
this.sendMail(this.usageStatsAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e);
|
logger.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(piwikInfo.getRequestorEmail(), subject, message);
|
this.sendMail(piwikInfo.getRequestorEmail(), subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e);
|
logger.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.usageStatsAdminEmail, subject, message);
|
this.sendMail(this.usageStatsAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e);
|
logger.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(piwikInfo.getRequestorEmail(), subject, message);
|
this.sendMail(piwikInfo.getRequestorEmail(), subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e);
|
logger.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.provideAdminEmail, subject, message);
|
this.sendMail(this.provideAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to the administrator", e);
|
logger.error("Error while sending registration notification email to the administrator", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(repository.getRegisteredby(), subject, message);
|
this.sendMail(repository.getRegisteredby(), subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.provideAdminEmail, subject, message);
|
this.sendMail(this.provideAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration of interface notification email to the administrator", e);
|
logger.error("Error while sending registration of interface notification email to the administrator", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(repository.getRegisteredby(), subject, message);
|
this.sendMail(repository.getRegisteredby(), subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredby(), e);
|
logger.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredby(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(repository.getRegisteredby(), subject, message);
|
this.sendMail(repository.getRegisteredby(), subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.provideAdminEmail, subject, message);
|
this.sendMail(this.provideAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(repository.getRegisteredby(), subject, message);
|
this.sendMail(repository.getRegisteredby(), subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.provideAdminEmail, subject, message);
|
this.sendMail(this.provideAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -414,7 +414,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(issuer, subject, message);
|
this.sendMail(issuer, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to the administrator", e);
|
logger.error("Error while sending registration notification email to the administrator", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,7 +443,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.provideAdminEmail, subject, message);
|
this.sendMail(this.provideAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to the administrator", e);
|
logger.error("Error while sending registration notification email to the administrator", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -473,7 +473,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(issuer, subject, message);
|
this.sendMail(issuer, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -504,7 +504,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.provideAdminEmail, subject, message);
|
this.sendMail(this.provideAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -524,7 +524,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(issuer, subject, message);
|
this.sendMail(issuer, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
|
logger.error("Error while sending validation submission notification email to user: " + issuer, e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -545,7 +545,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.provideAdminEmail, subject, message);
|
this.sendMail(this.provideAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
|
logger.error("Error while sending validation submission notification email to user: " + issuer, e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -563,7 +563,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.provideAdminEmail, subject, message);
|
this.sendMail(this.provideAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
|
logger.error("Error while sending validation submission notification email to user: " + issuer, e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -583,7 +583,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.provideAdminEmail, subject, message);
|
this.sendMail(this.provideAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to the administrator", e);
|
logger.error("Error while sending registration notification email to the administrator", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -604,7 +604,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(repository.getRegisteredby(), subject, message);
|
this.sendMail(repository.getRegisteredby(), subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -635,7 +635,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(this.provideAdminEmail, subject, message);
|
this.sendMail(this.provideAdminEmail, subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to the administrator", e);
|
logger.error("Error while sending registration notification email to the administrator", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -666,7 +666,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(repository.getRegisteredby(), subject, message);
|
this.sendMail(repository.getRegisteredby(), subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -686,7 +686,7 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
this.sendMail(jobForValidation.getUserEmail(), subject, message);
|
this.sendMail(jobForValidation.getUserEmail(), subject, message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e);
|
logger.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -742,10 +742,10 @@ public class EmailUtilsImpl implements EmailUtils {
|
||||||
|
|
||||||
public void sendMail(List<String> recipients, String subject, String message) throws Exception {
|
public void sendMail(List<String> recipients, String subject, String message) throws Exception {
|
||||||
try {
|
try {
|
||||||
LOGGER.debug("Sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message);
|
logger.debug("Sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message);
|
||||||
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);
|
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message, e);
|
logger.error("Error sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message, e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ import java.util.stream.Collectors;
|
||||||
@Service("monitorService")
|
@Service("monitorService")
|
||||||
public class MonitorServiceImpl implements MonitorService {
|
public class MonitorServiceImpl implements MonitorService {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(MonitorServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MapJobDao crisJobs;
|
private MapJobDao crisJobs;
|
||||||
|
|
||||||
|
@ -41,9 +43,6 @@ public class MonitorServiceImpl implements MonitorService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger
|
|
||||||
.getLogger(MonitorServiceImpl.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JobsOfUser getJobsOfUser(String user,
|
public JobsOfUser getJobsOfUser(String user,
|
||||||
String jobType,
|
String jobType,
|
||||||
|
@ -54,8 +53,8 @@ public class MonitorServiceImpl implements MonitorService {
|
||||||
String validationStatus,
|
String validationStatus,
|
||||||
String includeJobsTotal) throws JSONException, ValidatorServiceException {
|
String includeJobsTotal) throws JSONException, ValidatorServiceException {
|
||||||
|
|
||||||
LOGGER.debug("Getting jobs of user : " + user);
|
logger.debug("Getting jobs of user : " + user
|
||||||
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
|
+ "\n" + user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
|
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
|
||||||
|
@ -154,7 +153,7 @@ public class MonitorServiceImpl implements MonitorService {
|
||||||
public int getJobsOfUserPerValidationStatus(String user,
|
public int getJobsOfUserPerValidationStatus(String user,
|
||||||
String jobType,
|
String jobType,
|
||||||
String validationStatus) throws JSONException {
|
String validationStatus) throws JSONException {
|
||||||
LOGGER.debug("Getting job with validation status : " + validationStatus);
|
logger.debug("Getting job with validation status : " + validationStatus);
|
||||||
|
|
||||||
if (jobType.equalsIgnoreCase("cris")) {
|
if (jobType.equalsIgnoreCase("cris")) {
|
||||||
return crisJobs.getJobs(user, validationStatus).size();
|
return crisJobs.getJobs(user, validationStatus).size();
|
||||||
|
@ -163,7 +162,7 @@ public class MonitorServiceImpl implements MonitorService {
|
||||||
try {
|
try {
|
||||||
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
||||||
} catch (ValidatorServiceException e) {
|
} catch (ValidatorServiceException e) {
|
||||||
LOGGER.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -171,12 +170,12 @@ public class MonitorServiceImpl implements MonitorService {
|
||||||
@Override
|
@Override
|
||||||
public StoredJob getJobSummary(String jobId,
|
public StoredJob getJobSummary(String jobId,
|
||||||
String groupBy) throws JSONException {
|
String groupBy) throws JSONException {
|
||||||
LOGGER.debug("Getting job summary with id : " + jobId);
|
logger.debug("Getting job summary with id : " + jobId);
|
||||||
StoredJob job = null;
|
StoredJob job = null;
|
||||||
try {
|
try {
|
||||||
job = getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
|
job = getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
|
||||||
} catch (ValidatorServiceException e) {
|
} catch (ValidatorServiceException e) {
|
||||||
LOGGER.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
|
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
|
||||||
|
|
|
@ -32,6 +32,9 @@ import java.util.Map;
|
||||||
@Service("piwikService")
|
@Service("piwikService")
|
||||||
public class PiWikServiceImpl implements PiWikService {
|
public class PiWikServiceImpl implements PiWikService {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(PiWikServiceImpl.class);
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
@ -47,8 +50,6 @@ public class PiWikServiceImpl implements PiWikService {
|
||||||
@Qualifier("emailUtils")
|
@Qualifier("emailUtils")
|
||||||
private EmailUtils emailUtils;
|
private EmailUtils emailUtils;
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger
|
|
||||||
.getLogger(PiWikServiceImpl.class);
|
|
||||||
|
|
||||||
private final static String GET_PIWIK_SITE = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site where repositoryid = ?;";
|
private final static String GET_PIWIK_SITE = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site where repositoryid = ?;";
|
||||||
|
|
||||||
|
@ -168,10 +169,10 @@ public class PiWikServiceImpl implements PiWikService {
|
||||||
emailUtils.sendUserMetricsEnabled(piwikInfo);
|
emailUtils.sendUserMetricsEnabled(piwikInfo);
|
||||||
|
|
||||||
} catch (EmptyResultDataAccessException e) {
|
} catch (EmptyResultDataAccessException e) {
|
||||||
LOGGER.error("Error while approving piwik site: ", e);
|
logger.error("Error while approving piwik site: ", e);
|
||||||
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending email to administrator or user about the enabling of metrics", e);
|
logger.error("Error while sending email to administrator or user about the enabling of metrics", e);
|
||||||
throw new RepositoryServiceException(e, RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
throw new RepositoryServiceException(e, RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>("OK", HttpStatus.OK);
|
return new ResponseEntity<>("OK", HttpStatus.OK);
|
||||||
|
@ -202,13 +203,13 @@ public class PiWikServiceImpl implements PiWikService {
|
||||||
emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo);
|
emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo);
|
||||||
emailUtils.sendUserRequestToEnableMetrics(piwikInfo);
|
emailUtils.sendUserRequestToEnableMetrics(piwikInfo);
|
||||||
} catch (UnsupportedEncodingException uee) {
|
} catch (UnsupportedEncodingException uee) {
|
||||||
LOGGER.error("Error while creating piwikScript URL", uee);
|
logger.error("Error while creating piwikScript URL", uee);
|
||||||
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
LOGGER.error("Error while creating piwik site", ioe);
|
logger.error("Error while creating piwik site", ioe);
|
||||||
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while sending email to administrator or user about the request to enable metrics", e);
|
logger.error("Error while sending email to administrator or user about the request to enable metrics", e);
|
||||||
throw new RepositoryServiceException(e, RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
throw new RepositoryServiceException(e, RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
||||||
}
|
}
|
||||||
return piwikInfo;
|
return piwikInfo;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package eu.dnetlib.repo.manager.service;
|
package eu.dnetlib.repo.manager.service;
|
||||||
|
|
||||||
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
|
|
||||||
import eu.dnetlib.repo.manager.domain.*;
|
import eu.dnetlib.repo.manager.domain.*;
|
||||||
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
||||||
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
||||||
|
@ -43,12 +42,6 @@ public interface RepositoryService {
|
||||||
|
|
||||||
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
|
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
|
||||||
|
|
||||||
<T extends AggregationInfo> List<T> getRepositoryAggregations(String id) throws JSONException;
|
|
||||||
|
|
||||||
<T extends AggregationInfo> List<T> getRepositoryAggregations(String id, int from, int size) throws JSONException;
|
|
||||||
|
|
||||||
<T extends AggregationInfo> Map<String, List<T>> getRepositoryAggregationsByYear(String id) throws JSONException;
|
|
||||||
|
|
||||||
List<Repository> getRepositoriesByName(String name,
|
List<Repository> getRepositoriesByName(String name,
|
||||||
String page,
|
String page,
|
||||||
String size) throws JSONException;
|
String size) throws JSONException;
|
||||||
|
|
|
@ -11,7 +11,6 @@ import com.google.gson.JsonObject;
|
||||||
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
||||||
import eu.dnetlib.domain.enabling.Vocabulary;
|
import eu.dnetlib.domain.enabling.Vocabulary;
|
||||||
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
||||||
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
|
|
||||||
import eu.dnetlib.repo.manager.domain.*;
|
import eu.dnetlib.repo.manager.domain.*;
|
||||||
import eu.dnetlib.repo.manager.domain.broker.BrowseEntry;
|
import eu.dnetlib.repo.manager.domain.broker.BrowseEntry;
|
||||||
import eu.dnetlib.repo.manager.domain.dto.Role;
|
import eu.dnetlib.repo.manager.domain.dto.Role;
|
||||||
|
@ -51,14 +50,11 @@ import java.io.IOException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static eu.dnetlib.repo.manager.utils.DateUtils.getYear;
|
|
||||||
|
|
||||||
@Service("repositoryService")
|
@Service("repositoryService")
|
||||||
public class RepositoryServiceImpl implements RepositoryService {
|
public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RepositoryServiceImpl.class);
|
private static final Logger logger = Logger.getLogger(RepositoryServiceImpl.class);
|
||||||
|
|
||||||
private final AuthorizationService authorizationService;
|
private final AuthorizationService authorizationService;
|
||||||
private final RoleMappingService roleMappingService;
|
private final RoleMappingService roleMappingService;
|
||||||
|
@ -122,8 +118,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void init() {
|
private void init() {
|
||||||
LOGGER.debug("Initialization method of repository api!");
|
logger.debug("Initialization method of repository api! Updated version!");
|
||||||
LOGGER.debug("Updated version!");
|
|
||||||
|
|
||||||
for (String key : this.getVocabulary("dnet:datasource_typologies").getAsMap().keySet()) {
|
for (String key : this.getVocabulary("dnet:datasource_typologies").getAsMap().keySet()) {
|
||||||
if (key.contains("aggregator")) {
|
if (key.contains("aggregator")) {
|
||||||
|
@ -184,7 +179,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
@Override
|
@Override
|
||||||
public List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException {
|
public List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException {
|
||||||
List<Repository> repos = new ArrayList<>();
|
List<Repository> repos = new ArrayList<>();
|
||||||
LOGGER.debug("Retrieving repositories with ids : " + String.join(", ", ids));
|
logger.debug("Retrieving repositories with ids : " + String.join(", ", ids));
|
||||||
UriComponents uriComponents = searchDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
UriComponents uriComponents = searchDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
||||||
RequestFilter requestFilter = new RequestFilter();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
|
|
||||||
|
@ -229,11 +224,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.debug("Exception on getRepositoriesSnippetOfUser", e);
|
logger.debug("Exception on getRepositoriesSnippetOfUser", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.debug("resultSet:" + resultSet);
|
logger.debug("resultSet:" + resultSet);
|
||||||
resultSet.parallelStream().forEach(repositorySnippet -> {
|
resultSet.parallelStream().forEach(repositorySnippet -> {
|
||||||
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
|
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
|
||||||
});
|
});
|
||||||
|
@ -246,7 +241,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
String mode,
|
String mode,
|
||||||
Boolean managed) throws JSONException, IOException {
|
Boolean managed) throws JSONException, IOException {
|
||||||
|
|
||||||
LOGGER.debug("Getting repositories by country!");
|
logger.debug("Getting repositories by country!");
|
||||||
int page = 0;
|
int page = 0;
|
||||||
int size = 100;
|
int size = 100;
|
||||||
List<RepositorySnippet> resultSet = new ArrayList<>();
|
List<RepositorySnippet> resultSet = new ArrayList<>();
|
||||||
|
@ -259,8 +254,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
filterKey = "CRIS system";
|
filterKey = "CRIS system";
|
||||||
|
|
||||||
|
|
||||||
LOGGER.debug("Country code equals : " + country);
|
logger.debug("Country code equals : " + country + " | Filter mode equals : " + filterKey);
|
||||||
LOGGER.debug("Filter mode equals : " + filterKey);
|
|
||||||
|
|
||||||
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
||||||
RequestFilter requestFilter = new RequestFilter();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
|
@ -284,7 +278,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
|
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
|
||||||
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
|
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
|
||||||
|
|
||||||
LOGGER.debug("Searching registered repositories");
|
logger.debug("Searching registered repositories");
|
||||||
|
|
||||||
Paging<RepositorySnippet> snippets = null;
|
Paging<RepositorySnippet> snippets = null;
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
@ -300,7 +294,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
try {
|
try {
|
||||||
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
||||||
if (rs == null) {
|
if (rs == null) {
|
||||||
LOGGER.error(String.format("DSM response is null : [url=%s]", uriComponents.toUri()));
|
logger.error(String.format("DSM response is null : [url=%s]", uriComponents.toUri()));
|
||||||
} else {
|
} else {
|
||||||
JSONObject response = new JSONObject(rs);
|
JSONObject response = new JSONObject(rs);
|
||||||
JSONArray jsonArray = (JSONArray) response.get("datasourceInfo");
|
JSONArray jsonArray = (JSONArray) response.get("datasourceInfo");
|
||||||
|
@ -312,7 +306,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error searching registered datasources", e);
|
logger.error("Error searching registered datasources", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
return snippets != null ? snippets.getResults() : null; // TODO: return paging when ui is compatible
|
return snippets != null ? snippets.getResults() : null; // TODO: return paging when ui is compatible
|
||||||
|
@ -337,14 +331,14 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
@Override
|
@Override
|
||||||
public List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException {
|
public List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException {
|
||||||
String userEmail = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
|
String userEmail = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
|
||||||
LOGGER.debug("Retrieving repositories of authenticated user : " + userEmail);
|
logger.debug("Retrieving repositories of authenticated user : " + userEmail);
|
||||||
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles());
|
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles());
|
||||||
return getRepositories(new ArrayList<>(repoIds));
|
return getRepositories(new ArrayList<>(repoIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) throws JSONException {
|
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) throws JSONException {
|
||||||
LOGGER.debug("Retrieving repositories of authenticated user : " + userEmail);
|
logger.debug("Retrieving repositories of authenticated user : " + userEmail);
|
||||||
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles(userEmail));
|
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles(userEmail));
|
||||||
return getRepositories(new ArrayList<>(repoIds));
|
return getRepositories(new ArrayList<>(repoIds));
|
||||||
}
|
}
|
||||||
|
@ -376,7 +370,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
@Override
|
@Override
|
||||||
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException {
|
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException {
|
||||||
|
|
||||||
LOGGER.debug("Retrieving repositories with id : " + id);
|
logger.debug("Retrieving repositories with id : " + id);
|
||||||
RepositorySnippet repo;
|
RepositorySnippet repo;
|
||||||
UriComponents uriComponents = searchSnipperDatasource("0", "100");
|
UriComponents uriComponents = searchSnipperDatasource("0", "100");
|
||||||
RequestFilter requestFilter = new RequestFilter();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
|
@ -395,7 +389,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
@Override
|
@Override
|
||||||
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
|
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
|
||||||
|
|
||||||
LOGGER.debug("Retrieving repositories with id : " + id);
|
logger.debug("Retrieving repositories with id : " + id);
|
||||||
Repository repo;
|
Repository repo;
|
||||||
UriComponents uriComponents = searchDatasource("0", "100");
|
UriComponents uriComponents = searchDatasource("0", "100");
|
||||||
RequestFilter requestFilter = new RequestFilter();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
|
@ -418,51 +412,12 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends AggregationInfo> List<T> getRepositoryAggregations(String id) {
|
|
||||||
|
|
||||||
LOGGER.debug("Retrieving aggregations for repository with id : " + id);
|
|
||||||
UriComponents uriComponents = getAggregationHistory(id);
|
|
||||||
|
|
||||||
AggregationHistoryResponse rs = restTemplate.getForObject(uriComponents.toUri(), AggregationHistoryResponse.class);
|
|
||||||
|
|
||||||
return rs != null ? (List<T>) rs.getAggregationInfo() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends AggregationInfo> List<T> getRepositoryAggregations(String id, int from, int size) {
|
|
||||||
|
|
||||||
List<T> res = getRepositoryAggregations(id);
|
|
||||||
|
|
||||||
return res.subList(from, Math.min(from + size, res.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends AggregationInfo> Map<String, List<T>> getRepositoryAggregationsByYear(String id) {
|
|
||||||
LOGGER.debug("Retrieving aggregations (by year) for repository with id : " + id);
|
|
||||||
|
|
||||||
List<T> aggregationHistory = getRepositoryAggregations(id);
|
|
||||||
|
|
||||||
return aggregationHistory.isEmpty() ? new HashMap<>() : createYearMap(aggregationHistory);
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T extends AggregationInfo> Map<String, List<T>> createYearMap(List<T> aggregationHistory) {
|
|
||||||
|
|
||||||
aggregationHistory = aggregationHistory.stream()
|
|
||||||
.sorted(Comparator.comparing(AggregationInfo::getDate).reversed())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
return aggregationHistory.stream()
|
|
||||||
.collect(Collectors.groupingBy(item -> getYear(item.getDate())));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Repository> getRepositoriesByName(String name,
|
public List<Repository> getRepositoriesByName(String name,
|
||||||
String page,
|
String page,
|
||||||
String size) throws JSONException {
|
String size) throws JSONException {
|
||||||
|
|
||||||
LOGGER.debug("Retrieving repositories with official name : " + name);
|
logger.debug("Retrieving repositories with official name : " + name);
|
||||||
UriComponents uriComponents = searchDatasource("0", "100");
|
UriComponents uriComponents = searchDatasource("0", "100");
|
||||||
RequestFilter requestFilter = new RequestFilter();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
requestFilter.setOfficialname(name);
|
requestFilter.setOfficialname(name);
|
||||||
|
@ -485,15 +440,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -504,7 +463,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
@Override
|
@Override
|
||||||
public Repository addRepository(String datatype, Repository repository) throws Exception {
|
public Repository addRepository(String datatype, Repository repository) throws Exception {
|
||||||
|
|
||||||
LOGGER.debug("storing " + datatype + " repository with id: " + repository.getId());
|
logger.debug("storing " + datatype + " repository with id: " + repository.getId());
|
||||||
|
|
||||||
repository.setActivationId(UUID.randomUUID().toString());
|
repository.setActivationId(UUID.randomUUID().toString());
|
||||||
repository.setCollectedfrom("infrastruct_::openaire");
|
repository.setCollectedfrom("infrastruct_::openaire");
|
||||||
|
@ -543,10 +502,10 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
} catch (HttpClientErrorException e) {
|
} catch (HttpClientErrorException e) {
|
||||||
couId = registryCalls.getCouId(newRoleName);
|
couId = registryCalls.getCouId(newRoleName);
|
||||||
if (couId == null) {
|
if (couId == null) {
|
||||||
LOGGER.error(String.format("Could not create role '%s'", newRoleName), e);
|
logger.error(String.format("Could not create role '%s'", newRoleName), e);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(String.format("Could not create role '%s'", newRoleName), e);
|
logger.error(String.format("Could not create role '%s'", newRoleName), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,13 +519,12 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
// Add role to current user authorities
|
// Add role to current user authorities
|
||||||
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(repository.getId()));
|
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(repository.getId()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.debug("Exception on assign role to user during add repository", e);
|
logger.debug("Exception on assign role to user during add repository", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +537,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
// FIXME: problematic
|
// FIXME: problematic
|
||||||
// String json_repository = converter.toJson(repository);
|
// String json_repository = converter.toJson(repository);
|
||||||
// LOGGER.debug("JSON to add(update) -> " + json_repository);
|
// logger.debug("JSON to add(update) -> " + json_repository);
|
||||||
|
|
||||||
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders); // TODO: check if it works (Repository contains extra fields)
|
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 = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
||||||
|
@ -589,10 +547,13 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
emailUtils.sendUserRegistrationEmail(repository, authentication);
|
emailUtils.sendUserRegistrationEmail(repository, authentication);
|
||||||
emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
||||||
} 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;
|
||||||
}
|
}
|
||||||
|
@ -606,21 +567,23 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
// FIXME: problematic
|
// FIXME: problematic
|
||||||
// String json_repository = converter.toJson(repository);
|
// String json_repository = converter.toJson(repository);
|
||||||
// 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 {
|
||||||
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
|
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
|
||||||
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
|
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
|
||||||
} 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;
|
||||||
}
|
}
|
||||||
|
@ -646,10 +609,12 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
emailUtils.sendUserRegistrationEmail(repository, authentication);
|
emailUtils.sendUserRegistrationEmail(repository, authentication);
|
||||||
emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
||||||
} 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 storing repository: " + responseBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -660,7 +625,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
.fromHttpUrl(baseAddress + "/ds/api/")
|
.fromHttpUrl(baseAddress + "/ds/api/")
|
||||||
.path("/{id}")
|
.path("/{id}")
|
||||||
.build().expand(id).encode();
|
.build().expand(id).encode();
|
||||||
LOGGER.debug(uriComponents.toUri());
|
logger.debug(uriComponents.toUri());
|
||||||
restTemplate.delete(uriComponents.toUri());
|
restTemplate.delete(uriComponents.toUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,7 +651,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
|
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
|
||||||
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
|
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOGGER.error("Error sending emails: " + ex);
|
logger.error("Error sending emails: " + ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false);
|
submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false);
|
||||||
|
@ -709,10 +674,10 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
|
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
|
||||||
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
|
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error sending emails: " + e);
|
logger.error("Error sending emails: " + e);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn("Could not send emails", e);
|
logger.warn("Could not send emails", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
submitInterfaceValidation(getRepositoryById(repoId), getAuthenticatedUser().getEmail(), repositoryInterface, true);
|
submitInterfaceValidation(getRepositoryById(repoId), getAuthenticatedUser().getEmail(), repositoryInterface, true);
|
||||||
|
@ -775,7 +740,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
|
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
|
||||||
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
|
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
|
||||||
if (iFace.getAccessSet() == null || iFace.getAccessSet().isEmpty()) {
|
if (iFace.getAccessSet() == null || iFace.getAccessSet().isEmpty()) {
|
||||||
LOGGER.debug("set is empty: " + iFace.getAccessSet());
|
logger.debug("set is empty: " + iFace.getAccessSet());
|
||||||
// iFace.removeAccessSet();
|
// iFace.removeAccessSet();
|
||||||
iFace.setAccessSet("none");
|
iFace.setAccessSet("none");
|
||||||
}
|
}
|
||||||
|
@ -784,7 +749,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getDnetCountries() {
|
public List<String> getDnetCountries() {
|
||||||
LOGGER.debug("Getting dnet-countries!");
|
logger.debug("Getting dnet-countries!");
|
||||||
return converter.readFile("countries.txt");
|
return converter.readFile("countries.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,7 +775,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) {
|
||||||
|
@ -825,7 +791,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getCompatibilityClasses(String mode) {
|
public Map<String, String> getCompatibilityClasses(String mode) {
|
||||||
|
|
||||||
LOGGER.debug("Getting compatibility classes for mode: " + mode);
|
logger.debug("Getting compatibility classes for mode: " + mode);
|
||||||
Map<String, String> retMap = new HashMap<String, String>();
|
Map<String, String> retMap = new HashMap<String, String>();
|
||||||
|
|
||||||
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
|
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
|
||||||
|
@ -860,7 +826,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getDatasourceClasses(String mode) {
|
public Map<String, String> getDatasourceClasses(String mode) {
|
||||||
|
|
||||||
LOGGER.debug("Getting datasource classes for mode: " + mode);
|
logger.debug("Getting datasource classes for mode: " + mode);
|
||||||
|
|
||||||
Map<String, String> retMap = new HashMap<String, String>();
|
Map<String, String> retMap = new HashMap<String, String>();
|
||||||
|
|
||||||
|
@ -921,7 +887,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
return metricsInfo;
|
return metricsInfo;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while getting metrics info for repository: ", e);
|
logger.error("Error while getting metrics info for repository: ", e);
|
||||||
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1019,12 +985,6 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private UriComponents getAggregationHistory(String repoId) {
|
|
||||||
return UriComponentsBuilder
|
|
||||||
.fromHttpUrl(baseAddress + "/ds/aggregationhistory/")
|
|
||||||
.path(repoId)
|
|
||||||
.build().expand(repoId).encode();
|
|
||||||
}
|
|
||||||
|
|
||||||
private UriComponents searchDatasource(String page, String size) {
|
private UriComponents searchDatasource(String page, String size) {
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ import java.util.Objects;
|
||||||
@Service("statsService")
|
@Service("statsService")
|
||||||
public class StatsServiceImpl implements StatsService {
|
public class StatsServiceImpl implements StatsService {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(StatsServiceImpl.class);
|
private static final Logger logger = Logger.getLogger(StatsServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RestTemplate restTemplate;
|
RestTemplate restTemplate;
|
||||||
|
@ -67,10 +67,10 @@ public class StatsServiceImpl implements StatsService {
|
||||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||||
return String.valueOf(metadata.get("total"));
|
return String.valueOf(metadata.get("total"));
|
||||||
} catch ( RestClientException rce ) {
|
} catch ( RestClientException rce ) {
|
||||||
LOGGER.error(rce.getMessage());
|
logger.error(rce.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
LOGGER.error("", e);
|
logger.error("", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,15 +94,15 @@ public class StatsServiceImpl implements StatsService {
|
||||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||||
if ( metadata == null ) {
|
if ( metadata == null ) {
|
||||||
LOGGER.error("The metadata was null!");
|
logger.error("The metadata was null!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return String.valueOf(metadata.get("total"));
|
return String.valueOf(metadata.get("total"));
|
||||||
} catch ( RestClientException rce ) {
|
} catch ( RestClientException rce ) {
|
||||||
LOGGER.error(rce.getMessage());
|
logger.error(rce.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
LOGGER.error("", e);
|
logger.error("", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,15 +127,15 @@ public class StatsServiceImpl implements StatsService {
|
||||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||||
if ( metadata == null ) {
|
if ( metadata == null ) {
|
||||||
LOGGER.error("The metadata was null!");
|
logger.error("The metadata was null!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return String.valueOf(metadata.get("total"));
|
return String.valueOf(metadata.get("total"));
|
||||||
} catch ( RestClientException rce ) {
|
} catch ( RestClientException rce ) {
|
||||||
LOGGER.error(rce.getMessage());
|
logger.error(rce.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
LOGGER.error("", e);
|
logger.error("", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,15 +159,15 @@ public class StatsServiceImpl implements StatsService {
|
||||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||||
if ( metadata == null ) {
|
if ( metadata == null ) {
|
||||||
LOGGER.error("The metadata was null!");
|
logger.error("The metadata was null!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return String.valueOf(metadata.get("total"));
|
return String.valueOf(metadata.get("total"));
|
||||||
} catch ( RestClientException rce ) {
|
} catch ( RestClientException rce ) {
|
||||||
LOGGER.error(rce.getMessage());
|
logger.error(rce.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
LOGGER.error("", e);
|
logger.error("", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,15 +188,15 @@ public class StatsServiceImpl implements StatsService {
|
||||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||||
Map metadata = (Map<?, ?>) rs.getBody();
|
Map metadata = (Map<?, ?>) rs.getBody();
|
||||||
if ( metadata == null ) {
|
if ( metadata == null ) {
|
||||||
LOGGER.error("The metadata was null!");
|
logger.error("The metadata was null!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return String.valueOf(metadata.get("total"));
|
return String.valueOf(metadata.get("total"));
|
||||||
} catch ( RestClientException rce ) {
|
} catch ( RestClientException rce ) {
|
||||||
LOGGER.error(rce.getMessage());
|
logger.error(rce.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
LOGGER.error("", e);
|
logger.error("", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,15 +217,15 @@ public class StatsServiceImpl implements StatsService {
|
||||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||||
Map metadata = (Map<?, ?>) rs.getBody();
|
Map metadata = (Map<?, ?>) rs.getBody();
|
||||||
if ( metadata == null ) {
|
if ( metadata == null ) {
|
||||||
LOGGER.error("The metadata was null!");
|
logger.error("The metadata was null!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return String.valueOf(metadata.get("total"));
|
return String.valueOf(metadata.get("total"));
|
||||||
} catch ( RestClientException rce ) {
|
} catch ( RestClientException rce ) {
|
||||||
LOGGER.error(rce.getMessage());
|
logger.error(rce.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
LOGGER.error("", e);
|
logger.error("", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,15 +246,15 @@ public class StatsServiceImpl implements StatsService {
|
||||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||||
Map metadata = (Map<?, ?>) rs.getBody();
|
Map metadata = (Map<?, ?>) rs.getBody();
|
||||||
if ( metadata == null ) {
|
if ( metadata == null ) {
|
||||||
LOGGER.error("The metadata was null!");
|
logger.error("The metadata was null!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return String.valueOf(metadata.get("total"));
|
return String.valueOf(metadata.get("total"));
|
||||||
} catch ( RestClientException rce ) {
|
} catch ( RestClientException rce ) {
|
||||||
LOGGER.error(rce.getMessage());
|
logger.error(rce.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
LOGGER.error("", e);
|
logger.error("", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,10 +280,10 @@ public class StatsServiceImpl implements StatsService {
|
||||||
usagestats.put("year", year);
|
usagestats.put("year", year);
|
||||||
return usagestats;
|
return usagestats;
|
||||||
} catch ( RestClientException rce ) {
|
} catch ( RestClientException rce ) {
|
||||||
LOGGER.error(rce.getMessage());
|
logger.error(rce.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
LOGGER.error("", e);
|
logger.error("", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ public class StatsServiceImpl implements StatsService {
|
||||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("totals");
|
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("totals");
|
||||||
if ( metadata == null ) {
|
if ( metadata == null ) {
|
||||||
LOGGER.error("The metadata was null!");
|
logger.error("The metadata was null!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,10 +309,10 @@ public class StatsServiceImpl implements StatsService {
|
||||||
|
|
||||||
return (Integer) metadata.get("events");
|
return (Integer) metadata.get("events");
|
||||||
} catch ( RestClientException rce ) {
|
} catch ( RestClientException rce ) {
|
||||||
LOGGER.error(rce.getMessage());
|
logger.error(rce.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
LOGGER.error("", e);
|
logger.error("", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class SushiliteServiceImpl implements SushiliteService {
|
||||||
@Value("${services.provide.usagestats.sushiliteEndpoint}")
|
@Value("${services.provide.usagestats.sushiliteEndpoint}")
|
||||||
private String usagestatsSushiliteEndpoint;
|
private String usagestatsSushiliteEndpoint;
|
||||||
|
|
||||||
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(SushiliteServiceImpl.class);
|
private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(SushiliteServiceImpl.class);
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -85,19 +85,16 @@ public class SushiliteServiceImpl implements SushiliteService {
|
||||||
}
|
}
|
||||||
requestedItemList = resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems().subList(offset,upperIndex);
|
requestedItemList = resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems().subList(offset,upperIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
LOGGER.debug("Exception on getReportResults - trying to cast strings to integers", e);
|
logger.debug("Exception on getReportResults - trying to cast strings to integers", e);
|
||||||
//emailUtils.reportException(e);
|
//emailUtils.reportException(e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportResponseWrapper newReportResponse = resp.getBody();
|
ReportResponseWrapper newReportResponse = resp.getBody();
|
||||||
newReportResponse.getReportResponse().getReportWrapper().getReport().getCustomer().setReportItems(requestedItemList);
|
newReportResponse.getReportResponse().getReportWrapper().getReport().getCustomer().setReportItems(requestedItemList);
|
||||||
|
|
||||||
|
|
||||||
return newReportResponse;
|
return newReportResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -16,21 +16,25 @@ import java.util.stream.Collectors;
|
||||||
@Service("userService")
|
@Service("userService")
|
||||||
public class UserServiceImpl implements UserService {
|
public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
|
private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger
|
||||||
.getLogger(UserServiceImpl.class);
|
.getLogger(UserServiceImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Object> login() {
|
public ResponseEntity<Object> login() {
|
||||||
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||||
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;
|
||||||
|
@ -71,7 +70,7 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void loadRules(){
|
private void loadRules(){
|
||||||
LOGGER.debug("PostConstruct method! Load rules!");
|
logger.debug("PostConstruct method! Load rules!");
|
||||||
try {
|
try {
|
||||||
for (RuleSet ruleSet : getValidationService().getRuleSets()) {
|
for (RuleSet ruleSet : getValidationService().getRuleSets()) {
|
||||||
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) {
|
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) {
|
||||||
|
@ -124,7 +123,7 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||||||
} catch (ValidatorServiceException e) {
|
} catch (ValidatorServiceException e) {
|
||||||
LOGGER.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -132,12 +131,12 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
@Override
|
@Override
|
||||||
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
||||||
public JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException {
|
public JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException {
|
||||||
LOGGER.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId());
|
logger.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId());
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
emailUtils.sendSubmitJobForValidationEmail(SecurityContextHolder.getContext().getAuthentication(), jobForValidation);
|
emailUtils.sendSubmitJobForValidationEmail(SecurityContextHolder.getContext().getAuthentication(), jobForValidation);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error sending email ", e);
|
logger.error("Error sending email ", e);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
|
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
|
||||||
|
@ -154,7 +153,7 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
// this.getValidationService().submitValidationJob(jobForValidation);
|
// this.getValidationService().submitValidationJob(jobForValidation);
|
||||||
} catch (Exception e) { // FIXME: replaced exception with log
|
} catch (Exception e) { // FIXME: replaced exception with log
|
||||||
// throw new ValidatorServiceException(e);
|
// throw new ValidatorServiceException(e);
|
||||||
LOGGER.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return jobForValidation;
|
return jobForValidation;
|
||||||
|
@ -163,7 +162,7 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Object> reSubmitJobForValidation(String email,
|
public ResponseEntity<Object> reSubmitJobForValidation(String email,
|
||||||
String jobId) throws JSONException, ValidatorServiceException {
|
String jobId) throws JSONException, ValidatorServiceException {
|
||||||
LOGGER.debug("Resubmit validation job with id : " + jobId);
|
logger.debug("Resubmit validation job with id : " + jobId);
|
||||||
StoredJob job = monitorApi.getJobSummary(jobId, "all");
|
StoredJob job = monitorApi.getJobSummary(jobId, "all");
|
||||||
Set<Integer> contentRules = new HashSet<Integer>();
|
Set<Integer> contentRules = new HashSet<Integer>();
|
||||||
Set<Integer> usageRules = new HashSet<Integer>();
|
Set<Integer> usageRules = new HashSet<Integer>();
|
||||||
|
@ -198,20 +197,20 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RuleSet> getRuleSets(String mode) {
|
public List<RuleSet> getRuleSets(String mode) {
|
||||||
LOGGER.info("Getting rulesets for mode: " + mode);
|
logger.info("Getting rulesets for mode: " + mode);
|
||||||
return rulesetMap.get(mode);
|
return rulesetMap.get(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getSetsOfRepository(String url) {
|
public List<String> getSetsOfRepository(String url) {
|
||||||
LOGGER.debug("Getting sets of repository with url : " + url);
|
logger.debug("Getting sets of repository with url : " + url);
|
||||||
|
|
||||||
List<String> sets = null;
|
List<String> sets = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sets = OaiTools.getSetsOfRepo(url);
|
sets = OaiTools.getSetsOfRepo(url);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Exception on getSetsOfRepository" , e);
|
logger.error("Exception on getSetsOfRepository" , e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sets;
|
return sets;
|
||||||
|
@ -219,18 +218,18 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean identifyRepo(String url) {
|
public boolean identifyRepo(String url) {
|
||||||
LOGGER.debug("Identify repository with url : " + url);
|
logger.debug("Identify repository with url : " + url);
|
||||||
try {
|
try {
|
||||||
return OaiTools.identifyRepository(url);
|
return OaiTools.identifyRepository(url);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error while identifying repository with url: " + url, e);
|
logger.error("Error while identifying repository with url: " + url, e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RuleSet getRuleSet(String acronym) {
|
public RuleSet getRuleSet(String acronym) {
|
||||||
LOGGER.debug("Getting ruleset with acronym : " + acronym);
|
logger.debug("Getting ruleset with acronym : " + acronym);
|
||||||
RuleSet ruleSet = null;
|
RuleSet ruleSet = null;
|
||||||
try {
|
try {
|
||||||
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
|
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
|
||||||
|
@ -242,7 +241,7 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
}
|
}
|
||||||
return ruleSet;
|
return ruleSet;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error getting ruleset", e);
|
logger.error("Error getting ruleset", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,7 +280,7 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
@Override
|
@Override
|
||||||
public InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException {
|
public InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException {
|
||||||
try {
|
try {
|
||||||
LOGGER.debug("Getting interface information with url: " + baseUrl);
|
logger.debug("Getting interface information with url: " + baseUrl);
|
||||||
InterfaceInformation interfaceInformation = new InterfaceInformation();
|
InterfaceInformation interfaceInformation = new InterfaceInformation();
|
||||||
interfaceInformation.setIdentified(this.identifyRepo(baseUrl));
|
interfaceInformation.setIdentified(this.identifyRepo(baseUrl));
|
||||||
if (interfaceInformation.isIdentified())
|
if (interfaceInformation.isIdentified())
|
||||||
|
@ -289,7 +288,7 @@ public class ValidatorServiceImpl implements ValidatorService {
|
||||||
|
|
||||||
return interfaceInformation;
|
return interfaceInformation;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error getting interface information with url: " + baseUrl, e);
|
logger.error("Error getting interface information with url: " + baseUrl, e);
|
||||||
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
|
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package eu.dnetlib.repo.manager.utils;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
|
|
||||||
import eu.dnetlib.repo.manager.domain.*;
|
import eu.dnetlib.repo.manager.domain.*;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
@ -12,7 +11,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;
|
||||||
|
@ -22,7 +20,7 @@ import java.util.Objects;
|
||||||
@Component
|
@Component
|
||||||
public class Converter {
|
public class Converter {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(Converter.class);
|
private static final Logger logger = Logger.getLogger(Converter.class);
|
||||||
|
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@ -52,15 +50,6 @@ public class Converter {
|
||||||
return resultSet;
|
return resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RepositoryInterface> toRepositoryInterfaceList(JSONObject json) throws JSONException {
|
|
||||||
|
|
||||||
List<RepositoryInterface> resultSet = new ArrayList<>();
|
|
||||||
JSONArray rs = json.getJSONArray("api");
|
|
||||||
for (int i = 0; i < rs.length(); i++)
|
|
||||||
resultSet.add(toRepositoryInterface(rs.getJSONObject(i)));
|
|
||||||
return resultSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<RepositoryInterface> toRepositoryInterfaceList(List<ApiDetails> apiDetailsList) throws JSONException {
|
public List<RepositoryInterface> toRepositoryInterfaceList(List<ApiDetails> apiDetailsList) throws JSONException {
|
||||||
|
|
||||||
List<RepositoryInterface> resultSet = new ArrayList<>();
|
List<RepositoryInterface> resultSet = new ArrayList<>();
|
||||||
|
@ -86,28 +75,16 @@ public class Converter {
|
||||||
String line;
|
String line;
|
||||||
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("/eu/**/" + filename);
|
||||||
InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename);
|
BufferedReader br = new BufferedReader(new InputStreamReader(in)); // It may throw an NPE.
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
|
||||||
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.error("Error opening file!", e);
|
||||||
LOGGER.error(e);
|
|
||||||
}
|
}
|
||||||
return list;
|
return list; // It may be empty.
|
||||||
}
|
|
||||||
|
|
||||||
public List<AggregationInfo> toAggregationHistory(String aggregationHistoryResponse) throws JSONException {
|
|
||||||
List<AggregationInfo> aggregationInfoList = new ArrayList<>();
|
|
||||||
JSONArray aggregationInfo = new JSONObject(aggregationHistoryResponse).getJSONArray("aggregationInfo");
|
|
||||||
|
|
||||||
for (int i = 0; i < aggregationInfo.length(); i++)
|
|
||||||
aggregationInfoList.add(objectMapper.convertValue(aggregationInfo.getJSONObject(i), AggregationInfo.class));
|
|
||||||
|
|
||||||
return aggregationInfoList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Timezone> toTimezones(List<String> timezones) {
|
public List<Timezone> toTimezones(List<String> timezones) {
|
||||||
|
|
|
@ -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);
|
||||||
}};
|
}};
|
||||||
|
|
|
@ -24,16 +24,15 @@ public class OaiTools {
|
||||||
disableSslVerification();
|
disableSslVerification();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Logger LOGGER = Logger.getLogger(OaiTools.class);
|
private static Logger logger = Logger.getLogger(OaiTools.class);
|
||||||
|
|
||||||
public static List<String> getSetsOfRepo(String baseUrl) throws Exception {
|
public static List<String> getSetsOfRepo(String baseUrl) throws Exception {
|
||||||
try {
|
try {
|
||||||
LOGGER.debug("Getting sets of repository " + baseUrl);
|
logger.debug("Getting sets of repository " + baseUrl);
|
||||||
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();
|
||||||
|
@ -49,14 +48,14 @@ public class OaiTools {
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error getting sets of repository " + baseUrl, e);
|
logger.error("Error getting sets of repository " + baseUrl, e);
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
//throw e;
|
//throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean identifyRepository(String baseUrl) throws Exception {
|
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);
|
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
|
||||||
|
|
||||||
|
@ -71,7 +70,7 @@ public class OaiTools {
|
||||||
|
|
||||||
return verifyIdentify(d);
|
return verifyIdentify(d);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.debug("Error verifying identify response", e);
|
logger.debug("Error verifying identify response", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +111,7 @@ public class OaiTools {
|
||||||
private static void disableSslVerification() {
|
private static void disableSslVerification() {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LOGGER.debug("disabling ssl verification");
|
logger.debug("disabling ssl verification");
|
||||||
// Create a trust manager that does not validate certificate chains
|
// Create a trust manager that does not validate certificate chains
|
||||||
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
|
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
|
||||||
public X509Certificate[] getAcceptedIssuers() {
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
@ -140,9 +139,9 @@ public class OaiTools {
|
||||||
// Install the all-trusting host verifier
|
// Install the all-trusting host verifier
|
||||||
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
|
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
LOGGER.error("disabling ssl verification", e);
|
logger.error("disabling ssl verification", e);
|
||||||
} catch (KeyManagementException e) {
|
} catch (KeyManagementException e) {
|
||||||
LOGGER.error("error while disabling ssl verification", e);
|
logger.error("error while disabling ssl verification", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue