use of org.apache.atlas.typesystem.types.FieldMapping in project incubator-atlas by apache.
the class EntityNotificationImpl method getSuperTraits.
private static List<IStruct> getSuperTraits(String typeName, Map<String, Object> values, TypeSystem typeSystem) throws AtlasException {
List<IStruct> superTypes = new LinkedList<>();
TraitType traitDef = typeSystem.getDataType(TraitType.class, typeName);
Set<String> superTypeNames = traitDef.getAllSuperTypeNames();
for (String superTypeName : superTypeNames) {
TraitType superTraitDef = typeSystem.getDataType(TraitType.class, superTypeName);
Map<String, Object> superTypeValues = new HashMap<>();
FieldMapping fieldMapping = superTraitDef.fieldMapping();
if (fieldMapping != null) {
Set<String> superTypeAttributeNames = fieldMapping.fields.keySet();
for (String superTypeAttributeName : superTypeAttributeNames) {
if (values.containsKey(superTypeAttributeName)) {
superTypeValues.put(superTypeAttributeName, values.get(superTypeAttributeName));
}
}
}
IStruct superTrait = new Struct(superTypeName, superTypeValues);
superTypes.add(superTrait);
superTypes.addAll(getSuperTraits(superTypeName, values, typeSystem));
}
return superTypes;
}
use of org.apache.atlas.typesystem.types.FieldMapping in project incubator-atlas by apache.
the class DefaultPropertyMapperTest method testToQualifiedName_defaultMappings.
@Test
public void testToQualifiedName_defaultMappings() throws Exception {
String typeName = "testType";
HierarchicalType dataType = createNiceMock(HierarchicalType.class);
// currently only use key in map
Map<String, AttributeInfo> fields = new HashMap<>();
fields.put("foo", null);
fields.put("prop", null);
// can't mock FieldMapping due to direct access to final instance var 'fields'
FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// mock expectations
expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes();
expect(dataType.getQualifiedName("foo")).andReturn("foo");
expect(dataType.getQualifiedName("prop")).andReturn("Prefix.prop");
replay(dataType);
PropertyMapper propertyMapper = new TestDefaultPropertyMapper(dataType);
assertEquals(propertyMapper.toFullyQualifiedName("foo", typeName), "foo");
assertEquals(propertyMapper.toFullyQualifiedName("prop", typeName), "Prefix.prop");
assertEquals(propertyMapper.toFullyQualifiedName("other", typeName), "other");
assertEquals(propertyMapper.toFullyQualifiedName("Prefix.other", typeName), "Prefix.other");
verify(dataType);
}
use of org.apache.atlas.typesystem.types.FieldMapping in project incubator-atlas by apache.
the class DefaultPropertyMapperTest method testToQualifiedName_specifiedMappings.
@Test
public void testToQualifiedName_specifiedMappings() throws Exception {
String typeName = "testType";
HierarchicalType dataType = createNiceMock(HierarchicalType.class);
// currently only use key in map
Map<String, AttributeInfo> fields = new HashMap<>();
fields.put("foo", null);
fields.put("prop", null);
// can't mock FieldMapping due to direct access to final instance var 'fields'
FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// mock expectations
expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes();
expect(dataType.getQualifiedName("foo")).andReturn("foo");
expect(dataType.getQualifiedName("prop")).andReturn("Prefix.prop");
replay(dataType);
Map<String, String> cleanToQualifiedMap = new HashMap<>();
cleanToQualifiedMap.put("prop1", "property_1");
Map<String, String> qualifiedToCleanMap = new HashMap<>();
qualifiedToCleanMap.put("property_1", "prop1");
PropertyMapper propertyMapper = new TestDefaultPropertyMapper(typeName, qualifiedToCleanMap, cleanToQualifiedMap, dataType);
assertEquals(propertyMapper.toFullyQualifiedName("prop1", typeName), "property_1");
assertEquals(propertyMapper.toFullyQualifiedName("foo", typeName), "foo");
assertEquals(propertyMapper.toFullyQualifiedName("prop", typeName), "Prefix.prop");
assertEquals(propertyMapper.toFullyQualifiedName("other", typeName), "other");
assertEquals(propertyMapper.toFullyQualifiedName("Prefix.other", typeName), "Prefix.other");
verify(dataType);
}
use of org.apache.atlas.typesystem.types.FieldMapping in project incubator-atlas by apache.
the class DefaultPropertyMapperTest method testToCleanName_defaultMappings.
@Test
public void testToCleanName_defaultMappings() {
String typeName = "testType";
HierarchicalType dataType = createNiceMock(HierarchicalType.class);
// currently only use key in map
Map<String, AttributeInfo> fields = new HashMap<>();
fields.put("foo", null);
fields.put("prop", null);
// can't mock FieldMapping due to direct access to final instance var 'fields'
FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// mock expectations
expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes();
replay(dataType);
PropertyMapper propertyMapper = new TestDefaultPropertyMapper(dataType);
assertEquals(propertyMapper.toCleanName("Prefix.prop", typeName), "prop");
assertEquals(propertyMapper.toCleanName("foo", typeName), "foo");
assertEquals(propertyMapper.toCleanName("other", typeName), "other");
assertEquals(propertyMapper.toCleanName("Prefix.other", typeName), "Prefix.other");
verify(dataType);
}
use of org.apache.atlas.typesystem.types.FieldMapping in project incubator-atlas by apache.
the class DefaultPropertyMapper method toCleanName.
@Override
public String toCleanName(String propName, String type) {
HierarchicalType dataType = getDataType(type);
String replacement = m_qualifiedToCleanMap.get(propName);
if (replacement == null && dataType != null) {
FieldMapping fieldMap = dataType.fieldMapping();
if (!fieldMap.fields.containsKey(propName) && propName.contains(".")) {
String cleanName = propName.substring(propName.lastIndexOf('.') + 1);
if (fieldMap.fields.containsKey(cleanName)) {
replacement = cleanName;
}
}
}
if (replacement == null) {
replacement = propName;
}
return replacement;
}
Aggregations