Skip to content

Commit 816d973

Browse files
author
Open Lowcode SAS
committed
Close #282 Close #284
1 parent 0c85fb4 commit 816d973

4 files changed

Lines changed: 155 additions & 9 deletions

File tree

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,20 @@ public void addlines(E object, F[] newlines) {
119119
childrenbykey.put(key, thischild);
120120
}
121121
ArrayList<F> allobjectstoinsert = new ArrayList<F>();
122+
122123
for (int i = 0; i < newlines.length; i++) {
123124
F thisline = newlines[i];
124-
boolean invalid = helper.isInvalid(thisline);
125-
if (!invalid) {
126-
ArrayList<F> missingforthisoptional = helper.getOtherPrimaryelements(thisline, childrenbykey);
127-
for (int j = 0; j < missingforthisoptional.size(); j++) {
128-
F thismissing = missingforthisoptional.get(j);
129-
allobjectstoinsert.add(thismissing);
130-
childrenbykey.put(helper.generateKeyForObject(thismissing), thismissing);
131-
132-
}
125+
boolean valid = helper.isValidOrVoid(thisline);
126+
if (valid) {
127+
ArrayList<F> multipliedlines = helper.multiplyforvoidfields(thisline,previouschildren);
128+
for (int j=0;j<multipliedlines.size();j++) {
129+
ArrayList<F> missingforthisoptional = helper.getOtherPrimaryelements(multipliedlines.get(j), childrenbykey);
130+
for (int k = 0; k < missingforthisoptional.size(); k++) {
131+
F thismissing = missingforthisoptional.get(k);
132+
allobjectstoinsert.add(thismissing);
133+
childrenbykey.put(helper.generateKeyForObject(thismissing), thismissing);
134+
}
135+
}
133136
}
134137
}
135138

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,5 +720,9 @@ public ArrayList<E> getMissingElementsForKey(
720720
}
721721
return missingvalues;
722722
}
723+
724+
public SecondaryValueSelection<E,F,G> getSecondaryValueSelectionForField() {
725+
return new SecondaryValueSelection<E,F,G>(this);
726+
}
723727

