Delete wrong commited files

This commit is contained in:
Panagiotis Kanakakis 2019-02-16 10:47:48 +00:00
parent ef441e826c
commit 2a24630a1d
19 changed files with 0 additions and 2951 deletions

View File

@ -1,62 +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.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.POST,produces = MediaType.APPLICATION_JSON_VALUE)
DatasourcesBroker getDatasourcesOfUser(@RequestBody String params) throws BrokerException, JSONException;
@RequestMapping(value = "/getTopicsForDatasource/{datasourceName}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException;
@RequestMapping(value = "/advancedShowEvents" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
EventsPage advancedShowEvents(@RequestBody String params) throws BrokerException, JSONException ,IOException;
@RequestMapping(value = "/showEvents" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
EventsPage showEvents(@RequestBody String params) 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.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException;
@RequestMapping(value = "/unsubscribe/{subscriptionId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
void unsubscribe(String subscriptionId) throws BrokerException;
@RequestMapping(value = "/getSubscription/{subscriptionId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Subscription getSubscription(@PathVariable("subscriptionId") 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,403 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.Term;
import eu.dnetlib.repo.manager.shared.Tuple;
import eu.dnetlib.repo.manager.shared.broker.*;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
@Component
public class BrokerApiImpl implements BrokerApi {
@Autowired
private RepositoryApiImpl repoAPI;
@Value("${services.broker.url}:${services.broker.port}/${services.broker.api}${services.broker.openaire}")
private String openairePath;
@Value("${services.broker.url}:${services.broker.port}/${services.broker.api}")
private String apiPath;
@Value("${topic_types.url}")
private String topicsURL;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
.getLogger(BrokerApiImpl.class);
private RestTemplate restTemplate = null;
private HttpHeaders httpHeaders;
private HashMap<String,Term> topics = new HashMap<String, Term>();
@PostConstruct
private void initDnetTopicsMap() {
restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
LOGGER.debug("Init dnet topics!");
InputStream is = null;
try {
is = new URL(topicsURL).openStream();
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(is);
for (JsonNode term : root.path("terms") )
topics.put(term.path("code").textValue(), parseTerm(term));
} catch (IOException e) {
LOGGER.debug(e);
e.printStackTrace();
}
}
private Term parseTerm(JsonNode term) {
return new Term(term.path("englishName").textValue(),term.path("nativeName").textValue(),
term.path("encoding").textValue(),term.path("code").textValue());
}
@Override
public DatasourcesBroker getDatasourcesOfUser(String params) throws JSONException {
JSONObject json_params = new JSONObject(params);
DatasourcesBroker ret = new DatasourcesBroker();
String userEmail = json_params.getString("userEmail");
boolean includeShared = Boolean.parseBoolean( json_params.getString("includeShared") );
boolean includeByOthers = Boolean.parseBoolean( json_params.getString("includeByOthers") );
try {
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(userEmail)));
if (includeShared) {
//TODO whatever nikonas was saying
List<String> sharedDatasourceIds = new ArrayList<String>();
ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds)));
}
if (includeByOthers) {
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(userEmail)));
}
} catch (BrokerException e) {
e.printStackTrace();
}
return ret;
}
@Override
public List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException {
final String service = "/topicsForDatasource";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("ds", datasourceName);
ResponseEntity<List<BrowseEntry>> resp;
try {
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<BrowseEntry>>() {
});
} catch (RestClientException e) {
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public EventsPage advancedShowEvents(String params) throws BrokerException, JSONException ,IOException {
JSONObject json_params = new JSONObject(params);
String page = json_params.getString("page");
String pagesize = json_params.getString("pagesize");
String json_advQueryObject = json_params.getString("advQueryObject");
ObjectMapper mapper = new ObjectMapper();
AdvQueryObject advQueryObject = mapper.readValue(json_advQueryObject, AdvQueryObject.class);
final String service = "/events/{page}/{pageSize}";
Map<String, Long> uriParams = new HashMap<>();
uriParams.put("page", Long.parseLong(page));
uriParams.put("pageSize", Long.parseLong(pagesize));
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Content-Type", "application/json");
advQueryObject.setPage(Long.parseLong(page));
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, headers);
ResponseEntity<EventsPage> resp;
try {
resp = restTemplate.exchange(
builder.buildAndExpand(uriParams).encode().toUri(),
HttpMethod.POST,
entity,
new ParameterizedTypeReference<EventsPage>() {
}
);
} catch (RestClientException e) {
throw new BrokerException(e);
}
return resp.getBody();
}
private List<Tuple<BrowseEntry, String>> getDatasourcesOfUserType(List<Repository> repositories) throws BrokerException {
List<Tuple<BrowseEntry, String>> entries = new ArrayList<>();
for (Repository repo : repositories) {
BrowseEntry temp = new BrowseEntry();
temp.setValue(repo.getOfficialName());
temp.setSize(new Long(0));
for (BrowseEntry e : getTopicsForDatasource(repo.getOfficialName())) {
temp.setSize(temp.getSize() + e.getSize());
}
Tuple<BrowseEntry, String> tup = new Tuple<>(temp, repo.getLogoUrl());
entries.add(tup);
}
// sort the collection by the second field of the tuple which is size
Collections.sort(entries, new Comparator<Tuple<BrowseEntry, String>>() {
@Override
public int compare(Tuple<BrowseEntry, String> e1, Tuple<BrowseEntry, String> e2) {
return (int) (e2.getFirst().getSize().longValue() - e1.getFirst().getSize().longValue());
}
});
return entries;
}
private List<Repository> getRepositoriesOfUser(String userEmail) throws JSONException {
int page = 0;
int size = 50;
List<Repository> rs ;
List<Repository> resultSet = new ArrayList<>();
while (true){
rs = repoAPI.getRepositoriesOfUser(userEmail, String.valueOf(page), String.valueOf(size));
resultSet.addAll(rs);
page+=1;
if(rs.size() == 0) break;
}
return resultSet;
}
private List<Repository> getRepositoriesByIds(List<String> sharedDatasourceIds) {
return null;
}
@Override
public EventsPage showEvents(String params) throws BrokerException, JSONException {
JSONObject json_params = new JSONObject(params);
String datasourceName = json_params.getString("datasourceName");
String topic = json_params.getString("topic");
String page = json_params.getString("page");
final String service = "/showEvents";
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("ds", datasourceName)
.queryParam("topic", topic)
.queryParam("page", page);
ResponseEntity<EventsPage> resp;
try {
//communicate with endpoint
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<EventsPage>() {
});
} catch (RestClientException e) {
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException {
final String service = "/subscriptions";
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("email", userEmail);
//create new template engine
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
try {
//communicate with endpoint
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<Map<String, List<SimpleSubscriptionDesc>>>() {
});
} catch (RestClientException e) {
LOGGER.debug("Error " , e);
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public Subscription subscribe(OpenaireSubscription obj) throws BrokerException {
final String service = "/subscribe";
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
HttpEntity<OpenaireSubscription> entity = new HttpEntity<>(obj, httpHeaders);
//create new template engine
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<Subscription> resp;
try {
//communicate with endpoint
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.POST,
entity,
new ParameterizedTypeReference<Subscription>() {
});
} catch (RestClientException e) {
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public void unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException {
final String service = "/subscriptions/" + subscriptionId;
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiPath + service);
try {
//communicate with endpoint
restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.DELETE,
null,
new ParameterizedTypeReference<Void>() {
});
} catch (RestClientException e) {
throw new BrokerException(e);
}
}
@Override
public Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException {
final String service = "/subscriptions/" + subscriptionId;
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiPath + service);
ResponseEntity<Subscription> resp;
try {
//communicate with endpoint
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<Subscription>() {
});
} catch (RestClientException e) {
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public Map<String, Term> getDnetTopics() throws BrokerException {
return topics;
}
@Override
public EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId,
@PathVariable("page") String page,
@PathVariable("size") String size
) throws BrokerException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(openairePath + "/notifications/")
.path("/{id}/{page}/{size}/")
.build().expand(subscriptionId,page, size).encode();
ResponseEntity<EventsPage> resp;
try {
resp = restTemplate.exchange(
uriComponents.toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<EventsPage>() {
});
} catch (RestClientException e) {
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public Map<String, List<Subscription>> getSubscriptionsOfUser(@PathVariable("userEmail") String userEmail)
throws BrokerException {
Map<String, List<SimpleSubscriptionDesc>> simpleSubs = getSimpleSubscriptionsOfUser(userEmail);
Map<String,List<Subscription>> subs = new HashMap<>();
List<Subscription> subscriptions = null;
for(String s:simpleSubs.keySet()){
List<SimpleSubscriptionDesc> simpleSubscriptionDescs = simpleSubs.get(s);
for(SimpleSubscriptionDesc simpleSubscriptionDesc : simpleSubscriptionDescs) {
subscriptions = new ArrayList<>();
subscriptions.add(getSubscription(simpleSubscriptionDesc.getId()));
}
subs.put(s,subscriptions);
}
return subs;
}
}

