Compare commits

..

14 Commits

Author SHA1 Message Date
9afbe7c3a9 Add formal concept of system-user-session, as a subclass of QSession. during construction, it is given all all-access keys, and its hasPermission method is hard-coded to return true. 2024-06-07 16:52:01 -05:00
e1fd6d51c4 Update the processes to appear in the instance twice - on both jobs & triggers tables. 2024-06-07 12:46:32 -05:00
7ff7ae3a0c Merge pull request #95 from Kingsrook/feature/CE-938-order-release-automation
Feature/ce 938 order release automation
2024-06-04 20:04:42 -05:00
d7e295881f Merged dev into feature/CE-938-order-release-automation 2024-06-04 19:55:25 -05:00
9fd55746ca Merge pull request #94 from Kingsrook/feature/rename-run-to-runOnePage
Rename 'run' to 'runOnePage'
2024-06-04 19:54:57 -05:00
121f9aa477 Merge pull request #93 from Kingsrook/feature/sprint-43-cleanup
Feature/sprint 43 cleanup
2024-06-04 19:54:46 -05:00
c8edd14833 Merge pull request #92 from Kingsrook/feature/checkstyle-indentation-enhanced-switch
Upgrade checkstyle; remove supressed indentation markers for new-styl…
2024-06-04 19:54:24 -05:00
f7b6028ba1 CE-938: updated to get filter and column setup values from widget data for saved repoprts 2024-06-04 13:45:36 -05:00
bf2836b69f CE-938 - Add test on ProcessAlertWidget 2024-06-04 11:15:16 -05:00
d3f3e25ed5 Checkstyle 2024-06-04 11:07:05 -05:00
d0839dc93c CE-938 - Fix to enrich optional steps too 2024-06-04 11:02:40 -05:00
5540f85466 CE-938 - Initial checkin 2024-06-04 10:58:36 -05:00
1a66f45425 CE-938 - MORE propagation of updated steps from inside streamed-ETL pseudo-steps to top-level process state 2024-06-04 10:58:28 -05:00
90ac1bb9c3 CE-938 - Add existingLock to UnableToObtainProcessLockException 2024-06-04 10:57:52 -05:00
20 changed files with 809 additions and 50 deletions

View File

@ -0,0 +1,86 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.dashboard.widgets;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.MetaDataProducerInterface;
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.AlertData;
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.WidgetType;
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.dashboard.QWidgetMetaData;
/*******************************************************************************
** Widget that can add an Alert to a process screen.
**
** In the process, you'll want values:
** - alertType - name of entry in AlertType enum (ERROR, WARNING, SUCCESS)
** - alertHtml - html to display inside the alert (other than its icon)
*******************************************************************************/
public class ProcessAlertWidget extends AbstractWidgetRenderer implements MetaDataProducerInterface<QWidgetMetaData>
{
public static final String NAME = "ProcessAlertWidget";
/*******************************************************************************
**
*******************************************************************************/
@Override
public RenderWidgetOutput render(RenderWidgetInput input) throws QException
{
AlertData.AlertType alertType = AlertData.AlertType.WARNING;
if(input.getQueryParams().containsKey("alertType"))
{
alertType = AlertData.AlertType.valueOf(input.getQueryParams().get("alertType"));
}
String html = "Warning";
if(input.getQueryParams().containsKey("alertHtml"))
{
html = input.getQueryParams().get("alertHtml");
}
return (new RenderWidgetOutput(new AlertData(alertType, html)));
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public QWidgetMetaData produce(QInstance qInstance) throws QException
{
return new QWidgetMetaData()
.withType(WidgetType.ALERT.getType())
.withGridColumns(12)
.withName(NAME)
.withIsCard(false)
.withShowReloadButton(false)
.withCodeReference(new QCodeReference(getClass()));
}
}

View File

@ -384,9 +384,9 @@ public class QInstanceEnricher
process.setLabel(nameToLabel(process.getName()));
}
if(process.getStepList() != null)
for(QStepMetaData step : CollectionUtils.nonNullMap(process.getAllSteps()).values())
{
process.getStepList().forEach(this::enrichStep);
enrichStep(step);
}
for(QSupplementalProcessMetaData supplementalProcessMetaData : CollectionUtils.nonNullMap(process.getSupplementalMetaData()).values())

View File

