diff --git a/composite-parsers/src/main/java/com/devsoap/parsers/composites/CarunaHelenParser.java b/composite-parsers/src/main/java/com/devsoap/parsers/composites/CarunaHelenParser.java index 51e289e..7c31407 100644 --- a/composite-parsers/src/main/java/com/devsoap/parsers/composites/CarunaHelenParser.java +++ b/composite-parsers/src/main/java/com/devsoap/parsers/composites/CarunaHelenParser.java @@ -1,6 +1,7 @@ package com.devsoap.parsers.composites; import com.devsoap.parsers.caruna.CarunaParser; +import com.devsoap.parsers.helen.HelenParser; import java.io.PrintStream; import java.nio.file.Path; @@ -22,7 +23,7 @@ public class CarunaHelenParser { .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().transferNightKwh)); var daySiirto = carunaPeriods.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().transferDayKwh)); - var helenPeriods = com.devsoap.parsers.helen.Parser.parse(helenFile, daySiirto, nightSiirto); + var helenPeriods = HelenParser.parse(helenFile, daySiirto, nightSiirto); result.println("Kuukausi,Perusmaksu (energia),Perusmaksu (siirto),Päiväenergia (kWh),Päiväenergia " + "(EUR),Yöenergia (kWh),Yöenergia (EUR),Päiväsiirto (kWh),Päiväsiirto (EUR),Yösiirto (kWh)" + @@ -31,7 +32,7 @@ public class CarunaHelenParser { var months = new HashSet<>(carunaPeriods.keySet()); months.addAll(helenPeriods.keySet()); months.forEach(month -> { - var hp = helenPeriods.getOrDefault(month, new com.devsoap.parsers.helen.Parser.Period()); + var hp = helenPeriods.getOrDefault(month, new HelenParser.Period()); var cp = carunaPeriods.getOrDefault(month, new CarunaParser.Period()); var csv = String.format("%s,%.02f,%.02f,%d,%.02f,%d,%.02f,%d,%.02f,%d,%.02f,%.02f", diff --git a/helen-invoice/build.gradle b/helen-invoice/build.gradle index f1d9f1e..8fb3806 100644 --- a/helen-invoice/build.gradle +++ b/helen-invoice/build.gradle @@ -1 +1 @@ -application.mainClass='com.devsoap.parsers.helen.Parser' +application.mainClass='com.devsoap.parsers.helen.HelenParser' diff --git a/helen-invoice/src/main/java/com/devsoap/parsers/helen/Parser.java b/helen-invoice/src/main/java/com/devsoap/parsers/helen/HelenParser.java similarity index 87% rename from helen-invoice/src/main/java/com/devsoap/parsers/helen/Parser.java rename to helen-invoice/src/main/java/com/devsoap/parsers/helen/HelenParser.java index 370c885..334dcbe 100644 --- a/helen-invoice/src/main/java/com/devsoap/parsers/helen/Parser.java +++ b/helen-invoice/src/main/java/com/devsoap/parsers/helen/HelenParser.java @@ -4,10 +4,9 @@ import com.itextpdf.kernel.pdf.PdfDocument; import com.itextpdf.kernel.pdf.PdfReader; import com.itextpdf.kernel.pdf.canvas.parser.PdfTextExtractor; -import java.io.FileNotFoundException; import java.io.IOException; +import java.io.PrintStream; import java.nio.file.Path; -import java.nio.file.Paths; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; @@ -16,7 +15,7 @@ import java.util.*; import java.util.regex.Pattern; import java.util.stream.Collectors; -public class Parser { +public class HelenParser { private static final Pattern PERUSMAKSU_PATTERN = Pattern.compile( "perusmaksu (\\d\\d?\\.\\d\\d?\\.\\d\\d\\d\\d)-(\\d\\d?\\.\\d\\d?\\.\\d\\d\\d\\d).* (\\d*,\\d\\d) e"); @@ -39,23 +38,30 @@ public class Parser { public static void main(String[] args) { var filename = Path.of(args[0]); + var daySiirtoPeriods = args[1]; + var nightSiirtoPeriods = args[2]; + run(filename, daySiirtoPeriods, nightSiirtoPeriods, System.out); + } + + public static void run(Path helenFile, String daySiirtoKwhPeriods, String nightSiirtoKwhPeriods, + PrintStream result) { var daySiirtoKwh = Arrays - .stream(args[1].split(",")) + .stream(daySiirtoKwhPeriods.split(",")) .map(period -> period.split(":")) .collect(Collectors.toMap(values -> values[0], values -> Integer.parseInt(values[1]))); var nightSiirtoKwh = Arrays - .stream(args[2].split(",")) + .stream(nightSiirtoKwhPeriods.split(",")) .map(period -> period.split(":")) .collect(Collectors.toMap(values -> values[0], values -> Integer.parseInt(values[1]))); - System.out.println("Kuukausi,Perusmaksu (energia),Perusmaksu (siirto),Päiväenergia (kWh),Päiväenergia " + + result.println("Kuukausi,Perusmaksu (energia),Perusmaksu (siirto),Päiväenergia (kWh),Päiväenergia " + "(EUR),Yöenergia (kWh),Yöenergia (EUR),Päiväsiirto (kWh),Päiväsiirto (EUR),Yösiirto (kWh)" + ",Yösiirto (EUR),Vero"); - parse(filename,daySiirtoKwh, nightSiirtoKwh).forEach((month,period ) -> { + parse(helenFile,daySiirtoKwh, nightSiirtoKwh).forEach((month,period ) -> { var csv = String.format("%s,%.02f,,%d,%.02f,%d,%.02f,,,,", month, period.basicPay, period.dayEnergy, period.dayEnergyEur,period.nightEnergy, period.nightEnergyEur); - System.out.println(csv); + result.println(csv); }); } diff --git a/helen-invoice/src/main/resources/com/devsoap/parsers/helen/upload.html b/helen-invoice/src/main/resources/com/devsoap/parsers/helen/upload.html new file mode 100644 index 0000000..486c792 --- /dev/null +++ b/helen-invoice/src/main/resources/com/devsoap/parsers/helen/upload.html @@ -0,0 +1,14 @@ + + + +
+ + + + + + + +
+ + \ No newline at end of file diff --git a/rest-api/build.gradle b/rest-api/build.gradle index b8f9ab6..897e3d6 100644 --- a/rest-api/build.gradle +++ b/rest-api/build.gradle @@ -3,6 +3,7 @@ dependencies { implementation "org.thymeleaf:thymeleaf:3.0.11.RELEASE" implementation project(':caruna-invoice') + implementation project(':helen-invoice') implementation project(':composite-parsers') implementation 'org.apache.logging.log4j:log4j-core:2.11.0' diff --git a/rest-api/src/main/java/com/devsoap/parsers/api/Api.java b/rest-api/src/main/java/com/devsoap/parsers/api/Api.java index 776e599..a42a22d 100644 --- a/rest-api/src/main/java/com/devsoap/parsers/api/Api.java +++ b/rest-api/src/main/java/com/devsoap/parsers/api/Api.java @@ -2,6 +2,7 @@ package com.devsoap.parsers.api; import com.devsoap.parsers.caruna.CarunaParser; import com.devsoap.parsers.composites.CarunaHelenParser; +import com.devsoap.parsers.helen.HelenParser; import io.javalin.Javalin; import io.javalin.http.Context; import io.javalin.http.UploadedFile; @@ -43,11 +44,23 @@ public class Api { get(ctx -> ctx.render(renderParserStaticPage(CarunaParser.class, "upload.html"))); post(ctx -> { withUploadedFile(ctx.uploadedFiles().get(0), carunaFile -> { - renderParserOutput(ctx, result -> CarunaParser.run(carunaFile, result), "caruna-report.csv"); + renderParserOutput(ctx, result -> CarunaParser + .run(carunaFile, result), "caruna-report.csv"); }); }); }); + path(HelenParser.class.getSimpleName(), () -> { + get(ctx -> ctx.render(renderParserStaticPage(HelenParser.class, "upload.html"))); + post(ctx -> { + withUploadedFile(ctx.uploadedFiles().get(0), helenFile -> { + renderParserOutput(ctx, result -> HelenParser + .run(helenFile, ctx.formParam("dayKwh"), ctx.formParam("nightKwh"), result) + , "caruna-report.csv"); + }); + }); + }); + path(CarunaHelenParser.class.getSimpleName(), () -> { get(ctx -> ctx.render(renderParserStaticPage(CarunaHelenParser.class, "upload.html"))); post(ctx -> { @@ -59,6 +72,8 @@ public class Api { }); }); }); + + }); }); }