Compare commits

...

3 Commits

Author SHA1 Message Date
Ioannis Diplas cba5f4ec17 Removing unused files 2019-07-23 12:31:25 +00:00
Ioannis Diplas ee78250918 Cleaning code smells 2019-07-23 12:30:46 +00:00
Ioannis Diplas 22605ad0ad Creatin branch for code cleanup 2019-07-23 09:50:25 +00:00
32 changed files with 350 additions and 839 deletions

84
pom.xml
View File

@ -176,20 +176,12 @@
<artifactId>springfox-swagger-ui</artifactId> <artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version> <version>2.7.0</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/cz.habarta.typescript-generator/typescript-generator-maven-plugin -->
<!--<dependency>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-maven-plugin</artifactId>
<version>1.29.366</version>
</dependency>-->
<!-- https://mvnrepository.com/artifact/postgresql/postgresql --> <!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
<dependency> <dependency>
<groupId>postgresql</groupId> <groupId>postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<version>9.1-901.jdbc3</version> <version>9.1-901.jdbc3</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina --> <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
<dependency> <dependency>
<groupId>org.apache.tomcat</groupId> <groupId>org.apache.tomcat</groupId>
@ -304,82 +296,6 @@
<failOnMissingWebXml>false</failOnMissingWebXml> <failOnMissingWebXml>false</failOnMissingWebXml>
</configuration> </configuration>
</plugin> </plugin>
<!--<plugin>-->
<!--<groupId>com.googlecode.maven-download-plugin</groupId>-->
<!--<artifactId>download-maven-plugin</artifactId>-->
<!--<version>1.3.0</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<phase>process-resources</phase>-->
<!--<goals>-->
<!--<goal>wget</goal>-->
<!--</goals>-->
<!--<configuration>-->
<!--<url>-->
<!--https://github.com/ostranme/swagger-ui-themes/archive/v3.0.0.zip-->
<!--</url>-->
<!--<unpack>true</unpack>-->
<!--<outputDirectory>${project.build.directory}</outputDirectory>-->
<!--</configuration>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<sequential>
<echo>Add theme</echo>
<replace token="&lt;/head&gt;"
value="&lt;link href='webjars/springfox-swagger-ui/themes/2.x/theme-feeling-blue.css' rel=&quot;stylesheet&quot;/&gt;&lt;/head&gt;"
dir="${settings.localRepository}/io/springfox/springfox-swagger-ui/2.7.0/META-INF/resources">
<include name="swagger-ui.html"/>
</replace>
</sequential>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
-->
<!--<plugin>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-maven-plugin</artifactId>
<version>1.29.366</version>
<executions>
<execution>
<id>generate1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<jsonLibrary>jackson2</jsonLibrary>
<outputFileType>implementationFile</outputFileType>
<mapClasses>asClasses</mapClasses>
<classPatterns>
<pattern>eu.dnetlib.domain.data.*</pattern>
</classPatterns>
<outputFile>target/typeScriptClasses.ts</outputFile>
<outputKind>module</outputKind>
</configuration>
</execution>
</executions>
</plugin>-->
</plugins> </plugins>
<finalName>uoa-repository-manager-service</finalName> <finalName>uoa-repository-manager-service</finalName>
<resources> <resources>

View File

@ -1,8 +1,6 @@
package eu.dnetlib.repo.manager.config; package eu.dnetlib.repo.manager.config;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import java.util.Properties; import java.util.Properties;
@ -38,18 +36,12 @@ public class CascadingPropertyLoader extends PropertyPlaceholderConfigurer imple
logger.debug("Properties: " + properties); logger.debug("Properties: " + properties);
} }
@Override
protected void processProperties(final ConfigurableListableBeanFactory beanFactoryToProcess, final Properties props) throws BeansException {
super.processProperties(beanFactoryToProcess, props);
}
public Properties getProperties() { public Properties getProperties() {
return properties; return properties;
} }
@Override
public void setProperties(final Properties properties) { public void setProperties(final Properties properties) {
super.setProperties(properties);
this.properties = properties; this.properties = properties;
} }
} }

View File

@ -22,7 +22,7 @@ import javax.annotation.PostConstruct;
@ComponentScan(basePackages = "eu.dnetlib.repo.manager.*") @ComponentScan(basePackages = "eu.dnetlib.repo.manager.*")
public class Config { public class Config {
private static Logger LOGGER = Logger.getLogger(Config.class); private static Logger logger = Logger.getLogger(Config.class);
@Value("${redis.host:194.177.192.121}") @Value("${redis.host:194.177.192.121}")
private String host; private String host;
@ -34,16 +34,16 @@ public class Config {
private String password; private String password;
@Value("${aai.mode}") @Value("${aai.mode}")
private String aai_mode; private String aaiMode;
@PostConstruct @PostConstruct
private void init(){ private void init(){
LOGGER.info(host); logger.info(host);
} }
@Bean @Bean
JedisConnectionFactory connectionFactory() { JedisConnectionFactory connectionFactory() {
LOGGER.info(String.format("Redis : %s Port : %s Password : %s",host,port,password)); logger.info(String.format("Redis : %s Port : %s Password : %s",host,port,password));
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(); JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
jedisConnectionFactory.setHostName(host); jedisConnectionFactory.setHostName(host);
jedisConnectionFactory.setPort(Integer.parseInt(port)); jedisConnectionFactory.setPort(Integer.parseInt(port));
@ -56,10 +56,9 @@ public class Config {
DefaultCookieSerializer serializer = new DefaultCookieSerializer(); DefaultCookieSerializer serializer = new DefaultCookieSerializer();
serializer.setCookieName("openAIRESession"); serializer.setCookieName("openAIRESession");
serializer.setCookiePath("/"); serializer.setCookiePath("/");
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta")) if(aaiMode.equalsIgnoreCase("production") || aaiMode.equalsIgnoreCase("beta"))
serializer.setDomainName(".openaire.eu"); serializer.setDomainName(".openaire.eu");
// serializer.setDomainName(".athenarc.gr"); logger.info("Serializer : " + serializer);
LOGGER.info("Serializer : " + serializer);
return serializer; return serializer;
} }

View File

@ -19,16 +19,18 @@ public class FrontEndLinkURIAuthenticationSuccessHandler implements Authenticati
private String frontEndURI; private String frontEndURI;
private static final Logger LOGGER = Logger private static final Logger logger = Logger
.getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class); .getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class);
public void init(){ public void init(){
LOGGER.debug("Front end uri : " + frontEndURI); logger.debug("Front end uri : " + frontEndURI);
} }
@Value("${aai.mode}") @Value("${aai.mode}")
private String aai_mode; private String aaiMode;
private final static String ENCODING = "UTF-8";
@Override @Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
@ -39,46 +41,48 @@ public class FrontEndLinkURIAuthenticationSuccessHandler implements Authenticati
if (authOIDC.getUserInfo().getSub() == null) if (authOIDC.getUserInfo().getSub() == null)
userInfo.addProperty("sub", ""); userInfo.addProperty("sub", "");
else else
userInfo.addProperty("sub", URLEncoder.encode(authOIDC.getUserInfo().getSub(), "UTF-8")); userInfo.addProperty("sub", URLEncoder.encode(authOIDC.getUserInfo().getSub(), ENCODING));
if(authOIDC.getUserInfo().getName() != null) if(authOIDC.getUserInfo().getName() != null)
userInfo.addProperty("fullname", URLEncoder.encode(authOIDC.getUserInfo().getName(), "UTF-8")); userInfo.addProperty("fullname", URLEncoder.encode(authOIDC.getUserInfo().getName(), ENCODING));
if (authOIDC.getUserInfo().getGivenName() == null) if (authOIDC.getUserInfo().getGivenName() == null)
userInfo.addProperty("firstname", ""); userInfo.addProperty("firstname", "");
else else
userInfo.addProperty("firstname", URLEncoder.encode(authOIDC.getUserInfo().getGivenName(), "UTF-8") + ""); userInfo.addProperty("firstname", URLEncoder.encode(authOIDC.getUserInfo().getGivenName(), ENCODING) + "");
if (authOIDC.getUserInfo().getFamilyName() == null) if (authOIDC.getUserInfo().getFamilyName() == null)
userInfo.addProperty("lastname", ""); userInfo.addProperty("lastname", "");
else else
userInfo.addProperty("lastname", URLEncoder.encode(authOIDC.getUserInfo().getFamilyName(), "UTF-8") + ""); userInfo.addProperty("lastname", URLEncoder.encode(authOIDC.getUserInfo().getFamilyName(), ENCODING) + "");
userInfo.addProperty("email", authOIDC.getUserInfo().getEmail() + ""); userInfo.addProperty("email", authOIDC.getUserInfo().getEmail() + "");
if (authOIDC.getUserInfo().getSource().getAsJsonArray("edu_person_entitlements") == null) if (authOIDC.getUserInfo().getSource().getAsJsonArray("edu_person_entitlements") == null)
userInfo.addProperty("role", ""); userInfo.addProperty("role", "");
else else
userInfo.addProperty("role", URLEncoder.encode(authOIDC.getUserInfo() userInfo.addProperty("role", URLEncoder.encode(authOIDC.getUserInfo()
.getSource().getAsJsonArray("edu_person_entitlements").toString(), "UTF-8") + ""); .getSource().getAsJsonArray("edu_person_entitlements").toString(), ENCODING) + "");
Cookie openAIREUser = new Cookie("openAIREUser", new Gson().toJson(userInfo) ); Cookie openAIREUser = new Cookie("openAIREUser", new Gson().toJson(userInfo) );
openAIREUser.setMaxAge(14400); openAIREUser.setMaxAge(14400);
openAIREUser.setPath("/"); openAIREUser.setPath("/");
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta")) openAIREUser.setHttpOnly(true);
if(aaiMode.equalsIgnoreCase("production") || aaiMode.equalsIgnoreCase("beta"))
openAIREUser .setDomain(".openaire.eu"); openAIREUser .setDomain(".openaire.eu");
// openAIREUser.setDomain(".athenarc.gr");
response.addCookie(openAIREUser); response.addCookie(openAIREUser);
Cookie accessToken = new Cookie("AccessToken", authOIDC.getAccessTokenValue()); Cookie accessToken = new Cookie("AccessToken", authOIDC.getAccessTokenValue());
accessToken.setMaxAge(14400); accessToken.setMaxAge(14400);
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta")) accessToken.setHttpOnly(true);
if(aaiMode.equalsIgnoreCase("production") || aaiMode.equalsIgnoreCase("beta"))
accessToken.setDomain(".openaire.eu"); accessToken.setDomain(".openaire.eu");
accessToken.setPath("/"); accessToken.setPath("/");
// accessToken.setDomain(".athenarc.gr");
response.addCookie(accessToken); response.addCookie(accessToken);
response.sendRedirect(frontEndURI); response.sendRedirect(frontEndURI);
} }

View File