@ -0,0 +1,196 @@
/*
* 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.core.model.dashboard.widgets;
import java.util.List;
/*******************************************************************************
** Model containing datastructure expected by frontend filter and columns setup widget
**
*******************************************************************************/
public class FilterAndColumnsSetupData extends QWidgetData
{
private String tableName;
private Boolean allowVariables = false;
private Boolean hideColumns = false;
private List<String> filterDefaultFieldNames;
/*******************************************************************************
**
*******************************************************************************/
public FilterAndColumnsSetupData()
{
}
/*******************************************************************************
**
*******************************************************************************/
public FilterAndColumnsSetupData(String tableName, Boolean allowVariables, Boolean hideColumns, List<String> filterDefaultFieldNames)
{
this.tableName = tableName;
this.allowVariables = allowVariables;
this.hideColumns = hideColumns;
this.filterDefaultFieldNames = filterDefaultFieldNames;
}
/*******************************************************************************
** Getter for type
**
*******************************************************************************/
public String getType()
{
return WidgetType.FILTER_AND_COLUMNS_SETUP.getType();
}
/*******************************************************************************
** Getter for tableName
*******************************************************************************/
public String getTableName()
{
return (this.tableName);
}
/*******************************************************************************
** Setter for tableName
*******************************************************************************/
public void setTableName(String tableName)
{
this.tableName = tableName;
}
/*******************************************************************************
** Fluent setter for tableName
*******************************************************************************/
public FilterAndColumnsSetupData withTableName(String tableName)
{
this.tableName = tableName;
return (this);
}
/*******************************************************************************
** Getter for hideColumns
*******************************************************************************/
public Boolean getHideColumns()
{
return (this.hideColumns);
}
/*******************************************************************************
** Setter for hideColumns
*******************************************************************************/
public void setHideColumns(Boolean hideColumns)
{
this.hideColumns = hideColumns;
}
/*******************************************************************************
** Fluent setter for hideColumns
*******************************************************************************/
public FilterAndColumnsSetupData withHideColumns(Boolean hideColumns)
{
this.hideColumns = hideColumns;
return (this);
}
/*******************************************************************************
** Getter for filterDefaultFieldNames
*******************************************************************************/
public List<String> getFilterDefaultFieldNames()
{
return (this.filterDefaultFieldNames);
}
/*******************************************************************************
** Setter for filterDefaultFieldNames
*******************************************************************************/
public void setFilterDefaultFieldNames(List<String> filterDefaultFieldNames)
{
this.filterDefaultFieldNames = filterDefaultFieldNames;
}
/*******************************************************************************
** Fluent setter for filterDefaultFieldNames
*******************************************************************************/
public FilterAndColumnsSetupData withFilterDefaultFieldNames(List<String> filterDefaultFieldNames)
{
this.filterDefaultFieldNames = filterDefaultFieldNames;
return (this);
}
/*******************************************************************************
** Getter for allowVariables
*******************************************************************************/
public Boolean getAllowVariables()
{
return (this.allowVariables);
}
/*******************************************************************************
** Setter for allowVariables
*******************************************************************************/
public void setAllowVariables(Boolean allowVariables)
{
this.allowVariables = allowVariables;
}
/*******************************************************************************
** Fluent setter for allowVariables
*******************************************************************************/
public FilterAndColumnsSetupData withAllowVariables(Boolean allowVariables)
{
this.allowVariables = allowVariables;
return (this);
}
}

View File

@ -0,0 +1,45 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.savedreports;
import com.kingsrook.qqq.backend.core.actions.dashboard.widgets.AbstractWidgetRenderer;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.FilterAndColumnsSetupData;
/*******************************************************************************
**
*******************************************************************************/
public class SavedReportsFilterAndColumnsSetupRenderer extends AbstractWidgetRenderer
{
/*******************************************************************************
**
*******************************************************************************/
@Override
public RenderWidgetOutput render(RenderWidgetInput input) throws QException
{
return (new RenderWidgetOutput(new FilterAndColumnsSetupData(null, true, false, null)));
}
}

View File

@ -236,7 +236,7 @@ public class SavedReportsMetaDataProvider
.withLabel("Filters and Columns")
.withIsCard(true)
.withType(WidgetType.FILTER_AND_COLUMNS_SETUP.getType())
.withCodeReference(new QCodeReference(DefaultWidgetRenderer.class));
.withCodeReference(new QCodeReference(SavedReportsFilterAndColumnsSetupRenderer.class));
}

