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 952351b6a..12ff43b0a 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 @@ -70,7 +70,7 @@ public final class Permission { public static String BrowseDmp = "BrowseDmp"; public static String EditDmp = "EditDmp"; public static String NewDmp = "NewDmp"; - + public static String DepositDmp = "DepositDmp"; public static String DeleteDmp = "DeleteDmp"; public static String CloneDmp = "CloneDmp"; public static String CreateNewVersionDmp = "CreateNewVersionDmp"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/ElasticConfiguration.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/ElasticConfiguration.java index 48b61bc6e..64e97c757 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/ElasticConfiguration.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/ElasticConfiguration.java @@ -33,9 +33,17 @@ public class ElasticConfiguration extends AbstractElasticConfiguration { new DmpStatusToShortConverter(), new DescriptionStatusToShortConverter(), new IsActiveToShortConverter(), - new DescriptionTemplateVersionStatusToShortConverter(), new DmpVersionStatusToShortConverter(), - new DmpAccessTypeToShortConverter() + new DmpAccessTypeToShortConverter(), + + new ShortToDmpStatusConverter(), + new ShortToDmpUserRoleConverter(), + new ShortToDescriptionTemplateVersionStatusConverter(), + new ShortToDmpStatusConverter(), + new ShortToDescriptionStatusConverter(), + new ShortToIsActiveConverter(), + new ShortToDmpVersionStatusConverter(), + new ShortToDmpAccessTypeConverter() )); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/DmpStatusToShortConverter.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/DmpStatusToShortConverter.java index fd3dbee43..31b4209f0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/DmpStatusToShortConverter.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/DmpStatusToShortConverter.java @@ -1,6 +1,5 @@ package eu.eudat.elastic.converter; -import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.DmpStatus; import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.WritingConverter; @@ -12,3 +11,4 @@ public class DmpStatusToShortConverter implements Converter { return source.getValue(); } } + diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/IsActiveToShortConverter.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/IsActiveToShortConverter.java index 8f54da448..1a3cbdcdd 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/IsActiveToShortConverter.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/IsActiveToShortConverter.java @@ -1,13 +1,14 @@ package eu.eudat.elastic.converter; import eu.eudat.commons.enums.DmpStatus; +import eu.eudat.commons.enums.IsActive; import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.WritingConverter; @WritingConverter -public class IsActiveToShortConverter implements Converter { +public class IsActiveToShortConverter implements Converter { @Override - public Short convert(DmpStatus source) { + public Short convert(IsActive source) { return source.getValue(); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDescriptionStatusConverter.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDescriptionStatusConverter.java new file mode 100644 index 000000000..5ab5dca7c --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDescriptionStatusConverter.java @@ -0,0 +1,14 @@ +package eu.eudat.elastic.converter; + +import eu.eudat.commons.enums.DescriptionStatus; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.data.convert.WritingConverter; + +@ReadingConverter +public class ShortToDescriptionStatusConverter implements Converter { + @Override + public DescriptionStatus convert(Integer source) { + return DescriptionStatus.of(source.shortValue()); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDescriptionTemplateVersionStatusConverter.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDescriptionTemplateVersionStatusConverter.java new file mode 100644 index 000000000..34f3a1b3d --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDescriptionTemplateVersionStatusConverter.java @@ -0,0 +1,14 @@ +package eu.eudat.elastic.converter; + +import eu.eudat.commons.enums.DescriptionTemplateVersionStatus; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.data.convert.WritingConverter; + +@ReadingConverter +public class ShortToDescriptionTemplateVersionStatusConverter implements Converter { + @Override + public DescriptionTemplateVersionStatus convert(Integer source) { + return DescriptionTemplateVersionStatus.of(source.shortValue()); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpAccessTypeConverter.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpAccessTypeConverter.java new file mode 100644 index 000000000..044cb872a --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpAccessTypeConverter.java @@ -0,0 +1,14 @@ +package eu.eudat.elastic.converter; + +import eu.eudat.commons.enums.DmpAccessType; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.data.convert.WritingConverter; + +@ReadingConverter +public class ShortToDmpAccessTypeConverter implements Converter { + @Override + public DmpAccessType convert(Integer source) { + return DmpAccessType.of(source.shortValue()); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpStatusConverter.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpStatusConverter.java new file mode 100644 index 000000000..ab004da6e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpStatusConverter.java @@ -0,0 +1,14 @@ +package eu.eudat.elastic.converter; + +import eu.eudat.commons.enums.*; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; + +@ReadingConverter +public class ShortToDmpStatusConverter implements Converter { + @Override + public DmpStatus convert(Integer source) { + return DmpStatus.of(source.shortValue()); + } +} + diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpUserRoleConverter.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpUserRoleConverter.java new file mode 100644 index 000000000..d96377ce3 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpUserRoleConverter.java @@ -0,0 +1,14 @@ +package eu.eudat.elastic.converter; + +import eu.eudat.commons.enums.DmpUserRole; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.data.convert.WritingConverter; + +@ReadingConverter +public class ShortToDmpUserRoleConverter implements Converter { + @Override + public DmpUserRole convert(Integer source) { + return DmpUserRole.of(source.shortValue()); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpVersionStatusConverter.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpVersionStatusConverter.java new file mode 100644 index 000000000..99e547cbf --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToDmpVersionStatusConverter.java @@ -0,0 +1,14 @@ +package eu.eudat.elastic.converter; + +import eu.eudat.commons.enums.DmpVersionStatus; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.data.convert.WritingConverter; + +@ReadingConverter +public class ShortToDmpVersionStatusConverter implements Converter { + @Override + public DmpVersionStatus convert(Integer source) { + return DmpVersionStatus.of(source.shortValue()); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToIsActiveConverter.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToIsActiveConverter.java new file mode 100644 index 000000000..efec6765c --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/converter/ShortToIsActiveConverter.java @@ -0,0 +1,14 @@ +package eu.eudat.elastic.converter; + +import eu.eudat.commons.enums.IsActive; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.data.convert.WritingConverter; + +@ReadingConverter +public class ShortToIsActiveConverter implements Converter { + @Override + public IsActive convert(Integer source) { + return IsActive.of(source.shortValue()); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java index 43b70f284..2544abf19 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java @@ -208,12 +208,12 @@ public class DescriptionPersist { .iff(() -> !this.isNull(item.getProperties())) .on(DescriptionPersist._properties) .over(item.getProperties()) - .using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus()).withDefinition(definition)), - this.navSpec() - .iff(() -> !this.isNull(item.getTags())) - .on(DescriptionPersist._tags) - .over(item.getTags()) - .using((itm) -> this.validatorFactory.validator(TagPersist.TagPersistValidator.class)) + .using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus()).withDefinition(definition)) +// this.navSpec() +// .iff(() -> !this.isNull(item.getTags())) +// .on(DescriptionPersist._tags) +// .over(item.getTags()) +// .using((itm) -> this.validatorFactory.validator(TagPersist.TagPersistValidator.class)) ); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java index d34943d89..0dc4fab0e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java @@ -103,8 +103,10 @@ public class PropertyDefinitionPersist { boolean requiredAtLeastOneFieldSet = fieldSet.getMultiplicity() != null && fieldSet.getMultiplicity().getMin() > 0; if (requiredAtLeastOneFieldSet) { if (item == null || item.getFieldSets() == null) missingMultipleFieldSets.add(fieldSet); - PropertyDefinitionFieldSetPersist fieldSetPersist = item.getFieldSets().getOrDefault(fieldSet.getId(), null); - if (fieldSetPersist == null) missingMultipleFieldSets.add(fieldSet); + if (item.getFieldSets() != null) { + PropertyDefinitionFieldSetPersist fieldSetPersist = item.getFieldSets().getOrDefault(fieldSet.getId(), null); + if (fieldSetPersist == null) missingMultipleFieldSets.add(fieldSet); + } } } 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 index a609af160..cf844c57b 100644 --- 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 @@ -2,6 +2,7 @@ package eu.eudat.service.deposit; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; +import eu.eudat.authorization.authorizationcontentresolver.AuthorizationContentResolver; import eu.eudat.commonmodels.models.FileEnvelopeModel; import eu.eudat.commonmodels.models.dmp.DmpModel; import eu.eudat.commons.enums.StorageType; @@ -69,6 +70,7 @@ public class DepositServiceImpl implements DepositService { private final ValidatorFactory validatorFactory; private final StorageFileProperties storageFileProperties; private final ConventionService conventionService; + private final AuthorizationContentResolver authorizationContentResolver; @Autowired public DepositServiceImpl(DepositProperties depositProperties, TokenExchangeCacheService tokenExchangeCacheService, @@ -77,7 +79,7 @@ public class DepositServiceImpl implements DepositService { EntityDoiService doiService, QueryFactory queryFactory, MessageSource messageSource, - BuilderFactory builderFactory, DepositConfigurationCacheService depositConfigurationCacheService, FileTransformerService fileTransformerService, StorageFileService storageFileService, UserScope userScope, ValidatorFactory validatorFactory, StorageFileProperties storageFileProperties, ConventionService conventionService) { + BuilderFactory builderFactory, DepositConfigurationCacheService depositConfigurationCacheService, FileTransformerService fileTransformerService, StorageFileService storageFileService, UserScope userScope, ValidatorFactory validatorFactory, StorageFileProperties storageFileProperties, ConventionService conventionService, AuthorizationContentResolver authorizationContentResolver) { this.depositProperties = depositProperties; this.tokenExchangeCacheService = tokenExchangeCacheService; this.authorizationService = authorizationService; @@ -93,6 +95,7 @@ public class DepositServiceImpl implements DepositService { this.validatorFactory = validatorFactory; this.storageFileProperties = storageFileProperties; this.conventionService = conventionService; + this.authorizationContentResolver = authorizationContentResolver; this.clients = new HashMap<>(); } @@ -139,9 +142,7 @@ public class DepositServiceImpl implements DepositService { @Override public EntityDoi deposit(DepositRequest dmpDepositModel) throws Exception { - this.authorizationService.authorizeForce(Permission.EditDeposit); - - this.authorizationService.authorize(Permission.EditDmp); + this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(dmpDepositModel.getDmpId())), Permission.DepositDmp); //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())); 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 419dd3be1..26617a2a0 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 @@ -380,9 +380,8 @@ public class DescriptionServiceImpl implements DescriptionService { for (DescriptionEntity description: descriptions) { DescriptionValidationResult descriptionValidationResult = new DescriptionValidationResult(description.getId(), DescriptionValidationOutput.Invalid); -// // TODO Persist DescriptionPersist.DescriptionPersistValidator validator = this.validatorFactory.validator(DescriptionPersist.DescriptionPersistValidator.class); - validator.validate(new DescriptionPersist()); + validator.validate(this.buildDescriptionPersist(description)); if (validator.result().isValid()) descriptionValidationResult.setResult(DescriptionValidationOutput.Valid);; descriptionValidationResults.add(descriptionValidationResult); @@ -836,4 +835,91 @@ public class DescriptionServiceImpl implements DescriptionService { return storageFile; } + + //region build persist + + private @NotNull DescriptionPersist buildDescriptionPersist(DescriptionEntity data){ + DescriptionPersist persist = new DescriptionPersist(); + if (data == null) return persist; + + DescriptionTemplateEntity descriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, data.getDescriptionTemplateId()); + if (descriptionTemplateEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); + + persist.setLabel(data.getLabel()); + persist.setStatus(data.getStatus()); + persist.setDescription(data.getDescription()); + persist.setDescriptionTemplateId(data.getDescriptionTemplateId()); + persist.setDmpId(data.getDmpId()); + persist.setDmpDescriptionTemplateId(data.getDmpDescriptionTemplateId()); + + eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition()); + + persist.setProperties(this.buildPropertyDefinitionPersist( this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, data.getProperties()), definition)); + + return persist; + } + + private @NotNull PropertyDefinitionPersist buildPropertyDefinitionPersist(PropertyDefinitionEntity data, eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition){ + PropertyDefinitionPersist persist = new PropertyDefinitionPersist(); + if (data == null) return persist; + if (data.getFieldSets() != null && !data.getFieldSets().isEmpty()){ + persist.setFieldSets(new HashMap<>()); + for (String key: data.getFieldSets().keySet()) { + FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null; + persist.getFieldSets().put(key, this.buildPropertyDefinitionFieldSetPersist(data.getFieldSets().get(key), fieldSetEntity)); + } + } + return persist; + } + + private @NotNull PropertyDefinitionFieldSetPersist buildPropertyDefinitionFieldSetPersist(PropertyDefinitionFieldSetEntity data, FieldSetEntity fieldSetEntity){ + PropertyDefinitionFieldSetPersist persist = new PropertyDefinitionFieldSetPersist(); + if (data == null) return persist; + if (!this.conventionService.isListNullOrEmpty(data.getItems())){ + persist.setItems(new ArrayList<>()); + for (PropertyDefinitionFieldSetItemEntity itemsPersist: data.getItems()) { + persist.getItems().add(this.buildPropertyDefinitionFieldSetItemPersist(itemsPersist, fieldSetEntity)); + } + } + return persist; + } + + private @NotNull PropertyDefinitionFieldSetItemPersist buildPropertyDefinitionFieldSetItemPersist(PropertyDefinitionFieldSetItemEntity data, FieldSetEntity fieldSetEntity){ + PropertyDefinitionFieldSetItemPersist persist = new PropertyDefinitionFieldSetItemPersist(); + if (data == null) return persist; + if (data.getFields() != null && !data.getFields().isEmpty()){ + persist.setOrdinal(data.getOrdinal()); + persist.setComment(data.getComment()); + persist.setFields(new HashMap<>()); + for (String key: data.getFields().keySet()) { + eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null; + persist.getFields().put(key, this.buildFieldPersist(data.getFields().get(key), fieldEntity)); + } + } + return persist; + } + + private @NotNull FieldPersist buildFieldPersist(FieldEntity data, eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity) { + FieldType fieldType = fieldEntity != null && fieldEntity.getData() != null ? fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT; + + FieldPersist persist = new FieldPersist(); + if (data == null) return persist; + + if (FieldType.isTextType(fieldType)) persist.setTextValue(data.getTextValue()); + else if (FieldType.isTextListType(fieldType)) persist.setTextListValue(data.getTextListValue()); + else if (FieldType.isDateType(fieldType)) persist.setDateValue(persist.getDateValue()); + else if (FieldType.isExternalIdentifierType(fieldType) && data.getExternalIdentifier() != null) persist.setExternalIdentifier(this.buildExternalIdentifierPersist(data.getExternalIdentifier())); + else if (FieldType.isReferenceType(fieldType) && fieldEntity != null ) persist.setTextListValue(data.getTextListValue()); + + return persist; + } + + private @NotNull ExternalIdentifierPersist buildExternalIdentifierPersist(ExternalIdentifierEntity data){ + ExternalIdentifierPersist persist = new ExternalIdentifierPersist(); + if (data == null) return persist; + + persist.setIdentifier(data.getIdentifier()); + persist.setType(data.getType()); + return persist; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java index b11b7d16a..77a874889 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java @@ -836,6 +836,9 @@ public class DmpServiceImpl implements DmpService { if (description.getStatus().equals(DescriptionStatus.Finalized)){ throw new MyApplicationException("Description is already finalized"); } + if (this.descriptionService.validate(List.of(description.getId())).get(0).getResult().equals(DescriptionValidationOutput.Invalid)){ + throw new MyApplicationException("Description is invalid"); + } description.setStatus(DescriptionStatus.Finalized); description.setUpdatedAt(Instant.now()); description.setFinalizedAt(Instant.now()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticServiceImpl.java index c35428ca5..b7c6be0d0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticServiceImpl.java @@ -284,11 +284,14 @@ public class ElasticServiceImpl implements ElasticService { public void deleteDmp(DmpEntity dmp) throws IOException { if (!this.enabled()) return; this.ensureIndexes(); - - this.elasticsearchTemplate.delete(dmp.getId(), IndexCoordinates.of(this.appElasticProperties.getDmpIndexName())); + DmpElasticEntity dmpElasticEntity = this.elasticsearchTemplate.get(dmp.getId().toString(),DmpElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName())); + if (dmpElasticEntity == null) return; + this.elasticsearchTemplate.delete(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName())); List descriptions = this.queryFactory.query(DescriptionQuery.class).dmpSubQuery(this.queryFactory.query(DmpQuery.class).ids(dmp.getId())).collectAs(new BaseFieldSet().ensure(Description._id)); for (DescriptionEntity description: descriptions) { - this.elasticsearchTemplate.delete(description.getId(), IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName())); + DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName())); + if (descriptionElasticEntity == null) continue; + this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName())); } } @@ -312,7 +315,10 @@ public class ElasticServiceImpl implements ElasticService { if (!this.enabled()) return; this.ensureIndexes(); - this.elasticsearchTemplate.delete(description.getId(), IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName())); + DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName())); + if (descriptionElasticEntity == null) return; + this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName())); + DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, description.getDmpId()); if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (dmpEntity.getIsActive().equals(IsActive.Active)) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/cache/transformer/FileTransformerConfigurationCache.java b/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerConfigurationCache.java similarity index 94% rename from dmp-backend/core/src/main/java/eu/eudat/cache/transformer/FileTransformerConfigurationCache.java rename to dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerConfigurationCache.java index cff46434e..6158cc438 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/cache/transformer/FileTransformerConfigurationCache.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerConfigurationCache.java @@ -1,4 +1,4 @@ -package eu.eudat.cache.transformer; +package eu.eudat.service.transformer; import eu.eudat.configurations.deposit.DepositCacheOptions; diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerServiceImpl.java index a03851d47..dff99f04b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerServiceImpl.java @@ -2,7 +2,6 @@ package eu.eudat.service.transformer; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; -import eu.eudat.cache.transformer.FileTransformerConfigurationCache; import eu.eudat.commonmodels.models.FileEnvelopeModel; import eu.eudat.commonmodels.models.description.DescriptionModel; import eu.eudat.commonmodels.models.dmp.DmpModel; diff --git a/dmp-backend/core/src/main/java/eu/eudat/utilities/pdf/PDFUtils.java b/dmp-backend/core/src/main/java/eu/eudat/utilities/pdf/PDFUtils.java deleted file mode 100644 index 05ffb9d3b..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/utilities/pdf/PDFUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -//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/pom.xml b/dmp-backend/pom.xml index 22e63c0f7..2d0d0bf65 100644 --- a/dmp-backend/pom.xml +++ b/dmp-backend/pom.xml @@ -56,7 +56,7 @@ org.elasticsearch elasticsearch - 7.7.0 + 8.5.2 org.apache.httpcomponents @@ -412,6 +412,19 @@ + + cite-dev + + + cite-maven + CITE Maven Repository + https://crepo.cite.gr/repository/cite-maven/ + + + + true + + \ 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 2d15c8612..d1ae62801 100644 --- a/dmp-backend/web/src/main/resources/config/permissions.yml +++ b/dmp-backend/web/src/main/resources/config/permissions.yml @@ -387,6 +387,19 @@ permissions: clients: [ ] allowAnonymous: false allowAuthenticated: false + DepositDmp: + roles: + - Admin + dmp: + roles: + - Owner + - User + - DescriptionContributor + - Reviewer + claims: [ ] + clients: [ ] + allowAnonymous: false + allowAuthenticated: false CloneDmp: roles: - Admin diff --git a/dmp-frontend/src/app/core/common/enum/permission.enum.ts b/dmp-frontend/src/app/core/common/enum/permission.enum.ts index 6051f9205..a2c6c01f0 100644 --- a/dmp-frontend/src/app/core/common/enum/permission.enum.ts +++ b/dmp-frontend/src/app/core/common/enum/permission.enum.ts @@ -20,7 +20,8 @@ export enum AppPermission { BrowseDmp = "BrowseDmp", EditDmp = "EditDmp", NewDmp = "NewDmp", - DeleteDmp= "DeleteDmp", + DeleteDmp = "DeleteDmp", + DepositDmp = "DepositDmp", CloneDmp = "CloneDmp", CreateNewVersionDmp = "CreateNewVersionDmp", ExportDmp = "ExportDmp", diff --git a/dmp-frontend/src/app/core/services/dmp/dmp.service.ts b/dmp-frontend/src/app/core/services/dmp/dmp.service.ts index 772eff79a..736061c39 100644 --- a/dmp-frontend/src/app/core/services/dmp/dmp.service.ts +++ b/dmp-frontend/src/app/core/services/dmp/dmp.service.ts @@ -248,8 +248,4 @@ export class DmpService { } return dmpUserRoles; } - - isDmpOwner(dmpUsers: DmpUser[]): Boolean { - return this.getCurrentUserRolesInDmp(dmpUsers).includes(DmpUserRole.Owner); - } } diff --git a/dmp-frontend/src/app/ui/dmp/dmp-finalize-dialog/dmp-finalize-dialog.component.html b/dmp-frontend/src/app/ui/dmp/dmp-finalize-dialog/dmp-finalize-dialog.component.html index 9316e8c3a..1eec22dd5 100644 --- a/dmp-frontend/src/app/ui/dmp/dmp-finalize-dialog/dmp-finalize-dialog.component.html +++ b/dmp-frontend/src/app/ui/dmp/dmp-finalize-dialog/dmp-finalize-dialog.component.html @@ -36,7 +36,7 @@ : {{ description.label }} - +

{{ description.label }}

diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html index b858194f5..f1a42138e 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html @@ -144,8 +144,8 @@
- -
+ +
diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts index feaf3f4f4..235390a54 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts @@ -121,7 +121,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { if (this.dmp.descriptions) { if (this.dmp.status == DmpStatus.Finalized) { this.dmp.descriptions = data.descriptions.filter(x => x.isActive === IsActive.Active && x.status === DescriptionStatus.Finalized); - } else { + } else { this.dmp.descriptions = data.descriptions.filter(x => x.isActive === IsActive.Active && x.status !== DescriptionStatus.Canceled); } } @@ -202,11 +202,6 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { } else return false; } - isDmpOwner(): boolean { - const principalId: Guid = this.authentication.userId(); - if (principalId) return !!this.dmp.dmpUsers?.find(x => (x.role === DmpUserRole.Owner) && (principalId === x.user?.id)); - } - canEditDmp(): boolean{ return (this.isDraftDmp()) && (this.dmp.authorizationFlags?.some(x => x === AppPermission.EditDmp) || this.authentication.hasPermission(AppPermission.EditDmp)) && this.isPublicView == false; } @@ -239,6 +234,11 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { return this.dmp.authorizationFlags?.some(x => x === AppPermission.AssignDmpUsers) || this.authentication.hasPermission(AppPermission.AssignDmpUsers) && this.isPublicView == false; } + canDepositDmp(): boolean { + return this.dmp.authorizationFlags?.some(x => x === AppPermission.DepositDmp) || this.authentication.hasPermission(AppPermission.DepositDmp) && this.isPublicView == false; + } + + editClicked() { this.router.navigate(['/plans/edit/', this.dmp.id]); } @@ -741,6 +741,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { [nameof(x => x.authorizationFlags), AppPermission.InviteDmpUsers].join('.'), [nameof(x => x.authorizationFlags), AppPermission.AssignDmpUsers].join('.'), [nameof(x => x.authorizationFlags), AppPermission.EditDmp].join('.'), + [nameof(x => x.authorizationFlags), AppPermission.DepositDmp].join('.'), [nameof(x => x.entityDois), nameof(x => x.id)].join('.'), [nameof(x => x.entityDois), nameof(x => x.repositoryId)].join('.'), [nameof(x => x.entityDois), nameof(x => x.doi)].join('.'),