Partially fix Deposit Logic and add support for upcomming micro-services

This commit is contained in:
George Kalampokis 2023-10-18 18:15:52 +03:00
parent 5885e3ae5c
commit dc752f73ca
10 changed files with 143 additions and 19 deletions

View File

@ -35,6 +35,11 @@
<artifactId>oidc-authz</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>gr.cite.opendmp</groupId>
<artifactId>repositorydepositbase</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,35 @@
package eu.eudat.configurations;
import eu.eudat.depositinterface.repository.RepositoryDeposit;
import eu.eudat.repository.DepositRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import java.util.ArrayList;
import java.util.List;
@Configuration
@EnableConfigurationProperties({DepositProperties.class})
public class DepositConfiguration {
private final DepositProperties properties;
@Autowired
public DepositConfiguration(DepositProperties properties) {
this.properties = properties;
}
@Bean
@Qualifier("depositClients")
public List<RepositoryDeposit> depositClients() {
List<RepositoryDeposit> clients = new ArrayList<>();
for (String url: properties.getUrls()) {
clients.add(new DepositRepository(WebClient.builder().baseUrl(url + "/api/deposit").build()));
}
return clients;
}
}

View File

@ -0,0 +1,25 @@
package eu.eudat.configurations;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.ConstructorBinding;
import java.util.List;
@ConfigurationProperties(prefix = "deposit")
public class DepositProperties {
private List<String> urls;
@ConstructorBinding
public DepositProperties(List<String> urls) {
this.urls = urls;
}
public List<String> getUrls() {
return urls;
}
public void setUrls(List<String> urls) {
this.urls = urls;
}
}

View File

@ -0,0 +1,39 @@
package eu.eudat.repository;
import eu.eudat.depositinterface.models.DMPDepositModel;
import eu.eudat.depositinterface.repository.RepositoryDeposit;
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.reactive.function.client.WebClient;
import java.util.List;
public class DepositRepository implements RepositoryDeposit {
private final WebClient depositClient;
public DepositRepository(WebClient depositClient) {
this.depositClient = depositClient;
}
@Override
public String deposit(String repositoryId, DMPDepositModel dmpDepositModel, String repositoryAccessToken) throws Exception {
return depositClient.post().uri("/" + repositoryId, uriBuilder -> uriBuilder.queryParam("authToken", repositoryAccessToken).build()).bodyValue(dmpDepositModel).exchangeToMono(mono -> mono.bodyToMono(String.class)).block();
}
@Override
public String authenticate(String repositoryId, String code) {
return depositClient.get().uri("/authenticate/" + repositoryId, uriBuilder -> uriBuilder.queryParam("authToken", code).build()).exchangeToMono(mono -> mono.bodyToMono(String.class)).block();
}
@Override
public List<RepositoryDepositConfiguration> getConfiguration() {
return depositClient.get().uri("/configuration").exchangeToMono(mono -> mono.bodyToMono(new ParameterizedTypeReference<List<RepositoryDepositConfiguration>>() {})).block();
}
@Override
public String getLogo(String repositoryId) {
return depositClient.get().uri("/logo/" + repositoryId).exchangeToMono(mono -> mono.bodyToMono(String.class)).block();
}
}

View File

