Refactor to get rid of Usage parameter in QCodeReference

This commit is contained in:
2023-05-05 16:59:36 -05:00
parent cc765c66d6
commit 036b7dc115
27 changed files with 72 additions and 205 deletions

View File

@ -74,7 +74,7 @@ public class ChildRecordListRenderer extends AbstractWidgetRenderer
return (new Builder(new QWidgetMetaData()
.withName(join.getName())
.withIsCard(true)
.withCodeReference(new QCodeReference(ChildRecordListRenderer.class, null))
.withCodeReference(new QCodeReference(ChildRecordListRenderer.class))
.withType(WidgetType.CHILD_RECORD_LIST.getType())
.withDefaultValue("joinName", join.getName())));
}

View File

@ -39,7 +39,6 @@ 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;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeUsage;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
import com.kingsrook.qqq.backend.core.model.metadata.fields.FieldAdornment;
@ -706,7 +705,7 @@ public class QInstanceEnricher
.withTableName(table.getName())
.withIsHidden(true)
.withPermissionRules(qInstance.getDefaultPermissionRules().clone()
.withCustomPermissionChecker(new QCodeReference(BulkTableActionProcessPermissionChecker.class, QCodeUsage.CUSTOMIZER)));
.withCustomPermissionChecker(new QCodeReference(BulkTableActionProcessPermissionChecker.class)));
List<QFieldMetaData> editableFields = new ArrayList<>();
for(QFieldSection section : CollectionUtils.nonNullList(table.getSections()))
@ -770,7 +769,7 @@ public class QInstanceEnricher
.withTableName(table.getName())
.withIsHidden(true)
.withPermissionRules(qInstance.getDefaultPermissionRules().clone()
.withCustomPermissionChecker(new QCodeReference(BulkTableActionProcessPermissionChecker.class, QCodeUsage.CUSTOMIZER)));
.withCustomPermissionChecker(new QCodeReference(BulkTableActionProcessPermissionChecker.class)));
List<QFieldMetaData> editableFields = table.getFields().values().stream()
.filter(QFieldMetaData::getIsEditable)
@ -817,7 +816,7 @@ public class QInstanceEnricher
.withTableName(table.getName())
.withIsHidden(true)
.withPermissionRules(qInstance.getDefaultPermissionRules().clone()
.withCustomPermissionChecker(new QCodeReference(BulkTableActionProcessPermissionChecker.class, QCodeUsage.CUSTOMIZER)));
.withCustomPermissionChecker(new QCodeReference(BulkTableActionProcessPermissionChecker.class)));
List<QFieldMetaData> tableFields = table.getFields().values().stream().toList();
process.getFrontendStep("review").setRecordListFields(tableFields);

View File

