remove unused rules

This commit is contained in:
Efstratios Giannopoulos 2024-05-02 16:29:50 +03:00
parent c7c7255e19
commit 528fbcd758
15 changed files with 21 additions and 394 deletions

View File

@ -1,32 +0,0 @@
package org.opencdmp.commons.types.descriptiontemplate;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
@XmlAccessorType(XmlAccessType.FIELD)
public class ExternalIdentifierEntity {
@XmlAttribute(name="identifier")
private String identifier;
@XmlAttribute(name="type")
private String type;
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@ -24,8 +24,6 @@ public class RuleEntity {
@XmlElement(name = "booleanValue") @XmlElement(name = "booleanValue")
private Boolean booleanValue; private Boolean booleanValue;
@XmlElement(name="externalIdentifier")
private ExternalIdentifierEntity externalIdentifier;
public String getTarget() { public String getTarget() {
return this.target; return this.target;
@ -66,13 +64,5 @@ public class RuleEntity {
public void setBooleanValue(Boolean booleanValue) { public void setBooleanValue(Boolean booleanValue) {
this.booleanValue = booleanValue; this.booleanValue = booleanValue;
} }
public ExternalIdentifierEntity getExternalIdentifier() {
return this.externalIdentifier;
}
public void setExternalIdentifier(ExternalIdentifierEntity externalIdentifier) {
this.externalIdentifier = externalIdentifier;
}
} }

View File

@ -1,32 +0,0 @@
package org.opencdmp.commons.types.descriptiontemplate.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionTemplateExternalIdentifierImportExport {
@XmlAttribute(name="identifier")
private String identifier;
@XmlAttribute(name="type")
private String type;
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@ -25,9 +25,6 @@ public class DescriptionTemplateRuleImportExport {
@XmlElement(name = "booleanValue") @XmlElement(name = "booleanValue")
private Boolean booleanValue; private Boolean booleanValue;
@XmlElement(name="externalIdentifier")
private DescriptionTemplateExternalIdentifierImportExport externalIdentifier;
public String getTarget() { public String getTarget() {
return this.target; return this.target;
} }
@ -67,12 +64,4 @@ public class DescriptionTemplateRuleImportExport {
public void setBooleanValue(Boolean booleanValue) { public void setBooleanValue(Boolean booleanValue) {
this.booleanValue = booleanValue; this.booleanValue = booleanValue;
} }
public DescriptionTemplateExternalIdentifierImportExport getExternalIdentifier() {
return this.externalIdentifier;
}
public void setExternalIdentifier(DescriptionTemplateExternalIdentifierImportExport externalIdentifier) {
this.externalIdentifier = externalIdentifier;
}
} }

View File

@ -1,58 +0,0 @@
package org.opencdmp.model.builder.descriptiontemplatedefinition;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.types.descriptiontemplate.ExternalIdentifierEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.BaseBuilder;
import org.opencdmp.model.descriptiontemplatedefinition.ExternalIdentifier;
import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
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.*;
@Component("descriptiontemplatedefinition.ExternalIdentifierBuilder")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExternalIdentifierBuilder extends BaseBuilder<ExternalIdentifier, ExternalIdentifierEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public ExternalIdentifierBuilder(
ConventionService conventionService, BuilderFactory builderFactory, FieldDataHelperServiceProvider fieldDataHelperServiceProvider) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalIdentifierBuilder.class)));
}
public ExternalIdentifierBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<ExternalIdentifier> build(FieldSet fields, List<ExternalIdentifierEntity> 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<ExternalIdentifier> models = new ArrayList<>();
for (ExternalIdentifierEntity d : data) {
ExternalIdentifier m = new ExternalIdentifier();
if (fields.hasField(this.asIndexer(ExternalIdentifier._identifier))) m.setIdentifier(d.getIdentifier());
if (fields.hasField(this.asIndexer(ExternalIdentifier._type))) m.setType(d.getType());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -3,7 +3,6 @@ package org.opencdmp.model.builder.descriptiontemplatedefinition;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
@ -11,11 +10,8 @@ import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.enums.FieldType; import org.opencdmp.commons.enums.FieldType;
import org.opencdmp.commons.types.descriptiontemplate.RuleEntity; import org.opencdmp.commons.types.descriptiontemplate.RuleEntity;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.Reference;
import org.opencdmp.model.builder.BaseBuilder; import org.opencdmp.model.builder.BaseBuilder;
import org.opencdmp.model.builder.ReferenceBuilder;
import org.opencdmp.model.descriptiontemplatedefinition.Rule; import org.opencdmp.model.descriptiontemplatedefinition.Rule;
import org.opencdmp.query.ReferenceQuery;
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.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -23,7 +19,6 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Component @Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ -61,9 +56,6 @@ public class RuleBuilder extends BaseBuilder<Rule, RuleEntity> {
return new ArrayList<>(); return new ArrayList<>();
FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT; FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
FieldSet externalIdentifierFields = fields.extractPrefixed(this.asPrefix(Rule._externalIdentifier));
FieldSet referenceFields = fields.extractPrefixed(this.asPrefix(Rule._references));
Map<UUID, Reference> referenceItemsMap = FieldType.isReferenceType(fieldType) ? this.collectReferences(referenceFields, data) : null;
List<Rule> models = new ArrayList<>(); List<Rule> models = new ArrayList<>();
for (RuleEntity d : data) { for (RuleEntity d : data) {
@ -73,47 +65,9 @@ public class RuleBuilder extends BaseBuilder<Rule, RuleEntity> {
if (fields.hasField(this.asIndexer(Rule._booleanValue)) && FieldType.isBooleanType(fieldType)) m.setBooleanValue(d.getBooleanValue()); if (fields.hasField(this.asIndexer(Rule._booleanValue)) && FieldType.isBooleanType(fieldType)) m.setBooleanValue(d.getBooleanValue());
if (fields.hasField(this.asIndexer(Rule._textValue)) && FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue()); if (fields.hasField(this.asIndexer(Rule._textValue)) && FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue());
if (fields.hasField(this.asIndexer(Rule._textListValue)) && FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue()); if (fields.hasField(this.asIndexer(Rule._textListValue)) && FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue());
if (!referenceFields.isEmpty() && FieldType.isReferenceType(fieldType) && referenceItemsMap != null && d.getTextListValue() != null && !d.getTextListValue().isEmpty()) {
m.setReferences(new ArrayList<>());
for (UUID referenceId : d.getTextListValue().stream().map(UUID::fromString).toList()){
if (referenceItemsMap.containsKey(referenceId)) m.getReferences().add(referenceItemsMap.get(referenceId));
}
}
if (!externalIdentifierFields.isEmpty() && d.getExternalIdentifier() != null && FieldType.isExternalIdentifierType(fieldType)) m.setExternalIdentifier(this.builderFactory.builder(ExternalIdentifierBuilder.class).authorize(this.authorize).build(externalIdentifierFields, d.getExternalIdentifier()));
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models; return models;
} }
private Map<UUID, Reference> collectReferences(FieldSet fields, List<RuleEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", Reference.class.getSimpleName());
Map<UUID, Reference> itemMap;
if (!fields.hasOtherField(this.asIndexer(Reference._id))) {
itemMap = this.asEmpty(
data.stream().map(RuleEntity::getTextListValue).flatMap(List::stream).map(UUID::fromString).distinct().collect(Collectors.toList()),
x -> {
Reference item = new Reference();
item.setId(x);
return item;
},
Reference::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Reference._id);
ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(RuleEntity::getTextListValue).flatMap(List::stream).map(UUID::fromString).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId);
}
if (!fields.hasField(Reference._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
} }

View File

@ -1,27 +0,0 @@
package org.opencdmp.model.descriptiontemplatedefinition;
public class ExternalIdentifier {
private String identifier;
public static final String _identifier = "identifier";
private String type;
public static final String _type = "type";
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@ -1,7 +1,5 @@
package org.opencdmp.model.descriptiontemplatedefinition; package org.opencdmp.model.descriptiontemplatedefinition;
import org.opencdmp.model.Reference;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
@ -10,7 +8,6 @@ public class Rule {
public final static String _target = "target"; public final static String _target = "target";
private String target; private String target;
private String textValue; private String textValue;
public static final String _textValue = "textValue"; public static final String _textValue = "textValue";
@ -23,13 +20,6 @@ public class Rule {
private Boolean booleanValue; private Boolean booleanValue;
public static final String _booleanValue = "booleanValue"; public static final String _booleanValue = "booleanValue";
private List<Reference> references;
public static final String _references = "references";
private ExternalIdentifier externalIdentifier;
public static final String _externalIdentifier = "externalIdentifier";
public String getTarget() { public String getTarget() {
return this.target; return this.target;
} }
@ -70,19 +60,4 @@ public class Rule {
this.booleanValue = booleanValue; this.booleanValue = booleanValue;
} }
public List<Reference> getReferences() {
return this.references;
}
public void setReferences(List<Reference> references) {
this.references = references;
}
public ExternalIdentifier getExternalIdentifier() {
return this.externalIdentifier;
}
public void setExternalIdentifier(ExternalIdentifier externalIdentifier) {
this.externalIdentifier = externalIdentifier;
}
} }

View File

@ -1,6 +1,5 @@
package org.opencdmp.model.mapper.publicapi; package org.opencdmp.model.mapper.publicapi;
import org.opencdmp.commons.types.descriptiontemplate.ExternalIdentifierEntity;
import org.opencdmp.commons.types.descriptiontemplate.RuleEntity; import org.opencdmp.commons.types.descriptiontemplate.RuleEntity;
import org.opencdmp.model.publicapi.datasetwizard.DefaultValueEntity; import org.opencdmp.model.publicapi.datasetwizard.DefaultValueEntity;
import org.opencdmp.model.publicapi.datasetwizard.Field; import org.opencdmp.model.publicapi.datasetwizard.Field;
@ -31,11 +30,6 @@ public class DescriptionFieldToDatasetFieldMapper {
ruleEntity.setDateValue(x.getDateValue()); ruleEntity.setDateValue(x.getDateValue());
ruleEntity.setBooleanValue(x.getBooleanValue()); ruleEntity.setBooleanValue(x.getBooleanValue());
ruleEntity.setTextListValue(x.getTextListValue()); ruleEntity.setTextListValue(x.getTextListValue());
if (x.getExternalIdentifier() != null){
ruleEntity.setExternalIdentifier(new ExternalIdentifierEntity());
ruleEntity.getExternalIdentifier().setIdentifier(x.getExternalIdentifier().getIdentifier());
ruleEntity.getExternalIdentifier().setType(x.getExternalIdentifier().getType());
}
ruleEntity.setTarget(x.getTarget()); ruleEntity.setTarget(x.getTarget());
return ruleEntity; return ruleEntity;
}).toList()); }).toList());

