merge commit

This commit is contained in:
Konstantinos Spyrou 2022-12-20 20:53:54 +02:00
commit 4850581c53
28 changed files with 328 additions and 295 deletions

10
README.md Normal file
View File

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

View File

@ -1,7 +1,7 @@
# 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.
# 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

View File

@ -12,7 +12,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement
public class DatasourceConfiguration {
private static Logger LOGGER = Logger.getLogger(DatasourceConfiguration.class);
private static Logger logger = Logger.getLogger(DatasourceConfiguration.class);
@Value("${services.provide.db.driverClassName}")
private String driverClassname;

View File

@ -22,11 +22,10 @@ public class FrontEndLinkURIAuthenticationSuccessHandler implements Authenticati
private String frontEndURI;
private static final Logger LOGGER = Logger
.getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class);
private static final Logger logger = Logger.getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class);
public void init() {
LOGGER.debug("Front end uri : " + frontEndURI);
logger.debug("Front end uri : " + frontEndURI);
}

View File

@ -15,7 +15,7 @@ import javax.annotation.PostConstruct;
@EnableRedisHttpSession
public class RedisConfiguration {
private static Logger LOGGER = Logger.getLogger(RedisConfiguration.class);
private static Logger logger = Logger.getLogger(RedisConfiguration.class);
@Value("${services.provide.redis.host}")
private String host;
@ -31,12 +31,12 @@ public class RedisConfiguration {
@PostConstruct
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
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.setHostName(host);
jedisConnectionFactory.setPort(Integer.parseInt(port));
@ -51,7 +51,7 @@ public class RedisConfiguration {
serializer.setCookieName("openAIRESession");
serializer.setCookiePath("/");
serializer.setDomainName(domain);
LOGGER.info("Serializer : " + serializer);
logger.info("Serializer : " + serializer);
return serializer;
}

View File

@ -7,10 +7,7 @@ import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
import eu.dnetlib.repo.manager.domain.UsageSummary;
import eu.dnetlib.repo.manager.exception.BrokerException;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.service.BrokerService;
import eu.dnetlib.repo.manager.service.DashboardService;
import eu.dnetlib.repo.manager.service.PiWikService;
import eu.dnetlib.repo.manager.service.RepositoryService;
import eu.dnetlib.repo.manager.service.*;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
@ -33,6 +30,9 @@ public class DashboardController {
@Autowired
private RepositoryService repositoryService;
@Autowired
private AggregationService aggregationService;
@Autowired
private BrokerService brokerService;
@ -57,12 +57,12 @@ public class DashboardController {
@PathVariable("repoId") String repoId,
@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.setAggregationInfo(aggregationInfo);
size = 0;
do {
aggregationInfo = repositoryService.getRepositoryAggregations(repoId, size, size + 50);
aggregationInfo = aggregationService.getRepositoryAggregations(repoId, size, size + 50);
for (AggregationInfo aggregationDetail : aggregationInfo) {
if (aggregationDetail.isIndexedVersion()) {
collectionMonitorSummary.setLastIndexedVersion(aggregationDetail);

View File

@ -20,8 +20,7 @@ import org.springframework.web.bind.annotation.*;
@Api(description = "Monitor API", tags = {"monitor"})
public class MonitorController {
private static final Logger LOGGER = Logger
.getLogger(MonitorController.class);
private static final Logger logger = Logger.getLogger(MonitorController.class);
@Autowired
private MonitorServiceImpl monitorService;

View File

@ -33,8 +33,7 @@ import java.util.List;
@Api(description = "Piwik API", tags = {"piwik"})
public class PiWikController {
private static final Logger LOGGER = Logger
.getLogger(PiWikController.class);
private static final Logger logger = Logger.getLogger(PiWikController.class);
@Autowired
private PiWikServiceImpl piWikService;
@ -121,7 +120,7 @@ public class PiWikController {
writer.write(sb.toString());
} catch (FileNotFoundException e) {
LOGGER.error(e.getMessage());
logger.error(e.getMessage());
}

View File

@ -24,7 +24,7 @@ import java.io.File;
@RestController
@RequestMapping("/actuator/prometheus")
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 RepositoryService repositoryService;
@ -52,7 +52,7 @@ public class PrometheusController { // TODO: remove this with migration to Sprin
try (JvmGcMetrics jvmGcMetrics = new JvmGcMetrics() ) {
jvmGcMetrics.bindTo(registry);
} catch (Exception e) {
LOGGER.error("", e);
logger.error("", e);
}
new JvmMemoryMetrics().bindTo(registry);
new DiskSpaceMetrics(new File("/")).bindTo(registry);

View File

@ -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.exception.RepositoryServiceException;
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.security.AuthorizationService;
import eu.dnetlib.repo.manager.utils.JsonUtils;
@ -37,12 +38,16 @@ public class RepositoryController {
private static final Logger logger = Logger.getLogger(RepositoryController.class);
private final RepositoryService repositoryService;
private final AggregationService aggregationService;
private final AuthorizationService authorizationService;
@Autowired
RepositoryController(RepositoryService repositoryService,
AuthorizationService authorizationService) {
AggregationService aggregationService, AuthorizationService authorizationService) {
this.repositoryService = repositoryService;
this.aggregationService = aggregationService;
this.authorizationService = authorizationService;
}
@ -121,14 +126,14 @@ public class RepositoryController {
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
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,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
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,

View File

@ -16,19 +16,17 @@ public class RestTemplateResponseErrorHandler implements ResponseErrorHandler {
@Override
public boolean hasError(ClientHttpResponse httpResponse) throws IOException {
return (httpResponse.getStatusCode().series() == CLIENT_ERROR
|| httpResponse.getStatusCode().series() == SERVER_ERROR);
HttpStatus.Series seriesError = httpResponse.getStatusCode().series();
return ( (seriesError == CLIENT_ERROR) || (seriesError == SERVER_ERROR) );
}
@Override
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();
} else if (httpResponse.getStatusCode().series() == HttpStatus.Series.CLIENT_ERROR) {
if (httpResponse.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new IOException();
}
}
}
}

View File

@ -19,8 +19,7 @@ public class StatsController {
@Autowired
private StatsServiceImpl statsService;
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map getStatistics(){
return statsService.getStatistics();

View File

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

View File

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

View File

@ -40,8 +40,7 @@ public class BrokerServiceImpl implements BrokerService {
@Value("${services.provide.topic_types.url}")
private String topicsURL;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
.getLogger(BrokerServiceImpl.class);
private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(BrokerServiceImpl.class);
@Autowired
RestTemplate restTemplate;
@ -56,14 +55,14 @@ public class BrokerServiceImpl implements BrokerService {
httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
LOGGER.debug("Init dnet topics!");
logger.debug("Init dnet topics!");
try (InputStream is = new URL(topicsURL).openStream()) {
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(is);
for (JsonNode term : root.path("terms"))
topics.put(term.path("code").textValue(), parseTerm(term));
} 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)));
// }
} catch (Exception e) {
LOGGER.error("Exception on getDatasourcesOfUser", e);
logger.error("Exception on getDatasourcesOfUser", e);
}
long end = System.currentTimeMillis();
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)
.queryParam("email", userEmail);
LOGGER.debug(builder.build().encode().toUri());
logger.debug(builder.build().encode().toUri());
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
try {
resp = restTemplate.exchange(

View File

@ -23,6 +23,9 @@ public class DashboardServiceImpl implements DashboardService {
@Autowired
private RepositoryService repositoryService;
@Autowired
private AggregationService aggregationService;
@Autowired
private BrokerService brokerService;
@ -34,7 +37,6 @@ public class DashboardServiceImpl implements DashboardService {
List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>();
try {
List<RepositorySnippet> repositoriesOfUser = repositoryService.getRepositoriesSnippetsOfUser(userEmail, page, size);
for (RepositorySnippet repository : repositoriesOfUser) {
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?
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) {
if (aggregationInfo.isIndexedVersion()) {
repositorySummaryInfo.setRecordsCollected(aggregationInfo.getNumberOfRecords());
@ -53,35 +55,28 @@ public class DashboardServiceImpl implements DashboardService {
}
}
long end = System.currentTimeMillis();
System.out.println("Got repo aggregations in " + (end - start) + "ms");
try {
MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId());
repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads());
repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews());
} catch (RepositoryServiceException e) {
logger.error("Exception getting metrics info for repository: " + repository.getId(), e);
}
try {
List<BrowseEntry> events = brokerService.getTopicsForDatasource(repository.getOfficialname());
Long totalEvents = 0L;
for (BrowseEntry browseEntry : events)
totalEvents += browseEntry.getSize();
repositorySummaryInfo.setEnrichmentEvents(totalEvents);
} catch (BrokerException e) {
logger.error("Exception getting broker events for repository: " + repository.getId(), e);
}
repositorySummaryInfoList.add(repositorySummaryInfo);
}
} catch (Exception e) {
logger.error("Something baad happened!", e);
}

View File

@ -21,7 +21,7 @@ import java.util.stream.Collectors;
@Component("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 RepositoryService repositoryService;
@ -65,7 +65,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.usageStatsAdminEmail, subject, message);
} 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;
}
}
@ -102,7 +102,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(piwikInfo.getRequestorEmail(), subject, message);
} 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;
}
}
@ -126,7 +126,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.usageStatsAdminEmail, subject, message);
} 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;
}
}
@ -154,7 +154,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(piwikInfo.getRequestorEmail(), subject, message);
} 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;
}
}
@ -178,7 +178,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} 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;
}
}
@ -201,7 +201,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(repository.getRegisteredby(), subject, message);
} 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;
}
}
@ -234,7 +234,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} 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;
}
}
@ -265,7 +265,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(repository.getRegisteredby(), subject, message);
} 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;
}
}
@ -295,7 +295,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(repository.getRegisteredby(), subject, message);
} 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;
}
}
@ -326,7 +326,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} 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;
}
}
@ -355,7 +355,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(repository.getRegisteredby(), subject, message);
} 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;
}
}
@ -386,7 +386,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} 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;
}
}
@ -414,7 +414,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(issuer, subject, message);
} 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;
}
}
@ -443,7 +443,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} 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;
}
}
@ -473,7 +473,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(issuer, subject, message);
} 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;
}
}
@ -504,7 +504,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} 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;
}
}
@ -524,7 +524,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(issuer, subject, message);
} 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;
}
}
@ -545,7 +545,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} 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;
}
}
@ -563,7 +563,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} 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;
}
}
@ -583,7 +583,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} 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;
}
}
@ -604,7 +604,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(repository.getRegisteredby(), subject, message);
} 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;
}
}
@ -635,7 +635,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} 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;
}
}
@ -666,7 +666,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(repository.getRegisteredby(), subject, message);
} 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;
}
}
@ -686,7 +686,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(jobForValidation.getUserEmail(), subject, message);
} 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;
}
}
@ -742,10 +742,10 @@ public class EmailUtilsImpl implements EmailUtils {
public void sendMail(List<String> recipients, String subject, String message) throws Exception {
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);
} 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;
}
}