View File

@ -1,39 +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.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/monitor")
@Api(description = "Monitor API", tags = {"monitor"})
public interface MonitorApi {
@RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET,consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
JobsOfUser getJobsOfUser(@RequestBody String user,
@RequestBody String jobType,
@RequestBody String offset,
@RequestBody String limit,
@RequestBody String dateFrom,
@RequestBody String dateTo,
@RequestBody String validationStatus,
@RequestBody 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,91 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.api.functionality.ValidatorService;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.shared.JobsOfUser;
import eu.dnetlib.repo.manager.shared.Constants;
import gr.uoa.di.driver.util.ServiceLocator;
import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class MonitorApiImpl implements MonitorApi {
@Resource(name = "validatorServiceLocator")
private ServiceLocator<ValidatorService> validatorServiceLocator;
private ValidatorService getValidationService() {
return this.validatorServiceLocator.getService();
}
public ServiceLocator<ValidatorService> getValidatorServiceLocator() {
return validatorServiceLocator;
}
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) {
this.validatorServiceLocator = validatorServiceLocator;
}
private static final Logger LOGGER = Logger
.getLogger(MonitorApiImpl.class);
@Override
public JobsOfUser getJobsOfUser(@ApiParam(value = "User email", required = true) String user,
@ApiParam(value = "Equals to filter job type on validation history page", required = true) String jobType,
@ApiParam(value = "Page number", required = true) String offset,
@ApiParam(value = "Null value", required = true) String limit,
@ApiParam(value = "Null value", required = true) String dateFrom,
@ApiParam(value = "Null value", required = true) String dateTo,
@ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus,
@ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
LOGGER.debug("Getting jobs of user : " + user);
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
JobsOfUser retJobs = new JobsOfUser();
retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
Integer.parseInt(limit), dateFrom, dateTo, validationStatus));
if (Boolean.parseBoolean(includeJobsTotal)) {
retJobs.setTotalJobs(this.getJobsTotalNumberOfUser(user, jobType, null));
retJobs.setTotalJobsSuccessful(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_SUCCESSFUL));
retJobs.setTotalJobsFailed(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_FAILED));
retJobs.setTotalJobsOngoing(this.getJobsTotalNumberOfUser(user, jobType,Constants.VALIDATION_JOB_STATUS_ONGOING));
}
return retJobs;
}
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException {
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
}
@Override
public int getJobsOfUserPerValidationStatus(String user,
String jobType,
String validationStatus) throws JSONException {
LOGGER.debug("Getting job with validation status : " + validationStatus);
try {
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
} catch (ValidatorServiceException e) {
e.printStackTrace();
}
return 0;
}
@Override
public StoredJob getJobSummary(String jobId,
String groupBy) throws JSONException {
LOGGER.debug("Getting job summary with id : " + jobId);
try {
return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
} catch (ValidatorServiceException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -1,34 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.domain.data.PiwikInfo;
import io.swagger.annotations.Api;
import org.springframework.http.MediaType;
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(@RequestBody PiwikInfo piwikInfo);
@RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
List<PiwikInfo> getPiwikSitesForRepos();
@RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
void approvePiwikSite(String repositoryId);
@RequestMapping(value = "/getOpenaireId/{repositoryid}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String getOpenaireId(String repositoryid);
}

View File

@ -1,93 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.utils.md5.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.security.NoSuchAlgorithmException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
@Component
public class PiWikApiImpl implements PiWikApi{
@Autowired
@Qualifier("repomanager.dataSource")
private DataSource dataSource;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
.getLogger(PiWikApiImpl.class);
private final static String GET_PIWIK_SITE = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site where repositoryid = ?;";
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 APPROVE_PIWIK_SITE = "update piwik_site set validated=true, validationdate=now() where repositoryid = ?;";
private RowMapper<PiwikInfo> piwikRowMapper = (rs, i) -> new PiwikInfo(rs.getString("repositoryid"), getOpenaireId(rs.getString("repositoryid")), rs.getString("repositoryname"), rs.getString("country"),
rs.getString("siteid"), rs.getString("authenticationtoken"), rs.getTimestamp("creationdate"), rs.getString("requestorname"), rs.getString("requestoremail"),
rs.getBoolean("validated"), rs.getTimestamp("validationdate"), rs.getString("comment"));
@Override
public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) {
try{
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper);
}catch (EmptyResultDataAccessException e){
return null;
}
}
@Override
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()},
new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
return piwikInfo;
}
@Override
public List<PiwikInfo> getPiwikSitesForRepos() {
LOGGER.debug("Getting piwik sites for repos! ");
try{
return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper);
}catch (EmptyResultDataAccessException e){
return null;
}
}
@Override
public void approvePiwikSite(@PathVariable("repositoryId") String repositoryId) {
new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR});
}
@Override
public String getOpenaireId(@PathVariable("repositoryId") String repositoryid) {
try {
if (repositoryid != null && repositoryid.contains("::"))
return repositoryid.split("::")[0] + "::" + MD5.encrypt2Hex(repositoryid.split("::")[1]);
else
return null;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -1,172 +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.shared.*;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/repository")
@Api(description = "Repository API", tags = {"repository"})
public interface RepositoryApi {
@RequestMapping(value = "/testAggregations", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> testAggregations() throws JSONException;
@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<Repository> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException;
@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;
@RequestMapping(value = "/getRepositoryAggregations/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Aggregations getRepositoryAggregations(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
void addRepository(String datatype, Repository repository) throws Exception;
@RequestMapping(value = "/deleteInterface", method = RequestMethod.DELETE)
@ResponseBody
void deleteRepositoryInterface(String id);
@RequestMapping(value = "/addInterface", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
RepositoryInterface iFace) throws JSONException;
@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 = "/updateManagedStatus", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateManagedStatus(String id, String managed);
@RequestMapping(value = "/updateEnglishName", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateEnglishName(String id, String englishName);
@RequestMapping(value = "/updateLatitude", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateLatitude(String id, String latitude);
@RequestMapping(value = "/updateLongitude", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateLongitude(String id, String longitude);
@RequestMapping(value = "/updateOfficialName", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateOfficialName(String id, String officialName);
@RequestMapping(value = "/updateTimezone", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateTimezone(String id, String timezone);
@RequestMapping(value = "/updateTypology", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateTypology(String id, String typology);
@RequestMapping(value = "/updateLogoUrl", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateLogoUrl(String id, String logoUrl);
@RequestMapping(value = "/updatePlatform", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updatePlatform(String id, String platform);
@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;
}

View File

@ -1,824 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.domain.enabling.Vocabulary;
import eu.dnetlib.repo.manager.service.utils.Converter;
import eu.dnetlib.repo.manager.shared.*;
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import javax.ws.rs.QueryParam;
import java.sql.Timestamp;
import java.text.Normalizer;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@Component
public class RepositoryApiImpl implements RepositoryApi {
@Value("${api.baseAddress}")
private String baseAddress;
private RestTemplate restTemplate = null;
private HttpHeaders httpHeaders;
private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"};
private static final Logger LOGGER = Logger.getLogger(RepositoryApiImpl.class);
@Value("${services.repomanager.usageStatisticsDiagramsBaseURL}")
private String usageStatisticsDiagramsBaseURL;
@Value("${services.repomanager.usageStatisticsNumbersBaseURL}")
private String usageStatisticsNumbersBaseURL;
@Autowired
private VocabularyLoader vocabularyLoader;
@Autowired
private PiWikApi piWikApi;
private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>();
private Map<String, String> countriesMap = new HashMap<>();
private Map<String, String> inverseCountriesMap = new HashMap<>();
@PostConstruct
private void init() {
LOGGER.debug("Initialization method of repository api!");
restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
for (String vocName : vocabularyNames) {
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
}
Country[] countries = getCountries();
for (Country c : countries) {
countriesMap.put(c.getName(), c.getCode());
inverseCountriesMap.put(c.getCode(), c.getName());
}
}
@Override
public List<String> testAggregations() throws JSONException {
int page = 0;
int size = 1000;
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/list/")
.path("/{page}/{size}/")
.build().expand(page, size).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
List<String> ids = new ArrayList<>();
while (!rs.equals("[]")) {
ids.addAll(getIdsWithNonEmptyAggregations(rs));
LOGGER.debug("Checked " + (page + 1) * size + " records!");
page += 1;
uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/list/")
.path("/{page}/{size}/")
.build().expand(page, size).encode();
rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
}
return ids;
}
private List<String> getIdsWithNonEmptyAggregations(String rs) throws JSONException {
JSONArray ids = new JSONArray(rs);
List<String> agg_ids = new ArrayList<>();
for (int i = 0; i < ids.length(); i++) {
String id = ids.getString(i);
Aggregations aggregations = getRepositoryAggregations(id);
if (aggregations.getAggregationHistory() != null)
agg_ids.add(id);
}
return agg_ids;
}
@Override
public Country[] getCountries() {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/countries")
.build().encode();
return restTemplate.getForObject(uriComponents.toUri(), Country[].class);
}
@Override
public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country,
@PathVariable("mode") String mode,
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException {
LOGGER.debug("Getting repositories by country!");
int page = 0;
int size = 100;
String countryCode = countriesMap.get(country);
String filterKey = "UNKNOWN";
if (mode.equalsIgnoreCase("opendoar")) {
filterKey = "openaire____::opendoar";
} else if (mode.equalsIgnoreCase("re3data")) {
filterKey = "openaire____::re3data";
} else if (mode.equalsIgnoreCase("jour_aggr")) {
filterKey = "infrastruct_::openaire";
}
LOGGER.debug("Country code equals : " + countryCode);
LOGGER.debug("Filter mode equals : " + filterKey);
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/search/country/")
.path("/{page}/{size}/")
.queryParam("country", countryCode)
.queryParam("managed", managed)
.build().expand(page, size).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
List<Repository> resultSet = new ArrayList<>();
while (jsonArray.length() > 0 ) {
List<Repository> rep = Converter.jsonToRepositoryList(new JSONObject(rs));
Collection<Repository> repos = this.getRepositoriesByMode(filterKey, rep);
resultSet.addAll(repos);
page += 1;
uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/search/country/")
.path("/{page}/{size}/")
.queryParam("country", countryCode)
.queryParam("managed", managed)
.build().expand(page, size).encode();
rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
}
for (Repository r : resultSet)
this.getRepositoryInfo(r);
return resultSet;
}
private void getRepositoryInfo(Repository r) throws JSONException {
r.setInterfaces(this.getRepositoryInterface(r.getId()));
r.setPiwikInfo(piWikApi.getPiwikSiteForRepo(r.getId()));
r.setCountryName(getCountryName(r.getCountryCode()));
}
private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
List<Repository> reps = new ArrayList<>();
for (Repository r : rs) {
if (r.getCollectedFrom().equals(mode))
reps.add(r);
}
return reps;
}
@Override
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
LOGGER.debug("Retreiving repositories of user : " + userEmail );
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/search/registeredby/")
.path("/{page}/{size}/")
.queryParam("registeredBy", userEmail)
.build().expand(page, size).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
for (Repository r : repos)
this.getRepositoryInfo(r);
return repos;
}
@Override
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/get/")
.path("/{id}/")
.build().expand(id).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
Repository repo = Converter.jsonToRepositoryObject(new JSONObject(rs));
if (repo != null)
getRepositoryInfo(repo);
return repo;
}
@Override
public Aggregations getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/get/")
.path("/{id}/")
.build().expand(id).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
JSONObject repository = new JSONObject(rs);
Aggregations aggregations = new Aggregations();
try {
aggregations.setAggregationHistory(Converter.getAggregationHistoryFromJson(repository));
aggregations.setLastCollection(Converter.getLastCollectionFromJson(repository));
aggregations.setLastTransformation(Converter.getLastTransformationFromJson(repository));
return aggregations;
} catch (JSONException e) {
LOGGER.debug("JSON aggregation exception ", e);
throw e;
}
}
@Override
public List<Repository> getRepositoriesByName(@PathVariable("name") String name,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/search/name/")
.path("/{page}/{size}")
.queryParam("name", name)
.build().expand(page, size).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
for (Repository r : repos)
getRepositoryInfo(r);
return repos;
}
@Override
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/")
.path("/{id}/")
.build().expand(id).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
return Converter.jsonToRepositoryInterfaceList(new JSONArray(rs));
}
@Override
public void addRepository(@RequestParam("datatype") String datatype,
@RequestBody Repository repository) throws Exception {
/*JSONObject json_params = new JSONObject(params);
String datatype = json_params.getString("datatype");
String json_repository = json_params.getString("repository");
Repository repository = null;*/
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
try {
String json_repo = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(repository);
LOGGER.debug("repository -> " + json_repo);
// repository = mapper.readValue(json_repository, Repository.class);
} catch (Exception e) {
LOGGER.debug("Error parsing repository ", e);
throw e;
}
repository = this.setRepositoryFeatures(datatype,repository);
LOGGER.debug("storing " + datatype + " repository with id: " + repository.getId());
if (!datatype.equalsIgnoreCase("opendoar") && !datatype.equalsIgnoreCase("re3data")) {
if (datatype.equalsIgnoreCase("journal") || datatype.equalsIgnoreCase("aggregator")) {
LOGGER.debug("looking if " + datatype + " " + repository.getOfficialName() + " is already in datasources");
if (getRepositoryById(repository.getId()) != null) {
String retMessage = datatype + " '" + repository.getOfficialName() + "' is already in datasources.";
repository.getInterfaces().clear();
LOGGER.debug(retMessage);
} else {
LOGGER.debug(datatype + " " + repository.getOfficialName() + " is not in datasources. Inserting..");
this.storeRepository(repository);
}
}
} else {
this.updateRepository(repository);
}
LOGGER.debug("Inserting Interfaces");
Iterator var11 = repository.getInterfaces().iterator();
while (var11.hasNext()) {
RepositoryInterface iFace = (RepositoryInterface) var11.next();
if (!iFace.getBaseUrl().isEmpty() && !iFace.getDesiredCompatibilityLevel().isEmpty()) {
if (iFace.getId() != null && !iFace.getId().isEmpty()) {
LOGGER.debug("updating iface..");
this.updateInterface(datatype,iFace);
LOGGER.debug("updated successfully");
} else {
LOGGER.debug("adding new iface..");
this.registerRepositoryInterface(repository.getId(),iFace,datatype);
}
}
}
}
private void updateRepository(Repository repository) {
this.updateRegisteredByValue(repository.getId(),repository.getRegisteredBy());
this.updateEnglishName(repository.getId(),repository.getEnglishName());
this.updateLogoUrl(repository.getId(),repository.getLogoUrl());
this.updateTimezone(repository.getId(), String.valueOf(repository.getTimezone()));
//TODO update datasource type
}
private void updateRegisteredByValue(String id, String registeredBy) {
LOGGER.debug("Updating registered by value with : " + registeredBy );
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/registeredby/")
.queryParam("dsId",id)
.queryParam("registeredBy", registeredBy)
.build()
.encode();
restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
private Repository setRepositoryFeatures(String datatype, Repository repository) {
//TODO update map
repository.setCountryCode(countriesMap.get(repository.getCountryName()));
repository.setActivationId(UUID.randomUUID().toString());
// repo.setRegisteredBy((String) session.get(LocalVocabularies.loggedInField));
if (datatype.equals("opendoar") || datatype.equals("re3data")) {
repository.setProvenanceActionClass("sysimport:crosswalk:entityregistry");
} else if (datatype.equals("journal")) {
repository.setProvenanceActionClass("user:insert");
repository.setCollectedFrom("infrastruct_::openaire");
if (repository.getIssn() != null && repository.getIssn().length() == 0)
repository.setIssn(com.unboundid.util.Base64.encode(repository.getOfficialName()).substring(0, 8));
repository.setId("openaire____::issn" + repository.getIssn());
repository.setNamespacePrefix("issn" + repository.getIssn());
} else if (datatype.equals("aggregator")) {
repository.setProvenanceActionClass("user:insert");
repository.setCollectedFrom("infrastruct_::openaire");
repository.setId("openaire____::" + com.unboundid.util.Base64.encode(repository.getOfficialName()));
repository.setNamespacePrefix(Normalizer.normalize(repository.getOfficialName().toLowerCase().replace(" ", "_"), Normalizer.Form.NFD).replaceAll("[^a-zA-Z0-9]", ""));
if (repository.getNamespacePrefix().length() > 12) {
repository.setNamespacePrefix(repository.getNamespacePrefix().substring(0, 12));
} else {
while (repository.getNamespacePrefix().length() < 12)
repository.setNamespacePrefix(repository.getNamespacePrefix().concat("_"));
}
}
return repository;
}
private void updateInterface(String datatype,RepositoryInterface iFace) {
//TODO call update base url
//((DatasourceManagerService) this.dmService.getService()).updateBaseUrl(repo.getId(), iFace.getId(), iFace.getBaseUrl());
if (!iFace.getAccessSet().isEmpty()) {
LOGGER.debug("set not empty: " + iFace.getAccessSet());
//TODO call update method for access params
// ((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "set", iFace.getAccessSet(), false);
} else {
//TODO call deleteAccessParamOrExtraField
//((DatasourceManagerService) this.dmService.getService()).deleteAccessParamOrExtraField(repo.getId(), iFace.getId(), "set");
}
//TODO update content description
//((DatasourceManagerService) this.dmService.getService()).updateContentDescription(repo.getId(), iFace.getId(), "metadata");
if (datatype.equals("re3data")) {
//TODO call update access params
// ((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "format", "oai_datacite", false);
iFace.setAccessFormat("oai_datacite");
} else {
//TODO call update access params
//((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "format", "oai_dc", false);
iFace.setAccessFormat("oai_dc");
}
}
private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) {
iFace.setContentDescription("metadata");
iFace.setCompliance("UNKNOWN");
if (datatype.equals("re3data")) {
iFace.setAccessFormat("oai_datacite");
} else {
iFace.setAccessFormat("oai_dc");
}
if (repo.getDatasourceClass() != null && !repo.getDatasourceClass().isEmpty()) {
iFace.setTypology(repo.getDatasourceClass());
} else if (datatype.equalsIgnoreCase("journal")) {
iFace.setTypology("pubsrepository::journal");
} else if (datatype.equalsIgnoreCase("aggregator")) {
iFace.setTypology("aggregator::pubsrepository::unknown");
} else if (datatype.equalsIgnoreCase("opendoar")) {
iFace.setTypology("pubsrepository::unknown");
} else if (datatype.equalsIgnoreCase("re3data")) {
iFace.setTypology("datarepository::unknown");
}
iFace.setRemovable(true);
iFace.setAccessProtocol("oai");
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
// iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
if (iFace.getAccessSet().isEmpty()) {
LOGGER.debug("set is empty: " + iFace.getAccessSet());
iFace.removeAccessSet();
}
return iFace;
}
private void storeRepository(Repository repository) throws JSONException {
Date utilDate = new Date();
Timestamp date = new Timestamp(utilDate.getTime());
repository.setDateOfCollection(date);
repository.setAggregator("OPENAIRE");
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/add/")
.build()
.encode();
String json_repository = Converter.repositoryObjectToJson(repository);
HttpEntity<String> httpEntity = new HttpEntity <String> (json_repository,httpHeaders);
restTemplate.postForObject(uriComponents.toUri(),httpEntity,String.class);
}
@Override
public void deleteRepositoryInterface(@PathVariable("id") String id){
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/")
.path("/{id}/")
.build().expand(id).encode();
restTemplate.delete(uriComponents.toUri());
}
@Override
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype,
@RequestParam("repoId") String repoId,
@RequestBody RepositoryInterface repositoryInterface) throws JSONException {
/* JSONObject json_params = new JSONObject(params);
// LOGGER.debug(params);
//TODO iFace parameter from gui. Object to json
String datatype = json_params.getString("datatype");
String repoId = json_params.getString("repoId");
String json_iFace = json_params.getString("iFace");
RepositoryInterface iFace = null;
ObjectMapper mapper = new ObjectMapper();
try {
iFace = mapper.readValue(json_iFace, RepositoryInterface.class);
} catch (Exception e1) {
LOGGER.debug("Error parsing repository interface ", e1);
}*/
return registerRepositoryInterface(repoId,repositoryInterface,datatype);
}
private RepositoryInterface registerRepositoryInterface(String repoId, RepositoryInterface iFace, String datatype) {
Repository e = null;
try {
e = this.getRepositoryById(repoId);
iFace = createRepositoryInterface(e,iFace,datatype);
ObjectMapper mapper = new ObjectMapper();
String json_interface = Converter.repositoryInterfaceObjectToJson(e,iFace);
LOGGER.debug("iFace equals -> " + json_interface);
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/add/")
.build()
.encode();
HttpEntity<String> httpEntity = new HttpEntity <String> (json_interface,httpHeaders);
restTemplate.postForObject(uriComponents.toUri(),httpEntity,String.class);
return iFace;
} catch (JSONException e1) {
LOGGER.debug("Error parsing json ",e1);
}
return null;
}
@Override
public List<String> getDnetCountries() {
LOGGER.debug("Getting dnet-countries!");
return Converter.readFile("countries.txt");
}
@Override
public List<String> getTypologies() {
return Converter.readFile("typologies.txt");
}
@Override
public List<Timezone> getTimezones() {
List<String> timezones = Converter.readFile("timezones.txt");
return Converter.toTimezones(timezones);
}
@Override
public String updateManagedStatus(@RequestParam(value = "id") String id,
@RequestParam(value = "managed") String managed) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/manage/")
.queryParam("id",id)
.queryParam("managed",managed)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateEnglishName(@RequestParam(value = "id") String id,
@RequestParam(value = "englishname") String englishName) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/englishname/")
.queryParam("dsId",id)
.queryParam("englishname",englishName)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateLatitude(@RequestParam(value = "id") String id,
@RequestParam(value = "latitude") String latitude) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/latitude/")
.queryParam("dsId",id)
.queryParam("latitude",latitude)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateLongitude(@RequestParam(value = "id") String id,
@RequestParam(value = "longitude") String longitude) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/longitude/")
.queryParam("dsId",id)
.queryParam("longitude",longitude)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateOfficialName(@RequestParam(value = "id") String id,
@RequestParam(value = "officialname") String officialname) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/officialname/")
.queryParam("dsId",id)
.queryParam("officialname",officialname)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateTimezone(@RequestParam(value = "id") String id,
@RequestParam(value = "timezone") String timezone) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/timezone")
.queryParam("dsId",id)
.queryParam("timezone",timezone)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateTypology(@RequestParam(value = "id") String id,
@RequestParam(value = "typology") String typology) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/typology")
.queryParam("dsId",id)
.queryParam("typology",typology)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateLogoUrl(@RequestParam(value = "id") String id,
@RequestParam(value = "logoUrl") String logoUrl) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/logourl")
.queryParam("dsId",id)
.queryParam("logourl",logoUrl)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updatePlatform(String id, String platform) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/platform")
.queryParam("dsId",id)
.queryParam("platform",platform)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String user_email,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/api/baseurl/")
.path("/{page}/{size}")
.queryParam("userEmail",user_email)
.build().expand(page,size).encode();
return Arrays.asList(restTemplate.getForObject(uriComponents.toUri(), String[].class));
}
@Override
public List<String> getDatasourceVocabularies(@PathVariable("mode") String mode) {
List<String> resultSet = new ArrayList<>();
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
if (mode.equalsIgnoreCase("aggregator")) {
if (entry.getKey().contains("aggregator"))
resultSet.add(entry.getValue());
} else if (mode.equalsIgnoreCase("journal")) {
if (entry.getKey().contains("journal"))
resultSet.add(entry.getValue());
} else if (mode.equalsIgnoreCase("opendoar")) {
if (entry.getKey().contains("pubsrepository"))
resultSet.add(entry.getValue());
} else if (mode.equalsIgnoreCase("re3data")) {
if (entry.getKey().contains("datarepository"))
resultSet.add(entry.getValue());
}
}
return resultSet;
}
private Vocabulary getVocabulary(String vocName) {
if (!vocabularyMap.containsKey(vocName)) {
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
}
return vocabularyMap.get(vocName);
}
@Override
public Map<String, String> getCompatibilityClasses(@PathVariable("mode") String mode) {
LOGGER.debug("Getting compatibility classes for mode: " + mode);
Map<String, String> retMap = new HashMap<String, String>();
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
boolean foundData = false;
for (Map.Entry<String, String> entry : compatibilityClasses.entrySet()) {
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_ALL))
return compatibilityClasses;
else if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) {
if (entry.getKey().matches("^openaire[1-9].0_data$")) {
retMap.put(entry.getKey(), entry.getValue());
foundData = true;
}
} else {
if (entry.getKey().matches("^openaire[1-9].0$") || entry.getKey().equals("driver"))
retMap.put(entry.getKey(), entry.getValue());
}
}
//TODO TO BE REMOVED WHEN VOCABULARIES ARE UPDATED
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA) && !foundData)
retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)");
return retMap;
}
@Override
public Map<String, String> getDatasourceClasses(@PathVariable("mode") String mode) {
LOGGER.debug("Getting datasource classes for mode: " + mode);
Map<String, String> retMap = new HashMap<String, String>();
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
if (mode.equalsIgnoreCase("aggregator")) {
if (entry.getKey().contains("aggregator"))
retMap.put(entry.getKey(), entry.getValue());
} else if (mode.equalsIgnoreCase("journal")) {
if (entry.getKey().contains("journal"))
retMap.put(entry.getKey(), entry.getValue());
} else if (mode.equalsIgnoreCase("opendoar")) {
if (entry.getKey().contains("pubsrepository"))
retMap.put(entry.getKey(), entry.getValue());
} else if (mode.equalsIgnoreCase("re3data")) {
if (entry.getKey().contains("datarepository"))
retMap.put(entry.getKey(), entry.getValue());
}
}
return retMap;
}
@Override
public String getCountryName(String countryCode) {
return inverseCountriesMap.get(countryCode);
}
@Override
public MetricsInfo getMetricsInfoForRepository(@PathVariable("repoId") String repoId) throws RepositoryServiceException {
try {
MetricsInfo metricsInfo = new MetricsInfo();
metricsInfo.setDiagramsBaseURL(this.usageStatisticsDiagramsBaseURL);
metricsInfo.setMetricsNumbers(getMetricsNumbers(getOpenAIREId(repoId)));
return metricsInfo;
} catch (Exception e) {
LOGGER.error("Error while getting metrics info for repository: ", e);
//emailUtils.reportException(e);
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
}
}
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException {
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks");
//create new template engine
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<MetricsNumbers> resp;
try {
//communicate with endpoint
resp = template.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<MetricsNumbers>() {
});
} catch (RestClientException e) {
throw e;
}
return resp.getBody();
}
private String getOpenAIREId(String repoId) {
if (repoId != null && repoId.contains("::")) {
return repoId.split("::")[0] + "::" + DigestUtils.md5Hex(repoId.split("::")[1]);
}
return null;
}
}