View File

@ -1,68 +0,0 @@
package org.opencdmp.model.persist.descriptiontemplatedefinition;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class ExternalIdentifierPersist {
private String identifier;
public static final String _identifier = "identifier";
private String type;
public static final String _type = "type";
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Component(PersistValidator.ValidatorName)
public static class PersistValidator extends BaseValidator<ExternalIdentifierPersist> {
public static final String ValidatorName = "descriptiontemplatedefinition.ExternalIdentifierPersistPersistValidator";
private final MessageSource messageSource;
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<ExternalIdentifierPersist> modelClass() {
return ExternalIdentifierPersist.class;
}
@Override
protected List<Specification> specifications(ExternalIdentifierPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getIdentifier()))
.failOn(ExternalIdentifierPersist._identifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalIdentifierPersist._identifier}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getType()))
.failOn(ExternalIdentifierPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalIdentifierPersist._type}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -38,10 +38,6 @@ public class RulePersist {
private List<ReferencePersist> references; private List<ReferencePersist> references;
public static final String _references = "references"; public static final String _references = "references";
private ExternalIdentifierPersist externalIdentifier;
public static final String _externalIdentifier = "externalIdentifier";
public String getTarget() { public String getTarget() {
return this.target; return this.target;
} }
@ -90,14 +86,6 @@ public class RulePersist {
this.references = references; this.references = references;
} }
public ExternalIdentifierPersist getExternalIdentifier() {
return this.externalIdentifier;
}
public void setExternalIdentifier(ExternalIdentifierPersist externalIdentifier) {
this.externalIdentifier = externalIdentifier;
}
@Component(RulePersistValidator.ValidatorName) @Component(RulePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class RulePersistValidator extends BaseValidator<RulePersist> { public static class RulePersistValidator extends BaseValidator<RulePersist> {
@ -143,10 +131,6 @@ public class RulePersist {
.iff(()-> FieldType.isBooleanType(fieldType)) .iff(()-> FieldType.isBooleanType(fieldType))
.must(() -> !this.isNull(item.getBooleanValue())) .must(() -> !this.isNull(item.getBooleanValue()))
.failOn(RulePersist._booleanValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._booleanValue}, LocaleContextHolder.getLocale())), .failOn(RulePersist._booleanValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._booleanValue}, LocaleContextHolder.getLocale())),
this.spec()
.iff(()-> FieldType.isExternalIdentifierType(fieldType))
.must(() -> !this.isNull(item.getExternalIdentifier()))
.failOn(RulePersist._externalIdentifier).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._externalIdentifier}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(()-> FieldType.isTextListType(fieldType)) .iff(()-> FieldType.isTextListType(fieldType))
.must(() -> !this.isNull(item.getTextListValue())) .must(() -> !this.isNull(item.getTextListValue()))
@ -163,12 +147,7 @@ public class RulePersist {
.iff(() -> FieldType.isReferenceType(fieldType) && !this.isListNullOrEmpty(item.getReferences())) .iff(() -> FieldType.isReferenceType(fieldType) && !this.isListNullOrEmpty(item.getReferences()))
.on(RulePersist._references) .on(RulePersist._references)
.over(item.getReferences()) .over(item.getReferences())
.using((itm) -> this.validatorFactory.validator(ReferencePersist.ReferencePersistValidator.class)), .using((itm) -> this.validatorFactory.validator(ReferencePersist.ReferencePersistValidator.class))
this.refSpec()
.iff(() -> FieldType.isExternalIdentifierType(fieldType) && !this.isNull(item.getExternalIdentifier()))
.on(RulePersist._externalIdentifier)
.over(item.getExternalIdentifier())
.using(() -> this.validatorFactory.validator(ExternalIdentifierPersist.PersistValidator.class))
); );
} }
} }

