update common model

This commit is contained in:
Efstratios Giannopoulos 2024-05-03 11:50:06 +03:00
parent b7bd6dc449
commit 7158fdb6c3
4 changed files with 60 additions and 7 deletions

View File

@ -51,17 +51,17 @@
<dependency> <dependency>
<groupId>org.opencdmp</groupId> <groupId>org.opencdmp</groupId>
<artifactId>repositorydepositbase</artifactId> <artifactId>repositorydepositbase</artifactId>
<version>2.0.8</version> <version>2.0.11</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.opencdmp</groupId> <groupId>org.opencdmp</groupId>
<artifactId>common-models</artifactId> <artifactId>common-models</artifactId>
<version>0.0.11</version> <version>0.0.14</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.opencdmp</groupId> <groupId>org.opencdmp</groupId>
<artifactId>file-transformer-base</artifactId> <artifactId>file-transformer-base</artifactId>
<version>0.0.15</version> <version>0.0.18</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>

View File

@ -32,7 +32,6 @@ 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;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.net.URLConnection; import java.net.URLConnection;
@ -40,7 +39,6 @@ import java.time.Duration;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component("commonmodels.description")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel, FieldEntity> { public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel, FieldEntity> {
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
@ -93,7 +91,7 @@ public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel,
FieldModel m = new FieldModel(); FieldModel m = new FieldModel();
if (this.fieldEntity != null) m.setId(this.fieldEntity.getId()); if (this.fieldEntity != null) m.setId(this.fieldEntity.getId());
if (FieldType.isDateType(fieldType)) m.setDateValue(d.getDateValue()); if (FieldType.isDateType(fieldType)) m.setDateValue(d.getDateValue());
//if (FieldType.isBooleanType(fieldType)) m.setDateValue(d.getBooleanValue()); //TODO: Common field if (FieldType.isBooleanType(fieldType)) m.setBooleanValue(d.getBooleanValue());
if (FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue()); if (FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue());
if (FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue()); if (FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue());
if (FieldType.isReferenceType(fieldType) && referenceItemsMap != null && d.getTextListValue() != null && !d.getTextListValue().isEmpty()) { if (FieldType.isReferenceType(fieldType) && referenceItemsMap != null && d.getTextListValue() != null && !d.getTextListValue().isEmpty()) {

View File

@ -0,0 +1,55 @@
package org.opencdmp.model.builder.commonmodels.descriptiontemplate;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.descriptiotemplate.DefaultValueModel;
import org.opencdmp.commons.types.descriptiontemplate.DefaultValueEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.commonmodels.BaseCommonModelBuilder;
import org.opencdmp.model.builder.commonmodels.CommonModelBuilderItemResponse;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DefaultValueCommonModelBuilder extends BaseCommonModelBuilder<DefaultValueModel, DefaultValueEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DefaultValueCommonModelBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DefaultValueCommonModelBuilder.class)));
}
public DefaultValueCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
protected List<CommonModelBuilderItemResponse<DefaultValueModel, DefaultValueEntity>> buildInternal(List<DefaultValueEntity> data) throws MyApplicationException {
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty()) return new ArrayList<>();
List<CommonModelBuilderItemResponse<DefaultValueModel, DefaultValueEntity>> models = new ArrayList<>();
for (DefaultValueEntity d : data) {
DefaultValueModel m = new DefaultValueModel();
m.setDateValue(d.getDateValue());
m.setBooleanValue(d.getBooleanValue());
m.setTextValue(d.getTextValue());
models.add(new CommonModelBuilderItemResponse<>(m, d));
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -54,7 +54,7 @@ public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel,
m.setId(d.getId()); m.setId(d.getId());
m.setOrdinal(d.getOrdinal()); m.setOrdinal(d.getOrdinal());
m.setSchematics(d.getSchematics()); m.setSchematics(d.getSchematics());
//m.setDefaultValue(d.getDefaultValue()); //TODO if (d.getDefaultValue() != null) m.setDefaultValue(this.builderFactory.builder(DefaultValueCommonModelBuilder.class).build(d.getDefaultValue()));
m.setIncludeInExport(d.getIncludeInExport()); m.setIncludeInExport(d.getIncludeInExport());
if (!this.conventionService.isListNullOrEmpty(d.getValidations())){ if (!this.conventionService.isListNullOrEmpty(d.getValidations())){
m.setValidations(new ArrayList<>()); m.setValidations(new ArrayList<>());