View File

@ -1,23 +0,0 @@
/*
package eu.dnetlib.repo.manager.service.controllers;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@RestController
@RequestMapping(value = "/user")
@Api(description = "User API", tags = {"user"})
public interface UserApi {
@RequestMapping(value = "/login" , method = RequestMethod.GET)
void login(HttpServletRequest req,
HttpServletResponse resp);
}
*/

View File

@ -1,27 +0,0 @@
/*
package eu.dnetlib.repo.manager.service.controllers;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class UserApiImpl implements UserApi {
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
.getLogger(UserApiImpl.class);
@Value("${oidc.issuer}")
private String oidc_issuer;
@Override
public void login(HttpServletRequest req,
HttpServletResponse resp) {
LOGGER.debug(oidc_issuer);
resp.setStatus(HttpServletResponse.SC_FOUND);
resp.setHeader("Location", oidc_issuer);
}
}
*/

View File

@ -1,59 +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.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 )
@ResponseBody
void submitJobForValidation(@RequestBody JobForValidation jobForValidation);
@RequestMapping(value = "/reSubmitJobForValidation/",method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE )
@ResponseBody
void reSubmitJobForValidation(@RequestBody String jobId) throws JSONException;
@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(@RequestBody String url);
@RequestMapping(value = "/identifyRepository/{url}" , 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, Integer offset, Integer 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/{baseUrl}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException;
}

