diff --git a/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls b/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls index c7fda077d..036266e7d 100644 --- a/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls +++ b/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls @@ -15,7 +15,7 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler { private static final String DEFAULT_STORAGE_LOCATION_NAME = 'CUSTOM_OBJECTS'; private static final Database.DmlOptions DML_OPTIONS = createDmlOptions(); private static final String GUEST_USER_TYPE = 'Guest'; - private static final Map SCENARIO_UNIQUE_ID_TO_LOG_SCENARIO = new Map(); + private static final Map SCENARIO_UNIQUE_ID_TO_SCENARIO = new Map(); private static final Map TRANSACTION_ID_TO_LOG = new Map(); @TestVisible @@ -54,7 +54,7 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler { this.logEntryEvents = this.filterLogEntryEventsToSave((List) triggerNew); if (this.logEntryEvents.isEmpty() == false) { - this.upsertLogScenarios(); + this.upsertLoggerScenarios(); this.upsertLogs(); this.upsertLogEntries(); this.appendRuleBasedTags(); @@ -74,19 +74,19 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler { return logEntryEventsToSave; } - private void upsertLogScenarios() { + private void upsertLoggerScenarios() { for (LogEntryEvent__e logEntryEvent : this.logEntryEvents) { - if (String.isBlank(logEntryEvent.Scenario__c) == true || SCENARIO_UNIQUE_ID_TO_LOG_SCENARIO.containsKey(logEntryEvent.Scenario__c)) { + if (String.isBlank(logEntryEvent.Scenario__c) == true || SCENARIO_UNIQUE_ID_TO_SCENARIO.containsKey(logEntryEvent.Scenario__c)) { continue; } - LoggerScenario__c logScenario = new LoggerScenario__c(Name = logEntryEvent.Scenario__c, UniqueId__c = logEntryEvent.Scenario__c); - logScenario.setOptions(DML_OPTIONS); - SCENARIO_UNIQUE_ID_TO_LOG_SCENARIO.put(logScenario.UniqueId__c, logScenario); + LoggerScenario__c loggerScenario = new LoggerScenario__c(Name = logEntryEvent.Scenario__c, UniqueId__c = logEntryEvent.Scenario__c); + loggerScenario.setOptions(DML_OPTIONS); + SCENARIO_UNIQUE_ID_TO_SCENARIO.put(loggerScenario.UniqueId__c, loggerScenario); } List upsertResults = LoggerDataStore.getDatabase() - .upsertRecords(SCENARIO_UNIQUE_ID_TO_LOG_SCENARIO.values(), Schema.LoggerScenario__c.UniqueId__c, System.Test.isRunningTest()); + .upsertRecords(SCENARIO_UNIQUE_ID_TO_SCENARIO.values(), Schema.LoggerScenario__c.UniqueId__c, System.Test.isRunningTest()); LoggerEmailSender.sendErrorEmail(Schema.LoggerScenario__c.SObjectType, upsertResults); } @@ -161,8 +161,8 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler { UserType__c = logEntryEvent.UserType__c ); - if (String.isNotBlank(logEntryEvent.Scenario__c) == true && SCENARIO_UNIQUE_ID_TO_LOG_SCENARIO.containsKey(logEntryEvent.Scenario__c) == true) { - log.TransactionScenario__c = SCENARIO_UNIQUE_ID_TO_LOG_SCENARIO.get(logEntryEvent.Scenario__c).Id; + if (String.isNotBlank(logEntryEvent.Scenario__c) == true && SCENARIO_UNIQUE_ID_TO_SCENARIO.containsKey(logEntryEvent.Scenario__c) == true) { + log.TransactionScenario__c = SCENARIO_UNIQUE_ID_TO_SCENARIO.get(logEntryEvent.Scenario__c).Id; } TRANSACTION_ID_TO_LOG.put(log.TransactionId__c, log); diff --git a/nebula-logger/core/main/log-management/classes/LogHandler.cls b/nebula-logger/core/main/log-management/classes/LogHandler.cls index bddbe013e..670875665 100644 --- a/nebula-logger/core/main/log-management/classes/LogHandler.cls +++ b/nebula-logger/core/main/log-management/classes/LogHandler.cls @@ -16,7 +16,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { private List logs; @TestVisible private Map oldLogsById; - private Map logScenariosById; + private Map loggerScenariosById; /** * @description Returns SObject Type that the handler is responsible for processing @@ -28,7 +28,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { protected override void executeBeforeInsert(List triggerNew) { this.logs = (List) triggerNew; - this.logScenariosById = queryLogScenarios(this.logs); + this.loggerScenariosById = queryLoggerScenarios(this.logs); this.setClosedStatusFields(); // The log OwnerId field should support being manually changed, so only auto-set it on insert @@ -133,7 +133,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { } private void setLogRetentionDetails() { - Map scenarioToScenarioRule = queryLogScenarioRules(this.logs, this.logScenariosById); + Map scenarioToScenarioRule = queryLogScenarioRules(this.logs, this.loggerScenariosById); for (Log__c log : this.logs) { // If the retention date has already been populated, leave it as-is if (log.LogRetentionDate__c != null) { @@ -146,8 +146,8 @@ public without sharing class LogHandler extends LoggerSObjectHandler { // Load the configured scenario rule (if one exists) LogScenarioRule__mdt matchingScenarioRule; if (log.TransactionScenario__c != null) { - LoggerScenario__c logScenario = this.logScenariosById.get(log.TransactionScenario__c); - matchingScenarioRule = scenarioToScenarioRule.get(logScenario.UniqueId__c); + LoggerScenario__c loggerScenario = this.loggerScenariosById.get(log.TransactionScenario__c); + matchingScenarioRule = scenarioToScenarioRule.get(loggerScenario.UniqueId__c); } Integer daysToRetainLog = Integer.valueOf( @@ -232,25 +232,25 @@ public without sharing class LogHandler extends LoggerSObjectHandler { return logStatusNameToStatus; } - private Map queryLogScenarios(List logs) { - List logScenarioIds = new List(); + private static Map queryLoggerScenarios(List logs) { + List loggerScenarioIds = new List(); for (Log__c log : logs) { if (log.TransactionScenario__c != null) { - logScenarioIds.add(log.TransactionScenario__c); + loggerScenarioIds.add(log.TransactionScenario__c); } } - Map logScenariosById = new Map(); + Map loggerScenariosById = new Map(); - if (logScenarioIds.isEmpty() == true) { - return logScenariosById; + if (loggerScenarioIds.isEmpty() == true) { + return loggerScenariosById; } - List matchingLogScenarios = LogManagementDataSelector.getInstance().getLoggerScenariosById(logScenarioIds); - if (matchingLogScenarios != null && matchingLogScenarios.isEmpty() == false) { - logScenariosById = new Map(matchingLogScenarios); + List matchingLoggerScenarios = LogManagementDataSelector.getInstance().getLoggerScenariosById(loggerScenarioIds); + if (matchingLoggerScenarios != null && matchingLoggerScenarios.isEmpty() == false) { + loggerScenariosById = new Map(matchingLoggerScenarios); } - return logScenariosById; + return loggerScenariosById; } private static Map queryQueues(List possibleQueueNames) { @@ -269,11 +269,11 @@ public without sharing class LogHandler extends LoggerSObjectHandler { return usersByUsername; } - private static Map queryLogScenarioRules(List logs, Map logScenariosById) { + private static Map queryLogScenarioRules(List logs, Map loggerScenariosById) { Set scenarios = new Set(); for (Log__c log : logs) { - if (log.TransactionScenario__c != null && logScenariosById.containsKey(log.TransactionScenario__c) == true) { - scenarios.add(logScenariosById.get(log.TransactionScenario__c).UniqueId__c); + if (log.TransactionScenario__c != null && loggerScenariosById.containsKey(log.TransactionScenario__c) == true) { + scenarios.add(loggerScenariosById.get(log.TransactionScenario__c).UniqueId__c); } } diff --git a/nebula-logger/core/main/log-management/objects/LoggerScenario__c/fields/UniqueId__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/fields/UniqueId__c.field-meta.xml index 7a0834fb6..f42d05a06 100644 --- a/nebula-logger/core/main/log-management/objects/LoggerScenario__c/fields/UniqueId__c.field-meta.xml +++ b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/fields/UniqueId__c.field-meta.xml @@ -3,7 +3,7 @@ UniqueId__c false true - An external ID field used to ensure that Log Scenario records are unique + An external ID field used to ensure that Logger Scenario records are unique 255 true diff --git a/nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/MyAssignedLogScenarios.listView-meta.xml b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/MyAssignedLoggerScenarios.listView-meta.xml similarity index 100% rename from nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/MyAssignedLogScenarios.listView-meta.xml rename to nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/MyAssignedLoggerScenarios.listView-meta.xml diff --git a/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls b/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls index 0d6f74f8a..981e05f86 100644 --- a/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls @@ -155,7 +155,7 @@ private class LogEntryEventHandler_Tests { } @IsTest - static void it_should_normalize_event_data_into_log_scenario_and_log_and_log_entry_when_scenario_specified() { + static void it_should_normalize_event_data_into_logger_scenario_and_log_and_log_entry_when_scenario_specified() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); LoggerTestConfigurator.setupMockSObjectHandlerConfigurations(); LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.Log__c.SObjectType).IsEnabled__c = false; @@ -182,7 +182,7 @@ private class LogEntryEventHandler_Tests { } @IsTest - static void it_should_upsert_log_scenarios_when_scenario_specified() { + static void it_should_upsert_logger_scenarios_when_scenario_specified() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); LoggerTestConfigurator.setupMockSObjectHandlerConfigurations(); LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.Log__c.SObjectType).IsEnabled__c = false; diff --git a/nebula-logger/core/tests/log-management/classes/LogHandler_Tests.cls b/nebula-logger/core/tests/log-management/classes/LogHandler_Tests.cls index 6befa0470..112e0a7a3 100644 --- a/nebula-logger/core/tests/log-management/classes/LogHandler_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LogHandler_Tests.cls @@ -276,7 +276,7 @@ private class LogHandler_Tests { } @IsTest - static void it_should_set_retention_details_when_configured_via_log_scenario_rules() { + static void it_should_set_retention_details_when_configured_via_logger_scenario_rules() { setupConfigurations(); Integer defaultDaysToRetainLog = 1; Integer daysToRetainLog = 90; diff --git a/nebula-logger/core/tests/logger-engine/classes/ComponentLogger_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/ComponentLogger_Tests.cls index 56dabc00d..41bb75345 100644 --- a/nebula-logger/core/tests/logger-engine/classes/ComponentLogger_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/ComponentLogger_Tests.cls @@ -186,7 +186,7 @@ private class ComponentLogger_Tests { } @IsTest - static void it_should_set_log_scenario() { + static void it_should_set_logger_scenario() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); Logger.getUserSettings().LoggingLevel__c = LoggingLevel.FINEST.name(); ComponentLogger.ComponentLogEntry componentLogEntry = new ComponentLogger.ComponentLogEntry(); diff --git a/nebula-logger/core/tests/logger-engine/classes/FlowCollectionLogEntry_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/FlowCollectionLogEntry_Tests.cls index 97a64cf9d..704dd6134 100644 --- a/nebula-logger/core/tests/logger-engine/classes/FlowCollectionLogEntry_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/FlowCollectionLogEntry_Tests.cls @@ -229,7 +229,7 @@ private class FlowCollectionLogEntry_Tests { } @IsTest - static void it_should_set_log_scenario() { + static void it_should_set_logger_scenario() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); LoggingLevel userLoggingLevel = LoggingLevel.FINEST; Logger.getUserSettings().LoggingLevel__c = userLoggingLevel.name(); diff --git a/nebula-logger/core/tests/logger-engine/classes/FlowLogEntry_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/FlowLogEntry_Tests.cls index 5abbc94e2..69374d4bb 100644 --- a/nebula-logger/core/tests/logger-engine/classes/FlowLogEntry_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/FlowLogEntry_Tests.cls @@ -185,7 +185,7 @@ private class FlowLogEntry_Tests { } @IsTest - static void it_should_set_log_scenario() { + static void it_should_set_logger_scenario() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); LoggingLevel userLoggingLevel = LoggingLevel.FINEST; System.Test.startTest(); diff --git a/nebula-logger/core/tests/logger-engine/classes/FlowRecordLogEntry_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/FlowRecordLogEntry_Tests.cls index e92507e6c..8a92dde1e 100644 --- a/nebula-logger/core/tests/logger-engine/classes/FlowRecordLogEntry_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/FlowRecordLogEntry_Tests.cls @@ -226,7 +226,7 @@ private class FlowRecordLogEntry_Tests { } @IsTest - static void it_should_set_log_scenario() { + static void it_should_set_logger_scenario() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); LoggingLevel userLoggingLevel = LoggingLevel.FINEST; Logger.getUserSettings().LoggingLevel__c = userLoggingLevel.name(); diff --git a/nebula-logger/core/tests/logger-engine/classes/LoggerEngineDataSelector_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/LoggerEngineDataSelector_Tests.cls index afcc44526..4e3ae27d3 100644 --- a/nebula-logger/core/tests/logger-engine/classes/LoggerEngineDataSelector_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/LoggerEngineDataSelector_Tests.cls @@ -21,7 +21,7 @@ private class LoggerEngineDataSelector_Tests { SessionType, SourceIp FROM AuthSession - WHERE UsersId = :UserInfo.getUserId() AND IsCurrent = TRUE AND ParentId = NULL // TODO this won't work in an async context (when running as Automated Process) + WHERE UsersId = :UserInfo.getUserId() AND IsCurrent = TRUE AND ParentId = NULL ]; AuthSession expectedAuthSession = sessions.isEmpty() ? null : sessions.get(0); System.assertEquals(1, Limits.getQueries()); diff --git a/scripts/data/migrate-log-scenario-field-to-logger-scenario-object.apex b/scripts/data/migrate-log-scenario-field-to-logger-scenario-object.apex index 3899e8624..a9f2defe5 100644 --- a/scripts/data/migrate-log-scenario-field-to-logger-scenario-object.apex +++ b/scripts/data/migrate-log-scenario-field-to-logger-scenario-object.apex @@ -1,7 +1,7 @@ -// Prior to v4.8.2 (?), a log's scenario was stored in the text field Log__c.Scenario__c. -// In v4.8.2, a new LoggerScenario__c object was introduced, and replaces Log__c.Scenario__c. -// This script handles migrating the text field's data into the new LoggerScenario__c object, -// and relates each Log__c record to the corresponding LoggerScenario__c record +// Prior to v4.8.1, a log's scenario was stored in the text field Log__c.Scenario__c. +// In v4.8.1, a new LoggerScenario__c object was introduced, and the new lookup field Log__c.TransactionScenario__c +// replaces the text field Log__c.Scenario__c. This script handles migrating the text field's data into the new +// LoggerScenario__c object, and relates each Log__c record to the corresponding LoggerScenario__c record Integer countOfRecordsToUpdate = [SELECT COUNT() FROM Log__c WHERE TransactionScenario__c = null AND Scenario__c != null]; if (countOfRecordsToUpdate == 0) { System.debug('No Log__c records to update! All data has been successfully migrated from Log__c.Scenario__c to the new lookup Log__c.TransactionScenario__c');