Skip to content

Commit 25f6856

Browse files
author
Open Lowcode SAS
committed
Close #135
1 parent e22f5ef commit 25f6856

File tree

7 files changed

+588
-38
lines changed

7 files changed

+588
-38
lines changed
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
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.design.advanced;
12+
13+
import java.io.IOException;
14+
import java.util.List;
15+
16+
import org.openlowcode.design.data.DataObjectDefinition;
17+
import org.openlowcode.design.data.properties.basic.LinkObject;
18+
import org.openlowcode.design.generation.SourceGenerator;
19+
import org.openlowcode.design.generation.StringFormatter;
20+
21+
22+
23+
/**
24+
* A Node link allowing navigation from the left object of a link to the right
25+
* object of a link
26+
*
27+
* @author <a href="https://openlowcode.com/" rel="nofollow">Open Lowcode
28+
* SAS</a>
29+
* @since 1.8
30+
*
31+
*/
32+
public class LinkObjectNodeLink
33+
extends
34+
SmartReportNodeLink {
35+
36+
private LinkObject<?, ?> linkobject;
37+
38+
/**
39+
* Create a new LinkObjectNodeLink
40+
*
41+
* @param childnode child node (should be right object for the link)
42+
* @param linkobject link object where left is the parent, and right is the link
43+
* object
44+
*/
45+
public LinkObjectNodeLink(SmartReportNode childnode, LinkObject<?, ?> linkobject) {
46+
super(childnode);
47+
this.linkobject = linkobject;
48+
if (linkobject.getRightobjectforlink() != childnode.getRelevantObject())
49+
throw new RuntimeException(
50+
"Incompatible objects, link right object = " + linkobject.getRightobjectforlink().getName()
51+
+ ", childnode object = " + childnode.getRelevantObject().getName());
52+
}
53+
54+
55+
56+
@Override
57+
protected void generateImports(SourceGenerator sg) throws IOException {
58+
DataObjectDefinition linkparentobject = linkobject.getParent();
59+
sg.wl("import "+linkparentobject.getOwnermodule().getPath()+".data."+StringFormatter.formatForJavaClass(linkparentobject.getName())+";");
60+
sg.wl("import org.openlowcode.server.data.TwoDataObjects;");
61+
sg.wl("import org.openlowcode.tools.misc.ObjectUtilities;");
62+
63+
}
64+
65+
66+
67+
@Override
68+
public List<FilterElement<?>> getFilterelement() {
69+
return null;
70+
}
71+
72+
@Override
73+
public List<LineGroupingCriteria> getLineGroupingCriteria() {
74+
return null;
75+
}
76+
77+
@Override
78+
public DataObjectDefinition getLeftObject() {
79+
return linkobject.getLeftobjectforlink();
80+
}
81+
82+
@Override
83+
protected void gatherData(
84+
SourceGenerator sg,
85+
SmartReportNode parent,
86+
String prefixparent,
87+
String prefixforlinkandchild,
88+
boolean first,
89+
int circuitbreaker,
90+
DataObjectDefinition rootobject,
91+
String reportname) throws IOException {
92+
93+
String childclass = StringFormatter.formatForJavaClass(linkobject.getRightobjectforlink().getName());
94+
String childattribute = StringFormatter.formatForAttribute(linkobject.getRightobjectforlink().getName());
95+
String parentattribute = StringFormatter.formatForAttribute(linkobject.getLeftobjectforlink().getName());
96+
String parentclass = StringFormatter.formatForJavaClass(linkobject.getLeftobjectforlink().getName());
97+
String linkclass = StringFormatter.formatForJavaClass(linkobject.getParent().getName());
98+
99+
String queryattribute = "null";
100+
// no need to be recursive here
101+
List<FilterElement<?>> filterelements = this.getChildNode().getFilterelement();
102+
List<LineGroupingCriteria> groupingelements = this.getChildNode().getLineGroupingCriteria();
103+
boolean hasfilterbefore = false;
104+
105+
if (filterelements != null)
106+
for (int i = 0; i < filterelements.size(); i++) {
107+
FilterElement<?> thiselement = filterelements.get(i);
108+
if (thiselement.hasfilterbefore())
109+
hasfilterbefore = true;
110+
111+
}
112+
sg.wl(" // ----- data gathering step " + prefixforlinkandchild);
113+
if (hasfilterbefore) {
114+
queryattribute = childattribute + "_step" + prefixforlinkandchild + "_query";
115+
116+
sg.wl(" AndQueryCondition " + queryattribute + " = new AndQueryCondition();");
117+
118+
if (filterelements != null)
119+
for (int i = 0; i < filterelements.size(); i++) {
120+
FilterElement<?> thiselement = filterelements.get(i);
121+
if (thiselement.hasfilterbefore()) {
122+
thiselement.writeFilterInDataGathering(sg, prefixforlinkandchild, rootobject, reportname);
123+
}
124+
125+
}
126+
127+
}
128+
129+
if (first) {
130+
sg.wl(" TwoDataObjects<" + linkclass + "," + childclass + ">[] " + childattribute + "_step"
131+
+ prefixforlinkandchild + " = " + linkclass + ".getlinksandrightobject(parentid,QueryFilter.get("
132+
+ queryattribute + "));");
133+
} else {
134+
sg.wl(" DataObjectId<"+parentclass+">[] "+parentattribute+"_step"+prefixparent+"_id = ObjectUtilities.generateIdTable("+parentattribute+"_step"+prefixparent+");");
135+
sg.wl(" TwoDataObjects<" + linkclass + "," + childclass + ">[] " + childattribute + "_step" + prefixforlinkandchild + "_links = " + linkclass
136+
+ ".getlinksandrightobject(" + parentattribute + "_step" + prefixparent + "_id,QueryFilter.get("
137+
+ queryattribute + "));");
138+
}
139+
sg.wl(" "+childclass+"[] "+childattribute+"_step"+prefixforlinkandchild+" = ObjectUtilities.extractUniqueObjectTable("+childattribute+"_step1_1_links, ((a)->(a.getObjectTwo())), ((a)->(a.getId().getId()))).toArray(new "+childclass+"[0]);");
140+
141+
boolean hasidtable = false;
142+
if (filterelements!=null) for (int i=0;i<filterelements.size();i++) if (filterelements.get(i).needArrayOfObjectId()) hasidtable=true;
143+
if (groupingelements!=null) for (int i=0;i<groupingelements.size();i++) if (groupingelements.get(i).needArrayOfObjectId()) hasidtable=true;
144+
145+
if (hasidtable) {
146+
sg.wl(" DataObjectId<" + childclass + ">[] " + childattribute + "_step" + prefixforlinkandchild
147+
+ "_id = new DataObjectId[" + childattribute + "_step" + prefixforlinkandchild + ".length];");
148+
sg.wl(" for (int i=0;i<" + childattribute + "_step" + prefixforlinkandchild + ".length;i++) "
149+
+ childattribute + "_step" + prefixforlinkandchild + "_id[i] = " + childattribute + "_step"
150+
+ prefixforlinkandchild + "[i].getId();");
151+
}
152+
153+
if (filterelements != null)
154+
for (int i = 0; i < filterelements.size(); i++) {
155+
FilterElement<?> thiselement = filterelements.get(i);
156+
if (thiselement.hasfilterafter()) {
157+
158+
thiselement.writeFilterInDataGathering(sg, prefixforlinkandchild, rootobject, reportname);
159+
}
160+
}
161+
162+
for (int i = 0; i < groupingelements.size(); i++) {
163+
LineGroupingCriteria thisgroupingelement = groupingelements.get(i);
164+
if (thisgroupingelement.hasDataGathering()) {
165+
thisgroupingelement.writeDataGathering(sg, prefixforlinkandchild);
166+
}
167+
}
168+
169+
this.getChildNode().gatherData(sg, circuitbreaker + 1, prefixforlinkandchild, rootobject, reportname);
170+
171+
}
172+
173+
@Override
174+
protected void orderData(
175+
SourceGenerator sg,
176+
SmartReportNode smartReportNode,
177+
String prefix,
178+
String prefixforlinkandchild,
179+
boolean first,
180+
int circuitbreaker,
181+
DataObjectDefinition rootobject,
182+
String reportname) throws IOException {
183+
String childclass = StringFormatter.formatForJavaClass(linkobject.getRightobjectforlink().getName());
184+
String childattribute = StringFormatter.formatForAttribute(linkobject.getRightobjectforlink().getName());
185+
@SuppressWarnings("unused")
186+
String parentattribute = StringFormatter.formatForAttribute(linkobject.getLeftobjectforlink().getName());
187+
String parentclass = StringFormatter.formatForJavaClass(linkobject.getLeftobjectforlink().getName());
188+
String linkclass = StringFormatter.formatForJavaClass(linkobject.getParent().getName());
189+
190+
List<LineGroupingCriteria> groupingcriteria = this.getChildNode().getLineGroupingCriteria();
191+
sg.wl(" CompositeObjectMap<" + parentclass + "," + childclass + ",TwoDataObjects<" + linkclass + "," + childclass + ">> " + childattribute + "_step"
192+
+ prefixforlinkandchild + "_map");
193+
sg.w(" = new CompositeObjectMap<" + parentclass + "," + childclass + ",TwoDataObjects<" + linkclass + "," + childclass + ">>(((a)->(a.getObjectOne().getLfid())),((a)->(a.getObjectTwo()))");
194+
for (int i = 0; i < groupingcriteria.size(); i++) {
195+
LineGroupingCriteria thiscriteria = groupingcriteria.get(i);
196+
String extractstring = thiscriteria.getExtractorFromobject(prefixforlinkandchild);
197+
sg.bl();
198+
if (extractstring != null)
199+
sg.w(" ," + extractstring);
200+
}
201+
sg.w(");");
202+
sg.wl(" " + childattribute + "_step" + prefixforlinkandchild + "_map.classifyObjects(" + childattribute
203+
+ "_step" + prefixforlinkandchild + "_links);");
204+
205+
}
206+
207+
}

