Skip to content

Commit 81aed80

Browse files
author
Open Lowcode SAS
committed
Close #288
1 parent 5ce827a commit 81aed80

File tree

6 files changed

+248
-25
lines changed

6 files changed

+248
-25
lines changed

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

+36
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.openlowcode.design.data.properties.basic.ComplexWorkflow;
3939
import org.openlowcode.design.data.properties.basic.ComputedDecimal;
4040
import org.openlowcode.design.data.properties.basic.ConstraintOnLinkObjectSameParent;
41+
import org.openlowcode.design.data.properties.basic.CustomLoader;
4142
import org.openlowcode.design.data.properties.basic.DataControl;
4243
import org.openlowcode.design.data.properties.basic.FileContent;
4344
import org.openlowcode.design.data.properties.basic.HasAutolink;
@@ -329,6 +330,18 @@ public String getName() {
329330

330331
}
331332

333+
public boolean HasLocalLoader() {
334+
335+
for (int i=0;i<this.propertylist.getSize();i++) {
336+
Property<?> thisproperty = this.propertylist.get(i);
337+
if (thisproperty instanceof CustomLoader) {
338+
CustomLoader customloader = (CustomLoader) thisproperty;
339+
if (customloader.getLocalLoader()) return true;
340+
}
341+
}
342+
return false;
343+
}
344+
332345
/**
333346
* get the lookup action group for this data object to grant privileges to an
334347
* authority for this action group
@@ -1451,6 +1464,28 @@ private ActionDefinition generateFlatFileLoader() {
14511464
return flatfileloaderaction;
14521465
}
14531466

1467+
private ActionDefinition generateLocalLoaderAction() {
1468+
String localloadername = "LOCALFLATFILELOADERFOR"+this.getName();
1469+
DynamicActionDefinition localloaderaction = new DynamicActionDefinition(localloadername,true);
1470+
localloaderaction.addInputArgumentAsAccessCriteria(new ObjectIdArgument(this.getName().toUpperCase()+"ID",this));
1471+
localloaderaction
1472+
.addInputArgument(new ChoiceArgument("LOCALE", SystemModule.getSystemModule().getApplicationLocale()));
1473+
localloaderaction.addInputArgument(
1474+
new ChoiceArgument("ENCODING", SystemModule.getSystemModule().getPreferedFileEncoding()));
1475+
localloaderaction.addInputArgument(new LargeBinaryArgument("FILE",false));
1476+
localloaderaction.addOutputArgument(new StringArgument("LOADINGCONTEXT", 500));
1477+
localloaderaction.addOutputArgument(new IntegerArgument("INSERTED"));
1478+
localloaderaction.addOutputArgument(new IntegerArgument("UPDATED"));
1479+
localloaderaction.addOutputArgument(new IntegerArgument("ERRORS"));
1480+
localloaderaction.addOutputArgument(new IntegerArgument("POSTPROCERRORS"));
1481+
1482+
localloaderaction.addOutputArgument(new IntegerArgument("LOADINGTIME"));
1483+
localloaderaction.addOutputArgument(new ArrayArgument(
1484+
new ObjectArgument("ERRORDETAIL", SystemModule.getSystemModule().getCSVLoaderError())));
1485+
localloaderaction.addOutputArgument(new ObjectIdArgument(this.getName().toUpperCase()+"ID_THRU", this));
1486+
return localloaderaction;
1487+
}
1488+
14541489
private ActionDefinition generateFlatFileSample() {
14551490
// security done, nothing to do
14561491
String generateflatfilesampleactionname = "GENERATEFLATFILESAMPLEFOR" + this.getName();
@@ -2224,6 +2259,7 @@ public void generateAutomaticPagesAndActions(Module module) {
22242259
module.addAction(generateUpdateAction());
22252260
module.addAction(generateMassUpdateAction());
22262261
module.addAction(generateFlatFileLoader());
2262+
if (this.HasLocalLoader()) module.addAction(generateLocalLoaderAction());
22272263
module.addAction(generateFlatFileSample());
22282264
module.AddPage(generateUpdatePage());
22292265
if (this.getPropertyByName("TYPED") != null) {

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

+86
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,92 @@ public static void generateFlatFileSampleToFile(String name, SourceGenerator sg,
345345
sg.close();
346346
}
347347

348+
/**
349+
* generates the code for a local flat file loader action
350+
*
351+
* @param name data object name
352+
* @param sg source generator
353+
* @param module parent module
354+
* @throws IOException if anything bad happens during code generation
355+
* @since 1.15
356+
*/
357+
public static void generateFlatFileLocalLoaderToFile(String name, SourceGenerator sg, Module module,DataObjectDefinition object) throws IOException {
358+
String objectclass = StringFormatter.formatForJavaClass(object.getName());
359+
String objectvariable = StringFormatter.formatForAttribute(object.getName());
360+
String loadername = StringFormatter.formatForJavaClass(name);
361+
362+
sg.wl("package " + module.getPath() + ".action.generated;");
363+
sg.wl("");
364+
sg.wl("import java.util.function.Function;");
365+
sg.wl("");
366+
sg.wl("import org.openlowcode.module.system.data.choice.ApplocaleChoiceDefinition;");
367+
sg.wl("import org.openlowcode.module.system.data.choice.PreferedfileencodingChoiceDefinition;");
368+
sg.wl("import org.openlowcode.module.system.page.ShowloadingreportforchildrenPage;");
369+
sg.wl("import org.openlowcode.server.data.ChoiceValue;");
370+
sg.wl("import org.openlowcode.server.data.loader.FlatFileLoader;");
371+
sg.wl("import org.openlowcode.server.data.loader.FlatFileLoaderReport;");
372+
sg.wl("import org.openlowcode.server.data.properties.DataObjectId;");
373+
sg.wl("import org.openlowcode.server.data.storage.QueryFilter;");
374+
sg.wl("import org.openlowcode.server.data.storage.TableAlias;");
375+
sg.wl("import org.openlowcode.server.graphic.SPage;");
376+
sg.wl("import org.openlowcode.server.runtime.SModule;");
377+
sg.wl("import org.openlowcode.tools.messages.SFile;");
378+
sg.wl("");
379+
sg.wl("");
380+
sg.wl("import " + module.getPath() + ".data."+objectclass+";");
381+
sg.wl("");
382+
sg.wl("public class Atg"+loadername+"Action");
383+
sg.wl(" extends");
384+
sg.wl(" Abs"+loadername+"Action {");
385+
sg.wl("");
386+
sg.wl(" public Atg"+loadername+"Action(SModule parent) {");
387+
sg.wl(" super(parent);");
388+
sg.wl("");
389+
sg.wl(" }");
390+
sg.wl("");
391+
sg.wl(" @Override");
392+
sg.wl(" public ActionOutputData executeActionLogic(");
393+
sg.wl(" DataObjectId<"+objectclass+"> "+objectvariable+"id,");
394+
sg.wl(" ChoiceValue<ApplocaleChoiceDefinition> locale,");
395+
sg.wl(" ChoiceValue<PreferedfileencodingChoiceDefinition> encoding,");
396+
sg.wl(" SFile file,");
397+
sg.wl(" Function<TableAlias, QueryFilter> datafilter) {");
398+
sg.wl(" "+objectclass+" "+objectvariable+" = "+objectclass+".readone("+objectvariable+"id);");
399+
sg.wl(" FlatFileLoader<"+objectclass+"> loader = new FlatFileLoader<"+objectclass+">("+objectclass+".getDefinition(),locale,encoding);");
400+
sg.wl(" loader.setHardObject("+objectvariable+");");
401+
sg.wl(" FlatFileLoaderReport returnmessage = loader.load(file);");
402+
sg.wl(" return new ActionOutputData(returnmessage.getContext(),");
403+
sg.wl(" returnmessage.getInserted(),");
404+
sg.wl(" returnmessage.getUpdated(),");
405+
sg.wl(" returnmessage.getError(),");
406+
sg.wl(" returnmessage.getPostprocError(),");
407+
sg.wl(" (int)(returnmessage.getLoadingtimems()/1000),");
408+
sg.wl(" returnmessage.getErrordetails(),");
409+
sg.wl(" "+objectvariable+"id);");
410+
sg.wl(" }");
411+
sg.wl("");
412+
sg.wl(" @Override");
413+
sg.wl(" public SPage choosePage(ActionOutputData logicoutput) {");
414+
sg.wl(" return new ShowloadingreportforchildrenPage(logicoutput.getLoadingcontext(),");
415+
sg.wl(" logicoutput.getInserted(),");
416+
sg.wl(" logicoutput.getUpdated(),");
417+
sg.wl(" logicoutput.getErrors(),");
418+
sg.wl(" logicoutput.getPostprocerrors(),");
419+
sg.wl(" logicoutput.getLoadingtime(),");
420+
sg.wl(" logicoutput.getErrordetail(),");
421+
sg.wl(" logicoutput.get"+objectclass+"id_thru());");
422+
sg.wl(" }");
423+
sg.wl("");
424+
sg.wl("}");
425+
426+
427+
428+
429+
430+
431+
sg.close();
432+
}
433+
348434
/**
349435
* generates the code for the flat file loader action
350436
*

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

+41
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.openlowcode.tools.misc.NamedList;
5252
import org.openlowcode.tools.misc.StandardUtil;
5353

54+
5455
/**
5556
* this class generates the show object page. This is the biggest automatically
5657
* generated class in the framework
@@ -362,6 +363,10 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
362363
sg.wl("import org.openlowcode.server.graphic.widget.SObjectArray;");
363364

364365
}
366+
if (dataobject.HasLocalLoader()) {
367+
sg.wl("import " + module.getPath() + ".action.generated.AtgLocalflatfileloaderfor"+objectvariable+"Action;");
368+
}
369+
365370
if (hasworkflow) {
366371

367372
sg.wl("import org.openlowcode.module.system.action.ShowactivetaskAction;");
@@ -1357,6 +1362,42 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
13571362
}
13581363
}
13591364

1365+
// --------------- locale load if exists
1366+
1367+
if (dataobject.HasLocalLoader()) {
1368+
1369+
sg.wl(" AtgLocalflatfileloaderfor"+objectvariable+"Action.ActionRef localloadaction = AtgLocalflatfileloaderfor"+objectvariable+"Action.get().getActionRef();");
1370+
sg.wl(" localloadaction.setBudgetroundid(objectdisplaydefinition.getAttributeInput(Budgetround.getIdMarker()));");
1371+
sg.wl(" SComponentBand localloadpopup = new SComponentBand(SComponentBand.DIRECTION_DOWN,this);");
1372+
sg.wl(" SPopupButton localloadpopupbutton = new SPopupButton(this, localloadpopup, \"Load\",\"Specific loading for this object\");");
1373+
sg.wl(" objectbuttonband.addElement(localloadpopupbutton);");
1374+
sg.wl(" SFileChooser csvfilechooserforlocalload = new SFileChooser(this, \"CSVFILECHOSERFORLOCALLOAD\",\"Select File\");");
1375+
sg.wl(" localloadpopup.addElement(csvfilechooserforlocalload);");
1376+
sg.wl(" SComponentBand csvloadcbandcontentforlocalload = new SComponentBand(SComponentBand.DIRECTION_DOWN,this);");
1377+
sg.wl(" SCollapsibleBand csvloadcbandforlocalload = new SCollapsibleBand(this, csvloadcbandcontentforlocalload, \"Settings\", false);");
1378+
sg.wl(" localloadpopup.addElement(csvloadcbandforlocalload);");
1379+
sg.wl(" SChoiceTextField<ApplocaleChoiceDefinition> csvloadlocaleforlocalload = new SChoiceTextField<ApplocaleChoiceDefinition>");
1380+
sg.wl(" (\"Locale\",\"APPLOCALEFORLOCALLOAD\",\"determines csv and number format, default is US\", ApplocaleChoiceDefinition.get(),");
1381+
sg.wl(" null, this, true, false, false, false, null);");
1382+
sg.wl(" csvloadlocaleforlocalload.setLinkedData(this.getUserlocale());");
1383+
sg.wl(" csvloadcbandcontentforlocalload.addElement(csvloadlocaleforlocalload);");
1384+
sg.wl(" SChoiceTextField<PreferedfileencodingChoiceDefinition> csvloadpreffileencodingforlocalload = new SChoiceTextField<PreferedfileencodingChoiceDefinition>");
1385+
sg.wl(" (\"Encoding\",\"FILEENCODINGFORLOCALLOAD\",\"determines file encoding, default is ANSI / Windows CP1522\", PreferedfileencodingChoiceDefinition.get(),");
1386+
sg.wl(" null, this, true, false, false, false, null);");
1387+
sg.wl(" csvloadpreffileencodingforlocalload.setLinkedData(this.getPrefencoding());");
1388+
sg.wl(" csvloadcbandcontentforlocalload.addElement(csvloadpreffileencodingforlocalload);");
1389+
sg.wl(" localloadaction.setLocale(csvloadlocaleforlocalload.getChoiceInput());");
1390+
sg.wl(" localloadaction.setEncoding(csvloadpreffileencodingforlocalload.getChoiceInput());");
1391+
sg.wl(" localloadaction.setFile(csvfilechooserforlocalload.getLargeBinaryInput());");
1392+
sg.wl(" SActionButton launchlocalload = new SActionButton(\"Load\",localloadaction,this);");
1393+
sg.wl(" localloadpopup.addElement(launchlocalload); ");
1394+
1395+
1396+
}
1397+
1398+
// ---------------- end of locale load
1399+
1400+
13601401
sg.wl(" objectdisplaydefinition.addButtonBarUnderTitle(objectbuttonband);");
13611402

13621403
}

src/org/openlowcode/design/data/properties/basic/CustomLoader.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,37 @@ public class CustomLoader
3030
extends
3131
Property<CustomLoader> {
3232

33+
/**
34+
* @return if a local loader should be generated
35+
* @since 1.15
36+
*/
37+
public boolean getLocalLoader() {
38+
return this.localloader;
39+
}
40+
41+
private boolean localloader;
42+
3343
/**
3444
* Creates a custom loader for the data object
3545
*
3646
* @param name a unique name amongst all the custom loaders of this data object
3747
* (should be a valid java attribute name)
3848
*/
3949
public CustomLoader(String name) {
40-
super(name, "CUSTOMLOADER");
50+
this(name, false);
51+
}
4152

53+
/**
54+
* creates a custom loader with the possibility to generate a local loader
55+
*
56+
* @param name a unique name amongst all the custom loaders of this data
57+
* object (should be a valid java attribute name)
58+
* @param localloader if true, generate a local loader for the object
59+
* @since 1.15
60+
*/
61+
public CustomLoader(String name, boolean localloader) {
62+
super(name, "CUSTOMLOADER");
63+
this.localloader = localloader;
4264
}
4365

4466
@Override

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

+12
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,18 @@ relevantlinkedtoparent, new SourceGenerator(new File(fullfilepathdeleteandshowob
18111811
this);
18121812
// flat file sample generation
18131813

1814+
if (currentobject.HasLocalLoader()) {
1815+
// flat file loading
1816+
String fullfilepathflatfileforlocalloader = srcautoactionfolder + "Atg"
1817+
+ StringFormatter.formatForJavaClass("LOCALFLATFILELOADERFOR"+ currentobject.getName())
1818+
+ "Action.java";
1819+
logger.info("generating file " + fullfilepathflatfileforlocalloader);
1820+
DataObjectDefinitionFileActions.generateFlatFileLocalLoaderToFile("LOCALFLATFILELOADERFOR"+ currentobject.getName(),
1821+
new SourceGenerator(new File(fullfilepathflatfileforlocalloader), this.getAuthor(), this.getVersionid()),
1822+
this,currentobject);
1823+
1824+
}
1825+
18141826
String fullfilepathflatfilesample = srcautoactionfolder + "Atg"
18151827
+ StringFormatter.formatForJavaClass("GENERATEFLATFILESAMPLEFOR" + currentobject.getName())
18161828
+ "Action.java";

0 commit comments

Comments
 (0)