Add REST API for Helen parser
This commit is contained in:
parent
bec6898e38
commit
4b29325f32
|
@ -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",
|
||||
|
|
|
@ -1 +1 @@
|
|||
application.mainClass='com.devsoap.parsers.helen.Parser'
|
||||
application.mainClass='com.devsoap.parsers.helen.HelenParser'
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<meta charset="UTF-8">
|
||||
<html>
|
||||
<body>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<label for="helenFile">Helen File:</label>
|
||||
<input type="file" id="helenFile" name="helen.pdf" required />
|
||||
<label for="dayKwh">Day Siirto Kwh Periods:</label>
|
||||
<input type="text" id="dayKwh" name="dayKwh" required />
|
||||
<label for="nightKwh">Night Siirto Kwh Periods:</label>
|
||||
<input type="text" id="nightKwh" name="nightKwh" required/>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -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'
|
||||
|
|
|
@ -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 {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue