Skip to content

Commit

Permalink
Updated some internal naming conventions from logScenario to loggerSc…
Browse files Browse the repository at this point in the history
…enario
  • Loading branch information
jongpie committed Sep 7, 2022
1 parent 1477eb2 commit 1bcd2e9
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, LoggerScenario__c> SCENARIO_UNIQUE_ID_TO_LOG_SCENARIO = new Map<String, LoggerScenario__c>();
private static final Map<String, LoggerScenario__c> SCENARIO_UNIQUE_ID_TO_SCENARIO = new Map<String, LoggerScenario__c>();
private static final Map<String, Log__c> TRANSACTION_ID_TO_LOG = new Map<String, Log__c>();

@TestVisible
Expand Down Expand Up @@ -54,7 +54,7 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
this.logEntryEvents = this.filterLogEntryEventsToSave((List<LogEntryEvent__e>) triggerNew);

if (this.logEntryEvents.isEmpty() == false) {
this.upsertLogScenarios();
this.upsertLoggerScenarios();
this.upsertLogs();
this.upsertLogEntries();
this.appendRuleBasedTags();
Expand All @@ -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<Database.UpsertResult> 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);
}

Expand Down Expand Up @@ -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);
Expand Down
36 changes: 18 additions & 18 deletions nebula-logger/core/main/log-management/classes/LogHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler {
private List<Log__c> logs;
@TestVisible
private Map<Id, Log__c> oldLogsById;
private Map<Id, LoggerScenario__c> logScenariosById;
private Map<Id, LoggerScenario__c> loggerScenariosById;

/**
* @description Returns SObject Type that the handler is responsible for processing
Expand All @@ -28,7 +28,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler {

protected override void executeBeforeInsert(List<SObject> triggerNew) {
this.logs = (List<Log__c>) 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
Expand Down Expand Up @@ -133,7 +133,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler {
}

private void setLogRetentionDetails() {
Map<String, LogScenarioRule__mdt> scenarioToScenarioRule = queryLogScenarioRules(this.logs, this.logScenariosById);
Map<String, LogScenarioRule__mdt> 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) {
Expand All @@ -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(
Expand Down Expand Up @@ -232,25 +232,25 @@ public without sharing class LogHandler extends LoggerSObjectHandler {
return logStatusNameToStatus;
}

private Map<Id, LoggerScenario__c> queryLogScenarios(List<Log__c> logs) {
List<Id> logScenarioIds = new List<Id>();
private static Map<Id, LoggerScenario__c> queryLoggerScenarios(List<Log__c> logs) {
List<Id> loggerScenarioIds = new List<Id>();
for (Log__c log : logs) {
if (log.TransactionScenario__c != null) {
logScenarioIds.add(log.TransactionScenario__c);
loggerScenarioIds.add(log.TransactionScenario__c);
}
}

Map<Id, LoggerScenario__c> logScenariosById = new Map<Id, LoggerScenario__c>();
Map<Id, LoggerScenario__c> loggerScenariosById = new Map<Id, LoggerScenario__c>();

if (logScenarioIds.isEmpty() == true) {
return logScenariosById;
if (loggerScenarioIds.isEmpty() == true) {
return loggerScenariosById;
}

List<LoggerScenario__c> matchingLogScenarios = LogManagementDataSelector.getInstance().getLoggerScenariosById(logScenarioIds);
if (matchingLogScenarios != null && matchingLogScenarios.isEmpty() == false) {
logScenariosById = new Map<Id, LoggerScenario__c>(matchingLogScenarios);
List<LoggerScenario__c> matchingLoggerScenarios = LogManagementDataSelector.getInstance().getLoggerScenariosById(loggerScenarioIds);
if (matchingLoggerScenarios != null && matchingLoggerScenarios.isEmpty() == false) {
loggerScenariosById = new Map<Id, LoggerScenario__c>(matchingLoggerScenarios);
}
return logScenariosById;
return loggerScenariosById;
}

private static Map<String, Id> queryQueues(List<String> possibleQueueNames) {
Expand All @@ -269,11 +269,11 @@ public without sharing class LogHandler extends LoggerSObjectHandler {
return usersByUsername;
}

private static Map<String, LogScenarioRule__mdt> queryLogScenarioRules(List<Log__c> logs, Map<Id, LoggerScenario__c> logScenariosById) {
private static Map<String, LogScenarioRule__mdt> queryLogScenarioRules(List<Log__c> logs, Map<Id, LoggerScenario__c> loggerScenariosById) {
Set<String> scenarios = new Set<String>();
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<fullName>UniqueId__c</fullName>
<caseSensitive>false</caseSensitive>
<externalId>true</externalId>
<inlineHelpText>An external ID field used to ensure that Log Scenario records are unique</inlineHelpText>
<inlineHelpText>An external ID field used to ensure that Logger Scenario records are unique</inlineHelpText>
<label>Unique ID</label>
<length>255</length>
<required>true</required>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
Expand Down

0 comments on commit 1bcd2e9

Please sign in to comment.