mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Checkpoint
This commit is contained in:
@ -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<JoinGraph.JoinConnectionList> 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<JoinGraph.JoinConnectionList> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.model.metadata.tables;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class ExposedJoin
|
||||
{
|
||||
private String label;
|
||||
private String joinTable;
|
||||
private List<String> 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<String> getJoinPath()
|
||||
{
|
||||
return (this.joinPath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for joinPath
|
||||
*******************************************************************************/
|
||||
public void setJoinPath(List<String> joinPath)
|
||||
{
|
||||
this.joinPath = joinPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for joinPath
|
||||
*******************************************************************************/
|
||||
public ExposedJoin withJoinPath(List<String> joinPath)
|
||||
{
|
||||
this.joinPath = joinPath;
|
||||
return (this);
|
||||
}
|
||||
|
||||
}
|
@ -101,6 +101,8 @@ public class QTableMetaData implements QAppChildMetaData, Serializable, MetaData
|
||||
|
||||
private Map<String, QMiddlewareTableMetaData> middlewareMetaData;
|
||||
|
||||
private List<ExposedJoin> exposedJoins;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -1296,4 +1298,51 @@ public class QTableMetaData implements QAppChildMetaData, Serializable, MetaData
|
||||
{
|
||||
qInstance.addTable(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for exposedJoins
|
||||
*******************************************************************************/
|
||||
public List<ExposedJoin> getExposedJoins()
|
||||
{
|
||||
return (this.exposedJoins);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for exposedJoins
|
||||
*******************************************************************************/
|
||||
public void setExposedJoins(List<ExposedJoin> exposedJoins)
|
||||
{
|
||||
this.exposedJoins = exposedJoins;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for exposedJoins
|
||||
*******************************************************************************/
|
||||
public QTableMetaData withExposedJoins(List<ExposedJoin> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user