@@ -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