mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-17 20:50:44 +00:00
Feedback from code reviews
This commit is contained in:
@ -206,12 +206,10 @@ public abstract class AbstractBaseFilesystemAction<FILE>
|
||||
{
|
||||
new CsvToQRecordAdapter().buildRecordsFromCsv(queryInput.getRecordPipe(), fileContents, table, null, (record ->
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// since the CSV adapter is the one responsible for putting records into the pipe (rather than the queryOutput), //
|
||||
// we must do some of QueryOutput's normal job here - and run the runPostQueryRecordCustomizer //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Before the records go into the pipe, make sure their backend details are added to them //
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
addBackendDetailsToRecord(record, file);
|
||||
queryOutput.runPostQueryRecordCustomizer(record);
|
||||
}));
|
||||
}
|
||||
else
|
||||
@ -308,7 +306,7 @@ public abstract class AbstractBaseFilesystemAction<FILE>
|
||||
*******************************************************************************/
|
||||
private String customizeFileContentsAfterReading(QTableMetaData table, String fileContents) throws QException
|
||||
{
|
||||
Optional<QCodeReference> optionalCustomizer = table.getCustomizer(FilesystemCustomizers.POST_READ_FILE);
|
||||
Optional<QCodeReference> optionalCustomizer = table.getCustomizer(FilesystemTableCustomizers.POST_READ_FILE.getRole());
|
||||
if(optionalCustomizer.isEmpty())
|
||||
{
|
||||
return (fileContents);
|
||||
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2022. 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.module.filesystem.base.actions;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.actions.customizers.Customizers;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Standard place where the names of QQQ Customization points for filesystem-based
|
||||
** backends are defined.
|
||||
*******************************************************************************/
|
||||
public interface FilesystemCustomizers extends Customizers
|
||||
{
|
||||
String POST_READ_FILE = "postReadFile";
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.kingsrook.qqq.backend.module.filesystem.base.actions;
|
||||
|
||||
|
||||
import java.util.function.Function;
|
||||
import com.kingsrook.qqq.backend.core.actions.customizers.TableCustomizer;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public enum FilesystemTableCustomizers
|
||||
{
|
||||
POST_READ_FILE(new TableCustomizer("postReadFile", Function.class, ((Object x) ->
|
||||
{
|
||||
Function<String, String> function = (Function<String, String>) x;
|
||||
String output = function.apply(new String());
|
||||
})));
|
||||
|
||||
private final TableCustomizer tableCustomizer;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
FilesystemTableCustomizers(TableCustomizer tableCustomizer)
|
||||
{
|
||||
this.tableCustomizer = tableCustomizer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Get the FilesystemTableCustomer for a given role (e.g., the role used in meta-data, not
|
||||
** the enum-constant name).
|
||||
*******************************************************************************/
|
||||
public static FilesystemTableCustomizers forRole(String name)
|
||||
{
|
||||
for(FilesystemTableCustomizers value : values())
|
||||
{
|
||||
if(value.tableCustomizer.getRole().equals(name))
|
||||
{
|
||||
return (value);
|
||||
}
|
||||
}
|
||||
|
||||
return (null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for tableCustomizer
|
||||
**
|
||||
*******************************************************************************/
|
||||
public TableCustomizer getTableCustomizer()
|
||||
{
|
||||
return tableCustomizer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** get the role from the tableCustomizer
|
||||
**
|
||||
*******************************************************************************/
|
||||
public String getRole()
|
||||
{
|
||||
return (tableCustomizer.getRole());
|
||||
}
|
||||
|
||||
}
|
@ -91,7 +91,7 @@ public class FilesystemSyncStep implements BackendStep
|
||||
String sourceFileName = sourceEntry.getKey();
|
||||
if(!archiveFiles.contains(sourceFileName))
|
||||
{
|
||||
LOG.info("Syncing file [" + sourceFileName + "] to [" + archiveTable.getName() + "] and [" + processingTable.getName() + "]");
|
||||
LOG.info("Syncing file [" + sourceFileName + "] to [" + archiveTable + "] and [" + processingTable + "]");
|
||||
InputStream inputStream = sourceActionBase.readFile(sourceEntry.getValue());
|
||||
byte[] bytes = inputStream.readAllBytes();
|
||||
|
||||
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2022. 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.module.filesystem;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class FilesystemModuleJunitExtension // implements Extension, BeforeAllCallback, AfterAllCallback
|
||||
{
|
||||
}
|
@ -22,22 +22,16 @@
|
||||
package com.kingsrook.qqq.backend.module.filesystem.local.actions;
|
||||
|
||||
|
||||
import java.util.function.Function;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.count.CountInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.count.CountOutput;
|
||||
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.code.QCodeUsage;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.module.filesystem.TestUtils;
|
||||
import com.kingsrook.qqq.backend.module.filesystem.base.actions.FilesystemCustomizers;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Unit test for FilesystemCountAction
|
||||
*******************************************************************************/
|
||||
public class FilesystemCountActionTest extends FilesystemActionTest
|
||||
{
|
||||
@ -55,35 +49,4 @@ public class FilesystemCountActionTest extends FilesystemActionTest
|
||||
Assertions.assertEquals(3, countOutput.getCount(), "Unfiltered count should find all rows");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void testCountWithFileCustomizer() throws QException
|
||||
{
|
||||
CountInput countInput = new CountInput();
|
||||
QInstance instance = TestUtils.defineInstance();
|
||||
|
||||
QTableMetaData table = instance.getTable(TestUtils.TABLE_NAME_PERSON_LOCAL_FS_JSON);
|
||||
table.withCustomizer(FilesystemCustomizers.POST_READ_FILE, new QCodeReference(ValueUpshifter.class, QCodeUsage.CUSTOMIZER));
|
||||
|
||||
countInput.setInstance(instance);
|
||||
countInput.setTableName(TestUtils.defineLocalFilesystemJSONPersonTable().getName());
|
||||
CountOutput countOutput = new FilesystemCountAction().execute(countInput);
|
||||
Assertions.assertEquals(3, countOutput.getCount(), "Unfiltered count should find all rows");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class ValueUpshifter implements Function<String, String>
|
||||
{
|
||||
@Override
|
||||
public String apply(String s)
|
||||
{
|
||||
return (s.replaceAll("kingsrook.com", "KINGSROOK.COM"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -32,7 +32,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeUsage;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.module.filesystem.TestUtils;
|
||||
import com.kingsrook.qqq.backend.module.filesystem.base.FilesystemRecordBackendDetailFields;
|
||||
import com.kingsrook.qqq.backend.module.filesystem.base.actions.FilesystemCustomizers;
|
||||
import com.kingsrook.qqq.backend.module.filesystem.base.actions.FilesystemTableCustomizers;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -71,7 +71,7 @@ public class FilesystemQueryActionTest extends FilesystemActionTest
|
||||
QInstance instance = TestUtils.defineInstance();
|
||||
|
||||
QTableMetaData table = instance.getTable(TestUtils.TABLE_NAME_PERSON_LOCAL_FS_JSON);
|
||||
table.withCustomizer(FilesystemCustomizers.POST_READ_FILE, new QCodeReference(ValueUpshifter.class, QCodeUsage.CUSTOMIZER));
|
||||
table.withCustomizer(FilesystemTableCustomizers.POST_READ_FILE.getRole(), new QCodeReference(ValueUpshifter.class, QCodeUsage.CUSTOMIZER));
|
||||
|
||||
queryInput.setInstance(instance);
|
||||
queryInput.setTableName(TestUtils.defineLocalFilesystemJSONPersonTable().getName());
|
||||
|
Reference in New Issue
Block a user