Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-04-30 11:06:45 +03:00
commit bb206125a6
11 changed files with 112 additions and 119 deletions

View File

@ -27,7 +27,7 @@ queue:
exchange: null exchange: null
rabbitmq: rabbitmq:
enable: false enable: false
interval-seconds: 30 interval-seconds: 3
options: options:
retry-threashold: 100 retry-threashold: 100
retry-delay-step-seconds: 300 retry-delay-step-seconds: 300
@ -46,7 +46,7 @@ queue:
annotation-entities-removal-topic: annotation.entities.remove annotation-entities-removal-topic: annotation.entities.remove
rabbitmq: rabbitmq:
enable: false enable: false
interval-seconds: 30 interval-seconds: 3
options: options:
retry-threashold: 100 retry-threashold: 100
retry-delay-step-seconds: 300 retry-delay-step-seconds: 300

View File

@ -1,10 +1,10 @@
package org.opencdmp.data; package org.opencdmp.data;
import jakarta.persistence.*;
import org.opencdmp.commons.enums.StorageType; import org.opencdmp.commons.enums.StorageType;
import org.opencdmp.data.converters.enums.StorageTypeConverter; import org.opencdmp.data.converters.enums.StorageTypeConverter;
import org.opencdmp.data.tenant.TenantScopedBaseEntity; import org.opencdmp.data.tenant.TenantScopedBaseEntity;
import jakarta.persistence.*;
import java.time.Instant; import java.time.Instant;
import java.util.UUID; import java.util.UUID;
@ -60,7 +60,7 @@ public class StorageFileEntity extends TenantScopedBaseEntity {
public final static String _ownerId = "ownerId"; public final static String _ownerId = "ownerId";
public UUID getId() { public UUID getId() {
return id; return this.id;
} }
public void setId(UUID id) { public void setId(UUID id) {
@ -68,7 +68,7 @@ public class StorageFileEntity extends TenantScopedBaseEntity {
} }
public String getFileRef() { public String getFileRef() {
return fileRef; return this.fileRef;
} }
public void setFileRef(String fileRef) { public void setFileRef(String fileRef) {
@ -76,7 +76,7 @@ public class StorageFileEntity extends TenantScopedBaseEntity {
} }
public String getName() { public String getName() {
return name; return this.name;
} }
public void setName(String name) { public void setName(String name) {
@ -84,7 +84,7 @@ public class StorageFileEntity extends TenantScopedBaseEntity {
} }
public String getExtension() { public String getExtension() {
return extension; return this.extension;
} }
public void setExtension(String extension) { public void setExtension(String extension) {
@ -92,7 +92,7 @@ public class StorageFileEntity extends TenantScopedBaseEntity {
} }
public String getMimeType() { public String getMimeType() {
return mimeType; return this.mimeType;
} }
public void setMimeType(String mimeType) { public void setMimeType(String mimeType) {
@ -100,7 +100,7 @@ public class StorageFileEntity extends TenantScopedBaseEntity {
} }
public StorageType getStorageType() { public StorageType getStorageType() {
return storageType; return this.storageType;
} }
public void setStorageType(StorageType storageType) { public void setStorageType(StorageType storageType) {
@ -109,7 +109,7 @@ public class StorageFileEntity extends TenantScopedBaseEntity {
public Instant getCreatedAt() { public Instant getCreatedAt() {
return createdAt; return this.createdAt;
} }
public void setCreatedAt(Instant createdAt) { public void setCreatedAt(Instant createdAt) {
@ -117,7 +117,7 @@ public class StorageFileEntity extends TenantScopedBaseEntity {
} }
public Instant getPurgeAt() { public Instant getPurgeAt() {
return purgeAt; return this.purgeAt;
} }
public void setPurgeAt(Instant purgeAt) { public void setPurgeAt(Instant purgeAt) {
@ -125,7 +125,7 @@ public class StorageFileEntity extends TenantScopedBaseEntity {
} }
public Instant getPurgedAt() { public Instant getPurgedAt() {
return purgedAt; return this.purgedAt;
} }
public void setPurgedAt(Instant purgedAt) { public void setPurgedAt(Instant purgedAt) {
@ -133,7 +133,7 @@ public class StorageFileEntity extends TenantScopedBaseEntity {
} }
public UUID getOwnerId() { public UUID getOwnerId() {
return ownerId; return this.ownerId;
} }
public void setOwnerId(UUID ownerId) { public void setOwnerId(UUID ownerId) {

View File

@ -5,7 +5,6 @@ import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.tenant.TenantScoped; import org.opencdmp.commons.scope.tenant.TenantScoped;
import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.opencdmp.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.exception.MyForbiddenException; import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.PrePersist; import jakarta.persistence.PrePersist;
import jakarta.persistence.PreRemove; import jakarta.persistence.PreRemove;

View File

@ -1,5 +1,12 @@
package org.opencdmp.query; package org.opencdmp.query;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission; import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
@ -9,18 +16,10 @@ import org.opencdmp.data.DescriptionReferenceEntity;
import org.opencdmp.data.DmpEntity; import org.opencdmp.data.DmpEntity;
import org.opencdmp.data.DmpReferenceEntity; import org.opencdmp.data.DmpReferenceEntity;
import org.opencdmp.data.ReferenceEntity; import org.opencdmp.data.ReferenceEntity;
import org.opencdmp.model.DescriptionReference;
import org.opencdmp.model.PublicReference; import org.opencdmp.model.PublicReference;
import org.opencdmp.model.Reference; import org.opencdmp.model.Reference;
import org.opencdmp.query.utils.BuildSubQueryInput; import org.opencdmp.query.utils.BuildSubQueryInput;
import org.opencdmp.query.utils.QueryUtilsService; import org.opencdmp.query.utils.QueryUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -29,7 +28,7 @@ import java.time.Instant;
import java.util.*; import java.util.*;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ReferenceQuery extends QueryBase<ReferenceEntity> { public class ReferenceQuery extends QueryBase<ReferenceEntity> {
private String like; private String like;
@ -219,20 +218,20 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
if (userId != null || usePublic) { if (userId != null || usePublic) {
predicates.add(queryContext.CriteriaBuilder.or( predicates.add(queryContext.CriteriaBuilder.or(
userId != null ? queryContext.CriteriaBuilder.equal(queryContext.Root.get(ReferenceEntity._createdById), userId) : queryContext.CriteriaBuilder.or(), //Creates a false query userId != null ? queryContext.CriteriaBuilder.equal(queryContext.Root.get(ReferenceEntity._createdById), userId) : queryContext.CriteriaBuilder.or(), //Creates a false query
queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id)).value(queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DmpReferenceEntity.class, UUID.class) queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id)).value(this.queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DmpReferenceEntity.class, UUID.class)
.query(queryContext.Query) .query(queryContext.Query)
.criteriaBuilder(queryContext.CriteriaBuilder) .criteriaBuilder(queryContext.CriteriaBuilder)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpReferenceEntity._referenceId)) .keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpReferenceEntity._referenceId))
.filterFunc((subQueryRoot, cb) -> .filterFunc((subQueryRoot, cb) ->
cb.in(subQueryRoot.get(DmpReferenceEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)) cb.in(subQueryRoot.get(DmpReferenceEntity._dmpId)).value(this.queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic))
) )
))), ))),
queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id)).value(queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DescriptionReferenceEntity.class, UUID.class) queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id)).value(this.queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DescriptionReferenceEntity.class, UUID.class)
.query(queryContext.Query) .query(queryContext.Query)
.criteriaBuilder(queryContext.CriteriaBuilder) .criteriaBuilder(queryContext.CriteriaBuilder)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DescriptionReferenceEntity._referenceId)) .keyPathFunc((subQueryRoot) -> subQueryRoot.get(DescriptionReferenceEntity._referenceId))
.filterFunc((subQueryRoot, cb) -> .filterFunc((subQueryRoot, cb) ->
cb.in(subQueryRoot.get(DescriptionReferenceEntity._descriptionId)).value(queryUtilsService.buildDescriptionAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)) cb.in(subQueryRoot.get(DescriptionReferenceEntity._descriptionId)).value(this.queryUtilsService.buildDescriptionAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic))
) )
))) )))
)); ));
@ -255,9 +254,9 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
predicates.add(inClause); predicates.add(inClause);
} }
if (this.like != null && !this.like.isEmpty()) { if (this.like != null && !this.like.isEmpty()) {
predicates.add(queryContext.CriteriaBuilder.or(queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(ReferenceEntity._label), this.like), predicates.add(queryContext.CriteriaBuilder.or(this.queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(ReferenceEntity._label), this.like),
queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(ReferenceEntity._description), this.like), this.queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(ReferenceEntity._description), this.like),
queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(ReferenceEntity._reference), this.like) this.queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(ReferenceEntity._reference), this.like)
)); ));
} }
if (this.isActives != null) { if (this.isActives != null) {

View File

@ -1,5 +1,19 @@
package org.opencdmp.service.description; package org.opencdmp.service.description;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.Ordering;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.*;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidatorFactory;
import jakarta.xml.bind.JAXBException;
import org.apache.commons.io.FilenameUtils;
import org.jetbrains.annotations.NotNull;
import org.opencdmp.authorization.AffiliatedResource; import org.opencdmp.authorization.AffiliatedResource;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission; import org.opencdmp.authorization.Permission;
@ -7,6 +21,7 @@ import org.opencdmp.authorization.authorizationcontentresolver.AuthorizationCont
import org.opencdmp.commons.JsonHandlingService; import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService; import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.*; import org.opencdmp.commons.enums.*;
import org.opencdmp.commons.notification.NotificationProperties;
import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope; import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.commons.types.description.*; import org.opencdmp.commons.types.description.*;
@ -15,12 +30,8 @@ import org.opencdmp.commons.types.descriptionreference.DescriptionReferenceDataE
import org.opencdmp.commons.types.descriptiontemplate.FieldSetEntity; import org.opencdmp.commons.types.descriptiontemplate.FieldSetEntity;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.UploadDataEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.UploadDataEntity;
import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity;
import org.opencdmp.commons.types.dmp.DmpContactEntity;
import org.opencdmp.commons.types.dmp.importexport.*;
import org.opencdmp.commons.types.notification.*; import org.opencdmp.commons.types.notification.*;
import org.opencdmp.commons.types.reference.DefinitionEntity; import org.opencdmp.commons.types.reference.DefinitionEntity;
import org.opencdmp.commons.notification.NotificationProperties;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.*; import org.opencdmp.data.*;
import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.opencdmp.errorcode.ErrorThesaurusProperties;
@ -43,24 +54,10 @@ import org.opencdmp.model.persist.referencedefinition.DefinitionPersist;
import org.opencdmp.query.*; import org.opencdmp.query.*;
import org.opencdmp.service.descriptiontemplate.DescriptionTemplateService; import org.opencdmp.service.descriptiontemplate.DescriptionTemplateService;
import org.opencdmp.service.elastic.ElasticService; import org.opencdmp.service.elastic.ElasticService;
import org.opencdmp.service.filetransformer.FileTransformerService;
import org.opencdmp.service.responseutils.ResponseUtilsService; import org.opencdmp.service.responseutils.ResponseUtilsService;
import org.opencdmp.service.storage.StorageFileProperties; import org.opencdmp.service.storage.StorageFileProperties;
import org.opencdmp.service.storage.StorageFileService; import org.opencdmp.service.storage.StorageFileService;
import org.opencdmp.service.filetransformer.FileTransformerService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.Ordering;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.*;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidatorFactory;
import jakarta.xml.bind.JAXBException;
import org.apache.commons.io.FilenameUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
@ -510,13 +507,13 @@ public class DescriptionServiceImpl implements DescriptionService {
if (FieldType.UPLOAD.equals(fieldType)){ if (FieldType.UPLOAD.equals(fieldType)){
UUID newFileId = this.conventionService.isValidUUID(persist.getTextValue()) ? UUID.fromString(persist.getTextValue()) : null; UUID newFileId = this.conventionService.isValidUUID(persist.getTextValue()) ? UUID.fromString(persist.getTextValue()) : null;
if (newFileId != null){ if (newFileId != null){
StorageFileEntity existingFile = this.queryFactory.query(StorageFileQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(newFileId).firstAs(new BaseFieldSet().ensure(StorageFile._id)); StorageFileEntity storageFileEntity = this.queryFactory.query(StorageFileQuery.class).ids(newFileId).firstAs(new BaseFieldSet().ensure(StorageFile._id).ensure(StorageFile._storageType));
if (existingFile == null){ if (storageFileEntity == null || storageFileEntity.getStorageType().equals(StorageType.Temp)){
StorageFile storageFile = this.storageFileService.copyToStorage(newFileId, StorageType.Main, true, new BaseFieldSet().ensure(StorageFile._id)); StorageFile storageFile = this.storageFileService.copyToStorage(newFileId, StorageType.Main, true, new BaseFieldSet().ensure(StorageFile._id));
this.storageFileService.updatePurgeAt(storageFile.getId(), null); this.storageFileService.updatePurgeAt(storageFile.getId(), null);
data.setTextValue(storageFile.getId().toString()); data.setTextValue(storageFile.getId().toString());
} else { } else {
if (existingFile.getId() != null){ if (storageFileEntity.getId() != null){
//DO NOT Remove we can not be sure uf the description is copied //DO NOT Remove we can not be sure uf the description is copied
//this.storageFileService.updatePurgeAt(existingFileId, Instant.now().minusSeconds(60)); //this.storageFileService.updatePurgeAt(existingFileId, Instant.now().minusSeconds(60));
} }

View File

@ -1,30 +1,6 @@
package org.opencdmp.service.dmpblueprint; package org.opencdmp.service.dmpblueprint;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.*;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.types.dmpblueprint.*;
import org.opencdmp.commons.types.dmpblueprint.importexport.*;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DmpBlueprintEntity;
import org.opencdmp.data.DmpEntity;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.model.DmpBlueprint;
import org.opencdmp.model.builder.DmpBlueprintBuilder;
import org.opencdmp.model.deleter.DmpBlueprintDeleter;
import org.opencdmp.model.dmpblueprintdefinition.Definition;
import org.opencdmp.model.dmpblueprintdefinition.Field;
import org.opencdmp.model.dmpblueprintdefinition.Section;
import org.opencdmp.model.persist.DmpBlueprintPersist;
import org.opencdmp.model.persist.NewVersionDmpBlueprintPersist;
import org.opencdmp.model.persist.dmpblueprintdefinition.*;
import org.opencdmp.query.DmpBlueprintQuery;
import org.opencdmp.query.DmpQuery;
import org.opencdmp.service.responseutils.ResponseUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.deleter.DeleterFactory;
@ -40,6 +16,28 @@ import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.ValidatorFactory;
import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.*;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.types.dmpblueprint.*;
import org.opencdmp.commons.types.dmpblueprint.importexport.*;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DmpBlueprintEntity;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.model.DmpBlueprint;
import org.opencdmp.model.builder.DmpBlueprintBuilder;
import org.opencdmp.model.deleter.DmpBlueprintDeleter;
import org.opencdmp.model.dmpblueprintdefinition.Definition;
import org.opencdmp.model.dmpblueprintdefinition.Field;
import org.opencdmp.model.dmpblueprintdefinition.Section;
import org.opencdmp.model.persist.DmpBlueprintPersist;
import org.opencdmp.model.persist.NewVersionDmpBlueprintPersist;
import org.opencdmp.model.persist.dmpblueprintdefinition.*;
import org.opencdmp.query.DmpBlueprintQuery;
import org.opencdmp.service.responseutils.ResponseUtilsService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;

View File

@ -18,22 +18,22 @@ public class Field {
private final ExternalIdentifier externalIdentifier; private final ExternalIdentifier externalIdentifier;
public String getTextValue() { public String getTextValue() {
return textValue; return this.textValue;
} }
public List<String> getTextListValue() { public List<String> getTextListValue() {
return textListValue; return this.textListValue;
} }
public Instant getDateValue() { public Instant getDateValue() {
return dateValue; return this.dateValue;
} }
public ExternalIdentifier getExternalIdentifier() { public ExternalIdentifier getExternalIdentifier() {
return externalIdentifier; return this.externalIdentifier;
} }

View File

@ -27,13 +27,13 @@ public class VisibilityServiceImpl implements VisibilityService {
private void initRules(){ private void initRules(){
if (this.rulesBySources != null) return; if (this.rulesBySources != null) return;
rulesBySources = new HashMap<>(); this.rulesBySources = new HashMap<>();
for (FieldEntity fieldEntity : this.definition.getAllField()){ for (FieldEntity fieldEntity : this.definition.getAllField()){
if (fieldEntity.getVisibilityRules() != null && !fieldEntity.getVisibilityRules().isEmpty()) { if (fieldEntity.getVisibilityRules() != null && !fieldEntity.getVisibilityRules().isEmpty()) {
for (RuleEntity rule : fieldEntity.getVisibilityRules()){ for (RuleEntity rule : fieldEntity.getVisibilityRules()){
if (!rulesBySources.containsKey(fieldEntity.getId())) rulesBySources.put(fieldEntity.getId(), new ArrayList<>()); if (!this.rulesBySources.containsKey(fieldEntity.getId())) this.rulesBySources.put(fieldEntity.getId(), new ArrayList<>());
RuleWithTarget ruleWithTarget = new RuleWithTarget(fieldEntity.getId(), rule, fieldEntity); RuleWithTarget ruleWithTarget = new RuleWithTarget(fieldEntity.getId(), rule, fieldEntity);
rulesBySources.get(fieldEntity.getId()).add(ruleWithTarget); this.rulesBySources.get(fieldEntity.getId()).add(ruleWithTarget);
} }
} }
} }
@ -49,11 +49,11 @@ public class VisibilityServiceImpl implements VisibilityService {
@Override @Override
public Map<FieldKey, Boolean> getVisibilityStates() { public Map<FieldKey, Boolean> getVisibilityStates() {
this.calculateVisibility(); this.calculateVisibility();
return visibility; return this.visibility;
} }
private void calculateVisibility(){ private void calculateVisibility(){
if (visibility != null) return; if (this.visibility != null) return;
this.initRules(); this.initRules();
this.buildTargetVisibility(); this.buildTargetVisibility();
@ -63,11 +63,11 @@ public class VisibilityServiceImpl implements VisibilityService {
} }
private void buildTargetVisibility(){ private void buildTargetVisibility(){
visibility = new HashMap<>(); this.visibility = new HashMap<>();
for (Map.Entry<String, List<RuleWithTarget>> ruleForSource : rulesBySources.entrySet()){ for (Map.Entry<String, List<RuleWithTarget>> ruleForSource : this.rulesBySources.entrySet()){
for (RuleWithTarget rule : ruleForSource.getValue()){ for (RuleWithTarget rule : ruleForSource.getValue()){
if (propertyDefinition.getFieldSets() != null && !propertyDefinition.getFieldSets().isEmpty()){ if (this.propertyDefinition.getFieldSets() != null && !this.propertyDefinition.getFieldSets().isEmpty()){
for (PropertyDefinitionFieldSet propertyDefinitionFieldSet: propertyDefinition.getFieldSets().values()) { for (PropertyDefinitionFieldSet propertyDefinitionFieldSet: this.propertyDefinition.getFieldSets().values()) {
if (propertyDefinitionFieldSet.getItems() != null && !propertyDefinitionFieldSet.getItems().isEmpty()) { if (propertyDefinitionFieldSet.getItems() != null && !propertyDefinitionFieldSet.getItems().isEmpty()) {
for (PropertyDefinitionFieldSetItem definitionFieldSetItem : propertyDefinitionFieldSet.getItems()) { for (PropertyDefinitionFieldSetItem definitionFieldSetItem : propertyDefinitionFieldSet.getItems()) {
if (definitionFieldSetItem.getFields() != null && !definitionFieldSetItem.getFields().isEmpty()) { if (definitionFieldSetItem.getFields() != null && !definitionFieldSetItem.getFields().isEmpty()) {
@ -78,18 +78,18 @@ public class VisibilityServiceImpl implements VisibilityService {
if (definitionFieldSetItem.getFields().containsKey(rule.getTarget())){ //Rule applies only for current multiple item if (definitionFieldSetItem.getFields().containsKey(rule.getTarget())){ //Rule applies only for current multiple item
FieldKey fieldKey = new FieldKey(rule.getTarget(), definitionFieldSetItem.getOrdinal()); FieldKey fieldKey = new FieldKey(rule.getTarget(), definitionFieldSetItem.getOrdinal());
boolean currentState = this.visibility.getOrDefault(fieldKey, false); boolean currentState = this.visibility.getOrDefault(fieldKey, false);
this.visibility.put(fieldKey, currentState || ruleIsTrue(rule, field)); this.visibility.put(fieldKey, currentState || this.ruleIsTrue(rule, field));
} else if (!this.definition.getFieldById(rule.getTarget()).isEmpty() || !this.definition.getFieldSetById(rule.getTarget()).isEmpty()) { //Rule applies to different fieldset, so we apply for all multiple items } else if (!this.definition.getFieldById(rule.getTarget()).isEmpty() || !this.definition.getFieldSetById(rule.getTarget()).isEmpty()) { //Rule applies to different fieldset, so we apply for all multiple items
List<Integer> ordinals = this.getKeyOrdinals(rule.getTarget()); List<Integer> ordinals = this.getKeyOrdinals(rule.getTarget());
for (Integer ordinal : ordinals){ for (Integer ordinal : ordinals){
FieldKey fieldKey = new FieldKey(rule.getTarget(), ordinal); FieldKey fieldKey = new FieldKey(rule.getTarget(), ordinal);
boolean currentState = this.visibility.getOrDefault(fieldKey, false); boolean currentState = this.visibility.getOrDefault(fieldKey, false);
this.visibility.put(fieldKey, currentState || ruleIsTrue(rule, field)); this.visibility.put(fieldKey, currentState || this.ruleIsTrue(rule, field));
} }
} else { } else {
FieldKey fieldKey = new FieldKey(rule.getTarget(), null); //Ordinal is null if target not on field FieldKey fieldKey = new FieldKey(rule.getTarget(), null); //Ordinal is null if target not on field
boolean currentState = this.visibility.getOrDefault(fieldKey, false); boolean currentState = this.visibility.getOrDefault(fieldKey, false);
this.visibility.put(fieldKey, currentState || ruleIsTrue(rule, field)); this.visibility.put(fieldKey, currentState || this.ruleIsTrue(rule, field));
} }
} }
} }
@ -103,8 +103,8 @@ public class VisibilityServiceImpl implements VisibilityService {
} }
private List<Integer> getKeyOrdinals(String key){ private List<Integer> getKeyOrdinals(String key){
if (propertyDefinition.getFieldSets() != null && !propertyDefinition.getFieldSets().isEmpty()){ if (this.propertyDefinition.getFieldSets() != null && !this.propertyDefinition.getFieldSets().isEmpty()){
for (Map.Entry<String, PropertyDefinitionFieldSet> propertyDefinitionFieldSet: propertyDefinition.getFieldSets().entrySet()) { for (Map.Entry<String, PropertyDefinitionFieldSet> propertyDefinitionFieldSet: this.propertyDefinition.getFieldSets().entrySet()) {
if (propertyDefinitionFieldSet.getKey().equals(key)) return propertyDefinitionFieldSet.getValue().getItems().stream().map(PropertyDefinitionFieldSetItem::getOrdinal).toList(); if (propertyDefinitionFieldSet.getKey().equals(key)) return propertyDefinitionFieldSet.getValue().getItems().stream().map(PropertyDefinitionFieldSetItem::getOrdinal).toList();
if (propertyDefinitionFieldSet.getValue() != null && propertyDefinitionFieldSet.getValue().getItems() != null && !propertyDefinitionFieldSet.getValue().getItems().isEmpty()) { if (propertyDefinitionFieldSet.getValue() != null && propertyDefinitionFieldSet.getValue().getItems() != null && !propertyDefinitionFieldSet.getValue().getItems().isEmpty()) {
@ -168,8 +168,8 @@ public class VisibilityServiceImpl implements VisibilityService {
} }
if (sectionEntity.getFieldSets() != null) { if (sectionEntity.getFieldSets() != null) {
for (FieldSetEntity fieldSetEntity : sectionEntity.getFieldSets()) { for (FieldSetEntity fieldSetEntity : sectionEntity.getFieldSets()) {
if (propertyDefinition.getFieldSets() != null && !propertyDefinition.getFieldSets().isEmpty()){ if (this.propertyDefinition.getFieldSets() != null && !this.propertyDefinition.getFieldSets().isEmpty()){
PropertyDefinitionFieldSet propertyDefinitionFieldSet = propertyDefinition.getFieldSets().getOrDefault(fieldSetEntity.getId(), null); PropertyDefinitionFieldSet propertyDefinitionFieldSet = this.propertyDefinition.getFieldSets().getOrDefault(fieldSetEntity.getId(), null);
if (propertyDefinitionFieldSet != null && propertyDefinitionFieldSet.getItems() != null && !propertyDefinitionFieldSet.getItems().isEmpty()) { if (propertyDefinitionFieldSet != null && propertyDefinitionFieldSet.getItems() != null && !propertyDefinitionFieldSet.getItems().isEmpty()) {
for (PropertyDefinitionFieldSetItem definitionFieldSetItem : propertyDefinitionFieldSet.getItems()) { for (PropertyDefinitionFieldSetItem definitionFieldSetItem : propertyDefinitionFieldSet.getItems()) {
FieldKey fieldKey = new FieldKey(fieldSetEntity.getId(), definitionFieldSetItem.getOrdinal()); FieldKey fieldKey = new FieldKey(fieldSetEntity.getId(), definitionFieldSetItem.getOrdinal());
@ -244,8 +244,8 @@ public class VisibilityServiceImpl implements VisibilityService {
} }
if (sectionEntity.getFieldSets() != null) { if (sectionEntity.getFieldSets() != null) {
for (FieldSetEntity fieldSetEntity : sectionEntity.getFieldSets()) { for (FieldSetEntity fieldSetEntity : sectionEntity.getFieldSets()) {
if (propertyDefinition.getFieldSets() != null && !propertyDefinition.getFieldSets().isEmpty()){ if (this.propertyDefinition.getFieldSets() != null && !this.propertyDefinition.getFieldSets().isEmpty()){
PropertyDefinitionFieldSet propertyDefinitionFieldSet = propertyDefinition.getFieldSets().getOrDefault(fieldSetEntity.getId(), null); PropertyDefinitionFieldSet propertyDefinitionFieldSet = this.propertyDefinition.getFieldSets().getOrDefault(fieldSetEntity.getId(), null);
if (propertyDefinitionFieldSet != null && propertyDefinitionFieldSet.getItems() != null && !propertyDefinitionFieldSet.getItems().isEmpty()) { if (propertyDefinitionFieldSet != null && propertyDefinitionFieldSet.getItems() != null && !propertyDefinitionFieldSet.getItems().isEmpty()) {
for (PropertyDefinitionFieldSetItem definitionFieldSetItem : propertyDefinitionFieldSet.getItems()) { for (PropertyDefinitionFieldSetItem definitionFieldSetItem : propertyDefinitionFieldSet.getItems()) {
FieldKey fieldKey = new FieldKey(fieldSetEntity.getId(), definitionFieldSetItem.getOrdinal()); FieldKey fieldKey = new FieldKey(fieldSetEntity.getId(), definitionFieldSetItem.getOrdinal());
@ -313,8 +313,8 @@ public class VisibilityServiceImpl implements VisibilityService {
} }
if (sectionEntity.getFieldSets() != null) { if (sectionEntity.getFieldSets() != null) {
for (FieldSetEntity fieldSetEntity : sectionEntity.getFieldSets()) { for (FieldSetEntity fieldSetEntity : sectionEntity.getFieldSets()) {
if (propertyDefinition.getFieldSets() != null && !propertyDefinition.getFieldSets().isEmpty()){ if (this.propertyDefinition.getFieldSets() != null && !this.propertyDefinition.getFieldSets().isEmpty()){
PropertyDefinitionFieldSet propertyDefinitionFieldSet = propertyDefinition.getFieldSets().getOrDefault(fieldSetEntity.getId(), null); PropertyDefinitionFieldSet propertyDefinitionFieldSet = this.propertyDefinition.getFieldSets().getOrDefault(fieldSetEntity.getId(), null);
if (propertyDefinitionFieldSet != null && propertyDefinitionFieldSet.getItems() != null && !propertyDefinitionFieldSet.getItems().isEmpty()) { if (propertyDefinitionFieldSet != null && propertyDefinitionFieldSet.getItems() != null && !propertyDefinitionFieldSet.getItems().isEmpty()) {
for (PropertyDefinitionFieldSetItem definitionFieldSetItem : propertyDefinitionFieldSet.getItems()) { for (PropertyDefinitionFieldSetItem definitionFieldSetItem : propertyDefinitionFieldSet.getItems()) {
FieldKey fieldKey = new FieldKey(fieldSetEntity.getId(), definitionFieldSetItem.getOrdinal()); FieldKey fieldKey = new FieldKey(fieldSetEntity.getId(), definitionFieldSetItem.getOrdinal());

View File

@ -1,18 +1,5 @@
package org.opencdmp.controllers; package org.opencdmp.controllers;
import org.opencdmp.audit.AuditableAction;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.StorageType;
import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.StorageFileEntity;
import org.opencdmp.model.StorageFile;
import org.opencdmp.model.builder.StorageFileBuilder;
import org.opencdmp.model.persist.StorageFilePersist;
import org.opencdmp.query.StorageFileQuery;
import org.opencdmp.service.storage.StorageFileProperties;
import org.opencdmp.service.storage.StorageFileService;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.auditing.AuditService; import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
@ -26,6 +13,19 @@ import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.ValidatorFactory;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.opencdmp.audit.AuditableAction;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.StorageType;
import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.StorageFileEntity;
import org.opencdmp.model.StorageFile;
import org.opencdmp.model.builder.StorageFileBuilder;
import org.opencdmp.model.persist.StorageFilePersist;
import org.opencdmp.query.StorageFileQuery;
import org.opencdmp.service.storage.StorageFileProperties;
import org.opencdmp.service.storage.StorageFileService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
@ -86,7 +86,7 @@ public class StorageFileController {
StorageFileQuery query = this.queryFactory.query(StorageFileQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); StorageFileQuery query = this.queryFactory.query(StorageFileQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id);
StorageFile model = this.builderFactory.builder(StorageFileBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); StorageFile model = this.builderFactory.builder(StorageFileBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet));
if (model == null) if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, StorageFile.class.getSimpleName()}, LocaleContextHolder.getLocale())); throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, StorageFile.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.StorageFile_Query, Map.ofEntries( this.auditService.track(AuditableAction.StorageFile_Query, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id), new AbstractMap.SimpleEntry<String, Object>("id", id),
@ -130,10 +130,10 @@ public class StorageFileController {
this.authorizationService.authorizeForce(Permission.BrowseStorageFile, Permission.DeferredAffiliation); this.authorizationService.authorizeForce(Permission.BrowseStorageFile, Permission.DeferredAffiliation);
StorageFileEntity storageFile = this.queryFactory.query(StorageFileQuery.class).ids(id).firstAs(new BaseFieldSet().ensure(StorageFile._createdAt, StorageFile._fullName, StorageFile._mimeType, StorageFile._extension)); StorageFileEntity storageFile = this.queryFactory.query(StorageFileQuery.class).ids(id).firstAs(new BaseFieldSet().ensure(StorageFile._createdAt, StorageFile._fullName, StorageFile._mimeType, StorageFile._extension));
if (storageFile == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, StorageFile.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (storageFile == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, StorageFile.class.getSimpleName()}, LocaleContextHolder.getLocale()));
byte[] file = this.storageFileService.readAsBytesSafe(id); byte[] file = this.storageFileService.readAsBytesSafe(id);
if (file == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, StorageFile.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (file == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, StorageFile.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.StorageFile_Download, Map.ofEntries( this.auditService.track(AuditableAction.StorageFile_Download, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id) new AbstractMap.SimpleEntry<String, Object>("id", id)

View File

@ -43,7 +43,7 @@ queue:
generate-file-topic: generate.file generate-file-topic: generate.file
rabbitmq: rabbitmq:
enable: true enable: true
interval-seconds: 30 interval-seconds: 3
options: options:
retry-threashold: 100 retry-threashold: 100
retry-delay-step-seconds: 300 retry-delay-step-seconds: 300
@ -56,7 +56,7 @@ queue:
exchange: null exchange: null
rabbitmq: rabbitmq:
enable: true enable: true
interval-seconds: 30 interval-seconds: 3
options: options:
retry-threashold: 100 retry-threashold: 100
retry-delay-step-seconds: 300 retry-delay-step-seconds: 300

View File

@ -17,7 +17,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
import java.util.ArrayList; import java.util.ArrayList;
@SpringBootApplication(scanBasePackages = {"org.opencdmp" ,"eu.old.eudat", "eu.old.eudat.depositinterface", "gr.cite"}) @SpringBootApplication(scanBasePackages = {"org.opencdmp" ,"org.opencdmp.data.tenant" ,"eu.old.eudat", "eu.old.eudat.depositinterface", "gr.cite"})
@Configuration @Configuration
@EnableAsync @EnableAsync
public class EuDatApplication extends SpringBootServletInitializer { public class EuDatApplication extends SpringBootServletInitializer {