diff --git a/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls b/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls index d38566953..50995122e 100644 --- a/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls +++ b/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls @@ -80,9 +80,7 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler { continue; } - LogScenario__c logScenario = new LogScenario__c(Name = logEntryEvent.Scenario__c); - logScenario.UniqueId__c = LogScenarioHandler.generateUniqueId(logScenario); - + LogScenario__c logScenario = new LogScenario__c(UniqueId__c = logEntryEvent.Scenario__c); SCENARIO_UNIQUE_ID_TO_LOG_SCENARIO.put(logScenario.UniqueId__c, logScenario); } diff --git a/nebula-logger/core/main/log-management/classes/LogScenarioHandler.cls b/nebula-logger/core/main/log-management/classes/LogScenarioHandler.cls index eb03bbdd5..ba43db807 100644 --- a/nebula-logger/core/main/log-management/classes/LogScenarioHandler.cls +++ b/nebula-logger/core/main/log-management/classes/LogScenarioHandler.cls @@ -8,21 +8,9 @@ * @description Handles trigger events for the `LogScenario__c` object */ public without sharing class LogScenarioHandler extends LoggerSObjectHandler { - private static final Map TRANSACTION_ID_TO_LOG = new Map(); - @TestVisible private List logScenarios; - /** - * @description Generates a unique key for the `LogScenario__c` record, which - * is used to set the field `LogScenario__c.UniqueId__c` - * @param logScenario The `LogScenario__c` record to use for generating a unique ID - * @return The unique key for the record - */ - public static String generateUniqueId(LogScenario__c logScenario) { - return logScenario.Name?.trim(); - } - /** * @description Returns SObject Type that the handler is responsible for processing * @return The instance of `SObjectType` @@ -34,18 +22,16 @@ public without sharing class LogScenarioHandler extends LoggerSObjectHandler { protected override void executeBeforeInsert(List triggerNew) { this.logScenarios = (List) triggerNew; - this.setUniqueIdField(); - } - - protected override void executeBeforeUpdate(Map triggerNewMap, Map triggerOldMap) { - this.logScenarios = (List) triggerNewMap.values(); - - this.setUniqueIdField(); + this.setNameField(); } - private void setUniqueIdField() { + private void setNameField() { for (LogScenario__c logScenario : this.logScenarios) { - logScenario.UniqueId__c = logScenario.Name; + if (String.isBlank(logScenario.Name) == true && String.isNotBlank(logScenario.UniqueId__c) == true) { + logScenario.Name = logScenario.UniqueId__c; + } + Integer nameFieldMaxLength = Schema.LogScenario__c.Name.getDescribe().getLength(); + logScenario.Name = logScenario.UniqueId__c.left(nameFieldMaxLength); } } } diff --git a/nebula-logger/core/main/log-management/objects/LogScenario__c/LogScenario__c.object-meta.xml b/nebula-logger/core/main/log-management/objects/LogScenario__c/LogScenario__c.object-meta.xml index e963ebb2c..bf77b9b29 100644 --- a/nebula-logger/core/main/log-management/objects/LogScenario__c/LogScenario__c.object-meta.xml +++ b/nebula-logger/core/main/log-management/objects/LogScenario__c/LogScenario__c.object-meta.xml @@ -168,8 +168,9 @@ Log Scenarios - PrintableListView Accept + PrintableListView + Import UniqueId__c OWNER.ALIAS CREATED_DATE diff --git a/nebula-logger/core/main/log-management/objects/LogScenario__c/listViews/All.listView-meta.xml b/nebula-logger/core/main/log-management/objects/LogScenario__c/listViews/All.listView-meta.xml index 337d91732..134d40625 100644 --- a/nebula-logger/core/main/log-management/objects/LogScenario__c/listViews/All.listView-meta.xml +++ b/nebula-logger/core/main/log-management/objects/LogScenario__c/listViews/All.listView-meta.xml @@ -2,6 +2,7 @@ All NAME + UniqueId__c OWNER.ALIAS CREATEDBY_USER CREATED_DATE diff --git a/nebula-logger/core/main/log-management/objects/LogScenario__c/listViews/MyAssignedLogScenarios.listView-meta.xml b/nebula-logger/core/main/log-management/objects/LogScenario__c/listViews/MyAssignedLogScenarios.listView-meta.xml index 9eaa78200..f80fcbb1f 100644 --- a/nebula-logger/core/main/log-management/objects/LogScenario__c/listViews/MyAssignedLogScenarios.listView-meta.xml +++ b/nebula-logger/core/main/log-management/objects/LogScenario__c/listViews/MyAssignedLogScenarios.listView-meta.xml @@ -2,6 +2,7 @@ MyAssignedLogScenarios NAME + UniqueId__c OWNER.ALIAS CREATEDBY_USER CREATED_DATE 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 da0985a12..cd5a45bf9 100644 --- a/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls @@ -161,7 +161,7 @@ private class LogEntryEventHandler_Tests { LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.Log__c.SObjectType).IsEnabled__c = false; LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.LogEntry__c.SObjectType).IsEnabled__c = false; LogEntryEvent__e logEntryEvent = createLogEntryEvent(); - logEntryEvent.Scenario__c = 'some scenario'; + logEntryEvent.Scenario__c = '0'.repeat(Schema.LogEntryEvent__e.Scenario__c.getDescribe().getLength()); Database.SaveResult saveResult = LoggerMockDataStore.getEventBus().publishRecord(logEntryEvent); LoggerMockDataStore.getEventBus().deliver(new LogEntryEventHandler()); @@ -187,7 +187,7 @@ private class LogEntryEventHandler_Tests { LoggerTestConfigurator.setupMockSObjectHandlerConfigurations(); LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.Log__c.SObjectType).IsEnabled__c = false; LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.LogEntry__c.SObjectType).IsEnabled__c = false; - LogScenario__c existingLogScenario = new LogScenario__c(Name = 'hello, world'); + LogScenario__c existingLogScenario = new LogScenario__c(UniqueId__c = 'hello, world'); insert existingLogScenario; System.assertEquals(1, [SELECT COUNT() FROM LogScenario__c]); LogEntryEvent__e firstLogEntryEvent = createLogEntryEvent(); diff --git a/nebula-logger/core/tests/log-management/classes/LogScenarioHandler_Tests.cls b/nebula-logger/core/tests/log-management/classes/LogScenarioHandler_Tests.cls index e7f72f37e..241e30e57 100644 --- a/nebula-logger/core/tests/log-management/classes/LogScenarioHandler_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LogScenarioHandler_Tests.cls @@ -11,16 +11,6 @@ private class LogScenarioHandler_Tests { System.assertEquals(Schema.LogScenario__c.SObjectType, new LogScenarioHandler().getSObjectType()); } - @IsTest - static void it_generates_a_unique_id() { - LogScenario__c logScenario = new LogScenario__c(Name = 'Some scenario name'); - String expectedUniqueId = logScenario.Name.trim(); - - String generatedUniqueId = LogScenarioHandler.generateUniqueId(logScenario); - - System.assertEquals(expectedUniqueId, generatedUniqueId); - } - @IsTest static void it_should_not_run_when_disabled_via_configuration() { LoggerTestConfigurator.setupMockSObjectHandlerConfigurations(); @@ -39,11 +29,8 @@ private class LogScenarioHandler_Tests { } @IsTest - static void it_should_set_unique_id_on_insert() { - LogScenario__c logScenario = (LogScenario__c) LoggerMockDataCreator.createDataBuilder(Schema.LogScenario__c.SObjectType) - .populateRequiredFields() - .getRecord(); - logScenario.Name = 'Some log scenario name'; + static void it_should_set_name_on_insert_when_null() { + LogScenario__c logScenario = new LogScenario__c(UniqueId__c = 'Some scenario'); LoggerDataStore.getDatabase().insertRecord(logScenario); System.assertEquals( @@ -56,11 +43,10 @@ private class LogScenarioHandler_Tests { } @IsTest - static void it_should_set_unique_id_on_update() { - LogScenario__c logScenario = (LogScenario__c) LoggerMockDataCreator.createDataBuilder(Schema.LogScenario__c.SObjectType) - .populateRequiredFields() - .getRecord(); - logScenario.Name = 'Some log scenario name'; + static void it_should_truncate_name_on_insert_when_name_value_exceeds_name_field_length() { + Integer nameFieldMaxLength = Schema.LogScenario__c.Name.getDescribe().getLength(); + LogScenario__c logScenario = new LogScenario__c(Name = '0'.repeat(nameFieldMaxLength + 1), UniqueId__c = 'Some scenario'); + System.assertEquals(true, logScenario.Name.length() > nameFieldMaxLength); LoggerDataStore.getDatabase().insertRecord(logScenario); System.assertEquals( @@ -68,24 +54,25 @@ private class LogScenarioHandler_Tests { LoggerSObjectHandler.getExecutedHandlers().get(Schema.LogScenario__c.SObjectType).size(), 'Handler class should have executed two times - once for BEFORE_INSERT and once for AFTER_INSERT' ); + String expectedTruncatedValue = logScenario.Name.left(nameFieldMaxLength); logScenario = [SELECT Id, Name, UniqueId__c FROM LogScenario__c WHERE Id = :logScenario.Id]; - System.assertEquals(logScenario.Name, logScenario.UniqueId__c); + System.assertEquals(expectedTruncatedValue, logScenario.Name); } @IsTest - static void it_should_not_insert_duplicate_tag() { + static void it_should_not_allow_duplicate_scenario_to_be_inserted() { LogScenario__c logScenario = (LogScenario__c) LoggerMockDataCreator.createDataBuilder(Schema.LogScenario__c.SObjectType) .populateRequiredFields() .getRecord(); logScenario.Name = 'Some log scenario name'; LoggerDataStore.getDatabase().insertRecord(logScenario); - LogScenario__c duplicateTag = (LogScenario__c) LoggerMockDataCreator.createDataBuilder(new LogScenario__c(Name = logScenario.Name)) + LogScenario__c duplicateScenario = (LogScenario__c) LoggerMockDataCreator.createDataBuilder(new LogScenario__c(Name = logScenario.Name)) .populateRequiredFields() .getRecord(); Exception thrownException; try { - insert duplicateTag; + insert duplicateScenario; System.assert(false, 'Exception expected on previous line'); } catch (Exception ex) { thrownException = ex;