View File

@ -22,6 +22,8 @@ import java.util.stream.Collectors;
@Service("monitorService")
public class MonitorServiceImpl implements MonitorService {
private static final Logger logger = Logger.getLogger(MonitorServiceImpl.class);
@Autowired
private MapJobDao crisJobs;
@ -41,9 +43,6 @@ public class MonitorServiceImpl implements MonitorService {
}
private static final Logger LOGGER = Logger
.getLogger(MonitorServiceImpl.class);
@Override
public JobsOfUser getJobsOfUser(String user,
String jobType,
@ -54,8 +53,8 @@ public class MonitorServiceImpl implements MonitorService {
String validationStatus,
String includeJobsTotal) throws JSONException, ValidatorServiceException {
LOGGER.debug("Getting jobs of user : " + user);
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
logger.debug("Getting jobs of user : " + user
+ "\n" + user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
/////////////////////////////////////////////////////////////////////////////////////////
// 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,
String jobType,
String validationStatus) throws JSONException {
LOGGER.debug("Getting job with validation status : " + validationStatus);
logger.debug("Getting job with validation status : " + validationStatus);
if (jobType.equalsIgnoreCase("cris")) {
return crisJobs.getJobs(user, validationStatus).size();
@ -163,7 +162,7 @@ public class MonitorServiceImpl implements MonitorService {
try {
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
} catch (ValidatorServiceException e) {
LOGGER.error(e);
logger.error(e);
}
return 0;
}
@ -171,12 +170,12 @@ public class MonitorServiceImpl implements MonitorService {
@Override
public StoredJob getJobSummary(String jobId,
String groupBy) throws JSONException {
LOGGER.debug("Getting job summary with id : " + jobId);
logger.debug("Getting job summary with id : " + jobId);
StoredJob job = null;
try {
job = getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
} catch (ValidatorServiceException e) {
LOGGER.error(e);
logger.error(e);
}
/////////////////////////////////////////////////////////////////////////////////////////
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //

View File

@ -32,6 +32,9 @@ import java.util.Map;
@Service("piwikService")
public class PiWikServiceImpl implements PiWikService {
private static final Logger logger = Logger.getLogger(PiWikServiceImpl.class);
@Autowired
private DataSource dataSource;
@ -47,8 +50,6 @@ public class PiWikServiceImpl implements PiWikService {
@Qualifier("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 = ?;";
@ -168,10 +169,10 @@ public class PiWikServiceImpl implements PiWikService {
emailUtils.sendUserMetricsEnabled(piwikInfo);
} 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);
} 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);
}
return new ResponseEntity<>("OK", HttpStatus.OK);
@ -202,13 +203,13 @@ public class PiWikServiceImpl implements PiWikService {
emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo);
emailUtils.sendUserRequestToEnableMetrics(piwikInfo);
} 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);
} 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);
} 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);
}
return piwikInfo;

