- Fixing some code-smells
- Implemented search of piwik repos - Added site_id info on repository
This commit is contained in:
parent
ed247a82f3
commit
9d332bd962
|
@ -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<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException{
|
||||
public List<BrowseEntry> 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<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);
|
||||
}
|
||||
|
||||
|
@ -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<Object> unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{
|
||||
public ResponseEntity<Object> 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<String, Term> getDnetTopics() throws BrokerException{
|
||||
public Map<String, Term> 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<String, List<Subscription>> getSubscriptionsOfUser(String userEmail) throws BrokerException{
|
||||
return brokerService.getSubscriptionsOfUser(userEmail);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<PiwikInfo> getPiwikSitesForRepos(){
|
||||
return piWikService.getPiwikSitesForRepos();
|
||||
public List<PiwikInfo> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> getDnetCountries(){
|
||||
public List<String> getDnetCountries(){
|
||||
return repositoryService.getDnetCountries();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getTypologies", method = RequestMethod.GET,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
List<String> getTypologies(){
|
||||
public List<String> getTypologies(){
|
||||
return repositoryService.getTypologies();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getTimezones", method = RequestMethod.GET,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
List<Timezone> getTimezones(){
|
||||
public List<Timezone> getTimezones(){
|
||||
return repositoryService.getTimezones();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')")
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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") )
|
||||
|
|
|
@ -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<PiwikInfo> getPiwikSitesForRepos();
|
||||
List<PiwikInfo> getPiwikSitesForRepos(OrderByField orderByField, OrderByType orderByType, int from, int quantity, String searchField);
|
||||
|
||||
ResponseEntity<Object> approvePiwikSite(String repositoryId);
|
||||
|
||||
|
|
|
@ -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<PiwikInfo> getPiwikSitesForRepos() {
|
||||
public List<PiwikInfo> 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<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});
|
||||
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<Object> markPiwikSiteAsValidated(@PathVariable("repositoryId") String repositoryId) throws RepositoryServiceException {
|
||||
public ResponseEntity<Object> 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) {
|
||||
|
|
|
@ -281,8 +281,9 @@ public class Converter {
|
|||
|
||||
//TODO check identitites
|
||||
//Map<String,String> identity = new HashMap<>();
|
||||
List identities = new ArrayList();
|
||||
// identities.add(identities);
|
||||
Map<String, Object> identities = new HashMap<>();
|
||||
identities.put("issuertype", "piwik");
|
||||
identities.put("pid","piwik:"+repository.getPiwikInfo().getSiteId());
|
||||
repositoryMap.put("identities",identities);
|
||||
repositoryMap.put("subjects","");
|
||||
|
||||
|
|
Loading…
Reference in New Issue