update instance enricher to make children of app-sections become children of apps

This commit is contained in:
2023-11-30 20:17:50 -06:00
parent 0c6d8d23c2
commit 19d7559dbf
2 changed files with 107 additions and 0 deletions

View File

@ -77,6 +77,7 @@ import com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert.Bulk
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.ExtractViaQueryStep;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.StreamedETLWithFrontendProcess;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import com.kingsrook.qqq.backend.core.utils.ListingHash;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
@ -531,11 +532,70 @@ public class QInstanceEnricher
enrichAppSection(section);
}
ensureAppSectionMembersAreAppChildren(app);
enrichPermissionRules(app);
}
/*******************************************************************************
**
*******************************************************************************/
private void ensureAppSectionMembersAreAppChildren(QAppMetaData app)
{
ListingHash<Class<? extends QAppChildMetaData>, String> childrenByType = new ListingHash<>();
childrenByType.put(QTableMetaData.class, new ArrayList<>());
childrenByType.put(QProcessMetaData.class, new ArrayList<>());
childrenByType.put(QReportMetaData.class, new ArrayList<>());
for(QAppChildMetaData qAppChildMetaData : CollectionUtils.nonNullList(app.getChildren()))
{
childrenByType.add(qAppChildMetaData.getClass(), qAppChildMetaData.getName());
}
for(QAppSection section : CollectionUtils.nonNullList(app.getSections()))
{
for(String tableName : CollectionUtils.nonNullList(section.getTables()))
{
if(!childrenByType.get(QTableMetaData.class).contains(tableName))
{
QTableMetaData table = qInstance.getTable(tableName);
if(table != null)
{
app.withChild(table);
}
}
}
for(String processName : CollectionUtils.nonNullList(section.getProcesses()))
{
if(!childrenByType.get(QProcessMetaData.class).contains(processName))
{
QProcessMetaData process = qInstance.getProcess(processName);
if(process != null)
{
app.withChild(process);
}
}
}
for(String reportName : CollectionUtils.nonNullList(section.getReports()))
{
if(!childrenByType.get(QReportMetaData.class).contains(reportName))
{
QReportMetaData report = qInstance.getReport(reportName);
if(report != null)
{
app.withChild(report);
}
}
}
}
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -36,6 +36,8 @@ import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinOn;
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinType;
import com.kingsrook.qqq.backend.core.model.metadata.joins.QJoinMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppSection;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.tables.ExposedJoin;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QFieldSection;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
@ -45,6 +47,7 @@ import org.junit.jupiter.api.Test;
import static com.kingsrook.qqq.backend.core.utils.TestUtils.APP_NAME_GREETINGS;
import static com.kingsrook.qqq.backend.core.utils.TestUtils.APP_NAME_MISCELLANEOUS;
import static com.kingsrook.qqq.backend.core.utils.TestUtils.APP_NAME_PEOPLE;
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.assertNotNull;
@ -258,6 +261,50 @@ class QInstanceEnricherTest extends BaseTest
/*******************************************************************************
**
*******************************************************************************/
@Test
void testAppSectionMembersBecomeAppChildren()
{
QInstance qInstance = new QInstance();
qInstance.addTable(new QTableMetaData().withName("table1"));
qInstance.addProcess(new QProcessMetaData().withName("process1"));
qInstance.addApp(new QAppMetaData().withName("app1")
.withSection(new QAppSection().withTable("table1").withProcess("process1")));
/////////////////////////////////////////////////////
// first, show that the list of children was empty //
/////////////////////////////////////////////////////
assertThat(qInstance.getApp("app1").getChildren()).isNullOrEmpty();
/////////////////////////////
// now enrich the instance //
/////////////////////////////
new QInstanceEnricher(qInstance).enrich();
///////////////////////////////////////////////////////////////
// and now the table & process should be children of the app //
///////////////////////////////////////////////////////////////
assertThat(qInstance.getApp("app1").getChildren())
.contains(qInstance.getTable("table1"), qInstance.getProcess("process1"));
//////////////////////////////////////////////////////////////////
// make sure that re-enhancement doesn't duplicate the children //
//////////////////////////////////////////////////////////////////
new QInstanceEnricher(qInstance).enrich();
assertThat(qInstance.getApp("app1").getChildren()).hasSize(2);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// add a non-existing table - make sure we don't blow up, and in this case, it won't be added as a child //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
qInstance.getApp("app1").getSections().get(0).withTable("notATable");
new QInstanceEnricher(qInstance).enrich();
assertThat(qInstance.getApp("app1").getChildren()).hasSize(2);
}
/*******************************************************************************
**
*******************************************************************************/