View File

@ -1,6 +1,5 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
@ -43,12 +42,6 @@ public interface RepositoryService {
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,
String page,
String size) throws JSONException;

View File

@ -11,7 +11,6 @@ import com.google.gson.JsonObject;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.enabling.Vocabulary;
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.broker.BrowseEntry;
import eu.dnetlib.repo.manager.domain.dto.Role;
@ -51,14 +50,11 @@ import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static eu.dnetlib.repo.manager.utils.DateUtils.getYear;
@Service("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 RoleMappingService roleMappingService;
@ -122,8 +118,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@PostConstruct
private void init() {
LOGGER.debug("Initialization method of repository api!");
LOGGER.debug("Updated version!");
logger.debug("Initialization method of repository api! Updated version!");
for (String key : this.getVocabulary("dnet:datasource_typologies").getAsMap().keySet()) {
if (key.contains("aggregator")) {
@ -184,7 +179,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException {
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)));
RequestFilter requestFilter = new RequestFilter();
@ -229,11 +224,11 @@ public class RepositoryServiceImpl implements RepositoryService {
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
}
} catch (Exception e) {
LOGGER.debug("Exception on getRepositoriesSnippetOfUser", e);
logger.debug("Exception on getRepositoriesSnippetOfUser", e);
throw e;
}
LOGGER.debug("resultSet:" + resultSet);
logger.debug("resultSet:" + resultSet);
resultSet.parallelStream().forEach(repositorySnippet -> {
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
});
@ -246,7 +241,7 @@ public class RepositoryServiceImpl implements RepositoryService {
String mode,
Boolean managed) throws JSONException, IOException {
LOGGER.debug("Getting repositories by country!");
logger.debug("Getting repositories by country!");
int page = 0;
int size = 100;
List<RepositorySnippet> resultSet = new ArrayList<>();
@ -259,8 +254,7 @@ public class RepositoryServiceImpl implements RepositoryService {
filterKey = "CRIS system";
LOGGER.debug("Country code equals : " + country);
LOGGER.debug("Filter mode equals : " + filterKey);
logger.debug("Country code equals : " + country + " | Filter mode equals : " + filterKey);
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
RequestFilter requestFilter = new RequestFilter();
@ -284,7 +278,7 @@ public class RepositoryServiceImpl implements RepositoryService {
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
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;
ObjectMapper mapper = new ObjectMapper();
@ -300,7 +294,7 @@ public class RepositoryServiceImpl implements RepositoryService {
try {
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
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 {
JSONObject response = new JSONObject(rs);
JSONArray jsonArray = (JSONArray) response.get("datasourceInfo");
@ -312,7 +306,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
} catch (Exception e) {
LOGGER.error("Error searching registered datasources", e);
logger.error("Error searching registered datasources", e);
throw e;
}
return snippets != null ? snippets.getResults() : null; // TODO: return paging when ui is compatible
@ -337,14 +331,14 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException {
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());
return getRepositories(new ArrayList<>(repoIds));
}
@Override
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));
return getRepositories(new ArrayList<>(repoIds));
}
@ -376,7 +370,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException {
LOGGER.debug("Retrieving repositories with id : " + id);
logger.debug("Retrieving repositories with id : " + id);
RepositorySnippet repo;
UriComponents uriComponents = searchSnipperDatasource("0", "100");
RequestFilter requestFilter = new RequestFilter();
@ -395,7 +389,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
LOGGER.debug("Retrieving repositories with id : " + id);
logger.debug("Retrieving repositories with id : " + id);
Repository repo;
UriComponents uriComponents = searchDatasource("0", "100");
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
public List<Repository> getRepositoriesByName(String name,
String page,
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");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setOfficialname(name);
@ -485,15 +440,19 @@ public class RepositoryServiceImpl implements RepositoryService {
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.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!
List<ApiDetails> res = new ArrayList<>();
for (ApiDetails det: rs.getApi()) {
if (!det.getProtocol().equals("sword") &&
!det.getProtocol().equals("rest") &&
!det.getProtocol().equals("ftp")) {
String protocol = det.getProtocol();
if ( !protocol.equals("sword") &&
!protocol.equals("rest") &&
!protocol.equals("ftp")) {
res.add(det);
}
}
@ -504,7 +463,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
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.setCollectedfrom("infrastruct_::openaire");
@ -543,10 +502,10 @@ public class RepositoryServiceImpl implements RepositoryService {
} catch (HttpClientErrorException e) {
couId = registryCalls.getCouId(newRoleName);
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) {
LOGGER.error(String.format("Could not create role '%s'", newRoleName), e);
logger.error(String.format("Could not create role '%s'", newRoleName), e);
throw e;
}
@ -560,13 +519,12 @@ public class RepositoryServiceImpl implements RepositoryService {
// Add role to current user authorities
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(repository.getId()));
} 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;
}
}
return repository;
}
@ -579,7 +537,7 @@ public class RepositoryServiceImpl implements RepositoryService {
// FIXME: problematic
// 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)
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.sendAdminRegistrationEmail(repository, authentication);
} catch (Exception e) {
LOGGER.error("Error sending email", e);
logger.error("Error sending email", e);
}
} else
LOGGER.error("Error storing repository: " + responseEntity.getBody().toString());
} else {
Object responseBody = responseEntity.getBody();
if ( responseBody != null )
logger.error("Error updating repository: " + responseBody);
}
return repository;
}
@ -606,21 +567,23 @@ public class RepositoryServiceImpl implements RepositoryService {
// FIXME: problematic
// 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);
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity
, ResponseEntity.class);
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
try {
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
} catch (Exception e) {
LOGGER.error("Error sending emails: " + e);
logger.error("Error sending emails: " + e);
}
} else
LOGGER.debug(responseEntity.getBody().toString());
} else {
Object responseBody = responseEntity.getBody();
if ( responseBody != null )
logger.error("Error updating repository: " + responseBody);
}
return repository;
}
@ -646,10 +609,12 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} catch (Exception e) {
LOGGER.error("Error sending emails: " + e);
logger.error("Error sending emails: " + e);
}
} 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/")
.path("/{id}")
.build().expand(id).encode();
LOGGER.debug(uriComponents.toUri());
logger.debug(uriComponents.toUri());
restTemplate.delete(uriComponents.toUri());
}
@ -686,7 +651,7 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
} catch (Exception ex) {
LOGGER.error("Error sending emails: " + ex);
logger.error("Error sending emails: " + ex);
}
submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false);
@ -709,10 +674,10 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
} catch (Exception e) {
LOGGER.error("Error sending emails: " + e);
logger.error("Error sending emails: " + 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);
@ -775,7 +740,7 @@ public class RepositoryServiceImpl implements RepositoryService {
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
if (iFace.getAccessSet() == null || iFace.getAccessSet().isEmpty()) {
LOGGER.debug("set is empty: " + iFace.getAccessSet());
logger.debug("set is empty: " + iFace.getAccessSet());
// iFace.removeAccessSet();
iFace.setAccessSet("none");
}
@ -784,7 +749,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<String> getDnetCountries() {
LOGGER.debug("Getting dnet-countries!");
logger.debug("Getting dnet-countries!");
return converter.readFile("countries.txt");
}
@ -810,7 +775,8 @@ public class RepositoryServiceImpl implements RepositoryService {
RequestFilter requestFilter = new RequestFilter();
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) {
@ -825,7 +791,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
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> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
@ -860,7 +826,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
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>();
@ -921,7 +887,7 @@ public class RepositoryServiceImpl implements RepositoryService {
return metricsInfo;
} 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);
}
}
@ -1019,12 +985,6 @@ public class RepositoryServiceImpl implements RepositoryService {
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) {

View File

@ -19,7 +19,7 @@ import java.util.Objects;
@Service("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
RestTemplate restTemplate;
@ -67,10 +67,10 @@ public class StatsServiceImpl implements StatsService {
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
return String.valueOf(metadata.get("total"));
} catch ( RestClientException rce ) {
LOGGER.error(rce.getMessage());
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
LOGGER.error("", e);
logger.error("", e);
return null;
}
}
@ -94,15 +94,15 @@ public class StatsServiceImpl implements StatsService {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
if ( metadata == null ) {
LOGGER.error("The metadata was null!");
logger.error("The metadata was null!");
return null;
}
return String.valueOf(metadata.get("total"));
} catch ( RestClientException rce ) {
LOGGER.error(rce.getMessage());
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
LOGGER.error("", e);
logger.error("", e);
return null;
}
}
@ -127,15 +127,15 @@ public class StatsServiceImpl implements StatsService {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
if ( metadata == null ) {
LOGGER.error("The metadata was null!");
logger.error("The metadata was null!");
return null;
}
return String.valueOf(metadata.get("total"));
} catch ( RestClientException rce ) {
LOGGER.error(rce.getMessage());
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
LOGGER.error("", e);
logger.error("", e);
return null;
}
}
@ -159,15 +159,15 @@ public class StatsServiceImpl implements StatsService {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
if ( metadata == null ) {
LOGGER.error("The metadata was null!");
logger.error("The metadata was null!");
return null;
}
return String.valueOf(metadata.get("total"));
} catch ( RestClientException rce ) {
LOGGER.error(rce.getMessage());
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
LOGGER.error("", e);
logger.error("", e);
return null;
}
}
@ -188,15 +188,15 @@ public class StatsServiceImpl implements StatsService {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map<?, ?>) rs.getBody();
if ( metadata == null ) {
LOGGER.error("The metadata was null!");
logger.error("The metadata was null!");
return null;
}
return String.valueOf(metadata.get("total"));
} catch ( RestClientException rce ) {
LOGGER.error(rce.getMessage());
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
LOGGER.error("", e);
logger.error("", e);
return null;
}
}
@ -217,15 +217,15 @@ public class StatsServiceImpl implements StatsService {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map<?, ?>) rs.getBody();
if ( metadata == null ) {
LOGGER.error("The metadata was null!");
logger.error("The metadata was null!");
return null;
}
return String.valueOf(metadata.get("total"));
} catch ( RestClientException rce ) {
LOGGER.error(rce.getMessage());
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
LOGGER.error("", e);
logger.error("", e);
return null;
}
}
@ -246,15 +246,15 @@ public class StatsServiceImpl implements StatsService {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map<?, ?>) rs.getBody();
if ( metadata == null ) {
LOGGER.error("The metadata was null!");
logger.error("The metadata was null!");
return null;
}
return String.valueOf(metadata.get("total"));
} catch ( RestClientException rce ) {
LOGGER.error(rce.getMessage());
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
LOGGER.error("", e);
logger.error("", e);
return null;
}
}
@ -280,10 +280,10 @@ public class StatsServiceImpl implements StatsService {
usagestats.put("year", year);
return usagestats;
} catch ( RestClientException rce ) {
LOGGER.error(rce.getMessage());
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
LOGGER.error("", e);
logger.error("", e);
return null;
}
}
@ -299,7 +299,7 @@ public class StatsServiceImpl implements StatsService {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("totals");
if ( metadata == null ) {
LOGGER.error("The metadata was null!");
logger.error("The metadata was null!");
return null;
}
@ -309,10 +309,10 @@ public class StatsServiceImpl implements StatsService {
return (Integer) metadata.get("events");
} catch ( RestClientException rce ) {
LOGGER.error(rce.getMessage());
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
LOGGER.error("", e);
logger.error("", e);
return null;
}
}

View File

@ -22,7 +22,7 @@ public class SushiliteServiceImpl implements SushiliteService {
@Value("${services.provide.usagestats.sushiliteEndpoint}")
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
@ -85,19 +85,16 @@ public class SushiliteServiceImpl implements SushiliteService {
}
requestedItemList = resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems().subList(offset,upperIndex);
}
} 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);
throw e;
}
}
ReportResponseWrapper newReportResponse = resp.getBody();
newReportResponse.getReportResponse().getReportWrapper().getReport().getCustomer().setReportItems(requestedItemList);
return newReportResponse;
}

View File

@ -1,7 +1,7 @@
package eu.dnetlib.repo.manager.service;
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.ResponseEntity;
import org.springframework.security.core.GrantedAuthority;
@ -16,21 +16,25 @@ import java.util.stream.Collectors;
@Service("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);
@Override
public ResponseEntity<Object> login() {
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LOGGER.debug("User authentication : " + authentication);
logger.debug("User authentication : " + authentication);
Map<String,Object> body = new HashMap<>();
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());
body.put("role",roles);

View File

@ -57,8 +57,7 @@ public class ValidatorServiceImpl implements ValidatorService {
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
private static final Logger LOGGER = Logger
.getLogger(ValidatorServiceImpl.class);
private static final Logger logger = Logger.getLogger(ValidatorServiceImpl.class);
@Autowired
private EmailUtils emailUtils;
@ -71,7 +70,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@PostConstruct
private void loadRules(){
LOGGER.debug("PostConstruct method! Load rules!");
logger.debug("PostConstruct method! Load rules!");
try {
for (RuleSet ruleSet : getValidationService().getRuleSets()) {
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) {
@ -124,7 +123,7 @@ public class ValidatorServiceImpl implements ValidatorService {
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
} catch (ValidatorServiceException e) {
LOGGER.error(e);
logger.error(e);
}
}
@ -132,12 +131,12 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
@PreAuthorize("hasAuthority('REGISTERED_USER')")
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 {
emailUtils.sendSubmitJobForValidationEmail(SecurityContextHolder.getContext().getAuthentication(), jobForValidation);
} 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 //
@ -154,7 +153,7 @@ public class ValidatorServiceImpl implements ValidatorService {
// this.getValidationService().submitValidationJob(jobForValidation);
} catch (Exception e) { // FIXME: replaced exception with log
// throw new ValidatorServiceException(e);
LOGGER.error(e);
logger.error(e);
}
return jobForValidation;
@ -163,7 +162,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public ResponseEntity<Object> reSubmitJobForValidation(String email,
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");
Set<Integer> contentRules = new HashSet<Integer>();
Set<Integer> usageRules = new HashSet<Integer>();
@ -198,20 +197,20 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public List<RuleSet> getRuleSets(String mode) {
LOGGER.info("Getting rulesets for mode: " + mode);
logger.info("Getting rulesets for mode: " + mode);
return rulesetMap.get(mode);
}
@Override
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;
try {
sets = OaiTools.getSetsOfRepo(url);
} catch (Exception e) {
LOGGER.error("Exception on getSetsOfRepository" , e);
logger.error("Exception on getSetsOfRepository" , e);
}
return sets;
@ -219,18 +218,18 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public boolean identifyRepo(String url) {
LOGGER.debug("Identify repository with url : " + url);
logger.debug("Identify repository with url : " + url);
try {
return OaiTools.identifyRepository(url);
} 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;
}
}
@Override
public RuleSet getRuleSet(String acronym) {
LOGGER.debug("Getting ruleset with acronym : " + acronym);
logger.debug("Getting ruleset with acronym : " + acronym);
RuleSet ruleSet = null;
try {
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
@ -242,7 +241,7 @@ public class ValidatorServiceImpl implements ValidatorService {
}
return ruleSet;
} catch (Exception e) {
LOGGER.error("Error getting ruleset", e);
logger.error("Error getting ruleset", e);
return null;
}
}
@ -281,7 +280,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException {
try {
LOGGER.debug("Getting interface information with url: " + baseUrl);
logger.debug("Getting interface information with url: " + baseUrl);
InterfaceInformation interfaceInformation = new InterfaceInformation();
interfaceInformation.setIdentified(this.identifyRepo(baseUrl));
if (interfaceInformation.isIdentified())
@ -289,7 +288,7 @@ public class ValidatorServiceImpl implements ValidatorService {
return interfaceInformation;
} 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);
}
}

View File

@ -2,7 +2,6 @@ package eu.dnetlib.repo.manager.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
@ -12,7 +11,6 @@ import org.json.JSONObject;
import org.springframework.stereotype.Component;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
@ -22,7 +20,7 @@ import java.util.Objects;
@Component
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;
@ -52,15 +50,6 @@ public class Converter {
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 {
List<RepositoryInterface> resultSet = new ArrayList<>();
@ -86,28 +75,16 @@ public class Converter {
String line;
List<String> list = new ArrayList<>();
try {
//InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
InputStream in = Converter.class.getResourceAsStream("/eu/**/" + filename);
BufferedReader br = new BufferedReader(new InputStreamReader(in)); // It may throw an NPE.
while ((line = br.readLine()) != null) {
list.add(line.trim());
}
br.close();
} catch (IOException e) {
LOGGER.debug("Error opening file!");
LOGGER.error(e);
} catch (Exception e) {
logger.error("Error opening file!", e);
}
return list;
}
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;
return list; // It may be empty.
}
public List<Timezone> toTimezones(List<String> timezones) {

View File

@ -10,7 +10,7 @@ import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
@Component
@ -78,8 +78,7 @@ public class HttpUtils {
private HttpHeaders createHeaders(String username, String password) {
return new HttpHeaders() {{
String auth = username + ":" + password;
byte[] encodedAuth = Base64.encodeBase64(
auth.getBytes(Charset.forName("US-ASCII")));
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.US_ASCII));
String authHeader = "Basic " + new String(encodedAuth);
set("Authorization", authHeader);
}};

View File

@ -24,16 +24,15 @@ public class OaiTools {
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 {
try {
LOGGER.debug("Getting sets of repository " + baseUrl);
logger.debug("Getting sets of repository " + baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
SetsList setList = harvester.listSets();
ResumptionToken token = setList.getResumptionToken();
List<Set> sets = new ArrayList<Set>();
sets.addAll(setList.asList());
List<Set> sets = new ArrayList<>(setList.asList());
while (token != null) {
setList = harvester.listSets(token);
token = setList.getResumptionToken();
@ -49,14 +48,14 @@ public class OaiTools {
return ret;
} 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>();
//throw e;
}
}
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);
@ -71,7 +70,7 @@ public class OaiTools {
return verifyIdentify(d);
} catch (Exception e) {
LOGGER.debug("Error verifying identify response", e);
logger.debug("Error verifying identify response", e);
throw e;
}
}
@ -112,7 +111,7 @@ public class OaiTools {
private static void disableSslVerification() {
try
{
LOGGER.debug("disabling ssl verification");
logger.debug("disabling ssl verification");
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
@ -140,9 +139,9 @@ public class OaiTools {
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (NoSuchAlgorithmException e) {
LOGGER.error("disabling ssl verification", e);
logger.error("disabling ssl verification", e);
} catch (KeyManagementException e) {
LOGGER.error("error while disabling ssl verification", e);
logger.error("error while disabling ssl verification", e);
}
}
}