View File

@ -1,196 +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.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.RuleSet;
import eu.dnetlib.repo.manager.shared.Constants;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import eu.dnetlib.api.functionality.ValidatorService;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@Component
public class ValidatorApiImpl implements ValidatorApi{
@Autowired
private MonitorApiImpl monitorApi;
@Resource(name = "validatorServiceLocator")
private ServiceLocator<ValidatorService> validatorServiceLocator;
private ValidatorService getValidationService() {
return this.validatorServiceLocator.getService();
}
public ServiceLocator<ValidatorService> getValidatorServiceLocator() {
return validatorServiceLocator;
}
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) {
this.validatorServiceLocator = validatorServiceLocator;
}
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
private static final Logger LOGGER = Logger
.getLogger(ValidatorApiImpl.class);
@PostConstruct
private void loadRules(){
LOGGER.debug("PostConstruct method! Load rules!");
try {
for (RuleSet ruleSet : getValidationService().getRuleSets()) {
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) {
String key = "";
if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_data$"))
key = Constants.VALIDATION_MODE_DATA;
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0$") || ruleSet.getGuidelinesAcronym().equals("driver"))
key = Constants.VALIDATION_MODE_LITERATURE;
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_cris$"))
key = Constants.VALIDATION_MODE_CRIS;
if (rulesetMap.containsKey(key))
rulesetMap.get(key).add(ruleSet);
else {
List<RuleSet> ruleSets = new ArrayList<RuleSet>();
ruleSets.add(ruleSet);
rulesetMap.put(key, ruleSets);
}
}
}
} catch (ValidatorServiceException e) {
e.printStackTrace();
}
}
@Override
public void submitJobForValidation(JobForValidation jobForValidation) {
LOGGER.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId());
try {
this.getValidationService().submitValidationJob(jobForValidation);
} catch (ValidatorServiceException e) {
e.printStackTrace();
}
}
@Override
public void reSubmitJobForValidation(String jobId) throws JSONException {
LOGGER.debug("Resubmit validation job with id : " + jobId);
StoredJob job = monitorApi.getJobSummary(jobId,"all");
Set<Integer> contentRules = new HashSet<Integer>();
Set<Integer> usageRules = new HashSet<Integer>();
RuleSet ruleSet = null;
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
for (RuleSet rSet : ruleSets)
if (rSet.getGuidelinesAcronym().equals(job.getDesiredCompatibilityLevel())) {
ruleSet = rSet;
break;
}
}
for (int ruleId : job.getRules()) {
if (ruleSet.getContentRulesIds().contains(ruleId))
contentRules.add(ruleId);
else if (ruleSet.getUsageRulesIds().contains(ruleId))
usageRules.add(ruleId);
}
if (!contentRules.isEmpty())
job.setSelectedContentRules(contentRules);
if (!usageRules.isEmpty())
job.setSelectedUsageRules(usageRules);
this.submitJobForValidation(job);
}
@Override
public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) {
LOGGER.info("Getting rulesets for mode: " + mode);
return rulesetMap.get(mode);
}
@Override
public List<String> getSetsOfRepository(@PathVariable("url") String url) {
LOGGER.debug("Getting sets of repository with url : " + url);
try {
return OaiTools.getSetsOfRepo(url);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public boolean identifyRepo(@PathVariable("url") String url) {
LOGGER.debug("Identify repository with url : " + url);
try {
return OaiTools.identifyRepository(url);
} catch (Exception e) {
LOGGER.error("Error while identifying repository with url: " + url, e);
return false;
}
}
@Override
public RuleSet getRuleSet(@PathVariable("acronym") String acronym) {
LOGGER.debug("Getting ruleset with acronym : " + acronym);
RuleSet ruleSet = null;
try {
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
for (RuleSet rSet : ruleSets)
if (rSet.getGuidelinesAcronym().equals(acronym)) {
ruleSet = rSet;
break;
}
}
return ruleSet;
} catch (Exception e) {
LOGGER.error("Error getting ruleset", e);
return null;
}
}
@Override
public List<StoredJob> getStoredJobsNew(String user, String jobType, Integer offset, Integer limit, String dateFrom,
String dateTo, String validationStatus) throws ValidatorServiceException {
return getValidationService().getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus);
}
@Override
public int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException {
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
}
@Override
public InterfaceInformation getInterfaceInformation(@PathVariable("baseUrl") String baseUrl) throws ValidationServiceException {
try {
LOGGER.debug("Getting interface information with url: " + baseUrl);
InterfaceInformation interfaceInformation = new InterfaceInformation();
interfaceInformation.setIdentified(this.identifyRepo(baseUrl));
if (interfaceInformation.isIdentified())
interfaceInformation.setSets(this.getSetsOfRepository(baseUrl));
return interfaceInformation;
} catch (Exception e) {
LOGGER.error("Error getting interface information with url: " + baseUrl, e);
// emailUtils.reportException(e);
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
}
}
}

