changes to make script processes in api better

This commit is contained in:
2023-06-14 16:42:04 -05:00
parent d273d091df
commit 1c1a0f99e8
4 changed files with 68 additions and 22 deletions

View File

@ -102,6 +102,8 @@ public class ScriptsMetaDataProvider
{ {
return (new QProcessMetaData() return (new QProcessMetaData()
.withName(STORE_SCRIPT_REVISION_PROCESS_NAME) .withName(STORE_SCRIPT_REVISION_PROCESS_NAME)
.withTableName(Script.TABLE_NAME)
.withIsHidden(true)
.withStepList(List.of( .withStepList(List.of(
new QBackendStepMetaData() new QBackendStepMetaData()
.withName("main") .withName("main")
@ -118,6 +120,8 @@ public class ScriptsMetaDataProvider
{ {
return (new QProcessMetaData() return (new QProcessMetaData()
.withName(TEST_SCRIPT_PROCESS_NAME) .withName(TEST_SCRIPT_PROCESS_NAME)
.withTableName(Script.TABLE_NAME)
.withIsHidden(true)
.withStepList(List.of( .withStepList(List.of(
new QBackendStepMetaData() new QBackendStepMetaData()
.withName("main") .withName("main")

View File

@ -202,8 +202,8 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
*******************************************************************************/ *******************************************************************************/
public GenerateOpenApiSpecOutput execute(GenerateOpenApiSpecInput input) throws QException public GenerateOpenApiSpecOutput execute(GenerateOpenApiSpecInput input) throws QException
{ {
QInstance qInstance = QContext.getQInstance(); QInstance qInstance = QContext.getQInstance();
String version = input.getVersion(); String version = input.getVersion();
ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(qInstance); ApiInstanceMetaDataContainer apiInstanceMetaDataContainer = ApiInstanceMetaDataContainer.of(qInstance);
if(apiInstanceMetaDataContainer == null) if(apiInstanceMetaDataContainer == null)
@ -1052,7 +1052,7 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
private static Parameter processFieldToParameter(ApiInstanceMetaData apiInstanceMetaData, QFieldMetaData field) private Parameter processFieldToParameter(ApiInstanceMetaData apiInstanceMetaData, QFieldMetaData field)
{ {
ApiFieldMetaDataContainer apiFieldMetaDataContainer = ApiFieldMetaDataContainer.ofOrNew(field); ApiFieldMetaDataContainer apiFieldMetaDataContainer = ApiFieldMetaDataContainer.ofOrNew(field);
ApiFieldMetaData apiFieldMetaData = apiFieldMetaDataContainer.getApiFieldMetaData(apiInstanceMetaData.getName()); ApiFieldMetaData apiFieldMetaData = apiFieldMetaDataContainer.getApiFieldMetaData(apiInstanceMetaData.getName());
@ -1062,16 +1062,14 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
{ {
description += " Default value is " + field.getDefaultValue() + ", if not given."; description += " Default value is " + field.getDefaultValue() + ", if not given.";
} }
if(apiFieldMetaData != null && StringUtils.hasContent(apiFieldMetaData.getDescription()))
{ Schema fieldSchema = getFieldSchema(field, description, apiInstanceMetaData);
description = apiFieldMetaData.getDescription();
}
Parameter parameter = new Parameter() Parameter parameter = new Parameter()
.withName(field.getName()) .withName(field.getName())
.withDescription(description) .withDescription(description)
.withRequired(field.getIsRequired()) .withRequired(field.getIsRequired())
.withSchema(new Schema().withType(getFieldType(field))); .withSchema(fieldSchema);
if(apiFieldMetaData != null) if(apiFieldMetaData != null)
{ {
@ -1183,7 +1181,14 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
for(QFieldMetaData field : tableApiFields) for(QFieldMetaData field : tableApiFields)
{ {
Schema fieldSchema = getFieldSchema(table, field); String fieldLabel = field.getLabel();
if(!StringUtils.hasContent(fieldLabel))
{
fieldLabel = QInstanceEnricher.nameToLabel(field.getName());
}
String defaultDescription = fieldLabel + " for the " + table.getLabel() + ".";
Schema fieldSchema = getFieldSchema(field, defaultDescription, apiInstanceMetaData);
tableFields.put(ApiFieldMetaData.getEffectiveApiFieldName(apiInstanceMetaData.getName(), field), fieldSchema); tableFields.put(ApiFieldMetaData.getEffectiveApiFieldName(apiInstanceMetaData.getName(), field), fieldSchema);
} }
@ -1354,20 +1359,22 @@ public class GenerateOpenApiSpecAction extends AbstractQActionFunction<GenerateO
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
private Schema getFieldSchema(QTableMetaData table, QFieldMetaData field) private Schema getFieldSchema(QFieldMetaData field, String defaultDescription, ApiInstanceMetaData apiInstanceMetaData)
{ {
String fieldLabel = field.getLabel(); ApiFieldMetaDataContainer apiFieldMetaDataContainer = ApiFieldMetaDataContainer.ofOrNew(field);
if(!StringUtils.hasContent(fieldLabel)) ApiFieldMetaData apiFieldMetaData = apiFieldMetaDataContainer.getApiFieldMetaData(apiInstanceMetaData.getName());
{
fieldLabel = QInstanceEnricher.nameToLabel(field.getName());
}
String description = fieldLabel + " for the " + table.getLabel() + "."; String description = defaultDescription;
if(field.getType().equals(QFieldType.BLOB)) if(field.getType().equals(QFieldType.BLOB))
{ {
description = "Base64 encoded " + description; description = "Base64 encoded " + description;
} }
if(apiFieldMetaData != null && StringUtils.hasContent(apiFieldMetaData.getDescription()))
{
description = apiFieldMetaData.getDescription();
}
Schema fieldSchema = new Schema() Schema fieldSchema = new Schema()
.withType(getFieldType(field)) .withType(getFieldType(field))
.withFormat(getFieldFormat(field)) .withFormat(getFieldFormat(field))

View File

@ -52,6 +52,7 @@ public class ApiProcessMetaData
private String apiProcessName; private String apiProcessName;
private Boolean isExcluded; private Boolean isExcluded;
private Boolean overrideProcessIsHidden;
private String path; private String path;
private HttpMethod method; private HttpMethod method;
@ -577,4 +578,35 @@ public class ApiProcessMetaData
return (this); return (this);
} }
/*******************************************************************************
** Getter for overrideProcessIsHidden
*******************************************************************************/
public Boolean getOverrideProcessIsHidden()
{
return (this.overrideProcessIsHidden);
}
/*******************************************************************************
** Setter for overrideProcessIsHidden
*******************************************************************************/
public void setOverrideProcessIsHidden(Boolean overrideProcessIsHidden)
{
this.overrideProcessIsHidden = overrideProcessIsHidden;
}
/*******************************************************************************
** Fluent setter for overrideProcessIsHidden
*******************************************************************************/
public ApiProcessMetaData withOverrideProcessIsHidden(Boolean overrideProcessIsHidden)
{
this.overrideProcessIsHidden = overrideProcessIsHidden;
return (this);
}
} }

View File

@ -68,12 +68,6 @@ public class ApiProcessUtils
throw (new QNotFoundException("Could not find a process named " + processApiName + " in this api.")); throw (new QNotFoundException("Could not find a process named " + processApiName + " in this api."));
} }
if(BooleanUtils.isTrue(process.getIsHidden()))
{
LOG.info("404 because process isHidden", logPairs);
throw (new QNotFoundException("Could not find a process named " + processApiName + " in this api."));
}
ApiProcessMetaDataContainer apiProcessMetaDataContainer = ApiProcessMetaDataContainer.of(process); ApiProcessMetaDataContainer apiProcessMetaDataContainer = ApiProcessMetaDataContainer.of(process);
if(apiProcessMetaDataContainer == null) if(apiProcessMetaDataContainer == null)
{ {
@ -94,6 +88,15 @@ public class ApiProcessUtils
throw (new QNotFoundException("Could not find a process named " + processApiName + " in this api.")); throw (new QNotFoundException("Could not find a process named " + processApiName + " in this api."));
} }
if(BooleanUtils.isTrue(process.getIsHidden()))
{
if(!BooleanUtils.isTrue(apiProcessMetaData.getOverrideProcessIsHidden()))
{
LOG.info("404 because process isHidden", logPairs);
throw (new QNotFoundException("Could not find a process named " + processApiName + " in this api."));
}
}
APIVersion requestApiVersion = new APIVersion(version); APIVersion requestApiVersion = new APIVersion(version);
List<APIVersion> supportedVersions = apiInstanceMetaData.getSupportedVersions(); List<APIVersion> supportedVersions = apiInstanceMetaData.getSupportedVersions();
if(CollectionUtils.nullSafeIsEmpty(supportedVersions) || !supportedVersions.contains(requestApiVersion)) if(CollectionUtils.nullSafeIsEmpty(supportedVersions) || !supportedVersions.contains(requestApiVersion))