Skip to content

Commit 14519ae

Browse files
author
Open Lowcode SAS
committed
Close #220 #221
1 parent 8974954 commit 14519ae

File tree

5 files changed

+177
-58
lines changed

5 files changed

+177
-58
lines changed

src/org/openlowcode/client/graphic/widget/table/EditableTreeTable.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ private void resize() {
490490
});
491491

492492
ObservableList<TreeTableColumn<EditableTreeTableLineItem<Wrapper<E>>, ?>> columns = treetableview.getColumns();
493-
int totalwidth = 0;
494493
for (int i=0;i<columns.size();i++) {
495494
columns.get(i).widthProperty().addListener(new ChangeListener<Number>() {
496495

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void setDependentPropertyLinkedfromchildren(Linkedfromchildren<E, F> rela
5858
* Creates the property
5959
*
6060
* @param definition definition of the property
61-
* @param parentpayload pâyload of the parent object
61+
* @param parentpayload payload of the parent object
6262
*/
6363
public Hasmultidimensionalchild(
6464
HasmultidimensionalchildDefinition<E, F> definition,

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

Lines changed: 110 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import org.openlowcode.server.data.properties.multichild.MultidimensionchildHelper;
2727

2828
/**
29-
* A helper to manage the loading of objects with the Hasmultidimensionalchild property
29+
* A helper to manage the loading of objects with the Hasmultidimensionalchild
30+
* property
3031
*
3132
* @author <a href="https://openlowcode.com/" rel="nofollow">Open Lowcode
3233
* SAS</a>
@@ -62,11 +63,11 @@ public void setPayloadHelper(MultichildValueHelper<F, ?, E> payloadhelper) {
6263
public MultichildValueHelper<F, ?, E> getPayloadHelper() {
6364
return this.payloadhelper;
6465
}
65-
66+
6667
/**
6768
* @return
6869
*/
69-
public MultichildValueHelper<F,?,E> getMainValueHelper() {
70+
public MultichildValueHelper<F, ?, E> getMainValueHelper() {
7071
return this.mainvaluehelper;
7172
}
7273

@@ -82,8 +83,6 @@ public HasmultidimensionalchildFlatFileLoaderHelper(
8283
payloadhelper = helper.getPayloadValueHelper();
8384
}
8485

85-
86-
8786
@Override
8887
public FlatFileLoaderColumn<E> getFlatFileLoaderColumn(
8988
DataObjectDefinition<E> objectdefinition,
@@ -108,23 +107,26 @@ public FlatFileLoaderColumn<E> getFlatFileLoaderColumn(
108107
if (columnattributes.length >= 2) {
109108
if (maincolumnattribute.equals(this.mainvaluehelper.getFieldName())) {
110109
String maincolumnvalue = columnattributes[1];
111-
String[] extraattributes =null;
112-
if (columnattributes.length>2) {
113-
extraattributes = new String[columnattributes.length-2];
114-
for (int i=0;i<columnattributes.length-2;i++) extraattributes[i] = columnattributes[i+2];
110+
String[] extraattributes = null;
111+
if (columnattributes.length > 2) {
112+
extraattributes = new String[columnattributes.length - 2];
113+
for (int i = 0; i < columnattributes.length - 2; i++)
114+
extraattributes[i] = columnattributes[i + 2];
115115
}
116-
117-
return mainvaluehelper.new MainValueFlatFileLoader(this, locale, maincolumnvalue,payloadhelper,extraattributes);
116+
117+
return mainvaluehelper.new MainValueFlatFileLoader(this, locale, maincolumnvalue, payloadhelper,
118+
extraattributes);
118119
}
119120
}
120121
if (maincolumnattribute.equals("#TOTAL#")) {
121122
logger.finest(" >>> get total flat file loader");
122-
String[] extraattributes =null;
123-
if (columnattributes.length>1) {
124-
extraattributes = new String[columnattributes.length-1];
125-
for (int i=0;i<columnattributes.length-1;i++) extraattributes[i] = columnattributes[i+1];
123+
String[] extraattributes = null;
124+
if (columnattributes.length > 1) {
125+
extraattributes = new String[columnattributes.length - 1];
126+
for (int i = 0; i < columnattributes.length - 1; i++)
127+
extraattributes[i] = columnattributes[i + 1];
126128
}
127-
return this.payloadhelper.new MainValueTotalFlatFileLoader(this,locale,payloadhelper,extraattributes);
129+
return this.payloadhelper.new MainValueTotalFlatFileLoader(this, locale, payloadhelper, extraattributes);
128130
}
129131
potentialattributes.append(',');
130132
potentialattributes.append(mainvaluehelper.getFieldName());
@@ -160,8 +162,8 @@ public void executeAtEndOfLine(E objecforprocessing) {
160162

161163
}
162164

163-
public String getDebugForLineAndColumnKey(String linekey,String columnkey) {
164-
if (childrenbykey.get(linekey)==null) {
165+
public String getDebugForLineAndColumnKey(String linekey, String columnkey) {
166+
if (childrenbykey.get(linekey) == null) {
165167
StringBuffer droplinekey = new StringBuffer(" Line key not existing, given value = ");
166168
droplinekey.append(linekey);
167169
droplinekey.append(", valid keys = ");
@@ -184,18 +186,18 @@ public String getDebugForLineAndColumnKey(String linekey,String columnkey) {
184186
droplinekey.append(' ');
185187
}
186188
return droplinekey.toString();
187-
188-
189+
189190
}
190-
191+
191192
public ArrayList<F> getChildrenForLine(String linekey) {
192193
Iterator<F> values = childrenbykey.get(linekey).values().iterator();
193194
ArrayList<F> valueslist = new ArrayList<F>();
194-
while (values.hasNext()) valueslist.add(values.next());
195+
while (values.hasNext())
196+
valueslist.add(values.next());
195197
return valueslist;
196-
198+
197199
}
198-
200+
199201
public F getChildForLineAndColumnKey(String linekey, String columnkey) {
200202
if (childrenbykey == null) {
201203
StringBuffer error = new StringBuffer("Children list not initiated for linekey = " + linekey
@@ -219,57 +221,63 @@ public F getFirstChildForLineKey(String key) {
219221
return childrenbykey.get(key).values().iterator().next();
220222
}
221223

224+
private void putChildInKeyMap(E currentobject,F child) {
225+
String keyforchild = this.helper.generateKeyForObject(child, true);
226+
227+
HashMap<String, F> currentobjectsforkey = childrenbykey.get(keyforchild);
228+
if (currentobjectsforkey == null) {
229+
currentobjectsforkey = new HashMap<String, F>();
230+
childrenbykey.put(keyforchild, currentobjectsforkey);
231+
logger.finest("--- adding child map for key " + keyforchild);
232+
}
233+
String mainvalue = this.helper.getMainValueHelper().getAndPrint(child);
234+
F current = currentobjectsforkey.get(mainvalue);
235+
if (current != null)
236+
logger.warning(" -- Duplicate child for secondary key = " + keyforchild + " for main value "
237+
+ mainvalue + " for object = " + currentobject.dropIdToString());
238+
if (current == null) {
239+
currentobjectsforkey.put(mainvalue, child);
240+
logger.finest(" adding element for primary " + keyforchild + " secondary " + mainvalue + " for id "
241+
+ child.dropIdToString());
242+
}
243+
}
244+
222245
public void initColumnsForObject(E currentobject) {
223246
F[] children = hasmultidimensionalchilddefinition.getChildren(currentobject.getId());
224-
logger.finest(" ---------------- Generating keys for "+currentobject.dropIdToString()+" - "+(children!=null?children.length:"NULL")+" child(ren)---------------------------");
247+
logger.finest(" ---------------- Generating keys for " + currentobject.dropIdToString() + " - "
248+
+ (children != null ? children.length : "NULL") + " child(ren)---------------------------");
225249
childrenbykey = new HashMap<String, HashMap<String, F>>();
226250
for (int i = 0; i < children.length; i++) {
227251
F child = children[i];
228-
String keyforchild = this.helper.generateKeyForObject(child, true);
229-
230-
HashMap<String, F> currentobjectsforkey = childrenbykey.get(keyforchild);
231-
if (currentobjectsforkey == null) {
232-
currentobjectsforkey = new HashMap<String, F>();
233-
childrenbykey.put(keyforchild, currentobjectsforkey);
234-
logger.finest("--- adding child map for key "+keyforchild);
235-
}
236-
String mainvalue = this.helper.getMainValueHelper().getAndPrint(child);
237-
F current = currentobjectsforkey.get(mainvalue);
238-
if (current != null)
239-
logger.warning(" -- Duplicate child for secondary key = " + keyforchild + " for main value "
240-
+ mainvalue + " for object = " + currentobject.dropIdToString());
241-
if (current == null) {
242-
currentobjectsforkey.put(mainvalue, child);
243-
logger.finest(" adding element for primary "+keyforchild+" secondary "+mainvalue+" for id "+child.dropIdToString());
244-
}
252+
this.putChildInKeyMap(currentobject, child);
245253
}
246254

247255
}
248256

249257
public String[] generateKeyAndLoadExistingData(E currentobject) {
250-
258+
251259
// Find why two logics with children in initColumn and method below
252260
initColumnsForObject(currentobject);
253261
F[] children = hasmultidimensionalchilddefinition.getChildren(currentobject.getId());
254-
HashMap<String,String> classificationkeys = new HashMap<String,String>();
262+
HashMap<String, String> classificationkeys = new HashMap<String, String>();
255263
for (int i = 0; i < children.length; i++) {
256264
F child = children[i];
257265
String keyforchild = this.helper.generateKeyForObject(child, true);
258-
classificationkeys.put(keyforchild,keyforchild);
266+
classificationkeys.put(keyforchild, keyforchild);
259267
}
260268
Set<String> keys = classificationkeys.keySet();
261269
Iterator<String> keyiterator = keys.iterator();
262270
logger.finest(" ---------------- key drop -------------------");
263-
while (keyiterator.hasNext()) logger.finest(" key "+keyiterator.next());
271+
while (keyiterator.hasNext())
272+
logger.finest(" key " + keyiterator.next());
264273
logger.finest(" ----------------------------------------");
265274
return keys.toArray(new String[0]);
266275

267276
}
268277

269278
private ArrayList<String> secondaryvalues = new ArrayList<String>();
270279
private E contextobject = null;
271-
272-
280+
273281
public void setSecondaryValueForLoading(int index, String string) {
274282
if (secondaryvalues.size() <= index)
275283
for (int i = secondaryvalues.size(); i < index + 1; i++)
@@ -287,17 +295,66 @@ public String getContextKey() {
287295
}
288296

289297
public void setContext(E object) {
290-
boolean same=false;
291-
if (contextobject!=null) {
298+
boolean same = false;
299+
if (contextobject != null) {
292300
if (object.getId().equals(contextobject.getId())) {
293-
same=true;
301+
same = true;
294302
}
295303
}
296304
if (!same) {
297-
contextobject=object;
305+
contextobject = object;
298306
this.initColumnsForObject(contextobject);
299307
}
300-
308+
309+
}
310+
311+
/**
312+
* generates a new row of objects for the given context, and inserts them.
313+
*
314+
* @param parent parent object for generating new row
315+
* @param extraattributes
316+
* @param applocale
317+
* @return true if the new row for context could be generated, false else
318+
*/
319+
public boolean generateNewRowForContext(
320+
E parent,
321+
ChoiceValue<ApplocaleChoiceDefinition> applocale,
322+
String[] extraattributes) {
323+
boolean iscontextvalid = true;
324+
logger.fine("---------------------- generate new row for context ----------------");
325+
for (int i = 0; i < secondaryvalues.size(); i++) {
326+
String value = secondaryvalues.get(i);
327+
logger.fine(" > Evaluating value "+value);
328+
MultichildValueHelper<F, ?, E> helper = secondvaluehelpers.get(i);
329+
boolean valid = helper.isTextValid(value, applocale, extraattributes);
330+
if (!valid) {
331+
logger.fine(" !!! INVALID !!! ");
332+
iscontextvalid = false;
333+
}
334+
}
335+
if (!iscontextvalid)
336+
return false;
337+
DataObjectDefinition<F> childdefinition = this.hasmultidimensionalchilddefinition
338+
.getRelatedDefinitionLinkedFromChildren().getChildObjectDefinition();
339+
F firstblank = childdefinition.generateBlank();
340+
for (int i = 0; i < secondaryvalues.size(); i++) {
341+
String value = secondaryvalues.get(i);
342+
MultichildValueHelper<F, ?, E> helper = secondvaluehelpers.get(i);
343+
helper.fillWithValue(firstblank, value, applocale, extraattributes);
344+
}
345+
logger.fine(" -> First blank = "+firstblank.dropToString());
346+
ArrayList<F> newobjects = mainvaluehelper.generateElementsForAllMandatory(firstblank,parent);
347+
logger.fine("Generating elements number = "+(newobjects==null?"null":newobjects.size()));
348+
if (newobjects!=null) if (newobjects.size()>0) {
349+
for (int i=0;i<newobjects.size();i++) {
350+
F newobject = newobjects.get(i);
351+
newobject.setmultidimensionparentidwithoutupdate(parent.getId());
352+
putChildInKeyMap(parent,newobject);
353+
}
354+
newobjects.get(0).getMassiveInsert().insert(newobjects.toArray(childdefinition.generateArrayTemplate()));
355+
356+
}
357+
return true;
301358
}
302359

303360
}

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

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,22 @@ public void fillCell(Cell cell, E object, String[] extraattributes) {
230230
this.cellfiller.apply(cell, extraattributes, this.getter.apply(object));
231231
}
232232

233+
/**
234+
* @param cell
235+
* @param parsedvalue
236+
* @param locale
237+
* @param extraattributes
238+
* @since 1.12
239+
*/
240+
public void fillWithValue(
241+
E object,
242+
String parsedvalue,
243+
ChoiceValue<ApplocaleChoiceDefinition> locale,
244+
String[] extraattributes) {
245+
F payload = this.payloadparser.apply(parsedvalue, locale, extraattributes);
246+
this.setter.accept(object, payload);
247+
}
248+
233249
/**
234250
* @param cell
235251
* @param value
@@ -531,8 +547,16 @@ public boolean load(G object, Object value, PostUpdateProcessingStore<G> postupd
531547
E relevantchild = helper.getChildForLineAndColumnKey(helpercontextkey,
532548
MultichildValueHelper.this.print(mainvalue));
533549
if (relevantchild == null) {
534-
throw new RuntimeException("Did not find existing child for key, debug = " + helper
535-
.getDebugForLineAndColumnKey(helpercontextkey, MultichildValueHelper.this.print(mainvalue)));
550+
551+
boolean valid = helper.generateNewRowForContext(object, applocale, extraattributes);
552+
if (valid) {
553+
relevantchild = helper.getChildForLineAndColumnKey(helpercontextkey,
554+
MultichildValueHelper.this.print(mainvalue));
555+
} else
556+
557+
throw new RuntimeException(
558+
"Did not find existing child for key, debug = " + helper.getDebugForLineAndColumnKey(
559+
helpercontextkey, MultichildValueHelper.this.print(mainvalue)));
536560
}
537561
return this.payloadhelper.LoadIfDifferent(relevantchild, value, applocale, extraattributes);
538562

@@ -565,6 +589,8 @@ protected boolean putContentInCell(G currentobject, Cell cell, String context) {
565589
* @since 1.12
566590
*/
567591
public boolean isValid(E optionalorinvalid) {
592+
if (this.allowothervalues())
593+
return true;
568594
F value = getter.apply(optionalorinvalid);
569595
F[] mandatoryvalues = this.getMandatoryValues();
570596
F[] optionalvalues = this.getOptionalValues();
@@ -577,6 +603,41 @@ public boolean isValid(E optionalorinvalid) {
577603
return false;
578604
}
579605

606+
public boolean isTextValid(
607+
String text,
608+
ChoiceValue<ApplocaleChoiceDefinition> applocale,
609+
String[] extraattributes) {
610+
F payload = payloadparser.apply(text, applocale, extraattributes);
611+
if (this.allowothervalues())
612+
return true;
613+
F[] mandatoryvalues = this.getMandatoryValues();
614+
F[] optionalvalues = this.getOptionalValues();
615+
for (int i = 0; i < mandatoryvalues.length; i++)
616+
if (payload.equals(mandatoryvalues[i]))
617+
return true;
618+
for (int i = 0; i < optionalvalues.length; i++)
619+
if (payload.equals(optionalvalues[i]))
620+
return true;
621+
return false;
622+
}
623+
624+
/**
625+
* @param thisoptional
626+
* @return
627+
* @since 1.12
628+
*/
629+
public ArrayList<E> generateElementsForAllMandatory(E thisoptional, G thisparent) {
630+
ArrayList<E> returnelements = new ArrayList<E>();
631+
this.setContext(thisparent);
632+
F[] allmandatories = this.getMandatoryValues();
633+
for (int i = 0; i < allmandatories.length; i++) {
634+
E thischild = thisoptional.deepcopy();
635+
setter.accept(thischild, allmandatories[i]);
636+
returnelements.add(thischild);
637+
}
638+
return returnelements;
639+
}
640+
580641
/**
581642
* @param thisoptional
582643
* @param childrenbykey
@@ -601,7 +662,7 @@ public ArrayList<E> getMissingElementsForKey(
601662
while (existingvalues.hasNext()) {
602663
F value = existingvalues.next();
603664
E newoptional = thisoptional.deepcopy();
604-
payloadhelper.set(newoptional,null);
665+
payloadhelper.set(newoptional, null);
605666
this.setter.accept(newoptional, value);
606667
String keyforobject = multidimensionhelper.generateKeyForObject(newoptional);
607668
if (!childrenbykey.containsKey(keyforobject))

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,6 @@ public ArrayList<E> getOtherPrimaryelements(E thisoptional, HashMap<String, E> c
244244

245245

246246

247+
248+
247249
}

0 commit comments

Comments
 (0)