Skip to content

Commit 77bb444

Browse files
author
Open Lowcode SAS
committed
Close #122
1 parent 3ba2159 commit 77bb444

File tree

1 file changed

+72
-11
lines changed

1 file changed

+72
-11
lines changed

src/org/openlowcode/server/data/helpers/ReportTree.java

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.ArrayList;
1717
import java.util.Collections;
1818
import java.util.HashMap;
19+
import java.util.List;
1920
import java.util.Set;
2021
import java.util.logging.Logger;
2122

@@ -104,6 +105,27 @@ public interface Consolidator<E extends DataObject<E>> {
104105
public void consolidate(E parent, E child);
105106
}
106107

108+
/**
109+
* A complex consolidator will be called after all data has been entered, and
110+
* allows to perform consolidation with all data known. Compared to
111+
* consolidator, this should be used for algorithms that need all data present
112+
*
113+
* @author <a href="https://openlowcode.com/" rel="nofollow">Open Lowcode
114+
* SAS</a>
115+
*
116+
* @param <E> report data object
117+
*/
118+
@FunctionalInterface
119+
public interface ComplexConsolidator<E extends DataObject<E>> {
120+
/**
121+
* consolidates the parent on all children
122+
*
123+
* @param parent parent node
124+
* @param allchildren all children of the parent node
125+
*/
126+
public void consolidateWithFullData(E parent, List<E> allchildren);
127+
}
128+
107129
/**
108130
* feature to initiate a new report object
109131
*
@@ -284,7 +306,10 @@ public static String printBigDecimal(BigDecimal decimal, int scale) {
284306
* @param extractor extractor of the value on the object
285307
* @param setter setter of the value on the object
286308
*/
287-
public static <E extends DataObject<E>> void sumInparent(E parent, E child, ValueExtractor<E, BigDecimal> extractor,
309+
public static <E extends DataObject<E>> void sumInparent(
310+
E parent,
311+
E child,
312+
ValueExtractor<E, BigDecimal> extractor,
288313
ValueSetter<E, BigDecimal> setter) {
289314
BigDecimal parentvalue = extractor.extract(parent);
290315
BigDecimal childvalue = extractor.extract(child);
@@ -301,8 +326,11 @@ public static <E extends DataObject<E>> void sumInparent(E parent, E child, Valu
301326
* @param extractor extractor of the value on the object
302327
* @param setter setter of the value on the object
303328
*/
304-
public static <E extends DataObject<E>> void sumInparent(E parent, BigDecimal childvalue,
305-
ValueExtractor<E, BigDecimal> extractor, ValueSetter<E, BigDecimal> setter) {
329+
public static <E extends DataObject<E>> void sumInparent(
330+
E parent,
331+
BigDecimal childvalue,
332+
ValueExtractor<E, BigDecimal> extractor,
333+
ValueSetter<E, BigDecimal> setter) {
306334
BigDecimal parentvalue = extractor.extract(parent);
307335
setter.set(parent, sumIfNotNull(parentvalue, childvalue));
308336
logger.finer(
@@ -319,6 +347,7 @@ public interface Enricher<E extends DataObject<E>> {
319347

320348
private Namesetter<E> namesetter;
321349
private Consolidator<E>[] consolidators;
350+
private ComplexConsolidator<E> complexconsolidator;
322351
private ValueExtractor<E, String> nameextractor;
323352
private Initiator<E> initiator;
324353

@@ -332,8 +361,12 @@ public interface Enricher<E extends DataObject<E>> {
332361
* @param initiator initiator to set the root node
333362
* @param rootname root node name
334363
*/
335-
public ReportTree(DataObjectDefinition<E> objectdefinition, Namesetter<E> namesetter,
336-
ValueExtractor<E, String> nameextractor, Consolidator<E>[] consolidators, Initiator<E> initiator,
364+
public ReportTree(
365+
DataObjectDefinition<E> objectdefinition,
366+
Namesetter<E> namesetter,
367+
ValueExtractor<E, String> nameextractor,
368+
Consolidator<E>[] consolidators,
369+
Initiator<E> initiator,
337370
String rootname) {
338371
this(objectdefinition, namesetter, nameextractor, consolidators, rootname);
339372
this.initiator = initiator;
@@ -349,8 +382,12 @@ public ReportTree(DataObjectDefinition<E> objectdefinition, Namesetter<E> namese
349382
* @param consolidator data consolidators
350383
* @param rootname root node name
351384
*/
352-
public ReportTree(DataObjectDefinition<E> objectdefinition, Namesetter<E> namesetter,
353-
ValueExtractor<E, String> nameextractor, Consolidator<E>[] consolidators, String rootname) {
385+
public ReportTree(
386+
DataObjectDefinition<E> objectdefinition,
387+
Namesetter<E> namesetter,
388+
ValueExtractor<E, String> nameextractor,
389+
Consolidator<E>[] consolidators,
390+
String rootname) {
354391
this.objectdefinition = objectdefinition;
355392
this.namesetter = namesetter;
356393
this.consolidators = consolidators;
@@ -372,8 +409,12 @@ public ReportTree(DataObjectDefinition<E> objectdefinition, Namesetter<E> namese
372409
* @param initiator initiator to set the root node
373410
* @param rootname root node name
374411
*/
375-
public ReportTree(DataObjectDefinition<E> objectdefinition, Namesetter<E> namesetter,
376-
ValueExtractor<E, String> nameextractor, Consolidator<E> uniqueconsolidator, Initiator<E> initiator,
412+
public ReportTree(
413+
DataObjectDefinition<E> objectdefinition,
414+
Namesetter<E> namesetter,
415+
ValueExtractor<E, String> nameextractor,
416+
Consolidator<E> uniqueconsolidator,
417+
Initiator<E> initiator,
377418
String rootname) {
378419
this(objectdefinition, namesetter, nameextractor, uniqueconsolidator, rootname);
379420
this.initiator = initiator;
@@ -390,8 +431,12 @@ public ReportTree(DataObjectDefinition<E> objectdefinition, Namesetter<E> namese
390431
* @param rootname root node name
391432
*/
392433
@SuppressWarnings("unchecked")
393-
public ReportTree(DataObjectDefinition<E> objectdefinition, Namesetter<E> namesetter,
394-
ValueExtractor<E, String> nameextractor, Consolidator<E> uniqueconsolidator, String rootname) {
434+
public ReportTree(
435+
DataObjectDefinition<E> objectdefinition,
436+
Namesetter<E> namesetter,
437+
ValueExtractor<E, String> nameextractor,
438+
Consolidator<E> uniqueconsolidator,
439+
String rootname) {
395440
this.objectdefinition = objectdefinition;
396441
this.namesetter = namesetter;
397442
this.consolidators = new Consolidator[] { uniqueconsolidator };
@@ -403,6 +448,16 @@ public ReportTree(DataObjectDefinition<E> objectdefinition, Namesetter<E> namese
403448
this.initiator = null;
404449
}
405450

451+
/**
452+
* adds a complex consolidator
453+
*
454+
* @param complexconsolidator complex consolidator to be applied after all data
455+
* entered
456+
*/
457+
public void addComplexConsolidator(ComplexConsolidator<E> complexconsolidator) {
458+
this.complexconsolidator = complexconsolidator;
459+
}
460+
406461
/**
407462
* This method will add the given object as a node if it has a label. If it does
408463
* not have a label, the value will be rolled-up into the parent of the last
@@ -523,6 +578,12 @@ private void rollupamount(Node parentnode, int circuitbreaker) {
523578
rollupamount(childnode, circuitbreaker + 1);
524579
for (int j = 0; j < this.consolidators.length; j++)
525580
consolidators[j].consolidate(parentnode.element, childnode.element);
581+
582+
}
583+
if (complexconsolidator!=null) {
584+
ArrayList<E> allchildren = new ArrayList<E>();
585+
for (int i=0;i<orderedchildrenkeys.size();i++) allchildren.add(parentnode.getChild(orderedchildrenkeys.get(i)).getElement());
586+
complexconsolidator.consolidateWithFullData(parentnode.element,allchildren);
526587
}
527588

528589
}

0 commit comments

Comments
 (0)