@ -14,7 +14,7 @@ public class OpenAireProviderAuthoritiesMapper implements OIDCAuthoritiesMapper
private static Logger logger = LoggerFactory.getLogger(OpenAireProviderAuthoritiesMapper.class); private static Logger logger = LoggerFactory.getLogger(OpenAireProviderAuthoritiesMapper.class);
final private static String ROLE_CLAIMS = "edu_person_entitlements"; private final static String ROLE_CLAIMS = "edu_person_entitlements";
private Map<String,SimpleGrantedAuthority> userRolesMap; private Map<String,SimpleGrantedAuthority> userRolesMap;
@ -32,7 +32,7 @@ public class OpenAireProviderAuthoritiesMapper implements OIDCAuthoritiesMapper
userInfo.getSource().getAsJsonArray(ROLE_CLAIMS).forEach(role -> { userInfo.getSource().getAsJsonArray(ROLE_CLAIMS).forEach(role -> {
SimpleGrantedAuthority authority = userRolesMap.get(role.getAsString()); SimpleGrantedAuthority authority = userRolesMap.get(role.getAsString());
if (authority != null) { if (authority != null) {
logger.debug("Role mapped " + role); logger.debug(String.format("Role mapped %s",role));
out.add(authority); out.add(authority);
} }
}); });

View File

@ -36,7 +36,6 @@ public class RepoManagerContextLoaderListener extends ContextLoaderListener {
logger.info("User mode: " + userMode); logger.info("User mode: " + userMode);
logger.info("Repo mode: " + repoMode); logger.info("Repo mode: " + repoMode);
logger.info("Standalone mode: " + standaloneMode); logger.info("Standalone mode: " + standaloneMode);
// logger.info("Dnet workflow enabled: " + repoMode);
XmlWebApplicationContext ctx = new XmlWebApplicationContext(); XmlWebApplicationContext ctx = new XmlWebApplicationContext();
ctx.setServletContext(servletContext); ctx.setServletContext(servletContext);
@ -56,11 +55,7 @@ public class RepoManagerContextLoaderListener extends ContextLoaderListener {
"classpath*:/eu/dnetlib/repos/ehcacher/springContext-repos-ehcacher.xml", "classpath*:/eu/dnetlib/repos/ehcacher/springContext-repos-ehcacher.xml",
"classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml", "classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml",
"classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml", "classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml",
// "classpath*:/eu/dnetlib/validator/web/actions/springContext-validator-struts.xml",
// "classpath*:/eu/dnetlib/validator/web/actions/springContext-validator-emailer.xml",
// "classpath*:/eu/dnetlib/validator/web/config/springContext-validator.xml",
"classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml", "classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml",
// "classpath*:/eu/dnetlib/validator/commons/dao/springContext-*.xml",
"classpath*:/eu/dnetlib/repos/springContext-repos-" + repoMode + ".xml", "classpath*:/eu/dnetlib/repos/springContext-repos-" + repoMode + ".xml",
"classpath*:/" + userApiContext "classpath*:/" + userApiContext
}; };

View File

