Add 'unspecifiedError' for higher-level exceptions; add primaryKeys in summary lines

This commit is contained in:
2023-09-29 17:07:24 -05:00
parent dd57a327dd
commit e89093f339

View File

@ -35,6 +35,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
import com.kingsrook.qqq.backend.core.actions.values.QPossibleValueTranslator;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.actions.audits.AuditSingleInput;
@ -74,18 +75,21 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt
private ProcessSummaryLine okToInsert = StandardProcessSummaryLineProducer.getOkToInsertLine();
private ProcessSummaryLine okToUpdate = StandardProcessSummaryLineProducer.getOkToUpdateLine();
private ProcessSummaryLine willNotInsert = new ProcessSummaryLine(Status.INFO)
.withMessageSuffix("because of this process' configuration.")
.withSingularFutureMessage("will not be inserted ")
.withPluralFutureMessage("will not be inserted ")
.withSingularPastMessage("was not inserted ")
.withPluralPastMessage("were not inserted ");
private ProcessSummaryLine willNotUpdate = new ProcessSummaryLine(Status.INFO)
.withMessageSuffix("because of this process' configuration.")
.withSingularFutureMessage("will not be updated ")
.withPluralFutureMessage("will not be updated ")
.withSingularPastMessage("was not updated ")
.withPluralPastMessage("were not updated ");
private ProcessSummaryLine errorMissingKeyField = new ProcessSummaryLine(Status.ERROR)
.withMessageSuffix("missing a value for the key field.")
.withSingularFutureMessage("will not be synced, because it is ")
@ -93,6 +97,13 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt
.withSingularPastMessage("was not synced, because it is ")
.withPluralPastMessage("were not synced, because they are ");
private ProcessSummaryLine unspecifiedError = new ProcessSummaryLine(Status.ERROR)
.withMessageSuffix("of an unexpected error: ")
.withSingularFutureMessage("will not be synced, ")
.withPluralFutureMessage("will not be synced, ")
.withSingularPastMessage("was not synced, ")
.withPluralPastMessage("were not synced, ");
protected RunBackendStepInput runBackendStepInput = null;
protected RunBackendStepOutput runBackendStepOutput = null;
protected RecordLookupHelper recordLookupHelper = null;
@ -107,8 +118,17 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt
@Override
public ArrayList<ProcessSummaryLineInterface> getProcessSummary(RunBackendStepOutput runBackendStepOutput, boolean isForResultScreen)
{
ArrayList<ProcessSummaryLineInterface> processSummaryLineList = StandardProcessSummaryLineProducer.toArrayList(okToInsert, okToUpdate, errorMissingKeyField, willNotInsert, willNotUpdate);
return (processSummaryLineList);
return StandardProcessSummaryLineProducer.toArrayList(okToInsert, okToUpdate, errorMissingKeyField, unspecifiedError, willNotInsert, willNotUpdate);
}
/*******************************************************************************
**
*******************************************************************************/
protected ArrayList<ProcessSummaryLineInterface> getErrorProcessSummaryLines(RunBackendStepOutput runBackendStepOutput, boolean isForResultScreen)
{
return StandardProcessSummaryLineProducer.toArrayList(errorMissingKeyField, unspecifiedError);
}
@ -237,6 +257,7 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt
Set<Serializable> processedSourceKeys = new HashSet<>();
for(QRecord sourceRecord : runBackendStepInput.getRecords())
{
Serializable sourcePrimaryKey = sourceRecord.getValue(QContext.getQInstance().getTable(config.sourceTable).getPrimaryKeyField());
Serializable sourceKeyValue = sourceRecord.getValue(sourceTableKeyField);
if(processedSourceKeys.contains(sourceKeyValue))
{
@ -247,7 +268,7 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt
if(sourceKeyValue == null || "".equals(sourceKeyValue))
{
errorMissingKeyField.incrementCount();
errorMissingKeyField.incrementCountAndAddPrimaryKey(sourcePrimaryKey);
try
{
@ -266,6 +287,8 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt
//////////////////////////////////////////////////////////////
// look for the existing record, to determine insert/update //
//////////////////////////////////////////////////////////////
try
{
QRecord existingRecord = getExistingRecord(existingRecordsByForeignKey, destinationForeignKeyField, sourceKeyValue);
QRecord recordToStore;
@ -282,12 +305,12 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt
if(existingRecord != null)
{
LOG.info("Skipping storing existing record because this sync process is set to not perform updates");
willNotInsert.incrementCount();
willNotInsert.incrementCountAndAddPrimaryKey(sourcePrimaryKey);
}
else
{
LOG.info("Skipping storing new record because this sync process is set to not perform inserts");
willNotUpdate.incrementCount();
willNotUpdate.incrementCountAndAddPrimaryKey(sourcePrimaryKey);
}
continue;
}
@ -300,16 +323,22 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt
{
if(existingRecord != null)
{
okToUpdate.incrementCount();
okToUpdate.incrementCountAndAddPrimaryKey(sourcePrimaryKey);
}
else
{
okToInsert.incrementCount();
okToInsert.incrementCountAndAddPrimaryKey(sourcePrimaryKey);
}
runBackendStepOutput.addRecord(recordToStore);
}
}
catch(Exception e)
{
unspecifiedError.incrementCountAndAddPrimaryKey(sourcePrimaryKey);
unspecifiedError.setMessageSuffix(unspecifiedError.getMessageSuffix() + e.getMessage());
}
}
////////////////////////////////////////////////
// populate possible-values for review screen //