Skip to content

Commit 59354cb

Browse files
author
Open Lowcode SAS
committed
Close #116
1 parent bab9204 commit 59354cb

File tree

2 files changed

+179
-1
lines changed

2 files changed

+179
-1
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package org.openlowcode.design.advanced;
2+
3+
import java.io.IOException;
4+
import java.util.ArrayList;
5+
6+
import org.openlowcode.design.data.DataObjectDefinition;
7+
import org.openlowcode.design.data.Field;
8+
import org.openlowcode.design.data.properties.basic.LinkObject;
9+
import org.openlowcode.design.generation.SourceGenerator;
10+
import org.openlowcode.design.generation.StringFormatter;
11+
12+
/**
13+
* This feature will group criteria by linked object. As an object may be linked
14+
* to several linked objects, classification is by the combination of linked
15+
* objects (e.g. : A - B - A,B - C - C,A)
16+
*
17+
* @author <a href="https://openlowcode.com/" rel="nofollow">Open Lowcode
18+
* SAS</a>
19+
*/
20+
public class LineGroupingCriteriaMultipleLink
21+
extends
22+
LineGroupingCriteria {
23+
24+
DataObjectDefinition uniquelinkobject;
25+
LinkObject<?, ?> linkobject;
26+
27+
/**
28+
* create a line grouping criteria for a multiple link. Objects will be regrouped
29+
* if they are linked to the same combination of right objects
30+
*
31+
* @param uniquelinkobject the unique link having the node object as left object
32+
*/
33+
public LineGroupingCriteriaMultipleLink(DataObjectDefinition uniquelinkobject) {
34+
this.uniquelinkobject = uniquelinkobject;
35+
if (uniquelinkobject == null)
36+
throw new RuntimeException("Uniquelinkobject cannot be null");
37+
if (uniquelinkobject.getPropertyByName("LINKOBJECT") == null)
38+
throw new RuntimeException("Object " + this.uniquelinkobject.getName() + " is not a link object");
39+
linkobject = (LinkObject<?, ?>) uniquelinkobject.getPropertyByName("LINKOBJECT");
40+
}
41+
42+
@Override
43+
public DataObjectDefinition getObject() {
44+
return linkobject.getLeftobjectforlink();
45+
}
46+
47+
@Override
48+
public boolean hasDataGathering() {
49+
return true;
50+
}
51+
52+
@Override
53+
public void writeDataGathering(SourceGenerator sg, String objectprefix) throws IOException {
54+
String linkobjectattribute = StringFormatter.formatForAttribute(linkobject.getParent().getName());
55+
String linkobjectclass = StringFormatter.formatForJavaClass(linkobject.getParent().getName());
56+
String leftobjectattribute = StringFormatter.formatForAttribute(linkobject.getLeftobjectforlink().getName());
57+
String leftobjectclass = StringFormatter.formatForJavaClass(linkobject.getLeftobjectforlink().getName());
58+
String rightobjectclass = StringFormatter.formatForJavaClass(linkobject.getRightobjectforlink().getName());
59+
sg.wl(" TwoDataObjects<" + linkobjectclass + "," + rightobjectclass + ">[] " + leftobjectattribute + "_step"
60+
+ objectprefix + "_linegrouping_" + linkobjectattribute + " = ");
61+
sg.wl(" " + linkobjectclass + ".getlinksandrightobject(" + leftobjectattribute + "_step"
62+
+ objectprefix + "_id, null);");
63+
sg.wl(" Function<DataObjectId<" + leftobjectclass + ">, String> " + leftobjectattribute + "_step"
64+
+ objectprefix + "_linegrouping_" + linkobjectattribute
65+
+ "_mapping = SmartReportUtility.getMultipleLinkNr(" + leftobjectattribute + "_step" + objectprefix
66+
+ "_linegrouping_" + linkobjectattribute + ");");
67+
68+
}
69+
70+
@Override
71+
protected String getExtractorFromobject(String objectprefix) {
72+
String linkobjectattribute = StringFormatter.formatForAttribute(linkobject.getParent().getName());
73+
String leftobjectattribute = StringFormatter.formatForAttribute(linkobject.getLeftobjectforlink().getName());
74+
return "(a)->(" + leftobjectattribute + "_step" + objectprefix + "_linegrouping_" + linkobjectattribute
75+
+ "_mapping.apply(a.getId()))";
76+
}
77+
78+
@Override
79+
public String[] getImportStatements() {
80+
ArrayList<String> importstatements = new ArrayList<String>();
81+
importstatements.add("import " + linkobject.getParent().getOwnermodule().getPath() + ".data."
82+
+ StringFormatter.formatForJavaClass(linkobject.getParent().getName()) + ";");
83+
importstatements.add("import " + linkobject.getRightobjectforlink().getOwnermodule().getPath() + ".data."
84+
+ StringFormatter.formatForJavaClass(linkobject.getRightobjectforlink().getName()) + ";");
85+
importstatements.add("import org.openlowcode.server.data.TwoDataObjects;");
86+
return importstatements.toArray(new String[0]);
87+
}
88+
89+
@Override
90+
protected void writeClassification(
91+
SourceGenerator sg,
92+
ObjectReportNode objectReportNode,
93+
String prefix,
94+
String extraindent) throws IOException {
95+
String linkname = StringFormatter.formatForAttribute(linkobject.getParent().getName());
96+
sg.wl(extraindent + " String " + linkname + " = "
97+
+ StringFormatter.formatForAttribute(objectReportNode.getRelevantObject().getName()) + "_step" + prefix
98+
+ "_linegrouping_" + linkname + "_mapping.apply(this"
99+
+ StringFormatter.formatForAttribute(objectReportNode.getRelevantObject().getName()) + "step" + prefix
100+
+ ".getId());");
101+
sg.wl(extraindent + " if (" + linkname + "!=null) step" + prefix + "classification.add("
102+
+ linkname + ");");
103+
104+
}
105+
106+
@Override
107+
public boolean isbacktobject() {
108+
return false;
109+
}
110+
111+
@Override
112+
protected void feedfields(ArrayList<Field> fieldlist, boolean before) {
113+
// donothin
114+
115+
}
116+
117+
@Override
118+
protected void writeFields(SourceGenerator sg, String prefix) throws IOException {
119+
// donothing
120+
121+
}
122+
123+
@Override
124+
public boolean needArrayOfObjectId() {
125+
return true;
126+
}
127+
128+
}

