Commit 2ac124f3 authored by ethiraj krishnamanaidu's avatar ethiraj krishnamanaidu
Browse files

Merge branch 'mapping-info-fix-datatype' into 'master'

Fix mapping info datatype

See merge request !39
parents a56a8e23 3557f585
Pipeline #30701 failed with stages
in 33 minutes and 16 seconds
{
"id": "1a3c1f16-25c7-44cf-9fbd-7d9cbc90805a",
"version": "1606039291",
"version": 1606039291,
"authority": "opendes",
"kind": "opendes:mapping:mapping:1.0.0",
"mappingSchemaMajorVersion": "1",
"mappingSchemaMinorVersion": "0",
"mappingSchemaPatchVersion": "0",
"mappingSchemaMajorVersion": 1,
"mappingSchemaMinorVersion": 0,
"mappingSchemaPatchVersion": 0,
"sourceSchemaAuthority": "opendes",
"sourceSchemaSource": "oga",
"sourceEntityType": "well",
"sourceSchemaMajorVersion": "1",
"sourceSchemaMajorVersion": 1,
"sourceSchemaKind": "opendes:oga:well:1",
"targetSchemaAuthority": "slb",
"targetSchemaSource": "wks",
"targetEntityType": "well",
"targetSchemaMajorVersion": "4",
"targetSchemaMajorVersion": 4,
"targetSchemaKind": "slb:wks:well:4",
"createdBy": "automation",
"fileName": "1a3c1f16-25c7-44cf-9fbd-7d9cbc90805a.json",
......
{
"id": "4b312ef2-447d-4898-9d54-2a401975bd0b",
"version": "1606039291",
"version": 1606039291,
"authority": "opendes",
"kind": "opendes:mapping:mapping:1.0.0",
"mappingSchemaMajorVersion": "1",
"mappingSchemaMinorVersion": "0",
"mappingSchemaPatchVersion": "0",
"mappingSchemaMajorVersion": 1,
"mappingSchemaMinorVersion": 0,
"mappingSchemaPatchVersion": 0,
"sourceSchemaAuthority": "opendes",
"sourceSchemaSource": "ihs",
"sourceEntityType": "log",
"sourceSchemaMajorVersion": "1",
"sourceSchemaMajorVersion": 1,
"sourceSchemaKind": "opendes:ihs:log:1",
"targetSchemaAuthority": "slb",
"targetSchemaSource": "wks",
"targetEntityType": "log",
"targetSchemaMajorVersion": "2",
"targetSchemaMajorVersion": 2,
"targetSchemaKind": "slb:wks:log:2",
"createdBy": "automation",
"fileName": "4b312ef2-447d-4898-9d54-2a401975bd0b.json",
......
{
"id": "aa0ee7f6-2c0b-474a-962c-3e837a3b7de3",
"version": "1606039291",
"version": 1606039291,
"authority": "opendes",
"kind": "opendes:mapping:mapping:1.0.0",
"mappingSchemaMajorVersion": "1",
"mappingSchemaMinorVersion": "0",
"mappingSchemaPatchVersion": "0",
"mappingSchemaMajorVersion": 1,
"mappingSchemaMinorVersion": 0,
"mappingSchemaPatchVersion": 0,
"sourceSchemaAuthority": "opendes",
"sourceSchemaSource": "oga",
"sourceEntityType": "well",
"sourceSchemaMajorVersion": "1",
"sourceSchemaMajorVersion": 1,
"sourceSchemaKind": "opendes:oga:well:1",
"targetSchemaAuthority": "abc",
"targetSchemaSource": "wks",
"targetEntityType": "well",
"targetSchemaMajorVersion": "1",
"targetSchemaMajorVersion": 1,
"targetSchemaKind": "abc:wks:well:1",
"createdBy": "automation",
"fileName": "aa0ee7f6-2c0b-474a-962c-3e837a3b7de3.json",
......
{
"id": "d61a36bc-7b7b-4e7c-8a9c-33e7315bc076",
"version": "1606039291",
"version": 1606039291,
"authority": "opendes",
"kind": "opendes:mapping:mapping:1.0.0",
"mappingSchemaMinorVersion": "0",
"mappingSchemaPatchVersion": "0",
"mappingSchemaMajorVersion": 1,
"mappingSchemaMinorVersion": 0,
"mappingSchemaPatchVersion": 0,
"sourceSchemaAuthority": "opendes",
"sourceSchemaSource": "ihs",
"sourceEntityType": "log",
"sourceSchemaMajorVersion": "1",
"sourceSchemaMajorVersion": 1,
"sourceSchemaKind": "opendes:ihs:log:1",
"targetSchemaAuthority": "abc",
"targetSchemaSource": "wks",
"targetEntityType": "log",
"targetSchemaMajorVersion": "3",
"targetSchemaMajorVersion": 3,
"targetSchemaKind": "abc:wks:log:3",
"createdBy": "automation",
"fileName": "d61a36bc-7b7b-4e7c-8a9c-33e7315bc076.json",
......
{
"id": "dda587cd-770b-4104-bae3-3f834c3a8aec",
"version": "1606039291",
"version": 1606039291,
"authority": "opendes",
"kind": "opendes:mapping:mapping:1.0.0",
"mappingSchemaMajorVersion": "1",
"mappingSchemaMinorVersion": "0",
"mappingSchemaPatchVersion": "0",
"mappingSchemaMajorVersion": 1,
"mappingSchemaMinorVersion": 0,
"mappingSchemaPatchVersion": 0,
"sourceSchemaAuthority": "opendes",
"sourceSchemaSource": "oga",
"sourceEntityType": "well",
"sourceSchemaMajorVersion": "1",
"sourceSchemaMajorVersion": 1,
"sourceSchemaKind": "opendes:oga:well:1",
"targetSchemaAuthority": "slb",
"targetSchemaSource": "wks",
"targetEntityType": "well",
"targetSchemaMajorVersion": "5",
"targetSchemaMajorVersion": 5,
"targetSchemaKind": "slb:wks:well:5",
"createdBy": "automation",
"fileName": "dda587cd-770b-4104-bae3-3f834c3a8aec.json",
......
{
"id": "e2678b5f-5917-4bb1-8b30-2006efcb720d",
"version": "1606039291",
"version": 1606039291,
"authority": "opendes",
"kind": "opendes:mapping:mapping:1.0.0",
"mappingSchemaMajorVersion": "1",
"mappingSchemaMinorVersion": "0",
"mappingSchemaPatchVersion": "0",
"mappingSchemaMajorVersion": 1,
"mappingSchemaMinorVersion": 0,
"mappingSchemaPatchVersion": 0,
"sourceSchemaAuthority": "opendes",
"sourceSchemaSource": "at",
"sourceEntityType": "wellbore",
"sourceSchemaMajorVersion": "1",
"sourceSchemaMajorVersion": 1,
"sourceSchemaKind": "opendes:at:wellbore:1",
"targetSchemaAuthority": "slb",
"targetSchemaSource": "wks",
"targetEntityType": "wellbore",
"targetSchemaMajorVersion": "1",
"targetSchemaMajorVersion": 1,
"targetSchemaKind": "slb:wks:wellbore:1",
"createdBy": "automation",
"fileName": "e2678b5f-5917-4bb1-8b30-2006efcb720d.json",
......
......@@ -42,8 +42,8 @@ public class MappingStoreImpl implements MappingStore {
private RequestIdentity requestIdentity;
@Override
public List<MappingInfo> getMappingInfo(final String authority, final String entity, final String source, final String majorVersion) {
String schemaKind = String.join(Constants.COLON_SEPARATOR, authority, source, entity, majorVersion);
public List<MappingInfo> getMappingInfo(final String authority, final String entity, final String source, final int majorVersion) {
String schemaKind = String.join(Constants.COLON_SEPARATOR, authority, source, entity, Integer.toString(majorVersion));
SqlQuerySpec query = new SqlQuerySpec(
"SELECT * FROM c where c.sourceSchemaAuthority = @authority AND c.sourceEntityType = @entity AND "
......
......@@ -44,7 +44,7 @@ public class MappingStoreImplTest {
private static final String AUTHORITY_NAME = "opendes";
private static final String SOURCE = "wks";
private static final String ENTITY_TYPE = "wellbore";
private static final String MAJOR_VERSION = "1";
private static final int MAJOR_VERSION = 1;
private static final String WKS_SCHEMA_KIND = "opendes:wks:wellbore:1";
@InjectMocks
......
......@@ -41,7 +41,7 @@ public class MappingStoreImpl implements MappingStore {
*/
@Override
public List<MappingInfo> getMappingInfo(String authorityName, String entityNamePrefix, String sourceName, String majorVersion) {
public List<MappingInfo> getMappingInfo(String authorityName, String entityNamePrefix, String sourceName, int majorVersion) {
return new ArrayList<>();
}
......
package org.opengroup.osdu.wks.model.mapping;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import org.opengroup.osdu.wks.enums.MappingScope;
import java.sql.Timestamp;
@Getter
@Setter
@AllArgsConstructor
......@@ -15,16 +10,16 @@ import java.sql.Timestamp;
@Builder
public class MappingInfo {
private String id;
private String version;
private long version;
private String authority;
private String sourceSchemaAuthority;
private String sourceSchemaSource;
private String sourceEntityType;
private String sourceSchemaMajorVersion;
private int sourceSchemaMajorVersion;
private String sourceSchemaKind;
private String targetSchemaAuthority;
private String targetSchemaSource;
private String targetSchemaMajorVersion;
private int targetSchemaMajorVersion;
private String targetEntityType;
private String targetSchemaKind;
private String fileName;
......
......@@ -6,6 +6,6 @@ import org.opengroup.osdu.wks.model.mapping.MappingDefinition;
import org.opengroup.osdu.wks.model.mapping.MappingInfo;
public interface MappingStore {
List<MappingInfo> getMappingInfo(String authorityName, String entityNamePrefix, String sourceName, String majorVersion);
List<MappingInfo> getMappingInfo(String authorityName, String entityNamePrefix, String sourceName, int majorVersion);
MappingDefinition getMappingDefinitionFromStorage(MappingInfo mappingsInfo);
}
......@@ -9,6 +9,6 @@ import org.opengroup.osdu.wks.model.mapping.MappingInfo;
public interface MappingService {
List<MappingDefinition> getMapping(String kind) throws ApplicationException;
List<MappingInfo> getMappingInfos(String authority, String entity, String source, String majorVersion);
List<MappingInfo> getMappingInfos(String authority, String entity, String source, int majorVersion);
}
......@@ -25,7 +25,7 @@ public class MappingServiceImpl implements MappingService {
String authorityName = kindUtil.retrieveAuthorityName(kind);
String entityNamePrefix = kindUtil.retrieveEntityName(kind);
String sourceName = kindUtil.retrieveSourceName(kind);
String majorVersion = kindUtil.retrieveMajorVersion(kind);
int majorVersion = kindUtil.retrieveMajorVersion(kind);
List<MappingInfo> mappingInfos = mappingStore.getMappingInfo(authorityName, entityNamePrefix, sourceName, majorVersion);
if(mappingInfos.isEmpty()) {
return Collections.emptyList();
......@@ -34,7 +34,7 @@ public class MappingServiceImpl implements MappingService {
}
@Override
public List<MappingInfo> getMappingInfos(final String authority, final String entity, final String source, final String majorVersion) {
public List<MappingInfo> getMappingInfos(final String authority, final String entity, final String source, final int majorVersion) {
return mappingStore.getMappingInfo(authority, entity, source, majorVersion);
}
......
......@@ -9,15 +9,6 @@ import java.util.stream.Stream;
@Component
public class KindUtil {
public Integer getMajorVersionFromKind(String kind) {
String version = Stream.of(kind.split(Constants.COLON_SEPARATOR)).reduce( (first, last) -> last).get();
return Integer.parseInt(version.split("\\.")[0]);
}
public String getVersionFromKind(String kind) {
return Stream.of(kind.split(Constants.COLON_SEPARATOR)).reduce( (first, last) -> last).get();
}
public String prepareKind(String authority, String source, String entity, String majorVersion,
String minorVersion, String patchVersion) {
......@@ -41,9 +32,9 @@ public class KindUtil {
return idArr[SchemaConstants.SOURCE_INDEX];
}
public String retrieveMajorVersion(String kind) {
public int retrieveMajorVersion(String kind) {
String[] idArr = kind.split(Constants.COLON_SEPARATOR);
String version = idArr[SchemaConstants.VERSION_INDEX];
return version.split("\\.")[0];
return Integer.parseInt(version.split("\\.")[0]);
}
}
......@@ -280,7 +280,7 @@ public class RelationshipBlockHandler {
private List<WksInfo> getWKSRecordsCreatedByWKSService(String rawId, List<WksInfo> wksInfos, Kind rawKind) {
List<WksInfo> result = new ArrayList<>();
String majorVersion = rawKind.getVersion().split("\\.")[0];
int majorVersion = kindUtil.retrieveMajorVersion(rawKind.getKindAsString());
// TODO Look out for performance improvement through caching (FYI: Once mapping service comes
// online the entire logic of datastore look up will become obsolete)
List<MappingInfo> mappingInfos = mappingService.getMappingInfos(rawKind.getAuthority(),
......@@ -305,7 +305,7 @@ public class RelationshipBlockHandler {
return result;
}
private String generateKind(String authority, String source, String entity, String majorVersion) {
private String generateKind(String authority, String source, String entity, int majorVersion) {
String not = "0";
return authority + Constants.COLON_SEPARATOR + source + Constants.COLON_SEPARATOR + entity
+ Constants.COLON_SEPARATOR + majorVersion + Constants.POINT + not + Constants.POINT + not;
......
......@@ -19,7 +19,7 @@ public class WksIdGenerator {
.toString();
String[] idStrArr = rawId.split(Constants.COLON_SEPARATOR);
String majorVersion = new KindUtil().getMajorVersionFromKind(targetSchemaKind).toString();
int majorVersion = new KindUtil().retrieveMajorVersion(targetSchemaKind);
String targetSchemaKindInMapping = targetSchemaKind.substring(0, targetSchemaKind.lastIndexOf(Constants.COLON_SEPARATOR)) + Constants.COLON_SEPARATOR + majorVersion;
//Replacing semicolons here with dots since Record Id should be of the format a:b:c
......
......@@ -35,9 +35,9 @@ public class MappingServiceImplTest {
when(kindUtil.retrieveAuthorityName(KIND)).thenReturn("tenant1");
when(kindUtil.retrieveSourceName(KIND)).thenReturn("source");
when(kindUtil.retrieveEntityName(KIND)).thenReturn("entity");
when(kindUtil.retrieveMajorVersion(KIND)).thenReturn("1");
when(kindUtil.retrieveMajorVersion(KIND)).thenReturn(1);
MappingInfo mappingInfo = new MappingInfo();
when(mappingStore.getMappingInfo("tenant1", "source", "entity", "1")).thenReturn(Collections.singletonList(mappingInfo));
when(mappingStore.getMappingInfo("tenant1", "source", "entity", 1)).thenReturn(Collections.singletonList(mappingInfo));
List<MappingDefinition> mappings = mappingService.getMapping(KIND);
assertNotNull(mappings);
}
......
......@@ -13,6 +13,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.runner.RunWith;
......@@ -48,7 +49,7 @@ class RelationshipBlockHandlerTest {
private static final String AUTHORITY = "part1";
private static final String SOURCE = "wks";
private static final String ENTITY = "wellbore";
private static final String MAJOR_VERSION = "1";
private static final int MAJOR_VERSION = 1;
@Mock
private StorageService storageService;
......@@ -59,15 +60,16 @@ class RelationshipBlockHandlerTest {
@Mock
private MappingService mappingService;
@Mock
private KindUtil kindUtil;
@Mock
private TargetSchemaUtil targetSchemaUtil;
@InjectMocks
private RelationshipBlockHandler relationshipBlockHandler;
@BeforeEach
void setUp() {
relationshipBlockHandler = new RelationshipBlockHandler(storageService,searchService,mappingService,new KindUtil(),targetSchemaUtil);
}
@Test
public void testRelationshipForOneToOneRelationshipWhenWKSFound()
throws IOException, ApplicationException, NotFoundException {
......@@ -93,6 +95,9 @@ class RelationshipBlockHandlerTest {
assertTrue(response.getPendingEnitites().size() == 0);
}
/*
When no WKS is found for related WKS, than WKS id is cooked for related raw record if mapping exist and added to relationship block
*/
@Test
public void testRelationshipForOneToManyRelationshipWhenNoRelatedWksIdFound() throws IOException, ApplicationException {
Tree rawRecordWithRelationship = findJsonTree("raw_record_valid_relationship_block_oneToMany.json");
......@@ -115,7 +120,9 @@ class RelationshipBlockHandlerTest {
assertNotNull(response);
assertNotNull(response.getRelationshipTree());
assertTrue(response.getPendingEnitites().size() != 0);
assertEquals("part1:wellbore:wks-5512187e645eda7f7b3b02ebbd0a5cbbe68770fb.part1.wks.wellbore.1",response.getRelationshipTree().get("wellbores.ids").get(0).asString());
assertEquals("part1:wellbore:wks-e62beaebded27e04ea5b5c0c1c5b7345d75e6e01.part1.wks.wellbore.1",response.getRelationshipTree().get("wellbores.ids").get(1).asString());
assertEquals(0,response.getPendingEnitites().size());
}
@SneakyThrows
......@@ -133,10 +140,9 @@ class RelationshipBlockHandlerTest {
mappingInfoList.add(mappingInfo);
when(kindUtil.retrieveAuthorityName(TARGET_SCHEMA_KIND)).thenReturn(AUTHORITY);
when(storageService.getRecord(any(String.class))).thenReturn(Optional.of(wksRecordStr));
when(searchService.query(any(String.class))).thenReturn(searchResults);
when(mappingService.getMappingInfos(any(), any(), any(), any())).thenReturn(mappingInfoList);
when(mappingService.getMappingInfos(eq(AUTHORITY), eq(ENTITY), eq(SOURCE), eq(MAJOR_VERSION))).thenReturn(mappingInfoList);
UpdatedRelationshipBlock response = relationshipBlockHandler
.updateRelationshipBlockWithWksIds(rawRelationshipsBlockTree,TARGET_SCHEMA_KIND);
......@@ -160,10 +166,9 @@ class RelationshipBlockHandlerTest {
mappingInfoList.add(mappingInfo);
when(kindUtil.retrieveAuthorityName(TARGET_SCHEMA_KIND)).thenReturn(AUTHORITY);
when(storageService.getRecord(any(String.class))).thenReturn(Optional.of(wksRecordStr));
when(searchService.query(any(String.class))).thenReturn(searchResults);
when(mappingService.getMappingInfos(any(), any(), any(), any())).thenReturn(mappingInfoList);
when(mappingService.getMappingInfos(eq(AUTHORITY), eq(ENTITY), eq(SOURCE), eq(MAJOR_VERSION))).thenReturn(mappingInfoList);
UpdatedRelationshipBlock response = relationshipBlockHandler
.updateRelationshipBlockWithWksIds(rawRelationshipsBlockTree,TARGET_SCHEMA_KIND);
......@@ -172,6 +177,9 @@ class RelationshipBlockHandlerTest {
assertTrue(response.getPendingEnitites().size() == 0);
}
/*
When no WKS is found for related WKS, than WKS id is cooked for related raw record if mapping exist and added to relationship block
*/
@Test
public void testRelationshipForOneToOneRelationshipWhenNoWKSRecordCreatedByService() throws IOException, ApplicationException {
Tree rawRecordWithRelationship = findJsonTree("raw_record_valid_relationship_block_oneToOne.json");
......@@ -194,7 +202,9 @@ class RelationshipBlockHandlerTest {
assertNotNull(response);
assertNotNull(response.getRelationshipTree());
assertTrue(response.getPendingEnitites().size() != 0);
//Assert Cooked up wks id
assertEquals("part1:wellbore:wks-5512187e645eda7f7b3b02ebbd0a5cbbe68770fb.part1.wks.wellbore.1",response.getRelationshipTree().get("wellbore.id").asString());
assertEquals(0,response.getPendingEnitites().size());
}
@Test
......@@ -221,7 +231,7 @@ class RelationshipBlockHandlerTest {
String searchResults = findJsonTree("search_results_multiple_wks_generated_within_same_universe.json").toString();
List<MappingInfo> mappingInfoList = new ArrayList<>();
MappingInfo mappingInfo1 = getMappingInfoObject(AUTHORITY, SOURCE, ENTITY, MAJOR_VERSION);
MappingInfo mappingInfo2 = getMappingInfoObject(AUTHORITY, SOURCE, ENTITY, "3");
MappingInfo mappingInfo2 = getMappingInfoObject(AUTHORITY, SOURCE, ENTITY, 3);
mappingInfoList.add(mappingInfo1);
mappingInfoList.add(mappingInfo2);
......@@ -250,8 +260,8 @@ class RelationshipBlockHandlerTest {
String wksRecordStr = findJsonTree("wks_record.json").toString();
String searchResults = findJsonTree("search_results_multiple_wks_generated_within_different_universe.json").toString();
List<MappingInfo> mappingInfoList = new ArrayList<>();
MappingInfo mappingInfo1 = getMappingInfoObject("differentUniverse", SOURCE, ENTITY, "5");
MappingInfo mappingInfo2 = getMappingInfoObject(AUTHORITY, SOURCE, ENTITY, "7");
MappingInfo mappingInfo1 = getMappingInfoObject("differentUniverse", SOURCE, ENTITY, 5);
MappingInfo mappingInfo2 = getMappingInfoObject(AUTHORITY, SOURCE, ENTITY, 7);
mappingInfoList.add(mappingInfo1);
mappingInfoList.add(mappingInfo2);
......@@ -272,7 +282,7 @@ class RelationshipBlockHandlerTest {
assertTrue(response.getPendingEnitites().size() == 0);
}
private MappingInfo getMappingInfoObject(String authority, String source, String entity, String majorVersion) {
private MappingInfo getMappingInfoObject(String authority, String source, String entity, int majorVersion) {
MappingInfo mappingInfo = new MappingInfo();
mappingInfo.setTargetSchemaAuthority(authority);
mappingInfo.setTargetEntityType(entity);
......
Supports Markdown
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