View File

@ -0,0 +1,125 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.session;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.security.QSecurityKeyType;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
/*******************************************************************************
** Special session, indicating that an action being executed is being done not
** on behalf of a (human or otherwise) user - but instead, is the application/
** system itself.
**
** Generally this means, escalated privileges - e.g., permission to all tables,
** processes etc, and all security keys (e.g., all-access keys).
*******************************************************************************/
public class QSystemUserSession extends QSession
{
private static final QLogger LOG = QLogger.getLogger(QSystemUserSession.class);
private static List<String> allAccessKeyNames = null;
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public QSystemUserSession()
{
super();
////////////////////////////////////////////////////////
// always give system user all of the all-access keys //
////////////////////////////////////////////////////////
for(String allAccessKeyName : getAllAccessKeyNames())
{
withSecurityKeyValue(allAccessKeyName, true);
}
}
/*******************************************************************************
** System User Sessions should always have permission to all the things.
*******************************************************************************/
@Override
public boolean hasPermission(String permissionName)
{
return (true);
}
/*******************************************************************************
**
*******************************************************************************/
private List<String> getAllAccessKeyNames()
{
if(allAccessKeyNames == null)
{
QInstance qInstance = QContext.getQInstance();
if(qInstance == null)
{
LOG.warn("QInstance was not set in context when creating a QSystemUserSession and trying to prime allAccessKeyNames... This SystemUserSession will NOT have any allAccessKeys.");
return (Collections.emptyList());
}
///////////////////////////////////////////////////////////////////////////////////////
// ideally only 1 thread would do this, but, it's cheap, so don't bother locking. //
// and, if multiple get in, only the last one will assign to the field, so, s/b fine //
///////////////////////////////////////////////////////////////////////////////////////
List<String> list = new ArrayList<>();
for(QSecurityKeyType securityKeyType : qInstance.getSecurityKeyTypes().values())
{
if(StringUtils.hasContent(securityKeyType.getAllAccessKeyName()))
{
list.add(securityKeyType.getAllAccessKeyName());
}
}
LOG.info("Initialized allAccessKeyNames for SystemUserSessions as: " + list);
allAccessKeyNames = list;
}
return (allAccessKeyNames);
}
/*******************************************************************************
** Meant for use in tests - to explicitly null-out the allAccessKeyNames field.
*******************************************************************************/
static void unsetAllAccessKeyNames()
{
allAccessKeyNames = null;
}
}

View File

