Commit 03541555 authored by devesh bajpai's avatar devesh bajpai
Browse files

Merge branch 'pick-latest-version-of-mapping-file' into 'master'

Pick latest version of mapping file

See merge request !67
parents 2d7d4c66 8fe4d11c
Pipeline #44553 passed with stages
in 39 minutes and 19 seconds
......@@ -38,11 +38,15 @@ public class MappingService {
return Collections.emptyList();
}
return selectLatestVersionForEachMappingId(
groupByMappingId(mappingInfos));
groupBySourceTargetKind(mappingInfos));
}
private Collection<List<MappingInfo>> groupByMappingId(List<MappingInfo> mappingInfoList) {
return mappingInfoList.stream().collect(groupingBy(MappingInfo::getId)).values();
private Collection<List<MappingInfo>> groupBySourceTargetKind(List<MappingInfo> mappingInfoList) {
return mappingInfoList.stream().collect(groupingBy(this::getUniqueSourceTargetKindIdentifier)).values();
}
public String getUniqueSourceTargetKindIdentifier(MappingInfo mappingInfo){
return mappingInfo.getSourceSchemaKind() + mappingInfo.getTargetSchemaKind();
}
private List<MappingInfo> selectLatestVersionForEachMappingId(Collection<List<MappingInfo>> mappingsGroupedByMappingId) {
......
......@@ -48,7 +48,7 @@ public class MappingServiceTest {
assertEquals("sampleMapping",mappings.get(0).getId());
}
// Scenario: If multiple version of same mappingId is present then pick latest version only
// Scenario: If multiple version of mapping present for a combination source and target schema kind then pick latest version only
@Test
public void testGetMappingInfoMultipleVersionOfSameMapping() {
when(kindUtil.retrieveAuthorityName(KIND)).thenReturn("tenant1");
......@@ -56,25 +56,32 @@ public class MappingServiceTest {
when(kindUtil.retrieveEntityName(KIND)).thenReturn("entity");
when(kindUtil.retrieveMajorVersion(KIND)).thenReturn(1);
MappingInfo mappingInfoWithLowerVersion = new MappingInfo();
mappingInfoWithLowerVersion.setId("sampleMapping");
mappingInfoWithLowerVersion.setId("100000:sampleMapping");
mappingInfoWithLowerVersion.setSourceSchemaKind("tenant1:source:entity:1");
mappingInfoWithLowerVersion.setTargetSchemaKind("tenant1:target:entity:1");
mappingInfoWithLowerVersion.setVersion(100000);
MappingInfo mappingInfoWithHigherVersion = new MappingInfo();
mappingInfoWithHigherVersion.setId("sampleMapping");
mappingInfoWithHigherVersion.setId("200000:sampleMapping");
mappingInfoWithHigherVersion.setVersion(200000);
MappingInfo mappingInfoWithDIfferentId = new MappingInfo();
mappingInfoWithDIfferentId.setId("differentMapping");
mappingInfoWithDIfferentId.setVersion(200000);
List<MappingInfo> mappingInfo = Arrays.asList(mappingInfoWithDIfferentId,mappingInfoWithHigherVersion,mappingInfoWithLowerVersion);
mappingInfoWithHigherVersion.setSourceSchemaKind("tenant1:source:entity:1");
mappingInfoWithHigherVersion.setTargetSchemaKind("tenant1:target:entity:1");
MappingInfo mappingInfoWithDifferentTarget = new MappingInfo();
mappingInfoWithDifferentTarget.setId("200000:differentMapping");
mappingInfoWithDifferentTarget.setVersion(200000);
mappingInfoWithDifferentTarget.setSourceSchemaKind("tenant1:source:entity:1");
mappingInfoWithDifferentTarget.setTargetSchemaKind("tenant1:DifferentTarget:entity:1");
List<MappingInfo> mappingInfo = Arrays.asList(mappingInfoWithDifferentTarget,mappingInfoWithHigherVersion,mappingInfoWithLowerVersion);
when(mappingStore.getMappingInfo("tenant1", "entity","source", 1)).thenReturn(mappingInfo);
List<MappingInfo> mappings = mappingService.getMappingInfos("tenant1", "entity","source", 1);
assertNotNull(mappings);
//Then only one mapping is returned
//Then two mapping is returned
// based on the unique combination of source and target schema kind
assertEquals(2,mappings.size());
// And returned mapping is of higher mapping version.
assertEquals("sampleMapping", mappings.get(0).getId());
assertEquals("200000:sampleMapping", mappings.get(0).getId());
assertEquals(200000, mappings.get(0).getVersion());
// And returned mapping is of higher mapping version.
assertEquals("differentMapping", mappings.get(1).getId());
assertEquals("200000:differentMapping", mappings.get(1).getId());
assertEquals(200000, mappings.get(1).getVersion());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment