reference type refactor

This commit is contained in:
Efstratios Giannopoulos 2024-02-08 18:27:54 +02:00
parent 4f1b05ab20
commit 87dd56ff2c
15 changed files with 76 additions and 67 deletions

View File

@ -8,12 +8,12 @@ import java.util.Map;
public enum DmpBlueprintFieldCategory implements DatabaseEnum<Short> {
System((short) 0),
Extra((short) 1),
Reference((short) 1);
ReferenceType((short) 1);
public static class Names {
public static final String System = "system";
public static final String Extra = "extra";
public static final String Reference = "reference";
public static final String ReferenceType = "referenceType";
}
private final Short value;

View File

@ -7,7 +7,7 @@ import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class ReferenceFieldEntity extends FieldEntity {
public class ReferenceTypeFieldEntity extends FieldEntity {
@XmlAttribute(name="referenceTypeId")
private UUID referenceTypeId;

View File

@ -26,7 +26,7 @@ public class SectionEntity {
@XmlElements({
@XmlElement(name = DmpBlueprintFieldCategory.Names.Extra, type = ExtraFieldEntity.class),
@XmlElement(name = DmpBlueprintFieldCategory.Names.System, type = SystemFieldEntity.class),
@XmlElement(name = DmpBlueprintFieldCategory.Names.Reference, type = ReferenceFieldEntity.class),
@XmlElement(name = DmpBlueprintFieldCategory.Names.ReferenceType, type = ReferenceTypeFieldEntity.class),
})
private List<FieldEntity> fields;

View File

@ -7,7 +7,7 @@ import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class ReferenceFieldImportExport {
public class ReferenceTypeFieldImportExport {
@XmlAttribute(name = "id")
private UUID id;

View File

@ -24,7 +24,7 @@ public class SectionImportExport {
private List<ExtraFieldImportExport> extraFields;
@XmlElementWrapper(name = "referenceFields")
@XmlElement(name = "referenceField")
private List<ReferenceFieldImportExport> referenceFields;
private List<ReferenceTypeFieldImportExport> referenceFields;
@XmlAttribute(name = "hasTemplates")
private boolean hasTemplates;
@XmlElementWrapper(name = "descriptionTemplates")
@ -79,11 +79,11 @@ public class SectionImportExport {
this.extraFields = extraFields;
}
public List<ReferenceFieldImportExport> getReferenceFields() {
public List<ReferenceTypeFieldImportExport> getReferenceFields() {
return referenceFields;
}
public void setReferenceFields(List<ReferenceFieldImportExport> referenceFields) {
public void setReferenceFields(List<ReferenceTypeFieldImportExport> referenceFields) {
this.referenceFields = referenceFields;
}

View File

@ -1,8 +1,16 @@
package eu.eudat.model.builder.dmpblueprintdefinition;
import eu.eudat.commons.types.dmpblueprint.ReferenceFieldEntity;
import eu.eudat.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.dmpblueprintdefinition.ReferenceField;
import eu.eudat.model.Dmp;
import eu.eudat.model.PublicReferenceType;
import eu.eudat.model.builder.PublicReferenceTypeBuilder;
import eu.eudat.model.builder.ReferenceTypeBuilder;
import eu.eudat.model.dmpblueprintdefinition.ReferenceTypeField;
import eu.eudat.query.ReferenceTypeQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
@ -13,20 +21,27 @@ import org.springframework.stereotype.Component;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ReferenceFieldBuilder extends FieldBuilder<ReferenceField, ReferenceFieldEntity> {
public class ReferenceFieldBuilder extends FieldBuilder<ReferenceTypeField, ReferenceTypeFieldEntity> {
private final QueryFactory queryFactory;
private final BuilderFactory builderFactory;
@Autowired
public ReferenceFieldBuilder(
ConventionService conventionService) {
ConventionService conventionService, QueryFactory queryFactory, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFieldBuilder.class)));
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
}
protected ReferenceField getInstance() {
return new ReferenceField();
protected ReferenceTypeField getInstance() {
return new ReferenceTypeField();
}
protected ReferenceField buildChild(FieldSet fields, ReferenceFieldEntity data, ReferenceField model) {
if (fields.hasField(this.asIndexer(ReferenceField._referenceTypeId))) model.setReferenceTypeId(data.getReferenceTypeId());
protected ReferenceTypeField buildChild(FieldSet fields, ReferenceTypeFieldEntity data, ReferenceTypeField model) {
FieldSet referenceTypeFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeField._referenceType));
if (data.getReferenceTypeId() != null && !referenceTypeFields.isEmpty() ) model.setReferenceType(this.builderFactory.builder(ReferenceTypeBuilder.class).build(referenceTypeFields, this.queryFactory.query(ReferenceTypeQuery.class).ids(data.getReferenceTypeId()).first())); //TODO: Optimize
return model;
}
}

View File

@ -18,7 +18,6 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
@Component("dmpblueprintdefinitionsectionbuilder")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ -65,7 +64,7 @@ public class SectionBuilder extends BaseBuilder<Section, SectionEntity> {
m.getFields().addAll(this.builderFactory.builder(SystemFieldBuilder.class).authorize(this.authorize).build(fieldsFields, systemFieldEntities));
List<ExtraFieldEntity> extraFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.Extra.equals(x.getCategory())).map(x-> (ExtraFieldEntity)x).toList();
m.getFields().addAll(this.builderFactory.builder(ExtraFieldBuilder.class).authorize(this.authorize).build(fieldsFields, extraFieldEntities));
List<ReferenceFieldEntity> referenceFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.Reference.equals(x.getCategory())).map(x-> (ReferenceFieldEntity)x).toList();
List<ReferenceTypeFieldEntity> referenceFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.ReferenceType.equals(x.getCategory())).map(x-> (ReferenceTypeFieldEntity)x).toList();
m.getFields().addAll(this.builderFactory.builder(ReferenceFieldBuilder.class).authorize(this.authorize).build(fieldsFields, referenceFieldEntities));
}
models.add(m);

View File

@ -6,16 +6,11 @@ import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.types.dmpblueprint.*;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.file.transformer.enums.DmpBlueprintExtraFieldDataType;
import eu.eudat.file.transformer.enums.DmpBlueprintFieldCategory;
import eu.eudat.file.transformer.enums.DmpBlueprintSystemFieldType;
import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
import eu.eudat.file.transformer.models.dmpblueprint.DmpBlueprintFileTransformerModel;
import eu.eudat.file.transformer.models.dmpblueprint.definition.*;
import eu.eudat.model.dmpblueprintdefinition.*;
import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.DmpBlueprintQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
@ -111,7 +106,7 @@ public class DmpBlueprintFileTransformerBuilder extends BaseFileTransformerBuild
FieldFileTransformerModel m = switch (fieldEntity.getCategory()) {
case System -> new SystemFieldFileTransformerModel();
case Extra -> new ExtraFieldFileTransformerModelFileTransformerModel();
case Reference -> throw new NotImplementedException("ReferenceFieldFileTransformerModel");
case ReferenceType -> throw new NotImplementedException("ReferenceFieldFileTransformerModel");
default -> throw new MyApplicationException("unrecognized type " + fieldEntity.getCategory());
};
m.setId(fieldEntity.getId());

View File

@ -1,17 +0,0 @@
package eu.eudat.model.dmpblueprintdefinition;
import java.util.UUID;
public class ReferenceField extends Field {
public final static String _referenceTypeId = "referenceTypeId";
private UUID referenceTypeId;
public UUID getReferenceTypeId() {
return referenceTypeId;
}
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
}

View File

@ -0,0 +1,19 @@
package eu.eudat.model.dmpblueprintdefinition;
import eu.eudat.model.ReferenceType;
import java.util.UUID;
public class ReferenceTypeField extends Field {
public final static String _referenceType = "referenceTypeId";
private ReferenceType referenceType;
public ReferenceType getReferenceType() {
return referenceType;
}
public void setReferenceType(ReferenceType referenceType) {
this.referenceType = referenceType;
}
}

View File

@ -12,7 +12,7 @@ import org.springframework.stereotype.Component;
import java.util.List;
import java.util.UUID;
public class ReferenceFieldPersist extends FieldPersist {
public class ReferenceTypeFieldPersist extends FieldPersist {
private UUID referenceTypeId;
@ -28,7 +28,7 @@ public class ReferenceFieldPersist extends FieldPersist {
@Component(ReferenceFieldPersistPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceFieldPersistPersistValidator extends BaseFieldPersistValidator<ReferenceFieldPersist> {
public static class ReferenceFieldPersistPersistValidator extends BaseFieldPersistValidator<ReferenceTypeFieldPersist> {
public static final String ValidatorName = "DmpBlueprint.ReferenceFieldPersistPersistValidator";
@ -37,17 +37,17 @@ public class ReferenceFieldPersist extends FieldPersist {
}
@Override
protected Class<ReferenceFieldPersist> modelClass() {
return ReferenceFieldPersist.class;
protected Class<ReferenceTypeFieldPersist> modelClass() {
return ReferenceTypeFieldPersist.class;
}
@Override
protected List<Specification> specifications(ReferenceFieldPersist item) {
protected List<Specification> specifications(ReferenceTypeFieldPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
this.spec()
.must(() -> !this.isNull(item.getReferenceTypeId()))
.failOn(ReferenceFieldPersist._referenceTypeId).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceFieldPersist._referenceTypeId}, LocaleContextHolder.getLocale()))
.failOn(ReferenceTypeFieldPersist._referenceTypeId).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeFieldPersist._referenceTypeId}, LocaleContextHolder.getLocale()))
);
return specifications;
}

View File

@ -1,6 +1,5 @@
package eu.eudat.model.persist.dmpblueprintdefinition;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.validation.ValidatorFactory;
@ -14,7 +13,6 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@ -154,8 +152,8 @@ public class SectionPersist {
case System -> {
return this.validatorFactory.validator(SystemFieldPersist.SystemFieldPersistValidator.class);
}
case Reference -> {
return this.validatorFactory.validator(ReferenceFieldPersist.ReferenceFieldPersistPersistValidator.class);
case ReferenceType -> {
return this.validatorFactory.validator(ReferenceTypeFieldPersist.ReferenceFieldPersistPersistValidator.class);
}
default -> throw new MyApplicationException("unrecognized type " + ((FieldPersist) itm).getCategory());
}

View File

@ -5,6 +5,6 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(DashboardServiceProperties.class)
public class PublicApiConfiguration {
public class DashboardServiceConfiguration {
}

View File

@ -12,7 +12,7 @@ import eu.eudat.commons.types.actionconfirmation.DmpInvitationEntity;
import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity;
import eu.eudat.commons.types.dmp.DmpContactEntity;
import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
import eu.eudat.commons.types.dmpblueprint.ReferenceFieldEntity;
import eu.eudat.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
import eu.eudat.commons.types.dmpreference.DmpReferenceDataEntity;
import eu.eudat.commons.types.notification.*;
import eu.eudat.commons.types.reference.DefinitionEntity;
@ -650,8 +650,8 @@ public class DmpServiceImpl implements DmpService {
referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId());
if (referenceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
} else {
ReferenceFieldEntity fieldEntity = blueprintDefinition.getFieldById(model.getData().getBlueprintFieldId()).stream().filter(x-> x.getCategory().equals(DmpBlueprintFieldCategory.Reference)).map(x-> (ReferenceFieldEntity)x).findFirst().orElse(null);
if (fieldEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getData().getBlueprintFieldId(), ReferenceFieldEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
ReferenceTypeFieldEntity fieldEntity = blueprintDefinition.getFieldById(model.getData().getBlueprintFieldId()).stream().filter(x-> x.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType)).map(x-> (ReferenceTypeFieldEntity)x).findFirst().orElse(null);
if (fieldEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getData().getBlueprintFieldId(), ReferenceTypeFieldEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).typeIds(fieldEntity.getReferenceTypeId()).sources(referencePersist.getSource()).isActive(IsActive.Active).references(referencePersist.getReference()).first();
if (referenceEntity == null){

View File

@ -262,9 +262,9 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
dataTyped.setType(((SystemFieldPersist) persist).getSystemFieldType());
data = dataTyped;
}
case Reference -> {
ReferenceFieldEntity dataTyped = new ReferenceFieldEntity();
dataTyped.setReferenceTypeId(((ReferenceFieldPersist) persist).getReferenceTypeId());
case ReferenceType -> {
ReferenceTypeFieldEntity dataTyped = new ReferenceTypeFieldEntity();
dataTyped.setReferenceTypeId(((ReferenceTypeFieldPersist) persist).getReferenceTypeId());
data = dataTyped;
}
default -> throw new InternalError("unknown type: " + persist.getCategory());
@ -490,10 +490,10 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
}
xml.setExtraFields(dmpBlueprintExtraFieldModels);
List<ReferenceFieldImportExport> dmpBlueprintReferenceFieldModels = new LinkedList<>();
List<ReferenceTypeFieldImportExport> dmpBlueprintReferenceFieldModels = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getFields())) {
for (ReferenceFieldEntity referenceFieldEntity : entity.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.Reference).map(x -> (ReferenceFieldEntity) x).toList()) {
dmpBlueprintReferenceFieldModels.add(this.referenceFieldXmlToExport(referenceFieldEntity));
for (ReferenceTypeFieldEntity referenceTypeFieldEntity : entity.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.ReferenceType).map(x -> (ReferenceTypeFieldEntity) x).toList()) {
dmpBlueprintReferenceFieldModels.add(this.referenceFieldXmlToExport(referenceTypeFieldEntity));
}
}
xml.setReferenceFields(dmpBlueprintReferenceFieldModels);
@ -529,8 +529,8 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return xml;
}
private ReferenceFieldImportExport referenceFieldXmlToExport(ReferenceFieldEntity entity) {
ReferenceFieldImportExport xml = new ReferenceFieldImportExport();
private ReferenceTypeFieldImportExport referenceFieldXmlToExport(ReferenceTypeFieldEntity entity) {
ReferenceTypeFieldImportExport xml = new ReferenceTypeFieldImportExport();
xml.setId(entity.getId());
xml.setReferenceTypeId(entity.getReferenceTypeId());
xml.setLabel(entity.getLabel());
@ -603,7 +603,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
}
}
if (!this.conventionService.isListNullOrEmpty(importXml.getReferenceFields())) {
for (ReferenceFieldImportExport referenceField : importXml.getReferenceFields()) {
for (ReferenceTypeFieldImportExport referenceField : importXml.getReferenceFields()) {
dmpBlueprintFieldModels.add(this.xmlReferenceFieldToPersist(referenceField));
}
}
@ -658,10 +658,10 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return persist;
}
private FieldPersist xmlReferenceFieldToPersist(ReferenceFieldImportExport importXml) {
ReferenceFieldPersist persist = new ReferenceFieldPersist();
private FieldPersist xmlReferenceFieldToPersist(ReferenceTypeFieldImportExport importXml) {
ReferenceTypeFieldPersist persist = new ReferenceTypeFieldPersist();
persist.setId(importXml.getId());
persist.setCategory(DmpBlueprintFieldCategory.Reference);
persist.setCategory(DmpBlueprintFieldCategory.ReferenceType);
persist.setReferenceTypeId(importXml.getReferenceTypeId());
persist.setLabel(importXml.getLabel());
persist.setPlaceholder(importXml.getPlaceholder());