src/org/openlowcode/design/advanced/LinkedToChildrenNodeLink.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ protected void orderData(
179179
String childattribute = StringFormatter.formatForAttribute(linkedtoparent.getParent().getName());
180180
String parentclass = StringFormatter.formatForJavaClass(linkedtoparent.getParentObjectForLink().getName());
181181
List<LineGroupingCriteria> groupingcriteria = this.getChildNode().getLineGroupingCriteria();
182-
sg.wl(" CompositeObjectMap<" + parentclass + "," + childclass + "> " + childattribute + "_step"
182+
sg.wl(" CompositeObjectMap<" + parentclass + "," + childclass + ","+childclass+"> " + childattribute + "_step"
183183
+ prefixforlinkandchild + "_map");
184-
sg.w(" = new CompositeObjectMap<" + parentclass + "," + childclass + ">((a)->(a.getLinkedtoparentfor"
185-
+ linkedtoparentinstancename + "id())");
184+
sg.w(" = new CompositeObjectMap<" + parentclass + "," + childclass + ","+childclass+">((a)->(a.getLinkedtoparentfor"
185+
+ linkedtoparentinstancename + "id()),((a)->(a))");
186186
for (int i = 0; i < groupingcriteria.size(); i++) {
187187
LineGroupingCriteria thiscriteria = groupingcriteria.get(i);
188188
String extractstring = thiscriteria.getExtractorFromobject(prefixforlinkandchild);

0 commit comments

Comments
 (0)