Skip to content

Commit 270f6ac

Browse files
author
Open Lowcode SAS
committed
Close #280
1 parent 8adc13d commit 270f6ac

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

src/org/openlowcode/server/data/properties/HasmultidimensionalchildFlatFileLoaderHelper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public FlatFileLoaderColumn<E> getFlatFileLoaderColumn(
107107
if (columnattributes.length >= 2) {
108108
if (maincolumnattribute.equals(this.mainvaluehelper.getFieldName())) {
109109
String maincolumnvalue = columnattributes[1];
110+
110111
String[] extraattributes = null;
111112
if (columnattributes.length > 2) {
112113
extraattributes = new String[columnattributes.length - 2];
@@ -333,6 +334,9 @@ public boolean generateNewRowForContext(
333334
iscontextvalid = false;
334335
}
335336
}
337+
338+
339+
336340
if (!iscontextvalid)
337341
return false;
338342
DataObjectDefinition<F> childdefinition = this.hasmultidimensionalchilddefinition
@@ -344,7 +348,8 @@ public boolean generateNewRowForContext(
344348
helper.fillWithValue(firstblank, value, applocale, extraattributes);
345349
}
346350
logger.fine(" -> First blank = "+firstblank.dropToString());
347-
ArrayList<F> newobjects = mainvaluehelper.generateElementsForAllMandatory(firstblank,parent);
351+
352+
ArrayList<F> newobjects = mainvaluehelper.generateElementsForAllMandatory(firstblank,parent,helper,childrenbykey);
348353
logger.fine("Generating elements number = "+(newobjects==null?"null":newobjects.size()));
349354
if (newobjects!=null) if (newobjects.size()>0) {
350355
for (int i=0;i<newobjects.size();i++) {

src/org/openlowcode/server/data/properties/multichild/MultichildValueHelper.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,20 @@ public String getAndPrint(E object) {
279279
* @return the mandatory values required for this field
280280
*/
281281
public abstract F[] getMandatoryValues();
282+
283+
/**
284+
* Returns true if the value is part of mandatory values
285+
*
286+
* @param mainvalue the value
287+
* @return
288+
*/
289+
public boolean isIsMandatory(Object mainvalue) {
290+
F[] mandatoryvalues = getMandatoryValues();
291+
if (mandatoryvalues!=null) for (int i=0;i<mandatoryvalues.length;i++) {
292+
if (mandatoryvalues[i]!=null) if (mandatoryvalues[i].equals(mainvalue)) return true;
293+
}
294+
return false;
295+
}
282296

283297
/**
284298
* gets the optional values that have to exist for this field on the list of
@@ -464,7 +478,6 @@ public class MainValueTotalFlatFileLoader
464478
private HasmultidimensionalchildFlatFileLoaderHelper<G, E> helper;
465479
@SuppressWarnings("unused")
466480
private ChoiceValue<ApplocaleChoiceDefinition> applocale;
467-
@SuppressWarnings("unused")
468481
private MultichildValueHelper<E, F, G> payloadhelper;
469482
private String[] extraattributes;
470483
private MultichildValueHelper<E, ?, G> mainvaluehelper;
@@ -548,10 +561,12 @@ public boolean processAfterLineInsertion() {
548561
public boolean load(G object, Object value, PostUpdateProcessingStore<G> postupdateprocessingstore) {
549562
helper.setContext(object);
550563
String helpercontextkey = helper.getContextKey();
564+
helper.getMainValueHelper().setContext(object);
565+
if (!helper.getMainValueHelper().isIsMandatory(mainvalue)) throw new RuntimeException("Column is not valid: "+mainvalue);
551566
E relevantchild = helper.getChildForLineAndColumnKey(helpercontextkey,
552567
MultichildValueHelper.this.print(mainvalue));
553568
if (relevantchild == null) {
554-
569+
555570
boolean valid = helper.generateNewRowForContext(object, applocale, extraattributes);
556571
if (valid) {
557572
relevantchild = helper.getChildForLineAndColumnKey(helpercontextkey,
@@ -636,14 +651,19 @@ public boolean isTextValid(
636651
* @return
637652
* @since 1.12
638653
*/
639-
public ArrayList<E> generateElementsForAllMandatory(E thisoptional, G thisparent) {
654+
public ArrayList<E> generateElementsForAllMandatory(E thisoptional, G thisparent,MultidimensionchildHelper<E,G> helper,HashMap<String, HashMap<String, E>> childrenbykey) {
640655
ArrayList<E> returnelements = new ArrayList<E>();
641656
this.setContext(thisparent);
642657
F[] allmandatories = this.getMandatoryValues();
643658
for (int i = 0; i < allmandatories.length; i++) {
644659
E thischild = thisoptional.deepcopy();
645660
setter.accept(thischild, allmandatories[i]);
646-
returnelements.add(thischild);
661+
662+
String keyforchild = helper.generateKeyForObject(thischild, true);
663+
String mainvalue = helper.getMainValueHelper().getAndPrint(thischild);
664+
boolean alreadypresent=false;
665+
if (childrenbykey.containsKey(keyforchild)) if (childrenbykey.get(keyforchild).containsKey(mainvalue)) alreadypresent=true;
666+
if (!alreadypresent) returnelements.add(thischild);
647667
}
648668
return returnelements;
649669
}

0 commit comments

Comments
 (0)