View File

@ -47,7 +47,6 @@ public class Rule {
else if (rule.getDateValue() != null) this.requiredValue = rule.getDateValue().toString(); else if (rule.getDateValue() != null) this.requiredValue = rule.getDateValue().toString();
else if (rule.getBooleanValue() != null) this.requiredValue = rule.getBooleanValue().toString(); else if (rule.getBooleanValue() != null) this.requiredValue = rule.getBooleanValue().toString();
else if (rule.getTextListValue() != null) this.requiredValue = String.join(", ", rule.getTextListValue()); else if (rule.getTextListValue() != null) this.requiredValue = String.join(", ", rule.getTextListValue());
else if (rule.getExternalIdentifier() != null) this.requiredValue = rule.getExternalIdentifier().getIdentifier();
return this; return this;
} }

View File

@ -395,35 +395,21 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
data.setTarget(persist.getTarget()); data.setTarget(persist.getTarget());
if (FieldType.isTextType(fieldType)) { if (FieldType.isTextType(fieldType)) {
if (FieldType.UPLOAD.equals(fieldType) && !this.conventionService.isNullOrEmpty(persist.getTextValue())){ if (FieldType.UPLOAD.equals(fieldType) && !this.conventionService.isNullOrEmpty(persist.getTextValue())) throw new NotImplementedException("Upload not supported");
throw new NotImplementedException("Upload not supported");
} else {
data.setTextValue(persist.getTextValue()); data.setTextValue(persist.getTextValue());
} }
}
else if (FieldType.isTextListType(fieldType)) { else if (FieldType.isTextListType(fieldType)) {
if (FieldType.INTERNAL_ENTRIES_DMPS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){ if (FieldType.INTERNAL_ENTRIES_DMPS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())) throw new NotImplementedException("dmps not supported");
List<UUID> ids = persist.getTextListValue().stream().map(UUID::fromString).toList(); if (FieldType.INTERNAL_ENTRIES_DESCRIPTIONS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())) throw new NotImplementedException("descriptions not supported");
Set<UUID> existingIds = this.queryFactory.query(DmpQuery.class).ids(ids).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Dmp._id)).stream().map(DmpEntity::getId).collect(Collectors.toSet()); if (FieldType.TAGS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())) throw new NotImplementedException("tags not supported");
for (UUID id : ids){
if (!existingIds.contains(id)) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
} if (FieldType.INTERNAL_ENTRIES_DESCRIPTIONS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){
List<UUID> ids = persist.getTextListValue().stream().map(UUID::fromString).toList();
Set<UUID> existingIds = this.queryFactory.query(DescriptionQuery.class).ids(ids).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Description._id)).stream().map(DescriptionEntity::getId).collect(Collectors.toSet());
for (UUID id : ids){
if (!existingIds.contains(id)) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
}
data.setTextListValue(persist.getTextListValue()); data.setTextListValue(persist.getTextListValue());
} }
else if (FieldType.isReferenceType(fieldType) ) { else if (FieldType.isReferenceType(fieldType) ) {
List<UUID> referenceIds = this.patchAndSaveReferences(persist.getReferences(), fieldEntity); throw new NotImplementedException("reference not supported");
if (!referenceIds.isEmpty()) data.setTextListValue(referenceIds.stream().map(UUID::toString).toList());
} }
else if (FieldType.isDateType(fieldType)) data.setDateValue(persist.getDateValue()); else if (FieldType.isDateType(fieldType)) data.setDateValue(persist.getDateValue());
else if (FieldType.isBooleanType(fieldType)) data.setBooleanValue(persist.getBooleanValue()); else if (FieldType.isBooleanType(fieldType)) data.setBooleanValue(persist.getBooleanValue());
else if (FieldType.isExternalIdentifierType(fieldType) && persist.getExternalIdentifier() != null) data.setExternalIdentifier(this.buildExternalIdentifierEntity(persist.getExternalIdentifier())); else if (FieldType.isExternalIdentifierType(fieldType)) throw new NotImplementedException("ExternalIdentifier not supported");
return data; return data;
} }
@ -434,23 +420,13 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
if (persist == null) return data; if (persist == null) return data;
if (FieldType.isTextType(fieldType)) { if (FieldType.isTextType(fieldType)) {
if (FieldType.UPLOAD.equals(fieldType) && !this.conventionService.isNullOrEmpty(persist.getTextValue())){ if (FieldType.UPLOAD.equals(fieldType) && !this.conventionService.isNullOrEmpty(persist.getTextValue())) throw new NotImplementedException("Upload not supported");
throw new NotImplementedException("Upload not supported");
} else {
data.setTextValue(persist.getTextValue()); data.setTextValue(persist.getTextValue());
} }
}
else if (FieldType.isTextListType(fieldType)) { else if (FieldType.isTextListType(fieldType)) {
if (FieldType.INTERNAL_ENTRIES_DMPS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){ if (FieldType.INTERNAL_ENTRIES_DMPS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())) throw new NotImplementedException("dmps not supported");
throw new NotImplementedException("dmps not supported"); if (FieldType.INTERNAL_ENTRIES_DESCRIPTIONS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())) throw new NotImplementedException("descriptions not supported");
if (FieldType.TAGS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())) throw new NotImplementedException("tags not supported");
}
if (FieldType.INTERNAL_ENTRIES_DESCRIPTIONS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){
throw new NotImplementedException("descriptions not supported");
}
if (FieldType.TAGS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){
throw new NotImplementedException("tags not supported");
}
data.setTextListValue(persist.getTextListValue()); data.setTextListValue(persist.getTextListValue());
} }
else if (FieldType.isReferenceType(fieldType) ) { else if (FieldType.isReferenceType(fieldType) ) {
@ -464,14 +440,6 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return data; return data;
} }
private @NotNull ExternalIdentifierEntity buildExternalIdentifierEntity(ExternalIdentifierPersist persist){
ExternalIdentifierEntity data = new ExternalIdentifierEntity();
if (persist == null) return data;
data.setIdentifier(persist.getIdentifier());
data.setType(persist.getType());
return data;
}
private List<UUID> patchAndSaveReferences(List<ReferencePersist> models, FieldEntity fieldEntity) throws InvalidApplicationException { private List<UUID> patchAndSaveReferences(List<ReferencePersist> models, FieldEntity fieldEntity) throws InvalidApplicationException {
if (models == null) models = new ArrayList<>(); if (models == null) models = new ArrayList<>();
@ -1080,11 +1048,6 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
xml.setBooleanValue(entity.getBooleanValue()); xml.setBooleanValue(entity.getBooleanValue());
xml.setTextListValue(entity.getTextListValue()); xml.setTextListValue(entity.getTextListValue());
xml.setTextValue(entity.getTextValue()); xml.setTextValue(entity.getTextValue());
if (entity.getExternalIdentifier() != null){
xml.setExternalIdentifier(new DescriptionTemplateExternalIdentifierImportExport());
xml.getExternalIdentifier().setIdentifier(entity.getExternalIdentifier().getIdentifier());
xml.getExternalIdentifier().setType(entity.getExternalIdentifier().getType());
}
return xml; return xml;
} }

