Skip to content

Commit faeda15

Browse files
James ZhouJames Zhou
authored andcommitted
Merge pull request #335 in DM/herd from feature/DM-10653 to develop
* commit 'e469d2d5bd3d0d9a3a6890b6c54d3c0f2febac45': DM-10653 ( Allow non-backwards compatible Schema changes based on Format indicator)
2 parents e6522f5 + e469d2d commit faeda15

File tree

4 files changed

+63
-27
lines changed

4 files changed

+63
-27
lines changed

herd-code/herd-service/src/main/java/org/finra/herd/service/impl/BusinessObjectFormatServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ public BusinessObjectFormat deleteBusinessObjectFormat(BusinessObjectFormatKey b
427427
previousVersionBusinessObjectFormatEntity.setRecordFlag(businessObjectFormatEntity.isRecordFlag());
428428
previousVersionBusinessObjectFormatEntity.setRetentionPeriodInDays(businessObjectFormatEntity.getRetentionPeriodInDays());
429429
previousVersionBusinessObjectFormatEntity.setRetentionType(businessObjectFormatEntity.getRetentionType());
430+
431+
// Update the previous version schema compatibility changes information.
432+
previousVersionBusinessObjectFormatEntity
433+
.setAllowNonBackwardsCompatibleChanges(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges());
434+
435+
// Save the updated entity.
430436
businessObjectFormatDao.saveAndRefresh(previousVersionBusinessObjectFormatEntity);
431437
}
432438
}

herd-code/herd-service/src/main/java/org/finra/herd/service/impl/RelationalTableRegistrationHelperServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ BusinessObjectData registerRelationalTableImpl(RelationalTableRegistrationCreate
396396
BusinessObjectFormatEntity businessObjectFormatEntity =
397397
businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatHelper.getBusinessObjectFormatKey(businessObjectFormat));
398398

399+
// Allow non-backwards-compatible schema changes.
400+
businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(true);
401+
businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
402+
399403
// Get a business object data status entity for the VALID status.
400404
BusinessObjectDataStatusEntity businessObjectDataStatusEntity =
401405
businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(BusinessObjectDataStatusEntity.VALID);

herd-code/herd-service/src/test/java/org/finra/herd/service/BusinessObjectFormatServiceTest.java

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4661,26 +4661,27 @@ public void testCreateBusinessObjectFormatWithAllowNonBackwardsCompatibleChanges
46614661
businessObjectFormatServiceTestHelper.createTestDatabaseEntitiesForBusinessObjectFormatTesting();
46624662

46634663
// Create an initial version of a business object format with a schema.
4664-
BusinessObjectFormat businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatServiceTestHelper
4664+
BusinessObjectFormat businessObjectFormatV0 = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatServiceTestHelper
46654665
.createBusinessObjectFormatCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_KEY, FORMAT_DESCRIPTION,
46664666
businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(),
46674667
businessObjectFormatServiceTestHelper.getTestSchema()));
46684668

4669-
// Validate allowNonBackwardsCompatibleChanges is not set.
4670-
assertNull(businessObjectFormat.isAllowNonBackwardsCompatibleChanges());
4669+
// Validate allowNonBackwardsCompatibleChanges is not set on businessObjectFormatV0
4670+
assertNull(businessObjectFormatV0.isAllowNonBackwardsCompatibleChanges());
46714671

4672-
// Create business object format key for the initial version of the format.
4673-
BusinessObjectFormatKey businessObjectFormatKey =
4672+
// Create business object format key for format V0.
4673+
BusinessObjectFormatKey businessObjectFormatKeyV0 =
46744674
new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION);
46754675

4676-
// Create a business object format create request with non-backwards compatible schema changes.
4677-
// Try to create a second version of the business object format with a schema that has a different null value.
4678-
Schema newSchema = businessObjectFormatServiceTestHelper.getTestSchema();
4679-
newSchema.setNullValue(SCHEMA_NULL_VALUE_NULL_WORD);
4676+
// Create a business object format create request with non-backwards compatible schema changes, schema that has a different null value.
4677+
Schema nonBackwardsCompatibleSchema = businessObjectFormatServiceTestHelper.getTestSchema();
4678+
nonBackwardsCompatibleSchema.setNullValue(SCHEMA_NULL_VALUE_NULL_WORD);
46804679
BusinessObjectFormatCreateRequest businessObjectFormatCreateRequest = businessObjectFormatServiceTestHelper
46814680
.createBusinessObjectFormatCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_KEY, FORMAT_DESCRIPTION,
4682-
businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), newSchema);
4681+
businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(),
4682+
nonBackwardsCompatibleSchema);
46834683

4684+
// Try to create a second version of the business object format with non-backwards compatible schema changes.
46844685
// We expected to fail as allowNonBackwardsCompatibleChanges is not set.
46854686
try
46864687
{
@@ -4693,14 +4694,15 @@ public void testCreateBusinessObjectFormatWithAllowNonBackwardsCompatibleChanges
46934694
"New format version null value does not match to the previous format version null value.", e.getMessage());
46944695
}
46954696

4696-
// Get the business object format entity by alternate key.
4697-
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
4698-
assertNotNull(businessObjectFormatEntity);
4697+
// Get the initial format version of the business object format entity.
4698+
BusinessObjectFormatEntity businessObjectFormatEntityV0 = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKeyV0);
4699+
assertNotNull(businessObjectFormatEntityV0);
46994700

4700-
// Update allowNonBackwardsCompatibleChanges to false.
4701-
businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(false);
4702-
assertFalse(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges());
4701+
// Update businessObjectFormatEntityV0 to allowNonBackwardsCompatibleChanges to false.
4702+
businessObjectFormatEntityV0.setAllowNonBackwardsCompatibleChanges(false);
4703+
assertFalse(businessObjectFormatEntityV0.isAllowNonBackwardsCompatibleChanges());
47034704

4705+
// Try to create a second version of the business object format with non-backwards compatible schema changes..
47044706
// We expected to fail as allowNonBackwardsCompatibleChanges is set to false.
47054707
try
47064708
{
@@ -4713,21 +4715,43 @@ public void testCreateBusinessObjectFormatWithAllowNonBackwardsCompatibleChanges
47134715
"New format version null value does not match to the previous format version null value.", e.getMessage());
47144716
}
47154717

4716-
// Get the business object format entity by alternate key.
4717-
businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
4718-
assertNotNull(businessObjectFormatEntity);
4718+
// Get the initial format version and validate that the allowNonBackwardsCompatibleChanges is set to false.
4719+
businessObjectFormatV0 = businessObjectFormatService.getBusinessObjectFormat(businessObjectFormatKeyV0);
4720+
assertFalse(businessObjectFormatV0.isAllowNonBackwardsCompatibleChanges());
47194721

4720-
// Update allowNonBackwardsCompatibleChanges to true.
4721-
businessObjectFormatEntity.setAllowNonBackwardsCompatibleChanges(true);
4722-
assertTrue(businessObjectFormatEntity.isAllowNonBackwardsCompatibleChanges());
4722+
// Update businessObjectFormatEntityV0 to allowNonBackwardsCompatibleChanges to true.
4723+
businessObjectFormatEntityV0.setAllowNonBackwardsCompatibleChanges(true);
4724+
assertTrue(businessObjectFormatEntityV0.isAllowNonBackwardsCompatibleChanges());
47234725

47244726
// Call create business object format when allowNonBackwardsCompatibleChanges is set to true.
4725-
businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest);
4727+
BusinessObjectFormat businessObjectFormatV1 = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest);
4728+
4729+
// Validate businessObjectFormatV1 and businessObjectFormatEntityV0.
4730+
assertNotNull(businessObjectFormatV1);
4731+
assertEquals(true, businessObjectFormatV1.isAllowNonBackwardsCompatibleChanges());
4732+
assertEquals(SECOND_FORMAT_VERSION, Integer.valueOf(businessObjectFormatV1.getBusinessObjectFormatVersion()));
4733+
assertNull(businessObjectFormatEntityV0.isAllowNonBackwardsCompatibleChanges());
4734+
4735+
// Get the initial format version and validate that the allowNonBackwardsCompatibleChanges is set to true.
4736+
businessObjectFormatV0 = businessObjectFormatService.getBusinessObjectFormat(businessObjectFormatKeyV0);
4737+
assertTrue(businessObjectFormatV0.isAllowNonBackwardsCompatibleChanges());
4738+
4739+
// Delete the second version of business object format.
4740+
BusinessObjectFormat deletedBusinessObjectFormat = businessObjectFormatService
4741+
.deleteBusinessObjectFormat(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, SECOND_FORMAT_VERSION));
4742+
assertNotNull(deletedBusinessObjectFormat);
4743+
assertTrue(deletedBusinessObjectFormat.isAllowNonBackwardsCompatibleChanges());
4744+
4745+
// Get the initial format version of the business object format entity.
4746+
businessObjectFormatEntityV0 = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKeyV0);
4747+
4748+
// Validate the schema compatibility changes got propagated to the latest format version.
4749+
assertNotNull(businessObjectFormatEntityV0);
4750+
assertEquals(true, businessObjectFormatEntityV0.isAllowNonBackwardsCompatibleChanges());
4751+
assertEquals(INITIAL_FORMAT_VERSION, Integer.valueOf(businessObjectFormatEntityV0.getBusinessObjectFormatVersion()));
47264752

4727-
// Validate results.
4728-
assertNotNull(businessObjectFormat);
4729-
assertEquals(true, businessObjectFormat.isAllowNonBackwardsCompatibleChanges());
4730-
assertEquals(SECOND_FORMAT_VERSION, Integer.valueOf(businessObjectFormat.getBusinessObjectFormatVersion()));
4753+
// Validate initial version business object format entity.
4754+
assertTrue(businessObjectFormatEntityV0.isAllowNonBackwardsCompatibleChanges());
47314755
}
47324756

47334757
private GlobalAttributeDefinitionEntity createGlobalAttributeDefinitionEntityWithAllowedAttributeValues()

herd-code/herd-service/src/test/java/org/finra/herd/service/RelationalTableRegistrationServiceTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public void testCreateRelationalTableRegistration()
137137
new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_TABLE_NAME),
138138
relationalTableName)));
139139
expectedBusinessObjectFormat.setSchema(expectedSchema);
140+
expectedBusinessObjectFormat.setAllowNonBackwardsCompatibleChanges(true);
140141

141142
// Validate the newly created business object format.
142143
assertEquals(expectedBusinessObjectFormat, resultBusinessObjectFormat);
@@ -248,6 +249,7 @@ public void testCreateRelationalTableRegistrationWithAppendToExistingBusinessObj
248249
new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_TABLE_NAME),
249250
relationalTableName)));
250251
expectedBusinessObjectFormat.setSchema(expectedSchema);
252+
expectedBusinessObjectFormat.setAllowNonBackwardsCompatibleChanges(true);
251253

252254
// Validate the newly created business object format.
253255
assertEquals(expectedBusinessObjectFormat, businessObjectFormat);

0 commit comments

Comments
 (0)