- Fixing some code-smells

- Implemented search of piwik repos
- Added site_id info on repository
This commit is contained in:
Ioannis Diplas 2019-07-22 13:00:51 +00:00
parent ed247a82f3
commit 9d332bd962
16 changed files with 141 additions and 57 deletions

View File

@ -23,14 +23,14 @@ import java.util.Map;
public class BrokerController{ public class BrokerController{
@Autowired @Autowired
BrokerServiceImpl brokerService; private BrokerServiceImpl brokerService;
@RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.GET, @RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")
DatasourcesBroker getDatasourcesOfUser(@RequestParam("user") public DatasourcesBroker getDatasourcesOfUser(@RequestParam("user")
@ApiParam(value = "User email", required = true) String user, @ApiParam(value = "User email", required = true) String user,
@RequestParam("includeShared") @RequestParam("includeShared")
@ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared, @ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared,
@ -43,7 +43,7 @@ public class BrokerController{
method = RequestMethod.GET, method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException{ public List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException{
return brokerService.getTopicsForDatasource(datasourceName); return brokerService.getTopicsForDatasource(datasourceName);
} }
@ -52,7 +52,7 @@ public class BrokerController{
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")
EventsPage advancedShowEvents(@PathVariable("page") String page, public EventsPage advancedShowEvents(@PathVariable("page") String page,
@PathVariable("size") String size, @PathVariable("size") String size,
@RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException{ @RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException{
return brokerService.advancedShowEvents(page, size, advQueryObject); return brokerService.advancedShowEvents(page, size, advQueryObject);
@ -63,7 +63,7 @@ public class BrokerController{
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")
EventsPage showEvents(@RequestParam("datasourceName") String datasourceName, public EventsPage showEvents(@RequestParam("datasourceName") String datasourceName,
@RequestParam("topic") String topic, @RequestParam("topic") String topic,
@RequestParam("page") String page, @RequestParam("page") String page,
@RequestParam("size") String size) throws BrokerException, JSONException{ @RequestParam("size") String size) throws BrokerException, JSONException{
@ -75,7 +75,7 @@ public class BrokerController{
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")
Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException{ public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException{
return brokerService.getSimpleSubscriptionsOfUser(userEmail); return brokerService.getSimpleSubscriptionsOfUser(userEmail);
} }
@ -84,7 +84,7 @@ public class BrokerController{
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@PreAuthorize("hasRole('ROLE_USER') ") @PreAuthorize("hasRole('ROLE_USER') ")
Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException{ public Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException{
return brokerService.subscribe(obj); return brokerService.subscribe(obj);
} }
@ -93,7 +93,7 @@ public class BrokerController{
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")
ResponseEntity<Object> unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{ public ResponseEntity<Object> unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{
return brokerService.unsubscribe(subscriptionId); return brokerService.unsubscribe(subscriptionId);
} }
@ -101,7 +101,7 @@ public class BrokerController{
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@PreAuthorize("hasRole('ROLE_USER')") @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); return brokerService.getSubscription(subscriptionId);
} }
@ -109,7 +109,7 @@ public class BrokerController{
@RequestMapping(value = "/getDnetTopics" , method = RequestMethod.GET, @RequestMapping(value = "/getDnetTopics" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
Map<String, Term> getDnetTopics() throws BrokerException{ public Map<String, Term> getDnetTopics() throws BrokerException{
return brokerService.getDnetTopics(); return brokerService.getDnetTopics();
} }
@ -117,18 +117,10 @@ public class BrokerController{
,produces = MediaType.APPLICATION_JSON_VALUE) ,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")
EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId, public EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId,
@PathVariable("page") String page, @PathVariable("page") String page,
@PathVariable("size") String size) throws BrokerException{ @PathVariable("size") String size) throws BrokerException{
return brokerService.getNotificationsBySubscriptionId(subscriptionId, page, size); return brokerService.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 brokerService.getSubscriptionsOfUser(userEmail);
}
} }

View File

@ -17,7 +17,7 @@ import java.util.List;
public class DashboardController { public class DashboardController {
@Autowired @Autowired
DashboardService dashboardService; private DashboardService dashboardService;
@RequestMapping(value = "/getRepositoriesSummary/{userEmail}/{page}/{size}" , method = RequestMethod.GET, @RequestMapping(value = "/getRepositoriesSummary/{userEmail}/{page}/{size}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)

View File

@ -29,37 +29,36 @@ public class GenericControllerAdvice {
@ResponseStatus(HttpStatus.NOT_FOUND) @ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(ResourceNotFoundException.class) @ExceptionHandler(ResourceNotFoundException.class)
@ResponseBody @ResponseBody
ServerError securityException(HttpServletRequest req, Exception ex) { public ServerError securityException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex); return new ServerError(req.getRequestURL().toString(),ex);
} }
@ResponseStatus(HttpStatus.FORBIDDEN) @ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(AccessDeniedException.class) @ExceptionHandler(AccessDeniedException.class)
@ResponseBody @ResponseBody
ServerError accessDeniedException(HttpServletRequest req, Exception ex) { public ServerError accessDeniedException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex); return new ServerError(req.getRequestURL().toString(),ex);
} }
@ResponseStatus(HttpStatus.NOT_FOUND) @ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(UnknownHostException.class) @ExceptionHandler(UnknownHostException.class)
@ResponseBody @ResponseBody
ServerError unknownHostException(HttpServletRequest req, Exception ex) { public ServerError unknownHostException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex); return new ServerError(req.getRequestURL().toString(),ex);
} }
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler({JSONException.class,BrokerException.class,ValidatorServiceException.class}) @ExceptionHandler({JSONException.class,BrokerException.class,ValidatorServiceException.class})
@ResponseBody @ResponseBody
ServerError internalException(HttpServletRequest req, Exception ex) { public ServerError internalException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex); return new ServerError(req.getRequestURL().toString(),ex);
} }
@ResponseStatus(HttpStatus.GATEWAY_TIMEOUT) @ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
@ExceptionHandler(EndPointException.class) @ExceptionHandler(EndPointException.class)
@ResponseBody @ResponseBody
ServerError endPointException(HttpServletRequest req, Exception ex) { public ServerError endPointException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex); return new ServerError(req.getRequestURL().toString(),ex);
} }
} }

View File

@ -22,7 +22,7 @@ public class MonitorController {
.getLogger(MonitorController.class); .getLogger(MonitorController.class);
@Autowired @Autowired
MonitorServiceImpl monitorService; private MonitorServiceImpl monitorService;
@RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET, @RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)

View File

@ -1,6 +1,8 @@
package eu.dnetlib.repo.manager.controllers; package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.domain.data.PiwikInfo; 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.service.PiWikServiceImpl;
import eu.dnetlib.repo.manager.shared.RepositoryServiceException; import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -18,7 +20,7 @@ import java.util.List;
public class PiWikController { public class PiWikController {
@Autowired @Autowired
PiWikServiceImpl piWikService; private PiWikServiceImpl piWikService;
@RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @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) @RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
List<PiwikInfo> getPiwikSitesForRepos(){ public List<PiwikInfo> getPiwikSitesForRepos(
return piWikService.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) @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) @RequestMapping(value = "/getOpenaireId/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
String getOpenaireId(String repositoryid){ public String getOpenaireId(String repositoryid){
return piWikService.getOpenaireId(repositoryid); return piWikService.getOpenaireId(repositoryid);
} }

View File

@ -25,7 +25,7 @@ import java.util.Map;
public class RepositoryController { public class RepositoryController {
@Autowired @Autowired
RepositoryServiceImpl repositoryService; private RepositoryServiceImpl repositoryService;
@RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@ -118,21 +118,21 @@ public class RepositoryController {
@RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET, @RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
List<String> getDnetCountries(){ public List<String> getDnetCountries(){
return repositoryService.getDnetCountries(); return repositoryService.getDnetCountries();
} }
@RequestMapping(value = "/getTypologies", method = RequestMethod.GET, @RequestMapping(value = "/getTypologies", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
List<String> getTypologies(){ public List<String> getTypologies(){
return repositoryService.getTypologies(); return repositoryService.getTypologies();
} }
@RequestMapping(value = "/getTimezones", method = RequestMethod.GET, @RequestMapping(value = "/getTimezones", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
List<Timezone> getTimezones(){ public List<Timezone> getTimezones(){
return repositoryService.getTimezones(); return repositoryService.getTimezones();
} }

View File

@ -18,12 +18,12 @@ import java.util.Map;
public class StatsController { public class StatsController {
@Autowired @Autowired
StatsServiceImpl statsService; private StatsServiceImpl statsService;
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET, @RequestMapping(value = "/getStatistics" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
public Map getStatistics() throws JSONException { public Map getStatistics(){
return statsService.getStatistics(); return statsService.getStatistics();
} }
} }

View File

@ -15,7 +15,7 @@ public class SushiliteController {
@Autowired @Autowired
SushiliteServiceImpl sushiliteService; private SushiliteServiceImpl sushiliteService;
@RequestMapping(value = "/getReportResults/{page}/{pageSize}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/getReportResults/{page}/{pageSize}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody

View File

@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
public class UserController { public class UserController {
@Autowired @Autowired
UserServiceImpl userService; private UserServiceImpl userService;
@RequestMapping(value = "/login" , method = RequestMethod.GET) @RequestMapping(value = "/login" , method = RequestMethod.GET)
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")

View File

@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.*;
public class ValidatorController { public class ValidatorController {
@Autowired @Autowired
ValidatorServiceImpl validatorService; private ValidatorServiceImpl validatorService;
@RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST, @RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE,

View File

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

View File

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

View File

@ -59,9 +59,7 @@ public class BrokerServiceImpl implements BrokerService {
httpHeaders.set("Content-Type", "application/json"); httpHeaders.set("Content-Type", "application/json");
LOGGER.debug("Init dnet topics!"); LOGGER.debug("Init dnet topics!");
InputStream is = null; try (InputStream is = new URL(topicsURL).openStream() ){
try {
is = new URL(topicsURL).openStream();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(is); JsonNode root = mapper.readTree(is);
for (JsonNode term : root.path("terms") ) for (JsonNode term : root.path("terms") )

View File

@ -2,6 +2,8 @@ package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.PiwikInfo; 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 eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -14,7 +16,7 @@ public interface PiWikService {
PiwikInfo savePiwikInfo(PiwikInfo piwikInfo); PiwikInfo savePiwikInfo(PiwikInfo piwikInfo);
List<PiwikInfo> getPiwikSitesForRepos(); List<PiwikInfo> getPiwikSitesForRepos(OrderByField orderByField, OrderByType orderByType, int from, int quantity, String searchField);
ResponseEntity<Object> approvePiwikSite(String repositoryId); ResponseEntity<Object> approvePiwikSite(String repositoryId);

View File

@ -2,6 +2,9 @@ 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;
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 eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -12,8 +15,11 @@ import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus; 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.PreparedStatementSetter;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service; 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;
@ -24,9 +30,13 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Service("piwikService") @Service("piwikService")
public class PiWikServiceImpl implements PiWikService { public class PiWikServiceImpl implements PiWikService {
@ -40,6 +50,9 @@ public class PiWikServiceImpl implements PiWikService {
private String analyticsURL; private String analyticsURL;
@Autowired
private RepositoryService repositoryService;
@Autowired @Autowired
@Qualifier("emailUtils") @Qualifier("emailUtils")
EmailUtils 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 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 = ?;"; 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 @Override
public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) { public PiwikInfo getPiwikSiteForRepo(String repositoryId) {
try{ try{
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper); return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper);
}catch (EmptyResultDataAccessException e){ }catch (EmptyResultDataAccessException e){
@ -73,7 +86,7 @@ public class PiWikServiceImpl implements PiWikService {
@Override @Override
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN') or (hasRole('ROLE_USER') and #piwikInfo.requestorEmail == authentication.userInfo.email)") @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 jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.update(INSERT_PIWIK_INFO, new Object[]{piwikInfo.getRepositoryId(), piwikInfo.getSiteId(), piwikInfo.getRequestorName(), jdbcTemplate.update(INSERT_PIWIK_INFO, new Object[]{piwikInfo.getRepositoryId(), piwikInfo.getSiteId(), piwikInfo.getRequestorName(),
piwikInfo.getRequestorEmail(), piwikInfo.isValidated(), piwikInfo.getRepositoryName(), piwikInfo.getCountry(), piwikInfo.getAuthenticationToken()}, piwikInfo.getRequestorEmail(), piwikInfo.isValidated(), piwikInfo.getRepositoryName(), piwikInfo.getCountry(), piwikInfo.getAuthenticationToken()},
@ -82,10 +95,30 @@ public class PiWikServiceImpl implements PiWikService {
} }
@Override @Override
public List<PiwikInfo> getPiwikSitesForRepos() { public List<PiwikInfo> getPiwikSitesForRepos(OrderByField orderByField, OrderByType orderByType, int from, int quantity, String searchField) {
LOGGER.debug("Getting piwik sites for repos! "); LOGGER.debug("Getting piwik sites for repos! ");
try{ 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){ }catch (EmptyResultDataAccessException e){
return null; return null;
} }
@ -94,13 +127,13 @@ public class PiWikServiceImpl implements PiWikService {
@Override @Override
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')")
public ResponseEntity<Object> approvePiwikSite(@PathVariable("repositoryId") String repositoryId) { public ResponseEntity<Object> approvePiwikSite(String repositoryId) {
new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR}); new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR});
return new ResponseEntity<>("OK",HttpStatus.OK); return new ResponseEntity<>("OK",HttpStatus.OK);
} }
@Override @Override
public String getOpenaireId(@PathVariable("repositoryId") String repositoryId) { public String getOpenaireId(String repositoryId) {
if (repositoryId != null && repositoryId.contains("::")) if (repositoryId != null && repositoryId.contains("::"))
return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]); return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]);
return null; return null;
@ -108,7 +141,7 @@ public class PiWikServiceImpl implements PiWikService {
@Override @Override
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')")
public ResponseEntity<Object> markPiwikSiteAsValidated(@PathVariable("repositoryId") String repositoryId) throws RepositoryServiceException { public ResponseEntity<Object> markPiwikSiteAsValidated(String repositoryId) throws RepositoryServiceException {
try { try {
approvePiwikSite(repositoryId); approvePiwikSite(repositoryId);
@ -129,9 +162,9 @@ public class PiWikServiceImpl implements PiWikService {
@Override @Override
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN') or (hasRole('ROLE_USER') and #piwikInfo.requestorEmail == authentication.userInfo.email)") @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, public PiwikInfo enableMetricsForRepository(String officialName,
@RequestParam("repoWebsite") String repoWebsite, String repoWebsite,
@RequestBody PiwikInfo piwikInfo) throws RepositoryServiceException { PiwikInfo piwikInfo) throws RepositoryServiceException {
try { try {
String URL = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url=" String URL = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url="
+ URLEncoder.encode(repoWebsite, "UTF-8"); + URLEncoder.encode(repoWebsite, "UTF-8");
@ -143,6 +176,12 @@ public class PiWikServiceImpl implements PiWikService {
piwikInfo.setSiteId(siteId); piwikInfo.setSiteId(siteId);
savePiwikInfo(piwikInfo); savePiwikInfo(piwikInfo);
Repository repository = repositoryService.getRepositoryById(piwikInfo.getRepositoryId());
repository.setPiwikInfo(piwikInfo);
repositoryService.updateRepository(repository, SecurityContextHolder.getContext().getAuthentication());
emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo); emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo);
emailUtils.sendUserRequestToEnableMetrics(piwikInfo); emailUtils.sendUserRequestToEnableMetrics(piwikInfo);
} catch (UnsupportedEncodingException uee) { } catch (UnsupportedEncodingException uee) {

View File

@ -281,8 +281,9 @@ public class Converter {
//TODO check identitites //TODO check identitites
//Map<String,String> identity = new HashMap<>(); //Map<String,String> identity = new HashMap<>();
List identities = new ArrayList(); Map<String, Object> identities = new HashMap<>();
// identities.add(identities); identities.put("issuertype", "piwik");
identities.put("pid","piwik:"+repository.getPiwikInfo().getSiteId());
repositoryMap.put("identities",identities); repositoryMap.put("identities",identities);
repositoryMap.put("subjects",""); repositoryMap.put("subjects","");