724728
}

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,59 @@ public BiConsumer<E, E> getConsolidator() {
215215

216216

217217

218+
/**
219+
* Specific treatment for new lines.
220+
*
221+
* @param newline
222+
* @return true if the element has at least one valid criteria and null criterias (no invalid criteria)
223+
* @since 1.15
224+
*/
225+
public boolean isValidOrVoid(E newline) {
226+
boolean hasonevalidelement=false;
227+
for (int i=0;i<this.secondarycriteriavaluehelpers.size();i++) {
228+
MultichildValueHelper<E, ?, F> helper = this.secondarycriteriavaluehelpers.get(i);
229+
if (!helper.allowUserValue()) if (!helper.allowothervalues()) {
230+
boolean isvalid = helper.isValid(newline);
231+
if (isvalid) hasonevalidelement=true;
232+
if (!isvalid) if (helper.get(newline)!=null) return false;
233+
}
234+
}
235+
if (hasonevalidelement) return true;
236+
return false;
237+
}
238+
239+
/**
240+
* Multiply the blank objects
241+
*
242+
* @param thisline
243+
* @param previouschildren
244+
* @return
245+
* @since 1.15
246+
*/
247+
public ArrayList<E> multiplyforvoidfields(E thisline, E[] previouschildren) {
248+
ArrayList<E> newlines = new ArrayList<E>();
249+
boolean hasonenullcriteria=false;
250+
for (int i=0;i<this.secondarycriteriavaluehelpers.size();i++) {
251+
MultichildValueHelper<E, ?, F> helper = this.secondarycriteriavaluehelpers.get(i);
252+
if (helper.get(thisline)==null) hasonenullcriteria=true;
253+
}
254+
if (!hasonenullcriteria) newlines.add(thisline);
255+
if (hasonenullcriteria) {
256+
257+
newlines.add(thisline);
258+
for (int i=0;i<this.secondarycriteriavaluehelpers.size();i++) {
259+
MultichildValueHelper<E, ?, F> helper = this.secondarycriteriavaluehelpers.get(i);
260+
if (helper.get(thisline)==null) {
261+
SecondaryValueSelection<E, ?, F> secondaryvalueselection = helper.getSecondaryValueSelectionForField();
262+
secondaryvalueselection.GetAllValuesFromExistingObjects(previouschildren);
263+
newlines = secondaryvalueselection.createclonesforallvalues(newlines);
264+
}
265+
}
266+
}
267+
return newlines;
268+
269+
}
270+
218271
/**
219272
* @param a child object
220273
* @return true if invalid
@@ -246,4 +299,6 @@ public ArrayList<E> getOtherPrimaryelements(E thisoptional, HashMap<String, E> c
246299

247300

248301

302+
303+
249304
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/********************************************************************************
2+
* Copyright (c) 2020 [Open Lowcode SAS](https://openlowcode.com/)
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0 .
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
********************************************************************************/
10+
11+
package org.openlowcode.server.data.properties.multichild;
12+
13+
import java.util.ArrayList;
14+
import java.util.HashMap;
15+
import java.util.Iterator;
16+
import java.util.Map.Entry;
17+
18+
import org.openlowcode.server.data.DataObject;
19+
import org.openlowcode.server.data.properties.MultidimensionchildInterface;
20+
import org.openlowcode.server.data.properties.UniqueidentifiedInterface;
21+
22+
/**
23+
* A class holding a selection of secondary values
24+
*
25+
* @author <a href="https://openlowcode.com/" rel="nofollow">Open Lowcode
26+
* SAS</a>
27+
*
28+
* @param <E> type of child object
29+
* @param <F> payload of the field
30+
* @param <G> type of the parent object (or any other object to be used)
31+
* @since 1.15
32+
*/
33+
public class SecondaryValueSelection<
34+
E extends DataObject<E> & UniqueidentifiedInterface<E> & MultidimensionchildInterface<E, G>,
35+
F extends Object,
36+
G extends DataObject<G> & UniqueidentifiedInterface<G>> {
37+
private MultichildValueHelper<E,F,G> valuehelper;
38+
private HashMap<String,F> existingvalues;
39+
/**
40+
* Creates a secondary value selection for the secondary field
41+
*
42+
* @param valuehelper secondary field helper
43+
*/
44+
public SecondaryValueSelection(MultichildValueHelper<E,F,G> valuehelper) {
45+
this.valuehelper = valuehelper;
46+
}
47+
48+
/**
49+
* Initializes the object with all the values present in the existing objects
50+
*
51+
* @param existingobjects all existing children of the parent for the Multidimensionchild
52+
*/
53+
public void GetAllValuesFromExistingObjects(E[] existingobjects) {
54+
existingvalues = new HashMap<String,F>();
55+
if (existingobjects!=null) for (int i=0;i<existingobjects.length;i++) {
56+
E existingobject = existingobjects[i];
57+
F value = valuehelper.get(existingobject);
58+
if (value!=null) existingvalues.put(valuehelper.print(value), value);
59+
}
60+
}
61+
62+
/**
63+
* multiplies the objects given in entry setting one value
64+
*
65+
* @param entryvalues entry values
66+
* @return one clone per value from existing object for the
67+
*/
68+
public ArrayList<E> createclonesforallvalues(ArrayList<E> entryvalues) {
69+
ArrayList<E> newvalues = new ArrayList<E>();
70+
for (int i=0;i<entryvalues.size();i++) {
71+
E originvalue = entryvalues.get(i);
72+
Iterator<Entry<String, F>> valuesiterator = existingvalues.entrySet().iterator();
73+
while (valuesiterator.hasNext()) {
74+
F valueforfield = valuesiterator.next().getValue();
75+
E copy = originvalue.deepcopy();
76+
valuehelper.set(copy, valueforfield);
77+
newvalues.add(copy);
78+
}
79+
80+
}
81+
return newvalues;
82+
}
83+
84+
}

0 commit comments

Comments
 (0)