View File

@ -195,8 +195,6 @@ public class PublicDatasetsDescriptionDocumentation {
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._booleanValue), String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._booleanValue),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._textListValue), String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._textListValue),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._textValue), String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._textValue),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._externalIdentifier),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._references),
Description._createdAt, Description._createdAt,
Description._updatedAt, Description._updatedAt,
Description._finalizedAt Description._finalizedAt

View File

@ -484,11 +484,14 @@ public class DescriptionTemplateXmlMigrationService {
data.setTextListValue(valuesParsed == null ? List.of(textValue) : Arrays.stream(valuesParsed).toList()); data.setTextListValue(valuesParsed == null ? List.of(textValue) : Arrays.stream(valuesParsed).toList());
} }
} }
case DATASET_IDENTIFIER, VALIDATION -> { case DATASET_IDENTIFIER -> {
if(!this.conventionService.isNullOrEmpty(textValue)) { if(!this.conventionService.isNullOrEmpty(textValue)) {
org.opencdmp.commons.types.descriptiontemplate.ExternalIdentifierEntity externalIdentifierEntity = migrationTools.tryParseJsonAsObjectString(org.opencdmp.commons.types.descriptiontemplate.ExternalIdentifierEntity.class, textValue); throw new NotSupportedException("DATASET_IDENTIFIER validator not supported");
if (externalIdentifierEntity == null) throw new MyApplicationException("Could not parse dataset External Identifier : " + textValue); }
data.setExternalIdentifier(externalIdentifierEntity); }
case VALIDATION -> {
if(!this.conventionService.isNullOrEmpty(textValue)) {
throw new NotSupportedException("VALIDATION validator not supported");
} }
} }
case UPLOAD -> throw new NotSupportedException("Upload validator not supported"); case UPLOAD -> throw new NotSupportedException("Upload validator not supported");