@ -72,6 +72,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.authentication.Auth0AuthenticationMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.security.QSecurityKeyType;
import com.kingsrook.qqq.backend.core.model.session.QSession;
import com.kingsrook.qqq.backend.core.model.session.QSystemUserSession;
import com.kingsrook.qqq.backend.core.model.session.QUser;
import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleCustomizerInterface;
import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleInterface;
@ -491,6 +492,11 @@ public class Auth0AuthenticationModule implements QAuthenticationModuleInterface
return (true);
}
if(session instanceof QSystemUserSession)
{
return (true);
}
if(session == null)
{
return (false);

View File

@ -51,6 +51,7 @@ import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.authentication.TableBasedAuthenticationMetaData;
import com.kingsrook.qqq.backend.core.model.session.QSession;
import com.kingsrook.qqq.backend.core.model.session.QSystemUserSession;
import com.kingsrook.qqq.backend.core.model.session.QUser;
import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleInterface;
import com.kingsrook.qqq.backend.core.state.InMemoryStateProvider;
@ -256,6 +257,11 @@ public class TableBasedAuthenticationModule implements QAuthenticationModuleInte
return (true);
}
if(session instanceof QSystemUserSession)
{
return (true);
}
if(session == null)
{
return (false);

View File

@ -173,6 +173,14 @@ public class StreamedETLExecuteStep extends BaseStreamedETLStep implements Backe
transformStep.postRun(postRunInput, postRunOutput);
loadStep.postRun(postRunInput, postRunOutput);
//////////////////////////////////////////////////////////////////////
// propagate data from inner-step state to process-level step state //
//////////////////////////////////////////////////////////////////////
if(postRunOutput.getUpdatedFrontendStepList() != null)
{
runBackendStepOutput.setUpdatedFrontendStepList(postRunOutput.getUpdatedFrontendStepList());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// explicitly copy values back into the runStepOutput from the post-run output //
// this might not be needed, since they (presumably) share a processState object, but just in case that changes... //
@ -270,6 +278,15 @@ public class StreamedETLExecuteStep extends BaseStreamedETLStep implements Backe
transformStep.runOnePage(streamedBackendStepInput, streamedBackendStepOutput);
List<AuditInput> auditInputListFromTransform = streamedBackendStepOutput.getAuditInputList();
//////////////////////////////////////////////////////////////////////
// propagate data from inner-step state to process-level step state //
//////////////////////////////////////////////////////////////////////
if(streamedBackendStepOutput.getUpdatedFrontendStepList() != null)
{
runBackendStepOutput.getProcessState().setStepList(streamedBackendStepOutput.getProcessState().getStepList());
runBackendStepOutput.setUpdatedFrontendStepList(streamedBackendStepOutput.getUpdatedFrontendStepList());
}
////////////////////////////////////////////////
// pass the records through the load function //
////////////////////////////////////////////////
@ -279,6 +296,15 @@ public class StreamedETLExecuteStep extends BaseStreamedETLStep implements Backe
loadStep.runOnePage(streamedBackendStepInput, streamedBackendStepOutput);
List<AuditInput> auditInputListFromLoad = streamedBackendStepOutput.getAuditInputList();
//////////////////////////////////////////////////////////////////////
// propagate data from inner-step state to process-level step state //
//////////////////////////////////////////////////////////////////////
if(streamedBackendStepOutput.getUpdatedFrontendStepList() != null)
{
runBackendStepOutput.getProcessState().setStepList(streamedBackendStepOutput.getProcessState().getStepList());
runBackendStepOutput.setUpdatedFrontendStepList(streamedBackendStepOutput.getUpdatedFrontendStepList());
}
///////////////////////////////////////////////////////
// copy a small number of records to the output list //
///////////////////////////////////////////////////////

View File

@ -145,7 +145,9 @@ public class StreamedETLPreviewStep extends BaseStreamedETLStep implements Backe
BackendStepPostRunInput postRunInput = new BackendStepPostRunInput(runBackendStepInput);
transformStep.postRun(postRunInput, postRunOutput);
// todo figure out what kind of test we can get on this
//////////////////////////////////////////////////////////////////////
// propagate data from inner-step state to process-level step state //
//////////////////////////////////////////////////////////////////////
if(postRunOutput.getUpdatedFrontendStepList() != null)
{
runBackendStepOutput.setUpdatedFrontendStepList(postRunOutput.getUpdatedFrontendStepList());
@ -214,6 +216,15 @@ public class StreamedETLPreviewStep extends BaseStreamedETLStep implements Backe
/////////////////////////////////////////////////////
transformStep.runOnePage(streamedBackendStepInput, streamedBackendStepOutput);
//////////////////////////////////////////////////////////////////////
// propagate data from inner-step state to process-level step state //
//////////////////////////////////////////////////////////////////////
if(streamedBackendStepOutput.getUpdatedFrontendStepList() != null)
{
runBackendStepOutput.getProcessState().setStepList(streamedBackendStepOutput.getProcessState().getStepList());
runBackendStepOutput.setUpdatedFrontendStepList(streamedBackendStepOutput.getUpdatedFrontendStepList());
}
////////////////////////////////////////////////////
// add the transformed records to the output list //
////////////////////////////////////////////////////

View File

@ -142,6 +142,9 @@ public class StreamedETLValidateStep extends BaseStreamedETLStep implements Back
BackendStepPostRunInput postRunInput = new BackendStepPostRunInput(runBackendStepInput);
transformStep.postRun(postRunInput, postRunOutput);
//////////////////////////////////////////////////////////////////////
// propagate data from inner-step state to process-level step state //
//////////////////////////////////////////////////////////////////////
if(postRunOutput.getUpdatedFrontendStepList() != null)
{
runBackendStepOutput.setUpdatedFrontendStepList(postRunOutput.getUpdatedFrontendStepList());
@ -177,6 +180,15 @@ public class StreamedETLValidateStep extends BaseStreamedETLStep implements Back
/////////////////////////////////////////////////////
transformStep.runOnePage(streamedBackendStepInput, streamedBackendStepOutput);
//////////////////////////////////////////////////////////////////////
// propagate data from inner-step state to process-level step state //
//////////////////////////////////////////////////////////////////////
if(streamedBackendStepOutput.getUpdatedFrontendStepList() != null)
{
runBackendStepOutput.getProcessState().setStepList(streamedBackendStepOutput.getProcessState().getStepList());
runBackendStepOutput.setUpdatedFrontendStepList(streamedBackendStepOutput.getUpdatedFrontendStepList());
}
///////////////////////////////////////////////////////
// copy a small number of records to the output list //
///////////////////////////////////////////////////////

View File

@ -103,12 +103,13 @@ public class ProcessLockUtils
// if inserting failed... see if we can get existing lock //
////////////////////////////////////////////////////////////
StringBuilder existingLockDetails = new StringBuilder();
ProcessLock existingLock = null;
if(CollectionUtils.nullSafeHasContents(insertOutputRecord.getErrors()))
{
QRecord existingLockRecord = new GetAction().executeForRecord(new GetInput(ProcessLock.TABLE_NAME).withUniqueKey(Map.of("key", key, "processLockTypeId", lockType.getId())));
if(existingLockRecord != null)
{
ProcessLock existingLock = new ProcessLock(existingLockRecord);
existingLock = new ProcessLock(existingLockRecord);
if(StringUtils.hasContent(existingLock.getUserId()))
{
existingLockDetails.append("Held by: ").append(existingLock.getUserId());
@ -153,7 +154,8 @@ public class ProcessLockUtils
/////////////////////////////////////////////////////////////////////////////////
LOG.info("Errors in process lock record after attempted insert", logPair("errors", insertOutputRecord.getErrors()),
logPair("key", key), logPair("type", typeName), logPair("details", details));
throw (new UnableToObtainProcessLockException("A Process Lock already exists for key [" + key + "] of type [" + typeName + "], " + existingLockDetails));
throw (new UnableToObtainProcessLockException("A Process Lock already exists for key [" + key + "] of type [" + typeName + "], " + existingLockDetails)
.withExistingLock(existingLock));
}
LOG.info("Created process lock", logPair("id", processLock.getId()),
@ -202,12 +204,15 @@ public class ProcessLockUtils
}
}
////////////////////////////////////////////////////////////////////////////////////////
// var can never be null with current code-path, but prefer defensiveness regardless. //
////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
// this variable can never be null with current code-path, but prefer to be defensive regardless //
///////////////////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("ConstantValue")
String suffix = lastCaughtUnableToObtainProcessLockException == null ? "" : ": " + lastCaughtUnableToObtainProcessLockException.getMessage();
throw (new UnableToObtainProcessLockException("Unable to obtain process lock for key [" + key + "] in type [" + type + "] after [" + maxWait + "]" + suffix));
//noinspection ConstantValue
throw (new UnableToObtainProcessLockException("Unable to obtain process lock for key [" + key + "] in type [" + type + "] after [" + maxWait + "]" + suffix)
.withExistingLock(lastCaughtUnableToObtainProcessLockException == null ? null : lastCaughtUnableToObtainProcessLockException.getExistingLock()));
}

View File

@ -30,6 +30,9 @@ import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
*******************************************************************************/
public class UnableToObtainProcessLockException extends QUserFacingException
{
private ProcessLock existingLock;
/*******************************************************************************
**
@ -49,4 +52,35 @@ public class UnableToObtainProcessLockException extends QUserFacingException
super(message, cause);
}
/*******************************************************************************
** Getter for existingLock
*******************************************************************************/
public ProcessLock getExistingLock()
{
return (this.existingLock);
}
/*******************************************************************************
** Setter for existingLock
*******************************************************************************/
public void setExistingLock(ProcessLock existingLock)
{
this.existingLock = existingLock;
}
/*******************************************************************************
** Fluent setter for existingLock
*******************************************************************************/
public UnableToObtainProcessLockException withExistingLock(ProcessLock existingLock)
{
this.existingLock = existingLock;
return (this);
}
}

View File

@ -23,15 +23,18 @@ package com.kingsrook.qqq.backend.core.scheduler.quartz.processes;
import java.util.List;
import java.util.function.BiFunction;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.MetaDataProducerInterface;
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.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerMultiOutput;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon;
import com.kingsrook.qqq.backend.core.model.metadata.permissions.QPermissionRules;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.AbstractLoadStep;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.ExtractViaQueryStep;
@ -43,33 +46,39 @@ import com.kingsrook.qqq.backend.core.scheduler.quartz.QuartzScheduler;
/*******************************************************************************
**
*******************************************************************************/
public class PauseQuartzJobsProcess extends AbstractLoadStep implements MetaDataProducerInterface<QProcessMetaData>
public class PauseQuartzJobsProcess extends AbstractLoadStep implements MetaDataProducerInterface<MetaDataProducerMultiOutput>
{
/*******************************************************************************
**
*******************************************************************************/
@Override
public QProcessMetaData produce(QInstance qInstance) throws QException
public MetaDataProducerMultiOutput produce(QInstance qInstance) throws QException
{
String tableName = "quartzJobDetails";
BiFunction<String, String, QProcessMetaData> processMaker = (String tableName, String label) ->
StreamedETLWithFrontendProcess.processMetaDataBuilder()
.withName(getClass().getSimpleName())
.withLabel(label)
.withPreviewMessage("This is a preview of the jobs that will be paused.")
.withTableName(tableName)
.withSourceTable(tableName)
.withDestinationTable(tableName)
.withExtractStepClass(ExtractViaQueryStep.class)
.withTransformStepClass(NoopTransformStep.class)
.withLoadStepClass(getClass())
.withIcon(new QIcon("pause_circle_outline"))
.withReviewStepRecordFields(List.of(
new QFieldMetaData("id", QFieldType.LONG),
new QFieldMetaData("jobName", QFieldType.STRING),
new QFieldMetaData("jobGroup", QFieldType.STRING),
new QFieldMetaData("description", QFieldType.STRING)))
.getProcessMetaData()
.withPermissionRules(new QPermissionRules().withPermissionBaseName(getClass().getSimpleName()));
return StreamedETLWithFrontendProcess.processMetaDataBuilder()
.withName(getClass().getSimpleName())
.withLabel("Pause Quartz Jobs")
.withPreviewMessage("This is a preview of the jobs that will be paused.")
.withTableName(tableName)
.withSourceTable(tableName)
.withDestinationTable(tableName)
.withExtractStepClass(ExtractViaQueryStep.class)
.withTransformStepClass(NoopTransformStep.class)
.withLoadStepClass(getClass())
.withIcon(new QIcon("pause_circle_outline"))
.withReviewStepRecordFields(List.of(
new QFieldMetaData("id", QFieldType.LONG),
new QFieldMetaData("jobName", QFieldType.STRING),
new QFieldMetaData("jobGroup", QFieldType.STRING)))
.getProcessMetaData();
MetaDataProducerMultiOutput output = new MetaDataProducerMultiOutput();
output.add(processMaker.apply("quartzJobDetails", "Pause Quartz Jobs"));
output.add(processMaker.apply("quartzTriggers", "Pause Quartz Triggers").withName(getClass().getSimpleName() + "ForTriggers"));
return (output);
}

View File

@ -23,15 +23,18 @@ package com.kingsrook.qqq.backend.core.scheduler.quartz.processes;
import java.util.List;
import java.util.function.BiFunction;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.MetaDataProducerInterface;
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.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerMultiOutput;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon;
import com.kingsrook.qqq.backend.core.model.metadata.permissions.QPermissionRules;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.AbstractLoadStep;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.ExtractViaQueryStep;
@ -43,33 +46,39 @@ import com.kingsrook.qqq.backend.core.scheduler.quartz.QuartzScheduler;
/*******************************************************************************
**
*******************************************************************************/
public class ResumeQuartzJobsProcess extends AbstractLoadStep implements MetaDataProducerInterface<QProcessMetaData>
public class ResumeQuartzJobsProcess extends AbstractLoadStep implements MetaDataProducerInterface<MetaDataProducerMultiOutput>
{
/*******************************************************************************
**
*******************************************************************************/
@Override
public QProcessMetaData produce(QInstance qInstance) throws QException
public MetaDataProducerMultiOutput produce(QInstance qInstance) throws QException
{
String tableName = "quartzJobDetails";
BiFunction<String, String, QProcessMetaData> processMaker = (String tableName, String label) ->
StreamedETLWithFrontendProcess.processMetaDataBuilder()
.withName(getClass().getSimpleName())
.withLabel(label)
.withPreviewMessage("This is a preview of the jobs that will be resumed.")
.withTableName(tableName)
.withSourceTable(tableName)
.withDestinationTable(tableName)
.withExtractStepClass(ExtractViaQueryStep.class)
.withTransformStepClass(NoopTransformStep.class)
.withLoadStepClass(getClass())
.withIcon(new QIcon("play_circle_outline"))
.withReviewStepRecordFields(List.of(
new QFieldMetaData("id", QFieldType.LONG),
new QFieldMetaData("jobName", QFieldType.STRING),
new QFieldMetaData("jobGroup", QFieldType.STRING),
new QFieldMetaData("description", QFieldType.STRING)))
.getProcessMetaData()
.withPermissionRules(new QPermissionRules().withPermissionBaseName(getClass().getSimpleName()));
return StreamedETLWithFrontendProcess.processMetaDataBuilder()
.withName(getClass().getSimpleName())
.withLabel("Resume Quartz Jobs")
.withPreviewMessage("This is a preview of the jobs that will be resumed.")
.withTableName(tableName)
.withSourceTable(tableName)
.withDestinationTable(tableName)
.withExtractStepClass(ExtractViaQueryStep.class)
.withTransformStepClass(NoopTransformStep.class)
.withLoadStepClass(getClass())
.withIcon(new QIcon("play_circle_outline"))
.withReviewStepRecordFields(List.of(
new QFieldMetaData("id", QFieldType.LONG),
new QFieldMetaData("jobName", QFieldType.STRING),
new QFieldMetaData("jobGroup", QFieldType.STRING)))
.getProcessMetaData();
MetaDataProducerMultiOutput output = new MetaDataProducerMultiOutput();
output.add(processMaker.apply("quartzJobDetails", "Resume Quartz Jobs"));
output.add(processMaker.apply("quartzTriggers", "Resume Quartz Triggers").withName(getClass().getSimpleName() + "ForTriggers"));
return (output);
}

View File

@ -0,0 +1,72 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.dashboard.widgets;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.actions.dashboard.RenderWidgetAction;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.AlertData;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerHelper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*******************************************************************************
** Unit test for ProcessAlertWidget
*******************************************************************************/
class ProcessAlertWidgetTest extends BaseTest
{
/*******************************************************************************
**
*******************************************************************************/
@Test
void test() throws QException
{
MetaDataProducerHelper.processAllMetaDataProducersInPackage(QContext.getQInstance(), ProcessAlertWidget.class.getPackageName());
RenderWidgetInput input = new RenderWidgetInput();
input.setWidgetMetaData(QContext.getQInstance().getWidget(ProcessAlertWidget.NAME));
///////////////////////////////////////////////////////////////////////////////////////////
// make sure we run w/o exceptions (and w/ default outputs) if there are no query params //
///////////////////////////////////////////////////////////////////////////////////////////
RenderWidgetOutput output = new RenderWidgetAction().execute(input);
assertEquals(AlertData.AlertType.WARNING, ((AlertData) output.getWidgetData()).getAlertType());
assertEquals("Warning", ((AlertData) output.getWidgetData()).getHtml());
//////////////////////////////////////////////////////
// make sure we input params come through to output //
//////////////////////////////////////////////////////
input.addQueryParam("alertType", "ERROR");
input.addQueryParam("alertHtml", "Do not touch Willy");
output = new RenderWidgetAction().execute(input);
assertEquals(AlertData.AlertType.ERROR, ((AlertData) output.getWidgetData()).getAlertType());
assertEquals("Do not touch Willy", ((AlertData) output.getWidgetData()).getHtml());
}
}

View File

@ -28,6 +28,7 @@ import java.util.List;
import java.util.Optional;
import com.kingsrook.qqq.backend.core.BaseTest;
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.AdornmentType;
import com.kingsrook.qqq.backend.core.model.metadata.fields.DynamicDefaultValueBehavior;
import com.kingsrook.qqq.backend.core.model.metadata.fields.FieldAdornment;
@ -38,6 +39,8 @@ 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.QBackendStepMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QFrontendStepMetaData;
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;
@ -232,6 +235,7 @@ class QInstanceEnricherTest extends BaseTest
}
/*******************************************************************************
**
*******************************************************************************/
@ -546,4 +550,26 @@ class QInstanceEnricherTest extends BaseTest
assertEquals(DynamicDefaultValueBehavior.MODIFY_DATE, table.getField("modifyDate").getBehaviorOnlyIfSet(DynamicDefaultValueBehavior.class));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testOptionalProcessSteps()
{
QInstance qInstance = TestUtils.defineInstance();
QProcessMetaData process = new QProcessMetaData();
process.setName("test");
process.withStepList(List.of(new QBackendStepMetaData().withName("execute").withCode(new QCodeReference(TestUtils.IncreaseBirthdateStep.class))));
process.addOptionalStep(new QFrontendStepMetaData()
.withName("screen")
.withViewField(new QFieldMetaData("myField", QFieldType.STRING)));
qInstance.addProcess(process);
new QInstanceEnricher(qInstance).enrich();
assertEquals("My Field", qInstance.getProcess("test").getFrontendStep("screen").getViewFields().get(0).getLabel());
}
}

View File

@ -0,0 +1,88 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.session;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.modules.authentication.implementations.Auth0AuthenticationModule;
import com.kingsrook.qqq.backend.core.modules.authentication.implementations.FullyAnonymousAuthenticationModule;
import com.kingsrook.qqq.backend.core.modules.authentication.implementations.MockAuthenticationModule;
import com.kingsrook.qqq.backend.core.modules.authentication.implementations.TableBasedAuthenticationModule;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/*******************************************************************************
** Unit test for QSystemUserSession
*******************************************************************************/
class QSystemUserSessionTest extends BaseTest
{
/*******************************************************************************
**
*******************************************************************************/
@Test
void test()
{
QSystemUserSession systemUserSession = new QSystemUserSession();
assertEquals(List.of(true), systemUserSession.getSecurityKeyValues(TestUtils.SECURITY_KEY_TYPE_STORE_ALL_ACCESS));
assertTrue(new Auth0AuthenticationModule().isSessionValid(QContext.getQInstance(), systemUserSession));
assertTrue(new TableBasedAuthenticationModule().isSessionValid(QContext.getQInstance(), systemUserSession));
assertTrue(new MockAuthenticationModule().isSessionValid(QContext.getQInstance(), systemUserSession));
assertTrue(new FullyAnonymousAuthenticationModule().isSessionValid(QContext.getQInstance(), systemUserSession));
assertTrue(systemUserSession.hasPermission(null));
assertTrue(systemUserSession.hasPermission(""));
assertTrue(systemUserSession.hasPermission("anything"));
assertTrue(systemUserSession.hasPermission(UUID.randomUUID().toString()));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testWeDoNotBlowUpIfInstanceIsntInContextWhenPrimingAllAccessKeyNames()
{
QInstance qInstance = QContext.getQInstance();
QSystemUserSession.unsetAllAccessKeyNames();
QContext.clear();
QSystemUserSession systemUserSession = new QSystemUserSession();
assertEquals(Collections.emptyList(), systemUserSession.getSecurityKeyValues(TestUtils.SECURITY_KEY_TYPE_STORE_ALL_ACCESS));
QContext.setQInstance(qInstance);
systemUserSession = new QSystemUserSession();
assertEquals(List.of(true), systemUserSession.getSecurityKeyValues(TestUtils.SECURITY_KEY_TYPE_STORE_ALL_ACCESS));
}
}

View File

@ -109,7 +109,8 @@ class ProcessLockUtilsTest extends BaseTest
.isInstanceOf(UnableToObtainProcessLockException.class)
.hasMessageContaining("Held by: " + QContext.getQSession().getUser().getIdReference())
.hasMessageContaining("with details: me")
.hasMessageNotContaining("expiring at: 20");
.hasMessageNotContaining("expiring at: 20")
.matches(e -> ((UnableToObtainProcessLockException) e).getExistingLock() != null);
/////////////////////////////////////////////////////////
// make sure we can create another for a different key //
@ -179,7 +180,8 @@ class ProcessLockUtilsTest extends BaseTest
.isInstanceOf(UnableToObtainProcessLockException.class)
.hasMessageContaining("Held by: " + QContext.getQSession().getUser().getIdReference())
.hasMessageContaining("with details: me")
.hasMessageContaining("expiring at: 20");
.hasMessageContaining("expiring at: 20")
.matches(e -> ((UnableToObtainProcessLockException) e).getExistingLock() != null);
}

View File

@ -9,3 +9,4 @@ qqq-middleware-picocli
qqq-middleware-slack
qqq-middleware-api
qqq-frontend-material-dashboard
qqq-bom-pom