|
| 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 | +} |
0 commit comments