mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-17 21:00:45 +00:00
Add java backend for field-level form adjusters
This commit is contained in:
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. 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.frontend.materialdashboard.actions.formadjuster;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class FormAdjusterInput
|
||||
{
|
||||
private String event;
|
||||
private String fieldName;
|
||||
|
||||
private Serializable newValue;
|
||||
private Map<String, Serializable> allValues;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for event
|
||||
*******************************************************************************/
|
||||
public String getEvent()
|
||||
{
|
||||
return (this.event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for event
|
||||
*******************************************************************************/
|
||||
public void setEvent(String event)
|
||||
{
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for event
|
||||
*******************************************************************************/
|
||||
public FormAdjusterInput withEvent(String event)
|
||||
{
|
||||
this.event = event;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for fieldName
|
||||
*******************************************************************************/
|
||||
public String getFieldName()
|
||||
{
|
||||
return (this.fieldName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for fieldName
|
||||
*******************************************************************************/
|
||||
public void setFieldName(String fieldName)
|
||||
{
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for fieldName
|
||||
*******************************************************************************/
|
||||
public FormAdjusterInput withFieldName(String fieldName)
|
||||
{
|
||||
this.fieldName = fieldName;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for newValue
|
||||
*******************************************************************************/
|
||||
public Serializable getNewValue()
|
||||
{
|
||||
return (this.newValue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for newValue
|
||||
*******************************************************************************/
|
||||
public void setNewValue(Serializable newValue)
|
||||
{
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for newValue
|
||||
*******************************************************************************/
|
||||
public FormAdjusterInput withNewValue(Serializable newValue)
|
||||
{
|
||||
this.newValue = newValue;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for allValues
|
||||
*******************************************************************************/
|
||||
public Map<String, Serializable> getAllValues()
|
||||
{
|
||||
return (this.allValues);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for allValues
|
||||
*******************************************************************************/
|
||||
public void setAllValues(Map<String, Serializable> allValues)
|
||||
{
|
||||
this.allValues = allValues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for allValues
|
||||
*******************************************************************************/
|
||||
public FormAdjusterInput withAllValues(Map<String, Serializable> allValues)
|
||||
{
|
||||
this.allValues = allValues;
|
||||
return (this);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. 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.frontend.materialdashboard.actions.formadjuster;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** interface to be implemented by application-specific form-adjusters
|
||||
*******************************************************************************/
|
||||
public interface FormAdjusterInterface
|
||||
{
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
***************************************************************************/
|
||||
FormAdjusterOutput execute(FormAdjusterInput input) throws QException;
|
||||
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. 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.frontend.materialdashboard.actions.formadjuster;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.frontend.QFrontendFieldMetaData;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class FormAdjusterOutput
|
||||
{
|
||||
private Map<String, QFrontendFieldMetaData> updatedFieldMetaData = null;
|
||||
private Map<String, Serializable> updatedFieldValues = null;
|
||||
private Map<String, String> updatedFieldDisplayValues = null;
|
||||
private Set<String> fieldsToClear = null;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for updatedFieldValues
|
||||
*******************************************************************************/
|
||||
public Map<String, Serializable> getUpdatedFieldValues()
|
||||
{
|
||||
return (this.updatedFieldValues);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for updatedFieldValues
|
||||
*******************************************************************************/
|
||||
public void setUpdatedFieldValues(Map<String, Serializable> updatedFieldValues)
|
||||
{
|
||||
this.updatedFieldValues = updatedFieldValues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for updatedFieldValues
|
||||
*******************************************************************************/
|
||||
public FormAdjusterOutput withUpdatedFieldValues(Map<String, Serializable> updatedFieldValues)
|
||||
{
|
||||
this.updatedFieldValues = updatedFieldValues;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for fieldsToClear
|
||||
*******************************************************************************/
|
||||
public Set<String> getFieldsToClear()
|
||||
{
|
||||
return (this.fieldsToClear);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for fieldsToClear
|
||||
*******************************************************************************/
|
||||
public void setFieldsToClear(Set<String> fieldsToClear)
|
||||
{
|
||||
this.fieldsToClear = fieldsToClear;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for fieldsToClear
|
||||
*******************************************************************************/
|
||||
public FormAdjusterOutput withFieldsToClear(Set<String> fieldsToClear)
|
||||
{
|
||||
this.fieldsToClear = fieldsToClear;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for updatedFieldMetaData
|
||||
*******************************************************************************/
|
||||
public Map<String, QFrontendFieldMetaData> getUpdatedFieldMetaData()
|
||||
{
|
||||
return (this.updatedFieldMetaData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for updatedFieldMetaData
|
||||
*******************************************************************************/
|
||||
public void setUpdatedFieldMetaData(Map<String, QFrontendFieldMetaData> updatedFieldMetaData)
|
||||
{
|
||||
this.updatedFieldMetaData = updatedFieldMetaData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for updatedFieldMetaData
|
||||
*******************************************************************************/
|
||||
public FormAdjusterOutput withUpdatedFieldMetaData(Map<String, QFrontendFieldMetaData> updatedFieldMetaData)
|
||||
{
|
||||
this.updatedFieldMetaData = updatedFieldMetaData;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for updatedFieldDisplayValues
|
||||
*******************************************************************************/
|
||||
public Map<String, String> getUpdatedFieldDisplayValues()
|
||||
{
|
||||
return (this.updatedFieldDisplayValues);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for updatedFieldDisplayValues
|
||||
*******************************************************************************/
|
||||
public void setUpdatedFieldDisplayValues(Map<String, String> updatedFieldDisplayValues)
|
||||
{
|
||||
this.updatedFieldDisplayValues = updatedFieldDisplayValues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for updatedFieldDisplayValues
|
||||
*******************************************************************************/
|
||||
public FormAdjusterOutput withUpdatedFieldDisplayValues(Map<String, String> updatedFieldDisplayValues)
|
||||
{
|
||||
this.updatedFieldDisplayValues = updatedFieldDisplayValues;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. 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.frontend.materialdashboard.actions.formadjuster;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.actions.customizers.QCodeLoader;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
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.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.javalin.QJavalinMetaData;
|
||||
import com.kingsrook.qqq.frontend.materialdashboard.model.metadata.MaterialDashboardFieldMetaData;
|
||||
import com.kingsrook.qqq.middleware.javalin.metadata.JavalinRouteProviderMetaData;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Class that stores code-references for the application's defined fromAdjusters
|
||||
** This class also, when registering its first formAdjuster, adds the route to
|
||||
** the javalin instance to service form-adjuster calls from the frontend.
|
||||
*******************************************************************************/
|
||||
public class FormAdjusterRegistry
|
||||
{
|
||||
private static final QLogger LOG = QLogger.getLogger(FormAdjusterRegistry.class);
|
||||
|
||||
private static boolean didRegisterRouteProvider = false;
|
||||
private static QInstance lastRegisteredQInstance = null;
|
||||
|
||||
private static Map<String, QCodeReference> onChangeAdjusters = new HashMap<>();
|
||||
private static Map<String, QCodeReference> onLoadAdjusters = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
public static void registerFormAdjusters(QInstance qInstance, MaterialDashboardFieldMetaData materialDashboardFieldMetaData) throws QException
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// support hot-swaps, by checking if the input qInstance is different from one we previously registered for //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
if(didRegisterRouteProvider && lastRegisteredQInstance != qInstance)
|
||||
{
|
||||
didRegisterRouteProvider = false;
|
||||
onChangeAdjusters.clear();
|
||||
onLoadAdjusters.clear();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// if we need to register the javalin router, do so (only once per qInstance) //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
if(!didRegisterRouteProvider)
|
||||
{
|
||||
QJavalinMetaData javalinMetaData = QJavalinMetaData.ofOrWithNew(qInstance);
|
||||
javalinMetaData.withRouteProvider(new JavalinRouteProviderMetaData()
|
||||
.withHostedPath("/material-dashboard-backend/form-adjuster/{identifier}/{event}")
|
||||
.withMethods(List.of("POST"))
|
||||
.withProcessName(RunFormAdjusterProcess.NAME)
|
||||
);
|
||||
|
||||
qInstance.add(new RunFormAdjusterProcess().produce(qInstance));
|
||||
|
||||
didRegisterRouteProvider = true;
|
||||
lastRegisteredQInstance = qInstance;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// add the code-references to the map of registered adjusters //
|
||||
////////////////////////////////////////////////////////////////
|
||||
String identifier = materialDashboardFieldMetaData.getFormAdjusterIdentifier();
|
||||
|
||||
QCodeReference onChangeCode = materialDashboardFieldMetaData.getOnChangeFormAdjuster();
|
||||
if(onChangeCode != null)
|
||||
{
|
||||
if(onChangeAdjusters.containsKey(identifier))
|
||||
{
|
||||
LOG.warn("Attempt to register more than one onChangeFormAdjuster with identifier: " + identifier);
|
||||
}
|
||||
onChangeAdjusters.put(identifier, onChangeCode);
|
||||
}
|
||||
|
||||
QCodeReference onLoadCode = materialDashboardFieldMetaData.getOnLoadFormAdjuster();
|
||||
if(onLoadCode != null)
|
||||
{
|
||||
if(onLoadAdjusters.containsKey(identifier))
|
||||
{
|
||||
LOG.warn("Attempt to register more than one onLoadFormAdjuster with identifier: " + identifier);
|
||||
}
|
||||
onLoadAdjusters.put(identifier, onLoadCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
static FormAdjusterInterface getOnChangeAdjuster(String identifier)
|
||||
{
|
||||
QCodeReference codeReference = onChangeAdjusters.get(identifier);
|
||||
if(codeReference != null)
|
||||
{
|
||||
return QCodeLoader.getAdHoc(FormAdjusterInterface.class, codeReference);
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
static FormAdjusterInterface getOnLoadAdjuster(String identifier)
|
||||
{
|
||||
QCodeReference codeReference = onLoadAdjusters.get(identifier);
|
||||
if(codeReference != null)
|
||||
{
|
||||
return QCodeLoader.getAdHoc(FormAdjusterInterface.class, codeReference);
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. 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.frontend.materialdashboard.actions.formadjuster;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.kingsrook.qqq.backend.core.actions.processes.BackendStep;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
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.metadata.MetaDataProducerInterface;
|
||||
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.processes.QBackendStepMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qqq.middleware.javalin.routeproviders.ProcessBasedRouterPayload;
|
||||
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** process that looks up a form adjuster from the registry, and then runs it
|
||||
*******************************************************************************/
|
||||
public class RunFormAdjusterProcess implements BackendStep, MetaDataProducerInterface<QProcessMetaData>
|
||||
{
|
||||
public static final String NAME = "MaterialDashboardRunFormAdjusterProcess";
|
||||
|
||||
private static final QLogger LOG = QLogger.getLogger(RunFormAdjusterProcess.class);
|
||||
|
||||
public static final String EVENT_ON_LOAD = "onLoad";
|
||||
public static final String EVENT_ON_CHANGE = "onChange";
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public QProcessMetaData produce(QInstance qInstance) throws QException
|
||||
{
|
||||
return new QProcessMetaData()
|
||||
.withName(NAME)
|
||||
.withStep(new QBackendStepMetaData()
|
||||
.withName("execute")
|
||||
.withCode(new QCodeReference(getClass())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
|
||||
{
|
||||
ProcessBasedRouterPayload payload = runBackendStepInput.getProcessPayload(ProcessBasedRouterPayload.class);
|
||||
|
||||
String identifier = payload.getPathParams().get("identifier");
|
||||
String event = payload.getPathParams().get("event");
|
||||
|
||||
try
|
||||
{
|
||||
FormAdjusterInterface formAdjuster = switch(event)
|
||||
{
|
||||
case EVENT_ON_CHANGE -> FormAdjusterRegistry.getOnChangeAdjuster(identifier);
|
||||
case EVENT_ON_LOAD -> FormAdjusterRegistry.getOnLoadAdjuster(identifier);
|
||||
default -> throw new QException("Unknown event type: " + event);
|
||||
};
|
||||
|
||||
if(formAdjuster == null)
|
||||
{
|
||||
throw new QException("No form adjuster found for identifier: " + identifier + " and event: " + event);
|
||||
}
|
||||
|
||||
FormAdjusterInput input = new FormAdjusterInput();
|
||||
input.setEvent(event);
|
||||
input.setFieldName(payload.getFormParam("fieldName"));
|
||||
input.setNewValue(payload.getFormParam("newValue"));
|
||||
|
||||
String allValuesJson = payload.getFormParam("allValues");
|
||||
Map<String, Serializable> allValues = StringUtils.hasContent(allValuesJson) ? JsonUtils.toObject(allValuesJson, new TypeReference<>() {}) : Collections.emptyMap();
|
||||
input.setAllValues(allValues);
|
||||
|
||||
FormAdjusterOutput output = formAdjuster.execute(input);
|
||||
|
||||
payload.setResponseString(JsonUtils.toJson(output));
|
||||
runBackendStepOutput.setProcessPayload(payload);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.warn("Error running form adjuster process", e, logPair("identifier", identifier), logPair("event", event));
|
||||
throw new QException("Error running form adjuster process: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. 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.frontend.materialdashboard.model.metadata;
|
||||
|
||||
|
||||
import java.util.Set;
|
||||
import com.kingsrook.qqq.backend.core.instances.QInstanceValidator;
|
||||
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.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QSupplementalFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qqq.frontend.materialdashboard.actions.formadjuster.FormAdjusterInterface;
|
||||
import com.kingsrook.qqq.frontend.materialdashboard.actions.formadjuster.FormAdjusterRegistry;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class MaterialDashboardFieldMetaData extends QSupplementalFieldMetaData
|
||||
{
|
||||
public static final String TYPE = "materialDashboard";
|
||||
|
||||
private static final QLogger LOG = QLogger.getLogger(MaterialDashboardFieldMetaData.class);
|
||||
|
||||
private String formAdjusterIdentifier = null;
|
||||
private QCodeReference onChangeFormAdjuster = null;
|
||||
private QCodeReference onLoadFormAdjuster = null;
|
||||
private Set<String> fieldsToDisableWhileRunningAdjusters = null;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public boolean includeInFrontendMetaData()
|
||||
{
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for onChangeFormAdjuster
|
||||
*******************************************************************************/
|
||||
public QCodeReference getOnChangeFormAdjuster()
|
||||
{
|
||||
return (this.onChangeFormAdjuster);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for onChangeFormAdjuster
|
||||
*******************************************************************************/
|
||||
public void setOnChangeFormAdjuster(QCodeReference onChangeFormAdjuster)
|
||||
{
|
||||
this.onChangeFormAdjuster = onChangeFormAdjuster;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for onChangeFormAdjuster
|
||||
*******************************************************************************/
|
||||
public MaterialDashboardFieldMetaData withOnChangeFormAdjuster(QCodeReference onChangeFormAdjuster)
|
||||
{
|
||||
this.onChangeFormAdjuster = onChangeFormAdjuster;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for onLoadFormAdjuster
|
||||
*******************************************************************************/
|
||||
public QCodeReference getOnLoadFormAdjuster()
|
||||
{
|
||||
return (this.onLoadFormAdjuster);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for onLoadFormAdjuster
|
||||
*******************************************************************************/
|
||||
public void setOnLoadFormAdjuster(QCodeReference onLoadFormAdjuster)
|
||||
{
|
||||
this.onLoadFormAdjuster = onLoadFormAdjuster;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for onLoadFormAdjuster
|
||||
*******************************************************************************/
|
||||
public MaterialDashboardFieldMetaData withOnLoadFormAdjuster(QCodeReference onLoadFormAdjuster)
|
||||
{
|
||||
this.onLoadFormAdjuster = onLoadFormAdjuster;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public void enrich(QInstance qInstance, QFieldMetaData fieldMetaData)
|
||||
{
|
||||
try
|
||||
{
|
||||
FormAdjusterRegistry.registerFormAdjusters(qInstance, this);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.warn("Error enriching MaterialDashboardFieldMetaData", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public void validate(QInstance qInstance, QFieldMetaData fieldMetaData, QInstanceValidator qInstanceValidator)
|
||||
{
|
||||
String prefix = "MaterialDashboardFieldMetaData for field [" + fieldMetaData.getName() + "]";
|
||||
|
||||
boolean needsFormAdjusterIdentifer = false;
|
||||
if(onChangeFormAdjuster != null)
|
||||
{
|
||||
needsFormAdjusterIdentifer = true;
|
||||
qInstanceValidator.validateSimpleCodeReference(prefix + ", onChangeFormAdjuster", onChangeFormAdjuster, FormAdjusterInterface.class);
|
||||
}
|
||||
|
||||
if(onLoadFormAdjuster != null)
|
||||
{
|
||||
needsFormAdjusterIdentifer = true;
|
||||
qInstanceValidator.validateSimpleCodeReference(prefix + ", onLoadFormAdjuster", onLoadFormAdjuster, FormAdjusterInterface.class);
|
||||
}
|
||||
|
||||
if(needsFormAdjusterIdentifer)
|
||||
{
|
||||
qInstanceValidator.assertCondition(StringUtils.hasContent(formAdjusterIdentifier), prefix + ", formAdjusterIdentifier is required if using any FormAdjusters");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for formAdjusterIdentifier
|
||||
*******************************************************************************/
|
||||
public String getFormAdjusterIdentifier()
|
||||
{
|
||||
return (this.formAdjusterIdentifier);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for formAdjusterIdentifier
|
||||
*******************************************************************************/
|
||||
public void setFormAdjusterIdentifier(String formAdjusterIdentifier)
|
||||
{
|
||||
this.formAdjusterIdentifier = formAdjusterIdentifier;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for formAdjusterIdentifier
|
||||
*******************************************************************************/
|
||||
public MaterialDashboardFieldMetaData withFormAdjusterIdentifier(String formAdjusterIdentifier)
|
||||
{
|
||||
this.formAdjusterIdentifier = formAdjusterIdentifier;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for fieldsToDisableWhileRunningAdjusters
|
||||
*******************************************************************************/
|
||||
public Set<String> getFieldsToDisableWhileRunningAdjusters()
|
||||
{
|
||||
return (this.fieldsToDisableWhileRunningAdjusters);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for fieldsToDisableWhileRunningAdjusters
|
||||
*******************************************************************************/
|
||||
public void setFieldsToDisableWhileRunningAdjusters(Set<String> fieldsToDisableWhileRunningAdjusters)
|
||||
{
|
||||
this.fieldsToDisableWhileRunningAdjusters = fieldsToDisableWhileRunningAdjusters;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for fieldsToDisableWhileRunningAdjusters
|
||||
*******************************************************************************/
|
||||
public MaterialDashboardFieldMetaData withFieldsToDisableWhileRunningAdjusters(Set<String> fieldsToDisableWhileRunningAdjusters)
|
||||
{
|
||||
this.fieldsToDisableWhileRunningAdjusters = fieldsToDisableWhileRunningAdjusters;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user