added download from excel and zip in frontend
This commit is contained in:
@@ -5,7 +5,6 @@ import java.util.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.ejb.EJB;
|
||||
import jakarta.ejb.LocalBean;
|
||||
import jakarta.ejb.Stateless;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -13,7 +12,6 @@ import jakarta.persistence.TypedQuery;
|
||||
import jakarta.persistence.criteria.*;
|
||||
import marketing.heyday.hartmann.fotodocumentation.core.model.Questionnaire;
|
||||
import marketing.heyday.hartmann.fotodocumentation.core.model.QuestionnaireCustomer;
|
||||
import marketing.heyday.hartmann.fotodocumentation.core.query.QueryService;
|
||||
import marketing.heyday.hartmann.fotodocumentation.core.utils.CalendarUtil;
|
||||
import marketing.heyday.hartmann.fotodocumentation.core.utils.ExcelUtils;
|
||||
import marketing.heyday.hartmann.fotodocumentation.core.utils.ZipExportUtils;
|
||||
@@ -35,9 +33,6 @@ import marketing.heyday.hartmann.fotodocumentation.rest.vo.QuestionnaireCustomer
|
||||
@PermitAll
|
||||
public class QuestionnaireCustomerService extends AbstractService {
|
||||
|
||||
@EJB
|
||||
private QueryService queryService;
|
||||
|
||||
@Inject
|
||||
private ZipExportUtils zipExportUtils;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class ExcelUtilsTest implements TestAble {
|
||||
@Test
|
||||
void create_singleQuestionnaire_returnsPresent() {
|
||||
QuestionnaireCustomer customer = createCustomer("Müller GmbH", "C-001", "Berlin", "10115");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date(), "What is your rating?");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date());
|
||||
|
||||
Optional<byte[]> result = excelUtils.create(customer, List.of(questionnaire));
|
||||
|
||||
@@ -51,7 +51,7 @@ class ExcelUtilsTest implements TestAble {
|
||||
@Test
|
||||
void create_singleQuestionnaire_returnsValidXlsx() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Müller GmbH", "C-001", "Berlin", "10115");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date(), "What is your rating?");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date());
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(questionnaire)).orElseThrow();
|
||||
|
||||
@@ -61,14 +61,11 @@ class ExcelUtilsTest implements TestAble {
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_emptyQuestionnaires_returnsEmptyWorkbook() throws IOException {
|
||||
void create_emptyQuestionnaires_returnsEmptyWorkbook() {
|
||||
QuestionnaireCustomer customer = createCustomer("Müller GmbH", "C-001", "Berlin", "10115");
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, Collections.emptyList()).orElseThrow();
|
||||
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(bytes))) {
|
||||
assertEquals(0, workbook.getNumberOfSheets());
|
||||
}
|
||||
Optional<byte[]> result = excelUtils.create(customer, Collections.emptyList());
|
||||
assertFalse(result.isPresent());
|
||||
}
|
||||
|
||||
// --- create: sheet count ---
|
||||
@@ -76,7 +73,7 @@ class ExcelUtilsTest implements TestAble {
|
||||
@Test
|
||||
void create_singleQuestionnaire_createsOneSheet() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Müller GmbH", "C-001", "Berlin", "10115");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date(), "Q1");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date());
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(questionnaire)).orElseThrow();
|
||||
|
||||
@@ -88,9 +85,9 @@ class ExcelUtilsTest implements TestAble {
|
||||
@Test
|
||||
void create_multipleQuestionnaires_createsSheetPerQuestionnaire() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Müller GmbH", "C-001", "Berlin", "10115");
|
||||
Questionnaire q1 = createQuestionnaire(new Date(), "Q1");
|
||||
Questionnaire q2 = createQuestionnaire(new Date(), "Q2");
|
||||
Questionnaire q3 = createQuestionnaire(new Date(), "Q3");
|
||||
Questionnaire q1 = createQuestionnaire(new Date());
|
||||
Questionnaire q2 = createQuestionnaire(new Date());
|
||||
Questionnaire q3 = createQuestionnaire(new Date());
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(q1, q2, q3)).orElseThrow();
|
||||
|
||||
@@ -106,73 +103,24 @@ class ExcelUtilsTest implements TestAble {
|
||||
@Test
|
||||
void create_writesCustomerNameInRow0() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Hartmann AG", "C-100", "München", "80331");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date(), "Q1");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date());
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(questionnaire)).orElseThrow();
|
||||
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(bytes))) {
|
||||
assertEquals("Hartmann AG", workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_writesCustomerNumberInRow1() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Hartmann AG", "C-100", "München", "80331");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date(), "Q1");
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(questionnaire)).orElseThrow();
|
||||
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(bytes))) {
|
||||
assertEquals("C-100", workbook.getSheetAt(0).getRow(1).getCell(0).getStringCellValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_writesCustomerCityInRow2() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Hartmann AG", "C-100", "München", "80331");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date(), "Q1");
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(questionnaire)).orElseThrow();
|
||||
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(bytes))) {
|
||||
assertEquals("München", workbook.getSheetAt(0).getRow(2).getCell(0).getStringCellValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_writesCustomerZipInRow3() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Hartmann AG", "C-100", "München", "80331");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date(), "Q1");
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(questionnaire)).orElseThrow();
|
||||
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(bytes))) {
|
||||
assertEquals("80331", workbook.getSheetAt(0).getRow(3).getCell(0).getStringCellValue());
|
||||
}
|
||||
}
|
||||
|
||||
// --- create: questionnaire date in row 4 ---
|
||||
|
||||
@Test
|
||||
void create_writesQuestionnaireDateInRow4() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Test", "C-001", "Berlin", "10115");
|
||||
Date date = new Date();
|
||||
Questionnaire questionnaire = createQuestionnaire(date, "Q1");
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(questionnaire)).orElseThrow();
|
||||
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(bytes))) {
|
||||
XSSFRow row = workbook.getSheetAt(0).getRow(4);
|
||||
assertEquals(date, row.getCell(0).getDateCellValue());
|
||||
}
|
||||
}
|
||||
|
||||
// --- create: question data in row 7 (after 5 customer rows + 2 blank rows) ---
|
||||
|
||||
@Test
|
||||
void create_writesFirstQuestionTitleInRow7() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Test", "C-001", "Berlin", "10115");
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date(), null);
|
||||
Questionnaire questionnaire = createQuestionnaire(new Date());
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(questionnaire)).orElseThrow();
|
||||
|
||||
@@ -190,7 +138,7 @@ class ExcelUtilsTest implements TestAble {
|
||||
@Test
|
||||
void create_nullCustomerFields_writesNullsWithoutError() {
|
||||
QuestionnaireCustomer customer = createCustomer(null, null, null, null);
|
||||
Questionnaire questionnaire = createQuestionnaire(null, null);
|
||||
Questionnaire questionnaire = createQuestionnaire(null);
|
||||
|
||||
Optional<byte[]> result = excelUtils.create(customer, List.of(questionnaire));
|
||||
|
||||
@@ -202,8 +150,8 @@ class ExcelUtilsTest implements TestAble {
|
||||
@Test
|
||||
void create_multipleSheets_eachSheetHasCustomerData() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Hartmann AG", "C-100", "München", "80331");
|
||||
Questionnaire q1 = createQuestionnaire(new Date(), "Q1");
|
||||
Questionnaire q2 = createQuestionnaire(new Date(), "Q2");
|
||||
Questionnaire q1 = createQuestionnaire(new Date());
|
||||
Questionnaire q2 = createQuestionnaire(new Date());
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(q1, q2)).orElseThrow();
|
||||
|
||||
@@ -219,8 +167,8 @@ class ExcelUtilsTest implements TestAble {
|
||||
@Test
|
||||
void create_multipleSheets_eachSheetHasQuestionData() throws IOException {
|
||||
QuestionnaireCustomer customer = createCustomer("Test", "C-001", "Berlin", "10115");
|
||||
Questionnaire q1 = createQuestionnaire(new Date(), null);
|
||||
Questionnaire q2 = createQuestionnaire(new Date(), null);
|
||||
Questionnaire q1 = createQuestionnaire(new Date());
|
||||
Questionnaire q2 = createQuestionnaire(new Date());
|
||||
|
||||
byte[] bytes = excelUtils.create(customer, List.of(q1, q2)).orElseThrow();
|
||||
|
||||
@@ -243,7 +191,7 @@ class ExcelUtilsTest implements TestAble {
|
||||
.build();
|
||||
}
|
||||
|
||||
private Questionnaire createQuestionnaire(Date date, String questions) {
|
||||
private Questionnaire createQuestionnaire(Date date) {
|
||||
return new Questionnaire.Builder()
|
||||
.questionnaireDate(date)
|
||||
.questions(QuestionnaireJsonParserTest.TEST_JSON_1)
|
||||
|
||||
Reference in New Issue
Block a user