Skip to content
Snippets Groups Projects
Commit 4e65a216 authored by Neelesh Thakur's avatar Neelesh Thakur
Browse files

fix type mapping

parent 9bd0ef15
No related branches found
No related tags found
2 merge requests!346Merge branch 'aws-integration' into 'master',!222Add endpoint to consume schema service events
......@@ -143,11 +143,11 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements IMa
for (Map.Entry<String, Object> entry : schema.getMetaSchema().entrySet()) {
if (entry.getKey() == RecordMetaAttribute.AUTHORITY.getValue()) {
metaMapping.put(entry.getKey(), TypeMapper.getConstantIndexerType(RecordMetaAttribute.AUTHORITY, authority));
metaMapping.put(entry.getKey(), TypeMapper.getMetaAttributeIndexerMapping(entry.getKey(), authority));
} else if (entry.getKey() == RecordMetaAttribute.SOURCE.getValue()) {
metaMapping.put(entry.getKey(), TypeMapper.getConstantIndexerType(RecordMetaAttribute.SOURCE, source));
metaMapping.put(entry.getKey(), TypeMapper.getMetaAttributeIndexerMapping(entry.getKey(), source));
} else {
metaMapping.put(entry.getKey(), TypeMapper.getMetaAttributeIndexerMapping(entry.getKey()));
metaMapping.put(entry.getKey(), TypeMapper.getMetaAttributeIndexerMapping(entry.getKey(), null));
}
}
return metaMapping;
......@@ -211,11 +211,11 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements IMa
String source = parts[1];
for (String attribute : missing) {
if (attribute == RecordMetaAttribute.AUTHORITY.getValue()) {
properties.put(attribute, TypeMapper.getConstantIndexerType(RecordMetaAttribute.AUTHORITY, authority));
properties.put(attribute, TypeMapper.getMetaAttributeIndexerMapping(attribute, authority));
} else if (attribute == RecordMetaAttribute.SOURCE.getValue()) {
properties.put(attribute, TypeMapper.getConstantIndexerType(RecordMetaAttribute.SOURCE, source));
properties.put(attribute, TypeMapper.getMetaAttributeIndexerMapping(attribute, source));
} else {
properties.put(attribute, TypeMapper.getMetaAttributeIndexerMapping(attribute));
properties.put(attribute, TypeMapper.getMetaAttributeIndexerMapping(attribute, null));
}
}
......
......@@ -91,12 +91,8 @@ public class TypeMapper {
return metaAttributeIndexerType.getOrDefault(attribute.getValue(), null);
}
public static Object getConstantIndexerType(RecordMetaAttribute attribute, String value) {
if (RecordMetaAttribute.AUTHORITY != attribute && RecordMetaAttribute.SOURCE != attribute) {
return null;
}
Map<String, Object> constantAttribute = (Map<String, Object>) metaAttributeIndexerType.get(attribute.getValue());
private static Object getConstantIndexerType(String key, String value) {
Map<String, Object> constantAttribute = (Map<String, Object>) metaAttributeIndexerType.get(key);
constantAttribute.put("value", value);
return constantAttribute;
}
......@@ -105,10 +101,12 @@ public class TypeMapper {
return new ArrayList<>(metaAttributeIndexerType.keySet());
}
public static Object getMetaAttributeIndexerMapping(String key) {
public static Object getMetaAttributeIndexerMapping(String key, String value) {
if (key.equals(RecordMetaAttribute.ACL.getValue())
|| key.equals(RecordMetaAttribute.LEGAL.getValue()) || key.equals(RecordMetaAttribute.ANCESTRY.getValue()) || key.equals(RecordMetaAttribute.INDEX_STATUS.getValue())) {
return metaAttributeIndexerType.get(key);
} else if (key.equals(RecordMetaAttribute.AUTHORITY.getValue()) || key.equals(RecordMetaAttribute.SOURCE.getValue())) {
return getConstantIndexerType(key, value);
}
return Records.Type.builder().type(metaAttributeIndexerType.get(key).toString()).build();
}
......
......@@ -2,6 +2,7 @@ package org.opengroup.osdu.indexer.util;
import org.junit.Test;
import org.opengroup.osdu.core.common.model.indexer.ElasticType;
import org.opengroup.osdu.core.common.model.indexer.Records;
import org.opengroup.osdu.core.common.model.indexer.StorageType;
import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute;
......@@ -54,10 +55,11 @@ public class TypeMapperTest {
@Test
public void validate_constantAttribute_indexerMapping() {
Object value = TypeMapper.getConstantIndexerType(RecordMetaAttribute.ID, "");
assertNull(value);
Object value = TypeMapper.getMetaAttributeIndexerMapping(RecordMetaAttribute.ID.getValue(), "");
Records.Type recordsType = (Records.Type) value;
assertEquals("keyword", recordsType.getType());
value = TypeMapper.getConstantIndexerType(RecordMetaAttribute.AUTHORITY, "opendes");
value = TypeMapper.getMetaAttributeIndexerMapping(RecordMetaAttribute.AUTHORITY.getValue(), "opendes");
Map<String, Object> mapping = (Map<String, Object>) value;
assertEquals("constant_keyword", mapping.get("type"));
assertEquals("opendes", mapping.get("value"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment