reports-service пофиксил запуск из jar (не мог прочитать ресурсы как файл), убрал томкат сервер (такое когда-то было несколько лет назад с проектом report-srvc)
This commit is contained in:
parent
30a9c39726
commit
62abb0d58b
6 changed files with 30 additions and 19 deletions
|
|
@ -24,6 +24,12 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
|||
|
|
@ -48,4 +48,9 @@ DAILY - все ежедневные
|
|||
|
||||
reports-service.kafka-consumer - группа настроек для подключения к очереди kafka
|
||||
|
||||
и другие настройки.
|
||||
и другие настройки.
|
||||
|
||||
Рабочие папки
|
||||
-------------
|
||||
|
||||
* Из настройки reports-service.ReportModuleOut=./report_out - путь к папке для результатов генерации отчётов
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
package ru.spcex.clearing.reports.notifications;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.spcex.clearing.reports.exceptions.ConfigException;
|
||||
import ru.spcex.clearing.reports.services.DOCXService;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.TextStyle;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class NotificationBuilder {
|
||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||
protected final DateTimeFormatter filenameDateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy'T'HH:mm:ss");
|
||||
protected final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
protected final DOCXService docxService;
|
||||
|
|
@ -41,17 +42,17 @@ public abstract class NotificationBuilder {
|
|||
|
||||
}
|
||||
|
||||
protected File getTemplateFile() {
|
||||
File templateFile;
|
||||
protected URL getTemplateFile() {
|
||||
String templateResourceName = getTemplateResourceName();
|
||||
URL resource = null;
|
||||
try {
|
||||
URL resource = getClass().getClassLoader().getResource(templateResourceName);
|
||||
resource = getClass().getClassLoader().getResource(templateResourceName);
|
||||
if (resource == null) throw new Exception();
|
||||
templateFile = new File(resource.toURI());
|
||||
} catch (Exception e) {
|
||||
throw new ConfigException("Can't read template resource " + templateResourceName, e);
|
||||
throw new ConfigException("Can't read template resource " + templateResourceName +" (URL \""+resource+"\")", e);
|
||||
}
|
||||
return templateFile;
|
||||
log.info("Use resource: {}", resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
protected String normalizeFilenameForOS(String filename) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -43,7 +44,7 @@ public class DOCXService {
|
|||
/**
|
||||
* Файл шаблона
|
||||
*/
|
||||
private File templateFile;
|
||||
private URL templateFile;
|
||||
|
||||
/**
|
||||
* Флаг инициализации
|
||||
|
|
@ -53,13 +54,14 @@ public class DOCXService {
|
|||
/**
|
||||
* (ре)Инициализация сервиса
|
||||
*/
|
||||
public boolean init(File templateFile, String keyPattern) {
|
||||
public boolean init(URL templateFile, String keyPattern) {
|
||||
initialized = false;
|
||||
if (templateFile == null || !templateFile.exists() || !templateFile.isFile()) {
|
||||
log.warn("Invalid templateFile");
|
||||
if (templateFile == null /*|| !templateFile.exists() || !templateFile.isFile()*/) {
|
||||
log.warn("Invalid templateFile {}", templateFile);
|
||||
return false;
|
||||
}
|
||||
this.templateFile = templateFile;
|
||||
log.debug("{} use template from {}", getClass().getSimpleName(), templateFile);
|
||||
if (keyPattern != null) {
|
||||
try {
|
||||
this.keyPattern = Pattern.compile(keyPattern);
|
||||
|
|
@ -108,7 +110,7 @@ public class DOCXService {
|
|||
}
|
||||
}
|
||||
|
||||
try (InputStream inputStream = new FileInputStream(templateFile);
|
||||
try (InputStream inputStream = templateFile.openStream(); //new FileInputStream(templateFile);
|
||||
OutputStream outputStream = new FileOutputStream(outputFile)) {
|
||||
XWPFDocument doc = new XWPFDocument(inputStream);
|
||||
|
||||
|
|
@ -125,7 +127,7 @@ public class DOCXService {
|
|||
boolean checkOk = checkIntersection(valuesMap, notPresentInMap);
|
||||
if (!checkOk) {
|
||||
log.error("Can't insert values in file {}. Keys not in map: {}.",
|
||||
templateFile.getAbsolutePath(),
|
||||
templateFile.toExternalForm()/*templateFile.getAbsolutePath()*/,
|
||||
String.join(", ", notPresentInMap));
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
server.port=8080
|
||||
server.servlet.context-path=/reports_service
|
||||
spring.main.web-application-type=servlet
|
||||
|
||||
|
||||
reports-service.kafka-consumer.bootstrap-servers=localhost:9092
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class DOCXServiceTest {
|
|||
valuesMap.put("${test3}", "======== TEST 3 =========");
|
||||
|
||||
DOCXService service = new DOCXService();
|
||||
service.init(new File(getClass().getClassLoader().getResource("REC.ACTV_TEST.docx").getPath()), null);
|
||||
service.init(getClass().getClassLoader().getResource("REC.ACTV_TEST.docx"), null);
|
||||
service.insertValues(new File("output.docx"),
|
||||
valuesMap,
|
||||
false);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue