diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/processes/RunProcessAction.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/processes/RunProcessAction.java index 03ee26aa..ada00f9a 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/processes/RunProcessAction.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/processes/RunProcessAction.java @@ -79,6 +79,7 @@ public class RunProcessAction { private static final QLogger LOG = QLogger.getLogger(RunProcessAction.class); + public static final String BASEPULL_KEY_VALUE = "basepullKeyValue"; public static final String BASEPULL_THIS_RUNTIME_KEY = "basepullThisRuntimeKey"; public static final String BASEPULL_LAST_RUNTIME_KEY = "basepullLastRuntimeKey"; public static final String BASEPULL_TIMESTAMP_FIELD = "basepullTimestampField"; @@ -517,9 +518,13 @@ public class RunProcessAction /******************************************************************************* ** *******************************************************************************/ - protected String determineBasepullKeyValue(QProcessMetaData process, BasepullConfiguration basepullConfiguration) throws QException + protected String determineBasepullKeyValue(QProcessMetaData process, RunProcessInput runProcessInput, BasepullConfiguration basepullConfiguration) throws QException { String basepullKeyValue = (basepullConfiguration.getKeyValue() != null) ? basepullConfiguration.getKeyValue() : process.getName(); + if(runProcessInput.getValueString(BASEPULL_KEY_VALUE) != null) + { + basepullKeyValue = runProcessInput.getValueString(BASEPULL_KEY_VALUE); + } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // if process specifies that it uses variants, look for that data in the session and append to our basepull key // @@ -551,7 +556,7 @@ public class RunProcessAction String basepullTableName = basepullConfiguration.getTableName(); String basepullKeyFieldName = basepullConfiguration.getKeyField(); String basepullLastRunTimeFieldName = basepullConfiguration.getLastRunTimeFieldName(); - String basepullKeyValue = determineBasepullKeyValue(process, basepullConfiguration); + String basepullKeyValue = determineBasepullKeyValue(process, runProcessInput, basepullConfiguration); /////////////////////////////////////// // get the stored basepull timestamp // @@ -631,7 +636,7 @@ public class RunProcessAction String basepullKeyFieldName = basepullConfiguration.getKeyField(); String basepullLastRunTimeFieldName = basepullConfiguration.getLastRunTimeFieldName(); Integer basepullHoursBackForInitialTimestamp = basepullConfiguration.getHoursBackForInitialTimestamp(); - String basepullKeyValue = determineBasepullKeyValue(process, basepullConfiguration); + String basepullKeyValue = determineBasepullKeyValue(process, runProcessInput, basepullConfiguration); /////////////////////////////////////// // get the stored basepull timestamp // diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/tablesync/AbstractTableSyncTransformStep.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/tablesync/AbstractTableSyncTransformStep.java index 68619a28..9b0934a0 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/tablesync/AbstractTableSyncTransformStep.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/tablesync/AbstractTableSyncTransformStep.java @@ -23,6 +23,8 @@ package com.kingsrook.qqq.backend.core.processes.implementations.tablesync; import java.io.Serializable; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -35,6 +37,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.actions.values.QValueFormatter; import com.kingsrook.qqq.backend.core.context.QContext; import com.kingsrook.qqq.backend.core.exceptions.QException; import com.kingsrook.qqq.backend.core.logging.QLogger; @@ -53,6 +56,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryJoin; import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput; 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.session.QSession; import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.AbstractTransformStep; import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.StreamedETLWithFrontendProcess; import com.kingsrook.qqq.backend.core.processes.implementations.general.StandardProcessSummaryLineProducer; @@ -72,33 +76,33 @@ import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair; *******************************************************************************/ public abstract class AbstractTableSyncTransformStep extends AbstractTransformStep { - private static final QLogger LOG = QLogger.getLogger(AbstractTableSyncTransformStep.class); + protected static final QLogger LOG = QLogger.getLogger(AbstractTableSyncTransformStep.class); - private ProcessSummaryLine okToInsert = StandardProcessSummaryLineProducer.getOkToInsertLine(); - private ProcessSummaryLine okToUpdate = StandardProcessSummaryLineProducer.getOkToUpdateLine(); + protected ProcessSummaryLine okToInsert = StandardProcessSummaryLineProducer.getOkToInsertLine(); + protected ProcessSummaryLine okToUpdate = StandardProcessSummaryLineProducer.getOkToUpdateLine(); - private ProcessSummaryLine willNotInsert = new ProcessSummaryLine(Status.INFO) + protected ProcessSummaryLine willNotInsert = new ProcessSummaryLine(Status.INFO) .withMessageSuffix("because this process is not configured to insert records.") .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) + protected ProcessSummaryLine willNotUpdate = new ProcessSummaryLine(Status.INFO) .withMessageSuffix("because this process is not configured to update records.") .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) + protected ProcessSummaryLine errorMissingKeyField = new ProcessSummaryLine(Status.ERROR) .withMessageSuffix("missing a value for the key field.") .withSingularFutureMessage("will not be synced, because it is ") .withPluralFutureMessage("will not be synced, because they are ") .withSingularPastMessage("was not synced, because it is ") .withPluralPastMessage("were not synced, because they are "); - private ProcessSummaryLine unspecifiedError = new ProcessSummaryLine(Status.ERROR) + protected ProcessSummaryLine unspecifiedError = new ProcessSummaryLine(Status.ERROR) .withMessageSuffix("of an unexpected error: ") .withSingularFutureMessage("will not be synced, ") .withPluralFutureMessage("will not be synced, ") @@ -109,7 +113,11 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt protected RunBackendStepOutput runBackendStepOutput = null; protected RecordLookupHelper recordLookupHelper = null; - private QPossibleValueTranslator possibleValueTranslator; + protected QPossibleValueTranslator possibleValueTranslator; + + protected static final String SYNC_TABLE_PERFORM_INSERTS_KEY = "syncTablePerformInsertsKey"; + protected static final String SYNC_TABLE_PERFORM_UPDATES_KEY = "syncTablePerformUpdatesKey"; + protected static final String LOG_TRANSFORM_RESULTS = "logTransformResults"; @@ -214,6 +222,7 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt { if(CollectionUtils.nullSafeIsEmpty(runBackendStepInput.getRecords())) { + LOG.info("No input records were found."); return; } @@ -222,6 +231,17 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt SyncProcessConfig config = getSyncProcessConfig(); + //////////////////////////////////////////////////////////// + // see if these fields have been updated via input fields // + //////////////////////////////////////////////////////////// + if(runBackendStepInput.getValueString(SYNC_TABLE_PERFORM_INSERTS_KEY) != null) + { + config = new SyncProcessConfig(config.sourceTable, config.sourceTableKeyField, config.destinationTable, config.destinationTableForeignKey, true, config.performUpdates); + } + if(runBackendStepInput.getValueString(SYNC_TABLE_PERFORM_UPDATES_KEY) != null) + { + config = new SyncProcessConfig(config.sourceTable, config.sourceTableKeyField, config.destinationTable, config.destinationTableForeignKey, config.performUpdates, true); + } String sourceTableKeyField = config.sourceTableKeyField; String destinationTableForeignKeyField = config.destinationTableForeignKey; String destinationTableName = config.destinationTable; @@ -371,9 +391,57 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt possibleValueTranslator.translatePossibleValuesInRecords(QContext.getQInstance().getTable(destinationTableName), runBackendStepOutput.getRecords()); } } + + if(Boolean.parseBoolean(runBackendStepInput.getValueString(LOG_TRANSFORM_RESULTS))) + { + logResults(runBackendStepInput, config); + } } + + /******************************************************************************* + ** Log results of transformation + ** + *******************************************************************************/ + protected void logResults(RunBackendStepInput runBackendStepInput, SyncProcessConfig syncProcessConfig) + { + String timezone = QContext.getQSession().getValue(QSession.VALUE_KEY_USER_TIMEZONE); + if(timezone == null) + { + timezone = QContext.getQInstance().getDefaultTimeZoneId(); + } + ZonedDateTime dateTime = runBackendStepInput.getBasepullLastRunTime().atZone(ZoneId.of(timezone)); + + if(syncProcessConfig.performInserts) + { + if(okToInsert.getCount() == 0) + { + LOG.info("No Records were found to insert since " + QValueFormatter.formatDateTimeWithZone(dateTime) + "."); + } + else + { + String pluralized = okToInsert.getCount() > 1 ? " Records were " : " Record was "; + LOG.info(okToInsert.getCount() + pluralized + " found to insert since " + QValueFormatter.formatDateTimeWithZone(dateTime) + ".", logPair("primaryKeys", okToInsert.getPrimaryKeys())); + } + } + + if(syncProcessConfig.performUpdates) + { + if(okToUpdate.getCount() == 0) + { + LOG.info("No Records were found to update since " + QValueFormatter.formatDateTimeWithZone(dateTime) + "."); + } + else + { + String pluralized = okToUpdate.getCount() > 1 ? " Records were " : " Record was "; + LOG.info(okToUpdate.getCount() + pluralized + " found to update since " + QValueFormatter.formatDateTimeWithZone(dateTime) + ".", logPair("primaryKeys", okToInsert.getPrimaryKeys())); + } + } + } + + + /******************************************************************************* ** Given a source record, extract what we'll use as its key from it. **