From d086284de78923525f70b91e97127b1841422afd Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Thu, 20 Apr 2023 09:35:12 -0500 Subject: [PATCH] Checkpoint --- .../core/instances/QInstanceEnricher.java | 74 ++++++++++ .../model/metadata/tables/ExposedJoin.java | 130 ++++++++++++++++++ .../model/metadata/tables/QTableMetaData.java | 49 +++++++ 3 files changed, 253 insertions(+) create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/ExposedJoin.java diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/instances/QInstanceEnricher.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/instances/QInstanceEnricher.java index 8746b4a1..70185db0 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/instances/QInstanceEnricher.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/instances/QInstanceEnricher.java @@ -32,7 +32,9 @@ import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import com.kingsrook.qqq.backend.core.actions.metadata.JoinGraph; import com.kingsrook.qqq.backend.core.actions.permissions.BulkTableActionProcessPermissionChecker; +import com.kingsrook.qqq.backend.core.exceptions.QException; import com.kingsrook.qqq.backend.core.logging.QLogger; import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData; import com.kingsrook.qqq.backend.core.model.metadata.QInstance; @@ -59,6 +61,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.processes.QStepMetaData; import com.kingsrook.qqq.backend.core.model.metadata.reporting.QReportDataSource; import com.kingsrook.qqq.backend.core.model.metadata.reporting.QReportMetaData; import com.kingsrook.qqq.backend.core.model.metadata.reporting.QReportView; +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.QMiddlewareTableMetaData; import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData; @@ -144,6 +147,77 @@ public class QInstanceEnricher { qInstance.getWidgets().values().forEach(this::enrichWidget); } + + if(CollectionUtils.nullSafeHasContents(qInstance.getJoins())) + { + //todo! enrichJoins(); + } + } + + + + /******************************************************************************* + ** + *******************************************************************************/ + private void enrichJoins() + { + try + { + JoinGraph joinGraph = new JoinGraph(qInstance); + + for(QTableMetaData table : qInstance.getTables().values()) + { + Set joinConnections = joinGraph.getJoinConnections(table.getName()); + for(ExposedJoin exposedJoin : CollectionUtils.nonNullList(table.getExposedJoins())) + { + ///////////////////////////////////////////////////////////////////////////////////////////////////// + // proceed with caution - remember, validator will fail the instance if things are missing/invalid // + ///////////////////////////////////////////////////////////////////////////////////////////////////// + if(exposedJoin.getJoinTable() != null) + { + QTableMetaData joinTable = qInstance.getTable(exposedJoin.getJoinTable()); + if(joinTable != null) + { + ////////////////////////////////////////////////////////////////////////////////// + // default the exposed join's label to the join table's label, if it wasn't set // + ////////////////////////////////////////////////////////////////////////////////// + if(!StringUtils.hasContent(exposedJoin.getLabel())) + { + exposedJoin.setLabel(joinTable.getLabel()); + } + + /////////////////////////////////////////////////////////////////////////////// + // default the exposed join's join-path from the joinGraph, if it wasn't set // + /////////////////////////////////////////////////////////////////////////////// + if(CollectionUtils.nullSafeIsEmpty(exposedJoin.getJoinPath())) + { + List eligibleJoinConnections = new ArrayList<>(); + for(JoinGraph.JoinConnectionList joinConnection : joinConnections) + { + if(joinTable.getName().equals(joinConnection.list().get(0).joinTable())) + { + eligibleJoinConnections.add(joinConnection); + } + } + + if(eligibleJoinConnections.isEmpty()) + { + throw (new QException("Could not infer a joinPath for table [" + table.getName() + "], exposedJoin to [" + exposedJoin.getJoinTable() + "] - no join connections exist in this instance.")); + } + else if(eligibleJoinConnections.size() > 1) + { + throw (new QException("Could not infer a joinPath for table [" + table.getName() + "], exposedJoin to [" + exposedJoin.getJoinTable() + "] - multiple possible join connections exist in this instance: ")); // todo - list the paths so user can choose one! + } + } + } + } + } + } + } + catch(Exception e) + { + throw (new RuntimeException("Error enriching instance joins", e)); + } } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/ExposedJoin.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/ExposedJoin.java new file mode 100644 index 00000000..6588cb21 --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/ExposedJoin.java @@ -0,0 +1,130 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2023. 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 . + */ + +package com.kingsrook.qqq.backend.core.model.metadata.tables; + + +import java.util.List; + + +/******************************************************************************* + ** + *******************************************************************************/ +public class ExposedJoin +{ + private String label; + private String joinTable; + private List joinPath; + + + + /******************************************************************************* + ** Getter for label + *******************************************************************************/ + public String getLabel() + { + return (this.label); + } + + + + /******************************************************************************* + ** Setter for label + *******************************************************************************/ + public void setLabel(String label) + { + this.label = label; + } + + + + /******************************************************************************* + ** Fluent setter for label + *******************************************************************************/ + public ExposedJoin withLabel(String label) + { + this.label = label; + return (this); + } + + + + /******************************************************************************* + ** Getter for joinTable + *******************************************************************************/ + public String getJoinTable() + { + return (this.joinTable); + } + + + + /******************************************************************************* + ** Setter for joinTable + *******************************************************************************/ + public void setJoinTable(String joinTable) + { + this.joinTable = joinTable; + } + + + + /******************************************************************************* + ** Fluent setter for joinTable + *******************************************************************************/ + public ExposedJoin withJoinTable(String joinTable) + { + this.joinTable = joinTable; + return (this); + } + + + + /******************************************************************************* + ** Getter for joinPath + *******************************************************************************/ + public List getJoinPath() + { + return (this.joinPath); + } + + + + /******************************************************************************* + ** Setter for joinPath + *******************************************************************************/ + public void setJoinPath(List joinPath) + { + this.joinPath = joinPath; + } + + + + /******************************************************************************* + ** Fluent setter for joinPath + *******************************************************************************/ + public ExposedJoin withJoinPath(List joinPath) + { + this.joinPath = joinPath; + return (this); + } + +} diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/QTableMetaData.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/QTableMetaData.java index 77249eef..2fa71424 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/QTableMetaData.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/QTableMetaData.java @@ -101,6 +101,8 @@ public class QTableMetaData implements QAppChildMetaData, Serializable, MetaData private Map middlewareMetaData; + private List exposedJoins; + /******************************************************************************* @@ -1296,4 +1298,51 @@ public class QTableMetaData implements QAppChildMetaData, Serializable, MetaData { qInstance.addTable(this); } + + + + /******************************************************************************* + ** Getter for exposedJoins + *******************************************************************************/ + public List getExposedJoins() + { + return (this.exposedJoins); + } + + + + /******************************************************************************* + ** Setter for exposedJoins + *******************************************************************************/ + public void setExposedJoins(List exposedJoins) + { + this.exposedJoins = exposedJoins; + } + + + + /******************************************************************************* + ** Fluent setter for exposedJoins + *******************************************************************************/ + public QTableMetaData withExposedJoins(List exposedJoins) + { + this.exposedJoins = exposedJoins; + return (this); + } + + + + /******************************************************************************* + ** Fluent setter for exposedJoins + *******************************************************************************/ + public QTableMetaData withExposedJoin(ExposedJoin exposedJoin) + { + if(this.exposedJoins == null) + { + this.exposedJoins = new ArrayList<>(); + } + this.exposedJoins.add(exposedJoin); + return (this); + } + }