Merged feature/dk-misc-20250318 into dev

This commit is contained in:
2025-03-27 12:04:21 -05:00
39 changed files with 1016 additions and 203 deletions

View File

@ -22,12 +22,19 @@
package com.kingsrook.qqq.backend.core.actions.customizers;
import java.util.Map;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.model.metadata.code.InitializableViaCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReferenceWithProperties;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
import com.kingsrook.qqq.backend.core.utils.Timer;
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
/*******************************************************************************
@ -80,6 +87,7 @@ class QCodeLoaderTest extends BaseTest
}
/*******************************************************************************
**
*******************************************************************************/
@ -91,4 +99,50 @@ class QCodeLoaderTest extends BaseTest
}
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testCodeReferenceWithProperties()
{
assertNull(QCodeLoader.getAdHoc(SomeClass.class, new QCodeReference(SomeClass.class)));
SomeClass someObject = QCodeLoader.getAdHoc(SomeClass.class, new QCodeReferenceWithProperties(SomeClass.class, Map.of("property", "someValue")));
assertEquals("someValue", someObject.someProperty);
SomeClass someOtherObject = QCodeLoader.getAdHoc(SomeClass.class, new QCodeReferenceWithProperties(SomeClass.class, Map.of("property", "someOtherValue")));
assertEquals("someOtherValue", someOtherObject.someProperty);
}
/***************************************************************************
**
***************************************************************************/
public static class SomeClass implements InitializableViaCodeReference
{
private String someProperty;
/***************************************************************************
**
***************************************************************************/
@Override
public void initialize(QCodeReference codeReference)
{
if(codeReference instanceof QCodeReferenceWithProperties codeReferenceWithProperties)
{
someProperty = ValueUtils.getValueAsString(codeReferenceWithProperties.getProperties().get("property"));
}
if(!StringUtils.hasContent(someProperty))
{
throw new IllegalStateException("Missing property");
}
}
}
}

View File

@ -38,6 +38,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.actions.reporting.excel.TestExcelStyler;
import com.kingsrook.qqq.backend.core.actions.reporting.excel.fastexcel.ExcelFastexcelExportStreamer;
import com.kingsrook.qqq.backend.core.actions.reporting.excel.poi.BoldHeaderAndFooterPoiExcelStyler;
import com.kingsrook.qqq.backend.core.actions.reporting.excel.poi.ExcelPoiBasedStreamingExportStreamer;
@ -56,6 +57,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.fields.DisplayFormat;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
@ -490,6 +492,34 @@ public class GenerateReportActionTest extends BaseTest
/*******************************************************************************
**
*******************************************************************************/
@Test
void runXlsxWithStyleCustomizer() throws Exception
{
ReportFormat format = ReportFormat.XLSX;
String name = "/tmp/report-customized.xlsx";
try(FileOutputStream fileOutputStream = new FileOutputStream(name))
{
QInstance qInstance = QContext.getQInstance();
qInstance.addReport(defineTableOnlyReport());
insertPersonRecords(qInstance);
ReportInput reportInput = new ReportInput();
reportInput.setReportName(REPORT_NAME);
reportInput.setReportDestination(new ReportDestination().withReportFormat(format).withReportOutputStream(fileOutputStream));
reportInput.setInputValues(Map.of("startDate", LocalDate.of(1970, Month.MAY, 15), "endDate", LocalDate.now()));
reportInput.setExportStyleCustomizer(new QCodeReference(TestExcelStyler.class));
new GenerateReportAction().execute(reportInput);
System.out.println("Wrote File: " + name);
LocalMacDevUtils.openFile(name);
}
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -0,0 +1,76 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.backend.core.actions.reporting.excel;
import java.util.List;
import java.util.Map;
import com.kingsrook.qqq.backend.core.actions.reporting.excel.poi.ExcelPoiBasedStreamingStyleCustomizerInterface;
import com.kingsrook.qqq.backend.core.model.metadata.reporting.QReportView;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/*******************************************************************************
**
*******************************************************************************/
public class TestExcelStyler implements ExcelPoiBasedStreamingStyleCustomizerInterface
{
/***************************************************************************
**
***************************************************************************/
@Override
public List<Integer> getColumnWidthsForView(QReportView view)
{
return List.of(60, 50, 40);
}
/***************************************************************************
**
***************************************************************************/
@Override
public List<String> getMergedRangesForView(QReportView view)
{
return List.of("A1:B1");
}
/***************************************************************************
**
***************************************************************************/
@Override
public void customizeStyles(Map<String, XSSFCellStyle> styles, XSSFWorkbook workbook, CreationHelper createHelper)
{
Font font = workbook.createFont();
font.setFontHeightInPoints((short) 16);
font.setBold(true);
XSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFont(font);
styles.put("header", cellStyle);
}
}

View File

@ -41,6 +41,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -566,4 +567,22 @@ class QRecordEntityTest extends BaseTest
assertEquals(0, order.getLineItems().size());
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testTableName() throws QException
{
assertEquals(Item.TABLE_NAME, QRecordEntity.getTableName(Item.class));
assertEquals(Item.TABLE_NAME, Item.getTableName(Item.class));
assertEquals(Item.TABLE_NAME, new Item().tableName());
//////////////////////////////////
// no TABLE_NAME in Order class //
//////////////////////////////////
assertThatThrownBy(() -> Order.getTableName(Order.class));
}
}

View File

@ -22,8 +22,22 @@
package com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Optional;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.actions.tables.StorageAction;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.storage.StorageInput;
import com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert.model.BulkLoadProfile;
import com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert.model.BulkLoadProfileField;
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -66,4 +80,39 @@ class BulkInsertPrepareFileMappingStepTest extends BaseTest
assertEquals("BAA", BulkInsertPrepareFileMappingStep.toHeaderLetter(2 * 26 * 26 + 26 + 0));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void test() throws Exception
{
String fileName = "personFile.csv";
StorageInput storageInput = new StorageInput(TestUtils.TABLE_NAME_MEMORY_STORAGE).withReference(fileName);
OutputStream outputStream = new StorageAction().createOutputStream(storageInput);
outputStream.write("""
name,noOfShoes
John,2
Jane,4
""".getBytes(StandardCharsets.UTF_8));
outputStream.close();
RunProcessInput runProcessInput = new RunProcessInput();
BulkInsertStepUtils.setStorageInputForTheFile(runProcessInput, storageInput);
runProcessInput.addValue("tableName", TestUtils.TABLE_NAME_PERSON_MEMORY);
runProcessInput.addValue("prepopulatedValues", JsonUtils.toJson(Map.of("homeStateId", 1)));
RunBackendStepInput runBackendStepInput = new RunBackendStepInput(runProcessInput.getProcessState());
RunBackendStepOutput runBackendStepOutput = new RunBackendStepOutput();
new BulkInsertPrepareFileMappingStep().run(runBackendStepInput, runBackendStepOutput);
BulkLoadProfile bulkLoadProfile = (BulkLoadProfile) runBackendStepOutput.getValue("suggestedBulkLoadProfile");
Optional<BulkLoadProfileField> homeStateId = bulkLoadProfile.getFieldList().stream().filter(f -> f.getFieldName().equals("homeStateId")).findFirst();
assertThat(homeStateId).isPresent();
assertEquals("1", homeStateId.get().getDefaultValue());
}
}