New project structure

This commit is contained in:
Panagiotis Kanakakis 2019-01-03 12:19:45 +00:00
parent 3eaa39a3af
commit 499b96a9c7
57 changed files with 1307 additions and 676 deletions

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.config; package eu.dnetlib.repo.manager.config;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.config; package eu.dnetlib.repo.manager.config;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -16,7 +16,7 @@ import javax.annotation.PostConstruct;
@Configuration @Configuration
@EnableRedisHttpSession @EnableRedisHttpSession
@PropertySource(value = {"classpath:application.properties"} ) @PropertySource(value = {"classpath:application.properties"} )
@ComponentScan(basePackages = "eu.dnetlib.repo.manager.service.controllers") @ComponentScan(basePackages = "eu.dnetlib.repo.manager.controllers")
public class Config { public class Config {

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.config; package eu.dnetlib.repo.manager.config;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.config; package eu.dnetlib.repo.manager.config;
import com.nimbusds.jwt.JWT; import com.nimbusds.jwt.JWT;
import org.mitre.openid.connect.client.OIDCAuthoritiesMapper; import org.mitre.openid.connect.client.OIDCAuthoritiesMapper;

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.config; package eu.dnetlib.repo.manager.config;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;

View File

@ -1,9 +1,9 @@
package eu.dnetlib.repo.manager.service.config; package eu.dnetlib.repo.manager.config;
import eu.dnetlib.repo.manager.service.controllers.MonitorApi; import eu.dnetlib.repo.manager.service.MonitorApi;
import eu.dnetlib.repo.manager.service.controllers.PiWikApi; import eu.dnetlib.repo.manager.service.PiWikApi;
import eu.dnetlib.repo.manager.service.controllers.RepositoryApi; import eu.dnetlib.repo.manager.service.RepositoryApi;
import eu.dnetlib.repo.manager.service.controllers.ValidatorApi; import eu.dnetlib.repo.manager.service.ValidatorApi;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -16,6 +16,7 @@ import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -0,0 +1,134 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.BrokerApiImpl;
import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.Term;
import eu.dnetlib.repo.manager.shared.broker.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/broker")
@Api(description = "Broker API", tags = {"broker"})
public class BrokerController{
@Autowired
BrokerApiImpl brokerApi;
@RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
DatasourcesBroker getDatasourcesOfUser(@RequestParam("user")
@ApiParam(value = "User email", required = true) String user,
@RequestParam("includeShared")
@ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared,
@RequestParam("includeByOthers")
@ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException {
return brokerApi.getDatasourcesOfUser(user, includeShared, includeByOthers);
}
@RequestMapping(value = "/getTopicsForDatasource/{datasourceName:.+}" ,
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException{
return brokerApi.getTopicsForDatasource(datasourceName);
}
@RequestMapping(value = "/advancedShowEvents/{page}/{size}" ,
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
EventsPage advancedShowEvents(@PathVariable("page") String page,
@PathVariable("size") String size,
@RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException{
return brokerApi.advancedShowEvents(page, size, advQueryObject);
}
@RequestMapping(value = "/showEvents/{datasourceName:.+}/{topic}/{page}" ,
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
EventsPage showEvents(@RequestParam("datasourceName") String datasourceName,
@RequestParam("topic") String topic,
@RequestParam("page") String page,
@RequestParam("size") String size) throws BrokerException, JSONException{
return brokerApi.showEvents(datasourceName, topic, page, size);
}
@RequestMapping(value = "/getSimpleSubscriptionsOfUser/{userEmail}" ,
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException{
return brokerApi.getSimpleSubscriptionsOfUser(userEmail);
}
@RequestMapping(value = "/subscribe" , method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') ")
Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException{
return brokerApi.subscribe(obj);
}
@RequestMapping(value = "/unsubscribe/{subscriptionId}" , method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
ResponseEntity<Object> unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{
return brokerApi.unsubscribe(subscriptionId);
}
@RequestMapping(value = "/getSubscription/{subscriptionId}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{
return brokerApi.getSubscription(subscriptionId);
}
@RequestMapping(value = "/getDnetTopics" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, Term> getDnetTopics() throws BrokerException{
return brokerApi.getDnetTopics();
}
@RequestMapping(value = "/getNotificationsBySubscriptionId/{subscriptionId}/{page}/{size}" , method = RequestMethod.GET
,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId,
@PathVariable("page") String page,
@PathVariable("size") String size) throws BrokerException{
return brokerApi.getNotificationsBySubscriptionId(subscriptionId, page, size);
}
/*@RequestMapping(value = "/getSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET
,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody*/
Map<String, List<Subscription>> getSubscriptionsOfUser(String userEmail) throws BrokerException{
return brokerApi.getSubscriptionsOfUser(userEmail);
}
}

View File

@ -0,0 +1,65 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.repo.manager.exception.EndPointException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.exception.ServerError;
import eu.dnetlib.repo.manager.shared.BrokerException;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.net.UnknownHostException;
@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class GenericControllerAdvice {
private Logger logger = LogManager.getLogger(GenericControllerAdvice.class);
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(ResourceNotFoundException.class)
@ResponseBody
ServerError securityException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex);
}
@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(AccessDeniedException.class)
@ResponseBody
ServerError accessDeniedException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex);
}
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(UnknownHostException.class)
@ResponseBody
ServerError unknownHostException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex);
}
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler({JSONException.class,BrokerException.class,ValidatorServiceException.class})
@ResponseBody
ServerError internalException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex);
}
@ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
@ExceptionHandler(EndPointException.class)
@ResponseBody
ServerError endPointException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex);
}
}

View File

@ -0,0 +1,60 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.service.MonitorApiImpl;
import eu.dnetlib.repo.manager.shared.JobsOfUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/monitor")
@Api(description = "Monitor API", tags = {"monitor"})
public class MonitorController {
private static final Logger LOGGER = Logger
.getLogger(MonitorController.class);
@Autowired
MonitorApiImpl monitorApi;
@RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public JobsOfUser getJobsOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
@RequestParam(value = "jobType", required = false)
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus,
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
return monitorApi.getJobsOfUser(user, jobType, offset, limit, dateFrom, dateTo, validationStatus, includeJobsTotal);
}
@RequestMapping(value = "/getJobsOfUserPerValidationStatus" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public int getJobsOfUserPerValidationStatus(@RequestBody String user,
@RequestBody String jobType,
@RequestBody String validationStatus) throws JSONException {
return monitorApi.getJobsOfUserPerValidationStatus(user, jobType, validationStatus);
}
@RequestMapping(value = "/getJobSummary" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public StoredJob getJobSummary(@RequestBody String jobId,
@RequestBody String groupBy) throws JSONException {
return monitorApi.getJobSummary(jobId, groupBy);
}
}

View File

@ -0,0 +1,90 @@
package eu.dnetlib.repo.manager.controllers;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.repo.manager.service.PiWikApiImpl;
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import io.swagger.annotations.Api;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.sql.Types;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/piwik")
@Api(description = "Piwik API", tags = {"piwik"})
public class PiWikController {
@Autowired
PiWikApiImpl piWikApi;
@RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) {
return piWikApi.getPiwikSiteForRepo(repositoryId);
}
@RequestMapping(value = "/savePiwikInfo" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PORTAL_ADMIN') or (hasRole('ROLE_USER') " +
"and #piwikInfo.requestorEmail == authentication.userInfo.email)")
public PiwikInfo savePiwikInfo(@RequestBody PiwikInfo piwikInfo) {
return piWikApi.savePiwikInfo(piwikInfo);
}
@RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
List<PiwikInfo> getPiwikSitesForRepos(){
return piWikApi.getPiwikSitesForRepos();
}
@RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET)
@ResponseBody
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PORTAL_ADMIN')")
public ResponseEntity<Object> approvePiwikSite(@PathVariable("repositoryId") String repositoryId) {
return piWikApi.approvePiwikSite(repositoryId);
}
@RequestMapping(value = "/getOpenaireId/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String getOpenaireId(String repositoryid){
return piWikApi.getOpenaireId(repositoryid);
}
@RequestMapping(value = "/markPiwikSiteAsValidated/{repositoryId}" , method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PORTAL_ADMIN')")
public ResponseEntity<Object> markPiwikSiteAsValidated(@PathVariable("repositoryId") String repositoryId) throws RepositoryServiceException {
return piWikApi.markPiwikSiteAsValidated(repositoryId);
}
@RequestMapping(value = "/enableMetricsForRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PORTAL_ADMIN') or (hasRole('ROLE_USER') and #piwikInfo.requestorEmail == authentication.userInfo.email)")
public PiwikInfo enableMetricsForRepository(@RequestParam("officialName") String officialName,
@RequestParam("repoWebsite") String repoWebsite,
@RequestBody PiwikInfo piwikInfo) throws RepositoryServiceException {
return piWikApi.enableMetricsForRepository(officialName, repoWebsite, piwikInfo);
}
}

View File

@ -0,0 +1,203 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.RepositoryApiImpl;
import eu.dnetlib.repo.manager.shared.*;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/repository")
@Api(description = "Repository API", tags = {"repository"})
public class RepositoryController {
@Autowired
RepositoryApiImpl repositoryApi;
@RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Country[] getCountries() {
return repositoryApi.getCountries();
}
@RequestMapping(value = "/getRepositoriesByCountry/{country}/{mode}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<RepositorySnippet> getRepositoriesByCountry(@PathVariable("country") String country,
@PathVariable("mode") String mode,
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException, IOException {
return repositoryApi.getRepositoriesByCountry(country, mode, managed);
}
@RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
return repositoryApi.getRepositoriesOfUser(userEmail, page, size);
}
@RequestMapping(value = "/getRepositoryById/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException,ResourceNotFoundException {
return repositoryApi.getRepositoryById(id);
}
@RequestMapping(value = "/getRepositoryAggregations/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<AggregationDetails> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
return repositoryApi.getRepositoryAggregations(id);
}
@RequestMapping(value = "/getRepositoryAggregationsByYear/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException {
return repositoryApi.getRepositoryAggregationsByYear(id);
}
@RequestMapping(value = "/getRepositoriesByName/{name:.+}/{page}/{size}/", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<Repository> getRepositoriesByName(@PathVariable("name") String name,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
return repositoryApi.getRepositoriesByName(name, page, size);
}
@RequestMapping(value = "/getRepositoryInterface/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException {
return repositoryApi.getRepositoryInterface(id);
}
@RequestMapping(value = "/addRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') and #repository.registeredBy == authentication.userInfo.email")
public Repository addRepository(@RequestParam("datatype") String datatype,
@RequestBody Repository repository) throws Exception {
return repositoryApi.addRepository(datatype, repository);
}
@RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getDnetCountries(){
return repositoryApi.getDnetCountries();
}
@RequestMapping(value = "/getTypologies", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getTypologies(){
return repositoryApi.getTypologies();
}
@RequestMapping(value = "/getTimezones", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<Timezone> getTimezones(){
return repositoryApi.getTimezones();
}
@RequestMapping(value = "/updateRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
//@PreAuthorize("hasRole('ROLE_USER') and #repository.registeredBy == authentication.userInfo.email")
public Repository updateRepository(@RequestBody Repository repository,Authentication authentication) throws Exception {
return repositoryApi.updateRepository(repository, authentication);
}
@RequestMapping(value = "/deleteInterface/", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ROLE_USER') and #registeredBy == authentication.userInfo.email")
public void deleteRepositoryInterface(@RequestParam("id") String id ,
@RequestParam("registeredBy") String registeredBy){
repositoryApi.deleteRepositoryInterface(id, registeredBy);
}
@RequestMapping(value = "/addInterface", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') and #registeredBy == authentication.userInfo.email")
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype,
@RequestParam("repoId") String repoId,
@RequestParam("registeredBy") String registeredBy,
@RequestBody RepositoryInterface repositoryInterface) throws JSONException,ResourceNotFoundException {
return repositoryApi.addRepositoryInterface(datatype, repoId, registeredBy, repositoryInterface);
}
@RequestMapping(value = "/getUrlsOfUserRepos/{user_email}/{page}/{size}/",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
return repositoryApi.getUrlsOfUserRepos(userEmail, page, size);
}
@RequestMapping(value = "/getDatasourceVocabularies/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<String> getDatasourceVocabularies(@PathVariable("mode") String mode) {
return repositoryApi.getDatasourceVocabularies(mode);
}
@RequestMapping(value = "/getCompatibilityClasses/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, String> getCompatibilityClasses(@PathVariable("mode") String mode) {
return repositoryApi.getCompatibilityClasses(mode);
}
@RequestMapping(value = "/getDatasourceClasses/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, String> getDatasourceClasses(@PathVariable("mode") String mode) {
return repositoryApi.getDatasourceClasses(mode);
}
@RequestMapping(value = "/getMetricsInfoForRepository/{repoId}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public MetricsInfo getMetricsInfoForRepository(@PathVariable("repoId") String repoId) throws RepositoryServiceException {
return repositoryApi.getMetricsInfoForRepository(repoId);
}
@RequestMapping(value = "/getListLatestUpdate/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, String> getListLatestUpdate(@PathVariable("mode") String mode) throws JSONException {
return repositoryApi.getListLatestUpdate(mode);
}
@RequestMapping(value = "/updateRepositoryInterface", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') and #registeredBy == authentication.userInfo.email")
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId,
@RequestParam("registeredBy") String registeredBy,
@RequestBody RepositoryInterface repositoryInterface) throws JSONException {
return repositoryApi.updateRepositoryInterface(repoId, registeredBy, repositoryInterface);
}
}

View File

@ -1,7 +1,9 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.StatsApiImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
@ -13,14 +15,15 @@ import java.util.Map;
@RestController @RestController
@RequestMapping(value = "/stats") @RequestMapping(value = "/stats")
@Api(description = "Stats API", tags = {"statistics"}) @Api(description = "Stats API", tags = {"statistics"})
public interface StatsApi { public class StatsController {
@Autowired
StatsApiImpl statsApi;
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET, @RequestMapping(value = "/getStatistics" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
Map<String, Object> getStatistics() throws JSONException; public Map<String, Object> getStatistics() throws JSONException {
return statsApi.getStatistics();
}
} }

View File

@ -0,0 +1,52 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.SushiliteApiImpl;
import eu.dnetlib.usagestats.sushilite.domain.ReportItem;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping(value = "/sushilite")
@Api(description = "Sushi-Lite API", tags = {"sushilite"})
public class SushiliteController {
@Autowired
SushiliteApiImpl sushiliteApi;
@RequestMapping(value = "/getReportResults/{page}/{pageSize}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public ReportResponseWrapper getReportResults(@PathVariable("page") String page,
@PathVariable("pageSize") String pageSize,
@RequestParam(value = "Report") String Report,
@RequestParam(value = "Release",defaultValue="4") String Release,
@RequestParam(value = "RequestorID",required=false,defaultValue="anonymous") String RequestorID,
@RequestParam(value = "BeginDate",required=false,defaultValue="") String BeginDate,
@RequestParam(value = "EndDate",required=false,defaultValue="") String EndDate,
@RequestParam(value = "RepositoryIdentifier") String RepositoryIdentifier,
@RequestParam(value = "ItemIdentifier",required=false,defaultValue="") String ItemIdentifier,
@RequestParam(value = "ItemDataType",required=false,defaultValue="") String ItemDataType,
@RequestParam(value = "Granularity") String Granularity,
@RequestParam(value = "Pretty",required=false,defaultValue="") String Pretty) {
return sushiliteApi.getReportResults(page, pageSize, Report, Release, RequestorID, BeginDate, EndDate, RepositoryIdentifier, ItemIdentifier, ItemDataType, Granularity, Pretty);
}
}

View File

@ -1,7 +1,10 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.UserApiImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -9,10 +12,14 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping(value = "/user") @RequestMapping(value = "/user")
@Api(description = "User API", tags = {"user"}) @Api(description = "User API", tags = {"user"})
public interface UserApi { public class UserController {
@Autowired
UserApiImpl userApi;
@RequestMapping(value = "/login" , method = RequestMethod.GET) @RequestMapping(value = "/login" , method = RequestMethod.GET)
ResponseEntity<Object> login(); @PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<Object> login() {
return userApi.login();
}
} }

View File

@ -0,0 +1,113 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.service.ValidatorApiImpl;
import eu.dnetlib.repo.manager.utils.OaiTools;
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
import gr.uoa.di.driver.util.ServiceLocator;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.domain.functionality.validator.RuleSet;
import eu.dnetlib.repo.manager.shared.Constants;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import eu.dnetlib.api.functionality.ValidatorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@RestController
@RequestMapping(value = "/validator")
@Api(description = "Validator API", tags = {"validator"})
public class ValidatorController {
@Autowired
ValidatorApiImpl validatorApi;
@RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') and #jobForValidation.userEmail == authentication.userInfo.email")
public JobForValidation submitJobForValidation(@RequestBody JobForValidation jobForValidation) throws ValidatorServiceException {
return validatorApi.submitJobForValidation(jobForValidation);
}
@RequestMapping(value = "/reSubmitJobForValidation/{email}/{jobId}",method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') and #email == authentication.userInfo.email")
public ResponseEntity<Object> reSubmitJobForValidation(@PathVariable("email") String email,
@PathVariable("jobId") String jobId) throws JSONException, ValidatorServiceException {
return validatorApi.reSubmitJobForValidation(email, jobId);
}
@RequestMapping(value = "/getRuleSets/{mode}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) {
return validatorApi.getRuleSets(mode);
}
@RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<String> getSetsOfRepository(@RequestParam(value = "url", required = true) String url) {
return validatorApi.getSetsOfRepository(url);
}
@RequestMapping(value = "/identifyRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public boolean identifyRepo(@RequestParam(value = "url", required = true) String url) {
return validatorApi.identifyRepo(url);
}
@RequestMapping(value = "/getRuleSet/{acronym}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public RuleSet getRuleSet(@PathVariable("acronym") String acronym) {
return validatorApi.getRuleSet(acronym);
}
@RequestMapping(value = "/getStoredJobsNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public List<StoredJob> getStoredJobsNew(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
@RequestParam(value = "jobType", required = false)
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus
) throws ValidatorServiceException {
return validatorApi.getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus);
}
@RequestMapping(value = "/getStoredJobsTotalNumberNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException {
return validatorApi.getStoredJobsTotalNumberNew(user, jobType, validationStatus);
}
@RequestMapping(value = "/getInterfaceInformation" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public InterfaceInformation getInterfaceInformation(@RequestParam(value = "baseUrl", required = true) String baseUrl) throws ValidationServiceException {
return validatorApi.getInterfaceInformation(baseUrl);
}
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.domain; package eu.dnetlib.repo.manager.domain;
import com.google.gwt.user.client.rpc.IsSerializable; import com.google.gwt.user.client.rpc.IsSerializable;

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.domain; package eu.dnetlib.repo.manager.domain;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;

View File

@ -0,0 +1,17 @@
package eu.dnetlib.repo.manager.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
public class EndPointException extends Exception{
public EndPointException() {
super("Endpoint not responding!");
}
public EndPointException(String url) {
super("Endpoint with url: " + url + " not responding!");
}
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.exception; package eu.dnetlib.repo.manager.exception;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.exception; package eu.dnetlib.repo.manager.exception;
public class ServerError { public class ServerError {

View File

@ -0,0 +1,48 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.Term;
import eu.dnetlib.repo.manager.shared.broker.*;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public interface BrokerApi {
DatasourcesBroker getDatasourcesOfUser(String user, String includeShared, String includeByOthers) throws BrokerException, JSONException;
List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException;
EventsPage advancedShowEvents(String page,
String size,
AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException;
EventsPage showEvents(String datasourceName,
String topic,
String page,
String size) throws BrokerException, JSONException;
Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(String userEmail) throws BrokerException;
Subscription subscribe(OpenaireSubscription obj) throws BrokerException;
ResponseEntity<Object> unsubscribe(String subscriptionId) throws BrokerException;
Subscription getSubscription(String subscriptionId) throws BrokerException;
Map<String, Term> getDnetTopics() throws BrokerException;
EventsPage getNotificationsBySubscriptionId(String subscriptionId, String page, String size) throws BrokerException;
Map<String, List<Subscription>> getSubscriptionsOfUser(String userEmail) throws BrokerException;
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -16,6 +16,7 @@ import org.springframework.http.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -32,7 +33,7 @@ import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.*; import java.util.*;
@Component @Service("brokerService")
public class BrokerApiImpl implements BrokerApi { public class BrokerApiImpl implements BrokerApi {
@Autowired @Autowired
@ -86,13 +87,7 @@ public class BrokerApiImpl implements BrokerApi {
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')") public DatasourcesBroker getDatasourcesOfUser(String user,String includeShared,String includeByOthers) throws JSONException {
public DatasourcesBroker getDatasourcesOfUser(@RequestParam("user")
@ApiParam(value = "User email", required = true) String user,
@RequestParam("includeShared")
@ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared,
@RequestParam("includeByOthers")
@ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException {
DatasourcesBroker ret = new DatasourcesBroker(); DatasourcesBroker ret = new DatasourcesBroker();
try { try {
@ -115,7 +110,7 @@ public class BrokerApiImpl implements BrokerApi {
} }
@Override @Override
public List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException { public List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException {
final String service = "/topicsForDatasource"; final String service = "/topicsForDatasource";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service) UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
@ -139,10 +134,9 @@ public class BrokerApiImpl implements BrokerApi {
} }
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')") public EventsPage advancedShowEvents(String page,
public EventsPage advancedShowEvents(@PathVariable("page") String page, String size,
@PathVariable("size") String size, AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException {
@RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException {
final String service = "/events/{page}/{pageSize}"; final String service = "/events/{page}/{pageSize}";
@ -200,8 +194,6 @@ public class BrokerApiImpl implements BrokerApi {
return entries; return entries;
} }
private List<Repository> getRepositoriesOfUser(String userEmail) throws JSONException { private List<Repository> getRepositoriesOfUser(String userEmail) throws JSONException {
int page = 0; int page = 0;
@ -223,11 +215,10 @@ public class BrokerApiImpl implements BrokerApi {
} }
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')") public EventsPage showEvents(String datasourceName,
public EventsPage showEvents(@RequestParam("datasourceName") String datasourceName, String topic,
@RequestParam("topic") String topic, String page,
@RequestParam("page") String page, String size) throws BrokerException, JSONException {
@RequestParam("size") String size) throws BrokerException, JSONException {
final String service = "/events"; final String service = "/events";
@ -253,8 +244,7 @@ public class BrokerApiImpl implements BrokerApi {
} }
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')") public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(String userEmail)
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail)
throws BrokerException { throws BrokerException {
final String service = "/subscriptions"; final String service = "/subscriptions";
@ -280,8 +270,7 @@ public class BrokerApiImpl implements BrokerApi {
} }
@Override @Override
@PreAuthorize("hasRole('ROLE_USER') ") public Subscription subscribe(OpenaireSubscription obj) throws BrokerException {
public Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException {
final String service = "/subscribe"; final String service = "/subscribe";
//build the uri params //build the uri params
@ -311,8 +300,7 @@ public class BrokerApiImpl implements BrokerApi {
} }
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')") public ResponseEntity<Object> unsubscribe(String subscriptionId) throws BrokerException {
public ResponseEntity<Object> unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException {
final String service = "/subscriptions/" + subscriptionId; final String service = "/subscriptions/" + subscriptionId;
//build the uri params //build the uri params
@ -335,8 +323,7 @@ public class BrokerApiImpl implements BrokerApi {
} }
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')") public Subscription getSubscription( String subscriptionId) throws BrokerException {
public Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException {
final String service = "/subscriptions/" + subscriptionId; final String service = "/subscriptions/" + subscriptionId;
//build the uri params //build the uri params
@ -365,11 +352,9 @@ public class BrokerApiImpl implements BrokerApi {
} }
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')") public EventsPage getNotificationsBySubscriptionId(String subscriptionId,
public EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId, String page,
@PathVariable("page") String page, String size) throws BrokerException {
@PathVariable("size") String size
) throws BrokerException {
UriComponents uriComponents = UriComponentsBuilder UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(openairePath + "/notifications/") .fromHttpUrl(openairePath + "/notifications/")
@ -393,7 +378,7 @@ public class BrokerApiImpl implements BrokerApi {
} }
//@Override //@Override
public Map<String, List<Subscription>> getSubscriptionsOfUser(/*@PathVariable("userEmail")*/ String userEmail) public Map<String, List<Subscription>> getSubscriptionsOfUser(String userEmail)
throws BrokerException { throws BrokerException {
Map<String, List<SimpleSubscriptionDesc>> simpleSubs = getSimpleSubscriptionsOfUser(userEmail); Map<String, List<SimpleSubscriptionDesc>> simpleSubs = getSimpleSubscriptionsOfUser(userEmail);

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.PiwikInfo; import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.domain.data.Repository; import eu.dnetlib.domain.data.Repository;

View File

@ -1,9 +1,9 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.PiwikInfo; import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.domain.data.Repository; import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.functionality.validator.JobForValidation; import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader; import eu.dnetlib.repo.manager.config.CascadingPropertyLoader;
import eu.dnetlib.utils.MailLibrary; import eu.dnetlib.utils.MailLibrary;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken; import org.mitre.openid.connect.model.OIDCAuthenticationToken;

View File

@ -1,9 +1,9 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorServiceException; import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.repo.manager.service.exception.ResourceNotFoundException; import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.exception.ServerError; import eu.dnetlib.repo.manager.exception.ServerError;
import eu.dnetlib.repo.manager.shared.BrokerException; import eu.dnetlib.repo.manager.shared.BrokerException;
import org.apache.log4j.LogManager; import org.apache.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -12,7 +12,10 @@ import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.UnknownHostException; import java.net.UnknownHostException;

View File

@ -0,0 +1,32 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.shared.JobsOfUser;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
public interface MonitorApi {
JobsOfUser getJobsOfUser(String user,
String jobType,
String offset,
String limit,
String dateFrom,
String dateTo,
String validationStatus,
String includeJobsTotal) throws JSONException, ValidatorServiceException;
int getJobsOfUserPerValidationStatus(String user,
String jobType,
String validationStatus) throws JSONException;
StoredJob getJobSummary(String jobId,
String groupBy) throws JSONException;
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorService; import eu.dnetlib.api.functionality.ValidatorService;
import eu.dnetlib.api.functionality.ValidatorServiceException; import eu.dnetlib.api.functionality.ValidatorServiceException;
@ -11,11 +11,12 @@ import org.apache.log4j.Logger;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource; import javax.annotation.Resource;
@Component @Service("monitorService")
public class MonitorApiImpl implements MonitorApi { public class MonitorApiImpl implements MonitorApi {
@Resource(name = "validatorServiceLocator") @Resource(name = "validatorServiceLocator")
@ -38,16 +39,14 @@ public class MonitorApiImpl implements MonitorApi {
.getLogger(MonitorApiImpl.class); .getLogger(MonitorApiImpl.class);
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')") public JobsOfUser getJobsOfUser(String user,
public JobsOfUser getJobsOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user, String jobType,
@RequestParam(value = "jobType", required = false) String offset,
@ApiParam(value = "Equals to filter job type on validation history page") String jobType, String limit,
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset, String dateFrom,
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit, String dateTo,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom, String validationStatus,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo, String includeJobsTotal) throws JSONException, ValidatorServiceException {
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus,
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) 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); LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
@ -89,7 +88,6 @@ public class MonitorApiImpl implements MonitorApi {
} }
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')")
public int getJobsOfUserPerValidationStatus(String user, public int getJobsOfUserPerValidationStatus(String user,
String jobType, String jobType,
String validationStatus) throws JSONException { String validationStatus) throws JSONException {

View File

@ -0,0 +1,26 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import org.springframework.http.ResponseEntity;
import java.util.List;
public interface PiWikApi {
PiwikInfo getPiwikSiteForRepo(String repositoryId);
PiwikInfo savePiwikInfo(PiwikInfo piwikInfo);
List<PiwikInfo> getPiwikSitesForRepos();
ResponseEntity<Object> approvePiwikSite(String repositoryId);
String getOpenaireId(String repositoryid);
ResponseEntity<Object> markPiwikSiteAsValidated(String repositoryId) throws RepositoryServiceException;
PiwikInfo enableMetricsForRepository(String officialName, String repoWebsite, PiwikInfo piwikInfo) throws RepositoryServiceException;
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.PiwikInfo; import eu.dnetlib.domain.data.PiwikInfo;
@ -13,9 +13,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -29,8 +28,8 @@ import java.sql.Types;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@Component @Service("piwikService")
public class PiWikApiImpl implements PiWikApi{ public class PiWikApiImpl implements PiWikApi {
@Qualifier("repomanager.dataSource") @Qualifier("repomanager.dataSource")
@Autowired @Autowired

View File

@ -0,0 +1,72 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.shared.*;
import org.json.JSONException;
import org.springframework.security.core.Authentication;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public interface RepositoryApi {
Country[] getCountries() ;
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException;
List<Repository> getRepositoriesOfUser(String userEmail,
String page,
String size) throws JSONException;
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException;
Map<String,List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException;
List<Repository> getRepositoriesByName(String name,
String page,
String size) throws JSONException;
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
Repository addRepository(String datatype, Repository repository) throws Exception;
void deleteRepositoryInterface(String id, String registeredBy);
RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
String registeredBy,
RepositoryInterface iFace) throws JSONException,ResourceNotFoundException;
List<String> getDnetCountries();
List<String> getTypologies();
List<Timezone> getTimezones();
Repository updateRepository(Repository repository, Authentication authentication) throws Exception;
List<String> getUrlsOfUserRepos(String user_email,
String page,
String size) throws JSONException;
List<String> getDatasourceVocabularies(String mode);
Map<String, String> getCompatibilityClasses(String mode);
Map<String, String> getDatasourceClasses(String mode);
String getCountryName(String countryCode);
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException;
Map<String, String> getListLatestUpdate(String mode) throws RepositoryServiceException, JSONException;
RepositoryInterface updateRepositoryInterface(String repositoryId, String registeredBy, RepositoryInterface repositoryInterface) throws JSONException;
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -6,10 +6,10 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import eu.dnetlib.domain.data.Repository; import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface; import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.domain.enabling.Vocabulary; import eu.dnetlib.domain.enabling.Vocabulary;
import eu.dnetlib.repo.manager.service.domain.RepositorySnippet; import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.service.domain.RequestFilter; import eu.dnetlib.repo.manager.domain.RequestFilter;
import eu.dnetlib.repo.manager.service.exception.ResourceNotFoundException; import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.utils.Converter; import eu.dnetlib.repo.manager.utils.Converter;
import eu.dnetlib.repo.manager.shared.*; import eu.dnetlib.repo.manager.shared.*;
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader; import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
@ -25,7 +25,7 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -35,14 +35,13 @@ import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.xml.ws.Response;
import java.io.IOException; 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 java.util.stream.Collectors;
@Component @Service("repositoryService")
public class RepositoryApiImpl implements RepositoryApi { public class RepositoryApiImpl implements RepositoryApi {
@Value("${api.baseAddress}") @Value("${api.baseAddress}")

View File

@ -0,0 +1,12 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.exception.EndPointException;
import org.json.JSONException;
import java.util.Map;
public interface StatsApi {
Map<String, Object> getStatistics() throws JSONException, EndPointException;
}

View File

@ -0,0 +1,208 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.exception.EndPointException;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import java.rmi.ServerError;
import java.util.HashMap;
import java.util.Map;
@Service("statsService")
public class StatsApiImpl implements StatsApi {
private RestTemplate restTemplate = null;
private HttpHeaders httpHeaders;
private static final Logger LOGGER = Logger.getLogger(RepositoryApiImpl.class);
@Value("${search.api.baseAddress}")
private String baseAddress;
@Value("${search.api.usagestats}")
private String usagestatsBaseAddress;
@Value("${search.api.usageEvents}")
private String usagestatsEvents;
@PostConstruct
private void init() {
LOGGER.debug("Initialization method of statistics api!");
restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
}
@Override
public Map<String, Object> getStatistics() throws JSONException {
String aggregators = null;
try {
aggregators = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" ( datasourcetypename exact Institutional Repository Aggregator " +
" or datasourcetypename exact Publication Repository Aggregator )");
} catch (EndPointException e) {
LOGGER.debug(e);
aggregators = "N/A";
}
String dataRepositories = null;
try {
dataRepositories = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" datasourcetypename exact Data Repository " );
} catch (EndPointException e) {
LOGGER.debug(e);
dataRepositories = "N/A";
}
String literature = null;
try {
literature = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" ( datasourcetypename exact Institutional Repository " +
" or datasourcetypename exact Publication Repository )");
} catch (EndPointException e) {
LOGGER.debug(e);
literature = "N/A";
}
String journal = null;
try {
journal = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" datasourcetypename exact Journal");
} catch (EndPointException e) {
LOGGER.debug(e);
journal = "N/A";
}
String publications = null;
try {
publications = getTotalByType("other",baseAddress,"/publications/count");
} catch (EndPointException e) {
LOGGER.debug(e);
publications = "N/A";
}
String datasets = null;
try {
datasets = getTotalByType("other",baseAddress,"/datasets/count");
} catch (EndPointException e) {
LOGGER.debug(e);
datasets = "N/A";
}
String software = null;
try {
software = getTotalByType("other",baseAddress,"/software/count");
} catch (EndPointException e) {
LOGGER.debug(e);
software = "N/A";
}
JSONObject lastYearUsagestats = null;
try {
lastYearUsagestats = getLastYearUsageStatsTotal();
} catch (EndPointException e) {
LOGGER.debug(e);
lastYearUsagestats = null;
}
Integer usagestats = getUsageStatsTotal();
HashMap<String,Object> stats = new HashMap<>();
stats.put("aggregators",aggregators);
stats.put("dataRepositories",dataRepositories);
stats.put("literature",literature);
stats.put("journal",journal);
stats.put("publications",publications);
stats.put("datasets",datasets);
stats.put("software",software);
stats.put("lastYearUsagestats", lastYearUsagestats != null ? lastYearUsagestats.toString() : null);
stats.put("usagestats",usagestats.toString());
return stats;
}
private String getTotalByType(String type,String url,String query) throws JSONException, EndPointException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url + query)
.queryParam("page",0)
.queryParam("size",0)
.queryParam("format","json")
.build().encode();
ResponseEntity rs = restTemplate.getForObject(uriComponents.toUri(), ResponseEntity.class);
if(rs.getStatusCode().equals(HttpStatus.OK)){
if(type.equalsIgnoreCase("datasource")){
JSONObject metadata = (JSONObject) new JSONObject(rs.getBody()).get("meta");
return String.valueOf(metadata.get("total"));
}else
return String.valueOf(new JSONObject(rs.getBody()).get("total"));
}else
throw new EndPointException(uriComponents.toUri().toString());
}
private JSONObject getLastYearUsageStatsTotal() throws JSONException, EndPointException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(usagestatsBaseAddress + "/totals")
.build().encode();
ResponseEntity rs = restTemplate.getForObject(uriComponents.toUri(), ResponseEntity.class);
if(rs.getStatusCode().equals(HttpStatus.OK)){
JSONArray resultSet = (JSONArray) new JSONObject(rs.getBody()).getJSONArray("yearly_stats");
JSONObject lastYear = resultSet.getJSONObject(resultSet.length()-1);
Integer downloads = lastYear.getInt("downloads");
Integer views = lastYear.getInt("views");
String year = lastYear.getString("year");
JSONObject usagestats = new JSONObject();
usagestats.put("number",String.valueOf(downloads+views));
usagestats.put("year",year);
return usagestats;
}else
throw new EndPointException(uriComponents.toUri().toString());
}
private Integer getUsageStatsTotal() throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(usagestatsEvents)
.build().encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
JSONObject resultSet = new JSONObject(rs);
JSONObject totals = resultSet.getJSONObject("totals");
return Integer.valueOf(totals.getString("events"));
}
}

View File

@ -1,22 +1,12 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.service;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponse;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper; import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
import io.swagger.annotations.Api;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/sushilite")
@Api(description = "Sushi-Lite API", tags = {"sushilite"})
public interface SushiliteApi { public interface SushiliteApi {
@RequestMapping(value = "/getReportResults/{page}/{pageSize}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
ReportResponseWrapper getReportResults(String page, ReportResponseWrapper getReportResults(String page,
String pageSize, String pageSize,
String Report, String Report,

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.service;
import eu.dnetlib.usagestats.sushilite.domain.ReportItem; import eu.dnetlib.usagestats.sushilite.domain.ReportItem;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper; import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
@ -9,7 +9,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestClientException;
@ -19,7 +19,7 @@ import org.springframework.web.util.UriComponentsBuilder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Component @Service("sushiliteService")
public class SushiliteApiImpl implements SushiliteApi { public class SushiliteApiImpl implements SushiliteApi {

View File

@ -0,0 +1,9 @@
package eu.dnetlib.repo.manager.service;
import org.springframework.http.ResponseEntity;
public interface UserApi {
ResponseEntity<Object> login();
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.controllers; 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.springframework.beans.factory.annotation.Value;
@ -8,13 +8,14 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Service("userService")
public class UserApiImpl implements UserApi { public class UserApiImpl implements UserApi {
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
@ -24,7 +25,6 @@ public class UserApiImpl implements UserApi {
private String oidc_issuer; private String oidc_issuer;
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')")
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);

View File

@ -0,0 +1,42 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.domain.functionality.validator.RuleSet;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
import org.json.JSONException;
import org.springframework.http.ResponseEntity;
import java.util.List;
public interface ValidatorApi {
JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException;
ResponseEntity<Object> reSubmitJobForValidation(String email, String jobId) throws JSONException, ValidatorServiceException;
List<RuleSet> getRuleSets(String mode);
List<String> getSetsOfRepository(String url);
boolean identifyRepo(String url);
RuleSet getRuleSet(String acronym);
List<StoredJob> getStoredJobsNew(String user,
String jobType,
String offset,
String limit,
String dateFrom,
String dateTo,
String validationStatus) throws ValidatorServiceException;
int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException;
InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException;
}

View File

@ -1,18 +1,15 @@
package eu.dnetlib.repo.manager.service.controllers; package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorService;
import eu.dnetlib.api.functionality.ValidatorServiceException; import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.service.utils.OaiTools;
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
import gr.uoa.di.driver.util.ServiceLocator;
import eu.dnetlib.domain.functionality.validator.JobForValidation; import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.domain.functionality.validator.RuleSet; import eu.dnetlib.domain.functionality.validator.RuleSet;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.shared.Constants; import eu.dnetlib.repo.manager.shared.Constants;
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
import java.util.*; import eu.dnetlib.repo.manager.shared.ValidationServiceException;
import java.util.concurrent.ConcurrentHashMap; import eu.dnetlib.repo.manager.utils.OaiTools;
import eu.dnetlib.api.functionality.ValidatorService; import gr.uoa.di.driver.util.ServiceLocator;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.json.JSONException; import org.json.JSONException;
@ -22,16 +19,19 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@Component @Service("validatorService")
public class ValidatorApiImpl implements ValidatorApi{ public class ValidatorApiImpl implements ValidatorApi {
@Autowired @Autowired
private MonitorApiImpl monitorApi; private MonitorApiImpl monitorApi;

View File

@ -1,81 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.Term;
import eu.dnetlib.repo.manager.shared.broker.*;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/broker")
@Api(description = "Broker API", tags = {"broker"})
public interface BrokerApi {
@RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
DatasourcesBroker getDatasourcesOfUser(String user,String includeShared,String includeByOthers) throws BrokerException, JSONException;
@RequestMapping(value = "/getTopicsForDatasource/{datasourceName:.+}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException;
@RequestMapping(value = "/advancedShowEvents/{page}/{size}" , method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
EventsPage advancedShowEvents(String page,
String size,
AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException;
@RequestMapping(value = "/showEvents/{datasourceName:.+}/{topic}/{page}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
EventsPage showEvents(String datasourceName,
String topic,
String page,
String size) throws BrokerException, JSONException;
@RequestMapping(value = "/getSimpleSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(String userEmail) throws BrokerException;
@RequestMapping(value = "/subscribe" , method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Subscription subscribe(OpenaireSubscription obj) throws BrokerException;
@RequestMapping(value = "/unsubscribe/{subscriptionId}" , method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
ResponseEntity<Object> unsubscribe(String subscriptionId) throws BrokerException;
@RequestMapping(value = "/getSubscription/{subscriptionId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Subscription getSubscription(String subscriptionId) throws BrokerException;
@RequestMapping(value = "/getDnetTopics" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, Term> getDnetTopics() throws BrokerException;
@RequestMapping(value = "/getNotificationsBySubscriptionId/{subscriptionId}/{page}/{size}" , method = RequestMethod.GET
,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
EventsPage getNotificationsBySubscriptionId(String subscriptionId,String page,String size) throws BrokerException;
/*@RequestMapping(value = "/getSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET
,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody*/
Map<String, List<Subscription>> getSubscriptionsOfUser(String userEmail) throws BrokerException;
}

View File

@ -1,40 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.shared.JobsOfUser;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/monitor")
@Api(description = "Monitor API", tags = {"monitor"})
public interface MonitorApi {
@RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
JobsOfUser getJobsOfUser(String user,
String jobType,
String offset,
String limit,
String dateFrom,
String dateTo,
String validationStatus,
String includeJobsTotal) throws JSONException, ValidatorServiceException;
@RequestMapping(value = "/getJobsOfUserPerValidationStatus" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
int getJobsOfUserPerValidationStatus(@RequestBody String user,
@RequestBody String jobType,
@RequestBody String validationStatus) throws JSONException;
@RequestMapping(value = "/getJobSummary" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
StoredJob getJobSummary(@RequestBody String jobId,
@RequestBody String groupBy) throws JSONException;
}

View File

@ -1,46 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import io.swagger.annotations.Api;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/piwik")
@Api(description = "Piwik API", tags = {"piwik"})
public interface PiWikApi {
@RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
PiwikInfo getPiwikSiteForRepo(String repositoryId);
@RequestMapping(value = "/savePiwikInfo" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
PiwikInfo savePiwikInfo( PiwikInfo piwikInfo);
@RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
List<PiwikInfo> getPiwikSitesForRepos();
@RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET)
@ResponseBody
ResponseEntity<Object> approvePiwikSite(String repositoryId);
@RequestMapping(value = "/getOpenaireId/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String getOpenaireId(String repositoryid);
@RequestMapping(value = "/markPiwikSiteAsValidated/{repositoryId}" , method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
ResponseEntity<Object> markPiwikSiteAsValidated(String repositoryId) throws RepositoryServiceException;
@RequestMapping(value = "/enableMetricsForRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
PiwikInfo enableMetricsForRepository(String officialName,String repoWebsite,PiwikInfo piwikInfo) throws RepositoryServiceException;
}

View File

@ -1,148 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.repo.manager.service.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.service.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.shared.*;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/repository")
@Api(description = "Repository API", tags = {"repository"})
public interface RepositoryApi {
@RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Country[] getCountries() ;
@RequestMapping(value = "/getRepositoriesByCountry/{country}/{mode}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException;
@RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<Repository> getRepositoriesOfUser(String userEmail,
String page,
String size) throws JSONException;
@RequestMapping(value = "/getRepositoryById/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
@RequestMapping(value = "/getRepositoryAggregations/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException;
@RequestMapping(value = "/getRepositoryAggregationsByYear/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String,List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException;
@RequestMapping(value = "/getRepositoriesByName/{name:.+}/{page}/{size}/", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<Repository> getRepositoriesByName(String name,
String page,
String size) throws JSONException;
@RequestMapping(value = "/getRepositoryInterface/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
@RequestMapping(value = "/addRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Repository addRepository(String datatype, Repository repository) throws Exception;
@RequestMapping(value = "/deleteInterface/", method = RequestMethod.DELETE)
void deleteRepositoryInterface(String id,String registeredBy);
@RequestMapping(value = "/addInterface", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
String registeredBy,
RepositoryInterface iFace) throws JSONException,ResourceNotFoundException;
@RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getDnetCountries();
@RequestMapping(value = "/getTypologies", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getTypologies();
@RequestMapping(value = "/getTimezones", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<Timezone> getTimezones();
@RequestMapping(value = "/updateRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Repository updateRepository(Repository repository, Authentication authentication) throws Exception;
@RequestMapping(value = "/getUrlsOfUserRepos/{user_email}/{page}/{size}/",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getUrlsOfUserRepos(String user_email,
String page,
String size) throws JSONException;
@RequestMapping(value = "/getDatasourceVocabularies/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getDatasourceVocabularies(String mode);
@RequestMapping(value = "/getCompatibilityClasses/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, String> getCompatibilityClasses(String mode);
@RequestMapping(value = "/getDatasourceClasses/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, String> getDatasourceClasses(String mode);
String getCountryName(String countryCode);
@RequestMapping(value = "/getMetricsInfoForRepository/{repoId}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException;
@RequestMapping(value = "/getListLatestUpdate/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, String> getListLatestUpdate(String mode) throws RepositoryServiceException, JSONException;
@RequestMapping(value = "/updateRepositoryInterface", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
RepositoryInterface updateRepositoryInterface(String repositoryId,String registeredBy,RepositoryInterface repositoryInterface) throws JSONException;
}

View File

@ -1,152 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import com.mongodb.util.JSON;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
@Component
public class StatsApiImpl implements StatsApi {
private RestTemplate restTemplate = null;
private HttpHeaders httpHeaders;
private static final Logger LOGGER = Logger.getLogger(RepositoryApiImpl.class);
@Value("${search.api.baseAddress}")
private String baseAddress;
@Value("${search.api.usagestats}")
private String usagestatsBaseAddress;
@Value("${search.api.usageEvents}")
private String usagestatsEvents;
@PostConstruct
private void init() {
LOGGER.debug("Initialization method of statistics api!");
restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
}
@Override
public Map<String, Object> getStatistics() throws JSONException {
String aggregators = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" ( datasourcetypename exact Institutional Repository Aggregator " +
" or datasourcetypename exact Publication Repository Aggregator )");
String dataRepositories = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" datasourcetypename exact Data Repository " );
String literature = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" ( datasourcetypename exact Institutional Repository " +
" or datasourcetypename exact Publication Repository )");
String journal = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" datasourcetypename exact Journal");
String publications = getTotalByType("other",baseAddress,"/publications/count");
String datasets = getTotalByType("other",baseAddress,"/datasets/count");
String software = getTotalByType("other",baseAddress,"/software/count");
JSONObject lastYearUsagestats = getLastYearUsageStatsTotal();
Integer usagestats = getUsageStatsTotal();
HashMap<String,Object> stats = new HashMap<>();
stats.put("aggregators",aggregators);
stats.put("dataRepositories",dataRepositories);
stats.put("literature",literature);
stats.put("journal",journal);
stats.put("publications",publications);
stats.put("datasets",datasets);
stats.put("software",software);
stats.put("lastYearUsagestats",lastYearUsagestats.toString());
stats.put("usagestats",usagestats.toString());
return stats;
}
private String getTotalByType(String type,String url,String query) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url + query)
.queryParam("page",0)
.queryParam("size",0)
.queryParam("format","json")
.build().encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
if(type.equalsIgnoreCase("datasource")){
JSONObject metadata = (JSONObject) new JSONObject(rs).get("meta");
return String.valueOf(metadata.get("total"));
}else
return String.valueOf(new JSONObject(rs).get("total"));
}
private JSONObject getLastYearUsageStatsTotal() throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(usagestatsBaseAddress + "/totals")
.build().encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
JSONArray resultSet = (JSONArray) new JSONObject(rs).getJSONArray("yearly_stats");
JSONObject lastYear = resultSet.getJSONObject(resultSet.length()-1);
Integer downloads = lastYear.getInt("downloads");
Integer views = lastYear.getInt("views");
String year = lastYear.getString("year");
JSONObject usagestats = new JSONObject();
usagestats.put("number",String.valueOf(downloads+views));
usagestats.put("year",year);
return usagestats;
}
private Integer getUsageStatsTotal() throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(usagestatsEvents)
.build().encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
JSONObject resultSet = new JSONObject(rs);
JSONObject totals = resultSet.getJSONObject("totals");
return Integer.valueOf(totals.getString("events"));
}
}

View File

@ -1,69 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.domain.functionality.validator.RuleSet;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/validator")
@Api(description = "Validator API", tags = {"validator"})
public interface ValidatorApi {
@RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException;
@RequestMapping(value = "/reSubmitJobForValidation/{email}/{jobId}",method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
ResponseEntity<Object> reSubmitJobForValidation(String email,String jobId) throws JSONException, ValidatorServiceException;
@RequestMapping(value = "/getRuleSets/{mode}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<RuleSet> getRuleSets(String mode);
@RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getSetsOfRepository(String url);
@RequestMapping(value = "/identifyRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
boolean identifyRepo(String url);
@RequestMapping(value = "/getRuleSet/{acronym}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
RuleSet getRuleSet(String acronym);
@RequestMapping(value = "/getStoredJobsNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<StoredJob> getStoredJobsNew(String user,
String jobType,
String offset,
String limit,
String dateFrom,
String dateTo,
String validationStatus) throws ValidatorServiceException;
@RequestMapping(value = "/getStoredJobsTotalNumberNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException;
@RequestMapping(value = "/getInterfaceInformation" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException;
}

View File

@ -1,10 +1,10 @@
package eu.dnetlib.repo.manager.service.utils; 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.domain.data.Repository; import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface; import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.repo.manager.service.domain.RepositorySnippet; import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.shared.AggregationDetails; import eu.dnetlib.repo.manager.shared.AggregationDetails;
import eu.dnetlib.repo.manager.shared.Timezone; import eu.dnetlib.repo.manager.shared.Timezone;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.utils; package eu.dnetlib.repo.manager.utils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dom4j.io.DOMWriter; import org.dom4j.io.DOMWriter;

View File

@ -10,7 +10,7 @@
<context:component-scan base-package="eu.dnetlib.repo.manager.service.*"/> <context:component-scan base-package="eu.dnetlib.repo.manager.service.*"/>
<tx:annotation-driven transaction-manager="txManager"/> <tx:annotation-driven transaction-manager="txManager"/>
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" <bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader"
id="propertyLoader"> id="propertyLoader">
<property name="order" value="2"/> <property name="order" value="2"/>
<property name="properties"> <property name="properties">

View File

@ -42,7 +42,7 @@
<bean id="openIdConnectAuthenticationProvider" class="org.mitre.openid.connect.client.OIDCAuthenticationProvider"> <bean id="openIdConnectAuthenticationProvider" class="org.mitre.openid.connect.client.OIDCAuthenticationProvider">
<property name="authoritiesMapper"> <property name="authoritiesMapper">
<bean class="eu.dnetlib.repo.manager.service.config.OpenAireProviderAuthoritiesMapper"> <bean class="eu.dnetlib.repo.manager.config.OpenAireProviderAuthoritiesMapper">
<constructor-arg name="userRoles" ref="userRoles"/> <constructor-arg name="userRoles" ref="userRoles"/>
</bean> </bean>
</property> </property>
@ -54,7 +54,7 @@
</util:map> </util:map>
<bean class="eu.dnetlib.repo.manager.service.config.FrontEndLinkURIAuthenticationSuccessHandler" id="frontEndRedirect" <bean class="eu.dnetlib.repo.manager.config.FrontEndLinkURIAuthenticationSuccessHandler" id="frontEndRedirect"
init-method="init"> init-method="init">
<property name="frontEndURI" value="${webapp.dev.front}"/> <property name="frontEndURI" value="${webapp.dev.front}"/>
</bean> </bean>

View File

@ -36,7 +36,7 @@
<property name="debug" value="${services.validator.mail.debug}"/> <property name="debug" value="${services.validator.mail.debug}"/>
</bean> </bean>
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" <bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader"
id="propertyLoader"> id="propertyLoader">
<property name="order" value="2"/> <property name="order" value="2"/>
<property name="properties"> <property name="properties">
@ -94,6 +94,6 @@
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/> <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/> <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
<bean class="eu.dnetlib.repo.manager.service.config.SwaggerConfig"/> <bean class="eu.dnetlib.repo.manager.config.SwaggerConfig"/>
</beans> </beans>

View File

@ -2,7 +2,7 @@
package unitest; package unitest;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.repo.manager.service.config.RepoManagerContextLoaderListener; import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener;
import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringEscapeUtils;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;

View File

@ -1,12 +1,11 @@
package unitest; package unitest;
import eu.dnetlib.repo.manager.service.config.RepoManagerContextLoaderListener; import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener;
import eu.dnetlib.repo.manager.service.utils.OaiTools; import eu.dnetlib.repo.manager.utils.OaiTools;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = RepoManagerContextLoaderListener.class) @ContextConfiguration(classes = RepoManagerContextLoaderListener.class)

View File

@ -10,7 +10,7 @@
<context:component-scan base-package="eu.dnetlib.repo.manager.service.*"/> <context:component-scan base-package="eu.dnetlib.repo.manager.service.*"/>
<tx:annotation-driven transaction-manager="txManager"/> <tx:annotation-driven transaction-manager="txManager"/>
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" <bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader"
id="propertyLoader"> id="propertyLoader">
<property name="order" value="2"/> <property name="order" value="2"/>
<property name="properties"> <property name="properties">

View File

@ -36,7 +36,7 @@
<property name="debug" value="${services.validator.mail.debug}"/> <property name="debug" value="${services.validator.mail.debug}"/>
</bean> </bean>
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" <bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader"
id="propertyLoader"> id="propertyLoader">
<property name="order" value="2"/> <property name="order" value="2"/>
<property name="properties"> <property name="properties">
@ -94,6 +94,6 @@
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/> <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/> <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
<bean class="eu.dnetlib.repo.manager.service.config.SwaggerConfig"/> <bean class="eu.dnetlib.repo.manager.config.SwaggerConfig"/>
</beans> </beans>