src/org/openlowcode/server/action/utility/SmartReportUtility.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
import java.util.Arrays;
1515
import java.util.Collections;
1616
import java.util.HashMap;
17+
import java.util.Iterator;
18+
import java.util.List;
1719
import java.util.function.Function;
1820
import java.util.logging.Logger;
1921

22+
import org.apache.commons.compress.utils.Lists;
2023
import org.openlowcode.server.data.DataObject;
2124
import org.openlowcode.server.data.DataObjectDefinition;
2225
import org.openlowcode.server.data.TwoDataObjects;
@@ -112,8 +115,10 @@ G extends DataObject<G> & UniqueidentifiedInterface<G> & NumberedInterface<G>> E
112115

113116
/**
114117
* provides a mapper that provides second object number from a first object id
118+
*
115119
* @param mapdata a combination of object pairs
116-
* @return a function that provides the number of the second object, given the id of the first object for a link
120+
* @return a function that provides the number of the second object, given the
121+
* id of the first object for a link
117122
*/
118123
public static <
119124
E extends DataObject<E>,
@@ -129,6 +134,51 @@ G extends DataObject<G> & NumberedInterface<G>> Function<DataObjectId<E>, String
129134
return (id) -> (filtermap.get(id));
130135
}
131136

137+
/**
138+
* provides a mapper that provides second object number from a first object id
139+
*
140+
* @param mapdata a combination of object pairs
141+
* @return a function that provides a string containing all the values of number
142+
* in the right object, with each value being ordered by alphabetic
143+
* number
144+
*/
145+
public static <
146+
E extends DataObject<E>,
147+
F extends DataObject<F> & LinkobjectInterface<F, E, G>,
148+
G extends DataObject<G> & NumberedInterface<G>> Function<DataObjectId<E>, String> getMultipleLinkNr(
149+
TwoDataObjects<F, G>[] mapdata) {
150+
151+
HashMap<DataObjectId<E>, ArrayList<String>> filtermap = new HashMap<DataObjectId<E>, ArrayList<String>>();
152+
153+
if (mapdata != null)
154+
for (int i = 0; i < mapdata.length; i++) {
155+
TwoDataObjects<F, G> thislink = mapdata[i];
156+
ArrayList<String> previous = filtermap.get(thislink.getObjectOne().getLfid());
157+
if (previous == null) {
158+
previous = new ArrayList<String>();
159+
filtermap.put(thislink.getObjectOne().getLfid(),previous);
160+
}
161+
previous.add(thislink.getObjectTwo().getNr());
162+
}
163+
164+
HashMap<DataObjectId<E>,String> consolidatedfiltermap = new HashMap<DataObjectId<E>,String>();
165+
166+
Iterator<DataObjectId<E>> keyiterator = filtermap.keySet().iterator();
167+
while (keyiterator.hasNext()) {
168+
DataObjectId<E> key = keyiterator.next();
169+
ArrayList<String> allnumbers = filtermap.get(key);
170+
allnumbers.sort(null);
171+
StringBuffer classif = new StringBuffer();
172+
for (int i=0;i<allnumbers.size();i++) {
173+
if (i>0) classif.append(", ");
174+
classif.append(allnumbers.get(i));
175+
}
176+
consolidatedfiltermap.put(key, classif.toString());
177+
}
178+
179+
return (id) -> (consolidatedfiltermap.get(id));
180+
}
181+
132182
/**
133183
*
134184
*

0 commit comments

Comments
 (0)