diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java index 16764ec..757f1ca 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java @@ -71,6 +71,7 @@ public class BrokerApiImpl implements BrokerApi { for (JsonNode term : root.path("terms") ) topics.put(term.path("code").textValue(), parseTerm(term)); } catch (IOException e) { + LOGGER.debug(e); e.printStackTrace(); } } @@ -361,7 +362,7 @@ public class BrokerApiImpl implements BrokerApi { ) throws BrokerException { UriComponents uriComponents = UriComponentsBuilder - .fromHttpUrl(apiPath + "/openaireBroker/notifications/") + .fromHttpUrl(openairePath + "/notifications/") .path("/{id}/{page}/{size}/") .build().expand(subscriptionId,page, size).encode(); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApiImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApiImpl.java index 8783b14..1a761ee 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApiImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApiImpl.java @@ -6,6 +6,7 @@ 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; @@ -34,16 +35,17 @@ public class MonitorApiImpl implements MonitorApi { .getLogger(MonitorApiImpl.class); @Override - public JobsOfUser getJobsOfUser(String user, - String jobType, - String offset, - String limit, - String dateFrom, - String dateTo, - String validationStatus, - String includeJobsTotal) throws JSONException, ValidatorServiceException { + 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)); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java index b884de9..bc45ecf 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java @@ -2,9 +2,7 @@ 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.Aggregations; -import eu.dnetlib.repo.manager.shared.Country; -import eu.dnetlib.repo.manager.shared.Timezone; +import eu.dnetlib.repo.manager.shared.*; import io.swagger.annotations.Api; import org.json.JSONException; import org.springframework.http.MediaType; @@ -166,4 +164,9 @@ public interface RepositoryApi { String getCountryName(String countryCode); + + @RequestMapping(value = "/getMetricsInfoForRepository/{repoId}",method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody + MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException; } 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 52ba74d..4350fd6 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 @@ -6,24 +6,26 @@ 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.Aggregations; -import eu.dnetlib.repo.manager.shared.Constants; -import eu.dnetlib.repo.manager.shared.Country; -import eu.dnetlib.repo.manager.shared.Timezone; +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; @@ -49,6 +51,12 @@ public class RepositoryApiImpl implements RepositoryApi { 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; @@ -581,7 +589,7 @@ public class RepositoryApiImpl implements RepositoryApi { @Override public String updateLatitude(@RequestParam(value = "id") String id, - @RequestParam(value = "managed") String latitude) { + @RequestParam(value = "latitude") String latitude) { UriComponents uriComponents = UriComponentsBuilder .fromHttpUrl(baseAddress + "/ds/latitude/") @@ -763,4 +771,54 @@ public class RepositoryApiImpl implements RepositoryApi { 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 resp; + try { + //communicate with endpoint + resp = template.exchange( + builder.build().encode().toUri(), + HttpMethod.GET, + null, + new ParameterizedTypeReference() { + }); + } 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; + } + + } 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 75f46e7..ba19094 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 @@ -4,6 +4,7 @@ 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; @@ -52,4 +53,7 @@ public interface ValidatorApi { @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; } 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 26b307d..f49a1d9 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 @@ -3,6 +3,8 @@ 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; @@ -122,7 +124,7 @@ public class ValidatorApiImpl implements ValidatorApi{ } @Override - public List getSetsOfRepository(String url) { + public List getSetsOfRepository(@PathVariable("url") String url) { LOGGER.debug("Getting sets of repository with url : " + url); try { return OaiTools.getSetsOfRepo(url); @@ -133,7 +135,7 @@ public class ValidatorApiImpl implements ValidatorApi{ } @Override - public boolean identifyRepo(String url) { + public boolean identifyRepo(@PathVariable("url") String url) { LOGGER.debug("Identify repository with url : " + url); try { return OaiTools.identifyRepository(url); @@ -144,7 +146,7 @@ public class ValidatorApiImpl implements ValidatorApi{ } @Override - public RuleSet getRuleSet(String acronym) { + public RuleSet getRuleSet(@PathVariable("acronym") String acronym) { LOGGER.debug("Getting ruleset with acronym : " + acronym); RuleSet ruleSet = null; try { @@ -173,5 +175,22 @@ public class ValidatorApiImpl implements ValidatorApi{ 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); + } + } + } diff --git a/src/main/java/eu/dnetlib/repo/manager/shared/MetricsInfo.java b/src/main/java/eu/dnetlib/repo/manager/shared/MetricsInfo.java new file mode 100644 index 0000000..faf87cf --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/shared/MetricsInfo.java @@ -0,0 +1,36 @@ +package eu.dnetlib.repo.manager.shared; + +import com.google.gwt.user.client.rpc.IsSerializable; + +/** + * Created by stefania on 11/6/17. + */ +public class MetricsInfo implements IsSerializable { + + private MetricsNumbers metricsNumbers; + private String diagramsBaseURL; + + public MetricsInfo() { + } + + public MetricsInfo(MetricsNumbers metricsNumbers, String diagramsBaseURL) { + this.metricsNumbers = metricsNumbers; + this.diagramsBaseURL = diagramsBaseURL; + } + + public MetricsNumbers getMetricsNumbers() { + return metricsNumbers; + } + + public void setMetricsNumbers(MetricsNumbers metricsNumbers) { + this.metricsNumbers = metricsNumbers; + } + + public String getDiagramsBaseURL() { + return diagramsBaseURL; + } + + public void setDiagramsBaseURL(String diagramsBaseURL) { + this.diagramsBaseURL = diagramsBaseURL; + } +} diff --git a/src/main/java/eu/dnetlib/repo/manager/shared/MetricsNumbers.java b/src/main/java/eu/dnetlib/repo/manager/shared/MetricsNumbers.java new file mode 100644 index 0000000..d3e6175 --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/shared/MetricsNumbers.java @@ -0,0 +1,101 @@ +package eu.dnetlib.repo.manager.shared; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.gwt.user.client.rpc.IsSerializable; + +import java.util.List; + +/** + * Created by stefania on 11/7/17. + */ +public class MetricsNumbers implements IsSerializable { + + private List downloads; + private List views; + + @JsonProperty("total_downloads") + private String totalDownloads; + + @JsonProperty("total_views") + private String totalViews; + + @JsonProperty("total_openaire_downloads") + private String totalOpenAIREDownloads; + + @JsonProperty("total_openaire_views") + private String totalOpenAIREViews; + + @JsonProperty("pageviews") + private String pageViews; + + public MetricsNumbers() { + } + + public MetricsNumbers(List downloads, List views, String totalDownloads, String totalViews, + String totalOpenAIREDownloads, String totalOpenAIREViews, String pageViews) { + this.downloads = downloads; + this.views = views; + this.totalDownloads = totalDownloads; + this.totalViews = totalViews; + this.totalOpenAIREDownloads = totalOpenAIREDownloads; + this.totalOpenAIREViews = totalOpenAIREViews; + this.pageViews = pageViews; + } + + public List getDownloads() { + return downloads; + } + + public void setDownloads(List downloads) { + this.downloads = downloads; + } + + public List getViews() { + return views; + } + + public void setViews(List views) { + this.views = views; + } + + public String getTotalDownloads() { + return totalDownloads; + } + + public void setTotalDownloads(String totalDownloads) { + this.totalDownloads = totalDownloads; + } + + public String getTotalViews() { + return totalViews; + } + + public void setTotalViews(String totalViews) { + this.totalViews = totalViews; + } + + public String getTotalOpenAIREDownloads() { + return totalOpenAIREDownloads; + } + + public void setTotalOpenAIREDownloads(String totalOpenAIREDownloads) { + this.totalOpenAIREDownloads = totalOpenAIREDownloads; + } + + public String getTotalOpenAIREViews() { + return totalOpenAIREViews; + } + + public void setTotalOpenAIREViews(String totalOpenAIREViews) { + this.totalOpenAIREViews = totalOpenAIREViews; + } + + public String getPageViews() { + return pageViews; + } + + public void setPageViews(String pageViews) { + this.pageViews = pageViews; + } +} + diff --git a/src/main/resources/application-context.xml b/src/main/resources/application-context.xml index c5d0e89..5f0b431 100644 --- a/src/main/resources/application-context.xml +++ b/src/main/resources/application-context.xml @@ -1,36 +1,15 @@ - http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" - default-autowire="byType"> + - - - @@ -84,168 +62,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - openid - - - - - - ${webapp.home} - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/eu/dnetlib/repo/manager/service/aai-security.xml b/src/main/resources/eu/dnetlib/repo/manager/service/aai-security.xml new file mode 100644 index 0000000..e2ebd5c --- /dev/null +++ b/src/main/resources/eu/dnetlib/repo/manager/service/aai-security.xml @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + openid + + + + + + ${webapp.home} + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/eu/dnetlib/repo/manager/service/application.properties b/src/main/resources/eu/dnetlib/repo/manager/service/application.properties index 32f97c2..bc135bd 100644 --- a/src/main/resources/eu/dnetlib/repo/manager/service/application.properties +++ b/src/main/resources/eu/dnetlib/repo/manager/service/application.properties @@ -106,4 +106,8 @@ webapp.front=http://localhost:8380/ redis.host = 83.212.101.85 #redis.port = 6379 -#redis.password \ No newline at end of file +#redis.password + +services.repomanager.usageStatisticsDiagramsBaseURL = https://beta.openaire.eu/stats3/ +services.repomanager.usageStatisticsNumbersBaseURL = https://beta.services.openaire.eu/usagestats/datasources/ +services.repomanager.usagestats.adminEmail = repositoryusagestats@openaire.eu \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/applicationContext.xml b/src/main/webapp/WEB-INF/applicationContext.xml index 87f064d..a7cd216 100644 --- a/src/main/webapp/WEB-INF/applicationContext.xml +++ b/src/main/webapp/WEB-INF/applicationContext.xml @@ -15,22 +15,22 @@ - - - - - - - - - - - - - - -->