Skip to content

Commit

Permalink
rename example.conf.properties on conf.properties; rename pacakge rep…
Browse files Browse the repository at this point in the history
…ort_to_libreoffice on report; include conf.properties and templates to jar; added FileUtil
  • Loading branch information
Limraj committed Mar 21, 2023
1 parent 2b698a1 commit 5703f01
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 83 deletions.
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'org.scada_lts.report_to_libreoffice.App'
'Main-Class': 'org.scada_lts.report.App'
}
baseName = project.name + '-standalone'
from {
configurations.implementation.collect { it.isDirectory() ? it : zipTree(it) }
}
from("config/") {
include "conf.properties"
}
into("template/") {
from("template")
}
exclude "**/Log4j2Plugins.dat"
with jar
}
Expand Down
8 changes: 4 additions & 4 deletions config/example.conf.properties → config/conf.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ report.month=01
report.day=01
report.before=true
report.localizations=l1,l2,l3,l4,l5
report.template_source_monthly=/opt/PRJ/report-to-libreoffice/template/Usagers_2023_Frequentation_monthly.ods
report.template_source_yearly=/opt/PRJ/report-to-libreoffice/template/Usagers_2023_Frequentation_yearly.ods
report.template_source_daily=/opt/PRJ/report-to-libreoffice/template/Usagers_2023_Frequentation_daily.ods
report.out=/opt/PRJ/report-to-libreoffice/report_out/
report.template_source_monthly=template/Usagers_2023_Frequentation_monthly.ods
report.template_source_yearly=template/Usagers_2023_Frequentation_yearly.ods
report.template_source_daily=template/Usagers_2023_Frequentation_daily.ods
report.out=report_out/
report.formatDateForParseInYearlyReport=yy.MM
report.formatDateForParseInMonthlyReport=dd.MM.yy
report.formatDateForParseInDailyReport=yy.MM.dd
Expand Down
92 changes: 47 additions & 45 deletions src/main/java/org/scada_lts/config/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.scada_lts.config;

import org.scada_lts.utils.BeforeDate;
import org.scada_lts.utils.FileUtil;

import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;

import static org.scada_lts.report_to_libreoffice.PrintLog.error;
import static org.scada_lts.report.PrintLog.error;

/**
* @project count
Expand Down Expand Up @@ -41,63 +41,65 @@ public Date getDate() throws ParseException {
private Configuration() {

Properties prop = new Properties();
FileUtil.getFileFromJar("conf.properties").ifPresent( file -> {
try(InputStream input = new FileInputStream(file)) {

try(InputStream input = new FileInputStream("conf.properties")) {
prop.load(input);

prop.load(input);
String dbUrl = prop.getProperty("report.db.url");
String dbDriver = prop.getProperty("report.db.driver");
String dbuser = prop.getProperty("report.db.user");
String dbpasswd = prop.getProperty("report.db.password");
String tmpYear = prop.getProperty("report.year");
String tmpMonth = prop.getProperty("report.month");
String tmpDay = prop.getProperty("report.day");
String tmpBefore = prop.getProperty("report.before");

String dbUrl = prop.getProperty("report.db.url");
String dbDriver = prop.getProperty("report.db.driver");
String dbuser = prop.getProperty("report.db.user");
String dbpasswd = prop.getProperty("report.db.password");
String tmpYear = prop.getProperty("report.year");
String tmpMonth = prop.getProperty("report.month");
String tmpDay = prop.getProperty("report.day");
String tmpBefore = prop.getProperty("report.before");
String tmpLocalizations = prop.getProperty("report.localizations");
String type = prop.getProperty("report.type");

String tmpLocalizations = prop.getProperty("report.localizations");
String type = prop.getProperty("report.type");
String formatDateForParseInYearlyReport = prop.getProperty("report.formatDateForParseInYearlyReport");
String formatDateForParseInMonthlyReport = prop.getProperty("report.formatDateForParseInMonthlyReport");
String formatDateForParseInDailyReport = prop.getProperty("report.formatDateForParseInDailyReport");

String formatDateForParseInYearlyReport = prop.getProperty("report.formatDateForParseInYearlyReport");
String formatDateForParseInMonthlyReport = prop.getProperty("report.formatDateForParseInMonthlyReport");
String formatDateForParseInDailyReport = prop.getProperty("report.formatDateForParseInDailyReport");

TypeReport tr = type == null ? TypeReport.MONTHLY : TypeReport.typeOf(type);

TypeReport tr = type == null ? TypeReport.MONTHLY : TypeReport.typeOf(type);
BeforeDate beforeDate = new BeforeDate(tmpDay, tmpMonth, tmpYear, tr, Boolean.parseBoolean(tmpBefore));

BeforeDate beforeDate = new BeforeDate(tmpDay, tmpMonth, tmpYear, tr, Boolean.parseBoolean(tmpBefore));
String[] localizations = tmpLocalizations.split(",");

String[] localizations = tmpLocalizations.split(",");
String templateSourceFileYearly = prop.getProperty("report.template_source_yearly");
String templateSourceFileMonthly = prop.getProperty("report.template_source_monthly");
String templateSourceFileDaily = prop.getProperty("report.template_source_daily");
String templateOutDir = prop.getProperty("report.out");

String templateSourceFileYearly = prop.getProperty("report.template_source_yearly");
String templateSourceFileMonthly = prop.getProperty("report.template_source_monthly");
String templateSourceFileDaily = prop.getProperty("report.template_source_daily");
String templateOutDir = prop.getProperty("report.out");

conf = new Config(
dbUrl,
dbDriver,
dbuser,
dbpasswd,
beforeDate.getYear(),
beforeDate.getMonth(),
beforeDate.getDay(),
localizations,
templateSourceFileYearly,
templateSourceFileMonthly,
templateSourceFileDaily,
templateOutDir,
tr.toString(),
formatDateForParseInYearlyReport,
formatDateForParseInMonthlyReport,
formatDateForParseInDailyReport
);

conf = new Config(
dbUrl,
dbDriver,
dbuser,
dbpasswd,
beforeDate.getYear(),
beforeDate.getMonth(),
beforeDate.getDay(),
localizations,
templateSourceFileYearly,
templateSourceFileMonthly,
templateSourceFileDaily,
templateOutDir,
tr.toString(),
formatDateForParseInYearlyReport,
formatDateForParseInMonthlyReport,
formatDateForParseInDailyReport
);

} catch (Exception e) {
error(e.getMessage(), e);
}
});

} catch (Exception e) {
error(e.getMessage(), e);
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/scada_lts/dao/DailyReportDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Locale;
import java.util.Set;

import static org.scada_lts.report_to_libreoffice.PrintLog.*;
import static org.scada_lts.report.PrintLog.*;
import static org.scada_lts.utils.DataUtils.formatPartOfDate;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/scada_lts/dao/MonthlyReportDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.text.SimpleDateFormat;
import java.util.*;

import static org.scada_lts.report_to_libreoffice.PrintLog.*;
import static org.scada_lts.report.PrintLog.*;
import static org.scada_lts.utils.DataUtils.formatPartOfDate;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/scada_lts/dao/YearlyReportDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.Locale;
import java.util.Set;

import static org.scada_lts.report_to_libreoffice.PrintLog.*;
import static org.scada_lts.report.PrintLog.*;
import static org.scada_lts.utils.DataUtils.formatPartOfDate;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.scada_lts.report_to_libreoffice;
package org.scada_lts.report;

import org.scada_lts.config.Configuration;
import org.scada_lts.config.TypeReport;

import static org.scada_lts.report_to_libreoffice.PrintLog.error;
import static org.scada_lts.report_to_libreoffice.PrintLog.p;
import static org.scada_lts.report.PrintLog.error;
import static org.scada_lts.report.PrintLog.p;

public class App {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scada_lts.report_to_libreoffice;
package org.scada_lts.report;

import org.jopendocument.dom.spreadsheet.MutableCell;
import org.jopendocument.dom.spreadsheet.Sheet;
Expand All @@ -15,8 +15,8 @@
import java.util.Locale;
import java.util.Set;

import static org.scada_lts.report_to_libreoffice.PrintLog.error;
import static org.scada_lts.report_to_libreoffice.PrintLog.p;
import static org.scada_lts.report.PrintLog.error;
import static org.scada_lts.report.PrintLog.p;

/**
* @project count
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scada_lts.report_to_libreoffice;
package org.scada_lts.report;


import org.jopendocument.dom.spreadsheet.Sheet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scada_lts.report_to_libreoffice;
package org.scada_lts.report;


import org.jopendocument.dom.spreadsheet.*;
Expand All @@ -17,8 +17,8 @@
import java.util.Locale;
import java.util.Set;

import static org.scada_lts.report_to_libreoffice.PrintLog.error;
import static org.scada_lts.report_to_libreoffice.PrintLog.p;
import static org.scada_lts.report.PrintLog.error;
import static org.scada_lts.report.PrintLog.p;

/**
* @project count
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scada_lts.report_to_libreoffice;
package org.scada_lts.report;

import org.apache.commons.logging.LogFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.scada_lts.report_to_libreoffice;
package org.scada_lts.report;


import org.jopendocument.dom.ODValueType;
import org.jopendocument.dom.spreadsheet.MutableCell;
import org.jopendocument.dom.spreadsheet.Sheet;
import org.jopendocument.dom.spreadsheet.SpreadSheet;
import org.scada_lts.utils.FileUtil;

import java.io.File;

import static org.scada_lts.report_to_libreoffice.PrintLog.error;
import static org.scada_lts.report_to_libreoffice.PrintLog.p;
import static org.scada_lts.report.PrintLog.error;
import static org.scada_lts.report.PrintLog.p;


/**
Expand All @@ -19,19 +20,21 @@
public abstract class Report implements IReportType {

public final void run() {
try {
String reportOdsPath = getReportPath();
String templateOdsPath = getTemplatePath();
SpreadSheet spreadSheet = SpreadSheet.createFromFile(new File(templateOdsPath));
Sheet sheet = spreadSheet.getSheet(0);
createHeader(sheet);
insertData(sheet);
spreadSheet.saveAs(new File(reportOdsPath));
p("done");

} catch (Exception e) {
error(e.getMessage(), e);
}
String reportOdsPath = getReportPath();
String templateOdsPath = getTemplatePath();
FileUtil.getFileFromJar(templateOdsPath).ifPresent(file -> {
try {
SpreadSheet spreadSheet = SpreadSheet.createFromFile(file);
Sheet sheet = spreadSheet.getSheet(0);
createHeader(sheet);
insertData(sheet);
spreadSheet.saveAs(new File(reportOdsPath));
p("done");

} catch (Exception e) {
error(e.getMessage(), e);
}
});

System.exit(0);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scada_lts.report_to_libreoffice;
package org.scada_lts.report;

import org.jopendocument.dom.spreadsheet.Sheet;
import org.scada_lts.config.Configuration;
Expand All @@ -10,8 +10,8 @@
import java.util.Date;
import java.util.Set;

import static org.scada_lts.report_to_libreoffice.PrintLog.error;
import static org.scada_lts.report_to_libreoffice.PrintLog.p;
import static org.scada_lts.report.PrintLog.error;
import static org.scada_lts.report.PrintLog.p;

/**
* @project count
Expand Down
Loading

0 comments on commit 5703f01

Please sign in to comment.