CTLE-421: added reveal adornment, warnings on child record insert failures

This commit is contained in:
Tim Chamberlain
2023-05-02 10:12:55 -05:00
parent 2832566dbd
commit 83e628d2d6
7 changed files with 82 additions and 6 deletions

View File

@ -120,6 +120,11 @@ public abstract class ChildInserterPostInsertCustomizer extends AbstractPostInse
InsertOutput insertOutput = new InsertAction().execute(insertInput); InsertOutput insertOutput = new InsertAction().execute(insertInput);
Iterator<QRecord> insertedRecordIterator = insertOutput.getRecords().iterator(); Iterator<QRecord> insertedRecordIterator = insertOutput.getRecords().iterator();
/////////////////////////////////////////////////////////////////////////////////
// check for any errors when inserting the children, if any errors were found, //
// then set a warning in the parent with the details of the problem //
/////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////
// iterate over the original list of records again - for any that need a child (e.g., are missing // // iterate over the original list of records again - for any that need a child (e.g., are missing //
// foreign key), set their foreign key to a newly inserted child's key, and add them to be updated. // // foreign key), set their foreign key to a newly inserted child's key, and add them to be updated. //
@ -127,6 +132,20 @@ public abstract class ChildInserterPostInsertCustomizer extends AbstractPostInse
List<QRecord> recordsToUpdate = new ArrayList<>(); List<QRecord> recordsToUpdate = new ArrayList<>();
for(QRecord record : records) for(QRecord record : records)
{ {
///////////////////////////////////////////////////////////////////////////////////////////////////
// get the corresponding child record, if it has any errors, set that as a warning in the parent //
///////////////////////////////////////////////////////////////////////////////////////////////////
QRecord childRecord = insertedRecordIterator.next();
if(childRecord.getErrors() != null)
{
for(String childWarning : childRecord.getErrors())
{
record.addWarning("Error creating child " + childTable.getLabel() + " (" + childWarning + ")");
}
rs.add(record);
continue;
}
Serializable primaryKey = record.getValue(table.getPrimaryKeyField()); Serializable primaryKey = record.getValue(table.getPrimaryKeyField());
if(record.getValue(getForeignKeyFieldName()) == null) if(record.getValue(getForeignKeyFieldName()) == null)
{ {

View File

@ -53,7 +53,6 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateOutput; import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateOutput;
import com.kingsrook.qqq.backend.core.model.data.QRecord; import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData; 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.tables.QTableMetaData; import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.tables.cache.CacheUseCase; import com.kingsrook.qqq.backend.core.model.metadata.tables.cache.CacheUseCase;
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleDispatcher; import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleDispatcher;
@ -380,8 +379,12 @@ public class GetAction
Map<String, QFieldMetaData> fields = QContext.getQInstance().getTable(getInput.getTableName()).getFields(); Map<String, QFieldMetaData> fields = QContext.getQInstance().getTable(getInput.getTableName()).getFields();
for(String fieldName : fields.keySet()) for(String fieldName : fields.keySet())
{ {
QFieldType fieldType = fields.get(fieldName).getType(); QFieldMetaData field = fields.get(fieldName);
if(fieldType != null && fieldType.needsMasked()) if(getInput.getShouldOmitHiddenFields() && field.getIsHidden())
{
returnRecord.removeValue(fieldName);
}
else if(field.getType() != null && field.getType().needsMasked())
{ {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// empty out the value completely first (which will remove from // // empty out the value completely first (which will remove from //
@ -395,7 +398,6 @@ public class GetAction
} }
} }
} }
QValueFormatter.setDisplayValuesInRecords(getInput.getTable(), List.of(returnRecord));
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -65,6 +65,7 @@ public class QRecord implements Serializable
private Map<String, String> displayValues = new LinkedHashMap<>(); private Map<String, String> displayValues = new LinkedHashMap<>();
private Map<String, Serializable> backendDetails = new LinkedHashMap<>(); private Map<String, Serializable> backendDetails = new LinkedHashMap<>();
private List<String> errors = new ArrayList<>(); private List<String> errors = new ArrayList<>();
private List<String> warnings = new ArrayList<>();
private Map<String, List<QRecord>> associatedRecords = new HashMap<>(); private Map<String, List<QRecord>> associatedRecords = new HashMap<>();
@ -652,4 +653,46 @@ public class QRecord implements Serializable
return (this); return (this);
} }
/*******************************************************************************
** Getter for warnings
*******************************************************************************/
public List<String> getWarnings()
{
return (this.warnings);
}
/*******************************************************************************
** Setter for warnings
*******************************************************************************/
public void setWarnings(List<String> warnings)
{
this.warnings = warnings;
}
/*******************************************************************************
** Fluent setter for warnings
*******************************************************************************/
public QRecord withWarnings(List<String> warnings)
{
this.warnings = warnings;
return (this);
}
/*******************************************************************************
** Add one warning to this record
**
*******************************************************************************/
public void addWarning(String warning)
{
this.warnings.add(warning);
}
} }

