Skip to content

Commit e760495

Browse files
author
Open Lowcode SAS
committed
Close #281
1 parent 270f6ac commit e760495

5 files changed

Lines changed: 53 additions & 5 deletions

File tree

src/org/openlowcode/server/data/loader/FlatFileLoader.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public class FlatFileLoader<E extends DataObject<E> & UniqueidentifiedInterface<
6464
private ChoiceValue<ApplocaleChoiceDefinition> selectedlocale;
6565
private FlatFileLoaderSupplement<E> supplement;
6666
private ChoiceValue<PreferedfileencodingChoiceDefinition> preferedencoding;
67-
67+
private ArrayList<FlatFileLoaderColumn<E>> loadercolumns;
68+
6869
/**
6970
* Creates a FlatFileLoader without supplement
7071
*
@@ -102,6 +103,14 @@ public FlatFileLoader(
102103
this.supplement = supplement;
103104
}
104105

106+
public int getFlatFileLoaderColumnNumber() {
107+
return this.loadercolumns.size();
108+
}
109+
110+
public FlatFileLoaderColumn<E> getColumnAtIndex(int index) {
111+
return this.loadercolumns.get(index);
112+
}
113+
105114
/**
106115
* This method returns true if the line has some data. A data is defined as a
107116
* string of length greater than 0
@@ -153,7 +162,7 @@ private FlatFileLoaderReport load(
153162
try {
154163

155164
Object[] headline = parser.parseOneLine();
156-
ArrayList<FlatFileLoaderColumn<E>> loadercolumns = new ArrayList<FlatFileLoaderColumn<E>>();
165+
loadercolumns = new ArrayList<FlatFileLoaderColumn<E>>();
157166
// custom loader helpers sorted by classname.
158167
HashMap<
159168
String,
@@ -465,6 +474,7 @@ private FlatFileLoaderReport load(
465474
while (loaderhelperiterator.hasNext()) {
466475
try {
467476
CustomloaderHelper<E> customloaderhelper = loaderhelperiterator.next();
477+
customloaderhelper.setContextLoader(this);
468478
customloaderhelper.executeAtEndOfLine(objectforprocessing);
469479
} catch (Exception e) {
470480
postprocerror++;

src/org/openlowcode/server/data/properties/Customloader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @param <E> parent data object
2525
*/
26-
public class Customloader<E extends DataObject<E>> extends DataObjectProperty<E> {
26+
public class Customloader<E extends DataObject<E> & UniqueidentifiedInterface<E>> extends DataObjectProperty<E> {
2727

2828
/**
2929
* creates a custom loader property

src/org/openlowcode/server/data/properties/CustomloaderDefinition.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.openlowcode.server.data.DataObjectPayload;
2222
import org.openlowcode.server.data.DataObjectPropertyDefinition;
2323
import org.openlowcode.server.data.PropertyExtractor;
24+
import org.openlowcode.server.data.loader.FlatFileLoader;
2425
import org.openlowcode.server.data.loader.FlatFileLoaderColumn;
2526
import org.openlowcode.server.data.specificstorage.ExternalFieldSchema;
2627
import org.openlowcode.server.data.storage.QueryCondition;
@@ -33,7 +34,7 @@
3334
*
3435
* @param <E> parent data object
3536
*/
36-
public class CustomloaderDefinition<E extends DataObject<E>> extends DataObjectPropertyDefinition<E> {
37+
public class CustomloaderDefinition<E extends DataObject<E> & UniqueidentifiedInterface<E>> extends DataObjectPropertyDefinition<E> {
3738

3839
/**
3940
* the interface that a custom loader helper should comply to
@@ -45,6 +46,13 @@ public class CustomloaderDefinition<E extends DataObject<E>> extends DataObjectP
4546
*/
4647
public interface CustomloaderHelper<E extends DataObject<E>> {
4748

49+
/**
50+
* sets the context loader. It can help a helper get an access to a dependent loader / helper
51+
*
52+
* @param flatfileloader
53+
*/
54+
public void setContextLoader(FlatFileLoader<?> flatfileloader);
55+
4856
/**
4957
* gets the loader column for the corresponding column attributes
5058
*

src/org/openlowcode/server/data/properties/HasmultidimensionalchildFlatFileLoaderHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.openlowcode.server.data.ChoiceValue;
2121
import org.openlowcode.server.data.DataObject;
2222
import org.openlowcode.server.data.DataObjectDefinition;
23+
import org.openlowcode.server.data.loader.FlatFileLoader;
2324
import org.openlowcode.server.data.loader.FlatFileLoaderColumn;
2425
import org.openlowcode.server.data.properties.CustomloaderDefinition.CustomloaderHelper;
2526
import org.openlowcode.server.data.properties.multichild.MultichildValueHelper;
@@ -278,6 +279,8 @@ public String[] generateKeyAndLoadExistingData(E currentobject) {
278279

279280
private ArrayList<String> secondaryvalues = new ArrayList<String>();
280281
private E contextobject = null;
282+
@SuppressWarnings("unused")
283+
private FlatFileLoader<?> parentflatfileloader;
281284

282285
public void setSecondaryValueForLoading(int index, String string) {
283286
if (secondaryvalues.size() <= index)
@@ -363,4 +366,12 @@ public boolean generateNewRowForContext(
363366
return true;
364367
}
365368

369+
@Override
370+
public void setContextLoader(FlatFileLoader<?> flatfileloader) {
371+
this.parentflatfileloader = flatfileloader;
372+
373+
}
374+
375+
376+
366377
}

src/org/openlowcode/server/data/properties/multichild/MultichildValueHelper.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,16 @@ public class SecondValueFlatFileLoader
407407
private ChoiceValue<ApplocaleChoiceDefinition> applocale;
408408
private String[] extraattributes;
409409

410+
private F parsedvalue;
411+
412+
public F getParsedValue() {
413+
return parsedvalue;
414+
}
415+
416+
public MultichildValueHelper<E,F,G> getParent() {
417+
return MultichildValueHelper.this;
418+
}
419+
410420
public SecondValueFlatFileLoader(
411421
HasmultidimensionalchildFlatFileLoaderHelper<G, E> helper,
412422
ChoiceValue<ApplocaleChoiceDefinition> applocale,
@@ -430,6 +440,10 @@ public SecondValueFlatFileLoader(
430440
this.extraattributes = extraattributes;
431441
}
432442

443+
public HasmultidimensionalchildFlatFileLoaderHelper<G, E> getHelper() {
444+
return this.helper;
445+
}
446+
433447
@Override
434448
public String[] getValueRestriction() {
435449
return restrictions;
@@ -438,8 +452,9 @@ public String[] getValueRestriction() {
438452
@Override
439453
public boolean load(G object, Object value, PostUpdateProcessingStore<G> postupdateprocessingstore) {
440454
logger.warning("Adding value in index " + index + " value = " + value.toString());
455+
parsedvalue = MultichildValueHelper.this.payloadparser.apply(value, applocale, extraattributes);
441456
helper.setSecondaryValueForLoading(index, MultichildValueHelper.this
442-
.print(MultichildValueHelper.this.payloadparser.apply(value, applocale, extraattributes)));
457+
.print(parsedvalue));
443458

444459
// returns false as no change of value is done
445460
return false;
@@ -552,6 +567,10 @@ public MainValueFlatFileLoader(
552567
this.extraattributes = extraattributes;
553568
}
554569

570+
public HasmultidimensionalchildFlatFileLoaderHelper<G, E> getHelper() {
571+
return this.helper;
572+
}
573+
555574
@Override
556575
public boolean processAfterLineInsertion() {
557576
return true;

0 commit comments

Comments
 (0)