Updated dependencies and fixed compatibility for java 17

This commit is contained in:
Konstantinos Spyrou 2024-08-29 11:11:20 +03:00
parent e4009b7903
commit de76e89349
8 changed files with 276 additions and 163 deletions

26
pom.xml
View File

@ -115,12 +115,8 @@
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-clients</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0)</version>
<version>[2.0.0-SNAPSHOT,)</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
@ -135,23 +131,11 @@
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-runtime</artifactId>
<version>1.0.2-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-hcm</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0)</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
@ -320,13 +304,7 @@
<dependency>
<groupId>org.eurocris</groupId>
<artifactId>openaire-cris-validator</artifactId>
<version>1.0.1-SNAPSHOT</version>
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.apache.logging.log4j</groupId>-->
<!-- <artifactId>log4j-1.2-api</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<version>2.0.2-SNAPSHOT</version>
</dependency>
</dependencies>

View File

@ -1,108 +1,104 @@
//package eu.dnetlib.repo.manager.controllers;
//
//import eu.dnetlib.repo.manager.domain.dto.Role;
//import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
//import eu.dnetlib.repo.manager.service.security.AuthoritiesUpdater;
//import eu.dnetlib.repo.manager.service.security.AuthorizationService;
//import eu.dnetlib.repo.manager.service.security.RoleMappingService;
//import eu.dnetlib.repo.manager.utils.JsonUtils;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.web.bind.annotation.*;
//
//import javax.ws.rs.core.MediaType;
//import javax.ws.rs.core.Response;
//import java.util.Collection;
//
////@RestController
////@RequestMapping(value = "/role-management")
////@Api(description = "Role Management", value = "role-management")
//public class UserRoleController {
//
// private final AaiRegistryService aaiRegistryService;
// private final AuthoritiesUpdater authoritiesUpdater;
// private final RoleMappingService roleMappingService;
// private final AuthorizationService authorizationService;
//
// @Autowired
// UserRoleController(AaiRegistryService aaiRegistryService,
// AuthoritiesUpdater authoritiesUpdater,
// RoleMappingService roleMappingService,
// AuthorizationService authorizationService) {
// this.aaiRegistryService = aaiRegistryService;
// this.authoritiesUpdater = authoritiesUpdater;
// this.roleMappingService = roleMappingService;
// this.authorizationService = authorizationService;
// }
//
// /**
// * Get the role with the given id.
// **/
// @RequestMapping(method = RequestMethod.GET, path = "/role/{id}")
//// @PreAuthorize("hasAnyAuthority('REGISTERED_USER', 'SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
// public Response getRole(@RequestParam(value = "type", defaultValue = "datasource") String type, @PathVariable("id") String id) {
// int roleId = aaiRegistryService.getCouId(type, id);
// return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role id is: " + roleId).toString()).type(MediaType.APPLICATION_JSON).build();
// }
//
// /**
// * Create a new role with the given name and description.
// **/
// @RequestMapping(method = RequestMethod.POST, path = "/role")
// @PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR')")
// public Response createRole(@RequestBody Role role) {
// aaiRegistryService.createRole(role);
// return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
// }
//
// /**
// * Subscribe to a type(Community, etc.) with id(ee, egi, etc.)
// */
// @ApiOperation(value = "subscribe")
// @RequestMapping(method = RequestMethod.POST, path = "/subscribe/{type}/{id}")
// @PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
// public Response subscribe(@PathVariable("type") String type, @PathVariable("id") String id) {
// Integer coPersonId = aaiRegistryService.getCoPersonIdByIdentifier();
// if (coPersonId == null) {
// coPersonId = aaiRegistryService.getCoPersonIdsByEmail();
// }
// Integer couId = aaiRegistryService.getCouId(type, id);
// if (couId != null) {
// aaiRegistryService.assignMemberRole(coPersonId, couId);
//
// // Add role to current authorities
// authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(id));
//
// return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role has been assigned").toString()).type(MediaType.APPLICATION_JSON).build();
// } else {
// return Response.status(HttpStatus.NOT_FOUND.value()).entity(JsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
// }
// }
// /////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////
//
// @RequestMapping(method = RequestMethod.GET, path = "/users/couid/{id}")
// @PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
// public ResponseEntity<String> getUsersByCouId(@PathVariable("id") Integer id) {
//// calls.getUserByCoId()
// return ResponseEntity.ok(aaiRegistryService.getUsersByCouId(id).toString());
// }
//
//
// @RequestMapping(method = RequestMethod.GET, path = "/users/{email}/roles")
// @PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or hasAuthority('REGISTERED_USER') and authentication.userInfo.email==#email")
// public ResponseEntity<Collection<String>> getRolesByEmail(@PathVariable("email") String email) {
// return ResponseEntity.ok(authorizationService.getUserRolesByEmail(email));
// }
//
//
// @RequestMapping(method = RequestMethod.GET, path = "/user/roles/my")
// @PreAuthorize("hasAuthority('REGISTERED_USER')")
// public ResponseEntity<Collection<String>> getRoleNames() {
// return ResponseEntity.ok(authorizationService.getUserRoles());
// }
//
//}
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.domain.dto.Role;
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
import eu.dnetlib.repo.manager.service.security.AuthoritiesUpdater;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import eu.dnetlib.repo.manager.service.security.RoleMappingService;
import eu.dnetlib.repo.manager.utils.JsonUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Collection;
//@RestController
//@RequestMapping(value = "/role-management")
//@Api(description = "Role Management", value = "role-management")
public class UserRoleController {
private final AaiRegistryService aaiRegistryService;
private final AuthoritiesUpdater authoritiesUpdater;
private final RoleMappingService roleMappingService;
private final AuthorizationService authorizationService;
UserRoleController(AaiRegistryService aaiRegistryService,
AuthoritiesUpdater authoritiesUpdater,
RoleMappingService roleMappingService,
AuthorizationService authorizationService) {
this.aaiRegistryService = aaiRegistryService;
this.authoritiesUpdater = authoritiesUpdater;
this.roleMappingService = roleMappingService;
this.authorizationService = authorizationService;
}
/**
* Get the role with the given id.
**/
@RequestMapping(method = RequestMethod.GET, path = "/role/{id}")
// @PreAuthorize("hasAnyAuthority('REGISTERED_USER', 'SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
public Response getRole(@RequestParam(value = "type", defaultValue = "datasource") String type, @PathVariable("id") String id) {
int roleId = aaiRegistryService.getCouId(type, id);
return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role id is: " + roleId).toString()).type(MediaType.APPLICATION_JSON).build();
}
/**
* Create a new role with the given name and description.
**/
@RequestMapping(method = RequestMethod.POST, path = "/role")
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR')")
public Response createRole(@RequestBody Role role) {
aaiRegistryService.createRole(role);
return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
}
/**
* Subscribe to a type(Community, etc.) with id(ee, egi, etc.)
*/
@RequestMapping(method = RequestMethod.POST, path = "/subscribe/{type}/{id}")
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
public Response subscribe(@PathVariable("type") String type, @PathVariable("id") String id) {
Integer coPersonId = aaiRegistryService.getCoPersonIdByIdentifier();
if (coPersonId == null) {
coPersonId = aaiRegistryService.getCoPersonIdsByEmail().get(0);
}
Integer couId = aaiRegistryService.getCouId(type, id);
if (couId != null) {
aaiRegistryService.assignMemberRole(coPersonId, couId);
// Add role to current authorities
authoritiesUpdater.addRole(roleMappingService.repositoryIdToAuthority(id));
return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role has been assigned").toString()).type(MediaType.APPLICATION_JSON).build();
} else {
return Response.status(HttpStatus.NOT_FOUND.value()).entity(JsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
@RequestMapping(method = RequestMethod.GET, path = "/users/couid/{id}")
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
public ResponseEntity<String> getUsersByCouId(@PathVariable("id") Integer id) {
// calls.getUserByCoId()
return ResponseEntity.ok(aaiRegistryService.getUsersByCouId(id).toString());
}
@RequestMapping(method = RequestMethod.GET, path = "/users/{email}/roles")
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or hasAuthority('REGISTERED_USER') and authentication.userInfo.email==#email")
public ResponseEntity<Collection<String>> getRolesByEmail(@PathVariable("email") String email) {
return ResponseEntity.ok(authorizationService.getUserRolesByEmail(email));
}
@RequestMapping(method = RequestMethod.GET, path = "/user/roles/my")
@PreAuthorize("hasAuthority('REGISTERED_USER')")
public ResponseEntity<Collection<String>> getRoleNames() {
return ResponseEntity.ok(authorizationService.getUserRoles());
}
}

View File

@ -1,6 +1,8 @@
package eu.dnetlib.repo.manager.domain;
import java.util.ArrayList;
import java.util.List;
/**
* Created by panagiotis on 15/1/2018.
@ -11,6 +13,9 @@ public class Term {
private String nativeName;
private String encoding;
private String code;
private List<String> synonyms = new ArrayList<>();
public Term() {}
public Term(String englishName, String nativeName, String encoding, String code) {
this.englishName = englishName;
@ -19,6 +24,14 @@ public class Term {
this.code = code;
}
public Term(String englishName, String nativeName, String encoding, String code, List<String> synonyms) {
this.englishName = englishName;
this.nativeName = nativeName;
this.encoding = encoding;
this.code = code;
this.synonyms = synonyms;
}
public String getEnglishName() {
return englishName;
}
@ -50,4 +63,12 @@ public class Term {
public void setCode(String code) {
this.code = code;
}
public List<String> getSynonyms() {
return synonyms;
}
public void setSynonyms(List<String> synonyms) {
this.synonyms = synonyms;
}
}

View File

@ -34,8 +34,7 @@ import java.util.Map;
@Service("brokerService")
public class BrokerServiceImpl implements BrokerService {
@Autowired
private RepositoryServiceImpl repoAPI;
@Value("${services.provide.broker.url}:${services.provide.broker.port}/${services.provide.broker.api}${services.provide.broker.openaire}")
private String openairePath;
@Value("${services.provide.broker.url}:${services.provide.broker.port}/${services.provide.broker.api}")
@ -45,13 +44,19 @@ public class BrokerServiceImpl implements BrokerService {
private static final Logger logger = LoggerFactory.getLogger(BrokerServiceImpl.class);
@Autowired
RestTemplate restTemplate;
private final RepositoryService repoAPI;
private final RestTemplate restTemplate;
private HttpHeaders httpHeaders;
private final HashMap<String, Term> topics = new HashMap<>();
public BrokerServiceImpl(RepositoryService repositoryService, RestTemplate restTemplate) {
logger.info("init broker service");
this.repoAPI = repositoryService;
this.restTemplate = restTemplate;
}
@PostConstruct
private void initDnetTopicsMap() {

View File

@ -106,38 +106,42 @@ public class RepositoryServiceImpl implements RepositoryService {
private void init() {
logger.debug("Initialization method of repository api! Updated version!");
for (String key : this.getVocabulary("dnet:datasource_typologies").getAsMap().keySet()) {
if (key.contains("aggregator")) {
dataSourceClass.putIfAbsent("aggregator", new ArrayList<>());
dataSourceClass.get("aggregator").add(key);
} else if (key.contains("crissystem")) {
dataSourceClass.putIfAbsent("dris", new ArrayList<>());
dataSourceClass.get("dris").add(key);
} else if (key.contains("pubsrepository::journal")) { // do not change order -->
dataSourceClass.putIfAbsent("journal", Collections.singletonList("pubsrepository::journal"));
} else if (key.contains("pubsrepository")) { // do not change order <--
dataSourceClass.putIfAbsent("opendoar", new ArrayList<>());
dataSourceClass.get("opendoar").add(key);
} else if (key.contains("datarepository")) {
dataSourceClass.putIfAbsent("re3data", Collections.singletonList("datarepository::unknown"));
try {
for (String key : this.getVocabulary("dnet:datasource_typologies").getAsMap().keySet()) {
if (key.contains("aggregator")) {
dataSourceClass.putIfAbsent("aggregator", new ArrayList<>());
dataSourceClass.get("aggregator").add(key);
} else if (key.contains("crissystem")) {
dataSourceClass.putIfAbsent("dris", new ArrayList<>());
dataSourceClass.get("dris").add(key);
} else if (key.contains("pubsrepository::journal")) { // do not change order -->
dataSourceClass.putIfAbsent("journal", Collections.singletonList("pubsrepository::journal"));
} else if (key.contains("pubsrepository")) { // do not change order <--
dataSourceClass.putIfAbsent("opendoar", new ArrayList<>());
dataSourceClass.get("opendoar").add(key);
} else if (key.contains("datarepository")) {
dataSourceClass.putIfAbsent("re3data", Collections.singletonList("datarepository::unknown"));
}
}
}
for (Map.Entry<String, List<String>> entry : dataSourceClass.entrySet()) {
entry.getValue().forEach(v -> invertedDataSourceClass.put(v, entry.getKey()));
}
for (Map.Entry<String, List<String>> entry : dataSourceClass.entrySet()) {
entry.getValue().forEach(v -> invertedDataSourceClass.put(v, entry.getKey()));
}
httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
for (String vocName : vocabularyNames) {
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
}
for (String vocName : vocabularyNames) {
this.getVocabulary(vocName);
}
Country[] countries = getCountries();
for (Country c : countries) {
countriesMap.put(c.getName(), c.getCode());
inverseCountriesMap.put(c.getCode(), c.getName());
Country[] countries = getCountries();
for (Country c : countries) {
countriesMap.put(c.getName(), c.getCode());
inverseCountriesMap.put(c.getCode(), c.getName());
}
} catch (Exception e) {
logger.error("Could not retrieve vocabularies", e);
}
}

View File

@ -0,0 +1,69 @@
package eu.dnetlib.repo.manager.service.vocabulary;
import eu.dnetlib.repo.manager.domain.Term;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class DnetVocabulary {
private String id;
private String name;
private String description;
private String code;
private List<Term> terms = new ArrayList<>();
public DnetVocabulary() {
}
public static eu.dnetlib.domain.enabling.Vocabulary toVocabulary(DnetVocabulary vocabulary) {
Map<String, String> nameMap = new TreeMap<>();
Map<String, String> encodingMap = new TreeMap<>();
for (Term term : vocabulary.getTerms()) {
nameMap.put(term.getEnglishName(), term.getCode());
encodingMap.put(term.getCode(), term.getEnglishName());
}
return new eu.dnetlib.domain.enabling.Vocabulary(vocabulary.getName(), nameMap, encodingMap);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public List<Term> getTerms() {
return terms;
}
public void setTerms(List<Term> terms) {
this.terms = terms;
}
}

View File

@ -0,0 +1,37 @@
package eu.dnetlib.repo.manager.service.vocabulary;
import eu.dnetlib.domain.enabling.Vocabulary;
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.Locale;
@Service
@Primary
public class JsonApiVocabularyLoader implements VocabularyLoader {
private static final Logger logger = LoggerFactory.getLogger(JsonApiVocabularyLoader.class);
private static final String url = "%s/provision/mvc/vocabularies/%s.json";
private final String endpoint;
private final RestTemplate restTemplate = new RestTemplate();
public JsonApiVocabularyLoader(@Value("${services.openaireServicesBaseUrl}") String endpoint) {
this.endpoint = endpoint;
}
@Override
public Vocabulary getVocabulary(String vocabularyName, Locale locale, Locale defaultLocale) {
DnetVocabulary voc = restTemplate.getForObject(String.format(url, endpoint, vocabularyName), DnetVocabulary.class);
if (voc == null) {
logger.error("Error retrieving vocabulary '{}'", vocabularyName);
return null;
}
return DnetVocabulary.toVocabulary(voc);
}
}

View File

@ -59,6 +59,9 @@ public class CrisValidatorUtils {
public static List<JobResultEntry> crisResultsToJobEntries(Job crisJob) {
List<JobResultEntry> jobResultEntries = new ArrayList<>();
if (crisJob.getRuleResults() == null) {
crisJob.setRuleResults(new ArrayList<>());
}
for (RuleResults ruleResults : crisJob.getRuleResults()) {
Rule rule = ruleResults.getRule();
JobResultEntry jobResultEntry = new JobResultEntry();