View File

@ -1,56 +0,0 @@
/*
package eu.dnetlib.repo.manager.service.utils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;
import javax.annotation.PostConstruct;
import java.util.logging.Logger;
@Configuration
@EnableRedisHttpSession
@PropertySource(value = { "classpath:eu/dnetlib/repo/manager/service/application.properties", "classpath:application.properties"} )
@ComponentScan(basePackages = "eu.dnetlib.repo.manager")
public class Config {
private static Logger LOGGER = Logger.getLogger(String.valueOf(Config.class));
@Value("${redis.host}")
private String host;
@Value("${redis.port:6379}")
private String port;
@Value("${redis.password:#{null}}")
private String password;
@PostConstruct
private void init(){
LOGGER.info(host);
}
@Bean
public LettuceConnectionFactory connectionFactory() {
LOGGER.info(String.format("Redis connection listens to %s:%s",host,port));
LettuceConnectionFactory factory = new LettuceConnectionFactory(host,Integer.parseInt(port));
if(password != null) factory.setPassword(password);
return factory;
}
@Bean
public CookieSerializer cookieSerializer() {
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
serializer.setCookieName("SESSION"); // <1>
serializer.setCookiePath("/"); // <2>
return serializer;
}
}
*/

View File

@ -1,361 +0,0 @@
package eu.dnetlib.repo.manager.service.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.repo.manager.shared.*;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Converter {
private static final Logger LOGGER = Logger.getLogger(Converter.class);
public static Repository jsonToRepositoryObject(JSONObject repositoryObject) throws JSONException {
Repository repository = new Repository();
LOGGER.debug("datasource response -> " + repositoryObject);
JSONObject datasource = repositoryObject.getJSONObject("datasource");
if( datasource.equals(null))
return null;
repository.setActivationId(datasource.get("activationId").toString());
repository.setAggregator(datasource.get("aggregator").toString());
repository.setCertificates(datasource.get("certificates").toString());
repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").toString());
repository.setCollectedFrom( datasource.get("collectedfrom").toString());
repository.setContactEmail(datasource.get("contactemail").toString());
if(repository.getContactEmail().equals("null"))
repository.setContactEmail("");
repository.setDatabaseAccessRestriction(datasource.get("databaseaccessrestriction").toString());
repository.setDatabaseAccessType(datasource.get("databaseaccesstype").toString());
repository.setDataUploadRestriction(datasource.get("datauploadrestriction").toString());
repository.setDataUploadType(datasource.get("datauploadtype").toString());
repository.setDateOfCollection(convertStringToDate( datasource.get("dateofcollection").toString()));
repository.setDateOfValidation(convertStringToDate( datasource.get("dateofvalidation").toString()));
repository.setDescription(datasource.get("description").toString());
if(repository.getDescription().equals("null"))
repository.setDescription("");
repository.setEissn(datasource.get("eissn").toString());
repository.setEnglishName( datasource.get("englishname").toString());
if(repository.getEnglishName().equals("null"))
repository.setEnglishName("");
repository.setId(datasource.get("id").toString());
repository.setIssn(datasource.get("issn").toString());
repository.setOdLanguages(datasource.get("languages").toString());
repository.setLatitude( toDouble(datasource.get("latitude").toString()));
repository.setLissn(datasource.get("lissn").toString());
repository.setLogoUrl(datasource.get("logourl").toString());
if(repository.getLogoUrl().equals("null"))
repository.setLogoUrl("");
repository.setLongitude(toDouble(datasource.get("longitude").toString()));
//datasource.get("managed");
repository.setMissionStatementUrl(datasource.get("missionstatementurl").toString());
repository.setNamespacePrefix(datasource.get("namespaceprefix").toString());
repository.setOdContentTypes(datasource.get("od_contenttypes").toString());
repository.setOfficialName(datasource.get("officialname").toString());
if(repository.getOfficialName().equals("null"))
repository.setOfficialName("");
repository.setPidSystems(datasource.get("pidsystems").toString());
//datasource.get("platform");
repository.setProvenanceActionClass( datasource.get("provenanceaction").toString());
repository.setQualityManagementKind(datasource.get("qualitymanagementkind").toString());
repository.setRegisteredBy(datasource.get("registeredby").toString());
if(Objects.equals(repository.getRegisteredBy(),"null"))
repository.setRegistered(true);
repository.setReleaseEndDate(convertStringToDate(datasource.get("releaseenddate").toString()));
repository.setReleaseStartDate(convertStringToDate(datasource.get("releasestartdate").toString()));
repository.setServiceProvider(Boolean.valueOf(datasource.get("serviceprovider").toString()));
//datasource.get("subjects");
Double timezone = toDouble(datasource.get("timezone").toString());
repository.setTimezone(timezone!=null?timezone:0.0);
repository.setTypology(datasource.get("platform").toString());
repository.setVersioning(Boolean.valueOf(datasource.get("versioning").toString()));
repository.setWebsiteUrl(datasource.get("websiteurl").toString());
repository.setDatasourceClass(datasource.get("typology").toString());
//TODO change organization to list
repository.setOrganization( ((JSONArray)datasource.get("organizations")).getJSONObject(0).get("legalname").toString());
String countryCode = ((JSONArray)datasource.get("organizations")).getJSONObject(0).get("country").toString();
repository.setCountryCode(countryCode);
String collectedFrom = datasource.get("collectedfrom").toString();
//TODO check data consistency
String type = "UNKNOWN";
if (collectedFrom.equalsIgnoreCase("openaire____::opendoar")) {
type = "opendoar";
} else if (collectedFrom.equalsIgnoreCase("openaire____::re3data")) {
type = "re3data";
} else if (collectedFrom.equalsIgnoreCase("infrastruct_::openaire")) {
type = "journal";
}
repository.setDatasourceType(type);
return repository;
}
public static Date convertStringToDate(String date){
if(Objects.equals(date, "null"))
return null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
return formatter.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public static String convertDateToString(Date date){
if(Objects.equals(date, null))
return null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(date);
}
public static Double toDouble(String number){
if(Objects.equals(number, "null"))
return 0.0;
else
return Double.valueOf(number);
}
public static List<Repository> jsonToRepositoryList(JSONObject json) throws JSONException {
List<Repository> resultSet = new ArrayList<>();
JSONArray rs = json.getJSONArray("datasourceInfo");
for(int i=0;i<rs.length();i++)
resultSet.add(jsonToRepositoryObject( rs.getJSONObject(i)) );
return resultSet;
}
public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONArray rs) throws JSONException {
List<RepositoryInterface> resultSet = new ArrayList<>();
for(int i=0;i<rs.length();i++)
resultSet.add(jsonToRepositoryInterfaceObject( rs.getJSONObject(i)) );
return resultSet;
}
public static RepositoryInterface jsonToRepositoryInterfaceObject(JSONObject repositoryInterfaceObject) throws JSONException {
RepositoryInterface repositoryInterface = new RepositoryInterface();
repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString());
repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").toString());
repositoryInterface.setId(repositoryInterfaceObject.get("id").toString());
repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString());
repositoryInterface.setAccessProtocol(repositoryInterfaceObject.get("protocol").toString());
repositoryInterface.setTypology(repositoryInterfaceObject.get("typology").toString());
repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString());
repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString()));
repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString()));
repositoryInterface.setCompliance(repositoryInterfaceObject.get("compatibility").toString());
Map<String, String> accessParams = new HashMap<>();
Map<String, String> extraFields = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiparam");
for(int i=0;i<apiparams.length();i++)
accessParams.put(apiparams.getJSONObject(i).getString("param"),apiparams.getJSONObject(i).getString("value"));
return repositoryInterface;
}
public static String repositoryObjectToJson(Repository repository) throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("activationId",repository.getActivationId());
jsonObject.put("aggregator",repository.getAggregator());
jsonObject.put("certificates",repository.getCertificates());
jsonObject.put("citationguidelineurl",repository.getCitationGuidelineUrl());
jsonObject.put("collectedfrom",repository.getCollectedFrom());
jsonObject.put("contactemail",repository.getContactEmail());
jsonObject.put("databaseaccessrestriction",repository.getDatabaseAccessRestriction());
jsonObject.put("databaseaccesstype",repository.getDatabaseAccessType());
jsonObject.put("datauploadrestriction",repository.getDataUploadRestriction());
jsonObject.put("datauploadtype",repository.getDataUploadType());
jsonObject.put("dateofcollection",convertDateToString(repository.getDateOfCollection()));
jsonObject.put("dateofvalidation",convertDateToString(repository.getDateOfValidation()));
jsonObject.put("description",repository.getDescription());
jsonObject.put("eissn",repository.getEissn());
jsonObject.put("englishname",repository.getEnglishName());
jsonObject.put("id",repository.getId());
jsonObject.put("issn",repository.getIssn());
jsonObject.put("languages",repository.getOdLanguages());
jsonObject.put("latitude",repository.getLatitude().toString());
jsonObject.put("lissn",repository.getLissn());
jsonObject.put("logourl",repository.getLogoUrl());
jsonObject.put("longitude",repository.getLongitude().toString());
jsonObject.put("missionstatementurl",repository.getMissionStatementUrl());
jsonObject.put("namespaceprefix",repository.getNamespacePrefix());
jsonObject.put("od_contenttypes",repository.getOdContentTypes());
jsonObject.put("officialname",repository.getOfficialName());
jsonObject.put("pidsystems",repository.getPidSystems());
jsonObject.put("provenanceaction",repository.getProvenanceActionClass());
jsonObject.put("qualitymanagementkind",repository.getQualityManagementKind());
jsonObject.put("registeredby",repository.getRegisteredBy());
jsonObject.put("releaseenddate",convertDateToString(repository.getReleaseEndDate()));
jsonObject.put("releasestartdate",convertDateToString(repository.getReleaseStartDate()));
jsonObject.put("serviceprovider",repository.getServiceProvider());
jsonObject.put("timezone",repository.getTimezone());
jsonObject.put("typology",repository.getTypology());
jsonObject.put("versioning",repository.getVersioning());
jsonObject.put("websiteurl",repository.getWebsiteUrl());
//datasource.get("managed");
//datasource.get("platform");
//datasource.get("subjects");
return jsonObject.toString();
}
public static String repositoryInterfaceObjectToJson(Repository repository,RepositoryInterface repositoryInterface) throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("baseurl",repositoryInterface.getBaseUrl());
jsonObject.put("contentdescription",repositoryInterface.getContentDescription());
jsonObject.put("id",repositoryInterface.getId());
jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath());
jsonObject.put("protocol",repositoryInterface.getAccessProtocol());
jsonObject.put("typology",repositoryInterface.getTypology());
jsonObject.put("compatibility",repositoryInterface.getDesiredCompatibilityLevel());
jsonObject.put("datasource",repository.getId());
jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath());
jsonObject.put("protocol",repositoryInterface.getAccessProtocol());
jsonObject.put("removable",repositoryInterface.isRemovable());
jsonObject.put("active",repositoryInterface.isActive());
JSONArray apiparams = new JSONArray();
for(String param: repositoryInterface.getAccessParams().keySet()){
JSONObject jo = new JSONObject();
jo.put("param",param);
jo.put("value",repositoryInterface.getAccessParams().get(param));
apiparams.put(jo);
}
jsonObject.put("apiparam",apiparams);
jsonObject.put("lastCollectionDate",repositoryInterface.getLastCollectionDate());
//jsonObject.put("lastCollectionMdid",repositoryInterface);
//jsonObject.put("lastCollectionTotal");
//jsonObject.put("lastDownloadDate");
// jsonObject.put("lastDownloadMdid");
// jsonObject.put("lastDownloadTotal");
// jsonObject.put("lastValidationJob");
//jsonObject.put("lastAggregationDate");
//jsonObject.put("lastAggregationMdid");
//jsonObject.put("lastAggregationTotal");
return jsonObject.toString();
}
public static ArrayList<String> readFile(String filename) {
String line;
ArrayList<String> list = new ArrayList<String>();
try {
//InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
while((line = br.readLine()) != null) {
list.add(line.trim());
}
br.close();
} catch (IOException e) {
LOGGER.debug("Error opening file!");
e.printStackTrace();
}
return list;
}
public static List<AggregationDetails> getAggregationHistoryFromJson(JSONObject repositoryObject) throws JSONException {
/* if( repositoryObject.get("aggregationHistory").toString().equals("[]") ||
repositoryObject.get("aggregationHistory")!= null)
return null;*/
if(repositoryObject.get("aggregationHistory").toString().equals("[]"))
return null;
JSONArray rs = new JSONArray(repositoryObject.get("aggregationHistory").toString());
LOGGER.debug(rs.length());
List<AggregationDetails> aggregationDetailsList = new ArrayList<>();
for(int i=0;i<rs.length();i++)
aggregationDetailsList.add(jsonToAggregationDetails(rs.getJSONObject(i)));
return aggregationDetailsList;
}
private static AggregationDetails jsonToAggregationDetails(JSONObject aggregationObject) throws JSONException {
AggregationDetails aggregationDetails = new AggregationDetails();
aggregationDetails.setAggregationStage(aggregationObject.get("aggregationStage").toString());
if(aggregationObject.has("collectionMode"))
aggregationDetails.setCollectionMode(aggregationObject.get("collectionMode").toString());
aggregationDetails.setDate(convertStringToDate(aggregationObject.get("date").toString()));
aggregationDetails.setNumberOfRecords(Integer.parseInt(aggregationObject.get("numberOfRecords").toString()));
return aggregationDetails;
}
public static AggregationDetails getLastCollectionFromJson(JSONObject repositoryObject) throws JSONException {
if( repositoryObject.get("lastCollection").equals(null))
return null;
return jsonToAggregationDetails(repositoryObject.getJSONObject("lastCollection"));
}
public static AggregationDetails getLastTransformationFromJson(JSONObject repositoryObject) throws JSONException {
if( repositoryObject.get("lastTransformation").equals(null))
return null;
return jsonToAggregationDetails(repositoryObject.getJSONObject("lastTransformation"));
}
public static List<Timezone> toTimezones(List<String> timezones) {
List<Timezone> tmz = new ArrayList<>();
for(String t : timezones){
String[] s = t.split("\t");
tmz.add(new Timezone(s[1],Double.parseDouble(s[0])));
}
return tmz;
}
}

