Add first implementation of the new Repository Deposit Service
This commit is contained in:
parent
b389ebf160
commit
7bb8e850e8
21
dmp-backend/core/src/main/java/eu/eudat/cache/deposit/RepositoryDepositConfigurationCache.java
vendored
Normal file
21
dmp-backend/core/src/main/java/eu/eudat/cache/deposit/RepositoryDepositConfigurationCache.java
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
package eu.eudat.cache.deposit;
|
||||
|
||||
|
||||
import eu.eudat.configurations.deposit.DepositCacheOptions;
|
||||
import eu.eudat.model.doi.RepositoryConfigs;
|
||||
import gr.cite.tools.cache.CacheService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class RepositoryDepositConfigurationCache extends CacheService<RepositoryConfigs> {
|
||||
@Autowired
|
||||
public RepositoryDepositConfigurationCache(DepositCacheOptions options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<RepositoryConfigs> valueClass() {
|
||||
return RepositoryConfigs.class;
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package eu.eudat.configurations;
|
||||
|
||||
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
||||
import eu.eudat.repository.DepositRepository;
|
||||
import gr.cite.commons.web.oidc.apikey.ApiKeyCacheService;
|
||||
import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyExchangeFilterFunction;
|
||||
import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyWebfluxModel;
|
||||
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.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.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({DepositProperties.class})
|
||||
public class DepositConfiguration {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DepositConfiguration.class);
|
||||
|
||||
private final DepositProperties properties;
|
||||
|
||||
private final ApiKeyCacheService apiKeyCacheService;
|
||||
|
||||
@Autowired
|
||||
public DepositConfiguration(DepositProperties properties, ApiKeyCacheService apiKeyCacheService) {
|
||||
this.properties = properties;
|
||||
this.apiKeyCacheService = apiKeyCacheService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Qualifier("depositClients")
|
||||
public List<RepositoryDeposit> depositClients() {
|
||||
List<RepositoryDeposit> clients = new ArrayList<>();
|
||||
for (DepositProperties.DepositSource source: properties.getSources()) {
|
||||
|
||||
String host = URI.create(source.getUrl()).getHost();
|
||||
ApiKeyWebfluxModel apiKeyWebfluxModel = new ApiKeyWebfluxModel(host + "_" + source.getClientId(), source.getIssuerUrl(), source.getClientId(), source.getClientSecret(), source.getScope());
|
||||
ApiKeyExchangeFilterFunction apiKeyExchangeFilterFunction = new ApiKeyExchangeFilterFunction(this.apiKeyCacheService, apiKeyWebfluxModel);
|
||||
|
||||
clients.add(new DepositRepository(WebClient.builder().baseUrl(source.getUrl() + "/api/deposit").filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(apiKeyExchangeFilterFunction)).build()));
|
||||
}
|
||||
return clients;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package eu.eudat.configurations.deposit;
|
||||
|
||||
import gr.cite.tools.cache.CacheOptions;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@ConfigurationProperties(prefix = "cache.deposit")
|
||||
public class DepositCacheOptions extends CacheOptions {
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package eu.eudat.configurations.deposit;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({DepositProperties.class, DepositCacheOptions.class})
|
||||
public class DepositConfiguration {
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.configurations;
|
||||
package eu.eudat.configurations.deposit;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.models.data.doi;
|
||||
package eu.eudat.model.doi;
|
||||
|
||||
public class DepositCode {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.models.data.doi;
|
||||
package eu.eudat.model.doi;
|
||||
|
||||
public class DepositRequest {
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
package eu.eudat.models.data.doi;
|
||||
package eu.eudat.model.doi;
|
||||
|
||||
import eu.eudat.data.EntityDoiEntity;
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||
import eu.eudat.model.Dmp;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
@ -13,7 +12,7 @@ public class Doi {
|
|||
private String doi;
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
private DataManagementPlan dmp;
|
||||
private Dmp dmp;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
|
@ -50,20 +49,21 @@ public class Doi {
|
|||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public DataManagementPlan getDmp() {
|
||||
public Dmp getDmp() {
|
||||
return dmp;
|
||||
}
|
||||
public void setDmp(DataManagementPlan dmp) {
|
||||
public void setDmp(Dmp dmp) {
|
||||
this.dmp = dmp;
|
||||
}
|
||||
|
||||
public Doi fromDataModel(EntityDoiEntity entity) {
|
||||
this.id = entity.getId();
|
||||
this.repositoryId = entity.getRepositoryId();
|
||||
this.doi = entity.getDoi();
|
||||
this.createdAt = Date.from(entity.getCreatedAt());
|
||||
this.updatedAt = Date.from(entity.getUpdatedAt());
|
||||
return this;
|
||||
public static Doi fromDataModel(EntityDoiEntity entity) {
|
||||
Doi doi1 = new Doi();
|
||||
doi1.id = entity.getId();
|
||||
doi1.repositoryId = entity.getRepositoryId();
|
||||
doi1.doi = entity.getDoi();
|
||||
doi1.createdAt = Date.from(entity.getCreatedAt());
|
||||
doi1.updatedAt = Date.from(entity.getUpdatedAt());
|
||||
return doi1;
|
||||
}
|
||||
|
||||
public EntityDoiEntity toDataModel() throws Exception {
|
|
@ -1,7 +1,9 @@
|
|||
package eu.eudat.models.data.doi;
|
||||
package eu.eudat.model.doi;
|
||||
|
||||
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RepositoryConfig {
|
||||
|
||||
private int depositType;
|
||||
|
@ -61,14 +63,16 @@ public class RepositoryConfig {
|
|||
this.hasLogo = hasLogo;
|
||||
}
|
||||
|
||||
public RepositoryConfig toModel(RepositoryDepositConfiguration r){
|
||||
this.setDepositType(r.getDepositType());
|
||||
this.setRepositoryId(r.getRepositoryId());
|
||||
this.setRepositoryAuthorizationUrl(r.getRepositoryAuthorizationUrl());
|
||||
this.setRepositoryRecordUrl(r.getRepositoryRecordUrl());
|
||||
this.setRepositoryClientId(r.getRepositoryClientId());
|
||||
this.setRedirectUri(r.getRedirectUri());
|
||||
this.setHasLogo(r.isHasLogo());
|
||||
return this;
|
||||
public static RepositoryConfig toModel(RepositoryDepositConfiguration r){
|
||||
RepositoryConfig repositoryConfig = new RepositoryConfig();
|
||||
repositoryConfig.setDepositType(r.getDepositType());
|
||||
repositoryConfig.setRepositoryId(r.getRepositoryId());
|
||||
repositoryConfig.setRepositoryAuthorizationUrl(r.getRepositoryAuthorizationUrl());
|
||||
repositoryConfig.setRepositoryRecordUrl(r.getRepositoryRecordUrl());
|
||||
repositoryConfig.setRepositoryClientId(r.getRepositoryClientId());
|
||||
repositoryConfig.setRedirectUri(r.getRedirectUri());
|
||||
repositoryConfig.setHasLogo(r.isHasLogo());
|
||||
return repositoryConfig;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package eu.eudat.model.doi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RepositoryConfigs {
|
||||
private List<RepositoryConfig> repositoryConfigs;
|
||||
|
||||
public RepositoryConfigs() {
|
||||
}
|
||||
|
||||
public RepositoryConfigs(List<RepositoryConfig> repositoryConfigs) {
|
||||
this.repositoryConfigs = repositoryConfigs;
|
||||
}
|
||||
|
||||
public List<RepositoryConfig> getRepositoryConfigs() {
|
||||
return repositoryConfigs;
|
||||
}
|
||||
|
||||
public void setRepositoryConfigs(List<RepositoryConfig> repositoryConfigs) {
|
||||
this.repositoryConfigs = repositoryConfigs;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.logic.utilities.documents.helpers;
|
||||
package eu.eudat.model.file;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.logic.security.repositorydeposit.mapper;
|
||||
package eu.eudat.model.mapper.deposit;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
@ -0,0 +1,161 @@
|
|||
package eu.eudat.model.mapper.deposit;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.types.xml.XmlBuilder;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.data.old.UserDMP;
|
||||
import eu.eudat.data.old.UserInfo;
|
||||
import eu.eudat.depositinterface.models.*;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.criteria.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.xml.xpath.*;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class DmpEntityDepositMapper {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DmpEntityDepositMapper.class);
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
private final EntityManager entityManager;
|
||||
|
||||
public DmpEntityDepositMapper(EntityManager entityManager) {
|
||||
this.entityManager = entityManager;
|
||||
this.mapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
//TODO: WIP, missing some things like researchers, organizations etc. Must check Blueprint properties and check if those have some standard way to be identified
|
||||
public DMPDepositModel toDeposit(DmpEntity dmpEntity, File zip, FileEnvelope pdf, FileEnvelope json, String previousDOI) {
|
||||
DMPDepositModel model = new DMPDepositModel();
|
||||
List<DescriptionEntity> desciptions = this.getDescriptions(dmpEntity.getId());
|
||||
List<UserDMP> users = getUsers(dmpEntity.getId());
|
||||
model.setId(dmpEntity.getId());
|
||||
model.setLabel(dmpEntity.getLabel());
|
||||
model.setDescription(dmpEntity.getDescription());
|
||||
model.setVersion(dmpEntity.getVersion());
|
||||
model.setPdfFile(pdf);
|
||||
model.setRdaJsonFile(json);
|
||||
model.setSupportingFilesZip(zip);
|
||||
model.setDatasets(desciptions.stream().map(this::toDatasetDeposit).toList());
|
||||
model.setExtraProperties(dmpEntity.getProperties());
|
||||
model.setUsers(users.stream().map(this::toUserDeposit).collect(Collectors.toSet()));
|
||||
model.setPreviousDOI(previousDOI);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private List<DescriptionEntity> getDescriptions(UUID dmpId) {
|
||||
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<DescriptionEntity> query = builder.createQuery(DescriptionEntity.class);
|
||||
Root<DescriptionEntity> root = query.from(DescriptionEntity.class);
|
||||
query = query.where(builder.and(builder.equal(root.get("dmp"), dmpId), builder.equal(root.get("isActive"), IsActive.Active)));
|
||||
return entityManager.createQuery(query).getResultList();
|
||||
|
||||
}
|
||||
|
||||
private DatasetDepositModel toDatasetDeposit(DescriptionEntity entity) {
|
||||
DatasetDepositModel model = new DatasetDepositModel();
|
||||
model.setLabel(entity.getLabel());
|
||||
model.setDescription(entity.getDescription());
|
||||
model.setProperties(entity.getProperties());
|
||||
DescriptionTemplateEntity descriptionTemplateEntity = getDescriptionTemplate(entity.getProfile());
|
||||
model.setProfileDefinition(descriptionTemplateEntity.getDefinition());
|
||||
model.setFields(fromDefinitionAndProperties(descriptionTemplateEntity.getDefinition(), entity.getProperties()));
|
||||
return model;
|
||||
}
|
||||
|
||||
private DescriptionTemplateEntity getDescriptionTemplate(UUID descId) {
|
||||
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<DescriptionTemplateEntity> query = builder.createQuery(DescriptionTemplateEntity.class);
|
||||
Root<DescriptionTemplateEntity> root = query.from(DescriptionTemplateEntity.class);
|
||||
query = query.where(builder.and(builder.equal(root.get("id"), descId), builder.equal(root.get("isActive"), IsActive.Active)));
|
||||
return entityManager.createQuery(query).getSingleResult();
|
||||
}
|
||||
|
||||
private List<DatasetFieldsDepositModel> fromDefinitionAndProperties(String definition, String properties){
|
||||
List<DatasetFieldsDepositModel> deposit = new ArrayList<>();
|
||||
try {
|
||||
|
||||
Map<String, Object> datasetAnswers = mapper.readValue(properties, HashMap.class);
|
||||
|
||||
Document document = XmlBuilder.fromXml(definition);
|
||||
XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||
XPath xpath = xpathFactory.newXPath();
|
||||
XPathExpression expr = xpath.compile("//schematics");
|
||||
NodeList schematics = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
|
||||
for (int i = 0; i < schematics.getLength(); i++) {
|
||||
Node schematicsNode = schematics.item(i);
|
||||
NodeList schematicsList = schematicsNode.getChildNodes();
|
||||
DatasetFieldsDepositModel fieldDeposit = new DatasetFieldsDepositModel();
|
||||
List<String> schematicsDeposit = new ArrayList<>();
|
||||
if(schematicsList != null){
|
||||
for(int j = 0; j < schematicsList.getLength(); j++){
|
||||
Node schematic = schematicsList.item(j);
|
||||
if(schematic.getTextContent().matches(".*\\w+.*")) {
|
||||
schematicsDeposit.add(schematic.getTextContent());
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldDeposit.setSchematics(schematicsDeposit);
|
||||
String fieldId = schematicsNode.getParentNode().getAttributes().getNamedItem("id").getNodeValue();
|
||||
Object value = datasetAnswers.get(fieldId);
|
||||
fieldDeposit.setValue(value);
|
||||
Element field = (Element) schematicsNode.getParentNode();
|
||||
Element viewStyle = (Element) field.getElementsByTagName("viewStyle").item(0);
|
||||
String renderStyle = viewStyle.getAttribute("renderstyle");
|
||||
fieldDeposit.setRenderStyleType(renderStyle);
|
||||
Element data = (Element) field.getElementsByTagName("data").item(0);
|
||||
String multipleSelection = data.getAttribute("multiList");
|
||||
String multipleAutoComplete = data.getAttribute("multiAutoComplete");
|
||||
if(!multipleSelection.isEmpty()){
|
||||
fieldDeposit.setMultiple(Boolean.parseBoolean(multipleSelection));
|
||||
}
|
||||
else if(!multipleAutoComplete.isEmpty()){
|
||||
fieldDeposit.setMultiple(Boolean.parseBoolean(multipleAutoComplete));
|
||||
}
|
||||
else{
|
||||
fieldDeposit.setMultiple(false);
|
||||
}
|
||||
deposit.add(fieldDeposit);
|
||||
}
|
||||
}
|
||||
catch (XPathExpressionException | JsonProcessingException ex){
|
||||
logger.error(ex.getMessage(), ex);
|
||||
return null;
|
||||
}
|
||||
return deposit;
|
||||
}
|
||||
|
||||
private List<UserDMP> getUsers(UUID dmpId) {
|
||||
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<UserDMP> query = builder.createQuery(UserDMP.class);
|
||||
Root<UserDMP> root = query.from(UserDMP.class);
|
||||
Join<UserInfo, UserDMP> join = root.join("user").join("id");
|
||||
query = query.multiselect(root.get("user"), root.get("role"));
|
||||
return entityManager.createQuery(query).getResultList();
|
||||
}
|
||||
|
||||
private UserDMPDepositModel toUserDeposit(UserDMP user) {
|
||||
UserDMPDepositModel userDMPDepositModel = new UserDMPDepositModel();
|
||||
userDMPDepositModel.setUser(new UserInfoDepositModel());
|
||||
userDMPDepositModel.getUser().setName(user.getUser().getName());
|
||||
userDMPDepositModel.getUser().setEmail(user.getUser().getEmail());
|
||||
userDMPDepositModel.setRole(user.getRole());
|
||||
|
||||
return userDMPDepositModel;
|
||||
}
|
||||
}
|
|
@ -6,14 +6,17 @@ import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
|||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DepositRepository implements RepositoryDeposit {
|
||||
|
||||
private final WebClient depositClient;
|
||||
private final List<String> configurationIds;
|
||||
|
||||
public DepositRepository(WebClient depositClient) {
|
||||
this.depositClient = depositClient;
|
||||
this.configurationIds = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,4 +39,8 @@ public class DepositRepository implements RepositoryDeposit {
|
|||
public String getLogo(String repositoryId) {
|
||||
return depositClient.get().uri("/logo/" + repositoryId).exchangeToMono(mono -> mono.bodyToMono(String.class)).block();
|
||||
}
|
||||
|
||||
public List<String> getConfigurationIds() {
|
||||
return configurationIds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
package eu.eudat.service.deposit;
|
||||
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.cache.deposit.RepositoryDepositConfigurationCache;
|
||||
import eu.eudat.commons.enums.EntityType;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.configurations.deposit.DepositProperties;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.data.EntityDoiEntity;
|
||||
import eu.eudat.data.old.DMP;
|
||||
import eu.eudat.depositinterface.models.DMPDepositModel;
|
||||
import eu.eudat.depositinterface.models.FileEnvelope;
|
||||
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
||||
import eu.eudat.model.doi.DepositRequest;
|
||||
import eu.eudat.model.doi.Doi;
|
||||
import eu.eudat.model.doi.RepositoryConfig;
|
||||
import eu.eudat.model.doi.RepositoryConfigs;
|
||||
import eu.eudat.model.mapper.deposit.DmpEntityDepositMapper;
|
||||
import eu.eudat.repository.DepositRepository;
|
||||
import eu.eudat.utilities.pdf.PDFUtils;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.commons.web.oidc.apikey.ApiKeyCacheService;
|
||||
import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyExchangeFilterFunction;
|
||||
import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyWebfluxModel;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.NoResultException;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Join;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class RepositoryDepositService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RepositoryDepositService.class);
|
||||
|
||||
private final DepositProperties depositProperties;
|
||||
private final List<DepositRepository> clients;
|
||||
private final ApiKeyCacheService apiKeyCacheService;
|
||||
private final RepositoryDepositConfigurationCache repositoryDepositConfigurationCache;
|
||||
private final EntityManager entityManager;
|
||||
private final AuthorizationService authorizationService;
|
||||
private final ConventionService conventionService;
|
||||
private final Environment environment;
|
||||
private final DmpEntityDepositMapper depositMapper;
|
||||
|
||||
@Autowired
|
||||
public RepositoryDepositService(DepositProperties depositProperties, ApiKeyCacheService apiKeyCacheService, RepositoryDepositConfigurationCache repositoryDepositConfigurationCache, WebClient.Builder builder, EntityManager entityManager, AuthorizationService authorizationService, ConventionService conventionService, Environment environment, DmpEntityDepositMapper depositMapper) {
|
||||
this.depositProperties = depositProperties;
|
||||
this.apiKeyCacheService = apiKeyCacheService;
|
||||
this.repositoryDepositConfigurationCache = repositoryDepositConfigurationCache;
|
||||
this.clients = depositRepositories(builder);
|
||||
this.entityManager = entityManager;
|
||||
this.authorizationService = authorizationService;
|
||||
this.conventionService = conventionService;
|
||||
this.environment = environment;
|
||||
this.depositMapper = depositMapper;
|
||||
//GK: I don't like this but that way you can both cache the available configurations and set Configuration Ids for each client
|
||||
getAvailableConfigurations();
|
||||
}
|
||||
|
||||
|
||||
public List<RepositoryConfig> getAvailableConfigurations() {
|
||||
RepositoryConfigs configs = repositoryDepositConfigurationCache.lookup("base");
|
||||
if (configs == null) {
|
||||
List<RepositoryConfig> configurations = new ArrayList<>();
|
||||
|
||||
clients.forEach((client) -> {
|
||||
List<RepositoryDepositConfiguration> repositoryConfigs = client.getConfiguration();
|
||||
if (repositoryConfigs != null && !repositoryConfigs.isEmpty()) {
|
||||
client.getConfigurationIds().addAll(repositoryConfigs.stream().map(RepositoryDepositConfiguration::getRepositoryId).toList());
|
||||
configurations.addAll(repositoryConfigs.stream().map(RepositoryConfig::toModel).toList());
|
||||
}
|
||||
});
|
||||
|
||||
configs = new RepositoryConfigs(configurations);
|
||||
this.repositoryDepositConfigurationCache.put("base", configs);
|
||||
}
|
||||
|
||||
return configs.getRepositoryConfigs();
|
||||
}
|
||||
|
||||
public Doi deposit(DepositRequest dmpDepositModel) {
|
||||
this.authorizationService.authorize(Permission.EditDmp);
|
||||
//GK: Why it is in that service, and why it's not static?
|
||||
this.conventionService.isValidGuid(UUID.fromString(dmpDepositModel.getDmpId()));
|
||||
//GK: First get the right client
|
||||
DepositRepository repository = clients.stream().filter(client -> client.getConfigurationIds().contains(dmpDepositModel.getRepositoryId())).findFirst().orElseThrow();
|
||||
//GK: Second get the Target Data Management Plan
|
||||
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, UUID.fromString(dmpDepositModel.getDmpId()));
|
||||
|
||||
//GK: Third get the DOI from the previous Data Management Plan (if it exists)
|
||||
String previousDOI = null;
|
||||
if (dmpEntity.getVersion() > 1) { //TODO: Will it start from 1 or 0?
|
||||
previousDOI = this.getPreviousDOI(dmpEntity.getGroupId(), dmpEntity.getId(), dmpDepositModel.getRepositoryId());
|
||||
}
|
||||
|
||||
//GK: Forth make the required files to be uploaded with the deposit
|
||||
//TODO: Properly create required files
|
||||
FileEnvelope docEnvelope = new FileEnvelope();
|
||||
FileEnvelope pdfEnvelope = new FileEnvelope();
|
||||
FileEnvelope jsonEnvelope = new FileEnvelope();
|
||||
File zip = new File(environment.getProperty("temp.temp") + UUID.randomUUID() + ".zip");
|
||||
try {
|
||||
File documentFile = ResourceUtils.getFile(this.environment.getProperty("coniguration.h2020template"));
|
||||
docEnvelope.setFilename("test.docx");
|
||||
docEnvelope.setFile(documentFile);
|
||||
File pdfFile = PDFUtils.convertToPDF(docEnvelope, environment);
|
||||
pdfEnvelope.setFilename("test.pdf");
|
||||
pdfEnvelope.setFile(pdfFile);
|
||||
File jsonFile = new File(this.environment.getProperty("temp.temp") + UUID.randomUUID() + ".json");
|
||||
jsonEnvelope.setFilename("test.json");
|
||||
jsonEnvelope.setFile(jsonFile);
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
//GK: Fifth Transform them to the DepositModel
|
||||
DMPDepositModel depositModel = depositMapper.toDeposit(dmpEntity, zip, pdfEnvelope, jsonEnvelope, previousDOI);
|
||||
|
||||
//GK: Sixth Perform the deposit
|
||||
String doi = "";
|
||||
try {
|
||||
doi = repository.deposit(dmpDepositModel.getRepositoryId(), depositModel, "");
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
//GK: Something has gone wrong return null
|
||||
if (doi.isEmpty())
|
||||
return null;
|
||||
//GK: doi is fine store it in database
|
||||
EntityDoiEntity doiEntity = new EntityDoiEntity();
|
||||
doiEntity.setId(UUID.randomUUID());
|
||||
doiEntity.setDoi(doi);
|
||||
doiEntity.setEntityType(EntityType.DMP);
|
||||
DMP dmp = new DMP();
|
||||
dmp.setId(dmpEntity.getId());
|
||||
doiEntity.setEntityId(dmp);
|
||||
doiEntity.setCreatedAt(Instant.now());
|
||||
doiEntity.setIsActive(IsActive.Active);
|
||||
entityManager.persist(doiEntity);
|
||||
|
||||
|
||||
return Doi.fromDataModel(doiEntity);
|
||||
}
|
||||
|
||||
private List<DepositRepository> depositRepositories(WebClient.Builder builder) {
|
||||
List<DepositRepository> tclients = new ArrayList<>();
|
||||
for (DepositProperties.DepositSource source: depositProperties.getSources()) {
|
||||
|
||||
String host = URI.create(source.getUrl()).getHost();
|
||||
ApiKeyWebfluxModel apiKeyWebfluxModel = new ApiKeyWebfluxModel(host + "_" + source.getClientId(), source.getIssuerUrl(), source.getClientId(), source.getClientSecret(), source.getScope());
|
||||
ApiKeyExchangeFilterFunction apiKeyExchangeFilterFunction = new ApiKeyExchangeFilterFunction(this.apiKeyCacheService, apiKeyWebfluxModel);
|
||||
|
||||
tclients.add(new DepositRepository(builder.baseUrl(source.getUrl() + "/api/deposit").filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(apiKeyExchangeFilterFunction)).build()));
|
||||
}
|
||||
return tclients;
|
||||
}
|
||||
|
||||
private String getPreviousDOI(UUID groupId, UUID currentId, String repoId) {
|
||||
CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
|
||||
EntityDoiEntity doiEntity = null;
|
||||
|
||||
//GK: Step one get the previous version of the Data management plan
|
||||
CriteriaQuery<DmpEntity> query = builder.createQuery(DmpEntity.class);
|
||||
Root<DmpEntity> root = query.from(DmpEntity.class);
|
||||
query = query.select(root.get("id"));
|
||||
query = query.where(builder.and(builder.equal(root.get("groupId"), groupId), builder.equal(root.get("isActive"), IsActive.Active)));
|
||||
query = query.orderBy(builder.desc(root.get("version")));
|
||||
List<UUID> dmpIds = this.entityManager.createQuery(query).getResultList().stream().map(DmpEntity::getId).toList();
|
||||
|
||||
//GK: Step two get it's doiEntity
|
||||
CriteriaQuery<EntityDoiEntity> doiQuery = builder.createQuery(EntityDoiEntity.class);
|
||||
Root<EntityDoiEntity> doiRoot = doiQuery.from(EntityDoiEntity.class);
|
||||
doiQuery = doiQuery.multiselect(doiRoot.get("entityId").get("id"), doiRoot.get("doi"), doiRoot.get("repositoryId"));
|
||||
doiQuery = doiQuery.where(builder.and(doiRoot.get("entityId").get("id").in(dmpIds), builder.equal(doiRoot.get("isActive"), IsActive.Active)));
|
||||
List<EntityDoiEntity> dois = this.entityManager.createQuery(doiQuery).getResultList();
|
||||
|
||||
for(UUID uuid: dmpIds)
|
||||
{
|
||||
if (uuid.equals(currentId))
|
||||
continue;
|
||||
doiEntity = dois.stream()
|
||||
.filter(entityDoiEntity -> entityDoiEntity.getEntityId().getId().equals(uuid) && entityDoiEntity.getRepositoryId().equals(repoId)).findFirst().orElse(null);
|
||||
if (doiEntity != null)
|
||||
break;
|
||||
}
|
||||
return doiEntity != null ? doiEntity.getDoi() : null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.logic.utilities.documents.pdf;
|
||||
package eu.eudat.utilities.pdf;
|
||||
|
||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||
import eu.eudat.model.file.FileEnvelope;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
|
@ -18,6 +18,13 @@ import java.util.UUID;
|
|||
|
||||
public class PDFUtils {
|
||||
|
||||
public static File convertToPDF(eu.eudat.depositinterface.models.FileEnvelope file, Environment environment) throws IOException {
|
||||
FileEnvelope envelope = new FileEnvelope();
|
||||
envelope.setFilename(file.getFilename());
|
||||
envelope.setFile(file.getFile());
|
||||
return convertToPDF(envelope, environment);
|
||||
}
|
||||
|
||||
public static File convertToPDF(FileEnvelope file, Environment environment) throws IOException {
|
||||
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
||||
String uuid = UUID.randomUUID().toString();
|
|
@ -17,8 +17,8 @@ import eu.eudat.logic.managers.DataManagementPlanManager;
|
|||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||
import eu.eudat.logic.utilities.documents.pdf.PDFUtils;
|
||||
import eu.eudat.model.file.FileEnvelope;
|
||||
import eu.eudat.utilities.pdf.PDFUtils;
|
||||
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetsToBeFinalized;
|
||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||
|
|
|
@ -19,8 +19,8 @@ import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
|||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl;
|
||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||
import eu.eudat.logic.utilities.documents.pdf.PDFUtils;
|
||||
import eu.eudat.model.file.FileEnvelope;
|
||||
import eu.eudat.utilities.pdf.PDFUtils;
|
||||
import eu.eudat.models.data.dataset.DatasetOverviewModel;
|
||||
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
||||
import eu.eudat.models.data.datasetwizard.DataManagentPlanListingModel;
|
||||
|
|
|
@ -3,10 +3,10 @@ package eu.eudat.controllers;
|
|||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.logic.managers.DepositManager;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.doi.DepositCode;
|
||||
import eu.eudat.models.data.doi.DepositRequest;
|
||||
import eu.eudat.models.data.doi.Doi;
|
||||
import eu.eudat.models.data.doi.RepositoryConfig;
|
||||
import eu.eudat.model.doi.DepositCode;
|
||||
import eu.eudat.model.doi.DepositRequest;
|
||||
import eu.eudat.model.doi.Doi;
|
||||
import eu.eudat.model.doi.RepositoryConfig;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
|
|
|
@ -20,7 +20,7 @@ import eu.eudat.exceptions.security.UnauthorisedException;
|
|||
import eu.eudat.logic.managers.DatasetProfileManager;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||
import eu.eudat.model.file.FileEnvelope;
|
||||
import eu.eudat.logic.utilities.json.JsonSearcher;
|
||||
import eu.eudat.models.HintedModelFactory;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
|
|
|
@ -39,25 +39,25 @@ import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
|||
import eu.eudat.logic.mapper.elastic.DmpMapper;
|
||||
import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper;
|
||||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||
import eu.eudat.logic.security.repositorydeposit.mapper.DMPToDepositMapper;
|
||||
import eu.eudat.model.mapper.deposit.DMPToDepositMapper;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl;
|
||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.eudat.commons.types.xml.XmlBuilder;
|
||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||
import eu.eudat.logic.utilities.documents.pdf.PDFUtils;
|
||||
import eu.eudat.model.file.FileEnvelope;
|
||||
import eu.eudat.utilities.pdf.PDFUtils;
|
||||
import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
|
||||
import eu.eudat.logic.utilities.documents.word.WordBuilder;
|
||||
import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder;
|
||||
import eu.eudat.model.doi.DepositRequest;
|
||||
import eu.eudat.model.doi.Doi;
|
||||
import eu.eudat.models.HintedModelFactory;
|
||||
import eu.eudat.models.data.dataset.DatasetOverviewModel;
|
||||
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetsToBeFinalized;
|
||||
import eu.eudat.models.data.dmp.*;
|
||||
import eu.eudat.models.data.doi.DepositRequest;
|
||||
import eu.eudat.models.data.doi.Doi;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
|
||||
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
|
||||
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
|
||||
|
|
|
@ -33,7 +33,7 @@ import eu.eudat.logic.services.ApiContext;
|
|||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl;
|
||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||
import eu.eudat.model.file.FileEnvelope;
|
||||
import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
|
||||
import eu.eudat.logic.utilities.documents.word.WordBuilder;
|
||||
import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder;
|
||||
|
|
|
@ -2,9 +2,9 @@ package eu.eudat.logic.managers;
|
|||
|
||||
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
||||
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
||||
import eu.eudat.models.data.doi.DepositRequest;
|
||||
import eu.eudat.models.data.doi.Doi;
|
||||
import eu.eudat.models.data.doi.RepositoryConfig;
|
||||
import eu.eudat.model.doi.DepositRequest;
|
||||
import eu.eudat.model.doi.Doi;
|
||||
import eu.eudat.model.doi.RepositoryConfig;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
@ -4,9 +4,9 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.data.DmpBlueprintEntity;
|
||||
import eu.eudat.data.old.*;
|
||||
import eu.eudat.model.doi.Doi;
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
import eu.eudat.models.data.doi.Doi;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
|
||||
import eu.eudat.models.data.funder.Funder;
|
||||
import eu.eudat.models.data.helpermodels.Tuple;
|
||||
|
|
|
@ -5,12 +5,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import eu.eudat.data.old.DMP;
|
||||
import eu.eudat.data.old.DMPDatasetProfile;
|
||||
import eu.eudat.data.old.Dataset;
|
||||
import eu.eudat.model.doi.Doi;
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.models.data.dataset.DatasetOverviewModel;
|
||||
import eu.eudat.models.data.dmp.AssociatedProfile;
|
||||
import eu.eudat.models.data.dmp.Organisation;
|
||||
import eu.eudat.models.data.dmp.Researcher;
|
||||
import eu.eudat.models.data.doi.Doi;
|
||||
import eu.eudat.models.data.grant.GrantOverviewModel;
|
||||
|
||||
import java.util.*;
|
||||
|
|
|
@ -34,6 +34,14 @@ cache:
|
|||
expireAfterWriteMinutes: 10
|
||||
expireAfterAccessMinutes: 10
|
||||
refreshAfterWriteMinutes: 10
|
||||
- names: [ "deposit" ]
|
||||
allowNullValues: true
|
||||
initialCapacity: 100
|
||||
maximumSize: 500
|
||||
enableRecordStats: false
|
||||
expireAfterWriteMinutes: 10
|
||||
expireAfterAccessMinutes: 10
|
||||
refreshAfterWriteMinutes: 10
|
||||
mapCaches:
|
||||
apiKey:
|
||||
name: apikey
|
||||
|
@ -46,4 +54,7 @@ cache:
|
|||
keyPattern: supportive_material_$material$:v0
|
||||
Reference:
|
||||
name: Reference
|
||||
keyPattern: reference_$type$_$criteria$:v0
|
||||
keyPattern: reference_$type$_$criteria$:v0
|
||||
deposit:
|
||||
name: deposit
|
||||
keyPattern: base:v0
|
Loading…
Reference in New Issue