Commit dccae799 authored by Sheng Wang's avatar Sheng Wang
Browse files

record id format: <tenantId>:<kindSubType>:<uniqueId>

parent e39792e7
Pipeline #24568 failed with stages
in 11 minutes and 41 seconds
......@@ -33,7 +33,8 @@ public class RecordConversion {
public Record toRecord(EntityDto dto) {
String localId = dto.getEntityId();
String globalId = generateGlobalId(localId);
String kindSubType = dto.getKind().split(":")[2];
String globalId = generateGlobalId(kindSubType, localId);
Record record = new Record(dto.getKind(), globalId);
//assign record the metadata
......@@ -51,14 +52,17 @@ public class RecordConversion {
record.getData().addProperty("existenceKind", dto.getExistenceKind());
record.getData().addProperty("ddmsid", this.ddmsId);
record.getData().add("data", new Gson().toJsonTree(dto.getData()));
if(dto.getMeta() != null)
if (dto.getMeta() != null)
record.getData().add("meta", new Gson().toJsonTree(dto.getMeta()));
return record;
}
private String generateGlobalId(String localId) {return String.format("%s:wd-ddms:%s", getPartitionId(), localId); }
private String getPartitionId(){
private String generateGlobalId(String kindSubType, String localId) {
return String.format("%s:%s:%s", getPartitionId(), kindSubType, localId);
}
private String getPartitionId() {
return requestInfo.getDpsHeaders().getPartitionId();
}
}
......@@ -61,6 +61,7 @@ public class RecordConversionTest {
@Test
public void should_returnRecord_when_DtoValid() {
String entityType = "entitytype-test";
String ddmsId = "ddmsId-test";
ReflectionTestUtils.setField(this.sut, "ddmsId", ddmsId);
......@@ -68,8 +69,8 @@ public class RecordConversionTest {
EntityDto dto = new EntityDto(
"id-test",
"entityid-test",
"entityType-test",
"kind-test",
entityType,
"tenant:wd-ddms:"+ entityType + ":kind-test",
"schemaId-test",
5435435,
"groupType-test",
......@@ -85,7 +86,7 @@ public class RecordConversionTest {
dto.getLegal().setLegaltags(new HashSet<>(Arrays.asList("legal-test1", "legal-test1")));
dto.getLegal().setOtherRelevantDataCountries(new HashSet<>(Arrays.asList("country-test1", "country-test1")));
Record actual = this.sut.toRecord(dto);
assertEquals(HEADER_DATA_PARTITION_ID + ":wd-ddms:" + dto.getEntityId(), actual.getId());
assertEquals(HEADER_DATA_PARTITION_ID + ":" + entityType + ":" + dto.getEntityId(), actual.getId());
assertEquals(dto.getKind(), actual.getKind());
assertEquals(dto.getVersion(), (long) actual.getVersion());
assertEquals(dto.getAcl().getViewers().size(), actual.getAcl().getViewers().length);
......
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