@ -1960,6 +1960,7 @@ public class DataManagementPlanManager {
return fileEnvelope;
}
@Transactional
public FileEnvelope getRDAJsonDocument(String id, Principal principal) throws Exception {
DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (!dmp.isPublic() && dmp.getUsers().stream().noneMatch(userInfo -> userInfo.getUser().getId() == principal.getId()))
@ -2464,6 +2465,7 @@ public class DataManagementPlanManager {
return null;
}
@Transactional
public Doi createDoi(DepositRequest depositRequest, Principal principal) throws Exception {
DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(UUID.fromString(depositRequest.getDmpId()));
if (!isUserOwnerOfDmp(dmp, principal))

View File

@ -6,10 +6,14 @@ import eu.eudat.models.data.doi.DepositRequest;
import eu.eudat.models.data.doi.Doi;
import eu.eudat.models.data.doi.RepositoryConfig;
import eu.eudat.models.data.security.Principal;
import jakarta.transaction.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import java.util.ArrayList;
import java.util.List;
@ -19,18 +23,20 @@ import java.util.Optional;
public class DepositManager {
private static final Logger logger = LoggerFactory.getLogger(DepositManager.class);
private List<RepositoryDeposit> repositories;
//private List<RepositoryDeposit> repositories;
private DataManagementPlanManager dataManagementPlanManager;
private final List<RepositoryDeposit> depositClients;
@Autowired
public DepositManager(List<RepositoryDeposit> repositories, DataManagementPlanManager dataManagementPlanManager){
this.repositories = repositories;
public DepositManager(/*List<RepositoryDeposit> repositories,*/ DataManagementPlanManager dataManagementPlanManager, @Qualifier("depositClients") List<RepositoryDeposit> depositClients){
//this.repositories = repositories;
this.dataManagementPlanManager = dataManagementPlanManager;
this.depositClients = depositClients;
}
public List<RepositoryConfig> getAvailableRepos() {
List<RepositoryConfig> reposConfigModel = new ArrayList<>();
for (RepositoryDeposit r: this.repositories) {
for (RepositoryDeposit r: this.depositClients) {
List<RepositoryDepositConfiguration> repoConf = r.getConfiguration();
if(repoConf != null) {
for(RepositoryDepositConfiguration cf: repoConf){
@ -43,7 +49,7 @@ public class DepositManager {
}
public String authenticate(String id, String code) {
for(RepositoryDeposit r: this.repositories){
for(RepositoryDeposit r: this.depositClients){
if(r.getConfiguration().stream().anyMatch(x -> x.getRepositoryId().equals(id))){
return r.authenticate(id, code);
}
@ -51,12 +57,13 @@ public class DepositManager {
return null;
}
@Transactional
public Doi deposit(DepositRequest depositRequest, Principal principal) throws Exception {
return this.dataManagementPlanManager.createDoi(depositRequest, principal);
}
public String getRepositoryLogo(String repositoryId){
for(RepositoryDeposit r: this.repositories){
for(RepositoryDeposit r: this.depositClients){
Optional<RepositoryDepositConfiguration> cf = r.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst();
if(cf.isPresent()){
return cf.get().isHasLogo() ? r.getLogo(repositoryId) : null;

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.old.*;
import eu.eudat.depositinterface.models.*;
import eu.eudat.logic.utilities.builders.XmlBuilder;
import jakarta.transaction.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
@ -25,6 +26,7 @@ public class DMPToDepositMapper {
private static final Logger logger = LoggerFactory.getLogger(DMPToDepositMapper.class);
private static final ObjectMapper mapper = new ObjectMapper();
@Transactional
public static DMPDepositModel fromDMP(DMP entity, FileEnvelope pdfFile, FileEnvelope jsonFile, File supportingFilesZip, String previousDOI) {
DMPDepositModel deposit = new DMPDepositModel();
deposit.setId(entity.getId());
@ -49,6 +51,7 @@ public class DMPToDepositMapper {
return deposit;
}
@Transactional
private static DatasetDepositModel fromDataset(Dataset entity){
DatasetDepositModel deposit = new DatasetDepositModel();
deposit.setLabel(entity.getLabel());

View File

@ -88,20 +88,24 @@ public class DmpRDAMapper {
rda.getCost().add(CostRDAMapper.toRDA((Map)costl));
});
}
UserInfo contactDb = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(UUID.fromString((String) extraProperties.get("contact")));
UserInfo contact = new UserInfo();
contact.setId(contactDb.getId());
contact.setName(contactDb.getName());
contact.setEmail(contactDb.getEmail());
if(contact.getEmail() == null){
for(UserDMP userDMP: dmp.getUsers()){
if(userDMP.getDmp().getId() == dmp.getId() && userDMP.getUser().getEmail() != null){
contact.setEmail(userDMP.getUser().getEmail());
break;
try {
UserInfo contactDb = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(UUID.fromString((String) extraProperties.get("contact")));
UserInfo contact = new UserInfo();
contact.setId(contactDb.getId());
contact.setName(contactDb.getName());
contact.setEmail(contactDb.getEmail());
if (contact.getEmail() == null) {
for (UserDMP userDMP : dmp.getUsers()) {
if (userDMP.getDmp().getId() == dmp.getId() && userDMP.getUser().getEmail() != null) {
contact.setEmail(userDMP.getUser().getEmail());
break;
}
}
}
rda.setContact(ContactRDAMapper.toRDA(contact));
} catch (NoResultException e) {
logger.error(e.getMessage(), e);
}
rda.setContact(ContactRDAMapper.toRDA(contact));
}
/*UserInfo creator;

View File

@ -14,5 +14,6 @@ spring:
optional:classpath:config/elasticsearch.yml[.yml], optional:classpath:config/elasticsearch-${spring.profiles.active}.yml[.yml], optional:file:../config/elasticsearch-${spring.profiles.active}.yml[.yml],
optional:classpath:config/file-path.yml[.yml], optional:classpath:config/file-path-${spring.profiles.active}.yml[.yml], optional:file:../config/file-path-${spring.profiles.active}.yml[.yml],
optional:classpath:config/idpclaims.yml[.yml], optional:classpath:config/idpclaims-${spring.profiles.active}.yml[.yml], optional:file:../config/idpclaims-${spring.profiles.active}.yml[.yml],
optional:classpath:config/external.yml[.yml], optional:classpath:config/external-${spring.profiles.active}.yml[.yml], optional:file:../config/external-${spring.profiles.active}.yml[.yml]
optional:classpath:config/swagger.yml[.yml], optional:classpath:config/swagger-${spring.profiles.active}.yml[.yml], optional:file:../config/swagger-${spring.profiles.active}.yml[.yml]
optional:classpath:config/external.yml[.yml], optional:classpath:config/external-${spring.profiles.active}.yml[.yml], optional:file:../config/external-${spring.profiles.active}.yml[.yml],
optional:classpath:config/swagger.yml[.yml], optional:classpath:config/swagger-${spring.profiles.active}.yml[.yml], optional:file:../config/swagger-${spring.profiles.active}.yml[.yml],
optional:classpath:config/deposit.yml[.yml], optional:classpath:config/deposit-${spring.profiles.active}.yml[.yml], optional:file:../config/deposit-${spring.profiles.active}.yml[.yml]

View File

@ -0,0 +1,3 @@
deposit:
urls:
- http://localhost:8080