diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/BrokerController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/BrokerController.java index d630bc8..0515905 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/BrokerController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/BrokerController.java @@ -23,14 +23,14 @@ import java.util.Map; public class BrokerController{ @Autowired - BrokerServiceImpl brokerService; + private BrokerServiceImpl brokerService; @RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('ROLE_USER')") - DatasourcesBroker getDatasourcesOfUser(@RequestParam("user") + 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, @@ -43,7 +43,7 @@ public class BrokerController{ method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - List getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException{ + public List getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException{ return brokerService.getTopicsForDatasource(datasourceName); } @@ -52,7 +52,7 @@ public class BrokerController{ produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('ROLE_USER')") - EventsPage advancedShowEvents(@PathVariable("page") String page, + public EventsPage advancedShowEvents(@PathVariable("page") String page, @PathVariable("size") String size, @RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException{ return brokerService.advancedShowEvents(page, size, advQueryObject); @@ -63,7 +63,7 @@ public class BrokerController{ produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('ROLE_USER')") - EventsPage showEvents(@RequestParam("datasourceName") String datasourceName, + public EventsPage showEvents(@RequestParam("datasourceName") String datasourceName, @RequestParam("topic") String topic, @RequestParam("page") String page, @RequestParam("size") String size) throws BrokerException, JSONException{ @@ -75,7 +75,7 @@ public class BrokerController{ produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('ROLE_USER')") - Map> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException{ + public Map> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException{ return brokerService.getSimpleSubscriptionsOfUser(userEmail); } @@ -84,7 +84,7 @@ public class BrokerController{ produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('ROLE_USER') ") - Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException{ + public Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException{ return brokerService.subscribe(obj); } @@ -93,7 +93,7 @@ public class BrokerController{ produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('ROLE_USER')") - ResponseEntity unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{ + public ResponseEntity unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{ return brokerService.unsubscribe(subscriptionId); } @@ -101,7 +101,7 @@ public class BrokerController{ produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('ROLE_USER')") - Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{ + public Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{ return brokerService.getSubscription(subscriptionId); } @@ -109,7 +109,7 @@ public class BrokerController{ @RequestMapping(value = "/getDnetTopics" , method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - Map getDnetTopics() throws BrokerException{ + public Map getDnetTopics() throws BrokerException{ return brokerService.getDnetTopics(); } @@ -117,18 +117,10 @@ public class BrokerController{ ,produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @PreAuthorize("hasRole('ROLE_USER')") - EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId, + public EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId, @PathVariable("page") String page, @PathVariable("size") String size) throws BrokerException{ return brokerService.getNotificationsBySubscriptionId(subscriptionId, page, size); } - /*@RequestMapping(value = "/getSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET - ,produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody*/ - Map> getSubscriptionsOfUser(String userEmail) throws BrokerException{ - return brokerService.getSubscriptionsOfUser(userEmail); - } - - } diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java index 3c9befc..00e1beb 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java @@ -17,7 +17,7 @@ import java.util.List; public class DashboardController { @Autowired - DashboardService dashboardService; + private DashboardService dashboardService; @RequestMapping(value = "/getRepositoriesSummary/{userEmail}/{page}/{size}" , method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/GenericControllerAdvice.java b/src/main/java/eu/dnetlib/repo/manager/controllers/GenericControllerAdvice.java index f02f0b2..ce2f810 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/GenericControllerAdvice.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/GenericControllerAdvice.java @@ -29,37 +29,36 @@ public class GenericControllerAdvice { @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(ResourceNotFoundException.class) @ResponseBody - ServerError securityException(HttpServletRequest req, Exception ex) { + public 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) { + public 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) { + public 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) { + public 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) { + public ServerError endPointException(HttpServletRequest req, Exception ex) { return new ServerError(req.getRequestURL().toString(),ex); } - } diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/MonitorController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/MonitorController.java index fe7d32a..2d7540e 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/MonitorController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/MonitorController.java @@ -22,7 +22,7 @@ public class MonitorController { .getLogger(MonitorController.class); @Autowired - MonitorServiceImpl monitorService; + private MonitorServiceImpl monitorService; @RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/PiWikController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/PiWikController.java index 571fec2..2e4dd5b 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/PiWikController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/PiWikController.java @@ -1,6 +1,8 @@ package eu.dnetlib.repo.manager.controllers; import eu.dnetlib.domain.data.PiwikInfo; +import eu.dnetlib.repo.manager.domain.OrderByField; +import eu.dnetlib.repo.manager.domain.OrderByType; import eu.dnetlib.repo.manager.service.PiWikServiceImpl; import eu.dnetlib.repo.manager.shared.RepositoryServiceException; import io.swagger.annotations.Api; @@ -18,7 +20,7 @@ import java.util.List; public class PiWikController { @Autowired - PiWikServiceImpl piWikService; + private PiWikServiceImpl piWikService; @RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @@ -35,8 +37,15 @@ public class PiWikController { } @RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) - List getPiwikSitesForRepos(){ - return piWikService.getPiwikSitesForRepos(); + public List getPiwikSitesForRepos( + @RequestParam(value = "from",required=false,defaultValue = "0") int from, + @RequestParam(value = "quantity",required=false,defaultValue = "100") int quantity, + @RequestParam(value = "order",required=false,defaultValue = "ASC") OrderByType orderType, + @RequestParam(value = "orderField", required = false, defaultValue = "REPOSITORY_NAME") OrderByField orderField, + @RequestParam(value = "searchField", required = false, defaultValue = "") String searchField + + ){ + return piWikService.getPiwikSitesForRepos(orderField,orderType,from,quantity,searchField); } @RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET) @@ -48,7 +57,7 @@ public class PiWikController { @RequestMapping(value = "/getOpenaireId/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - String getOpenaireId(String repositoryid){ + public String getOpenaireId(String repositoryid){ return piWikService.getOpenaireId(repositoryid); } diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java index ecb15b3..de661d6 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java @@ -25,7 +25,7 @@ import java.util.Map; public class RepositoryController { @Autowired - RepositoryServiceImpl repositoryService; + private RepositoryServiceImpl repositoryService; @RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody @@ -118,21 +118,21 @@ public class RepositoryController { @RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - List getDnetCountries(){ + public List getDnetCountries(){ return repositoryService.getDnetCountries(); } @RequestMapping(value = "/getTypologies", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - List getTypologies(){ + public List getTypologies(){ return repositoryService.getTypologies(); } @RequestMapping(value = "/getTimezones", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - List getTimezones(){ + public List getTimezones(){ return repositoryService.getTimezones(); } diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/StatsController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/StatsController.java index 576331a..10e8925 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/StatsController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/StatsController.java @@ -18,12 +18,12 @@ import java.util.Map; public class StatsController { @Autowired - StatsServiceImpl statsService; + private StatsServiceImpl statsService; @RequestMapping(value = "/getStatistics" , method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - public Map getStatistics() throws JSONException { + public Map getStatistics(){ return statsService.getStatistics(); } } diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/SushiliteController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/SushiliteController.java index 1ed4967..7f934d5 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/SushiliteController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/SushiliteController.java @@ -15,7 +15,7 @@ public class SushiliteController { @Autowired - SushiliteServiceImpl sushiliteService; + private SushiliteServiceImpl sushiliteService; @RequestMapping(value = "/getReportResults/{page}/{pageSize}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/UserController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/UserController.java index c45831f..a7641a2 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/UserController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/UserController.java @@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController; public class UserController { @Autowired - UserServiceImpl userService; + private UserServiceImpl userService; @RequestMapping(value = "/login" , method = RequestMethod.GET) @PreAuthorize("hasRole('ROLE_USER')") diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/ValidatorController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/ValidatorController.java index 2b9c8cc..1addfcc 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/ValidatorController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/ValidatorController.java @@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.*; public class ValidatorController { @Autowired - ValidatorServiceImpl validatorService; + private ValidatorServiceImpl validatorService; @RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, diff --git a/src/main/java/eu/dnetlib/repo/manager/domain/OrderByField.java b/src/main/java/eu/dnetlib/repo/manager/domain/OrderByField.java new file mode 100644 index 0000000..13cba54 --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/domain/OrderByField.java @@ -0,0 +1,26 @@ +package eu.dnetlib.repo.manager.domain; + +public enum OrderByField { + + REPOSITORY_NAME("repositoryname"), + REPOSITORY_ID("repositoryid"), + SITE_ID("siteid"), + CREATION_DATE("creationdate"), + VALIDATION_DATE("validationdate"), + REQUESTOR_NAME("requestorname"), + REQUESTOR_EMAIL("requestoremail"), + VALIDATED("validated"), + COUNTRY("country"); + + + private final String text; + + OrderByField(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } +} diff --git a/src/main/java/eu/dnetlib/repo/manager/domain/OrderByType.java b/src/main/java/eu/dnetlib/repo/manager/domain/OrderByType.java new file mode 100644 index 0000000..920ca14 --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/domain/OrderByType.java @@ -0,0 +1,18 @@ +package eu.dnetlib.repo.manager.domain; + +public enum OrderByType { + + ASC("ASC"), + DSC("DESC"); + + private final String text; + + OrderByType(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } +} diff --git a/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java index 3bea73d..5a82b3c 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java @@ -59,9 +59,7 @@ public class BrokerServiceImpl implements BrokerService { httpHeaders.set("Content-Type", "application/json"); LOGGER.debug("Init dnet topics!"); - InputStream is = null; - try { - is = new URL(topicsURL).openStream(); + try (InputStream is = new URL(topicsURL).openStream() ){ ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(is); for (JsonNode term : root.path("terms") ) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/PiWikService.java b/src/main/java/eu/dnetlib/repo/manager/service/PiWikService.java index 5916aa4..22ef42a 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/PiWikService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/PiWikService.java @@ -2,6 +2,8 @@ package eu.dnetlib.repo.manager.service; import eu.dnetlib.domain.data.PiwikInfo; +import eu.dnetlib.repo.manager.domain.OrderByField; +import eu.dnetlib.repo.manager.domain.OrderByType; import eu.dnetlib.repo.manager.shared.RepositoryServiceException; import org.springframework.http.ResponseEntity; @@ -14,7 +16,7 @@ public interface PiWikService { PiwikInfo savePiwikInfo(PiwikInfo piwikInfo); - List getPiwikSitesForRepos(); + List getPiwikSitesForRepos(OrderByField orderByField, OrderByType orderByType, int from, int quantity, String searchField); ResponseEntity approvePiwikSite(String repositoryId); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java index b2e768e..08f4673 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java @@ -2,6 +2,9 @@ package eu.dnetlib.repo.manager.service; import com.fasterxml.jackson.databind.ObjectMapper; import eu.dnetlib.domain.data.PiwikInfo; +import eu.dnetlib.domain.data.Repository; +import eu.dnetlib.repo.manager.domain.OrderByField; +import eu.dnetlib.repo.manager.domain.OrderByType; import eu.dnetlib.repo.manager.shared.RepositoryServiceException; import org.apache.commons.codec.digest.DigestUtils; import org.apache.log4j.Logger; @@ -12,8 +15,11 @@ import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -24,9 +30,13 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLEncoder; +import java.sql.PreparedStatement; +import java.sql.SQLException; import java.sql.Types; +import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Service("piwikService") public class PiWikServiceImpl implements PiWikService { @@ -40,6 +50,9 @@ public class PiWikServiceImpl implements PiWikService { private String analyticsURL; + @Autowired + private RepositoryService repositoryService; + @Autowired @Qualifier("emailUtils") EmailUtils emailUtils; @@ -51,7 +64,7 @@ public class PiWikServiceImpl implements PiWikService { private final static String INSERT_PIWIK_INFO = "insert into piwik_site (repositoryid, siteid, creationdate, requestorname, requestoremail, validated, repositoryname, country, authenticationtoken) values (?, ?, now(), ?, ?, ?, ?, ?, ?)"; - private final static String GET_PIWIK_SITES = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site order by repositoryname"; + private final static String GET_PIWIK_SITES = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site "; private final static String APPROVE_PIWIK_SITE = "update piwik_site set validated=true, validationdate=now() where repositoryid = ?;"; @@ -63,7 +76,7 @@ public class PiWikServiceImpl implements PiWikService { @Override - public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) { + public PiwikInfo getPiwikSiteForRepo(String repositoryId) { try{ return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper); }catch (EmptyResultDataAccessException e){ @@ -73,7 +86,7 @@ public class PiWikServiceImpl implements PiWikService { @Override @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN') or (hasRole('ROLE_USER') and #piwikInfo.requestorEmail == authentication.userInfo.email)") - public PiwikInfo savePiwikInfo(@RequestBody PiwikInfo piwikInfo) { + public PiwikInfo savePiwikInfo(PiwikInfo piwikInfo) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update(INSERT_PIWIK_INFO, new Object[]{piwikInfo.getRepositoryId(), piwikInfo.getSiteId(), piwikInfo.getRequestorName(), piwikInfo.getRequestorEmail(), piwikInfo.isValidated(), piwikInfo.getRepositoryName(), piwikInfo.getCountry(), piwikInfo.getAuthenticationToken()}, @@ -82,10 +95,30 @@ public class PiWikServiceImpl implements PiWikService { } @Override - public List getPiwikSitesForRepos() { + public List getPiwikSitesForRepos(OrderByField orderByField, OrderByType orderByType, int from, int quantity, String searchField) { LOGGER.debug("Getting piwik sites for repos! "); try{ - return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper); + String finalizedQuery = GET_PIWIK_SITES + " where ("+ + " repositoryid ilike ? " + + " or siteid ilike ?" + + " or requestorname ilike ?" + + " or requestoremail ilike ?" + + " or comment ilike ?" + + " or repositoryname ilike ?"+ + " or country ilike ?" + +") order by "+orderByField + " " + orderByType + " offset ? limit ?"; + + return new JdbcTemplate(dataSource).query(finalizedQuery, preparedStatement -> { + preparedStatement.setString(1,"%"+searchField+"%"); + preparedStatement.setString(2,"%"+searchField+"%"); + preparedStatement.setString(3,"%"+searchField+"%"); + preparedStatement.setString(4,"%"+searchField+"%"); + preparedStatement.setString(5,"%"+searchField+"%"); + preparedStatement.setString(6,"%"+searchField+"%"); + preparedStatement.setString(7,"%"+searchField+"%"); + preparedStatement.setInt(8,from); + preparedStatement.setInt(9,quantity); + }, piwikRowMapper); }catch (EmptyResultDataAccessException e){ return null; } @@ -94,13 +127,13 @@ public class PiWikServiceImpl implements PiWikService { @Override @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')") - public ResponseEntity approvePiwikSite(@PathVariable("repositoryId") String repositoryId) { + public ResponseEntity approvePiwikSite(String repositoryId) { new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR}); return new ResponseEntity<>("OK",HttpStatus.OK); } @Override - public String getOpenaireId(@PathVariable("repositoryId") String repositoryId) { + public String getOpenaireId(String repositoryId) { if (repositoryId != null && repositoryId.contains("::")) return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]); return null; @@ -108,7 +141,7 @@ public class PiWikServiceImpl implements PiWikService { @Override @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')") - public ResponseEntity markPiwikSiteAsValidated(@PathVariable("repositoryId") String repositoryId) throws RepositoryServiceException { + public ResponseEntity markPiwikSiteAsValidated(String repositoryId) throws RepositoryServiceException { try { approvePiwikSite(repositoryId); @@ -129,9 +162,9 @@ public class PiWikServiceImpl implements PiWikService { @Override @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_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 { + public PiwikInfo enableMetricsForRepository(String officialName, + String repoWebsite, + PiwikInfo piwikInfo) throws RepositoryServiceException { try { String URL = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url=" + URLEncoder.encode(repoWebsite, "UTF-8"); @@ -143,6 +176,12 @@ public class PiWikServiceImpl implements PiWikService { piwikInfo.setSiteId(siteId); savePiwikInfo(piwikInfo); + + Repository repository = repositoryService.getRepositoryById(piwikInfo.getRepositoryId()); + repository.setPiwikInfo(piwikInfo); + + repositoryService.updateRepository(repository, SecurityContextHolder.getContext().getAuthentication()); + emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo); emailUtils.sendUserRequestToEnableMetrics(piwikInfo); } catch (UnsupportedEncodingException uee) { diff --git a/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java b/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java index 2922ed7..f41ddc7 100644 --- a/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java +++ b/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java @@ -281,8 +281,9 @@ public class Converter { //TODO check identitites //Map identity = new HashMap<>(); - List identities = new ArrayList(); -// identities.add(identities); + Map identities = new HashMap<>(); + identities.put("issuertype", "piwik"); + identities.put("pid","piwik:"+repository.getPiwikInfo().getSiteId()); repositoryMap.put("identities",identities); repositoryMap.put("subjects","");