From 048980ac39199028b4eae0c1c7e305edb41cf1a1 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Wed, 13 Dec 2023 11:42:59 +0200 Subject: [PATCH] zenodo model changes --- dmp-backend/core/pom.xml | 2 +- .../java/eu/eudat/audit/AuditableAction.java | 4 + .../eu/eudat/authorization/Permission.java | 3 + .../RepositoryDepositConfigurationCache.java | 21 -- .../deposit/DepositProperties.java | 57 +++-- .../builder/deposit/BaseDepositBuilder.java | 78 +++++++ .../deposit/DepositBuilderItemResponse.java | 19 ++ .../deposit/DepositConfigurationBuilder.java | 67 ++++++ .../deposit/DescriptionDepositBuilder.java | 100 ++++++++ .../DescriptionFieldDepositBuilder.java | 121 ++++++++++ .../builder/deposit/DmpDepositBuilder.java | 173 ++++++++++++++ .../deposit/DmpUserDepositBuilder.java | 84 +++++++ .../ReferenceDefinitionDepositBuilder.java | 49 ++++ .../deposit/ReferenceDepositBuilder.java | 92 ++++++++ .../deposit/ReferenceFieldDepositBuilder.java | 51 +++++ .../builder/deposit/UserDepositBuilder.java | 54 +++++ .../deposit/DepositConfigurationCensor.java | 43 ++++ .../DepositConfiguration.java} | 33 ++- .../eu/eudat/model/doi/DepositRequest.java | 29 --- .../src/main/java/eu/eudat/model/doi/Doi.java | 82 ------- .../eu/eudat/model/doi/RepositoryConfigs.java | 22 -- .../mapper/deposit/DMPToDepositMapper.java | 162 ------------- .../deposit/DmpEntityDepositMapper.java | 158 ------------- .../deposit/DepositAuthenticateRequest.java} | 12 +- .../model/persist/deposit/DepositRequest.java | 49 ++++ .../eu/eudat/query/DmpReferenceQuery.java | 2 + .../java/eu/eudat/query/EntityDoiQuery.java | 30 ++- .../eudat/repository/DepositRepository.java | 40 ---- .../service/deposit/DepositClientImpl.java | 37 +++ .../DepositConfigurationCacheOptions.java | 10 + .../DepositConfigurationCacheService.java | 66 ++++++ .../eudat/service/deposit/DepositService.java | 19 ++ .../service/deposit/DepositServiceImpl.java | 187 +++++++++++++++ .../deposit/RepositoryDepositService.java | 213 ------------------ .../description/DescriptionServiceImpl.java | 29 ++- .../AutoCompleteFieldDataHelperService.java | 5 + .../BaseFieldDataHelperService.java | 6 + ...BooleanDecisionFieldDataHelperService.java | 5 + .../CheckBoxFieldDataHelperService.java | 5 + .../CurrencyFieldDataHelperService.java | 5 + .../DataRepositoryFieldDataHelperService.java | 5 + ...setAutoCompleteFieldDataHelperService.java | 5 + ...tasetIdentifierFieldDataHelperService.java | 5 + .../DatePickerFieldDataHelperService.java | 5 + ...DmpAutoCompleteFieldDataHelperService.java | 5 + ...ExternalDatasetFieldDataHelperService.java | 5 + .../FieldDataHelperService.java | 1 + .../FreeTextFieldDataHelperService.java | 5 + ...urnalRepositoryFieldDataHelperService.java | 5 + .../LicenseFieldDataHelperService.java | 5 + .../OrganizationFieldDataHelperService.java | 5 + .../PublicationFieldDataHelperService.java | 5 + ...ationRepositoryFieldDataHelperService.java | 5 + .../RadioBoxFieldDataHelperService.java | 5 + .../RegistryFieldDataHelperService.java | 5 + ...herAutoCompleteFieldDataHelperService.java | 5 + .../ResearcherFieldDataHelperService.java | 5 + ...ichTextAreaDataFieldDataHelperService.java | 5 + .../ServiceFieldDataHelperService.java | 5 + .../TagFieldDataHelperService.java | 5 + .../TaxonomyFieldDataHelperService.java | 5 + .../TextAreaFieldDataHelperService.java | 5 + .../UploadFieldDataHelperService.java | 5 + .../ValidationFieldDataHelperService.java | 5 + .../WordListFieldDataHelperService.java | 6 + .../java/eu/eudat/utilities/pdf/PDFUtils.java | 104 ++++----- dmp-backend/web/pom.xml | 2 +- .../main/java/eu/eudat/controllers/DMPs.java | 3 +- .../java/eu/eudat/controllers/Datasets.java | 17 +- .../eudat/controllers/DepositController.java | 95 -------- .../controllers/v2/DepositController.java | 102 +++++++++ .../v2/DescriptionTemplateController.java | 2 +- .../managers/DataManagementPlanManager.java | 52 ++--- .../eudat/logic/managers/DepositManager.java | 73 ------ .../models/data/dmp/DataManagementPlan.java | 8 +- .../DataManagementPlanOverviewModel.java | 18 +- .../web/src/main/resources/config/cache.yml | 19 +- .../src/main/resources/config/permissions.yml | 14 ++ .../config/application-devel.properties | 6 +- 79 files changed, 1779 insertions(+), 1082 deletions(-) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/cache/deposit/RepositoryDepositConfigurationCache.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/BaseDepositBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositBuilderItemResponse.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositConfigurationBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpDepositBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpUserDepositBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDefinitionDepositBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDepositBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceFieldDepositBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/UserDepositBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/censorship/deposit/DepositConfigurationCensor.java rename dmp-backend/core/src/main/java/eu/eudat/model/{doi/RepositoryConfig.java => deposit/DepositConfiguration.java} (61%) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/doi/DepositRequest.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/doi/Doi.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/doi/RepositoryConfigs.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java rename dmp-backend/core/src/main/java/eu/eudat/model/{doi/DepositCode.java => persist/deposit/DepositAuthenticateRequest.java} (50%) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/persist/deposit/DepositRequest.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/repository/DepositRepository.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositConfigurationCacheOptions.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositConfigurationCacheService.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositService.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/service/deposit/RepositoryDepositService.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/controllers/DepositController.java create mode 100644 dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DepositController.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/logic/managers/DepositManager.java diff --git a/dmp-backend/core/pom.xml b/dmp-backend/core/pom.xml index 883457036..6c607edd2 100644 --- a/dmp-backend/core/pom.xml +++ b/dmp-backend/core/pom.xml @@ -37,7 +37,7 @@ gr.cite.opendmp repositorydepositbase - 1.0.4 + 2.0.0 gr.cite diff --git a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java index 684724804..73928b6da 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java +++ b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java @@ -104,4 +104,8 @@ public class AuditableAction { public static final EventId Lock_Persist = new EventId(17002, "Lock_Persist"); public static final EventId Lock_Delete = new EventId(17003, "Lock_Delete"); + public static final EventId Deposit_GetAvailableRepositories = new EventId(18000, "Deposit_GetAvailableRepositories"); + public static final EventId Deposit_GetAccessToken = new EventId(18001, "Deposit_GetAccessToken"); + public static final EventId Deposit_Deposit = new EventId(18002, "Deposit_Deposit"); + public static final EventId Deposit_GetLogo = new EventId(18003, "Deposit_GetLogo"); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java b/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java index 85558dca5..6ecc0b23b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java +++ b/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java @@ -26,6 +26,9 @@ public final class Permission { //Elastic public static String ManageElastic = "ManageElastic"; + //Deposit + public static String BrowseDeposit = "BrowseDeposit"; + public static String EditDeposit = "BrowseDeposit"; //Language diff --git a/dmp-backend/core/src/main/java/eu/eudat/cache/deposit/RepositoryDepositConfigurationCache.java b/dmp-backend/core/src/main/java/eu/eudat/cache/deposit/RepositoryDepositConfigurationCache.java deleted file mode 100644 index 904bf2e3d..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/cache/deposit/RepositoryDepositConfigurationCache.java +++ /dev/null @@ -1,21 +0,0 @@ -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 { - @Autowired - public RepositoryDepositConfigurationCache(DepositCacheOptions options) { - super(options); - } - - @Override - protected Class valueClass() { - return RepositoryConfigs.class; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/deposit/DepositProperties.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/deposit/DepositProperties.java index aeed04fa7..4ebcded6c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/deposit/DepositProperties.java +++ b/dmp-backend/core/src/main/java/eu/eudat/configurations/deposit/DepositProperties.java @@ -8,58 +8,71 @@ import java.util.List; @ConfigurationProperties(prefix = "deposit") public class DepositProperties { - private final List sources; - - @ConstructorBinding - public DepositProperties(List sources) { - this.sources = sources; - } + private List sources; public List getSources() { return sources; } + public void setSources(List sources) { + this.sources = sources; + } + public static class DepositSource { - private final String url; - private final List codes; - private final String issuerUrl; - private final String clientId; - private final String clientSecret; - private final String scope; + private String repositoryId; + private String url; + private String issuerUrl; + private String clientId; + private String clientSecret; + private String scope; - @ConstructorBinding - public DepositSource(String url, List codes, String issuerUrl, String clientId, String clientSecret, String scope) { - this.url = url; - this.codes = codes; - this.issuerUrl = issuerUrl; - this.clientId = clientId; - this.clientSecret = clientSecret; - this.scope = scope; + public String getRepositoryId() { + return repositoryId; + } + + public void setRepositoryId(String repositoryId) { + this.repositoryId = repositoryId; } public String getUrl() { return url; } + public void setUrl(String url) { + this.url = url; + } + public String getIssuerUrl() { return issuerUrl; } + public void setIssuerUrl(String issuerUrl) { + this.issuerUrl = issuerUrl; + } + public String getClientId() { return clientId; } + public void setClientId(String clientId) { + this.clientId = clientId; + } + public String getClientSecret() { return clientSecret; } + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } + public String getScope() { return scope; } - public List getCodes() { - return codes; + public void setScope(String scope) { + this.scope = scope; } } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/BaseDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/BaseDepositBuilder.java new file mode 100644 index 000000000..a45c1c847 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/BaseDepositBuilder.java @@ -0,0 +1,78 @@ +package eu.eudat.model.builder.deposit; + +import eu.eudat.convention.ConventionService; +import gr.cite.tools.data.builder.Builder; +import gr.cite.tools.data.query.QueryBase; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.LoggerService; + +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +public abstract class BaseDepositBuilder implements Builder { + protected final LoggerService logger; + protected final ConventionService conventionService; + + public BaseDepositBuilder( + ConventionService conventionService, + LoggerService logger + ) { + this.conventionService = conventionService; + this.logger = logger; + } + + public M build(D data) throws MyApplicationException { + if (data == null) { + //this.logger.Debug(new MapLogEntry("requested build for null item requesting fields").And("fields", directives)); +// return default(M); + M model = null; + return null; //TODO + } + List> models = this.buildInternal(List.of(data)); + return models.stream().map(DepositBuilderItemResponse::getModel).findFirst().orElse(null); //TODO + } + + public List build(List data) throws MyApplicationException{ + List> models = this.buildInternal(data); + return models == null ? null : models.stream().map(DepositBuilderItemResponse::getModel).collect(Collectors.toList()); + } + + protected abstract List> buildInternal(List data) throws MyApplicationException; + + public Map asForeignKey(QueryBase query, Function keySelector) throws MyApplicationException { + this.logger.trace("Building references from query"); + List data = query.collect(); + this.logger.debug("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0)); + return this.asForeignKey(data, keySelector); + } + + public Map asForeignKey(List data, Function keySelector) throws MyApplicationException { + this.logger.trace("building references"); + List> models = this.buildInternal(data); + this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0)); + return models == null ? new HashMap<>() : models.stream().collect(Collectors.toMap(x-> keySelector.apply(x.getData()), DepositBuilderItemResponse::getModel)); + } + public Map> asMasterKey(QueryBase query,Function keySelector) throws MyApplicationException { + this.logger.trace("Building details from query"); + List data = query.collect(); + this.logger.debug("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0)); + return this.asMasterKey(data, keySelector); + } + + public Map> asMasterKey(List data, Function keySelector) throws MyApplicationException { + this.logger.trace("building details"); + List> models = this.buildInternal(data); + this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0)); + Map> map = new HashMap<>(); + if (models == null) return map; + for (DepositBuilderItemResponse model : models) { + K key = keySelector.apply(model.getData()); + if (!map.containsKey(key)) map.put(key, new ArrayList()); + map.get(key).add(model.getModel()); + } + return map; + } +} + diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositBuilderItemResponse.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositBuilderItemResponse.java new file mode 100644 index 000000000..d2a45511e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositBuilderItemResponse.java @@ -0,0 +1,19 @@ +package eu.eudat.model.builder.deposit; + +public class DepositBuilderItemResponse{ + private final M model; + private final D data; + + public DepositBuilderItemResponse(M model, D data) { + this.model = model; + this.data = data; + } + + public D getData() { + return data; + } + + public M getModel() { + return model; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositConfigurationBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositConfigurationBuilder.java new file mode 100644 index 000000000..b6014685a --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositConfigurationBuilder.java @@ -0,0 +1,67 @@ +package eu.eudat.model.builder.deposit; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.TagEntity; +import eu.eudat.model.Tag; +import eu.eudat.model.User; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.builder.UserBuilder; +import eu.eudat.model.deposit.DepositConfiguration; +import eu.eudat.query.UserQuery; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.BaseFieldSet; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; +import java.util.stream.Collectors; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DepositConfigurationBuilder extends BaseBuilder { + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public DepositConfigurationBuilder( + ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DepositConfigurationBuilder.class))); + } + + public DepositConfigurationBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + + List models = new ArrayList<>(); + for (eu.eudat.depositinterface.repository.DepositConfiguration d : data) { + DepositConfiguration m = new DepositConfiguration(); + if (fields.hasField(this.asIndexer(DepositConfiguration._depositType))) m.setDepositType(d.getDepositType()); + if (fields.hasField(this.asIndexer(DepositConfiguration._redirectUri))) m.setRedirectUri(d.getRedirectUri()); + if (fields.hasField(this.asIndexer(DepositConfiguration._repositoryId))) m.setRepositoryId(d.getRepositoryId()); + if (fields.hasField(this.asIndexer(DepositConfiguration._repositoryAuthorizationUrl))) m.setRepositoryAuthorizationUrl(d.getRepositoryAuthorizationUrl()); + if (fields.hasField(this.asIndexer(DepositConfiguration._repositoryRecordUrl))) m.setRepositoryRecordUrl(d.getRepositoryRecordUrl()); + if (fields.hasField(this.asIndexer(DepositConfiguration._repositoryClientId))) m.setRepositoryClientId(d.getRepositoryClientId()); + if (fields.hasField(this.asIndexer(DepositConfiguration._hasLogo))) m.setHasLogo(d.isHasLogo()); + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java new file mode 100644 index 000000000..110d54af2 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java @@ -0,0 +1,100 @@ +package eu.eudat.model.builder.deposit; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.JsonHandlingService; +import eu.eudat.commons.XmlHandlingService; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.types.description.PropertyDefinitionEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DescriptionTemplateEntity; +import eu.eudat.depositinterface.models.DescriptionDepositModel; +import eu.eudat.model.*; +import eu.eudat.model.builder.*; +import eu.eudat.model.builder.descriptionpropertiesdefinition.PropertyDefinitionBuilder; +import eu.eudat.query.*; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.BaseFieldSet; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; +import java.util.stream.Collectors; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DescriptionDepositBuilder extends BaseDepositBuilder { + + private final QueryFactory queryFactory; + + private final BuilderFactory builderFactory; + private final JsonHandlingService jsonHandlingService; + + private final XmlHandlingService xmlHandlingService; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public DescriptionDepositBuilder( + ConventionService conventionService, + QueryFactory queryFactory, + BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionDepositBuilder.class))); + this.queryFactory = queryFactory; + this.builderFactory = builderFactory; + this.jsonHandlingService = jsonHandlingService; + this.xmlHandlingService = xmlHandlingService; + } + + public DescriptionDepositBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) return new ArrayList<>(); + + Map definitionMap = this.collectDescriptionTemplates(data); + + List> models = new ArrayList<>(); + for (DescriptionEntity d : data) { + DescriptionDepositModel m = new DescriptionDepositModel(); + m.setLabel(d.getLabel()); + m.setDescription(d.getDescription()); + if (d.getProperties() != null){ + PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties()); + if (definitionMap != null && definitionMap.containsKey(d.getDescriptionTemplateId()) && propertyDefinition != null && !this.conventionService.isListNullOrEmpty(propertyDefinition.getFields())) m.setFields(this.builderFactory.builder(DescriptionFieldDepositBuilder.class).authorize(this.authorize).setDefinition(definitionMap.get(d.getDescriptionTemplateId())).build(propertyDefinition.getFields())); + } + models.add(new DepositBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + + private Map collectDescriptionTemplates(List data) throws MyApplicationException { + if (data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); + + List descriptionTemplateEntities = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DescriptionTemplate._id).ensure(DescriptionTemplate._definition)); + MapitemMap = new HashMap<>(); + + for (DescriptionTemplateEntity descriptionTemplateEntity : descriptionTemplateEntities){ + eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition()); + itemMap.put(descriptionTemplateEntity.getId(), definition); + } + return itemMap; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java new file mode 100644 index 000000000..b044d0a4c --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java @@ -0,0 +1,121 @@ +package eu.eudat.model.builder.deposit; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.description.FieldEntity; +import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.depositinterface.enums.FieldType; +import eu.eudat.depositinterface.models.DescriptionFieldDepositModel; +import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DescriptionFieldDepositBuilder extends BaseDepositBuilder { + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + private eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition; + private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider; + @Autowired + public DescriptionFieldDepositBuilder( + ConventionService conventionService, FieldDataHelperServiceProvider fieldDataHelperServiceProvider + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionFieldDepositBuilder.class))); + this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider; + } + + public DescriptionFieldDepositBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + public DescriptionFieldDepositBuilder setDefinition(DefinitionEntity definition) { + this.definition = definition; + return this; + } + + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) return new ArrayList<>(); + + List> models = new ArrayList<>(); + ObjectMapper objectMapper = new ObjectMapper(); + for (FieldEntity d : data) { + DescriptionFieldDepositModel m = new DescriptionFieldDepositModel(); + if (definition != null){ + List fieldEntities = definition.getFieldById(d.getKey()); + if (!this.conventionService.isListNullOrEmpty(fieldEntities)){ + eu.eudat.commons.types.descriptiontemplate.FieldEntity field = fieldEntities.getFirst(); + m.setSchematics(field.getSchematics()); + if (field.getData() != null) { + boolean isMultiValue = fieldDataHelperServiceProvider.get(field.getData().getFieldType()).isMultiValue(field.getData()); + if (!isMultiValue) m.setValues(List.of(d.getValue())); + else { + try { + //TODO: Find better Solution + List values = objectMapper.readValue(d.getValue(), new TypeReference>() {}); + m.setValues(values); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + } + + switch (field.getData().getFieldType()) { + case AUTO_COMPLETE -> m.setFieldType(FieldType.AUTO_COMPLETE); + case WORD_LIST -> m.setFieldType(FieldType.WORD_LIST); + case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION); + case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX); + case INTERNAL_DMP_ENTRIES_RESEARCHERS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_RESEARCHERS); + case INTERNAL_DMP_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DMPS); + case INTERNAL_DMP_ENTRIES_DATASETS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DATASETS); + case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX); + case FREE_TEXT -> m.setFieldType(FieldType.FREE_TEXT); + case TEXT_AREA -> m.setFieldType(FieldType.TEXT_AREA); + case RICH_TEXT_AREA -> m.setFieldType(FieldType.RICH_TEXT_AREA); + case UPLOAD -> m.setFieldType(FieldType.UPLOAD); + case DATE_PICKER -> m.setFieldType(FieldType.DATE_PICKER); + case EXTERNAL_DATASETS -> m.setFieldType(FieldType.EXTERNAL_DATASETS); + case DATA_REPOSITORIES -> m.setFieldType(FieldType.DATA_REPOSITORIES); + case JOURNAL_REPOSITORIES -> m.setFieldType(FieldType.JOURNAL_REPOSITORIES); + case PUB_REPOSITORIES -> m.setFieldType(FieldType.PUB_REPOSITORIES); + case LICENSES -> m.setFieldType(FieldType.LICENSES); + case PUBLICATIONS -> m.setFieldType(FieldType.PUBLICATIONS); + case REGISTRIES -> m.setFieldType(FieldType.REGISTRIES); + case SERVICES -> m.setFieldType(FieldType.SERVICES); + case TAGS -> m.setFieldType(FieldType.TAGS); + case RESEARCHERS -> m.setFieldType(FieldType.RESEARCHERS); + case ORGANIZATIONS -> m.setFieldType(FieldType.ORGANIZATIONS); + case DATASET_IDENTIFIER -> m.setFieldType(FieldType.DATASET_IDENTIFIER); + case CURRENCY -> m.setFieldType(FieldType.CURRENCY); + case VALIDATION -> m.setFieldType(FieldType.VALIDATION); + case TAXONOMIES -> m.setFieldType(FieldType.TAXONOMIES); + default -> throw new MyApplicationException("unrecognized type " + field.getData().getFieldType()); + } + } + } + } + models.add(new DepositBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpDepositBuilder.java new file mode 100644 index 000000000..bc93e21a6 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpDepositBuilder.java @@ -0,0 +1,173 @@ +package eu.eudat.model.builder.deposit; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.*; +import eu.eudat.depositinterface.enums.DmpAccessType; +import eu.eudat.depositinterface.models.*; +import eu.eudat.model.*; +import eu.eudat.query.*; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.Ordering; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.BaseFieldSet; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; +import java.util.stream.Collectors; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DmpDepositBuilder extends BaseDepositBuilder { + + private final QueryFactory queryFactory; + + private final BuilderFactory builderFactory; + private FileEnvelope pdfFile; + private FileEnvelope rdaJsonFile; + private FileEnvelope supportingFilesZip; + private String repositoryId; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public DmpDepositBuilder(ConventionService conventionService, + QueryFactory queryFactory, + BuilderFactory builderFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpDepositBuilder.class))); + this.queryFactory = queryFactory; + this.builderFactory = builderFactory; + } + + public DmpDepositBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + public DmpDepositBuilder setPdfFile(FileEnvelope pdfFile) { + this.pdfFile = pdfFile; + return this; + } + + public DmpDepositBuilder setRdaJsonFile(FileEnvelope rdaJsonFile) { + this.rdaJsonFile = rdaJsonFile; + return this; + } + + public DmpDepositBuilder setSupportingFilesZip(FileEnvelope supportingFilesZip) { + this.supportingFilesZip = supportingFilesZip; + return this; + } + + public DmpDepositBuilder setRepositoryId(String repositoryId) { + this.repositoryId = repositoryId; + return this; + } + + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) return new ArrayList<>(); + + List> models = new ArrayList<>(); + + Map> dmpReferencesMap = this.collectReferences(data); + + Map> dmpUsersMap = this.collectDmpUsers(data); + + Map> descriptionsMap = this.collectDmpDescriptions(data); + + for (DmpEntity d : data) { + DmpDepositModel m = new DmpDepositModel(); + m.setId(d.getId()); + m.setLabel(d.getLabel()); + m.setVersion(d.getVersion()); + m.setDescription(d.getDescription()); + m.setFinalizedAt(d.getFinalizedAt()); + m.setPdfFile(this.pdfFile); + m.setRdaJsonFile(this.rdaJsonFile); + m.setSupportingFilesZip(this.supportingFilesZip); + if (d.getVersion() > (short)1) m.setPreviousDOI(this.getPreviousDOI(d.getGroupId(), d.getId())); + switch (d.getAccessType()){ + case Public -> m.setAccessType(DmpAccessType.Public); + case Restricted -> m.setAccessType(DmpAccessType.Restricted); + case null -> m.setAccessType(null); + default -> throw new MyApplicationException("unrecognized type " + d.getAccessType().getValue()); + } + if (dmpReferencesMap != null && !dmpReferencesMap.isEmpty() && dmpReferencesMap.containsKey(d.getId())) m.setReferences(dmpReferencesMap.get(d.getId())); + if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setUsers(dmpUsersMap.get(d.getId())); + if (descriptionsMap != null && !descriptionsMap.isEmpty() && descriptionsMap.containsKey(d.getId())) m.setDescriptions(descriptionsMap.get(d.getId())); + + models.add(new DepositBuilderItemResponse<>(m, d)); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + + private String getPreviousDOI(UUID dmpGroup, UUID currentDmpId) { + if (repositoryId == null || repositoryId.isEmpty()) throw new MyApplicationException("repositoryId required"); + + //GK: Step one get the previous version of the Data management plan + DmpQuery dmpQuery = this.queryFactory.query(DmpQuery.class); + dmpQuery.setOrder(new Ordering().addDescending(Dmp._version)); + List dmpIds = dmpQuery.groupIds(dmpGroup).excludedIds(currentDmpId).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Dmp._id)).stream().map(DmpEntity::getId).toList(); + + //GK: Step two get it's doiEntity + List dois = this.queryFactory.query(EntityDoiQuery.class).repositoryIds(repositoryId).entityIds(dmpIds).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(EntityDoi._entityId, EntityDoi._doi)); + for(UUID uuid: dmpIds) { + EntityDoiEntity doiEntity = dois.stream().filter(x -> x.getEntityId().equals(uuid)).findFirst().orElse(null); + if (doiEntity != null) return doiEntity.getDoi(); + } + return null; + } + + private Map> collectReferences(List data) throws MyApplicationException { + if (data.isEmpty()) return null; + this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); + + List dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DmpReference._dmp).ensure(DmpReference._reference)); + + Map> itemMap = new HashMap<>(); + ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(dmpReferences.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList())); + Map referenceDepositModelMap = this.builderFactory.builder(ReferenceDepositBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId); + if (referenceDepositModelMap == null) return null; + for (DmpReferenceEntity dmpReference : dmpReferences) { + ReferenceDepositModel model =referenceDepositModelMap.getOrDefault(dmpReference.getReferenceId(), null); + if (model == null) continue;; + UUID key = dmpReference.getDmpId(); + if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>()); + itemMap.get(key).add(model); + } + return itemMap; + } + + + private Map> collectDmpUsers(List data) throws MyApplicationException { + this.logger.debug("checking related - {}", DmpUser.class.getSimpleName()); + + Map> itemMap; + DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DmpUserDepositBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId); + + return itemMap; + } + + private Map> collectDmpDescriptions(List data) throws MyApplicationException { + if (data.isEmpty()) return null; + this.logger.debug("checking related - {}", Description.class.getSimpleName()); + + Map> itemMap; + DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DescriptionDepositBuilder.class).authorize(this.authorize).asMasterKey(query, DescriptionEntity::getDmpId); + + return itemMap; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpUserDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpUserDepositBuilder.java new file mode 100644 index 000000000..8fb81b47e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpUserDepositBuilder.java @@ -0,0 +1,84 @@ +package eu.eudat.model.builder.deposit; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.DmpUserEntity; +import eu.eudat.data.UserEntity; +import eu.eudat.depositinterface.enums.DmpUserRole; +import eu.eudat.depositinterface.models.DmpUserDepositModel; +import eu.eudat.depositinterface.models.UserDepositModel; +import eu.eudat.query.UserQuery; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; +import java.util.stream.Collectors; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DmpUserDepositBuilder extends BaseDepositBuilder { + + private final BuilderFactory builderFactory; + + private final QueryFactory queryFactory; + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public DmpUserDepositBuilder( + ConventionService conventionService, + BuilderFactory builderFactory, QueryFactory queryFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpUserDepositBuilder.class))); + this.builderFactory = builderFactory; + this.queryFactory = queryFactory; + } + + public DmpUserDepositBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null) + return new ArrayList<>(); + + + Map userItemsMap = this.collectUsers(data); + + List> models = new ArrayList<>(); + for (DmpUserEntity d : data) { + DmpUserDepositModel m = new DmpUserDepositModel(); + switch (d.getRole()){ + case User -> m.setRole(DmpUserRole.User); + case Owner -> m.setRole(DmpUserRole.Owner); + default -> throw new MyApplicationException("unrecognized type " + d.getRole().getValue()); + } + if (userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId())); + models.add(new DepositBuilderItemResponse<>(m, d)); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } + + private Map collectUsers(List data) throws MyApplicationException { + if (data.isEmpty()) + return null; + this.logger.debug("checking related - {}", UserDepositModel.class.getSimpleName()); + + Map itemMap; + UserQuery q = this.queryFactory.query(UserQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getUserId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(UserDepositBuilder.class).authorize(this.authorize).asForeignKey(q, UserEntity::getId); + return itemMap; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDefinitionDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDefinitionDepositBuilder.java new file mode 100644 index 000000000..98dd0e8b3 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDefinitionDepositBuilder.java @@ -0,0 +1,49 @@ +package eu.eudat.model.builder.deposit; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.reference.DefinitionEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.depositinterface.models.reference.DefinitionDepositModel; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; + +import java.util.*; + +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ReferenceDefinitionDepositBuilder extends BaseDepositBuilder { + + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public ReferenceDefinitionDepositBuilder( + ConventionService conventionService, BuilderFactory builderFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDefinitionDepositBuilder.class))); + this.builderFactory = builderFactory; + } + + public ReferenceDefinitionDepositBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) return new ArrayList<>(); + + List> models = new ArrayList<>(); + for (DefinitionEntity d : data) { + DefinitionDepositModel m = new DefinitionDepositModel(); + if (d.getFields() != null) m.setFields(this.builderFactory.builder(ReferenceFieldDepositBuilder.class).authorize(this.authorize).build(d.getFields())); + models.add(new DepositBuilderItemResponse<>(m, d)); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDepositBuilder.java new file mode 100644 index 000000000..069392b9e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDepositBuilder.java @@ -0,0 +1,92 @@ +package eu.eudat.model.builder.deposit; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.XmlHandlingService; +import eu.eudat.commons.types.reference.DefinitionEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.ReferenceEntity; +import eu.eudat.depositinterface.enums.ReferenceSourceType; +import eu.eudat.depositinterface.enums.ReferenceType; +import eu.eudat.depositinterface.models.ReferenceDepositModel; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ReferenceDepositBuilder extends BaseDepositBuilder { + + private final BuilderFactory builderFactory; + private final XmlHandlingService xmlHandlingService; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public ReferenceDepositBuilder( + ConventionService conventionService, + BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDepositBuilder.class))); + this.builderFactory = builderFactory; + this.xmlHandlingService = xmlHandlingService; + } + + public ReferenceDepositBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) return new ArrayList<>(); + + List> models = new ArrayList<>(); + for (ReferenceEntity d : data) { + ReferenceDepositModel m = new ReferenceDepositModel(); + m.setId(d.getId()); + m.setLabel(d.getLabel()); + if (d.getDefinition() != null){ + DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition()); + m.setDefinition(this.builderFactory.builder(ReferenceDefinitionDepositBuilder.class).authorize(this.authorize).build(definition)); + } + m.setReference(d.getReference()); + m.setAbbreviation(d.getAbbreviation()); + m.setDescription(d.getDescription()); + m.setSource(d.getSource()); + switch (d.getSourceType()){ + case Internal -> m.setSourceType(ReferenceSourceType.Internal); + case External -> m.setSourceType(ReferenceSourceType.External); + default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue()); + } + switch (d.getType()){ + case Taxonomies -> m.setType(ReferenceType.Taxonomies); + case Licenses -> m.setType(ReferenceType.Licenses); + case Publications -> m.setType(ReferenceType.Publications); + case Journals -> m.setType(ReferenceType.Journals); + case PubRepositories -> m.setType(ReferenceType.PubRepositories); + case DataRepositories -> m.setType(ReferenceType.DataRepositories); + case Registries -> m.setType(ReferenceType.Registries); + case Services -> m.setType(ReferenceType.Services); + case Project -> m.setType(ReferenceType.Project); + case Funder -> m.setType(ReferenceType.Funder); + case Datasets -> m.setType(ReferenceType.Datasets); + case Organizations -> m.setType(ReferenceType.Organizations); + case Grants -> m.setType(ReferenceType.Grants); + case Researcher -> m.setType(ReferenceType.Researcher); + default -> throw new MyApplicationException("unrecognized type " + d.getType().getValue()); + } + models.add(new DepositBuilderItemResponse<>(m, d)); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceFieldDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceFieldDepositBuilder.java new file mode 100644 index 000000000..592ac76fe --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceFieldDepositBuilder.java @@ -0,0 +1,51 @@ +package eu.eudat.model.builder.deposit; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.reference.FieldEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.depositinterface.models.reference.FieldDepositModel; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; + +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ReferenceFieldDepositBuilder extends BaseDepositBuilder { + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public ReferenceFieldDepositBuilder( + ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFieldDepositBuilder.class))); + } + + public ReferenceFieldDepositBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) return new ArrayList<>(); + + List> models = new ArrayList<>(); + for (FieldEntity d : data) { + FieldDepositModel m = new FieldDepositModel(); + m.setCode(d.getCode()); + m.setValue(d.getValue()); + + models.add(new DepositBuilderItemResponse<>(m, d)); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/UserDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/UserDepositBuilder.java new file mode 100644 index 000000000..318020187 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/UserDepositBuilder.java @@ -0,0 +1,54 @@ +package eu.eudat.model.builder.deposit; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.UserEntity; +import eu.eudat.depositinterface.models.UserDepositModel; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class UserDepositBuilder extends BaseDepositBuilder { + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public UserDepositBuilder(ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(UserDepositBuilder.class))); + } + + public UserDepositBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null) + return new ArrayList<>(); + + List> models = new ArrayList<>(); + + for (UserEntity d : data) { + UserDepositModel m = new UserDepositModel(); + m.setName(d.getName()); + models.add(new DepositBuilderItemResponse<>(m, d)); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/deposit/DepositConfigurationCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/deposit/DepositConfigurationCensor.java new file mode 100644 index 000000000..0e91aebcd --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/deposit/DepositConfigurationCensor.java @@ -0,0 +1,43 @@ +package eu.eudat.model.censorship.deposit; + +import eu.eudat.authorization.Permission; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.Description; +import eu.eudat.model.censorship.*; +import eu.eudat.model.censorship.descriptionproperties.PropertyDefinitionCensor; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.censor.CensorFactory; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DepositConfigurationCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DepositConfigurationCensor.class)); + + protected final AuthorizationService authService; + + + public DepositConfigurationCensor(ConventionService conventionService, AuthorizationService authService) { + super(conventionService); + this.authService = authService; + } + + public void censor(FieldSet fields, UUID userId) { + logger.debug(new DataLogEntry("censoring fields", fields)); + if (fields == null || fields.isEmpty()) + return; + + this.authService.authorizeForce(Permission.BrowseDeposit); + + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/doi/RepositoryConfig.java b/dmp-backend/core/src/main/java/eu/eudat/model/deposit/DepositConfiguration.java similarity index 61% rename from dmp-backend/core/src/main/java/eu/eudat/model/doi/RepositoryConfig.java rename to dmp-backend/core/src/main/java/eu/eudat/model/deposit/DepositConfiguration.java index ec62f7f09..d732210b8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/doi/RepositoryConfig.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deposit/DepositConfiguration.java @@ -1,23 +1,28 @@ -package eu.eudat.model.doi; +package eu.eudat.model.deposit; -import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration; +import eu.eudat.depositinterface.enums.DepositType; -import java.util.List; +public class DepositConfiguration { -public class RepositoryConfig { - - private int depositType; + private DepositType depositType; + public static final String _depositType = "depositType"; private String repositoryId; + public static final String _repositoryId = "repositoryId"; private String repositoryAuthorizationUrl; + public static final String _repositoryAuthorizationUrl = "repositoryAuthorizationUrl"; private String repositoryRecordUrl; + public static final String _repositoryRecordUrl = "repositoryRecordUrl"; private String repositoryClientId; + public static final String _repositoryClientId = "repositoryClientId"; private String redirectUri; + public static final String _redirectUri = "redirectUri"; private boolean hasLogo; + public static final String _hasLogo = "hasLogo"; - public int getDepositType() { + public DepositType getDepositType() { return depositType; } - public void setDepositType(int depositType) { + public void setDepositType(DepositType depositType) { this.depositType = depositType; } @@ -62,17 +67,5 @@ public class RepositoryConfig { public void setHasLogo(boolean hasLogo) { this.hasLogo = hasLogo; } - - 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; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/doi/DepositRequest.java b/dmp-backend/core/src/main/java/eu/eudat/model/doi/DepositRequest.java deleted file mode 100644 index 7502769b3..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/doi/DepositRequest.java +++ /dev/null @@ -1,29 +0,0 @@ -package eu.eudat.model.doi; - -public class DepositRequest { - - private String repositoryId; - private String dmpId; - private String accessToken; - - public String getRepositoryId() { - return repositoryId; - } - public void setRepositoryId(String repositoryId) { - this.repositoryId = repositoryId; - } - - public String getDmpId() { - return dmpId; - } - public void setDmpId(String dmpId) { - this.dmpId = dmpId; - } - - public String getAccessToken() { - return accessToken; - } - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/doi/Doi.java b/dmp-backend/core/src/main/java/eu/eudat/model/doi/Doi.java deleted file mode 100644 index 878e857c1..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/doi/Doi.java +++ /dev/null @@ -1,82 +0,0 @@ -package eu.eudat.model.doi; - -import eu.eudat.data.EntityDoiEntity; -import eu.eudat.model.Dmp; - -import java.util.Date; -import java.util.UUID; - -public class Doi { - private UUID id; - private String repositoryId; - private String doi; - private Date createdAt; - private Date updatedAt; - private Dmp dmp; - - public UUID getId() { - return id; - } - public void setId(UUID id) { - this.id = id; - } - - public String getRepositoryId() { - return repositoryId; - } - public void setRepositoryId(String repositoryId) { - this.repositoryId = repositoryId; - } - - public String getDoi() { - return doi; - } - public void setDoi(String doi) { - this.doi = doi; - } - - public Date getCreatedAt() { - return createdAt; - } - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - public Dmp getDmp() { - return dmp; - } - public void setDmp(Dmp dmp) { - this.dmp = dmp; - } - - 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 { - EntityDoiEntity entityDoi = new EntityDoiEntity(); - entityDoi.setId(this.id); - entityDoi.setRepositoryId(this.repositoryId); - entityDoi.setDoi(this.doi); - entityDoi.setCreatedAt(this.createdAt.toInstant()); - entityDoi.setUpdatedAt(this.updatedAt.toInstant()); - return entityDoi; - } - - public String getHint() { - return null; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/doi/RepositoryConfigs.java b/dmp-backend/core/src/main/java/eu/eudat/model/doi/RepositoryConfigs.java deleted file mode 100644 index b414bcb0e..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/doi/RepositoryConfigs.java +++ /dev/null @@ -1,22 +0,0 @@ -package eu.eudat.model.doi; - -import java.util.List; - -public class RepositoryConfigs { - private List repositoryConfigs; - - public RepositoryConfigs() { - } - - public RepositoryConfigs(List repositoryConfigs) { - this.repositoryConfigs = repositoryConfigs; - } - - public List getRepositoryConfigs() { - return repositoryConfigs; - } - - public void setRepositoryConfigs(List repositoryConfigs) { - this.repositoryConfigs = repositoryConfigs; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java deleted file mode 100644 index bda0312d5..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java +++ /dev/null @@ -1,162 +0,0 @@ -package eu.eudat.model.mapper.deposit; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.eudat.data.DescriptionEntity; -import eu.eudat.data.DmpEntity; -import eu.eudat.data.UserEntity; -import eu.eudat.data.old.*; -import eu.eudat.depositinterface.models.*; -import eu.eudat.commons.types.xml.XmlBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.transaction.annotation.Transactional; -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.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class DMPToDepositMapper { - - private static final Logger logger = LoggerFactory.getLogger(DMPToDepositMapper.class); - private static final ObjectMapper mapper = new ObjectMapper(); - - @Transactional - public static DMPDepositModel fromDMP(DmpEntity entity, FileEnvelope pdfFile, FileEnvelope jsonFile, File supportingFilesZip, String previousDOI) { - DMPDepositModel deposit = new DMPDepositModel(); -// deposit.setId(entity.getId()); -// deposit.setVersion(entity.getVersion()); -// deposit.setLabel(entity.getLabel()); -// deposit.setDescription(entity.getDescription()); -// deposit.setPublic(entity.isPublic()); -// deposit.setDatasets(entity.getDataset().stream().map(DMPToDepositMapper::fromDataset).collect(Collectors.toList())); -// deposit.setUsers(entity.getUsers().stream().map(DMPToDepositMapper::fromUserDMP).collect(Collectors.toSet())); -// deposit.setOrganisations(entity.getOrganisations().stream().map(DMPToDepositMapper::fromOrganisation).collect(Collectors.toSet())); -// deposit.setResearchers(entity.getResearchers().stream().map(DMPToDepositMapper::fromResearcher).collect(Collectors.toSet())); -// if (entity.getGrant() != null) { -// deposit.setGrant(fromGrant(entity.getGrant())); -// } -// -// deposit.setPdfFile(pdfFile); -// deposit.setRdaJsonFile(jsonFile); -// deposit.setSupportingFilesZip(supportingFilesZip); -// deposit.setPreviousDOI(previousDOI); -// -// deposit.setExtraProperties(entity.getExtraProperties()); - return deposit; - } - - @Transactional - private static DatasetDepositModel fromDataset(DescriptionEntity entity){ - DatasetDepositModel deposit = new DatasetDepositModel(); - deposit.setLabel(entity.getLabel()); - deposit.setDescription(entity.getDescription()); - //TODO - //deposit.setProfileDefinition(entity.getProfile().getDefinition()); - deposit.setProperties(entity.getProperties()); - deposit.setFields(fromDefinitionAndProperties(deposit.getProfileDefinition(), deposit.getProperties())); - return deposit; - } - - private static List fromDefinitionAndProperties(String definition, String properties){ - List deposit = new ArrayList<>(); - try { - - Map 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 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 static UserDMPDepositModel fromUserDMP(DmpUserEntity entity){ -// UserDMPDepositModel deposit = new UserDMPDepositModel(); -// deposit.setUser(fromUserInfo(entity.getUser())); -// deposit.setRole(entity.getRole().getValue().intValue()); -// return deposit; -// } - - private static UserInfoDepositModel fromUserInfo(UserEntity entity){ - UserInfoDepositModel deposit = new UserInfoDepositModel(); - deposit.setName(entity.getName()); - //deposit.setEmail(entity.getEmail());//TODO: GetEmail - return deposit; - } - - private static OrganisationDepositModel fromOrganisation(Organisation entity){ - OrganisationDepositModel deposit = new OrganisationDepositModel(); - deposit.setLabel(entity.getLabel()); - return deposit; - } - - private static ResearcherDepositModel fromResearcher(Researcher entity){ - ResearcherDepositModel deposit = new ResearcherDepositModel(); - deposit.setLabel(entity.getLabel()); - deposit.setReference(entity.getReference()); - return deposit; - } - - private static GrantDepositModel fromGrant(Grant entity){ - GrantDepositModel deposit = new GrantDepositModel(); - deposit.setId(entity.getId()); - deposit.setReference(entity.getReference()); - deposit.setFunder(fromFunder(entity.getFunder())); - return deposit; - } - - private static FunderDepositModel fromFunder(Funder entity){ - FunderDepositModel deposit = new FunderDepositModel(); - deposit.setLabel(entity.getLabel()); - return deposit; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java deleted file mode 100644 index 73a7c51e4..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java +++ /dev/null @@ -1,158 +0,0 @@ -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.*; -import eu.eudat.data.UserEntity; -import eu.eudat.depositinterface.models.*; -import eu.eudat.model.UserContactInfo; -import eu.eudat.query.*; -import gr.cite.tools.data.query.Ordering; -import gr.cite.tools.data.query.QueryFactory; -import jakarta.persistence.EntityManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationContext; -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 ApplicationContext applicationContext; - private final EntityManager entityManager; - private final QueryFactory queryFactory; - - public DmpEntityDepositMapper(ApplicationContext applicationContext, EntityManager entityManager, QueryFactory queryFactory) { - this.applicationContext = applicationContext; - this.entityManager = entityManager; - this.queryFactory = queryFactory; - - 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 desciptions = this.getDescriptions(dmpEntity.getId()); - List 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 getDescriptions(UUID dmpId) { - DescriptionQuery descriptionQuery = this.queryFactory.query(DescriptionQuery.class); - return descriptionQuery.dmpDescriptionTemplateSubQuery(this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(dmpId).isActive(IsActive.Active)).isActive(IsActive.Active).collect(); - - } - - 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.getDescriptionTemplateId()); - model.setProfileDefinition(descriptionTemplateEntity.getDefinition()); - model.setFields(fromDefinitionAndProperties(descriptionTemplateEntity.getDefinition(), entity.getProperties())); - return model; - } - - private DescriptionTemplateEntity getDescriptionTemplate(UUID descriptionTemplateId) { - DescriptionTemplateQuery descriptionTemplateQuery = this.queryFactory.query(DescriptionTemplateQuery.class); - return descriptionTemplateQuery.ids(descriptionTemplateId).isActive(IsActive.Active).first(); - } - - private List fromDefinitionAndProperties(String definition, String properties){ - List deposit = new ArrayList<>(); - try { - - Map 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 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 getUsers(UUID dmpId) { - return this.queryFactory.query(DmpUserQuery.class).userIds(dmpId).collect(); - } - - private UserDMPDepositModel toUserDeposit(DmpUserEntity user) { - UserDMPDepositModel userDMPDepositModel = new UserDMPDepositModel(); - userDMPDepositModel.setUser(new UserInfoDepositModel()); - UserEntity userInfo = this.entityManager.find(UserEntity.class, user.getUserId()); - userDMPDepositModel.getUser().setName(userInfo.getName()); - UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(userInfo.getId()); - query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal)); - userDMPDepositModel.getUser().setEmail(query.first().getValue()); - userDMPDepositModel.setRole(user.getRole().getValue().intValue()); - - return userDMPDepositModel; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/doi/DepositCode.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/deposit/DepositAuthenticateRequest.java similarity index 50% rename from dmp-backend/core/src/main/java/eu/eudat/model/doi/DepositCode.java rename to dmp-backend/core/src/main/java/eu/eudat/model/persist/deposit/DepositAuthenticateRequest.java index f60742540..9ed8c2ba6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/doi/DepositCode.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/deposit/DepositAuthenticateRequest.java @@ -1,8 +1,16 @@ -package eu.eudat.model.doi; +package eu.eudat.model.persist.deposit; -public class DepositCode { +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +public class DepositAuthenticateRequest { + + @NotNull(message = "{validation.empty}") + @NotEmpty(message = "{validation.empty}") private String repositoryId; + + @NotNull(message = "{validation.empty}") + @NotEmpty(message = "{validation.empty}") private String code; public String getRepositoryId() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/deposit/DepositRequest.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/deposit/DepositRequest.java new file mode 100644 index 000000000..09f737267 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/deposit/DepositRequest.java @@ -0,0 +1,49 @@ +package eu.eudat.model.persist.deposit; + +import eu.eudat.commons.validation.ValidId; +import gr.cite.tools.fieldset.BaseFieldSet; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; + +import java.util.UUID; + +public class DepositRequest { + + @NotNull(message = "{validation.empty}") + @NotEmpty(message = "{validation.empty}") + private String repositoryId; + @NotNull(message = "{validation.empty}") + @ValidId(message = "{validation.invalidid}") + private UUID dmpId; + private String accessToken; + + private BaseFieldSet project; + public String getRepositoryId() { + return repositoryId; + } + public void setRepositoryId(String repositoryId) { + this.repositoryId = repositoryId; + } + + public UUID getDmpId() { + return dmpId; + } + public void setDmpId(UUID dmpId) { + this.dmpId = dmpId; + } + + public String getAccessToken() { + return accessToken; + } + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public BaseFieldSet getProject() { + return project; + } + + public void setProject(BaseFieldSet project) { + this.project = project; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpReferenceQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpReferenceQuery.java index 771e5c6fa..546aead03 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpReferenceQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpReferenceQuery.java @@ -222,6 +222,8 @@ public class DmpReferenceQuery extends QueryBase { if (item.match(DmpReference._id) || item.match(PublicDmpReference._id)) return DmpReferenceEntity._id; else if (item.prefix(DmpReference._dmp) || item.prefix(PublicDmpReference._dmp)) return DmpReferenceEntity._dmpId; else if (item.prefix(DmpReference._reference) || item.prefix(PublicDmpReference._reference)) return DmpReferenceEntity._referenceId; + else if (item.match(DmpReference._dmp) || item.match(PublicDmpReference._dmp)) return DmpReferenceEntity._dmpId; + else if (item.match(DmpReference._reference) || item.match(PublicDmpReference._reference)) return DmpReferenceEntity._referenceId; else if (item.match(DmpReference._data)) return DmpReferenceEntity._data; else if (item.match(DmpReference._createdAt)) return DmpReferenceEntity._createdAt; else if (item.match(DmpReference._updatedAt)) return DmpReferenceEntity._updatedAt; diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java index 01b996cea..ece0bab11 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java @@ -33,6 +33,7 @@ public class EntityDoiQuery extends QueryBase { private Collection types; private Collection excludedIds; + private Collection repositoryIds; private Collection dois; @@ -115,6 +116,21 @@ public class EntityDoiQuery extends QueryBase { return this; } + public EntityDoiQuery repositoryIds(Collection values) { + this.repositoryIds = values; + return this; + } + + public EntityDoiQuery repositoryIds(String value) { + this.repositoryIds = List.of(value); + return this; + } + + public EntityDoiQuery repositoryIds(String... value) { + this.repositoryIds = Arrays.asList(value); + return this; + } + public EntityDoiQuery entityIds(Collection values) { this.entityIds = values; return this; @@ -135,16 +151,10 @@ public class EntityDoiQuery extends QueryBase { return this; } - private final UserScope userScope; - private final AuthorizationService authService; public EntityDoiQuery( - UserScope userScope, - AuthorizationService authService ) { - this.userScope = userScope; - this.authService = authService; } @Override @@ -154,7 +164,7 @@ public class EntityDoiQuery extends QueryBase { @Override protected Boolean isFalseQuery() { - return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.types); + return this.isEmpty(this.ids) || this.isEmpty(this.isActives)|| this.isEmpty(this.repositoryIds) || this.isEmpty(this.excludedIds) || this.isEmpty(this.types); } @Override @@ -191,6 +201,12 @@ public class EntityDoiQuery extends QueryBase { inClause.value(item); predicates.add(inClause); } + if (this.repositoryIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(EntityDoiEntity._repositoryId)); + for (String item : this.repositoryIds) + inClause.value(item); + predicates.add(inClause); + } if (this.entityIds != null) { CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(EntityDoiEntity._entityId)); diff --git a/dmp-backend/core/src/main/java/eu/eudat/repository/DepositRepository.java b/dmp-backend/core/src/main/java/eu/eudat/repository/DepositRepository.java deleted file mode 100644 index d5dddb83d..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/repository/DepositRepository.java +++ /dev/null @@ -1,40 +0,0 @@ -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.ArrayList; -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 getConfiguration() { - return depositClient.get().uri("/configuration").exchangeToMono(mono -> mono.bodyToMono(new ParameterizedTypeReference>() {})).block(); - } - - @Override - public String getLogo(String repositoryId) { - return depositClient.get().uri("/logo/" + repositoryId).exchangeToMono(mono -> mono.bodyToMono(String.class)).block(); - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java new file mode 100644 index 000000000..8df39caf1 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java @@ -0,0 +1,37 @@ +package eu.eudat.service.deposit; + +import eu.eudat.depositinterface.models.DmpDepositModel; +import eu.eudat.depositinterface.repository.DepositClient; +import eu.eudat.depositinterface.repository.DepositConfiguration; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.web.reactive.function.client.WebClient; + +public class DepositClientImpl implements DepositClient { + + private final WebClient depositClient; + + public DepositClientImpl(WebClient depositClient) { + this.depositClient = depositClient; + } + + + @Override + public String deposit(DmpDepositModel dmpDepositModel, String repositoryAccessToken) throws Exception { + return depositClient.post().uri("/", uriBuilder -> uriBuilder.queryParam("authToken", repositoryAccessToken).build()).bodyValue(dmpDepositModel).exchangeToMono(mono -> mono.bodyToMono(String.class)).block(); + } + + @Override + public String authenticate(String code) { + return depositClient.get().uri("/authenticate/", uriBuilder -> uriBuilder.queryParam("authToken", code).build()).exchangeToMono(mono -> mono.bodyToMono(String.class)).block(); + } + + @Override + public DepositConfiguration getConfiguration() { + return depositClient.get().uri("/configuration").exchangeToMono(mono -> mono.bodyToMono(new ParameterizedTypeReference() {})).block(); + } + + @Override + public String getLogo() { + return depositClient.get().uri("/logo/").exchangeToMono(mono -> mono.bodyToMono(String.class)).block(); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositConfigurationCacheOptions.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositConfigurationCacheOptions.java new file mode 100644 index 000000000..26c41cb63 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositConfigurationCacheOptions.java @@ -0,0 +1,10 @@ +package eu.eudat.service.deposit; + +import gr.cite.tools.cache.CacheOptions; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConfigurationProperties(prefix = "cache.deposit-config-by-id") +public class DepositConfigurationCacheOptions extends CacheOptions { +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositConfigurationCacheService.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositConfigurationCacheService.java new file mode 100644 index 000000000..ed1911de5 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositConfigurationCacheService.java @@ -0,0 +1,66 @@ +package eu.eudat.service.deposit; + +import eu.eudat.depositinterface.repository.DepositConfiguration; +import gr.cite.tools.cache.CacheService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; + +@Service +public class DepositConfigurationCacheService extends CacheService { + + public static class DepositConfigurationCacheValue { + + public DepositConfigurationCacheValue() { + } + + public DepositConfigurationCacheValue(String repositoryId, DepositConfiguration configuration) { + this.repositoryId = repositoryId; + this.configuration = configuration; + } + + private String repositoryId; + + public String getRepositoryId() { + return repositoryId; + } + + public void setRepositoryId(String repositoryId) { + this.repositoryId = repositoryId; + } + + private DepositConfiguration configuration; + + public DepositConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration(DepositConfiguration configuration) { + this.configuration = configuration; + } + } + + + @Autowired + public DepositConfigurationCacheService(DepositConfigurationCacheOptions options) { + super(options); + } + + @Override + protected Class valueClass() { + return DepositConfigurationCacheValue.class; + } + + @Override + public String keyOf(DepositConfigurationCacheValue value) { + return this.buildKey(value.getRepositoryId()); + } + + + public String buildKey(String subject) { + HashMap keyParts = new HashMap<>(); + keyParts.put("$repositoryId$", subject); + return this.generateKey(keyParts); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositService.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositService.java new file mode 100644 index 000000000..2d0ad9fed --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositService.java @@ -0,0 +1,19 @@ +package eu.eudat.service.deposit; + +import eu.eudat.model.EntityDoi; +import eu.eudat.model.persist.deposit.DepositAuthenticateRequest; +import eu.eudat.model.persist.deposit.DepositRequest; +import eu.eudat.model.deposit.DepositConfiguration; +import gr.cite.tools.fieldset.FieldSet; + +import java.util.List; + +public interface DepositService { + List getAvailableConfigurations(FieldSet fieldSet); + + EntityDoi deposit(DepositRequest dmpDepositModel) throws Exception; + + String getLogo(String repositoryId); + + String authenticate(DepositAuthenticateRequest model); +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java new file mode 100644 index 000000000..70dbb1a1e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java @@ -0,0 +1,187 @@ +package eu.eudat.service.deposit; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.authorization.Permission; +import eu.eudat.configurations.deposit.DepositProperties; +import eu.eudat.data.DmpEntity; +import eu.eudat.depositinterface.models.DmpDepositModel; +import eu.eudat.depositinterface.models.FileEnvelope; +import eu.eudat.depositinterface.repository.DepositClient; +import eu.eudat.depositinterface.repository.DepositConfiguration; +import eu.eudat.model.EntityDoi; +import eu.eudat.model.builder.deposit.DepositConfigurationBuilder; +import eu.eudat.model.builder.deposit.DmpDepositBuilder; +import eu.eudat.model.persist.deposit.DepositAuthenticateRequest; +import eu.eudat.model.persist.deposit.DepositRequest; +import eu.eudat.model.persist.EntityDoiPersist; +import eu.eudat.query.DmpQuery; +import eu.eudat.service.entitydoi.EntityDoiService; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeCacheService; +import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeFilterFunction; +import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeModel; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyNotFoundException; +import gr.cite.tools.fieldset.FieldSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class DepositServiceImpl implements DepositService { + private static final Logger logger = LoggerFactory.getLogger(DepositServiceImpl.class); + + private final DepositProperties depositProperties; + private final Map clients; + private final TokenExchangeCacheService tokenExchangeCacheService; + private final AuthorizationService authorizationService; + private final WebClient.Builder webClientBuilder; + private final EntityDoiService doiService; + private final QueryFactory queryFactory; + private final MessageSource messageSource; + private final BuilderFactory builderFactory; + private final DepositConfigurationCacheService depositConfigurationCacheService; + + @Autowired + public DepositServiceImpl(DepositProperties depositProperties, + TokenExchangeCacheService tokenExchangeCacheService, + WebClient.Builder builder, + AuthorizationService authorizationService, + EntityDoiService doiService, + QueryFactory queryFactory, + MessageSource messageSource, + BuilderFactory builderFactory, DepositConfigurationCacheService depositConfigurationCacheService) { + this.depositProperties = depositProperties; + this.tokenExchangeCacheService = tokenExchangeCacheService; + this.authorizationService = authorizationService; + this.webClientBuilder = builder; + this.doiService = doiService; + this.queryFactory = queryFactory; + this.messageSource = messageSource; + this.builderFactory = builderFactory; + this.depositConfigurationCacheService = depositConfigurationCacheService; + this.clients = new HashMap<>(); + } + + private DepositClient getDepositClient(String repositoryId) { + if (this.clients.containsKey(repositoryId)) return this.clients.get(repositoryId); + + //GK: It's register time + DepositProperties.DepositSource source = depositProperties.getSources().stream().filter(depositSource -> depositSource.getRepositoryId().equals(repositoryId)).findFirst().orElse(null); + if (source != null) { + String host = URI.create(source.getUrl()).getHost(); + TokenExchangeModel tokenExchangeModel = new TokenExchangeModel("deposit:" + source.getRepositoryId(), source.getIssuerUrl(), source.getClientId(), source.getClientSecret(), source.getScope()); + TokenExchangeFilterFunction apiKeyExchangeFilterFunction = new TokenExchangeFilterFunction(this.tokenExchangeCacheService, tokenExchangeModel); + WebClient webClient = webClientBuilder.baseUrl(source.getUrl() + "/api/deposit").filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(apiKeyExchangeFilterFunction)).build(); + DepositClientImpl repository = new DepositClientImpl(webClient); + this.clients.put(source.getRepositoryId(), repository); + return repository; + } + return null; + } + + + @Override + public List getAvailableConfigurations(FieldSet fieldSet) { + this.authorizationService.authorizeForce(Permission.BrowseDeposit); + + List configurations = new ArrayList<>(); + + for (DepositProperties.DepositSource depositSource : depositProperties.getSources()) { + DepositConfigurationCacheService.DepositConfigurationCacheValue cacheValue = this.depositConfigurationCacheService.lookup(this.depositConfigurationCacheService.buildKey(depositSource.getRepositoryId())); + if (cacheValue == null){ + DepositClient depositClient = getDepositClient(depositSource.getRepositoryId()); + if (depositClient == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{depositSource.getRepositoryId(), DepositClient.class.getSimpleName()}, LocaleContextHolder.getLocale())); + + DepositConfiguration configuration = depositClient.getConfiguration(); + cacheValue = new DepositConfigurationCacheService.DepositConfigurationCacheValue(depositSource.getRepositoryId(), configuration); + this.depositConfigurationCacheService.put(cacheValue); + } + eu.eudat.model.deposit.DepositConfiguration depositConfiguration = this.builderFactory.builder(DepositConfigurationBuilder.class).build(fieldSet, cacheValue.getConfiguration()); + configurations.add(depositConfiguration); + } + + return configurations; + } + + @Override + public EntityDoi deposit(DepositRequest dmpDepositModel) throws Exception { + this.authorizationService.authorizeForce(Permission.EditDeposit); + + this.authorizationService.authorize(Permission.EditDmp); + //GK: First get the right client + DepositClient depositClient = getDepositClient(dmpDepositModel.getRepositoryId()); + if (depositClient == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpDepositModel.getRepositoryId(), DepositClient.class.getSimpleName()}, LocaleContextHolder.getLocale())); + + //GK: Second get the Target Data Management Plan + DmpEntity dmpEntity = this.queryFactory.query(DmpQuery.class).ids(dmpDepositModel.getDmpId()).first(); + if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpDepositModel.getDmpId(), DmpEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); + + //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(); + FileEnvelope zip = new FileEnvelope(); + //TODO: Create Files +// File zip = new File(environment.getProperty("temp.temp") + UUID.randomUUID() + ".zip"); +// try { +// docEnvelope.setFilename("test.docx"); +// docEnvelope.setFile(this.storageFileService.getH2020TemplateFile()); +// 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 = this.builderFactory.builder(DmpDepositBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic) + .setRepositoryId(dmpDepositModel.getRepositoryId()).setPdfFile(pdfEnvelope).setRdaJsonFile(jsonEnvelope).setSupportingFilesZip(zip).build(dmpEntity); + + //GK: Sixth Perform the deposit + String doi = depositClient.deposit(depositModel, dmpDepositModel.getAccessToken()); + //GK: Something has gone wrong return null + if (doi.isEmpty()) return null; + //GK: doi is fine store it in database + EntityDoiPersist doiPersist = new EntityDoiPersist(); + doiPersist.setRepositoryId(dmpDepositModel.getRepositoryId()); + doiPersist.setDoi(doi); + doiPersist.setEntityId(dmpEntity.getId()); + return doiService.persist(doiPersist, dmpDepositModel.getProject()); + } + + @Override + public String getLogo(String repositoryId) { + this.authorizationService.authorizeForce(Permission.BrowseDeposit); + + DepositClient depositClient = getDepositClient(repositoryId); + if (depositClient == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{repositoryId, DepositClient.class.getSimpleName()}, LocaleContextHolder.getLocale())); + return depositClient.getLogo(); + } + + @Override + public String authenticate(DepositAuthenticateRequest model) { + this.authorizationService.authorizeForce(Permission.BrowseDeposit); + + DepositClient depositClient = getDepositClient(model.getRepositoryId()); + if (depositClient == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getRepositoryId(), DepositClient.class.getSimpleName()}, LocaleContextHolder.getLocale())); + return depositClient.authenticate(model.getCode()); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/RepositoryDepositService.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/RepositoryDepositService.java deleted file mode 100644 index 02cf92191..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/RepositoryDepositService.java +++ /dev/null @@ -1,213 +0,0 @@ -package eu.eudat.service.deposit; - -import eu.eudat.authorization.Permission; -import eu.eudat.cache.deposit.RepositoryDepositConfigurationCache; -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.depositinterface.models.DMPDepositModel; -import eu.eudat.depositinterface.models.FileEnvelope; -import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration; -import eu.eudat.model.EntityDoi; -import eu.eudat.model.doi.DepositRequest; -import eu.eudat.model.doi.RepositoryConfig; -import eu.eudat.model.doi.RepositoryConfigs; -import eu.eudat.model.mapper.deposit.DmpEntityDepositMapper; -import eu.eudat.model.persist.EntityDoiPersist; -import eu.eudat.query.DmpQuery; -import eu.eudat.query.EntityDoiQuery; -import eu.eudat.repository.DepositRepository; -import eu.eudat.service.entitydoi.EntityDoiService; -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 gr.cite.tools.data.query.Ordering; -import gr.cite.tools.fieldset.BaseFieldSet; -import gr.cite.tools.fieldset.FieldSet; -import jakarta.persistence.EntityManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -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 javax.management.InvalidApplicationException; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.util.*; - -@Service -public class RepositoryDepositService { - private static final Logger logger = LoggerFactory.getLogger(RepositoryDepositService.class); - - private final DepositProperties depositProperties; - private final Map clients; - private final ApiKeyCacheService apiKeyCacheService; - private final RepositoryDepositConfigurationCache repositoryDepositConfigurationCache; - private final AuthorizationService authorizationService; - private final ConventionService conventionService; - private final Environment environment; - private final DmpEntityDepositMapper depositMapper; - private final WebClient.Builder webClientBuilder; - private final EntityDoiService doiService; - private final ApplicationContext applicationContext; - - - @Autowired - public RepositoryDepositService(DepositProperties depositProperties, ApiKeyCacheService apiKeyCacheService, RepositoryDepositConfigurationCache repositoryDepositConfigurationCache, WebClient.Builder builder, EntityManager entityManager, AuthorizationService authorizationService, ConventionService conventionService, Environment environment, DmpEntityDepositMapper depositMapper, DmpQuery dmpQuery, EntityDoiQuery doiQuery, EntityDoiService doiService, ApplicationContext applicationContext) { - this.depositProperties = depositProperties; - this.apiKeyCacheService = apiKeyCacheService; - this.repositoryDepositConfigurationCache = repositoryDepositConfigurationCache; - this.authorizationService = authorizationService; - this.conventionService = conventionService; - this.environment = environment; - this.depositMapper = depositMapper; - this.webClientBuilder = builder; - this.doiService = doiService; - this.applicationContext = applicationContext; - this.clients = new HashMap<>(); - } - - private DepositRepository getRepository(String repoId) { - if (this.clients.containsKey(repoId)) return this.clients.get(repoId); - - //GK: It's register time - DepositProperties.DepositSource source = depositProperties.getSources().stream().filter(depositSource -> depositSource.getCodes().contains(repoId)).findFirst().orElse(null); - if (source != null) { - 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); -// DepositRepository repository = new DepositRepository(webClientBuilder.baseUrl(source.getUrl() + "/api/deposit").filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(apiKeyExchangeFilterFunction)).build()); -// source.getCodes().forEach(code -> this.clients.put(code, repository)); -// return repository; - } - return null; - } - - - public List getAvailableConfigurations() { - RepositoryConfigs configs = repositoryDepositConfigurationCache.lookup("base"); - if (configs == null) { - List configurations = new ArrayList<>(); - //GK: So much for lazy loading - List repositories = depositProperties.getSources().stream().map(depositSource -> getRepository(depositSource.getCodes().get(0))).toList(); - - repositories.forEach((client) -> { - List repositoryConfigs = client.getConfiguration(); - if (repositoryConfigs != null && !repositoryConfigs.isEmpty()) { - configurations.addAll(repositoryConfigs.stream().map(RepositoryConfig::toModel).toList()); - } - }); - - configs = new RepositoryConfigs(configurations); - this.repositoryDepositConfigurationCache.put("base", configs); - } - - return configs.getRepositoryConfigs(); - } - - public EntityDoi deposit(DepositRequest dmpDepositModel) throws InvalidApplicationException { - 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 = getRepository(dmpDepositModel.getRepositoryId()); - //GK: Second get the Target Data Management Plan - DmpQuery dmpQuery = applicationContext.getBean(DmpQuery.class); - DmpEntity dmpEntity = dmpQuery.ids(UUID.fromString(dmpDepositModel.getDmpId())).first(); - - //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("configuration.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 - EntityDoiPersist doiPersist = new EntityDoiPersist(); - doiPersist.setRepositoryId(dmpDepositModel.getRepositoryId()); - doiPersist.setDoi(doi); - doiPersist.setEntityId(dmpEntity.getId()); - FieldSet fieldSet = new BaseFieldSet(); - return doiService.persist(doiPersist, fieldSet); - } - - public String getLogo(String repoId) { - //GK: First get the right client - DepositRepository repository = getRepository(repoId); - if (repository != null) { - return repository.getLogo(repoId); - } - return null; - } - - private String getPreviousDOI(UUID groupId, UUID currentId, String repoId) { - EntityDoiEntity doiEntity = null; - - //GK: Step one get the previous version of the Data management plan - DmpQuery dmpQuery = this.applicationContext.getBean(DmpQuery.class); - Ordering ordering = new Ordering(); - ordering.setItems(List.of("-version")); - dmpQuery.setOrder(ordering); - FieldSet fieldSet = new BaseFieldSet(); - fieldSet.ensure("id"); - List dmpIds = dmpQuery.groupIds(groupId).isActive(IsActive.Active).collectAs(fieldSet).stream().map(DmpEntity::getId).toList(); - - //GK: Step two get it's doiEntity - EntityDoiQuery doiQuery = this.applicationContext.getBean(EntityDoiQuery.class); - List dois = doiQuery.entityIds(dmpIds).isActive(IsActive.Active).collect(); - - for(UUID uuid: dmpIds) - { - if (uuid.equals(currentId)) - continue; - doiEntity = dois.stream() - .filter(entityDoiEntity -> entityDoiEntity.getEntityId().equals(uuid)).findFirst().orElse(null); - if (doiEntity != null) - break; - } - return doiEntity != null ? doiEntity.getDoi() : null; - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java index 08416d1c4..655eee0b3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java @@ -11,6 +11,8 @@ import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.description.FieldEntity; import eu.eudat.commons.types.description.PropertyDefinitionEntity; +import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity; +import eu.eudat.commons.types.descriptiontemplate.SectionEntity; import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.convention.ConventionService; import eu.eudat.data.*; @@ -181,12 +183,33 @@ public class DescriptionServiceImpl implements DescriptionService { return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Description._id), data); } - public void descriptionForce(DescriptionEntity description) throws Exception { +// public List getFieldById(String id){ +// List fieldEntities = new ArrayList<>(); +// if (id == null || id.isBlank()) return fieldEntities; +// if (this.getFieldSets() != null){ +// for (FieldSetEntity fieldSetEntity: this.getFieldSets()) { +// fieldEntities.addAll(fieldSetEntity.getFieldById(id)); +// } +// } +// if (this.getSections() != null){ +// for (SectionEntity sectionEntity: this.getSections()) { +// fieldEntities.addAll(sectionEntity.getFieldById(id)); +// } +// } +// return fieldEntities; +// } + + private void descriptionForce(DescriptionEntity description) throws Exception { List datasetProfileValidators = new LinkedList<>(); DescriptionTemplateEntity descriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, description.getDescriptionTemplateId()); if (descriptionTemplateEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); - eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXml(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition()); -// DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + eu.eudat.commons.types.descriptiontemplate.DefinitionEntity descriptionTemplateDefinition = this.xmlHandlingService.fromXml(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition()); + + + + + + // DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); // DocumentBuilder builder = builderFactory.newDocumentBuilder(); // Document xmlDocument = builder.parse(new ByteArrayInputStream(profile.getDefinition().getBytes())); // diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/AutoCompleteFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/AutoCompleteFieldDataHelperService.java index 6f43aa446..db9386b18 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/AutoCompleteFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/AutoCompleteFieldDataHelperService.java @@ -202,6 +202,11 @@ public class AutoCompleteFieldDataHelperService extends BaseFieldDataHelperServi return xml; } + @Override + protected boolean isMultiValueInternal(AutoCompleteDataEntity data) { + return data.getMultiAutoComplete(); + } + private @NotNull AutoCompleteSingleData buildAutoCompleteSingleData(AutoCompleteDataEntity.AutoCompleteSingleData data){ AutoCompleteSingleData xml = new AutoCompleteSingleData(); if (data == null) return xml; diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BaseFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BaseFieldDataHelperService.java index 876fb0b90..22102cde3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BaseFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BaseFieldDataHelperService.java @@ -25,6 +25,7 @@ public abstract class BaseFieldDataHelperService newDataInstance() { return this.newDataInstanceInternal(); @@ -59,6 +60,11 @@ public abstract class BaseFieldDataHelperService data){ + return this.isMultiValueInternal((D)data); + } @Override public BaseFieldDataEntity applyPersist(BaseFieldDataPersist persist){ BaseFieldDataEntity instance = this.newDataInstance(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BooleanDecisionFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BooleanDecisionFieldDataHelperService.java index 267be13de..873c2909c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BooleanDecisionFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BooleanDecisionFieldDataHelperService.java @@ -93,4 +93,9 @@ public class BooleanDecisionFieldDataHelperService extends BaseFieldDataHelperSe return xml; } + @Override + protected boolean isMultiValueInternal(BooleanDecisionDataEntity data) { + return false; + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/CheckBoxFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/CheckBoxFieldDataHelperService.java index 99094543e..1feef1698 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/CheckBoxFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/CheckBoxFieldDataHelperService.java @@ -96,4 +96,9 @@ public class CheckBoxFieldDataHelperService extends BaseFieldDataHelperService applyPersist(BaseFieldDataPersist persist, BaseFieldDataEntity data); BaseFieldDataPersist importExportMapDataToPersist(BaseFieldDataImportExport xml); BaseFieldDataImportExport dataToImportExportXml(BaseFieldDataEntity data); + boolean isMultiValue(BaseFieldDataEntity data); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FreeTextFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FreeTextFieldDataHelperService.java index f7399f1a5..f21eadab0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FreeTextFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FreeTextFieldDataHelperService.java @@ -96,4 +96,9 @@ public class FreeTextFieldDataHelperService extends BaseFieldDataHelperService buildInternal(FieldSet fieldSet, List data, EnumSet authorizationFlags){ return this.builderFactory.builder(PublicationDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/PublicationRepositoryFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/PublicationRepositoryFieldDataHelperService.java index 5a0248b53..640d64a8d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/PublicationRepositoryFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/PublicationRepositoryFieldDataHelperService.java @@ -100,4 +100,9 @@ public class PublicationRepositoryFieldDataHelperService extends BaseFieldDataHe xml.setMultiAutoComplete(data.getMultiAutoComplete()); return xml; } + + @Override + protected boolean isMultiValueInternal(PublicationRepositoryDataEntity data) { + return data.getMultiAutoComplete(); + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/RadioBoxFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/RadioBoxFieldDataHelperService.java index a607fd275..28afddd3d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/RadioBoxFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/RadioBoxFieldDataHelperService.java @@ -139,6 +139,11 @@ public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService map = new LinkedMultiValueMap<>(); - String uuid = UUID.randomUUID().toString(); - map.add("files", new FileSystemResource(file.getFile())); - map.add("filename", uuid + ".pdf"); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.MULTIPART_FORM_DATA); - headers.add("Content-disposition", "attachment; filename=" + uuid + ".pdf"); - headers.add("Content-type", "application/pdf"); - - HttpEntity> requestEntity = new HttpEntity>( - map, headers); - - byte[] queueResult = new RestTemplate().postForObject(environment.getProperty("pdf.converter.url") + "forms/libreoffice/convert" - , requestEntity, byte[].class); - - File resultPdf = new File(environment.getProperty("temp.temp") + uuid + ".pdf"); - FileOutputStream output = new FileOutputStream(resultPdf); - IOUtils.write(queueResult, output); - output.close(); - Files.deleteIfExists(file.getFile().toPath()); - - return resultPdf; - } -} +//package eu.eudat.utilities.pdf; +// +//import eu.eudat.model.file.FileEnvelope; +//import org.apache.commons.io.IOUtils; +//import org.springframework.core.env.Environment; +//import org.springframework.core.io.FileSystemResource; +//import org.springframework.http.HttpEntity; +//import org.springframework.http.HttpHeaders; +//import org.springframework.http.MediaType; +//import org.springframework.util.LinkedMultiValueMap; +//import org.springframework.web.client.RestTemplate; +// +//import java.io.File; +//import java.io.FileOutputStream; +//import java.io.IOException; +//import java.nio.file.Files; +//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 map = new LinkedMultiValueMap<>(); +// String uuid = UUID.randomUUID().toString(); +// map.add("files", new FileSystemResource(file.getFile())); +// map.add("filename", uuid + ".pdf"); +// HttpHeaders headers = new HttpHeaders(); +// headers.setContentType(MediaType.MULTIPART_FORM_DATA); +// headers.add("Content-disposition", "attachment; filename=" + uuid + ".pdf"); +// headers.add("Content-type", "application/pdf"); +// +// HttpEntity> requestEntity = new HttpEntity>( +// map, headers); +// +// byte[] queueResult = new RestTemplate().postForObject(environment.getProperty("pdf.converter.url") + "forms/libreoffice/convert" +// , requestEntity, byte[].class); +// +// File resultPdf = new File(environment.getProperty("temp.temp") + uuid + ".pdf"); +// FileOutputStream output = new FileOutputStream(resultPdf); +// IOUtils.write(queueResult, output); +// output.close(); +// Files.deleteIfExists(file.getFile().toPath()); +// +// return resultPdf; +// } +//} diff --git a/dmp-backend/web/pom.xml b/dmp-backend/web/pom.xml index 1f42da5ea..660396550 100644 --- a/dmp-backend/web/pom.xml +++ b/dmp-backend/web/pom.xml @@ -34,7 +34,7 @@ gr.cite.opendmp repositorydepositbase - 1.0.4 + 2.0.0 diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java index 196180c26..428b8b971 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java @@ -19,7 +19,6 @@ import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.model.DmpUser; 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; @@ -221,7 +220,7 @@ public class DMPs extends BaseController { this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole); FileEnvelope file = this.dataManagementPlanManager.getWordDocument(id, configLoader); String name = file.getFilename().substring(0, file.getFilename().length() - 5).replace(" ", "_").replace(",", "_"); - File pdffile = PDFUtils.convertToPDF(file, environment); + File pdffile = null; //PDFUtils.convertToPDF(file, environment); //TODO InputStream resource = new FileInputStream(pdffile); logger.info("Mime Type of " + name + " is " + new MimetypesFileTypeMap().getContentType(file.getFile())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java index 3ddf38a57..2bdf34079 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java @@ -3,11 +3,7 @@ package eu.eudat.controllers; import eu.eudat.authorization.Permission; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.DescriptionEntity; -import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileWizardAutocompleteRequest; -import eu.eudat.data.query.items.table.dataset.DatasetPublicTableRequest; -import eu.eudat.data.query.items.table.dataset.DatasetTableRequest; -import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.exceptions.datasetwizard.DatasetWizardCannotUnlockException; import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.logic.managers.DatasetManager; @@ -19,19 +15,15 @@ import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl; 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.DatasetWizardModel; import eu.eudat.models.data.dmp.AssociatedProfile; -import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel; -import eu.eudat.models.data.listingmodels.DatasetListingModel; -import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.types.ApiMessageCode; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.QueryFactory; +import jakarta.persistence.NoResultException; +import jakarta.transaction.Transactional; import org.apache.poi.util.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,9 +36,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import jakarta.persistence.NoResultException; -import jakarta.transaction.Transactional; - import javax.management.InvalidApplicationException; import java.io.File; import java.io.FileInputStream; @@ -244,7 +233,7 @@ public class Datasets extends BaseController { if (fileName.endsWith(".docx")){ fileName = fileName.substring(0, fileName.length() - 5); } - File pdffile = PDFUtils.convertToPDF(file, environment); + File pdffile = null; // PDFUtils.convertToPDF(file, environment); //TODO InputStream resource = new FileInputStream(pdffile); HttpHeaders responseHeaders = new HttpHeaders(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DepositController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DepositController.java deleted file mode 100644 index cfb40ea67..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DepositController.java +++ /dev/null @@ -1,95 +0,0 @@ -package eu.eudat.controllers; - -import eu.eudat.authorization.Permission; -import eu.eudat.logic.managers.DepositManager; -import eu.eudat.logic.services.ApiContext; -import eu.eudat.model.EntityDoi; -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.service.deposit.RepositoryDepositService; -import eu.eudat.types.ApiMessageCode; -import gr.cite.commons.web.authz.service.AuthorizationService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@CrossOrigin -@RequestMapping(value = {"/api/deposit/"}) -public class DepositController extends BaseController { - private static final Logger logger = LoggerFactory.getLogger(DepositController.class); - - private final DepositManager depositManager; - private final AuthorizationService authorizationService; - private final RepositoryDepositService repositoryDepositService; - - @Autowired - public DepositController(ApiContext apiContext, DepositManager depositManager, AuthorizationService authorizationService, RepositoryDepositService repositoryDepositService){ - super(apiContext); - this.depositManager = depositManager; - this.authorizationService = authorizationService; - this.repositoryDepositService = repositoryDepositService; - } - - @RequestMapping(method = RequestMethod.GET, value = {"/repos"}) - public @ResponseBody - ResponseEntity>> getAvailableRepos() { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole); - - List ids = this.repositoryDepositService.getAvailableConfigurations(); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(ids)); - } - - @RequestMapping(method = RequestMethod.POST, value = {"/getAccessToken"}) - public @ResponseBody - ResponseEntity> getAccessToken(@RequestBody DepositCode depositCode) throws Exception { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole); - - String accessToken = this.depositManager.authenticate(depositCode.getRepositoryId(), depositCode.getCode()); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(accessToken)); - } - - @RequestMapping(method = RequestMethod.POST, value = {"/createDoi"}) - public @ResponseBody - ResponseEntity> createDoi(@RequestBody DepositRequest depositRequest) { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole); - try { - EntityDoi doi = this.repositoryDepositService.deposit(depositRequest); - if(doi != null){ - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(doi)); - } - else{ - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to create DOI for the Data Management Plan")); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to create DOI for the Data Management Plan: " + e.getMessage())); - } - } - - @RequestMapping(method = RequestMethod.GET, value = {"/logo/{repositoryId}"}) - public @ResponseBody - ResponseEntity> getLogo(@PathVariable("repositoryId") String repositoryId) { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole); - try { - String encodedLogo = this.repositoryDepositService.getLogo(repositoryId); - if(encodedLogo != null){ - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully loaded " + repositoryId + "'s logo.").payload(encodedLogo)); - } - else{ - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(repositoryId + " has no logo").payload(null)); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to load " + repositoryId + "'s logo: " + e.getMessage())); - } - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DepositController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DepositController.java new file mode 100644 index 000000000..fc51e801f --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DepositController.java @@ -0,0 +1,102 @@ +package eu.eudat.controllers.v2; + +import eu.eudat.audit.AuditableAction; +import eu.eudat.authorization.Permission; +import eu.eudat.controllers.BaseController; +import eu.eudat.logic.services.ApiContext; +import eu.eudat.model.EntityDoi; +import eu.eudat.model.censorship.EntityDoiCensor; +import eu.eudat.model.censorship.deposit.DepositConfigurationCensor; +import eu.eudat.model.deposit.DepositConfiguration; +import eu.eudat.model.persist.deposit.DepositAuthenticateRequest; +import eu.eudat.model.persist.deposit.DepositRequest; +import eu.eudat.service.deposit.DepositService; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.auditing.AuditService; +import gr.cite.tools.data.censor.CensorFactory; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.LoggerService; +import gr.cite.tools.logging.MapLogEntry; +import gr.cite.tools.validation.MyValidate; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; + +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; + +@RestController +@CrossOrigin +@RequestMapping(value = {"/api/deposit/"}) +public class DepositController extends BaseController { + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DepositController.class)); + + + private final AuthorizationService authorizationService; + private final DepositService depositService; + private final CensorFactory censorFactory; + private final AuditService auditService; + + @Autowired + public DepositController(ApiContext apiContext, AuthorizationService authorizationService, DepositService depositService, CensorFactory censorFactory, AuditService auditService){ + super(apiContext); + this.authorizationService = authorizationService; + this.depositService = depositService; + this.censorFactory = censorFactory; + this.auditService = auditService; + } + + @GetMapping("/repositories/available") + public List getAvailableRepos(FieldSet fieldSet) { + logger.debug(new MapLogEntry("retrieving" + DepositConfiguration.class.getSimpleName()).And("fields", fieldSet)); + + this.censorFactory.censor(DepositConfigurationCensor.class).censor(fieldSet, null); + + List model = this.depositService.getAvailableConfigurations(fieldSet); + this.auditService.track(AuditableAction.Deposit_GetAvailableRepositories, Map.ofEntries( + new AbstractMap.SimpleEntry("fields", fieldSet) + )); + //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); + + return model; + } + + @PostMapping("/get-access-token") + public String getAccessToken(@MyValidate @RequestBody DepositAuthenticateRequest model) throws Exception { + logger.debug(new MapLogEntry("get access token" + DepositAuthenticateRequest.class.getSimpleName()).And("model", model)); + + String accessToken = this.depositService.authenticate(model); + this.auditService.track(AuditableAction.Deposit_GetAccessToken, Map.ofEntries( + new AbstractMap.SimpleEntry("model", model) + )); + return accessToken; + } + + @PostMapping("/deposit") + @Transactional + public EntityDoi deposit(@MyValidate @RequestBody DepositRequest model) throws Exception { + logger.debug(new MapLogEntry("persisting" + DepositRequest.class.getSimpleName()).And("model", model).And("fieldSet", model.getProject())); + this.censorFactory.censor(EntityDoiCensor.class).censor(model.getProject(), null); + + EntityDoi persisted = this.depositService.deposit(model); + this.auditService.track(AuditableAction.Deposit_Deposit, Map.ofEntries( + new AbstractMap.SimpleEntry("model", model) + )); + //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); + return persisted; + } + + @GetMapping("/repositories/{repositoryId}/logo") + public String getLogo(@PathVariable("repositoryId") String repositoryId) { + logger.debug(new MapLogEntry("get logo" + DepositConfiguration.class.getSimpleName()).And("repositoryId", repositoryId)); + + String logo = this.depositService.getLogo(repositoryId); + this.auditService.track(AuditableAction.Deposit_GetLogo, Map.ofEntries( + new AbstractMap.SimpleEntry("repositoryId", repositoryId) + )); + //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); + return logo; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java index ad2576339..0b3877439 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java @@ -94,7 +94,7 @@ public class DescriptionTemplateController { } @GetMapping("{id}") - public DescriptionTemplate get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException { + public DescriptionTemplate get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { logger.debug(new MapLogEntry("retrieving" + DescriptionTemplate.class.getSimpleName()).And("id", id).And("fields", fieldSet)); this.censorFactory.censor(DescriptionTemplateCensor.class).censor(fieldSet, null); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index d720bea7f..ee6683be0 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -19,8 +19,7 @@ import eu.eudat.commons.enums.old.notification.NotifyState; import eu.eudat.data.query.items.table.dataset.DatasetTableRequest; import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest; -import eu.eudat.depositinterface.models.DMPDepositModel; -import eu.eudat.depositinterface.repository.RepositoryDeposit; +import eu.eudat.depositinterface.models.DmpDepositModel; import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException; import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException; import eu.eudat.exceptions.security.ForbiddenException; @@ -28,20 +27,18 @@ import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.logic.builders.entity.UserInfoBuilder; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.model.DmpUser; -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.model.EntityDoi; import eu.eudat.model.file.FileEnvelope; import eu.eudat.query.*; -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.model.persist.deposit.DepositRequest; import eu.eudat.models.HintedModelFactory; import eu.eudat.models.data.dataset.DatasetOverviewModel; import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel; @@ -57,6 +54,7 @@ import eu.eudat.models.data.listingmodels.*; import eu.eudat.models.data.project.ProjectDMPEditorModel; import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.queryable.QueryableList; +import eu.eudat.service.deposit.DepositService; import eu.eudat.service.dmpblueprint.DmpBlueprintService; import eu.eudat.types.MetricNames; import gr.cite.commons.web.authz.service.AuthorizationService; @@ -114,7 +112,7 @@ public class DataManagementPlanManager { private UserManager userManager; private final MetricsManager metricsManager; private final ConfigLoader configLoader; - private List repositoriesDeposit; + private DepositService repositoriesDeposit; private final UserScope userScope; private final AuthorizationService authorizationService; private final DmpBlueprintService dmpBlueprintService; @@ -123,7 +121,7 @@ public class DataManagementPlanManager { @Autowired public DataManagementPlanManager(XmlHandlingService xmlHandlingService, ApiContext apiContext, DatasetManager datasetManager, Environment environment, RDAManager rdaManager, UserManager userManager, - MetricsManager metricsManager, ConfigLoader configLoader, List repositoriesDeposit, UserScope userScope, AuthorizationService authorizationService, DmpBlueprintService dmpBlueprintService, QueryFactory queryFactory) { + MetricsManager metricsManager, ConfigLoader configLoader, DepositService repositoriesDeposit, UserScope userScope, AuthorizationService authorizationService, DmpBlueprintService dmpBlueprintService, QueryFactory queryFactory) { this.xmlHandlingService = xmlHandlingService; this.apiContext = apiContext; this.datasetManager = datasetManager; @@ -2573,8 +2571,8 @@ public class DataManagementPlanManager { @Transactional - public Doi createDoi(DepositRequest depositRequest) throws Exception { - DmpEntity dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(UUID.fromString(depositRequest.getDmpId())); + public EntityDoi createDoi(DepositRequest depositRequest) throws Exception { + DmpEntity dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(depositRequest.getDmpId()); if (!isUserOwnerOfDmp(dmp)) throw new Exception("User is not authorized to invoke this action"); if (!dmp.getStatus().equals(DmpStatus.Finalized)) @@ -2582,16 +2580,16 @@ public class DataManagementPlanManager { /*if (dmp.getDoi() != null) throw new Exception("DMP already has a DOI");*/ - FileEnvelope file = getWordDocument(depositRequest.getDmpId(), configLoader); + FileEnvelope file = getWordDocument(depositRequest.getDmpId().toString(), configLoader); String name = file.getFilename().substring(0, file.getFilename().length() - 5).replaceAll("[^a-zA-Z0-9_+ ]", "").replace(" ", "_").replace(",", "_"); - File pdfFile = PDFUtils.convertToPDF(file, environment); + byte[] pdfFile = null; //PDFUtils.convertToPDF(file, environment); //TODO eu.eudat.depositinterface.models.FileEnvelope pdfEnvelope = new eu.eudat.depositinterface.models.FileEnvelope(); pdfEnvelope.setFile(pdfFile); pdfEnvelope.setFilename(name + ".pdf"); eu.eudat.depositinterface.models.FileEnvelope rdaJsonFile = new eu.eudat.depositinterface.models.FileEnvelope(); try { - FileEnvelope rdaJsonDocument = getRDAJsonDocument(depositRequest.getDmpId()); - rdaJsonFile.setFile(rdaJsonDocument.getFile()); + FileEnvelope rdaJsonDocument = getRDAJsonDocument(depositRequest.getDmpId().toString()); + //rdaJsonFile.setFile(rdaJsonDocument.getFile()); //TODO rdaJsonFile.setFilename(rdaJsonDocument.getFilename()); } catch (Exception e) { logger.error(e.getMessage(), e); @@ -2600,20 +2598,16 @@ public class DataManagementPlanManager { File supportingFilesZip = this.createSupportingFilesZip(dmp); - DMPDepositModel dmpDepositModel = DMPToDepositMapper.fromDMP(dmp, pdfEnvelope, rdaJsonFile, supportingFilesZip, previousDOI); + DmpDepositModel dmpDepositModel = new DmpDepositModel(); // DMPToDepositMapper.fromDMP(dmp, pdfEnvelope, rdaJsonFile, supportingFilesZip, previousDOI);//TODO String finalDoi = null; - for(RepositoryDeposit repo: this.repositoriesDeposit){ - if(repo.getConfiguration().stream().anyMatch(x-> x.getRepositoryId().equals(depositRequest.getRepositoryId()))){ - try { - finalDoi = repo.deposit(depositRequest.getRepositoryId(), dmpDepositModel, depositRequest.getAccessToken()); - } catch (Exception e) { - logger.error(e.getMessage(), e); - return null; - } - } + try { + finalDoi = this.repositoriesDeposit.deposit(depositRequest).getDoi(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return null; } - Doi doiModel = null; + EntityDoi doiModel = null; if (finalDoi != null) { EntityDoiEntity doiEntity = new EntityDoiEntity(); @@ -2630,15 +2624,15 @@ public class DataManagementPlanManager { // dmp.getDois().add(doiEntity); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); - doiModel = new Doi().fromDataModel(doiEntity); + doiModel = new EntityDoi();//.fromDataModel(doiEntity); //TODO } if(supportingFilesZip != null) { Files.deleteIfExists(supportingFilesZip.toPath()); } - Files.deleteIfExists(rdaJsonFile.getFile().toPath()); - Files.deleteIfExists(pdfFile.toPath()); - Files.deleteIfExists(file.getFile().toPath()); +// Files.deleteIfExists(rdaJsonFile.getFile().toPath()); //TODO +// Files.deleteIfExists(pdfFile.toPath()); +// Files.deleteIfExists(file.getFile().toPath()); return doiModel; diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DepositManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DepositManager.java deleted file mode 100644 index 75ec14229..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DepositManager.java +++ /dev/null @@ -1,73 +0,0 @@ -package eu.eudat.logic.managers; - -import eu.eudat.depositinterface.repository.RepositoryDeposit; -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 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; -import java.util.Optional; - -@Component -public class DepositManager { - private static final Logger logger = LoggerFactory.getLogger(DepositManager.class); - - //private List repositories; - private DataManagementPlanManager dataManagementPlanManager; - private final List depositClients; - - @Autowired - public DepositManager(/*List repositories,*/ DataManagementPlanManager dataManagementPlanManager, @Qualifier("depositClients") List depositClients){ - //this.repositories = repositories; - this.dataManagementPlanManager = dataManagementPlanManager; - this.depositClients = depositClients; - } - - public List getAvailableRepos() { - List reposConfigModel = new ArrayList<>(); - for (RepositoryDeposit r: this.depositClients) { - List repoConf = r.getConfiguration(); - if(repoConf != null) { - for(RepositoryDepositConfiguration cf: repoConf){ - RepositoryConfig repoModel = new RepositoryConfig(); - reposConfigModel.add(repoModel.toModel(cf)); - } - } - } - return reposConfigModel; - } - - public String authenticate(String id, String code) { - for(RepositoryDeposit r: this.depositClients){ - if(r.getConfiguration().stream().anyMatch(x -> x.getRepositoryId().equals(id))){ - return r.authenticate(id, code); - } - } - return null; - } - - @Transactional - public Doi deposit(DepositRequest depositRequest) throws Exception { - return this.dataManagementPlanManager.createDoi(depositRequest); - } - - public String getRepositoryLogo(String repositoryId){ - for(RepositoryDeposit r: this.depositClients){ - Optional cf = r.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst(); - if(cf.isPresent()){ - return cf.get().isHasLogo() ? r.getLogo(repositoryId) : null; - } - } - return null; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java index bf7e23b5f..286116e59 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java @@ -2,7 +2,7 @@ package eu.eudat.models.data.dmp; import eu.eudat.data.DmpEntity; import eu.eudat.model.DmpUser; -import eu.eudat.model.doi.Doi; +import eu.eudat.model.EntityDoi; import eu.eudat.models.DataModel; import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue; @@ -33,7 +33,7 @@ public class DataManagementPlan implements DataModel dynamicFields; private Map properties; private List users; - private List dois; + private List dois; private Project project; private Funder funder; private Boolean isPublic; @@ -173,10 +173,10 @@ public class DataManagementPlan implements DataModel getDois() { + public List getDois() { return dois; } - public void setDois(List dois) { + public void setDois(List dois) { this.dois = dois; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanOverviewModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanOverviewModel.java index d8953765f..f80e0c3a9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanOverviewModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanOverviewModel.java @@ -1,12 +1,8 @@ package eu.eudat.models.data.listingmodels; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.eudat.commons.enums.DescriptionStatus; -import eu.eudat.commons.enums.IsActive; import eu.eudat.data.DmpEntity; import eu.eudat.model.DmpUser; -import eu.eudat.model.doi.Doi; +import eu.eudat.model.EntityDoi; import eu.eudat.models.DataModel; import eu.eudat.models.data.dataset.DatasetOverviewModel; import eu.eudat.models.data.dmp.AssociatedProfile; @@ -14,9 +10,9 @@ import eu.eudat.models.data.dmp.Organisation; import eu.eudat.models.data.dmp.Researcher; import eu.eudat.models.data.grant.GrantOverviewModel; -import java.time.Instant; -import java.util.*; -import java.util.stream.Collectors; +import java.util.Date; +import java.util.List; +import java.util.UUID; public class DataManagementPlanOverviewModel implements DataModel { private String id; @@ -37,7 +33,7 @@ public class DataManagementPlanOverviewModel implements DataModel dois; + private List dois; public String getId() { @@ -166,10 +162,10 @@ public class DataManagementPlanOverviewModel implements DataModel getDois() { + public List getDois() { return dois; } - public void setDois(List dois) { + public void setDois(List dois) { this.dois = dois; } diff --git a/dmp-backend/web/src/main/resources/config/cache.yml b/dmp-backend/web/src/main/resources/config/cache.yml index 17ea03686..7de1237d9 100644 --- a/dmp-backend/web/src/main/resources/config/cache.yml +++ b/dmp-backend/web/src/main/resources/config/cache.yml @@ -2,14 +2,6 @@ cache: manager: fallbackToNoOpCache: true caffeineCaches: - - names: [ "apikey" ] - allowNullValues: true - initialCapacity: 100 - maximumSize: 500 - enableRecordStats: false - expireAfterWriteMinutes: 10 - expireAfterAccessMinutes: 10 - refreshAfterWriteMinutes: 10 - names: [ "userBySubjectId" ] allowNullValues: true initialCapacity: 100 @@ -34,7 +26,7 @@ cache: expireAfterWriteMinutes: 10 expireAfterAccessMinutes: 10 refreshAfterWriteMinutes: 10 - - names: [ "deposit" ] + - names: [ "depositConfigById" ] allowNullValues: true initialCapacity: 100 maximumSize: 500 @@ -51,9 +43,6 @@ cache: expireAfterAccessMinutes: 1 refreshAfterWriteMinutes: 1 mapCaches: - apiKey: - name: apikey - keyPattern: resolve_$keyhash$:v0 userBySubjectId: name: userBySubjectId keyPattern: user_by_subject_$subject$:v0 @@ -66,6 +55,6 @@ cache: dashboardStatisticsByUserId: name: dashboardStatisticsByUserId keyPattern: dashboard_stats_by_usr_$key$:v0 - deposit: - name: deposit - keyPattern: base:v0 \ No newline at end of file + depositConfigById: + name: depositConfigById + keyPattern: deposit_config_by_id_$repositoryId$:v0 \ No newline at end of file diff --git a/dmp-backend/web/src/main/resources/config/permissions.yml b/dmp-backend/web/src/main/resources/config/permissions.yml index f94abab73..e18005768 100644 --- a/dmp-backend/web/src/main/resources/config/permissions.yml +++ b/dmp-backend/web/src/main/resources/config/permissions.yml @@ -94,6 +94,20 @@ permissions: allowAnonymous: false allowAuthenticated: false + # Deposit + BrowseDeposit: + roles: + - Admin + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + EditDeposit: + roles: + - Admin + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + # Language BrowseLanguage: roles: [ ] diff --git a/dmp-migration-tool/web/src/main/resources/config/application-devel.properties b/dmp-migration-tool/web/src/main/resources/config/application-devel.properties index c22ba097c..4230bf7bc 100644 --- a/dmp-migration-tool/web/src/main/resources/config/application-devel.properties +++ b/dmp-migration-tool/web/src/main/resources/config/application-devel.properties @@ -1,9 +1,9 @@ dmp.domain = http://localhost:4200 ####################PERSISTENCE OVERRIDES CONFIGURATIONS########## -database.url=jdbc:postgresql://dbserver02.local.cite.gr:5432/dmptool -database.username=dmtadm -database.password=t00L4DM@18! +database.url=jdbc:postgresql://dbserver05.local.cite.gr/opendmp-prod-anonym +database.username=opendmp-psql +database.password=EG$NCKq&mARNFCtFfM spring.datasource.maxIdle=10 spring.datasource.minIdle=5 spring.datasource.maxActive=10