Fix issue with unordered multiplicity fields

This commit is contained in:
George Kalampokis 2021-09-27 18:11:55 +03:00
parent faeb7e0d62
commit 06364873ca
4 changed files with 9 additions and 6 deletions

View File

@ -741,7 +741,7 @@ public class DatasetManager {
} }
private String propertiesModelToString(PagedDatasetProfile pagedDatasetProfile) { private String propertiesModelToString(PagedDatasetProfile pagedDatasetProfile) {
Map<String, Object> values = new HashMap(); Map<String, Object> values = new LinkedHashMap<>();
pagedDatasetProfile.toMap(values); pagedDatasetProfile.toMap(values);
JSONObject jobject = new JSONObject(values); JSONObject jobject = new JSONObject(values);
return jobject.toString(); return jobject.toString();

View File

@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
public class WordBuilder { public class WordBuilder {
private static final Logger logger = LoggerFactory.getLogger(WordBuilder.class); private static final Logger logger = LoggerFactory.getLogger(WordBuilder.class);
@ -178,7 +179,8 @@ public class WordBuilder {
} }
hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService); hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) { if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) {
for (FieldSet multiplicityFieldset : compositeField.getMultiplicityItems()) { List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList());
for (FieldSet multiplicityFieldset : list) {
hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService); hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
} }
} }
@ -198,7 +200,8 @@ public class WordBuilder {
private Boolean createFields(List<Field> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) { private Boolean createFields(List<Field> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
if (createListing) this.addListing(mainDocumentPart, indent, false, false); if (createListing) this.addListing(mainDocumentPart, indent, false, false);
boolean hasValue = false; boolean hasValue = false;
for (Field field: fields) { List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList());
for (Field field: tempFields) {
if (visibilityRuleService.isElementVisible(field.getId())) { if (visibilityRuleService.isElementVisible(field.getId())) {
if (!createListing) { if (!createListing) {
try { try {

View File

@ -175,12 +175,12 @@ public class FieldSet implements Comparable, PropertiesModelBuilder, ViewStyleDe
private FieldSet CloneForMultiplicity2(List<String> key, Map<String, Object> properties,String[] ids, int index){ private FieldSet CloneForMultiplicity2(List<String> key, Map<String, Object> properties,String[] ids, int index){
FieldSet newFieldSet = new FieldSet(); FieldSet newFieldSet = new FieldSet();
newFieldSet.id = ids[0]+"_"+ids[1]+"_"+ids[2]; newFieldSet.id = ids[0]+"_"+ids[1]+"_"+ids[2] + (ids.length > 4 ? "_" + ids[3] : "");
newFieldSet.description = this.description; newFieldSet.description = this.description;
newFieldSet.extendedDescription = this.extendedDescription; newFieldSet.extendedDescription = this.extendedDescription;
newFieldSet.additionalInformation=this.additionalInformation; newFieldSet.additionalInformation=this.additionalInformation;
newFieldSet.title = this.title; newFieldSet.title = this.title;
newFieldSet.ordinal = this.ordinal; newFieldSet.ordinal = ids.length > 4 ? Integer.valueOf(ids[3]) : this.ordinal;
newFieldSet.fields = new LinkedList(); newFieldSet.fields = new LinkedList();
for (Field field: this.fields) { for (Field field: this.fields) {

View File

@ -196,7 +196,7 @@ export class DatasetDescriptionCompositeFieldEditorModel extends BaseFormModel {
cloneForMultiplicity(item: CompositeField, ordinal: number, idMappings:{old:string, new:string}[] = []): DatasetDescriptionCompositeFieldEditorModel { cloneForMultiplicity(item: CompositeField, ordinal: number, idMappings:{old:string, new:string}[] = []): DatasetDescriptionCompositeFieldEditorModel {
const newItem: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel(); const newItem: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel();
newItem.id = 'multiple_' + item.id + '_' + Guid.create(); newItem.id = 'multiple_' + item.id + '_' + Guid.create() + '_' + ordinal;
idMappings.push({old: item.id, new: newItem.id }); idMappings.push({old: item.id, new: newItem.id });
item.fields.forEach((field, index) => { item.fields.forEach((field, index) => {