fix duplicate reference for multiple fields
This commit is contained in:
parent
562070a57b
commit
13bd401995
|
@ -17,6 +17,8 @@ public class DescriptionReferenceImportExport {
|
|||
private String reference;
|
||||
@XmlElement(name = "fieldId")
|
||||
private String fieldId;
|
||||
@XmlElement(name = "ordinal")
|
||||
private int ordinal;
|
||||
@XmlElement(name = "type")
|
||||
private DescriptionReferenceTypeImportExport type;
|
||||
|
||||
|
@ -59,4 +61,12 @@ public class DescriptionReferenceImportExport {
|
|||
public void setFieldId(String fieldId) {
|
||||
this.fieldId = fieldId;
|
||||
}
|
||||
|
||||
public int getOrdinal() {
|
||||
return this.ordinal;
|
||||
}
|
||||
|
||||
public void setOrdinal(int ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
package org.opencdmp.commons.types.descriptionreference;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DescriptionReferenceDataEntity {
|
||||
private String fieldId;
|
||||
private int ordinal;
|
||||
|
||||
public String getFieldId() {
|
||||
return fieldId;
|
||||
return this.fieldId;
|
||||
}
|
||||
|
||||
public void setFieldId(String fieldId) {
|
||||
this.fieldId = fieldId;
|
||||
}
|
||||
|
||||
public int getOrdinal() {
|
||||
return this.ordinal;
|
||||
}
|
||||
|
||||
public void setOrdinal(int ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class TenantEntityManager {
|
|||
if (!this.tenantFiltersDisabled && this.tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) {
|
||||
if (tenantScopedEntity.getTenantId() != null && !tenantScopedEntity.getTenantId().equals(this.tenantScope.getTenant())) return null;
|
||||
}
|
||||
if (disableTracking) this.entityManager.detach(entity);
|
||||
if (disableTracking && entity != null) this.entityManager.detach(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package org.opencdmp.model.builder.descriptionreference;
|
||||
|
||||
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.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.commons.types.descriptionreference.DescriptionReferenceDataEntity;
|
||||
import org.opencdmp.convention.ConventionService;
|
||||
import org.opencdmp.model.builder.BaseBuilder;
|
||||
import org.opencdmp.model.descriptionreference.DescriptionReferenceData;
|
||||
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;
|
||||
|
@ -18,7 +18,7 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.*;
|
||||
|
||||
@Component("referencedescriptionreferencedatabuilder")
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DescriptionReferenceDataBuilder extends BaseBuilder<DescriptionReferenceData, DescriptionReferenceDataEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
@ -47,6 +47,7 @@ public class DescriptionReferenceDataBuilder extends BaseBuilder<DescriptionRefe
|
|||
for (DescriptionReferenceDataEntity d : data) {
|
||||
DescriptionReferenceData m = new DescriptionReferenceData();
|
||||
if (fields.hasField(this.asIndexer(DescriptionReferenceData._fieldId))) m.setFieldId(d.getFieldId());
|
||||
if (fields.hasField(this.asIndexer(DescriptionReferenceData._ordinal))) m.setOrdinal(d.getOrdinal());
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
|
|
@ -1,16 +1,25 @@
|
|||
package org.opencdmp.model.descriptionreference;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DescriptionReferenceData {
|
||||
private String fieldId;
|
||||
public final static String _fieldId = "fieldId";
|
||||
|
||||
private Integer ordinal;
|
||||
public final static String _ordinal = "ordinal";
|
||||
|
||||
public String getFieldId() {
|
||||
return fieldId;
|
||||
return this.fieldId;
|
||||
}
|
||||
|
||||
public void setFieldId(String fieldId) {
|
||||
this.fieldId = fieldId;
|
||||
}
|
||||
|
||||
public Integer getOrdinal() {
|
||||
return this.ordinal;
|
||||
}
|
||||
|
||||
public void setOrdinal(Integer ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,11 @@ public class DescriptionReferenceDataPersist {
|
|||
|
||||
public static final String _fieldId = "fieldId";
|
||||
|
||||
private Integer ordinal;
|
||||
|
||||
public static final String _ordinal = "ordinal";
|
||||
|
||||
|
||||
public String getFieldId() {
|
||||
return this.fieldId;
|
||||
}
|
||||
|
@ -27,6 +32,14 @@ public class DescriptionReferenceDataPersist {
|
|||
this.fieldId = fieldId;
|
||||
}
|
||||
|
||||
public Integer getOrdinal() {
|
||||
return this.ordinal;
|
||||
}
|
||||
|
||||
public void setOrdinal(Integer ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
|
||||
@Component(DescriptionReferenceDataPersistValidator.ValidatorName)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class DescriptionReferenceDataPersistValidator extends BaseValidator<DescriptionReferenceDataPersist> {
|
||||
|
@ -49,7 +62,10 @@ public class DescriptionReferenceDataPersist {
|
|||
return Arrays.asList(
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getFieldId()))
|
||||
.failOn(DescriptionReferenceDataPersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferenceDataPersist._fieldId}, LocaleContextHolder.getLocale()))
|
||||
.failOn(DescriptionReferenceDataPersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferenceDataPersist._fieldId}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getOrdinal()))
|
||||
.failOn(DescriptionReferenceDataPersist._ordinal).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferenceDataPersist._ordinal}, LocaleContextHolder.getLocale()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.opencdmp.model.persist.dmpproperties;
|
||||
|
||||
import gr.cite.tools.validation.ValidatorFactory;
|
||||
import gr.cite.tools.validation.specification.Specification;
|
||||
import org.opencdmp.commons.enums.DmpBlueprintFieldCategory;
|
||||
import org.opencdmp.commons.enums.DmpBlueprintSystemFieldType;
|
||||
import org.opencdmp.commons.enums.DmpStatus;
|
||||
|
@ -8,8 +10,6 @@ import org.opencdmp.commons.types.dmpblueprint.FieldEntity;
|
|||
import org.opencdmp.commons.types.dmpblueprint.SectionEntity;
|
||||
import org.opencdmp.commons.types.dmpblueprint.SystemFieldEntity;
|
||||
import org.opencdmp.commons.validation.BaseValidator;
|
||||
import gr.cite.tools.validation.ValidatorFactory;
|
||||
import gr.cite.tools.validation.specification.Specification;
|
||||
import org.opencdmp.convention.ConventionService;
|
||||
import org.opencdmp.errorcode.ErrorThesaurusProperties;
|
||||
import org.opencdmp.model.persist.validation.StatusAware;
|
||||
|
@ -36,7 +36,7 @@ public class DmpPropertiesPersist {
|
|||
public static final String _contacts = "contacts";
|
||||
|
||||
public Map<UUID, DmpBlueprintValuePersist> getDmpBlueprintValues() {
|
||||
return dmpBlueprintValues;
|
||||
return this.dmpBlueprintValues;
|
||||
}
|
||||
|
||||
public void setDmpBlueprintValues(Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues) {
|
||||
|
@ -44,7 +44,7 @@ public class DmpPropertiesPersist {
|
|||
}
|
||||
|
||||
public List<DmpContactPersist> getContacts() {
|
||||
return contacts;
|
||||
return this.contacts;
|
||||
}
|
||||
|
||||
public void setContacts(List<DmpContactPersist> contacts) {
|
||||
|
@ -83,11 +83,11 @@ public class DmpPropertiesPersist {
|
|||
.on(DmpPropertiesPersist._dmpBlueprintValues)
|
||||
.over(item.getDmpBlueprintValues())
|
||||
.mapKey((k) -> ((UUID)k).toString())
|
||||
.using((itm) -> this.validatorFactory.validator(DmpBlueprintValuePersist.DmpBlueprintValuePersistValidator.class).withDefinition(definition)),
|
||||
.using((itm) -> this.validatorFactory.validator(DmpBlueprintValuePersist.DmpBlueprintValuePersistValidator.class).withDefinition(this.definition)),
|
||||
this.spec()
|
||||
.iff(() -> this.status == DmpStatus.Finalized && contactField != null)
|
||||
.must(() -> !this.isListNullOrEmpty(item.getContacts()))
|
||||
.failOn(DmpPropertiesPersist._contacts).failWith(messageSource.getMessage("Validation_Required", new Object[]{contactField}, LocaleContextHolder.getLocale())),
|
||||
.failOn(DmpPropertiesPersist._contacts).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{contactField}, LocaleContextHolder.getLocale())),
|
||||
this.navSpec()
|
||||
.iff(() -> this.status == DmpStatus.Finalized && !this.isListNullOrEmpty(item.getContacts()))
|
||||
.on(DmpPropertiesPersist._contacts)
|
||||
|
@ -108,9 +108,9 @@ public class DmpPropertiesPersist {
|
|||
}
|
||||
|
||||
private String getContactFieldLabel(){
|
||||
if (this.isListNullOrEmpty(definition.getSections())) return null;
|
||||
if (this.definition == null || this.isListNullOrEmpty(this.definition.getSections())) return null;
|
||||
|
||||
for (SectionEntity section: definition.getSections()) {
|
||||
for (SectionEntity section: this.definition.getSections()) {
|
||||
if (!this.isListNullOrEmpty(section.getFields())) {
|
||||
List<FieldEntity> fields = section.getFields().stream().filter(x -> x.getCategory().equals(DmpBlueprintFieldCategory.System)).collect(Collectors.toList());
|
||||
if (!this.isListNullOrEmpty(fields)){
|
||||
|
|
|
@ -517,13 +517,13 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
for (String key: persist.getFields().keySet()) {
|
||||
org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null;
|
||||
boolean isVisible = fieldEntity != null ? visibilityService.isVisible(fieldEntity.getId(), persist.getOrdinal()) : false;
|
||||
data.getFields().put(key, this.buildFieldEntity(persist.getFields().get(key), fieldEntity, fieldToReferenceMap, isVisible));
|
||||
data.getFields().put(key, this.buildFieldEntity(persist.getFields().get(key), fieldEntity, fieldToReferenceMap, persist.getOrdinal(), isVisible));
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private @NotNull FieldEntity buildFieldEntity(FieldPersist persist, org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity, Map<String, List<UUID>> fieldToReferenceMap, boolean isVisible) throws InvalidApplicationException {
|
||||
private @NotNull FieldEntity buildFieldEntity(FieldPersist persist, org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity, Map<String, List<UUID>> fieldToReferenceMap, int ordinal, boolean isVisible) throws InvalidApplicationException {
|
||||
FieldType fieldType = fieldEntity != null && fieldEntity.getData() != null ? fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
|
||||
FieldEntity data = new FieldEntity();
|
||||
if (persist == null || !isVisible) return data;
|
||||
|
@ -587,7 +587,8 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
data.setTextListValue(persist.getTextListValue());
|
||||
}
|
||||
} else if (FieldType.isReferenceType(fieldType) && fieldEntity != null ) {
|
||||
List<UUID> referenceIds = fieldToReferenceMap.getOrDefault(fieldEntity.getId(), null);
|
||||
String key = this.fieldToReferenceMapKey(fieldEntity.getId(), ordinal);
|
||||
List<UUID> referenceIds = fieldToReferenceMap.getOrDefault(key, null);
|
||||
if (referenceIds != null) data.setTextListValue(referenceIds.stream().map(UUID::toString).toList());
|
||||
} else if (FieldType.isTagType(fieldType)) {
|
||||
|
||||
|
@ -632,7 +633,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
for (String key : definitionFieldSetItemPersist.getFields().keySet()) {
|
||||
FieldPersist fieldPersist = definitionFieldSetItemPersist.getFields().get(key);
|
||||
boolean isVisible = visibilityService.isVisible(key, definitionFieldSetItemPersist.getOrdinal());
|
||||
if (isVisible) this.BuildDescriptionReferencePersist(key, fieldPersist, descriptionReferencePersists);
|
||||
if (isVisible) this.BuildDescriptionReferencePersist(key, definitionFieldSetItemPersist.getOrdinal(), fieldPersist, descriptionReferencePersists);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -642,7 +643,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
return descriptionReferencePersists;
|
||||
}
|
||||
|
||||
private void BuildDescriptionReferencePersist(String fieldId, FieldPersist fieldPersist, List<DescriptionReferencePersist> descriptionReferencePersists) {
|
||||
private void BuildDescriptionReferencePersist(String fieldId, int ordinal, FieldPersist fieldPersist, List<DescriptionReferencePersist> descriptionReferencePersists) {
|
||||
if (fieldPersist.getReference() != null) {
|
||||
if (fieldPersist.getReferences() == null) fieldPersist.setReferences(new ArrayList<>());
|
||||
fieldPersist.getReferences().add(fieldPersist.getReference());
|
||||
|
@ -655,6 +656,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
DescriptionReferencePersist descriptionReferencePersist = new DescriptionReferencePersist();
|
||||
descriptionReferencePersist.setData(new DescriptionReferenceDataPersist());
|
||||
descriptionReferencePersist.getData().setFieldId(fieldId);
|
||||
descriptionReferencePersist.getData().setOrdinal(ordinal);
|
||||
descriptionReferencePersist.setReference(referencePersist);
|
||||
descriptionReferencePersists.add(descriptionReferencePersist);
|
||||
}
|
||||
|
@ -726,7 +728,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
List<DescriptionReferenceEntity> descriptionReferenceEntities = descriptionReferenceEntityByReferenceId.getOrDefault(referenceEntity.getId(), new ArrayList<>());
|
||||
for (DescriptionReferenceEntity descriptionReferenceEntity : descriptionReferenceEntities){
|
||||
DescriptionReferenceDataEntity descriptionReferenceDataEntity = descriptionReferenceDataEntityMap.getOrDefault(descriptionReferenceEntity.getId(), new DescriptionReferenceDataEntity());
|
||||
if (Objects.equals(descriptionReferenceDataEntity.getFieldId(), model.getData().getFieldId())){
|
||||
if (Objects.equals(descriptionReferenceDataEntity.getFieldId(), model.getData().getFieldId()) && Objects.equals(descriptionReferenceDataEntity.getOrdinal(), model.getData().getOrdinal())){
|
||||
data = descriptionReferenceEntity;
|
||||
break;
|
||||
}
|
||||
|
@ -745,8 +747,9 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
updatedCreatedIds.add(data.getId());
|
||||
|
||||
if (model.getData() != null){
|
||||
if (!fieldToReferenceMap.containsKey(model.getData().getFieldId())) fieldToReferenceMap.put(model.getData().getFieldId(), new ArrayList<>());
|
||||
fieldToReferenceMap.get(model.getData().getFieldId()).add(referenceEntity.getId());
|
||||
String key = this.fieldToReferenceMapKey(model.getData().getFieldId(), model.getData().getOrdinal());
|
||||
if (!fieldToReferenceMap.containsKey(key)) fieldToReferenceMap.put(key, new ArrayList<>());
|
||||
fieldToReferenceMap.get(key).add(referenceEntity.getId());
|
||||
}
|
||||
|
||||
data.setUpdatedAt(Instant.now());
|
||||
|
@ -760,11 +763,16 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
|
||||
return fieldToReferenceMap;
|
||||
}
|
||||
|
||||
private String fieldToReferenceMapKey(String fieldId, int ordinal){
|
||||
return fieldId + "_" + ordinal;
|
||||
}
|
||||
|
||||
private @NotNull DescriptionReferenceDataEntity buildDescriptionReferenceDataEntity(DescriptionReferenceDataPersist persist){
|
||||
DescriptionReferenceDataEntity data = new DescriptionReferenceDataEntity();
|
||||
if (persist == null) return data;
|
||||
data.setFieldId(persist.getFieldId());
|
||||
data.setOrdinal(persist.getOrdinal());
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -1176,7 +1184,10 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
DescriptionReferenceImportExport xml = new DescriptionReferenceImportExport();
|
||||
if (entity == null) return xml;
|
||||
DescriptionReferenceDataEntity referenceData = this.jsonHandlingService.fromJsonSafe(DescriptionReferenceDataEntity.class, entity.getData());
|
||||
if (referenceData != null) xml.setFieldId(referenceData.getFieldId());
|
||||
if (referenceData != null){
|
||||
xml.setFieldId(referenceData.getFieldId());
|
||||
xml.setOrdinal(referenceData.getOrdinal());
|
||||
}
|
||||
ReferenceEntity reference = referenceEntityMap.getOrDefault(entity.getReferenceId(), null);
|
||||
|
||||
if (reference != null){
|
||||
|
@ -1363,7 +1374,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
|
||||
if (!this.conventionService.isListNullOrEmpty(importXml.getFields())){
|
||||
for (DescriptionFieldImportExport field: importXml.getFields()) {
|
||||
fields.put(field.getFieldId(), this.xmlFieldToPersist(field, references, descriptionTemplate));
|
||||
fields.put(field.getFieldId(), this.xmlFieldToPersist(field, importXml.getOrdinal(), references, descriptionTemplate));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1372,7 +1383,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
return persist;
|
||||
}
|
||||
|
||||
private FieldPersist xmlFieldToPersist(DescriptionFieldImportExport importXml, List<DescriptionReferenceImportExport> references, DescriptionTemplateImportExport descriptionTemplate) {
|
||||
private FieldPersist xmlFieldToPersist(DescriptionFieldImportExport importXml, int ordinal, List<DescriptionReferenceImportExport> references, DescriptionTemplateImportExport descriptionTemplate) {
|
||||
if (importXml == null || descriptionTemplate == null)
|
||||
return null;
|
||||
|
||||
|
@ -1386,7 +1397,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
if (!this.conventionService.isListNullOrEmpty(references) && descriptionTemplateField.getData().getFieldType().equals(FieldType.REFERENCE_TYPES)){
|
||||
ReferenceTypeDataImportExport referenceTypeDataImportExport = (ReferenceTypeDataImportExport) descriptionTemplateField.getData();
|
||||
if (referenceTypeDataImportExport != null){
|
||||
List<DescriptionReferenceImportExport> referencesByField = references.stream().filter(x -> x.getFieldId().equals(importXml.getFieldId())).collect(Collectors.toList());
|
||||
List<DescriptionReferenceImportExport> referencesByField = references.stream().filter(x -> x.getOrdinal() == ordinal && x.getFieldId().equals(importXml.getFieldId())).collect(Collectors.toList());
|
||||
if (!this.conventionService.isListNullOrEmpty(referencesByField)){
|
||||
if (referenceTypeDataImportExport.getMultipleSelect()){
|
||||
List<ReferencePersist> referencePersists = new ArrayList<>();
|
||||
|
|
|
@ -304,8 +304,8 @@ public class DmpServiceImpl implements DmpService {
|
|||
for (DmpUserEntity dmpUser : existingUsers) {
|
||||
if (!dmpUser.getUserId().equals(this.userScope.getUserIdSafe())){
|
||||
UserEntity user = this.queryFactory.query(UserQuery.class).disableTracking().ids(dmpUser.getUserId()).first();
|
||||
if (user == null || user.getIsActive().equals(IsActive.Inactive)) throw new MyValidationException(this.errors.getDmpInactiveUser().getCode(), this.errors.getDmpInactiveUser().getMessage());;
|
||||
this.createDmpNotificationEvent(dmp, user);
|
||||
if (user == null || user.getIsActive().equals(IsActive.Inactive)) throw new MyValidationException(this.errors.getDmpInactiveUser().getCode(), this.errors.getDmpInactiveUser().getMessage());
|
||||
this.createDmpNotificationEvent(dmp, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1796,7 +1796,7 @@ public class DmpServiceImpl implements DmpService {
|
|||
for (DmpUserImportExport user : dmpXml.getUsers()) {
|
||||
dmpUsers.add(this.xmlDmpUserToPersist(user, userIds));
|
||||
}
|
||||
persist.setUsers(dmpUsers);
|
||||
persist.setUsers(dmpUsers.stream().filter(Objects::nonNull).toList());
|
||||
}
|
||||
|
||||
if (dmpXml.getBlueprint() != null) persist.setBlueprint(dmpXml.getBlueprint().getId());
|
||||
|
@ -1806,7 +1806,7 @@ public class DmpServiceImpl implements DmpService {
|
|||
for (DmpDescriptionTemplateImportExport descriptionTemplate : dmpXml.getDescriptionTemplates()) {
|
||||
descriptionTemplates.add(this.xmlDmpDescriptionTemplateToPersist(descriptionTemplate));
|
||||
}
|
||||
persist.setDescriptionTemplates(descriptionTemplates);
|
||||
persist.setDescriptionTemplates(descriptionTemplates.stream().filter(Objects::nonNull).toList());
|
||||
}
|
||||
|
||||
this.validatorFactory.validator(DmpPersist.DmpPersistValidator.class).validateForce(persist);
|
||||
|
|
|
@ -433,7 +433,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
|
|||
this.ensureFieldSetEntity(description, licStartFieldSetEntity);
|
||||
|
||||
for (FieldEntity licStartDateNode : licStartEntities) {
|
||||
description.getProperties().getFieldSets().get(licStartFieldSetEntity.getId()).getItems().getFirst().getFields().put(licStartDateNode.getId(), this.buildPropertyDefinitionFieldItemValue(descriptionReferences,licStartDateNode, semanticTarget, issuedValue.toString(), type));
|
||||
description.getProperties().getFieldSets().get(licStartFieldSetEntity.getId()).getItems().getFirst().getFields().put(licStartDateNode.getId(), this.buildPropertyDefinitionFieldItemValue(descriptionReferences,licStartDateNode, 0, semanticTarget, issuedValue.toString(), type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
|
|||
if (!this.conventionService.isListNullOrEmpty(fieldEntities)) {
|
||||
this.ensureFieldSetEntity(description, fieldSetEntity);
|
||||
for (FieldEntity fieldEntity : fieldEntities){
|
||||
description.getProperties().getFieldSets().get(fieldSetEntity.getId()).getItems().getFirst().getFields().put(fieldEntity.getId() , this.buildPropertyDefinitionFieldItemValue(descriptionReferences, fieldEntity, semanticTarget, parsedValue, type));
|
||||
description.getProperties().getFieldSets().get(fieldSetEntity.getId()).getItems().getFirst().getFields().put(fieldEntity.getId() , this.buildPropertyDefinitionFieldItemValue(descriptionReferences, fieldEntity, 0, semanticTarget, parsedValue, type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
|
|||
}
|
||||
}
|
||||
|
||||
private Field buildPropertyDefinitionFieldItemValue(List<DescriptionReference> descriptionReferences, FieldEntity fieldEntity, String semanticTarget, String value, String type) {
|
||||
private Field buildPropertyDefinitionFieldItemValue(List<DescriptionReference> descriptionReferences, FieldEntity fieldEntity, int ordinal, String semanticTarget, String value, String type) {
|
||||
Field field = new Field();
|
||||
if (fieldEntity == null || fieldEntity.getData() == null || fieldEntity.getData().getFieldType() == null || this.conventionService.isNullOrEmpty(value)) return field;
|
||||
try{
|
||||
|
@ -601,6 +601,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
|
|||
descriptionReference.setReference(reference);
|
||||
DescriptionReferenceData descriptionReferenceData = new DescriptionReferenceData();
|
||||
descriptionReferenceData.setFieldId(fieldEntity.getId());
|
||||
descriptionReferenceData.setOrdinal(ordinal);
|
||||
descriptionReference.setData(descriptionReferenceData);
|
||||
descriptionReference.setIsActive(IsActive.Active);
|
||||
descriptionReferences.add(descriptionReference);
|
||||
|
|
|
@ -61,6 +61,7 @@ export interface DescriptionReference extends BaseEntity {
|
|||
|
||||
export interface DescriptionReferenceData {
|
||||
fieldId?: string;
|
||||
ordinal?: number;
|
||||
}
|
||||
|
||||
export interface DescriptionTag extends BaseEntity {
|
||||
|
|
|
@ -374,9 +374,9 @@ export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements Des
|
|||
if (item.fields) {
|
||||
//TODO: don't like it. Find a common way to parse it either its Map or json.
|
||||
if (item.fields instanceof Map)
|
||||
new Map(item.fields)?.forEach((value, key) => this.fields.set(key, new DescriptionFieldEditorModel(this.validationErrorModel).fromModel(value, definitionFieldSet?.fields?.find(x => x.id == key), descriptionReferences)));
|
||||
new Map(item.fields)?.forEach((value, key) => this.fields.set(key, new DescriptionFieldEditorModel(this.validationErrorModel).fromModel(value, item.ordinal, definitionFieldSet?.fields?.find(x => x.id == key), descriptionReferences)));
|
||||
else
|
||||
Object.keys(item.fields)?.forEach((key) => this.fields.set(key, new DescriptionFieldEditorModel(this.validationErrorModel).fromModel(item.fields[key], definitionFieldSet?.fields?.find(x => x.id == key), descriptionReferences)));
|
||||
Object.keys(item.fields)?.forEach((key) => this.fields.set(key, new DescriptionFieldEditorModel(this.validationErrorModel).fromModel(item.fields[key], item.ordinal, definitionFieldSet?.fields?.find(x => x.id == key), descriptionReferences)));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
|
@ -484,7 +484,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist {
|
|||
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||
) { }
|
||||
|
||||
public fromModel(item: DescriptionField, descriptionTemplateField: DescriptionTemplateField, descriptionReferences: DescriptionReference[]): DescriptionFieldEditorModel {
|
||||
public fromModel(item: DescriptionField, ordinal: number, descriptionTemplateField: DescriptionTemplateField, descriptionReferences: DescriptionReference[]): DescriptionFieldEditorModel {
|
||||
this.fieldDefinition = descriptionTemplateField;
|
||||
if (item) {
|
||||
this.textValue = item.textValue;
|
||||
|
@ -492,8 +492,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist {
|
|||
this.dateValue = item.dateValue;
|
||||
this.booleanValue = item.booleanValue;
|
||||
this.tags = item.tags?.map(x => x.label);
|
||||
|
||||
const references = descriptionReferences?.filter(x => x.data?.fieldId == descriptionTemplateField?.id && x.isActive == IsActive.Active).map(x => {
|
||||
const references = descriptionReferences?.filter(x => x.data?.fieldId == descriptionTemplateField?.id && x.data.ordinal == ordinal && x.isActive == IsActive.Active).map(x => {
|
||||
return {
|
||||
id: x.reference.id,
|
||||
label: x.reference.label,
|
||||
|
|
|
@ -88,6 +88,7 @@ export class DescriptionEditorResolver extends BaseEditorResolver {
|
|||
[nameof<Description>(x => x.descriptionTags), nameof<DescriptionTag>(x => x.isActive)].join('.'),
|
||||
|
||||
[nameof<Description>(x => x.descriptionReferences), nameof<DescriptionReference>(x => x.data), nameof<DescriptionReferenceData>(x => x.fieldId)].join('.'),
|
||||
[nameof<Description>(x => x.descriptionReferences), nameof<DescriptionReference>(x => x.data), nameof<DescriptionReferenceData>(x => x.ordinal)].join('.'),
|
||||
[nameof<Description>(x => x.descriptionReferences), nameof<DescriptionReference>(x => x.reference), nameof<Reference>(x => x.id)].join('.'),
|
||||
[nameof<Description>(x => x.descriptionReferences), nameof<DescriptionReference>(x => x.reference), nameof<Reference>(x => x.label)].join('.'),
|
||||
[nameof<Description>(x => x.descriptionReferences), nameof<DescriptionReference>(x => x.reference), nameof<Reference>(x => x.type), nameof<ReferenceType>(x => x.id)].join('.'),
|
||||
|
@ -168,9 +169,9 @@ export class DescriptionEditorResolver extends BaseEditorResolver {
|
|||
return this.descriptionService.getSingle(Guid.parse(id), fields).pipe(tap(d => this.breadcrumbService.addIdResolvedValue(d.id.toString(), d.label)));
|
||||
} else if (dmpId != null && dmpSectionId != null && copyDmpId == null) {
|
||||
return this.dmpService.getSingle(Guid.parse(dmpId), DescriptionEditorResolver.dmpLookupFields())
|
||||
.pipe(tap(x => {
|
||||
.pipe(tap(x => {
|
||||
this.breadcrumbService.addIdResolvedValue(`${x.id}/${dmpSectionId}`, this.language.instant("DESCRIPTION-EDITOR.TITLE-NEW"));
|
||||
|
||||
|
||||
}), takeUntil(this._destroyed), map(dmp => {
|
||||
|
||||
const description: Description = {};
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<app-description-form-field [propertiesFormGroup]="propertiesFormGroup.get('fields')" [field]="field" [fieldSet]="fieldSet" [isChild]="true"></app-description-form-field>
|
||||
<app-description-form-field [propertiesFormGroup]="propertiesFormGroup.get('fields')" [field]="field" [fieldSet]="fieldSet" [visibilityRulesService]="visibilityRulesService" [isChild]="true"></app-description-form-field>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Component, Inject } from "@angular/core";
|
|||
import { UntypedFormGroup } from "@angular/forms";
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog";
|
||||
import { DescriptionTemplateFieldSet } from "@app/core/model/description-template/description-template";
|
||||
import { VisibilityRulesService } from "../../../visibility-rules/visibility-rules.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-description-form-fieldset-editor-dialog',
|
||||
|
@ -10,6 +11,7 @@ import { DescriptionTemplateFieldSet } from "@app/core/model/description-templat
|
|||
})
|
||||
export class FormFieldSetEditorDialogComponent {
|
||||
|
||||
visibilityRulesService: VisibilityRulesService;
|
||||
numberingText: string;
|
||||
fieldSet: DescriptionTemplateFieldSet;
|
||||
propertiesFormGroup: UntypedFormGroup;
|
||||
|
@ -21,6 +23,9 @@ export class FormFieldSetEditorDialogComponent {
|
|||
this.fieldSet = data.fieldSet;
|
||||
this.propertiesFormGroup = data.propertiesFormGroup;
|
||||
this.numberingText = data.numberingText;
|
||||
this.visibilityRulesService = data.visibilityRulesService;
|
||||
this.visibilityRulesService.setContext(null, null);
|
||||
this.visibilityRulesService.reloadVisibility();
|
||||
}
|
||||
|
||||
cancel() {
|
||||
|
|
|
@ -119,7 +119,8 @@ export class DescriptionFormFieldSetComponent extends BaseComponent {
|
|||
data: {
|
||||
fieldSet: this.fieldSet,
|
||||
propertiesFormGroup: cloneAbstractControl((this.propertiesFormGroup?.get('items') as UntypedFormArray).at(fieldSetIndex)),
|
||||
numberingText: this.numbering
|
||||
numberingText: this.numbering,
|
||||
visibilityRulesService: this.visibilityRulesService
|
||||
}
|
||||
});
|
||||
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(data => {
|
||||
|
|
Loading…
Reference in New Issue