View File

@ -39,6 +39,7 @@ public enum AdornmentType
SIZE, SIZE,
CODE_EDITOR, CODE_EDITOR,
RENDER_HTML, RENDER_HTML,
REVEAL,
ERROR; ERROR;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// keep these values in sync with AdornmentType.ts in qqq-frontend-core // // keep these values in sync with AdornmentType.ts in qqq-frontend-core //

View File

@ -151,7 +151,7 @@ public class Auth0AuthenticationModule implements QAuthenticationModuleInterface
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
if(context.containsKey(BASIC_AUTH_KEY)) if(context.containsKey(BASIC_AUTH_KEY))
{ {
AuthAPI auth = new AuthAPI(metaData.getBaseUrl(), metaData.getClientId(), metaData.getClientSecret()); AuthAPI auth = AuthAPI.newBuilder(metaData.getBaseUrl(), metaData.getClientId(), metaData.getClientSecret()).build();
try try
{ {
///////////////////////////////////////////////// /////////////////////////////////////////////////

View File

@ -1547,12 +1547,19 @@ public class QJavalinApiHandler
response.add(outputRecord); response.add(outputRecord);
List<String> errors = record.getErrors(); List<String> errors = record.getErrors();
List<String> warnings = record.getWarnings();
if(CollectionUtils.nullSafeHasContents(errors)) if(CollectionUtils.nullSafeHasContents(errors))
{ {
outputRecord.put("statusCode", HttpStatus.Code.BAD_REQUEST.getCode()); outputRecord.put("statusCode", HttpStatus.Code.BAD_REQUEST.getCode());
outputRecord.put("statusText", HttpStatus.Code.BAD_REQUEST.getMessage()); outputRecord.put("statusText", HttpStatus.Code.BAD_REQUEST.getMessage());
outputRecord.put("error", "Error inserting " + table.getLabel() + ": " + StringUtils.joinWithCommasAndAnd(errors)); outputRecord.put("error", "Error inserting " + table.getLabel() + ": " + StringUtils.joinWithCommasAndAnd(errors));
} }
else if(CollectionUtils.nullSafeHasContents(warnings))
{
outputRecord.put("statusCode", HttpStatus.Code.BAD_REQUEST.getCode());
outputRecord.put("statusText", HttpStatus.Code.BAD_REQUEST.getMessage());
outputRecord.put("error", "Warning inserting " + table.getLabel() + ", some data may have been inserted: " + StringUtils.joinWithCommasAndAnd(warnings));
}
else else
{ {
outputRecord.put("statusCode", HttpStatus.Code.CREATED.getCode()); outputRecord.put("statusCode", HttpStatus.Code.CREATED.getCode());

View File

@ -687,6 +687,10 @@ public class QJavalinImplementation
{ {
throw (new QUserFacingException("Error inserting " + qInstance.getTable(tableName).getLabel() + ": " + insertOutput.getRecords().get(0).getErrors().get(0))); throw (new QUserFacingException("Error inserting " + qInstance.getTable(tableName).getLabel() + ": " + insertOutput.getRecords().get(0).getErrors().get(0)));
} }
if(CollectionUtils.nullSafeHasContents(insertOutput.getRecords().get(0).getWarnings()))
{
throw (new QUserFacingException("Warning inserting " + qInstance.getTable(tableName).getLabel() + ": " + insertOutput.getRecords().get(0).getWarnings().get(0)));
}
QJavalinAccessLogger.logEndSuccess(logPair("primaryKey", () -> (insertOutput.getRecords().get(0).getValue(qInstance.getTable(tableName).getPrimaryKeyField())))); QJavalinAccessLogger.logEndSuccess(logPair("primaryKey", () -> (insertOutput.getRecords().get(0).getValue(qInstance.getTable(tableName).getPrimaryKeyField()))));
context.result(JsonUtils.toJson(insertOutput)); context.result(JsonUtils.toJson(insertOutput));