@ -31,7 +31,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Stream;
import com.kingsrook.qqq.backend.core.actions.automation.RecordAutomationHandler;
@ -51,7 +50,6 @@ import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.QMiddlewareInstanceMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeType;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeUsage;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.ValueTooLongBehavior;
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinOn;
@ -909,9 +907,9 @@ public class QInstanceValidator
/*******************************************************************************
**
*******************************************************************************/
private void validateTableCustomizer(String tableName, String customizerName, QCodeReference codeReference)
private void validateTableCustomizer(String tableName, String roleName, QCodeReference codeReference)
{
String prefix = "Table " + tableName + ", customizer " + customizerName + ": ";
String prefix = "Table " + tableName + ", customizer " + roleName + ": ";
if(!preAssertionsForCodeReference(codeReference, prefix))
{
@ -934,7 +932,7 @@ public class QInstanceValidator
//////////////////////////////////////////////////
Object customizerInstance = getInstanceOfCodeReference(prefix, customizerClass);
TableCustomizers tableCustomizer = TableCustomizers.forRole(customizerName);
TableCustomizers tableCustomizer = TableCustomizers.forRole(roleName);
if(tableCustomizer == null)
{
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -947,29 +945,9 @@ public class QInstanceValidator
////////////////////////////////////////////////////////////////////////
// make sure the customizer instance can be cast to the expected type //
////////////////////////////////////////////////////////////////////////
if(customizerInstance != null && tableCustomizer.getTableCustomizer().getExpectedType() != null)
if(customizerInstance != null && tableCustomizer.getExpectedType() != null)
{
Object castedObject = getCastedObject(prefix, tableCustomizer.getTableCustomizer().getExpectedType(), customizerInstance);
Consumer<Object> validationFunction = tableCustomizer.getTableCustomizer().getValidationFunction();
if(castedObject != null && validationFunction != null)
{
try
{
validationFunction.accept(castedObject);
}
catch(ClassCastException e)
{
errors.add(prefix + "Error validating customizer type parameters: " + e.getMessage());
}
catch(Exception e)
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// mmm, calling customizers w/ random data is expected to often throw, so, this check is iffy at best... //
// if we run into more trouble here, we might consider disabling the whole "validation function" check. //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
assertObjectCanBeCasted(prefix, tableCustomizer.getExpectedType(), customizerInstance);
}
}
}
@ -979,18 +957,18 @@ public class QInstanceValidator
/*******************************************************************************
**
** Make sure that a given object can be casted to an expected type.
*******************************************************************************/
private <T> T getCastedObject(String prefix, Class<T> expectedType, Object customizerInstance)
private <T> T assertObjectCanBeCasted(String errorPrefix, Class<T> expectedType, Object object)
{
T castedObject = null;
try
{
castedObject = expectedType.cast(customizerInstance);
castedObject = expectedType.cast(object);
}
catch(ClassCastException e)
{
errors.add(prefix + "CodeReference is not of the expected type: " + expectedType);
errors.add(errorPrefix + "CodeReference is not of the expected type: " + expectedType);
}
return castedObject;
}
@ -1504,7 +1482,6 @@ public class QInstanceValidator
if(assertCondition(possibleValueSource.getCustomCodeReference() != null, "custom-type possibleValueSource " + pvsName + " is missing a customCodeReference."))
{
assertCondition(QCodeUsage.POSSIBLE_VALUE_PROVIDER.equals(possibleValueSource.getCustomCodeReference().getCodeUsage()), "customCodeReference for possibleValueSource " + pvsName + " is not a possibleValueProvider.");
validateSimpleCodeReference("PossibleValueSource " + pvsName + " custom code reference: ", possibleValueSource.getCustomCodeReference(), QCustomPossibleValueProvider.class);
}
}
@ -1548,7 +1525,7 @@ public class QInstanceValidator
////////////////////////////////////////////////////////////////////////
if(classInstance != null)
{
getCastedObject(prefix, expectedClass, classInstance);
assertObjectCanBeCasted(prefix, expectedClass, classInstance);
}
}
}

View File

