Skip to content

Commit 763c516

Browse files
author
Open Lowcode SAS
committed
Close #119
1 parent d7b1b9b commit 763c516

11 files changed

Lines changed: 332 additions & 134 deletions

src/org/openlowcode/design/action/ActionDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
10161016
if (thisarg instanceof ObjectArgument) {
10171017
ObjectArgument thisobjectarg = (ObjectArgument) thisarg;
10181018
sg.wl(" if (attribute" + i + ".getName().compareTo(\"" + thisarg.getName() + "\")==0) {");
1019-
if (thisobjectarg.getMasterObject().isUniqueIdentified()) {
1019+
if (thisobjectarg.getMasterObject().hasId()) {
10201020
sg.wl(" if (attribute" + i + ".getUID().length()>0) "
10211021
+ StringFormatter.formatForAttribute(thisarg.getName()) + " = " + thisarg.getType()
10221022
+ ".readone(DataObjectId.generatefromDataObjectElt(attribute" + i + "," + thisarg.getType()

src/org/openlowcode/design/data/DataObjectDefinition.java

Lines changed: 169 additions & 103 deletions
Large diffs are not rendered by default.

src/org/openlowcode/design/data/DataObjectDefinitionDeleteAndUpdate.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.openlowcode.design.generation.StringFormatter;
2424
import org.openlowcode.design.module.Module;
2525

26+
2627
/**
2728
* An utility class gathering the generation of code for all delete and update
2829
* actions
@@ -620,7 +621,7 @@ public static void generatePrepareupdateActionToFile(
620621
sg.wl(" {");
621622
sg.wl(" " + objectclass + " " + objectvariable + " = " + objectclass + ".readone(id);");
622623
if (companion!=null)
623-
sg.wl(" " + companionclass + " " + companionvariable + " = " + companionclass + ".readone(id);");
624+
sg.wl(" "+companionclass+" "+companionvariable+" = "+companionclass+".readone(DataObjectId.castDataObjectId(id, "+companionclass+".getDefinition()));");
624625
for (int i=0;i<dataobject.fieldlist.getSize();i++) {
625626
if (dataobject.fieldlist.get(i) instanceof StringField) {
626627
StringField stringfield = (StringField) dataobject.fieldlist.get(i);
@@ -1084,17 +1085,30 @@ public static void generateMassUpdateActionToFile(
10841085
sg.close();
10851086
}
10861087

1088+
public static void generateUpdateActionToFile(DataObjectDefinition dataobject, SourceGenerator sg, Module module)
1089+
throws IOException {
1090+
generateUpdateActionToFile(dataobject,null,sg,module);
1091+
}
1092+
10871093
/**
10881094
* generate the unitary update action to file
10891095
*
10901096
* @param dataobject data object
1097+
* @param companion companion for typed objects
10911098
* @param sg source generator
10921099
* @param module parent module
10931100
* @throws IOException if anything bad happens while writing the source code
10941101
*/
1095-
public static void generateUpdateActionToFile(DataObjectDefinition dataobject, SourceGenerator sg, Module module)
1102+
public static void generateUpdateActionToFile(DataObjectDefinition dataobject,DataObjectDefinition companion, SourceGenerator sg, Module module)
10961103
throws IOException {
10971104
String actionname = "Update" + dataobject.getName().toLowerCase() + "Action";
1105+
String companionclass = null;
1106+
String companionattribute=null;
1107+
if (companion!=null) {
1108+
actionname = "Update" + companion.getName().toLowerCase() + "Action";
1109+
companionclass = StringFormatter.formatForJavaClass(companion.getName());
1110+
companionattribute = StringFormatter.formatForAttribute(companion.getName());
1111+
}
10981112
String objectclass = StringFormatter.formatForJavaClass(dataobject.getName());
10991113
String objectvariable = StringFormatter.formatForAttribute(dataobject.getName());
11001114
LinkedToParent<?> subobject = dataobject.isSubObject();
@@ -1120,6 +1134,7 @@ public static void generateUpdateActionToFile(DataObjectDefinition dataobject, S
11201134
sg.wl("package " + module.getPath() + ".action.generated;");
11211135
sg.wl("");
11221136
sg.wl("import " + module.getPath() + ".data." + objectclass + ";");
1137+
if(companion!=null) sg.wl("import " + companion.getOwnermodule().getPath() + ".data." + companionclass + ";");
11231138
if (subobject != null) {
11241139
sg.wl("import " + subobject.getParentObjectForLink().getOwnermodule().getPath() + ".data."
11251140
+ StringFormatter.formatForJavaClass(subobject.getParentObjectForLink().getName()) + ";");
@@ -1145,7 +1160,7 @@ public static void generateUpdateActionToFile(DataObjectDefinition dataobject, S
11451160
sg.wl("");
11461161
sg.wl(" @Override");
11471162
sg.wl(" public DataObjectId<" + objectclass + "> executeActionLogic(" + objectclass + " " + objectvariable
1148-
+ extraattributesdeclaration.toString() + ",Function<TableAlias,QueryFilter> datafilter)");
1163+
+(companion!=null?", "+companionclass+" "+companionattribute+" ":"")+ extraattributesdeclaration.toString() + ",Function<TableAlias,QueryFilter> datafilter)");
11491164
sg.wl(" {");
11501165
for (int i = 0; i < dataobject.propertylist.getSize(); i++) {
11511166
Property<?> thisproperty = dataobject.propertylist.get(i);
@@ -1157,7 +1172,10 @@ public static void generateUpdateActionToFile(DataObjectDefinition dataobject, S
11571172
}
11581173
}
11591174
}
1160-
sg.wl(" " + objectvariable + ".update(this,SecurityInDataMethod.FAIL_IF_NOT_AUTHORIZED);");
1175+
if (companion==null)
1176+
sg.wl(" " + objectvariable+ ".update(this,SecurityInDataMethod.FAIL_IF_NOT_AUTHORIZED);");
1177+
if (companion!=null)
1178+
sg.wl(" " + companionattribute + ".updatetyped( " + objectvariable+",this,SecurityInDataMethod.FAIL_IF_NOT_AUTHORIZED);");
11611179
sg.wl(" return " + objectvariable + ".getId();");
11621180
sg.wl(" }");
11631181
sg.wl("");

src/org/openlowcode/design/data/DataObjectDefinitionOtherActions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,9 @@ public static void generateStandardCreateActionToFile(
11891189
sg.wl(" object" + methodsforcreation[j]);
11901190
}
11911191
}
1192+
if (dataobject.getPropertyByName("TYPED")!=null) {
1193+
sg.wl(" object.settypebeforecreation(type);");
1194+
}
11921195
sg.wl(" object.insert(this,SecurityInDataMethod.FAIL_IF_NOT_AUTHORIZED);");
11931196
sg.wl(" return object.getId();");
11941197
sg.wl(" }");

src/org/openlowcode/design/data/DataObjectDefinitionShowPage.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public DataObjectDefinitionShowPage(DataObjectDefinition dataobject) {
7979
* object given in argument
8080
*
8181
* @param dataobject Data object to generate code for
82+
* @param companion companion data object for typed object
8283
*/
8384
public DataObjectDefinitionShowPage(DataObjectDefinition dataobject,DataObjectDefinition companion) {
8485
this.dataobject = dataobject;
@@ -389,7 +390,16 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
389390
sg.wl("import org.openlowcode.server.graphic.widget.SObjectArray;");
390391
if (objectbuttonband)
391392
sg.wl("import org.openlowcode.server.graphic.widget.SActionButton;");
392-
393+
if (dataobject.getPropertyByName("UNIQUEIDENTIFIED")!=null) {
394+
if (this.companion==null) {
395+
sg.wl("import "+dataobject.getOwnermodule().getPath()+".action.generated.AtgPrepareupdate"+objectvariable+"Action;");
396+
397+
} else {
398+
sg.wl("import "+companion.getOwnermodule().getPath()+".action.generated.AtgPrepareupdate"+companionattribute+"Action;");
399+
400+
}
401+
}
402+
393403
for (int i = 0; i < allparentlinks.size(); i++) {
394404
LinkedToParent<?> linkedtoparent = allparentlinks.get(i);
395405
String changeparentvariable = StringFormatter.formatForAttribute(
@@ -865,6 +875,25 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
865875
sg.wl("");
866876
}
867877

878+
if (dataobject.getPropertyByName("UNIQUEIDENTIFIED")!=null) {
879+
String actionclassname="AtgPrepareupdate"+objectvariable;
880+
String actionattributename="update";
881+
String buttonname="\"Update\"";
882+
String inputargumentclass="Id";
883+
884+
if (this.companion!=null) {
885+
actionclassname="AtgPrepareupdate"+companionattribute;
886+
}
887+
sg.wl(" " + actionclassname + "Action.ActionRef " + actionattributename + "forobjectbandaction = "
888+
+ actionclassname + "Action.get().getActionRef();");
889+
sg.wl(" " + actionattributename + "forobjectbandaction.set" + inputargumentclass
890+
+ "(objectdisplaydefinition.getAttributeInput(" + objectclass + ".getIdMarker()));");
891+
sg.wl(" SActionButton " + actionattributename + "forobjectbandbutton = new SActionButton("
892+
+ buttonname + ",\"\"," + actionattributename + "forobjectbandaction,this);");
893+
sg.wl(" objectbuttonband.addElement(" + actionattributename + "forobjectbandbutton); ");
894+
sg.wl("");
895+
}
896+
868897
for (int i = 0; i < actionlistonobjectid.getSize(); i++) {
869898
DynamicActionDefinition thisaction = actionlistonobjectid.get(i);
870899
String actionclassname = StringFormatter.formatForJavaClass(thisaction.getName());

src/org/openlowcode/design/data/DataObjectDefinitionUpdatePage.java

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class DataObjectDefinitionUpdatePage
3333
GeneratedPages {
3434

3535
private DataObjectDefinition dataobject;
36+
private DataObjectDefinition companionobject;
3637

3738
/**
3839
* creates the update page class for the provided data object
@@ -41,11 +42,31 @@ public class DataObjectDefinitionUpdatePage
4142
*/
4243
public DataObjectDefinitionUpdatePage(DataObjectDefinition dataobject) {
4344
this.dataobject = dataobject;
45+
this.companionobject = null;
46+
}
47+
48+
/**
49+
* creates the update page class for the provided data object
50+
*
51+
* @param dataobject data object definition
52+
* @param companionobject companion data object definition (for typed object)
53+
*/
54+
public DataObjectDefinitionUpdatePage(DataObjectDefinition dataobject, DataObjectDefinition companionobject) {
55+
this.companionobject = companionobject;
56+
this.dataobject = dataobject;
4457
}
4558

4659
@Override
4760
public void generateToFile(SourceGenerator sg, Module module) throws IOException {
4861
String pagename = "Update" + dataobject.getName().toLowerCase() + "Page";
62+
String companionclass = null;
63+
String companionvariable = null;
64+
65+
if (companionobject != null) {
66+
pagename = "Update" + companionobject.getName().toLowerCase() + "Page";
67+
companionclass = StringFormatter.formatForJavaClass(companionobject.getName());
68+
companionvariable = StringFormatter.formatForAttribute(companionobject.getName());
69+
}
4970
String objectclass = StringFormatter.formatForJavaClass(dataobject.getName());
5071
String objectvariable = StringFormatter.formatForAttribute(dataobject.getName());
5172
HashMap<String, String> importdeclaration = new HashMap<String, String>();
@@ -83,26 +104,35 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
83104
pageattributeentry.append(" , ");
84105
pageattributeentry.append(" controlstatus ");
85106
}
86-
87-
// ------------------------ Attributes for field suggestions ---------------------
88-
for (int i=0;i<dataobject.fieldlist.getSize();i++) {
107+
108+
// ------------------------ Attributes for field suggestions
109+
// ---------------------
110+
for (int i = 0; i < dataobject.fieldlist.getSize(); i++) {
89111
if (dataobject.fieldlist.get(i) instanceof StringField) {
90-
StringField stringfield = (StringField) dataobject.fieldlist.get(i);
112+
StringField stringfield = (StringField) dataobject.fieldlist.get(i);
91113
if (stringfield.hasListOfValuesHelper()) {
92-
114+
93115
pageattributedeclaration
94-
.append(", String[] suggestionsforfield" + stringfield.getName().toLowerCase()+ " ");
95-
116+
.append(", String[] suggestionsforfield" + stringfield.getName().toLowerCase() + " ");
117+
96118
pageattributeentry.append(", suggestionsforfield" + stringfield.getName().toLowerCase() + " ");
97119
}
98120
}
99121
}
100-
122+
101123
sg.wl("package " + module.getPath() + ".page.generated;");
102124
sg.wl("");
103125
sg.wl("import " + module.getPath() + ".action.generated.AtgShow" + objectvariable + "Action;");
104-
sg.wl("import " + module.getPath() + ".action.generated.AtgUpdate" + objectvariable + "Action;");
126+
if (companionobject == null) {
127+
sg.wl("import " + module.getPath() + ".action.generated.AtgUpdate" + objectvariable + "Action;");
128+
} else {
129+
sg.wl("import " + companionobject.getOwnermodule().getPath() + ".action.generated.AtgUpdate"
130+
+ companionvariable + "Action;");
131+
}
105132
sg.wl("import " + module.getPath() + ".data." + objectclass + ";");
133+
if (companionobject != null) {
134+
sg.wl("import " + companionobject.getOwnermodule().getPath() + ".data." + companionclass + ";");
135+
}
106136
sg.wl("import org.openlowcode.server.action.SActionRef;");
107137
sg.wl("import org.openlowcode.server.graphic.SPageNode;");
108138
sg.wl("import org.openlowcode.server.graphic.widget.STextField;");
@@ -120,8 +150,10 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
120150

121151
sg.wl(" @Override");
122152
sg.wl(" public String generateTitle(" + objectclass + " " + objectvariable + " "
153+
+ (companionobject != null ? ", " + companionclass + " " + companionvariable + " " : "")
123154
+ pageattributedeclaration.toString() + ") {");
124-
sg.wl(" String objectdisplay = \"Update " + dataobject.getLabel() + "\";");
155+
sg.wl(" String objectdisplay = \"Update "
156+
+ (companionobject != null ? companionobject.getLabel() : dataobject.getLabel()) + "\";");
125157
if (dataobject.getPropertyByName("NUMBERED") != null) {
126158
sg.wl(" objectdisplay+=\" \"+" + objectvariable + ".getNr();");
127159
}
@@ -133,17 +165,20 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
133165
sg.wl(" }");
134166

135167
sg.wl(" public Atg" + pagename + "(" + objectclass + " " + objectvariable + " "
168+
+ (companionobject != null ? ", " + companionclass + " " + companionvariable + " " : "")
136169
+ pageattributedeclaration.toString() + ") {");
137-
sg.wl(" super(" + objectvariable + " " + pageattributeentry.toString() + ");");
170+
sg.wl(" super(" + objectvariable + (companionobject != null ? ", " + companionvariable + " " : "") + " "
171+
+ pageattributeentry.toString() + ");");
138172
sg.wl(" ");
139173
sg.wl(" }");
140174
sg.wl("");
141175
sg.wl(" @Override");
142176
sg.wl(" protected SPageNode getContent() {");
143177
sg.wl(" SComponentBand mainband = new SComponentBand(SComponentBand.DIRECTION_DOWN,this);");
144178
sg.wl(" mainband.addElement(new SPageText(\"Update " + objectclass + "\",SPageText.TYPE_TITLE,this));");
145-
sg.wl(" AtgUpdate" + objectvariable + "Action.ActionRef update" + objectvariable + "actionref = AtgUpdate"
146-
+ objectvariable + "Action.get().getActionRef();");
179+
sg.wl(" AtgUpdate" + (companionobject != null ? companionvariable : objectvariable)
180+
+ "Action.ActionRef update" + objectvariable + "actionref = AtgUpdate"
181+
+ (companionobject != null ? companionvariable : objectvariable) + "Action.get().getActionRef();");
147182
if (isdatacontrol) {
148183
sg.wl(" STextField controlstatus = new STextField(\"Control Status\",\"CONTROLSTATUS\",\"\",20000, \"\",");
149184
sg.wl(" false,this, true, false, false,null, false);");
@@ -157,17 +192,27 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
157192
+ ".getDefinition(),this, false);");
158193
sg.wl(" update" + objectvariable + "actionref.set" + objectclass
159194
+ "(objectupdatedefinition.getObjectInput()); ");
195+
if (companionobject != null) {
196+
sg.wl(" SObjectDisplay<" + companionclass + "> companionupdatedefinition = new SObjectDisplay<"
197+
+ companionclass + ">(\"" + companionobject.getName().toUpperCase() + "\", this.get"
198+
+ companionclass + "()," + companionclass + ".getDefinition(),this, false);");
199+
sg.wl(" update" + objectvariable + "actionref.set" + companionclass
200+
+ "(companionupdatedefinition.getObjectInput()); ");
201+
sg.wl(" companionupdatedefinition.setReducedDisplay(false);");
202+
}
160203

161-
for (int i=0;i<dataobject.fieldlist.getSize();i++) {
204+
for (int i = 0; i < dataobject.fieldlist.getSize(); i++) {
162205
if (dataobject.fieldlist.get(i) instanceof StringField) {
163-
StringField stringfield = (StringField) dataobject.fieldlist.get(i);
206+
StringField stringfield = (StringField) dataobject.fieldlist.get(i);
164207
if (stringfield.hasListOfValuesHelper()) {
165-
sg.wl(" objectupdatedefinition.addTextFieldSuggestion("+objectclass+".get"+StringFormatter.formatForJavaClass(stringfield.getName())+"FieldMarker(),this.getSuggestionsforfield"+stringfield.getName().toLowerCase()+"());");
208+
sg.wl(" objectupdatedefinition.addTextFieldSuggestion(" + objectclass + ".get"
209+
+ StringFormatter.formatForJavaClass(stringfield.getName())
210+
+ "FieldMarker(),this.getSuggestionsforfield" + stringfield.getName().toLowerCase()
211+
+ "());");
166212
}
167213
}
168214
}
169-
170-
215+
171216
for (int i = 0; i < dataobject.propertylist.getSize(); i++) {
172217
Property<?> thisproperty = dataobject.propertylist.get(i);
173218
if (thisproperty.isDataInputUsedForUpdate())
@@ -199,6 +244,8 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
199244

200245
}
201246
sg.wl(" mainband.addElement(objectupdatedefinition);");
247+
if (companionobject != null)
248+
sg.wl(" mainband.addElement(companionupdatedefinition);");
202249

203250
for (int i = 0; i < dataobject.propertylist.getSize(); i++) {
204251
Property<?> thisproperty = dataobject.propertylist.get(i);

src/org/openlowcode/design/module/Module.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,17 @@ relevantlinkedtoparent, new SourceGenerator(new File(fullfilepathdeleteandshowob
17811781
logger.info("generating file " + fullfilepathupdate);
17821782
DataObjectDefinitionDeleteAndUpdate.generateUpdateActionToFile(currentobject,
17831783
new SourceGenerator(new File(fullfilepathupdate), this.getAuthor(), this.getVersionid()), this);
1784+
if (currentobject.getPropertyByName("TYPED")!=null) {
1785+
Typed typed = (Typed) (currentobject.getPropertyByName("TYPED"));
1786+
for (int c=0;c<typed.getCompanionNumber();c++) {
1787+
DataObjectDefinition companion = typed.getCompanion(c);
1788+
String fullfilepathcompanionupdate = srcautoactionfolder + "Atg"
1789+
+ StringFormatter.formatForJavaClass("UPDATE" + companion.getName()) + "Action.java";
1790+
logger.info("generating file " + fullfilepathcompanionupdate);
1791+
DataObjectDefinitionDeleteAndUpdate.generateUpdateActionToFile(currentobject,companion,
1792+
new SourceGenerator(new File(fullfilepathcompanionupdate), this.getAuthor(), this.getVersionid()), this);
1793+
}
1794+
}
17841795
// flat file loading
17851796
String fullfilepathflatfile = srcautoactionfolder + "Atg"
17861797
+ StringFormatter.formatForJavaClass("FLATFILELOADERFOR" + currentobject.getName())
@@ -2111,7 +2122,17 @@ relevantlinkedtoparent, new SourceGenerator(new File(fullfilepathdeleteandshowob
21112122
logger.info("generating file " + fullfilepath);
21122123
(new DataObjectDefinitionUpdatePage(currentobject)).generateToFile(
21132124
new SourceGenerator(new File(fullfilepath), this.getAuthor(), this.getVersionid()), this);
2114-
2125+
if (currentobject.getPropertyByName("TYPED")!=null) {
2126+
Typed typed = (Typed) (currentobject.getPropertyByName("TYPED"));
2127+
for (int c=0;c<typed.getCompanionNumber();c++) {
2128+
DataObjectDefinition companion = typed.getCompanion(c);
2129+
String fullfilepathcompanion = srcautopagefolder + "Atg"
2130+
+ StringFormatter.formatForJavaClass("UPDATE" + companion.getName()) + "Page.java";
2131+
logger.info("generating file " + fullfilepathcompanion);
2132+
(new DataObjectDefinitionUpdatePage(currentobject,companion)).generateToFile(
2133+
new SourceGenerator(new File(fullfilepathcompanion), this.getAuthor(), this.getVersionid()), this);
2134+
}
2135+
}
21152136
}
21162137

21172138
if ((currentobject.IsIterated()) || (currentobject.isVersioned())) {

src/org/openlowcode/server/data/message/TObjectDataElt.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import java.util.HashMap;
1515

1616
import org.openlowcode.server.data.DataObject;
17-
18-
import org.openlowcode.server.data.properties.UniqueidentifiedInterface;
17+
import org.openlowcode.server.data.properties.HasidInterface;
1918
import org.openlowcode.server.runtime.OLcServer;
2019
import org.openlowcode.tools.messages.MessageWriter;
2120
import org.openlowcode.tools.misc.NamedInterface;
@@ -42,10 +41,10 @@ public class TObjectDataElt<E extends DataObject<E>> extends ObjectDataElt {
4241
public TObjectDataElt(String name, E object) {
4342
super(name, new TObjectDataEltType<E>(object.getDefinitionFromObject()), object.getFieldList());
4443
this.object = object;
45-
if (object instanceof UniqueidentifiedInterface) {
44+
if (object instanceof HasidInterface) {
4645
@SuppressWarnings({ "rawtypes", "unchecked" })
47-
UniqueidentifiedInterface<E> uiobject = (UniqueidentifiedInterface) object;
48-
this.setUID(uiobject.getId().getId());
46+
HasidInterface<E> hasidobject = (HasidInterface) object;
47+
this.setUID(hasidobject.getId().getId());
4948
} else {
5049
if (object.getTransientid() != null) {
5150
this.setUID(object.getTransientid());

0 commit comments

Comments
 (0)