View File

@ -1,18 +0,0 @@
package eu.dnetlib.repo.manager.service.utils;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.domain.functionality.UserProfile;
public interface EmailUtils {
void reportException(Exception exception);
void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
}

View File

@ -1,251 +0,0 @@
package eu.dnetlib.repo.manager.service.utils;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader;
import eu.dnetlib.utils.MailLibrary;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
@Component
public class EmailUtilsImpl implements EmailUtils {
private static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class);
private List<String> specialRecipients = new ArrayList<String>();
private boolean override = false, logonly = false;
private String overrideEmail = null, from = null;
@Autowired
private MailLibrary mailLibrary;
@Autowired
private CascadingPropertyLoader pLoader;
@Value("${services.repo-manager.baseUrl}")
private String baseUrl;
@Value("${services.repo-manager.adminEmail}")
private String adminEmail;
@Value("${services.repomanager.usagestats.adminEmail}")
private String usageStatsAdminEmail;
@Override
public void reportException(Exception exception) {
Writer writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
exception.printStackTrace(printWriter);
List<String> recipients = new ArrayList<String>();
try {
recipients.add(this.adminEmail);
String message = "An exception has occurred:\n"+writer.toString();
String subject = "Automatic Bug Report";
this.sendMail(recipients, subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error sending error report", e);
}
}
@Override
public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
try {
String subject = "[OpenAIRE-Usage Statistics] New request to enable usage statistics";
String message = "Dear administrator,\n" +
"\n" +
"we have received a request to enable the OpenAIRE usage statistics for the following repository \n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"For more information about this request, go here: \n" +
this.baseUrl + "/#admin/metrics\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
this.sendMail(this.usageStatsAdminEmail, subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e);
throw e;
}
}
@Override
public void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
try {
String subject = "[OpenAIRE-Usage Statistics] Your request to enable usage statistics";
String message = "Dear " + piwikInfo.getRequestorName() + ",\n" +
"\n" +
"we have received your request to enable the OpenAIRE usage statistics for your repository\n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"In order to enable the usage statistics, you must install the OpenAIRE's tracking code in your repository software. " +
"OpenAIRE's usage statistics service tracking code is maintained on Github as a patch for various versions of DSpace " +
"(https://github.com/openaire/OpenAIRE-Piwik-DSpace) and as an Eprints plugin for version 3 " +
"(https://github.com/openaire/EPrints-OAPiwik). In case the platform is different from DSpace or EPrints please contact " +
"the OpenAIRE team in repositoryusagestats@openaire.eu in order to find a solution.\n" +
"\n" +
"For more information about your request and configuration details, go here: \n" +
this.baseUrl + "/#getImpact/instructions/" + piwikInfo.getRepositoryId() + "\n" +
"\n" +
"Once you have finished configuring your repository or if you have any questions, please notify the OpenAIRE team by sending \n" +
"an email to repositoryusagestats@openaire.eu\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e);
throw e;
}
}
@Override
public void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception {
try {
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
String message = "Dear administrator,\n" +
"\n" +
"The installation and configuration of OpenAIRE's tracking code for the following repository " +
"has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e);
throw e;
}
}
@Override
public void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception {
try {
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
String message = "Dear " + piwikInfo.getRequestorName() + ",\n" +
"\n" +
"The installation and configuration of OpenAIRE's tracking code for your repository \"" + piwikInfo.getRepositoryName() +
"\" has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
"\n" +
"You can preview the statistics in your repository's dashboard: \n" +
this.baseUrl + "/#getImpact/" + piwikInfo.getRepositoryId() + "\n" +
"\n" +
" For more information and questions, you can contact the openaire support team by sending an email to " +
"repositoryusagestats@openaire.eu\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e);
throw e;
}
}
private void sendMail(String email, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception {
ArrayList<String> to = new ArrayList<String>();
to.add(email);
this.sendMail(to,subject,message,sendToSpecial,repoAdminMails);
}
private void sendMail(List<String> recipients, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception {
/* try {
if (sendToSpecial) {
recipients.addAll(this.specialRecipients);
}
if (repoAdminMails != null)
recipients.addAll(repoAdminMails);
if (this.override) {
recipients.clear();
recipients.add(overrideEmail);
}
if (!logonly)
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);
LOGGER.debug("Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message);
} catch (Exception e) {
LOGGER.error("Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message, e);
throw new Exception(e);
}*/
}
private String getEmailProperty(String key) {
return pLoader.getProperties().getProperty(key);
}
public void setSpecialRecipients(String specialRecipients) {
String[] recps = specialRecipients.split(",");
for (String recp : recps) {
recp = recp.trim();
this.specialRecipients.add(recp);
}
}
public void setOverride(boolean override) {
this.override = override;
}
public void setOverrideEmail(String overrideEmail) {
this.overrideEmail = overrideEmail;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public boolean isLogonly() {
return logonly;
}
public void setLogonly(boolean logonly) {
this.logonly = logonly;
}
}

View File

@ -1,38 +0,0 @@
/*
package eu.dnetlib.repo.manager.service.utils;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
private String frontEndURI;
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
Cookie sessionCookie = new Cookie("currentUser", authOIDC.getSub());
int expireSec = -1;
sessionCookie.setMaxAge(expireSec);
sessionCookie.setPath("/");
response.addCookie(sessionCookie);
response.sendRedirect(frontEndURI);
}
public String getFrontEndURI() {
return frontEndURI;
}
public void setFrontEndURI(String frontEndURI) {
this.frontEndURI = frontEndURI;
}
}
*/

View File

@ -1,146 +0,0 @@
package eu.dnetlib.repo.manager.service.utils;
import org.apache.log4j.Logger;
import org.dom4j.io.DOMWriter;
import org.w3c.dom.Document;
import se.kb.oai.pmh.*;
import se.kb.oai.pmh.Set;
import javax.net.ssl.*;
import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.*;
public class OaiTools {
{
disableSslVerification();
}
private static Logger LOGGER = Logger.getLogger(OaiTools.class);
public static List<String> getSetsOfRepo(String baseUrl) throws Exception {
try {
LOGGER.debug("Getting sets of repository " + baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
SetsList setList = harvester.listSets();
ResumptionToken token = setList.getResumptionToken();
List<Set> sets = new ArrayList<Set>();
sets.addAll(setList.asList());
while (token != null) {
setList = harvester.listSets(token);
token = setList.getResumptionToken();
sets.addAll(setList.asList());
}
List<String> ret = new ArrayList<String>();
for (Set set : sets) {
ret.add(set.getSpec().trim());
}
if (ret.size() > 0 )
Collections.sort(ret);
return ret;
} catch (Exception e) {
LOGGER.error("Error getting sets of repository " + baseUrl, e);
return new ArrayList<String>();
//throw e;
}
}
public static boolean identifyRepository(String baseUrl) throws Exception {
LOGGER.debug("sending identify request to repo " + baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
if (baseUrl.trim().isEmpty()) {
return false;
}
try {
Identification identification = harvester.identify();
DOMWriter d4Writer = new DOMWriter();
Document d = d4Writer.write(identification.getResponse());
return verifyIdentify(d);
} catch (Exception e) {
LOGGER.debug("Error verifying identify response", e);
throw e;
}
}
private static boolean verifyIdentify(Document doc) throws XPathExpressionException {
NamespaceContext ctx = new NamespaceContext() {
public String getNamespaceURI(String prefix) {
String uri;
if (prefix.equals("oai"))
uri = "http://www.openarchives.org/OAI/2.0/";
else
uri = null;
return uri;
}
// Dummy implementation - not used!
public Iterator<String> getPrefixes(String val) {
return null;
}
// Dummy implemenation - not used!
public String getPrefix(String uri) {
return null;
}
};
// Now the XPath expression
String xpathStr = "//oai:OAI-PMH/oai:Identify";
XPathFactory xpathFact = XPathFactory.newInstance();
XPath xpath = xpathFact.newXPath();
xpath.setNamespaceContext(ctx);
String result = xpath.evaluate(xpathStr, doc);
return (result != null && !result.equals(""));
}
private static void disableSslVerification() {
try
{
LOGGER.debug("disabling ssl verification");
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (NoSuchAlgorithmException e) {
LOGGER.error("disabling ssl verification", e);
} catch (KeyManagementException e) {
LOGGER.error("error while disabling ssl verification", e);
}
}
}

View File

@ -1,58 +0,0 @@
package eu.dnetlib.repo.manager.service.utils;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RequestFilter{
private String registeredby = null;
private String typology = null;
private String country = null;
private String id = null;
private String officialname = null;
public RequestFilter() {
}
public String getTypology() {
return typology;
}
public void setTypology(String typology) {
this.typology = typology;
}
public String getRegisteredby() {
return registeredby;
}
public void setRegisteredby(String registeredby) {
this.registeredby = registeredby;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getOfficialname() {
return officialname;
}
public void setOfficialname(String officialname) {
this.officialname = officialname;
}
}