@ -23,9 +23,6 @@ package com.kingsrook.qqq.backend.core.model.metadata.code;
import java.io.Serializable;
import com.kingsrook.qqq.backend.core.actions.automation.RecordAutomationHandler;
import com.kingsrook.qqq.backend.core.actions.processes.BackendStep;
import com.kingsrook.qqq.backend.core.actions.values.QCustomPossibleValueProvider;
/*******************************************************************************
@ -34,9 +31,8 @@ import com.kingsrook.qqq.backend.core.actions.values.QCustomPossibleValueProvide
*******************************************************************************/
public class QCodeReference implements Serializable
{
private String name;
private QCodeType codeType;
private QCodeUsage codeUsage;
private String name;
private QCodeType codeType;
private String inlineCode;
@ -54,11 +50,10 @@ public class QCodeReference implements Serializable
/*******************************************************************************
** Constructor that takes all args
*******************************************************************************/
public QCodeReference(String name, QCodeType codeType, QCodeUsage codeUsage)
public QCodeReference(String name, QCodeType codeType)
{
this.name = name;
this.codeType = codeType;
this.codeUsage = codeUsage;
}
@ -81,35 +76,6 @@ public class QCodeReference implements Serializable
{
this.name = javaClass.getName();
this.codeType = QCodeType.JAVA;
if(BackendStep.class.isAssignableFrom(javaClass))
{
this.codeUsage = QCodeUsage.BACKEND_STEP;
}
else if(QCustomPossibleValueProvider.class.isAssignableFrom(javaClass))
{
this.codeUsage = QCodeUsage.POSSIBLE_VALUE_PROVIDER;
}
else if(RecordAutomationHandler.class.isAssignableFrom(javaClass))
{
this.codeUsage = QCodeUsage.RECORD_AUTOMATION_HANDLER;
}
else
{
throw (new IllegalStateException("Unable to infer code usage type for class: " + javaClass.getName()));
}
}
/*******************************************************************************
** Constructor that just takes a java class and code usage.
*******************************************************************************/
public QCodeReference(Class<?> javaClass, QCodeUsage codeUsage)
{
this.name = javaClass.getName();
this.codeType = QCodeType.JAVA;
this.codeUsage = codeUsage;
}
@ -182,40 +148,6 @@ public class QCodeReference implements Serializable
/*******************************************************************************
** Getter for codeUsage
**
*******************************************************************************/
public QCodeUsage getCodeUsage()
{
return codeUsage;
}
/*******************************************************************************
** Setter for codeUsage
**
*******************************************************************************/
public void setCodeUsage(QCodeUsage codeUsage)
{
this.codeUsage = codeUsage;
}
/*******************************************************************************
** Setter for codeUsage
**
*******************************************************************************/
public QCodeReference withCodeUsage(QCodeUsage codeUsage)
{
this.codeUsage = codeUsage;
return (this);
}
/*******************************************************************************
** Getter for inlineCode
**

View File

@ -174,7 +174,7 @@ public class ScriptsMetaDataProvider
.withLabel("Contents")
.withIsCard(true)
.withType(WidgetType.SCRIPT_VIEWER.getType())
.withCodeReference(new QCodeReference(DefaultWidgetRenderer.class, null)));
.withCodeReference(new QCodeReference(DefaultWidgetRenderer.class)));
}

View File

@ -24,7 +24,6 @@ package com.kingsrook.qqq.backend.core.processes.implementations.etl.basic;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeType;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeUsage;
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.processes.QBackendStepMetaData;
@ -59,8 +58,7 @@ public class BasicETLProcess
.withName(FUNCTION_NAME_EXTRACT)
.withCode(new QCodeReference()
.withName(BasicETLExtractFunction.class.getName())
.withCodeType(QCodeType.JAVA)
.withCodeUsage(QCodeUsage.BACKEND_STEP))
.withCodeType(QCodeType.JAVA))
.withInputData(new QFunctionInputMetaData()
.withField(new QFieldMetaData(FIELD_SOURCE_TABLE, QFieldType.STRING)));
@ -68,8 +66,7 @@ public class BasicETLProcess
.withName(FUNCTION_NAME_TRANSFORM)
.withCode(new QCodeReference()
.withName(BasicETLTransformFunction.class.getName())
.withCodeType(QCodeType.JAVA)
.withCodeUsage(QCodeUsage.BACKEND_STEP))
.withCodeType(QCodeType.JAVA))
.withInputData(new QFunctionInputMetaData()
.withField(new QFieldMetaData(FIELD_MAPPING_JSON, QFieldType.STRING))
.withField(new QFieldMetaData(FIELD_DESTINATION_TABLE, QFieldType.STRING)));
@ -78,8 +75,7 @@ public class BasicETLProcess
.withName(FUNCTION_NAME_LOAD)
.withCode(new QCodeReference()
.withName(BasicETLLoadFunction.class.getName())
.withCodeType(QCodeType.JAVA)
.withCodeUsage(QCodeUsage.BACKEND_STEP))
.withCodeType(QCodeType.JAVA))
.withInputData(new QFunctionInputMetaData()
.withField(new QFieldMetaData(FIELD_DESTINATION_TABLE, QFieldType.STRING)))
.withOutputMetaData(new QFunctionOutputMetaData()

View File

@ -24,7 +24,6 @@ package com.kingsrook.qqq.backend.core.processes.implementations.etl.streamed;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeType;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeUsage;
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.processes.QBackendStepMetaData;
@ -39,9 +38,9 @@ import com.kingsrook.qqq.backend.core.model.metadata.processes.QStepMetaData;
*******************************************************************************/
public class StreamedETLProcess
{
public static final String PROCESS_NAME = "etl.streamed";
public static final String PROCESS_NAME = "etl.streamed";
public static final String FUNCTION_NAME_ETL = "streamedETL";
public static final String FUNCTION_NAME_ETL = "streamedETL";
public static final String FIELD_SOURCE_TABLE = "sourceTable";
public static final String FIELD_DESTINATION_TABLE = "destinationTable";
@ -59,8 +58,7 @@ public class StreamedETLProcess
.withName(FUNCTION_NAME_ETL)
.withCode(new QCodeReference()
.withName(StreamedETLBackendStep.class.getName())
.withCodeType(QCodeType.JAVA)
.withCodeUsage(QCodeUsage.BACKEND_STEP))
.withCodeType(QCodeType.JAVA))
.withInputData(new QFunctionInputMetaData()
.withField(new QFieldMetaData(FIELD_SOURCE_TABLE, QFieldType.STRING))
.withField(new QFieldMetaData(FIELD_MAPPING_JSON, QFieldType.STRING))

View File

@ -29,7 +29,6 @@ import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutp
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeType;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeUsage;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QBackendStepMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QFunctionInputMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QRecordListMetaData;
@ -71,8 +70,7 @@ public class LoadInitialRecordsStep implements BackendStep
.withName("loadInitialRecords")
.withCode(new QCodeReference()
.withName(LoadInitialRecordsStep.class.getName())
.withCodeType(QCodeType.JAVA)
.withCodeUsage(QCodeUsage.BACKEND_STEP))
.withCodeType(QCodeType.JAVA))
.withInputData(new QFunctionInputMetaData()
.withRecordListMetaData(new QRecordListMetaData()
.withTableName(tableName))));