Skip to content

Commit

Permalink
mekomsolutions#277 - CSV parser should save cached objects once file …
Browse files Browse the repository at this point in the history
…has been loaded.
  • Loading branch information
Amos Laboso committed Sep 13, 2024
1 parent 89060c1 commit ece3869
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PaymentModesCsvParser extends CsvParser<PaymentMode, BaseLineProces

@Autowired
public PaymentModesCsvParser(@Qualifier("cashierPaymentModeService") IPaymentModeService paymentModeService,
PaymentModesLineProcessor processor) {
PaymentModesLineProcessor processor) {
super(processor);
this.paymentModeService = paymentModeService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ public PaymentMode fill(PaymentMode paymentMode, CsvLine line) throws IllegalArg

String attributes = line.get(HEADER_ATTRIBUTES, false);
if (StringUtils.isNotBlank(attributes)) {
paymentMode.getAttributeTypes().clear();
if (paymentMode.getAttributeTypes() != null) {
paymentMode.getAttributeTypes().clear();
}
for (String attribute : attributes.split(BaseLineProcessor.LIST_SEPARATOR)) {
String[] parts = attribute.trim().split("::");
if (parts.length > 3) {
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(), Boolean.parseBoolean(parts[3].trim()));
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(),
Boolean.parseBoolean(parts[3].trim()));
} else if (parts.length > 2) {
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(), false);
} else if (parts.length > 1) {
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), null, false);
} else {
paymentMode.addAttributeType(parts[0].trim(), null, null, false);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ public void load_shouldLoadPaymentModesAccordingToCsvFiles() {
{
PaymentMode paymentMode = paymentModeService.getByUuid("e168c141-f5fd-4eec-bd3e-633bed1c9606");
assertNotNull(paymentMode);
assertEquals("Nutrition Cash Item", paymentMode.getName());
assertEquals("Paypal", paymentMode.getName());

paymentMode.getAttributeTypes().forEach(attributeType -> {
if (attributeType.getName().equals("Maximum")) {
assertEquals("Numeric", attributeType.getFormat());
assertTrue(attributeType.getRequired());
} else {
assertEquals("Minimum", attributeType.getName());
}
});
}

// Verify edition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
uuid,Void/Retire,name,attributes
526bf278-ba81-4436-b867-c2f6641d060a,,Visa card edited,
2b1b9aae-5d35-43dd-9214-3fd370fd7737,true,Bank transfer,
fd0ff4ff-dec2-47f5-bb19-5c93b400e94c,,Paypal,Maximum::Numeric::::True;Minimum
e168c141-f5fd-4eec-bd3e-633bed1c9606,,Paypal,Maximum::Numeric::::True;Minimum
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public List<String[]> getLines() {
* @return The resulting CsvParserResult instance.
*/
public CsvFailingLines process(List<String[]> lines) {
Context.flushSession();
Context.clearSession();

CsvFailingLines result = new CsvFailingLines();
int saved = 0;
Expand All @@ -211,9 +213,6 @@ public CsvFailingLines process(List<String[]> lines) {
}
}

Context.flushSession();
Context.clearSession();

return result;
}

Expand Down

0 comments on commit ece3869

Please sign in to comment.