From 7f00c2f3212f64847307512208fe3e39e17fe826 Mon Sep 17 00:00:00 2001 From: "panagiotis.kanakakis" Date: Wed, 21 Feb 2018 15:05:02 +0000 Subject: [PATCH] 1. Fix new dev api 2. Fix bugs on validator / broker / piwik api. 3. JSON changes on convert file for dev api 4. Add new class RequestFilter on utils package for search queries. --- .../service/controllers/BrokerApi.java | 19 +- .../manager/service/controllers/PiWikApi.java | 4 +- .../service/controllers/PiWikApiImpl.java | 10 +- .../controllers/RepositoryApiImpl.java | 47 ++-- .../service/controllers/ValidatorApi.java | 4 +- .../service/controllers/ValidatorApiImpl.java | 6 +- .../repo/manager/service/utils/Converter.java | 42 ++- .../manager/service/utils/EmailUtils.java | 18 ++ .../manager/service/utils/EmailUtilsImpl.java | 251 ++++++++++++++++++ .../manager/service/utils/RequestFilter.java | 26 +- .../manager/shared/broker/Subscription.java | 2 + 11 files changed, 363 insertions(+), 66 deletions(-) create mode 100644 src/main/java/eu/dnetlib/repo/manager/service/utils/EmailUtils.java create mode 100644 src/main/java/eu/dnetlib/repo/manager/service/utils/EmailUtilsImpl.java diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java index 1975701..58d97f0 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java @@ -18,23 +18,32 @@ import java.util.Map; @Api(description = "Broker API", tags = {"broker"}) public interface BrokerApi { - @RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.POST, + produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody DatasourcesBroker getDatasourcesOfUser(String user,String includeShared,String includeByOthers) throws BrokerException, JSONException; - @RequestMapping(value = "/getTopicsForDatasource/{datasourceName}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/getTopicsForDatasource/{datasourceName}" , method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody List getTopicsForDatasource(String datasourceName) throws BrokerException; - @RequestMapping(value = "/advancedShowEvents/{page}/{size}" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/advancedShowEvents/{page}/{size}" , method = RequestMethod.POST, + produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody EventsPage advancedShowEvents(String page, String size, AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException; - @RequestMapping(value = "/showEvents/{datasourceName}/{topic}/{page}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/showEvents/{datasourceName}/{topic}/{page}" , method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody EventsPage showEvents(String datasourceName, String topic, String page) throws BrokerException, JSONException; - @RequestMapping(value = "/getSimpleSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/getSimpleSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Map> getSimpleSubscriptionsOfUser(String userEmail) throws BrokerException; diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApi.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApi.java index f0903db..95fec39 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApi.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApi.java @@ -24,11 +24,11 @@ public interface PiWikApi { @RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) List getPiwikSitesForRepos(); - @RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET) @ResponseBody void approvePiwikSite(String repositoryId); - @RequestMapping(value = "/getOpenaireId/{repositoryid}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/getOpenaireId/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String getOpenaireId(String repositoryid); } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApiImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApiImpl.java index 031a236..35840b3 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApiImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/PiWikApiImpl.java @@ -77,14 +77,16 @@ public class PiWikApiImpl implements PiWikApi{ } @Override - public String getOpenaireId(@PathVariable("repositoryId") String repositoryid) { + public String getOpenaireId(@PathVariable("repositoryId") String repositoryId) { + LOGGER.debug("Getting openaire id for repository: " + repositoryId); try { - if (repositoryid != null && repositoryid.contains("::")) - return repositoryid.split("::")[0] + "::" + MD5.encrypt2Hex(repositoryid.split("::")[1]); + if (repositoryId != null && repositoryId.contains("::")) { + return repositoryId.split("::")[0] + "::" + MD5.encrypt2Hex(repositoryId.split("::")[1]); + } else return null; } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); + LOGGER.debug(e); } return null; } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java index 23a3690..a16dfc1 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java @@ -199,7 +199,6 @@ public class RepositoryApiImpl implements RepositoryApi { List reps = new ArrayList<>(); for (Repository r : rs) { - LOGGER.debug(r.getCollectedFrom()); if (r.getCollectedFrom() != null && r.getCollectedFrom().equals(mode)) reps.add(r); } @@ -216,7 +215,7 @@ public class RepositoryApiImpl implements RepositoryApi { RequestFilter requestFilter = new RequestFilter(); requestFilter.setRegisteredby(userEmail); String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); - LOGGER.debug(rs); + List repos = Converter.jsonToRepositoryList(new JSONObject(rs)); for (Repository r : repos) this.getRepositoryInfo(r); @@ -227,13 +226,13 @@ public class RepositoryApiImpl implements RepositoryApi { @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)); + LOGGER.debug("Retreiving repositories with id : " + id ); + UriComponents uriComponents = searchDatasource("0","100"); + RequestFilter requestFilter = new RequestFilter(); + requestFilter.setId(id); + String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); + JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); + Repository repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0)); if (repo != null) getRepositoryInfo(repo); return repo; @@ -243,20 +242,20 @@ public class RepositoryApiImpl implements RepositoryApi { @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); + LOGGER.debug("Retreiving aggregations for repository with id : " + id ); + UriComponents uriComponents = searchDatasource("0","100"); + RequestFilter requestFilter = new RequestFilter(); + requestFilter.setId(id); + String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, 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)); + LOGGER.debug(repository.getJSONArray("datasourceInfo").getJSONObject(0)); + aggregations.setAggregationHistory(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); + aggregations.setLastCollection(Converter.getLastCollectionFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); + aggregations.setLastTransformation(Converter.getLastTransformationFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); return aggregations; } catch (JSONException e) { LOGGER.debug("JSON aggregation exception ", e); @@ -269,13 +268,13 @@ public class RepositoryApiImpl implements RepositoryApi { public List 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); + LOGGER.debug("Retreiving repositories with official name : " + name ); + UriComponents uriComponents = searchDatasource("0","100"); + RequestFilter requestFilter = new RequestFilter(); + requestFilter.setOfficialname(name); + String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); + List repos = Converter.jsonToRepositoryList(new JSONObject(rs)); for (Repository r : repos) getRepositoryInfo(r); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApi.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApi.java index 2877c89..f70499f 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApi.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApi.java @@ -31,9 +31,9 @@ public interface ValidatorApi { @ResponseBody List getRuleSets(String mode); - @RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/getSetsOfRepository/{url}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - List getSetsOfRepository(@RequestBody String url); + List getSetsOfRepository(String url); @RequestMapping(value = "/identifyRepository/{url}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApiImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApiImpl.java index 81967b8..3aebfd9 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApiImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApiImpl.java @@ -126,7 +126,7 @@ public class ValidatorApiImpl implements ValidatorApi{ } @Override - public List getSetsOfRepository(@PathVariable("url") String url) { + public List getSetsOfRepository(@RequestParam(value = "url", required = true) String url) { LOGGER.debug("Getting sets of repository with url : " + url); try { return OaiTools.getSetsOfRepo(url); @@ -137,7 +137,7 @@ public class ValidatorApiImpl implements ValidatorApi{ } @Override - public boolean identifyRepo(@PathVariable("url") String url) { + public boolean identifyRepo(@RequestParam(value = "url", required = true) String url) { LOGGER.debug("Identify repository with url : " + url); try { return OaiTools.identifyRepository(url); @@ -185,7 +185,7 @@ public class ValidatorApiImpl implements ValidatorApi{ } @Override - public InterfaceInformation getInterfaceInformation(@PathVariable("baseUrl") String baseUrl) throws ValidationServiceException { + public InterfaceInformation getInterfaceInformation(@RequestParam(value = "baseUrl", required = true) String baseUrl) throws ValidationServiceException { try { LOGGER.debug("Getting interface information with url: " + baseUrl); InterfaceInformation interfaceInformation = new InterfaceInformation(); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java b/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java index d87364b..227305f 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java @@ -1,5 +1,6 @@ package eu.dnetlib.repo.manager.service.utils; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import eu.dnetlib.domain.data.Repository; import eu.dnetlib.domain.data.RepositoryInterface; @@ -21,9 +22,7 @@ public class Converter { 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)) @@ -97,11 +96,14 @@ public class Converter { 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); - + JSONArray organizations = ((JSONArray)datasource.get("organizations")); + if(organizations.length() != 0) { + 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"; @@ -300,19 +302,13 @@ public class Converter { return list; } - public static List getAggregationHistoryFromJson(JSONObject repositoryObject) throws JSONException { + public static List getAggregationHistoryFromJson(JSONObject datasourceInfo) throws JSONException { - /* if( repositoryObject.get("aggregationHistory").toString().equals("[]") || - repositoryObject.get("aggregationHistory")!= null) - return null;*/ - if(repositoryObject.get("aggregationHistory").toString().equals("[]")) + + if(datasourceInfo.get("aggregationHistory").toString().equals("[]")) return null; - - JSONArray rs = new JSONArray(repositoryObject.get("aggregationHistory").toString()); - - LOGGER.debug(rs.length()); - + JSONArray rs = new JSONArray(datasourceInfo.get("aggregationHistory").toString()); List aggregationDetailsList = new ArrayList<>(); for(int i=0;i toTimezones(List timezones) { diff --git a/src/main/java/eu/dnetlib/repo/manager/service/utils/EmailUtils.java b/src/main/java/eu/dnetlib/repo/manager/service/utils/EmailUtils.java new file mode 100644 index 0000000..df4db95 --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/service/utils/EmailUtils.java @@ -0,0 +1,18 @@ +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; +} diff --git a/src/main/java/eu/dnetlib/repo/manager/service/utils/EmailUtilsImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/utils/EmailUtilsImpl.java new file mode 100644 index 0000000..f82b782 --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/service/utils/EmailUtilsImpl.java @@ -0,0 +1,251 @@ +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 specialRecipients = new ArrayList(); + 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 recipients = new ArrayList(); + + 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 repoAdminMails) throws Exception { + ArrayList to = new ArrayList(); + to.add(email); + this.sendMail(to,subject,message,sendToSpecial,repoAdminMails); + } + + private void sendMail(List recipients, String subject, String message, boolean sendToSpecial, List 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; + } + + +} diff --git a/src/main/java/eu/dnetlib/repo/manager/service/utils/RequestFilter.java b/src/main/java/eu/dnetlib/repo/manager/service/utils/RequestFilter.java index 3644705..d2c0584 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/utils/RequestFilter.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/utils/RequestFilter.java @@ -1,11 +1,15 @@ package eu.dnetlib.repo.manager.service.utils; +import com.fasterxml.jackson.annotation.JsonInclude; +@JsonInclude(JsonInclude.Include.NON_NULL) public class RequestFilter{ - private String registeredby = ""; - private String typology = ""; - private String country = ""; + private String registeredby = null; + private String typology = null; + private String country = null; + private String id = null; + private String officialname = null; public RequestFilter() { @@ -35,4 +39,20 @@ public class RequestFilter{ 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; + } } diff --git a/src/main/java/eu/dnetlib/repo/manager/shared/broker/Subscription.java b/src/main/java/eu/dnetlib/repo/manager/shared/broker/Subscription.java index d32b12c..e5068a2 100644 --- a/src/main/java/eu/dnetlib/repo/manager/shared/broker/Subscription.java +++ b/src/main/java/eu/dnetlib/repo/manager/shared/broker/Subscription.java @@ -95,4 +95,6 @@ public class Subscription implements IsSerializable { public void setConditionsAsList(List conditionsAsList) { this.conditionsAsList = conditionsAsList; } + + }