@ -23,9 +23,6 @@ import java.net.UnknownHostException;
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
public class GenericControllerAdvice { public class GenericControllerAdvice {
private Logger logger = LogManager.getLogger(GenericControllerAdvice.class);
@ResponseStatus(HttpStatus.NOT_FOUND) @ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(ResourceNotFoundException.class) @ExceptionHandler(ResourceNotFoundException.class)
@ResponseBody @ResponseBody

View File

@ -18,9 +18,6 @@ import org.springframework.web.bind.annotation.*;
@Api(description = "Monitor API", tags = {"monitor"}) @Api(description = "Monitor API", tags = {"monitor"})
public class MonitorController { public class MonitorController {
private static final Logger LOGGER = Logger
.getLogger(MonitorController.class);
@Autowired @Autowired
private MonitorServiceImpl monitorService; private MonitorServiceImpl monitorService;
@ -35,8 +32,8 @@ public class MonitorController {
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit, @RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom, @RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo, @RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus, @RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs") String validationStatus,
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException { @RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws ValidatorServiceException {
return monitorService.getJobsOfUser(user, jobType, offset, limit, dateFrom, dateTo, validationStatus, includeJobsTotal); return monitorService.getJobsOfUser(user, jobType, offset, limit, dateFrom, dateTo, validationStatus, includeJobsTotal);
} }
@ -46,14 +43,14 @@ public class MonitorController {
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")
public int getJobsOfUserPerValidationStatus(@RequestBody String user, public int getJobsOfUserPerValidationStatus(@RequestBody String user,
@RequestBody String jobType, @RequestBody String jobType,
@RequestBody String validationStatus) throws JSONException { @RequestBody String validationStatus){
return monitorService.getJobsOfUserPerValidationStatus(user, jobType, validationStatus); return monitorService.getJobsOfUserPerValidationStatus(user, jobType, validationStatus);
} }
@RequestMapping(value = "/getJobSummary" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/getJobSummary" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
public StoredJob getJobSummary(@RequestParam String jobId, public StoredJob getJobSummary(@RequestParam String jobId,
@RequestParam String groupBy) throws JSONException { @RequestParam String groupBy){
return monitorService.getJobSummary(jobId, groupBy); return monitorService.getJobSummary(jobId, groupBy);
} }

View File

@ -34,7 +34,7 @@ import java.util.List;
@Api(description = "Piwik API", tags = {"piwik"}) @Api(description = "Piwik API", tags = {"piwik"})
public class PiWikController { public class PiWikController {
private static final Logger LOGGER = Logger private static final Logger logger = Logger
.getLogger(PiWikController.class); .getLogger(PiWikController.class);
@Autowired @Autowired
@ -123,7 +123,7 @@ public class PiWikController {
writer.write(sb.toString()); writer.write(sb.toString());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
LOGGER.error(e.getMessage()); logger.error(e.getMessage());
} }
@ -136,7 +136,7 @@ public class PiWikController {
String headerKey = "Content-Disposition"; String headerKey = "Content-Disposition";
SimpleDateFormat sdfDate = new SimpleDateFormat("ddMMyyyy");//dd/MM/yyyy SimpleDateFormat sdfDate = new SimpleDateFormat("ddMMyyyy");
Date now = new Date(); Date now = new Date();
String strDate = sdfDate.format(now); String strDate = sdfDate.format(now);
String headerValue = String.format("attachment; filename=\"csv-%s.csv\"", String headerValue = String.format("attachment; filename=\"csv-%s.csv\"",

View File

@ -108,7 +108,6 @@ public class RepositoryController {
@RequestMapping(value = "/addRepository", method = RequestMethod.POST, @RequestMapping(value = "/addRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE) consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
// @PreAuthorize("hasRole('ROLE_USER') and #repository.registeredBy == authentication.userInfo.email")
public Repository addRepository(@RequestParam("datatype") String datatype, public Repository addRepository(@RequestParam("datatype") String datatype,
@RequestBody Repository repository) throws Exception { @RequestBody Repository repository) throws Exception {
@ -139,7 +138,6 @@ public class RepositoryController {
@RequestMapping(value = "/updateRepository", method = RequestMethod.POST, @RequestMapping(value = "/updateRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE) consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
//@PreAuthorize("hasRole('ROLE_USER') and #repository.registeredBy == authentication.userInfo.email")
public Repository updateRepository(@RequestBody Repository repository,Authentication authentication) throws Exception { public Repository updateRepository(@RequestBody Repository repository,Authentication authentication) throws Exception {
return repositoryService.updateRepository(repository, authentication); return repositoryService.updateRepository(repository, authentication);
} }

View File

@ -25,10 +25,8 @@ public class RestTemplateResponseErrorHandler implements ResponseErrorHandler {
if (httpResponse.getStatusCode().series() == HttpStatus.Series.SERVER_ERROR) { if (httpResponse.getStatusCode().series() == HttpStatus.Series.SERVER_ERROR) {
throw new EndPointException(); throw new EndPointException();
} else if (httpResponse.getStatusCode().series() == HttpStatus.Series.CLIENT_ERROR) { } else if (httpResponse.getStatusCode().series() == HttpStatus.Series.CLIENT_ERROR && httpResponse.getStatusCode() == HttpStatus.NOT_FOUND) {
if (httpResponse.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new IOException(); throw new IOException();
} }
} }
} }
}

View File

@ -55,13 +55,13 @@ public class ValidatorController {
@RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
public List<String> getSetsOfRepository(@RequestParam(value = "url", required = true) String url) { public List<String> getSetsOfRepository(@RequestParam(value = "url") String url) {
return validatorService.getSetsOfRepository(url); return validatorService.getSetsOfRepository(url);
} }
@RequestMapping(value = "/identifyRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/identifyRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
public boolean identifyRepo(@RequestParam(value = "url", required = true) String url) { public boolean identifyRepo(@RequestParam(value = "url") String url) {
return validatorService.identifyRepo(url); return validatorService.identifyRepo(url);
} }
@ -94,7 +94,7 @@ public class ValidatorController {
@RequestMapping(value = "/getInterfaceInformation" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/getInterfaceInformation" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
public InterfaceInformation getInterfaceInformation(@RequestParam(value = "baseUrl", required = true) String baseUrl) throws ValidationServiceException { public InterfaceInformation getInterfaceInformation(@RequestParam(value = "baseUrl") String baseUrl) throws ValidationServiceException {
return validatorService.getInterfaceInformation(baseUrl); return validatorService.getInterfaceInformation(baseUrl);
} }

View File

@ -1,11 +1,7 @@
package eu.dnetlib.repo.manager.exception; package eu.dnetlib.repo.manager.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.io.IOException; import java.io.IOException;
//@ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
public class EndPointException extends IOException { public class EndPointException extends IOException {
public EndPointException() { public EndPointException() {

View File

@ -44,5 +44,4 @@ public interface BrokerService {
EventsPage getNotificationsBySubscriptionId(String subscriptionId, String page, String size) throws BrokerException; EventsPage getNotificationsBySubscriptionId(String subscriptionId, String page, String size) throws BrokerException;
Map<String, List<Subscription>> getSubscriptionsOfUser(String userEmail) throws BrokerException;
} }

View File

@ -39,7 +39,7 @@ public class BrokerServiceImpl implements BrokerService {
@Value("${topic_types.url}") @Value("${topic_types.url}")
private String topicsURL; private String topicsURL;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger
.getLogger(BrokerServiceImpl.class); .getLogger(BrokerServiceImpl.class);
@Autowired @Autowired
@ -58,14 +58,14 @@ public class BrokerServiceImpl implements BrokerService {
httpHeaders = new HttpHeaders(); httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json"); httpHeaders.set("Content-Type", "application/json");
LOGGER.debug("Init dnet topics!"); logger.debug("Init dnet topics!");
try (InputStream is = new URL(topicsURL).openStream() ){ try (InputStream is = new URL(topicsURL).openStream() ){
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(is); JsonNode root = mapper.readTree(is);
for (JsonNode term : root.path("terms") ) for (JsonNode term : root.path("terms") )
topics.put(term.path("code").textValue(), parseTerm(term)); topics.put(term.path("code").textValue(), parseTerm(term));
} catch (IOException e) { } catch (IOException e) {
LOGGER.debug("Exception on initDnetTopicsMap" , e); logger.debug("Exception on initDnetTopicsMap" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
} }
} }
@ -82,7 +82,6 @@ public class BrokerServiceImpl implements BrokerService {
DatasourcesBroker ret = new DatasourcesBroker(); DatasourcesBroker ret = new DatasourcesBroker();
try { try {
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(user))); ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
//TODO fix bug when values are true
if (Boolean.parseBoolean(includeShared)) { if (Boolean.parseBoolean(includeShared)) {
List<String> sharedDatasourceIds = new ArrayList<String>(); List<String> sharedDatasourceIds = new ArrayList<String>();
ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds))); ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds)));
@ -92,7 +91,7 @@ public class BrokerServiceImpl implements BrokerService {
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user))); ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
} }
} catch (BrokerException e) { } catch (BrokerException e) {
LOGGER.debug("Exception on getDatasourcesOfUser" , e); logger.debug("Exception on getDatasourcesOfUser" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
} }
@ -115,7 +114,7 @@ public class BrokerServiceImpl implements BrokerService {
new ParameterizedTypeReference<List<BrowseEntry>>() { new ParameterizedTypeReference<List<BrowseEntry>>() {
}); });
} catch (RestClientException e) { } catch (RestClientException e) {
LOGGER.debug("Exception on getTopicsForDatasource" , e); logger.debug("Exception on getTopicsForDatasource" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new BrokerException(e); throw new BrokerException(e);
} }
@ -126,7 +125,7 @@ public class BrokerServiceImpl implements BrokerService {
@Override @Override
public EventsPage advancedShowEvents(String page, public EventsPage advancedShowEvents(String page,
String size, String size,
AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException { AdvQueryObject advQueryObject) throws BrokerException {
final String service = "/events/{page}/{pageSize}"; final String service = "/events/{page}/{pageSize}";
@ -136,7 +135,6 @@ public class BrokerServiceImpl implements BrokerService {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
advQueryObject.setPage(Long.parseLong(page)); advQueryObject.setPage(Long.parseLong(page));
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, httpHeaders); HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, httpHeaders);
ResponseEntity<EventsPage> resp; ResponseEntity<EventsPage> resp;
@ -149,7 +147,7 @@ public class BrokerServiceImpl implements BrokerService {
} }
); );
} catch (RestClientException e) { } catch (RestClientException e) {
LOGGER.debug("Exception on advancedShowEvents" , e); logger.debug("Exception on advancedShowEvents" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new BrokerException(e); throw new BrokerException(e);
} }
@ -165,7 +163,7 @@ public class BrokerServiceImpl implements BrokerService {
for (Repository repo : repositories) { for (Repository repo : repositories) {
BrowseEntry temp = new BrowseEntry(); BrowseEntry temp = new BrowseEntry();
temp.setValue(repo.getOfficialName()); temp.setValue(repo.getOfficialName());
temp.setSize(new Long(0)); temp.setSize(0L);
for (BrowseEntry e : getTopicsForDatasource(repo.getOfficialName())) { for (BrowseEntry e : getTopicsForDatasource(repo.getOfficialName())) {
temp.setSize(temp.getSize() + e.getSize()); temp.setSize(temp.getSize() + e.getSize());
} }
@ -174,12 +172,7 @@ public class BrokerServiceImpl implements BrokerService {
} }
// sort the collection by the second field of the tuple which is size // sort the collection by the second field of the tuple which is size
Collections.sort(entries, new Comparator<Tuple<BrowseEntry, String>>() { entries.sort((e1, e2) -> (int) (e2.getFirst().getSize() - e1.getFirst().getSize()));
@Override
public int compare(Tuple<BrowseEntry, String> e1, Tuple<BrowseEntry, String> e2) {
return (int) (e2.getFirst().getSize().longValue() - e1.getFirst().getSize().longValue());
}
});
return entries; return entries;
} }
@ -201,14 +194,14 @@ public class BrokerServiceImpl implements BrokerService {
} }
private List<Repository> getRepositoriesByIds(List<String> sharedDatasourceIds) { private List<Repository> getRepositoriesByIds(List<String> sharedDatasourceIds) {
return null; return new ArrayList<>();
} }
@Override @Override
public EventsPage showEvents(String datasourceName, public EventsPage showEvents(String datasourceName,
String topic, String topic,
String page, String page,
String size) throws BrokerException, JSONException { String size) throws BrokerException{
final String service = "/events"; final String service = "/events";
@ -226,7 +219,7 @@ public class BrokerServiceImpl implements BrokerService {
new ParameterizedTypeReference<EventsPage>() { new ParameterizedTypeReference<EventsPage>() {
}); });
} catch (RestClientException e) { } catch (RestClientException e) {
LOGGER.debug("Exception on showEvents" , e); logger.debug("Exception on showEvents" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new BrokerException(e); throw new BrokerException(e);
} }
@ -242,7 +235,7 @@ public class BrokerServiceImpl implements BrokerService {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service) UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("email", userEmail); .queryParam("email", userEmail);
LOGGER.debug(builder.build().encode().toUri()); logger.debug(builder.build().encode().toUri());
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp; ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
try { try {
resp = restTemplate.exchange( resp = restTemplate.exchange(
@ -252,7 +245,7 @@ public class BrokerServiceImpl implements BrokerService {
new ParameterizedTypeReference<Map<String, List<SimpleSubscriptionDesc>>>() { new ParameterizedTypeReference<Map<String, List<SimpleSubscriptionDesc>>>() {
}); });
} catch (RestClientException e) { } catch (RestClientException e) {
LOGGER.debug("Exception on getSimpleSubscriptionsOfUser" , e); logger.debug("Exception on getSimpleSubscriptionsOfUser" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new BrokerException(e); throw new BrokerException(e);
} }
@ -281,7 +274,7 @@ public class BrokerServiceImpl implements BrokerService {
new ParameterizedTypeReference<Subscription>() { new ParameterizedTypeReference<Subscription>() {
}); });
} catch (RestClientException e) { } catch (RestClientException e) {
LOGGER.debug("Exception on OpenaireSubscription" , e); logger.debug("Exception on OpenaireSubscription" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new BrokerException(e); throw new BrokerException(e);
} }
@ -305,7 +298,7 @@ public class BrokerServiceImpl implements BrokerService {
new ParameterizedTypeReference<Void>() { new ParameterizedTypeReference<Void>() {
}); });
} catch (RestClientException e) { } catch (RestClientException e) {
LOGGER.debug("Exception on unsubscribe" , e); logger.debug("Exception on unsubscribe" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new BrokerException(e); throw new BrokerException(e);
} }
@ -329,7 +322,7 @@ public class BrokerServiceImpl implements BrokerService {
new ParameterizedTypeReference<Subscription>() { new ParameterizedTypeReference<Subscription>() {
}); });
} catch (RestClientException e) { } catch (RestClientException e) {
LOGGER.debug("Exception on getSubscription" , e); logger.debug("Exception on getSubscription" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new BrokerException(e); throw new BrokerException(e);
} }
@ -337,7 +330,7 @@ public class BrokerServiceImpl implements BrokerService {
} }
@Override @Override
public Map<String, Term> getDnetTopics() throws BrokerException { public Map<String, Term> getDnetTopics(){
return topics; return topics;
} }
@ -360,31 +353,11 @@ public class BrokerServiceImpl implements BrokerService {
new ParameterizedTypeReference<EventsPage>() { new ParameterizedTypeReference<EventsPage>() {
}); });
} catch (RestClientException e) { } catch (RestClientException e) {
LOGGER.debug("Exception on getNotificationsBySubscriptionId" , e); logger.debug("Exception on getNotificationsBySubscriptionId" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new BrokerException(e); throw new BrokerException(e);
} }
return resp.getBody(); return resp.getBody();
} }
//@Override
public Map<String, List<Subscription>> getSubscriptionsOfUser(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

@ -22,9 +22,6 @@ public class DashboardServiceImpl implements DashboardService {
private static final Logger logger = Logger.getLogger(DashboardServiceImpl.class); private static final Logger logger = Logger.getLogger(DashboardServiceImpl.class);
@Autowired
private EmailUtils emailUtils;
@Autowired @Autowired
private RepositoryService repositoryService; private RepositoryService repositoryService;
@ -32,9 +29,9 @@ public class DashboardServiceImpl implements DashboardService {
private BrokerService brokerService; private BrokerService brokerService;
@Override @Override
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail, public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(String userEmail,
@PathVariable("page") String page, String page,
@PathVariable("size") String size) throws JSONException { String size){
List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>(); List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>();
@ -48,7 +45,6 @@ try {
repositorySummaryInfo.setRepositoryName(repository.getOfficialName()); repositorySummaryInfo.setRepositoryName(repository.getOfficialName());
repositorySummaryInfo.setLogoURL(repository.getLogoUrl()); repositorySummaryInfo.setLogoURL(repository.getLogoUrl());
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
List<AggregationDetails> aggregationDetailsList = repositoryService.getRepositoryAggregations(repository.getId()); List<AggregationDetails> aggregationDetailsList = repositoryService.getRepositoryAggregations(repository.getId());
for(AggregationDetails aggregationDetails: aggregationDetailsList) { for(AggregationDetails aggregationDetails: aggregationDetailsList) {
if(aggregationDetails.getIndexedVersion()) { if(aggregationDetails.getIndexedVersion()) {
@ -86,7 +82,6 @@ try {
} catch (Exception e) { } catch (Exception e) {
logger.error("Something baad happened!", e); logger.error("Something baad happened!", e);
e.printStackTrace();
} }
return repositorySummaryInfoList; return repositorySummaryInfoList;

View File

@ -23,11 +23,11 @@ import java.util.List;
@Component("emailUtils") @Component("emailUtils")
public class EmailUtilsImpl implements EmailUtils { public class EmailUtilsImpl implements EmailUtils {
private static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class); private static Logger logger = Logger.getLogger(EmailUtilsImpl.class);
private List<String> specialRecipients = new ArrayList<String>(); private List<String> specialRecipients = new ArrayList<>();
private boolean override = false, logonly = false; private boolean override = false, logonly = false;
private String overrideEmail = null, from = null; private String overrideEmail = null;
@Autowired @Autowired
private MailLibrary mailLibrary; private MailLibrary mailLibrary;
@ -50,7 +50,7 @@ public class EmailUtilsImpl implements EmailUtils {
@PostConstruct @PostConstruct
public void init(){ public void init(){
System.out.println("url -> " + this.baseUrl); logger.info(String.format("url -> %s", this.baseUrl));
} }
@ -68,7 +68,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "Automatic Bug Report"; String subject = "Automatic Bug Report";
this.sendMail(recipients, subject, message, false, null); this.sendMail(recipients, subject, message, false, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error sending error report", e); logger.error("Error sending error report", e);
} }
} }
@ -96,7 +96,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.usageStatsAdminEmail, subject, message, false, null); this.sendMail(this.usageStatsAdminEmail, subject, message, false, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e); logger.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e);
throw e; throw e;
} }
} }
@ -133,7 +133,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null); this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e); logger.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e);
throw e; throw e;
} }
} }
@ -160,7 +160,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.usageStatsAdminEmail, subject, message, false, null); this.sendMail(this.usageStatsAdminEmail, subject, message, false, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e); logger.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e);
throw e; throw e;
} }
} }
@ -188,7 +188,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null); this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e); logger.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e);
throw e; throw e;
} }
} }
@ -214,7 +214,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message, false, null); this.sendMail(this.provideAdminEmail, subject, message, false, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending registration notification email to the administrator", e); logger.error("Error while sending registration notification email to the administrator", e);
throw e; throw e;
} }
} }
@ -241,7 +241,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(repository.getRegisteredBy(), subject, message, false, null); this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); logger.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
throw e; throw e;
} }
} }
@ -264,7 +264,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message, false, null); this.sendMail(this.provideAdminEmail, subject, message, false, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending registration notification email to the administrator", e); logger.error("Error while sending registration notification email to the administrator", e);
throw e; throw e;
} }
} }
@ -288,7 +288,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(repository.getRegisteredBy(), subject, message, false, null); this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); logger.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
throw e; throw e;
} }
} }
@ -310,7 +310,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(jobForValidation.getUserEmail(), subject, message, false, null); this.sendMail(jobForValidation.getUserEmail(), subject, message, false, null);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e); logger.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e);
throw e; throw e;
} }
} }
@ -337,51 +337,17 @@ public class EmailUtilsImpl implements EmailUtils {
} }
if (!logonly) if (!logonly)
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message); mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);
LOGGER.debug("Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message); logger.debug("Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message, e); logger.error("Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message, e);
throw new Exception(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) { public void setOverride(boolean override) {
this.override = 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

@ -22,16 +22,7 @@ public class MonitorServiceImpl implements MonitorService {
return this.validatorServiceLocator.getService(); return this.validatorServiceLocator.getService();
} }
public ServiceLocator<ValidatorService> getValidatorServiceLocator() { private static final Logger logger = Logger
return validatorServiceLocator;
}
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) {
this.validatorServiceLocator = validatorServiceLocator;
}
private static final Logger LOGGER = Logger
.getLogger(MonitorServiceImpl.class); .getLogger(MonitorServiceImpl.class);
@Override @Override
@ -42,10 +33,10 @@ public class MonitorServiceImpl implements MonitorService {
String dateFrom, String dateFrom,
String dateTo, String dateTo,
String validationStatus, String validationStatus,
String includeJobsTotal) throws JSONException, ValidatorServiceException { String includeJobsTotal) throws ValidatorServiceException {
LOGGER.debug("Getting jobs of user : " + user); logger.debug("Getting jobs of user : " + user);
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal); logger.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
JobsOfUser retJobs = new JobsOfUser(); JobsOfUser retJobs = new JobsOfUser();
retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset), retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
Integer.parseInt(limit), dateFrom, dateTo, validationStatus)); Integer.parseInt(limit), dateFrom, dateTo, validationStatus));
@ -56,7 +47,6 @@ public class MonitorServiceImpl implements MonitorService {
retJobs.setTotalJobsOngoing(this.getJobsTotalNumberOfUser(user, jobType,Constants.VALIDATION_JOB_STATUS_ONGOING)); retJobs.setTotalJobsOngoing(this.getJobsTotalNumberOfUser(user, jobType,Constants.VALIDATION_JOB_STATUS_ONGOING));
} }
//TODO fix status with new validator version
if(retJobs.getJobs() != null){ if(retJobs.getJobs() != null){
for(StoredJob job :retJobs.getJobs()){ for(StoredJob job :retJobs.getJobs()){
if (job.getContentJobStatus().equals("ongoing") || job.getUsageJobStatus().equals("ongoing")) { if (job.getContentJobStatus().equals("ongoing") || job.getUsageJobStatus().equals("ongoing")) {
@ -86,24 +76,24 @@ public class MonitorServiceImpl implements MonitorService {
@Override @Override
public int getJobsOfUserPerValidationStatus(String user, public int getJobsOfUserPerValidationStatus(String user,
String jobType, String jobType,
String validationStatus) throws JSONException { String validationStatus){
LOGGER.debug("Getting job with validation status : " + validationStatus); logger.debug("Getting job with validation status : " + validationStatus);
try { try {
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus); return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
} catch (ValidatorServiceException e) { } catch (ValidatorServiceException e) {
e.printStackTrace(); logger.error(e);
} }
return 0; return 0;
} }
@Override @Override
public StoredJob getJobSummary(String jobId, public StoredJob getJobSummary(String jobId,
String groupBy) throws JSONException { String groupBy){
LOGGER.debug("Getting job summary with id : " + jobId); logger.debug("Getting job summary with id : " + jobId);
try { try {
return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy); return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
} catch (ValidatorServiceException e) { } catch (ValidatorServiceException e) {
e.printStackTrace(); logger.error(e);
} }
return null; return null;
} }

View File

@ -15,28 +15,19 @@ import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Service("piwikService") @Service("piwikService")
public class PiWikServiceImpl implements PiWikService { public class PiWikServiceImpl implements PiWikService {
@ -57,7 +48,7 @@ public class PiWikServiceImpl implements PiWikService {
@Qualifier("emailUtils") @Qualifier("emailUtils")
private EmailUtils emailUtils; private EmailUtils emailUtils;
private static final Logger LOGGER = Logger private static final Logger logger = Logger
.getLogger(PiWikServiceImpl.class); .getLogger(PiWikServiceImpl.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 GET_PIWIK_SITE = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site where repositoryid = ?;";
@ -96,7 +87,7 @@ public class PiWikServiceImpl implements PiWikService {
@Override @Override
public List<PiwikInfo> getPiwikSitesForRepos(OrderByField orderByField, OrderByType orderByType, int from, int quantity, String searchField) { public List<PiwikInfo> getPiwikSitesForRepos(OrderByField orderByField, OrderByType orderByType, int from, int quantity, String searchField) {
LOGGER.debug("Getting piwik sites for repos! "); logger.debug("Getting piwik sites for repos! ");
try{ try{
String finalizedQuery = GET_PIWIK_SITES + " where ("+ String finalizedQuery = GET_PIWIK_SITES + " where ("+
" repositoryid ilike ? " + " repositoryid ilike ? " +
@ -159,11 +150,11 @@ public class PiWikServiceImpl implements PiWikService {
emailUtils.sendUserMetricsEnabled(piwikInfo); emailUtils.sendUserMetricsEnabled(piwikInfo);
} catch (EmptyResultDataAccessException e) { } catch (EmptyResultDataAccessException e) {
LOGGER.error("Error while approving piwik site: ", e); logger.error("Error while approving piwik site: ", e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR); throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending email to administrator or user about the enabling of metrics", e); logger.error("Error while sending email to administrator or user about the enabling of metrics", e);
emailUtils.reportException(e); emailUtils.reportException(e);
} }
return new ResponseEntity<>("OK",HttpStatus.OK); return new ResponseEntity<>("OK",HttpStatus.OK);
@ -194,15 +185,15 @@ public class PiWikServiceImpl implements PiWikService {
emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo); emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo);
emailUtils.sendUserRequestToEnableMetrics(piwikInfo); emailUtils.sendUserRequestToEnableMetrics(piwikInfo);
} catch (UnsupportedEncodingException uee) { } catch (UnsupportedEncodingException uee) {
LOGGER.error("Error while creating piwikScript URL", uee); logger.error("Error while creating piwikScript URL", uee);
emailUtils.reportException(uee); emailUtils.reportException(uee);
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR); throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
} catch (IOException ioe) { } catch (IOException ioe) {
LOGGER.error("Error while creating piwik site", ioe); logger.error("Error while creating piwik site", ioe);
emailUtils.reportException(ioe); emailUtils.reportException(ioe);
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR); throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while sending email to administrator or user about the request to enable metrics", e); logger.error("Error while sending email to administrator or user about the request to enable metrics", e);
emailUtils.reportException(e); emailUtils.reportException(e);
} }
return piwikInfo; return piwikInfo;

View File

@ -1,8 +1,6 @@
package eu.dnetlib.repo.manager.service; package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import eu.dnetlib.api.functionality.ValidatorServiceException; import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.data.Repository; import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface; import eu.dnetlib.domain.data.RepositoryInterface;
@ -14,7 +12,6 @@ import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.shared.*; import eu.dnetlib.repo.manager.shared.*;
import eu.dnetlib.repo.manager.utils.Converter; import eu.dnetlib.repo.manager.utils.Converter;
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader; import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
import gr.uoa.di.driver.xml.repository.INTERFACE;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.json.JSONArray; import org.json.JSONArray;
@ -59,7 +56,7 @@ public class RepositoryServiceImpl implements RepositoryService {
private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"}; private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"};
private static final Logger LOGGER = Logger.getLogger(RepositoryServiceImpl.class); private static final Logger logger = Logger.getLogger(RepositoryServiceImpl.class);
@Value("${services.repomanager.usageStatisticsDiagramsBaseURL}") @Value("${services.repomanager.usageStatisticsDiagramsBaseURL}")
private String usageStatisticsDiagramsBaseURL; private String usageStatisticsDiagramsBaseURL;
@ -85,46 +82,43 @@ public class RepositoryServiceImpl implements RepositoryService {
private Map<String, String> countriesMap = new HashMap<>(); private Map<String, String> countriesMap = new HashMap<>();
private Map<String, String> inverseCountriesMap = new HashMap<>(); private Map<String, String> inverseCountriesMap = new HashMap<>();
private static Map<String,List<String>> dataSourceClass = new HashMap<String,List<String>>(){{ private static Map<String,List<String>> dataSourceClass = new HashMap<>();
put("opendoar",new ArrayList<String>(){{ add("pubsrepository::institutional");
add("pubsrepository::thematic");
add("pubsrepository::unknown");
add("pubsrepository::mock");
}});
put("re3data",new ArrayList<String>(){{ add("datarepository::unknown");
}});
put("journal",new ArrayList<String>(){{ add("pubsrepository::journal");
}});
put("aggregator",new ArrayList<String>(){{ add("aggregator::pubsrepository::institutional");
add("aggregator::pubsrepository::journals");
add("aggregator::datarepository");
add("aggregator::pubsrepository::unknown");
}});
}};
private static Map<String,String> invertedDataSourceClass = new HashMap<String,String>(){{ private static Map<String,String> invertedDataSourceClass = new HashMap<>();
put("pubsrepository::institutional","opendoar");
put("pubsrepository::thematic","opendoar");
put("pubsrepository::unknown","opendoar");
put("pubsrepository::mock","opendoar");
put("datarepository::unknown","re3data");
put("pubsrepository::journal","journal");
put("aggregator::pubsrepository::institutional","aggregator");
put("aggregator::pubsrepository::journals","aggregator");
put("aggregator::datarepository","aggregator");
put("aggregator::pubsrepository::unknown","aggregator");
}};
@PostConstruct @PostConstruct
private void init() { private void init() {
LOGGER.debug("Initialization method of repository api!"); logger.debug("Initialization method of repository api!");
LOGGER.debug("Updated version!"); logger.debug("Updated version!");
invertedDataSourceClass.put("pubsrepository::institutional","opendoar");
invertedDataSourceClass.put("pubsrepository::thematic","opendoar");
invertedDataSourceClass.put("pubsrepository::unknown","opendoar");
invertedDataSourceClass.put("pubsrepository::mock","opendoar");
invertedDataSourceClass.put("datarepository::unknown","re3data");
invertedDataSourceClass.put("pubsrepository::journal","journal");
invertedDataSourceClass.put("aggregator::pubsrepository::institutional","aggregator");
invertedDataSourceClass.put("aggregator::pubsrepository::journals","aggregator");
invertedDataSourceClass.put("aggregator::datarepository","aggregator");
invertedDataSourceClass.put("aggregator::pubsrepository::unknown","aggregator");
dataSourceClass.put("opendoar",Arrays.asList("pubsrepository::institutional",
"pubsrepository::thematic",
"pubsrepository::unknown",
"pubsrepository::mock"));
dataSourceClass.put("re3data", Collections.singletonList("datarepository::unknown"));
dataSourceClass.put("journal", Collections.singletonList("pubsrepository::journal"));
dataSourceClass.put("aggregator",Arrays.asList("aggregator::pubsrepository::institutional",
"aggregator::pubsrepository::journals",
"aggregator::datarepository",
"aggregator::pubsrepository::unknown"));
httpHeaders = new HttpHeaders(); httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8); httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
@ -152,11 +146,11 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override @Override
public List<RepositorySnippet> getRepositoriesByCountry(@PathVariable("country") String country, public List<RepositorySnippet> getRepositoriesByCountry(String country,
@PathVariable("mode") String mode, String mode,
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException, IOException { Boolean managed) throws JSONException, IOException {
LOGGER.debug("Getting repositories by country!"); logger.debug("Getting repositories by country!");
int page = 0; int page = 0;
int size = 100; int size = 100;
List<RepositorySnippet> resultSet = new ArrayList<>(); List<RepositorySnippet> resultSet = new ArrayList<>();
@ -169,8 +163,8 @@ public class RepositoryServiceImpl implements RepositoryService {
filterKey = "openaire____::re3data"; filterKey = "openaire____::re3data";
LOGGER.debug("Country code equals : " + country); logger.debug("Country code equals : " + country);
LOGGER.debug("Filter mode equals : " + filterKey); logger.debug("Filter mode equals : " + filterKey);
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size)); UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size));
RequestFilter requestFilter = new RequestFilter(); RequestFilter requestFilter = new RequestFilter();
@ -190,7 +184,7 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
return resultSet; return resultSet;
}catch (Exception e){ }catch (Exception e){
LOGGER.debug("Exception on getRepositoriesByCountry" , e); logger.debug("Exception on getRepositoriesByCountry" , e);
// emailUtils.reportException(e); // emailUtils.reportException(e);
throw e; throw e;
} }
@ -199,7 +193,7 @@ public class RepositoryServiceImpl implements RepositoryService {
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName, public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception { String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
LOGGER.debug("Searching registered repositories"); logger.debug("Searching registered repositories");
List<RepositorySnippet> resultSet = new ArrayList<>(); List<RepositorySnippet> resultSet = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
@ -220,7 +214,7 @@ public class RepositoryServiceImpl implements RepositoryService {
return resultSet; return resultSet;
}catch (Exception e){ }catch (Exception e){
LOGGER.error("Error searching registered datasources" , e); logger.error("Error searching registered datasources" , e);
throw e; throw e;
} }
} }
@ -238,24 +232,12 @@ public class RepositoryServiceImpl implements RepositoryService {
return r; return r;
} }
private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
List<Repository> reps = new ArrayList<>();
for (Repository r : rs) {
if (r.getCollectedFrom() != null && r.getCollectedFrom().equals(mode))
reps.add(r);
}
return reps;
}
@Override @Override
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail, public List<Repository> getRepositoriesOfUser(String userEmail,
@PathVariable("page") String page, String page,
@PathVariable("size") String size) throws JSONException { String size) throws JSONException {
LOGGER.debug("Retreiving repositories of user : " + userEmail ); logger.debug("Retreiving repositories of user : " + userEmail );
UriComponents uriComponents = searchDatasource(page,size); UriComponents uriComponents = searchDatasource(page,size);
RequestFilter requestFilter = new RequestFilter(); RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail); requestFilter.setRegisteredby(userEmail);
@ -269,7 +251,7 @@ public class RepositoryServiceImpl implements RepositoryService {
return repos; return repos;
}catch (Exception e){ }catch (Exception e){
LOGGER.debug("Exception on getRepositoriesOfUser" , e); logger.debug("Exception on getRepositoriesOfUser" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
@ -278,7 +260,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override @Override
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException,ResourceNotFoundException { public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException,ResourceNotFoundException {
LOGGER.debug("Retreiving repositories with id : " + id ); logger.debug("Retreiving repositories with id : " + id );
Repository repo = null; Repository repo = null;
UriComponents uriComponents = searchDatasource("0","100"); UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter(); RequestFilter requestFilter = new RequestFilter();
@ -294,7 +276,7 @@ public class RepositoryServiceImpl implements RepositoryService {
repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0)); repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0));
return updateRepositoryInfo(repo); return updateRepositoryInfo(repo);
}catch (JSONException e){ }catch (JSONException e){
LOGGER.debug("Exception on getRepositoryById" , e); logger.debug("Exception on getRepositoryById" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
@ -303,9 +285,9 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override @Override
public List<AggregationDetails> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException { public List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException {
LOGGER.debug("Retreiving aggregations for repository with id : " + id ); logger.debug("Retreiving aggregations for repository with id : " + id );
UriComponents uriComponents = searchDatasource("0","100"); UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter(); RequestFilter requestFilter = new RequestFilter();
requestFilter.setId(id); requestFilter.setId(id);
@ -324,7 +306,7 @@ public class RepositoryServiceImpl implements RepositoryService {
.limit(20) .limit(20)
.collect(Collectors.toList()); .collect(Collectors.toList());
} catch (JSONException e) { } catch (JSONException e) {
LOGGER.debug("Exception on getRepositoryAggregations" , e); logger.debug("Exception on getRepositoryAggregations" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
@ -332,8 +314,8 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
@Override @Override
public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException { public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException {
LOGGER.debug("Retreiving aggregations (by year) for repository with id : " + id ); logger.debug("Retreiving aggregations (by year) for repository with id : " + id );
UriComponents uriComponents = searchDatasource("0","100"); UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter(); RequestFilter requestFilter = new RequestFilter();
requestFilter.setId(id); requestFilter.setId(id);
@ -351,14 +333,13 @@ public class RepositoryServiceImpl implements RepositoryService {
return aggregationHistory.size() == 0? aggregationByYear:createYearMap(aggregationHistory); return aggregationHistory.size() == 0? aggregationByYear:createYearMap(aggregationHistory);
} catch (JSONException e) { } catch (JSONException e) {
LOGGER.debug("Exception on getRepositoryAggregations" , e); logger.debug("Exception on getRepositoryAggregations" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
} }
private Map<String,List<AggregationDetails>> createYearMap(List<AggregationDetails> aggregationHistory) { private Map<String,List<AggregationDetails>> createYearMap(List<AggregationDetails> aggregationHistory) {
Map<String, List<AggregationDetails>> aggregationByYear;
aggregationHistory = aggregationHistory.stream() aggregationHistory = aggregationHistory.stream()
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed()) .sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -369,11 +350,11 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override @Override
public List<Repository> getRepositoriesByName(@PathVariable("name") String name, public List<Repository> getRepositoriesByName(String name,
@PathVariable("page") String page, String page,
@PathVariable("size") String size) throws JSONException { String size ) throws JSONException {
LOGGER.debug("Retreiving repositories with official name : " + name ); logger.debug("Retreiving repositories with official name : " + name );
UriComponents uriComponents = searchDatasource("0","100"); UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter(); RequestFilter requestFilter = new RequestFilter();
requestFilter.setOfficialname(name); requestFilter.setOfficialname(name);
@ -385,7 +366,7 @@ public class RepositoryServiceImpl implements RepositoryService {
updateRepositoryInfo(r); updateRepositoryInfo(r);
return repos; return repos;
}catch (Exception e){ }catch (Exception e){
LOGGER.debug("Exception on getRepositoriesByName" , e); logger.debug("Exception on getRepositoriesByName" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
@ -393,7 +374,7 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
@Override @Override
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException { public List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/") .fromHttpUrl(baseAddress + "/ds/api/")
@ -404,7 +385,7 @@ public class RepositoryServiceImpl implements RepositoryService {
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs)); return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs));
}catch (Exception e ){ }catch (Exception e ){
LOGGER.debug("Exception on getRepositoryInterface" , e); logger.debug("Exception on getRepositoryInterface" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
@ -412,10 +393,10 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
@Override @Override
public Repository addRepository(@RequestParam("datatype") String datatype, public Repository addRepository( String datatype,
@RequestBody Repository repository) throws Exception { Repository repository) throws Exception {
LOGGER.debug("storing " + datatype + " repository with id: " + repository.getId()); logger.debug("storing " + datatype + " repository with id: " + repository.getId());
repository.setCountryCode(countriesMap.get(repository.getCountryName())); repository.setCountryCode(countriesMap.get(repository.getCountryName()));
repository.setActivationId(UUID.randomUUID().toString()); repository.setActivationId(UUID.randomUUID().toString());
@ -445,12 +426,7 @@ public class RepositoryServiceImpl implements RepositoryService {
try { try {
String json_repository = Converter.repositoryObjectToJson(repository); String json_repository = Converter.repositoryObjectToJson(repository);
LOGGER.debug("JSON to add(update) -> " + json_repository); logger.debug("JSON to add(update) -> " + json_repository);
//
// // TODO delete these 3 lines
// HttpHeaders temp = new HttpHeaders();
// temp.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders); HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class); ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class);
@ -459,11 +435,11 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendUserRegistrationEmail(repository, authentication); emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication); emailUtils.sendAdminRegistrationEmail(repository, authentication);
} else } else
LOGGER.debug(responseEntity.getBody().toString()); logger.debug(responseEntity.getBody().toString());
return repository; return repository;
} catch (Exception e) { } catch (Exception e) {
LOGGER.debug("Exception on updateRepository" , e); logger.debug("Exception on updateRepository" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
@ -472,7 +448,7 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
@Override @Override
public Repository updateRepository(@RequestBody Repository repository,Authentication authentication) throws Exception { public Repository updateRepository(Repository repository,Authentication authentication) throws Exception {
UriComponents uriComponents = UriComponentsBuilder UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/update/") .fromHttpUrl(baseAddress + "/ds/update/")
.build() .build()
@ -481,7 +457,7 @@ public class RepositoryServiceImpl implements RepositoryService {
try { try {
String json_repository = Converter.repositoryObjectToJson(repository); String json_repository = Converter.repositoryObjectToJson(repository);
LOGGER.debug("JSON to update -> " + json_repository); logger.debug("JSON to update -> " + json_repository);
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders); HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity
@ -491,41 +467,15 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendUserUpdateRepositoryEmail(repository, authentication); emailUtils.sendUserUpdateRepositoryEmail(repository, authentication);
emailUtils.sendAdminUpdateRepositoryEmail(repository, authentication); emailUtils.sendAdminUpdateRepositoryEmail(repository, authentication);
} else } else
LOGGER.debug(responseEntity.getBody().toString()); logger.debug(responseEntity.getBody().toString());
return repository; return repository;
} catch (Exception e) { } catch (Exception e) {
LOGGER.debug("Exception on updateRepository" , e); logger.debug("Exception on updateRepository" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
} }
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 void storeRepository(Repository repository, Authentication authentication) throws Exception { private void storeRepository(Repository repository, Authentication authentication) throws Exception {
Date utilDate = new Date(); Date utilDate = new Date();
@ -546,26 +496,26 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendUserRegistrationEmail(repository, authentication); emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication); emailUtils.sendAdminRegistrationEmail(repository, authentication);
} else { } else {
LOGGER.debug(responseEntity.getBody().toString()); logger.debug(responseEntity.getBody().toString());
} }
} }
@Override @Override
public void deleteRepositoryInterface(@RequestParam("id") String id , public void deleteRepositoryInterface(String id ,
@RequestParam("registeredBy") String registeredBy){ String registeredBy){
UriComponents uriComponents = UriComponentsBuilder UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/") .fromHttpUrl(baseAddress + "/ds/api/")
.path("/{id}") .path("/{id}")
.build().expand(id).encode(); .build().expand(id).encode();
LOGGER.debug(uriComponents.toUri()); logger.debug(uriComponents.toUri());
restTemplate.delete(uriComponents.toUri()); restTemplate.delete(uriComponents.toUri());
} }
@Override @Override
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype, public RepositoryInterface addRepositoryInterface(String datatype,
@RequestParam("repoId") String repoId, String repoId,
@RequestParam("registeredBy") String registeredBy, String registeredBy,
@RequestBody RepositoryInterface repositoryInterface) throws JSONException,ResourceNotFoundException { RepositoryInterface repositoryInterface) throws JSONException,ResourceNotFoundException {
try { try {
Repository e = this.getRepositoryById(repoId); Repository e = this.getRepositoryById(repoId);
repositoryInterface = createRepositoryInterface(e,repositoryInterface,datatype); repositoryInterface = createRepositoryInterface(e,repositoryInterface,datatype);
@ -581,16 +531,16 @@ public class RepositoryServiceImpl implements RepositoryService {
return repositoryInterface; return repositoryInterface;
} catch (JSONException e) { } catch (JSONException e) {
LOGGER.debug("Exception on addRepositoryInterface" , e); logger.debug("Exception on addRepositoryInterface" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
} }
@Override @Override
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId, public RepositoryInterface updateRepositoryInterface(String repoId,
@RequestParam("registeredBy") String registeredBy, String registeredBy,
@RequestBody RepositoryInterface repositoryInterface) throws Exception { RepositoryInterface repositoryInterface) throws Exception {
this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl()); this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl());
this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance()); this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance());
@ -598,27 +548,6 @@ public class RepositoryServiceImpl implements RepositoryService {
return repositoryInterface; return repositoryInterface;
} }
private void submitInterfaceValidation(Repository repo, String repoType, String userEmail, RepositoryInterface iFace) throws ValidatorServiceException {
JobForValidation job = new JobForValidation();
job.setActivationId(UUID.randomUUID().toString());
job.setAdminEmails(Collections.singletonList(this.adminEmail));
job.setBaseUrl(iFace.getBaseUrl());
job.setDatasourceId(repo.getId());
job.setDesiredCompatibilityLevel(iFace.getDesiredCompatibilityLevel());
job.setInterfaceId(iFace.getId());
// job.setInterfaceIdOld(null);
job.setOfficialName(repo.getOfficialName());
job.setRepoType(repoType);
job.setUserEmail(userEmail);
job.setValidationSet(iFace.getAccessSet());
job.setRecords(-1);
job.setRegistration(true);
job.setUpdateExisting(false);
this.validatorService.submitJobForValidation(job);
}
private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) { private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) {
iFace.setContentDescription("metadata"); iFace.setContentDescription("metadata");
@ -646,7 +575,7 @@ public class RepositoryServiceImpl implements RepositoryService {
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']"); iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8)); iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
if (iFace.getAccessSet().isEmpty()) { if (iFace.getAccessSet().isEmpty()) {
LOGGER.debug("set is empty: " + iFace.getAccessSet()); logger.debug("set is empty: " + iFace.getAccessSet());
iFace.removeAccessSet(); iFace.removeAccessSet();
} }
return iFace; return iFace;
@ -654,7 +583,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override @Override
public List<String> getDnetCountries() { public List<String> getDnetCountries() {
LOGGER.debug("Getting dnet-countries!"); logger.debug("Getting dnet-countries!");
return Converter.readFile("countries.txt"); return Converter.readFile("countries.txt");
} }
@ -670,9 +599,9 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
@Override @Override
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail, public List<String> getUrlsOfUserRepos(String userEmail,
@PathVariable("page") String page, String page,
@PathVariable("size") String size) throws JSONException { String size) {
UriComponents uriComponents = UriComponentsBuilder UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/api/baseurl/") .fromHttpUrl(baseAddress + "/api/baseurl/")
.path("/{page}/{size}") .path("/{page}/{size}")
@ -683,14 +612,14 @@ public class RepositoryServiceImpl implements RepositoryService {
requestFilter.setRegisteredby(userEmail); requestFilter.setRegisteredby(userEmail);
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(),requestFilter, String[].class)); return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(),requestFilter, String[].class));
}catch (Exception e){ }catch (Exception e){
LOGGER.debug("Exception on addRepositoryInterface" , e); logger.debug("Exception on addRepositoryInterface" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
} }
@Override @Override
public List<String> getDatasourceVocabularies(@PathVariable("mode") String mode) { public List<String> getDatasourceVocabularies(String mode) {
List<String> resultSet = new ArrayList<>(); List<String> resultSet = new ArrayList<>();
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) { for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
@ -723,9 +652,9 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override @Override
public Map<String, String> getCompatibilityClasses(@PathVariable("mode") String mode) { public Map<String, String> getCompatibilityClasses(String mode) {
LOGGER.debug("Getting compatibility classes for mode: " + mode); logger.debug("Getting compatibility classes for mode: " + mode);
Map<String, String> retMap = new HashMap<String, String>(); Map<String, String> retMap = new HashMap<String, String>();
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap(); Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
@ -744,7 +673,6 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
} }
//TODO TO BE REMOVED WHEN VOCABULARIES ARE UPDATED
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA) && !foundData) if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA) && !foundData)
retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)"); retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)");
@ -752,9 +680,9 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
@Override @Override
public Map<String, String> getDatasourceClasses(@PathVariable("mode") String mode) { public Map<String, String> getDatasourceClasses(String mode) {
LOGGER.debug("Getting datasource classes for mode: " + mode); logger.debug("Getting datasource classes for mode: " + mode);
Map<String, String> retMap = new HashMap<String, String>(); Map<String, String> retMap = new HashMap<String, String>();
@ -793,7 +721,7 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
@Override @Override
public MetricsInfo getMetricsInfoForRepository(@PathVariable("repoId") String repoId) throws RepositoryServiceException { public MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException {
try { try {
MetricsInfo metricsInfo = new MetricsInfo(); MetricsInfo metricsInfo = new MetricsInfo();
@ -802,14 +730,14 @@ public class RepositoryServiceImpl implements RepositoryService {
return metricsInfo; return metricsInfo;
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while getting metrics info for repository: ", e); logger.error("Error while getting metrics info for repository: ", e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR); throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
} }
} }
@Override @Override
public Map<String, String> getListLatestUpdate(@PathVariable("mode") String mode) throws JSONException { public Map<String, String> getListLatestUpdate(String mode) throws JSONException {
if(mode.equals("opendoar")) if(mode.equals("opendoar"))
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(0).getLastCollectionDate()); return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(0).getLastCollectionDate());
else else
@ -851,7 +779,7 @@ public class RepositoryServiceImpl implements RepositoryService {
restTemplate.postForObject(uriComponents.toUri(),null,String.class); restTemplate.postForObject(uriComponents.toUri(),null,String.class);
} }
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException { private MetricsNumbers getMetricsNumbers(String openAIREID) {
//build the uri params //build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks"); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks");
@ -869,7 +797,7 @@ public class RepositoryServiceImpl implements RepositoryService {
new ParameterizedTypeReference<MetricsNumbers>() { new ParameterizedTypeReference<MetricsNumbers>() {
}); });
} catch (RestClientException e) { } catch (RestClientException e) {
LOGGER.debug("Exception on getMetricsNumbers" , e); logger.debug("Exception on getMetricsNumbers" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }

View File

@ -1,9 +1,5 @@
package eu.dnetlib.repo.manager.service; package eu.dnetlib.repo.manager.service;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import eu.dnetlib.repo.manager.exception.EndPointException;
import org.json.JSONException;
import java.util.Map; import java.util.Map;

View File

@ -29,23 +29,23 @@ public class SushiliteServiceImpl implements SushiliteService {
@Autowired @Autowired
private EmailUtils emailUtils; private EmailUtils emailUtils;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(SushiliteServiceImpl.class); private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(SushiliteServiceImpl.class);
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")
public ReportResponseWrapper getReportResults(@PathVariable("page") String page, public ReportResponseWrapper getReportResults(String page,
@PathVariable("pageSize") String pageSize, String pageSize,
@RequestParam(value = "Report") String Report, String Report,
@RequestParam(value = "Release",defaultValue="4") String Release, String Release,
@RequestParam(value = "RequestorID",required=false,defaultValue="anonymous") String RequestorID, String RequestorID,
@RequestParam(value = "BeginDate",required=false,defaultValue="") String BeginDate, String BeginDate,
@RequestParam(value = "EndDate",required=false,defaultValue="") String EndDate, String EndDate,
@RequestParam(value = "RepositoryIdentifier") String RepositoryIdentifier, String RepositoryIdentifier,
@RequestParam(value = "ItemIdentifier",required=false,defaultValue="") String ItemIdentifier, String ItemIdentifier,
@RequestParam(value = "ItemDataType",required=false,defaultValue="") String ItemDataType, String ItemDataType,
@RequestParam(value = "Granularity") String Granularity, String Granularity,
@RequestParam(value = "Pretty",required=false,defaultValue="") String Pretty) { String Pretty) {
//build the uri params //build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usagestatsSushiliteEndpoint + "GetReport/") UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usagestatsSushiliteEndpoint + "GetReport/")
@ -74,7 +74,7 @@ public class SushiliteServiceImpl implements SushiliteService {
new ParameterizedTypeReference<ReportResponseWrapper>() { new ParameterizedTypeReference<ReportResponseWrapper>() {
}); });
} catch (RestClientException e) { } catch (RestClientException e) {
LOGGER.debug("Exception on getReportResults" , e); logger.debug("Exception on getReportResults" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} }
@ -99,7 +99,7 @@ public class SushiliteServiceImpl implements SushiliteService {
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
LOGGER.debug("Exception on getReportResults - trying to cast strings to integers", e); logger.debug("Exception on getReportResults - trying to cast strings to integers", e);
//emailUtils.reportException(e); //emailUtils.reportException(e);
throw e; throw e;
} }

View File

@ -16,7 +16,7 @@ import java.util.stream.Collectors;
@Service("userService") @Service("userService")
public class UserServiceImpl implements UserService { public class UserServiceImpl implements UserService {
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger
.getLogger(UserServiceImpl.class); .getLogger(UserServiceImpl.class);
@Value("${oidc.issuer}") @Value("${oidc.issuer}")
@ -25,7 +25,7 @@ public class UserServiceImpl implements UserService {
@Override @Override
public ResponseEntity<Object> login() { public ResponseEntity<Object> login() {
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LOGGER.debug("User authentication : " + authentication); logger.debug("User authentication : " + authentication);
Map<String,Object> body = new HashMap<>(); Map<String,Object> body = new HashMap<>();
body.put("sub",authentication.getSub()); body.put("sub",authentication.getSub());
if(authentication.getUserInfo().getName() == null || authentication.getUserInfo().getName().equals("")) if(authentication.getUserInfo().getName() == null || authentication.getUserInfo().getName().equals(""))

View File

@ -51,7 +51,7 @@ public class ValidatorServiceImpl implements ValidatorService {
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>(); private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
private static final Logger LOGGER = Logger private static final Logger logger = Logger
.getLogger(ValidatorServiceImpl.class); .getLogger(ValidatorServiceImpl.class);
@Autowired @Autowired
@ -59,7 +59,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@PostConstruct @PostConstruct
private void loadRules(){ private void loadRules(){
LOGGER.debug("PostConstruct method! Load rules!"); logger.debug("PostConstruct method! Load rules!");
try { try {
for (RuleSet ruleSet : getValidationService().getRuleSets()) { for (RuleSet ruleSet : getValidationService().getRuleSets()) {
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) { if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) {
@ -81,33 +81,33 @@ public class ValidatorServiceImpl implements ValidatorService {
} }
} }
} catch (ValidatorServiceException e) { } catch (ValidatorServiceException e) {
e.printStackTrace(); logger.error("Exception on loadRules" , e);
} }
} }
@Override @Override
@PreAuthorize("hasRole('ROLE_USER') and #jobForValidation.userEmail == authentication.userInfo.email") @PreAuthorize("hasRole('ROLE_USER') and #jobForValidation.userEmail == authentication.userInfo.email")
public JobForValidation submitJobForValidation(@RequestBody JobForValidation jobForValidation) throws ValidatorServiceException { public JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException {
LOGGER.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId()); logger.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId());
try { try {
emailUtils.sendSubmitJobForValidationEmail(SecurityContextHolder.getContext().getAuthentication(),jobForValidation); emailUtils.sendSubmitJobForValidationEmail(SecurityContextHolder.getContext().getAuthentication(),jobForValidation);
this.getValidationService().submitValidationJob(jobForValidation); this.getValidationService().submitValidationJob(jobForValidation);
} catch (ValidatorServiceException e) { } catch (ValidatorServiceException e) {
LOGGER.debug("Exception on submitJobForValidation" , e); logger.debug("Exception on submitJobForValidation" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error("Exception on submitJobForValidation", e);
} }
return jobForValidation; return jobForValidation;
} }
@Override @Override
@PreAuthorize("hasRole('ROLE_USER') and #email == authentication.userInfo.email") @PreAuthorize("hasRole('ROLE_USER') and #email == authentication.userInfo.email")
public ResponseEntity<Object> reSubmitJobForValidation(@PathVariable("email") String email, public ResponseEntity<Object> reSubmitJobForValidation(String email,
@PathVariable("jobId") String jobId) throws JSONException, ValidatorServiceException { String jobId) throws ValidatorServiceException {
LOGGER.debug("Resubmit validation job with id : " + jobId); logger.debug("Resubmit validation job with id : " + jobId);
StoredJob job = monitorApi.getJobSummary(jobId,"all"); StoredJob job = monitorApi.getJobSummary(jobId,"all");
Set<Integer> contentRules = new HashSet<Integer>(); Set<Integer> contentRules = new HashSet<Integer>();
Set<Integer> usageRules = new HashSet<Integer>(); Set<Integer> usageRules = new HashSet<Integer>();
@ -120,13 +120,14 @@ public class ValidatorServiceImpl implements ValidatorService {
break; break;
} }
} }
if( ruleSet != null) {
for (int ruleId : job.getRules()) { for (int ruleId : job.getRules()) {
if (ruleSet.getContentRulesIds().contains(ruleId)) if (ruleSet.getContentRulesIds().contains(ruleId))
contentRules.add(ruleId); contentRules.add(ruleId);
else if (ruleSet.getUsageRulesIds().contains(ruleId)) else if (ruleSet.getUsageRulesIds().contains(ruleId))
usageRules.add(ruleId); usageRules.add(ruleId);
} }
}
if (!contentRules.isEmpty()) if (!contentRules.isEmpty())
job.setSelectedContentRules(contentRules); job.setSelectedContentRules(contentRules);
if (!usageRules.isEmpty()) if (!usageRules.isEmpty())
@ -136,38 +137,38 @@ public class ValidatorServiceImpl implements ValidatorService {
} }
@Override @Override
public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) { public List<RuleSet> getRuleSets(String mode) {
LOGGER.info("Getting rulesets for mode: " + mode); logger.info("Getting rulesets for mode: " + mode);
return rulesetMap.get(mode); return rulesetMap.get(mode);
} }
@Override @Override
public List<String> getSetsOfRepository(@RequestParam(value = "url", required = true) String url) { public List<String> getSetsOfRepository(String url) {
LOGGER.debug("Getting sets of repository with url : " + url); logger.debug("Getting sets of repository with url : " + url);
try { try {
return OaiTools.getSetsOfRepo(url); return OaiTools.getSetsOfRepo(url);
} catch (Exception e) { } catch (Exception e) {
LOGGER.debug("Exception on getSetsOfRepository" , e); logger.debug("Exception on getSetsOfRepository" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
} }
return null; return null;
} }
@Override @Override
public boolean identifyRepo(@RequestParam(value = "url", required = true) String url) { public boolean identifyRepo(String url) {
LOGGER.debug("Identify repository with url : " + url); logger.debug("Identify repository with url : " + url);
try { try {
return OaiTools.identifyRepository(url); return OaiTools.identifyRepository(url);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while identifying repository with url: " + url, e); logger.error("Error while identifying repository with url: " + url, e);
emailUtils.reportException(e); emailUtils.reportException(e);
return false; return false;
} }
} }
@Override @Override
public RuleSet getRuleSet(@PathVariable("acronym") String acronym) { public RuleSet getRuleSet( String acronym) {
LOGGER.debug("Getting ruleset with acronym : " + acronym); logger.debug("Getting ruleset with acronym : " + acronym);
RuleSet ruleSet = null; RuleSet ruleSet = null;
try { try {
for (List<RuleSet> ruleSets : this.rulesetMap.values()) { for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
@ -179,7 +180,7 @@ public class ValidatorServiceImpl implements ValidatorService {
} }
return ruleSet; return ruleSet;
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error getting ruleset", e); logger.error("Error getting ruleset", e);
emailUtils.reportException(e); emailUtils.reportException(e);
return null; return null;
} }
@ -187,14 +188,13 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override @Override
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")
public List<StoredJob> getStoredJobsNew(@RequestParam("user") @ApiParam(value = "User email", required = true) String user, public List<StoredJob> getStoredJobsNew(String user,
@RequestParam(value = "jobType", required = false) String jobType,
@ApiParam(value = "Equals to filter job type on validation history page") String jobType, String offset,
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset, String limit,
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit, String dateFrom,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom, String dateTo,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo, String validationStatus
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus
) throws ValidatorServiceException { ) throws ValidatorServiceException {
return getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset), Integer.parseInt(limit), dateFrom, dateTo, validationStatus); return getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset), Integer.parseInt(limit), dateFrom, dateTo, validationStatus);
} }
@ -205,9 +205,9 @@ public class ValidatorServiceImpl implements ValidatorService {
} }
@Override @Override
public InterfaceInformation getInterfaceInformation(@RequestParam(value = "baseUrl", required = true) String baseUrl) throws ValidationServiceException { public InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException {
try { try {
LOGGER.debug("Getting interface information with url: " + baseUrl); logger.debug("Getting interface information with url: " + baseUrl);
InterfaceInformation interfaceInformation = new InterfaceInformation(); InterfaceInformation interfaceInformation = new InterfaceInformation();
interfaceInformation.setIdentified(this.identifyRepo(baseUrl)); interfaceInformation.setIdentified(this.identifyRepo(baseUrl));
if (interfaceInformation.isIdentified()) if (interfaceInformation.isIdentified())
@ -215,7 +215,7 @@ public class ValidatorServiceImpl implements ValidatorService {
return interfaceInformation; return interfaceInformation;
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error getting interface information with url: " + baseUrl, e); logger.error("Error getting interface information with url: " + baseUrl, e);
emailUtils.reportException(e); emailUtils.reportException(e);
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR); throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
} }

View File

@ -29,9 +29,6 @@ public class UsageStatsTotalHystrixCommand extends HystrixCommand<Integer> {
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class); ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
Map metadata = (Map) ((Map)rs.getBody()).get("totals"); Map metadata = (Map) ((Map)rs.getBody()).get("totals");
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
// JSONObject resultSet = new JSONObject(rs);
// JSONObject totals = resultSet.getJSONObject("totals");
return (Integer) metadata.get("events"); return (Integer) metadata.get("events");
} }

View File

@ -7,10 +7,10 @@ import com.google.gwt.user.client.rpc.IsSerializable;
*/ */
public class Term implements IsSerializable { public class Term implements IsSerializable {
public String englishName; private String englishName;
public String nativeName; private String nativeName;
public String encoding; private String encoding;
public String code; private String code;
public Term(String englishName, String nativeName, String encoding, String code) { public Term(String englishName, String nativeName, String encoding, String code) {
this.englishName = englishName; this.englishName = englishName;
@ -19,35 +19,4 @@ public class Term implements IsSerializable {
this.code = code; this.code = code;
} }
public String getEnglishName() {
return englishName;
}
public void setEnglishName(String englishName) {
this.englishName = englishName;
}
public String getNativeName() {
return nativeName;
}
public void setNativeName(String nativeName) {
this.nativeName = nativeName;
}
public String getEncoding() {
return encoding;
}
public void setEncoding(String encoding) {
this.encoding = encoding;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
} }

View File

@ -3,8 +3,9 @@ package eu.dnetlib.repo.manager.shared;
import com.google.gwt.user.client.rpc.IsSerializable; import com.google.gwt.user.client.rpc.IsSerializable;
public class Timezone implements IsSerializable { public class Timezone implements IsSerializable {
public String name;
public double offset; private String name;
private double offset;
public Timezone(){ public Timezone(){
} }

View File

@ -7,8 +7,8 @@ import com.google.gwt.user.client.rpc.IsSerializable;
*/ */
public class BrowseEntry implements Comparable<BrowseEntry>, IsSerializable{ public class BrowseEntry implements Comparable<BrowseEntry>, IsSerializable{
public String value; private String value;
public Long size; private Long size;
public BrowseEntry() { public BrowseEntry() {
} }

View File

@ -24,7 +24,7 @@ import java.util.*;
public class Converter { public class Converter {
private static final Logger LOGGER = Logger.getLogger(Converter.class); private static final Logger logger = Logger.getLogger(Converter.class);
public static Repository jsonToRepositoryObject(JSONObject repositoryObject) throws JSONException { public static Repository jsonToRepositoryObject(JSONObject repositoryObject) throws JSONException {
@ -32,9 +32,6 @@ public class Converter {
JSONObject datasource = repositoryObject.getJSONObject("datasource"); JSONObject datasource = repositoryObject.getJSONObject("datasource");
//if( datasource.equals(null))
// return null;
repository.setId(datasource.get("id").toString()); repository.setId(datasource.get("id").toString());
repository.setOfficialName(datasource.get("officialname").toString()); repository.setOfficialName(datasource.get("officialname").toString());
@ -107,7 +104,7 @@ public class Converter {
return repository; return repository;
} }
public static Date convertStringToDate(String date){ private static Date convertStringToDate(String date){
if(Objects.equals(date, "null")) if(Objects.equals(date, "null"))
return null; return null;
@ -116,12 +113,12 @@ public class Converter {
try { try {
return formatter.parse(date); return formatter.parse(date);
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); logger.error("Error converting string to date",e);
} }
return null; return null;
} }
public static String convertDateToString(Date date){ private static String convertDateToString(Date date){
if(Objects.equals(date, null)) if(Objects.equals(date, null))
return null; return null;
@ -130,47 +127,13 @@ public class Converter {
return formatter.format(date); return formatter.format(date);
} }
public static Double toDouble(String number){ private static Double toDouble(String number){
if(Objects.equals(number, "null")) if(Objects.equals(number, "null"))
return 0.0; return 0.0;
else else
return Double.valueOf(number); return Double.valueOf(number);
} }
public static List<RepositorySnippet> jsonToRepositorySnippetList(JSONObject json) throws JSONException {
List<RepositorySnippet> resultSet = new ArrayList<>();
JSONArray rs = json.getJSONArray("datasourceInfo");
for(int i=0;i<rs.length();i++)
resultSet.add(jsonToRepositorySnippetObject( rs.getJSONObject(i)) );
return resultSet;
}
private static RepositorySnippet jsonToRepositorySnippetObject(JSONObject repositorySnippetObject) throws JSONException {
RepositorySnippet repositorySnippet = new RepositorySnippet();
// JSONObject datasource = repositorySnippetObject.getJSONObject("datasource");
repositorySnippet.setId(repositorySnippetObject.get("id").toString());
repositorySnippet.setOfficialname(repositorySnippetObject.get("officialname").toString());
repositorySnippet.setEnglishname( repositorySnippetObject.get("englishname").toString());
if(repositorySnippet.getEnglishname().equals("null"))
repositorySnippet.setEnglishname("");
repositorySnippet.setWebsiteurl(repositorySnippetObject.get("websiteurl").toString());
if(repositorySnippet.getWebsiteurl().equals("null"))
repositorySnippet.setWebsiteurl("");
repositorySnippet.setRegisteredby(repositorySnippetObject.get("registeredby").toString());
if(repositorySnippet.getRegisteredby().equals("null"))
repositorySnippet.setRegisteredby("");
return repositorySnippet;
}
public static List<Repository> jsonToRepositoryList(JSONObject json) throws JSONException { public static List<Repository> jsonToRepositoryList(JSONObject json) throws JSONException {
@ -205,15 +168,10 @@ public class Converter {
repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString())); repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString()));
// repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString());
repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString()); repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString());
//repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString()));
Map<String, String> accessParams = new HashMap<>(); Map<String, String> accessParams = new HashMap<>();
Map<String, String> extraFields = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiParams"); JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiParams");
for(int i=0;i<apiparams.length();i++) for(int i=0;i<apiparams.length();i++)
@ -224,7 +182,7 @@ public class Converter {
return repositoryInterface; return repositoryInterface;
} }
public static String repositoryObjectToJson(Repository repository) throws JSONException, JsonProcessingException { public static String repositoryObjectToJson(Repository repository) throws JsonProcessingException {
HashMap<String,Object> repositoryMap = new HashMap<>(); HashMap<String,Object> repositoryMap = new HashMap<>();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
@ -279,34 +237,12 @@ public class Converter {
organizations.add(organization); organizations.add(organization);
repositoryMap.put("organizations",organizations); repositoryMap.put("organizations",organizations);
//TODO check identitites
//Map<String,String> identity = new HashMap<>();
Map<String, Object> identities = new HashMap<>(); Map<String, Object> identities = new HashMap<>();
identities.put("issuertype", "piwik"); identities.put("issuertype", "piwik");
identities.put("pid","piwik:"+repository.getPiwikInfo().getSiteId()); identities.put("pid","piwik:"+repository.getPiwikInfo().getSiteId());
repositoryMap.put("identities",identities); repositoryMap.put("identities",identities);
repositoryMap.put("subjects",""); repositoryMap.put("subjects","");
//TODO check fields
/* jsonObject.put("certificates",repository.getCertificates());
jsonObject.put("citationguidelineurl",repository.getCitationGuidelineUrl());
jsonObject.put("databaseaccessrestriction",repository.getDatabaseAccessRestriction());
jsonObject.put("databaseaccesstype",repository.getDatabaseAccessType());
jsonObject.put("datauploadrestriction",repository.getDataUploadRestriction());
jsonObject.put("datauploadtype",repository.getDataUploadType());
jsonObject.put("missionstatementurl",repository.getMissionStatementUrl());
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("releaseenddate",convertDateToString(repository.getReleaseEndDate()));
jsonObject.put("releasestartdate",convertDateToString(repository.getReleaseStartDate()));
jsonObject.put("serviceprovider",repository.getServiceProvider());
jsonObject.put("versioning",repository.getVersioning());
//datasource.get("platform");
//datasource.get("subjects");*/
return mapper.writeValueAsString(repositoryMap); return mapper.writeValueAsString(repositoryMap);
} }
@ -344,9 +280,6 @@ public class Converter {
jsonObject.put("apiParams",apiparams); jsonObject.put("apiParams",apiparams);
// jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath());
return jsonObject.toString(); return jsonObject.toString();
} }
@ -354,7 +287,6 @@ public class Converter {
String line; String line;
ArrayList<String> list = new ArrayList<String>(); ArrayList<String> list = new ArrayList<String>();
try { try {
//InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename); InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename);
BufferedReader br = new BufferedReader(new InputStreamReader(in)); BufferedReader br = new BufferedReader(new InputStreamReader(in));
while((line = br.readLine()) != null) { while((line = br.readLine()) != null) {
@ -362,8 +294,7 @@ public class Converter {
} }
br.close(); br.close();
} catch (IOException e) { } catch (IOException e) {
LOGGER.debug("Error opening file!"); logger.debug("Error opening file!",e);
e.printStackTrace();
} }
return list; return list;
} }
@ -396,21 +327,6 @@ public class Converter {
return aggregationDetails; return aggregationDetails;
} }
public static AggregationDetails getLastCollectionFromJson(JSONObject datasourceInfo) throws JSONException {
if( datasourceInfo.get("lastCollection").equals(null))
return null;
return jsonToAggregationDetails(datasourceInfo.getJSONObject("lastCollection"));
}
public static AggregationDetails getLastTransformationFromJson(JSONObject datasourceInfo) throws JSONException {
if( datasourceInfo.get("lastTransformation").equals(null))
return null;
return jsonToAggregationDetails(datasourceInfo.getJSONObject("lastTransformation"));
}
public static List<Timezone> toTimezones(List<String> timezones) { public static List<Timezone> toTimezones(List<String> timezones) {
@ -422,7 +338,7 @@ public class Converter {
return tmz; return tmz;
} }
public static String getOpenaireId(String repositoryId) { private static String getOpenaireId(String repositoryId) {
if (repositoryId != null && repositoryId.contains("::")) if (repositoryId != null && repositoryId.contains("::"))
return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]); return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]);
return null; return null;

View File

@ -22,11 +22,11 @@ public class OaiTools {
disableSslVerification(); disableSslVerification();
} }
private static Logger LOGGER = Logger.getLogger(OaiTools.class); private static Logger logger = Logger.getLogger(OaiTools.class);
public static List<String> getSetsOfRepo(String baseUrl) throws Exception { public static List<String> getSetsOfRepo(String baseUrl) throws Exception {
try { try {
LOGGER.debug("Getting sets of repository " + baseUrl); logger.debug("Getting sets of repository " + baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl); OaiPmhServer harvester = new OaiPmhServer(baseUrl);
SetsList setList = harvester.listSets(); SetsList setList = harvester.listSets();
ResumptionToken token = setList.getResumptionToken(); ResumptionToken token = setList.getResumptionToken();
@ -47,14 +47,13 @@ public class OaiTools {
return ret; return ret;
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error getting sets of repository " + baseUrl, e); logger.error("Error getting sets of repository " + baseUrl, e);
return new ArrayList<String>(); return new ArrayList<>();
//throw e;
} }
} }
public static boolean identifyRepository(String baseUrl) throws Exception { public static boolean identifyRepository(String baseUrl) throws Exception {
LOGGER.debug("sending identify request to repo " + baseUrl); logger.debug("sending identify request to repo " + baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl); OaiPmhServer harvester = new OaiPmhServer(baseUrl);
@ -69,7 +68,7 @@ public class OaiTools {
return verifyIdentify(d); return verifyIdentify(d);
} catch (Exception e) { } catch (Exception e) {
LOGGER.debug("Error verifying identify response", e); logger.debug("Error verifying identify response", e);
throw e; throw e;
} }
} }
@ -110,21 +109,23 @@ public class OaiTools {
private static void disableSslVerification() { private static void disableSslVerification() {
try try
{ {
LOGGER.debug("disabling ssl verification"); logger.debug("disabling ssl verification");
// Create a trust manager that does not validate certificate chains // Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() { public X509Certificate[] getAcceptedIssuers() {
return null; return null;
} }
public void checkClientTrusted(X509Certificate[] certs, String authType) { public void checkClientTrusted(X509Certificate[] certs, String authType) {
} }
public void checkServerTrusted(X509Certificate[] certs, String authType) { public void checkServerTrusted(X509Certificate[] certs, String authType) {
} }
} }
}; };
// Install the all-trusting trust manager // Install the all-trusting trust manager
SSLContext sc = SSLContext.getInstance("SSL"); SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom()); sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
@ -138,9 +139,9 @@ public class OaiTools {
// Install the all-trusting host verifier // Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
LOGGER.error("disabling ssl verification", e); logger.error("disabling ssl verification", e);
} catch (KeyManagementException e) { } catch (KeyManagementException e) {
LOGGER.error("error while disabling ssl verification", e); logger.error("error while disabling ssl verification", e);
} }
} }
} }

View File

@ -1,72 +0,0 @@
/*
package unitest;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener;
import org.apache.commons.lang.StringEscapeUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = RepoManagerContextLoaderListener.class)
public class PiwikTest {
String analyticsURL = "https://analytics.openaire.eu/addsite.php?";
@Test
public void enableMetricsRepo1(){
String officialName = "BỘ SƯU TẬP SỐ";
String repoWebsite = "http://www.vnulib.edu.vn:8000/dspace/";
enableMetrics(officialName, repoWebsite, analyticsURL);
}
@Test
public void enableMetricsRepo2(){
String officialName = "ILC4CLARIN repository of language resources and tools";
String repoWebsite = "https://dspace-clarin-it.ilc.cnr.it/repository/xmlui";
enableMetrics(officialName, repoWebsite, analyticsURL);
}
@Test
public void enableMetricsRepo3(){
String officialName = "ANSTO Publications Online";
String repoWebsite = "http://apo.ansto.gov.au/dspace/";
enableMetrics(officialName, repoWebsite, analyticsURL);
}
private void enableMetrics(String officialName, String repoWebsite, String analyticsURL) {
String url;
try {
url = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url="
+ URLEncoder.encode(repoWebsite, "UTF-8");
url = StringEscapeUtils.escapeJava(url);
Map map = null;
String siteId = null;
URL u = new URL(url);
map = new ObjectMapper().readValue(u, Map.class);
if(map.get("value")!=null) {
siteId = map.get("value").toString();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}*/

View File

@ -1,31 +0,0 @@
//package unitest;
//
//import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener;
//import eu.dnetlib.repo.manager.utils.OaiTools;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.test.context.ContextConfiguration;
//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//
//@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration(classes = RepoManagerContextLoaderListener.class)
////@WebAppConfiguration
//public class ValidatorTest {
//
//
// @Test
// public void identiFy(){
//
// String url = "https://repozitorij.srce.unizg.hr/oai";
//
//
// System.out.println("Identify repository with url : " + url);
// try {
// System.out.println(OaiTools.identifyRepository(url));
// } catch (Exception e) {
// System.out.println(e);
// }
// }
//
//
//}