Search in sources :

Example 6 with FieldMapping

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);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) HashMap(java.util.HashMap) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType) Test(org.testng.annotations.Test)

Example 7 with FieldMapping

use of org.apache.atlas.typesystem.types.FieldMapping in project incubator-atlas by apache.

the class DefaultPropertyMapper method toFullyQualifiedName.

@Override
public String toFullyQualifiedName(String propName, String type) {
    HierarchicalType dataType = getDataType(type);
    String replacement = m_cleanToQualifiedMap.get(propName);
    if (replacement == null && dataType != null) {
        FieldMapping fieldMap = dataType.fieldMapping();
        if (fieldMap.fields.containsKey(propName)) {
            try {
                replacement = dataType.getQualifiedName(propName);
            } catch (AtlasException e) {
                throw new CatalogRuntimeException(String.format("Unable to resolve fully qualified property name for type '%s': %s", type, e), e);
            }
        }
    }
    if (replacement == null) {
        replacement = propName;
    }
    return replacement;
}
Also used : FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) CatalogRuntimeException(org.apache.atlas.catalog.exception.CatalogRuntimeException) AtlasException(org.apache.atlas.AtlasException) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType)

Example 8 with FieldMapping

use of org.apache.atlas.typesystem.types.FieldMapping in project incubator-atlas by apache.

the class NotificationEntityChangeListener 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;
}
Also used : HashMap(java.util.HashMap) TraitType(org.apache.atlas.typesystem.types.TraitType) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct)

Example 9 with FieldMapping

use of org.apache.atlas.typesystem.types.FieldMapping in project incubator-atlas by apache.

the class DefaultPropertyMapperTest method testToCleanName_specifiedMappings.

@Test
public void testToCleanName_specifiedMappings() {
    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);
    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.toCleanName("property_1", typeName), "prop1");
    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);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) HashMap(java.util.HashMap) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType) Test(org.testng.annotations.Test)

Aggregations

FieldMapping (org.apache.atlas.typesystem.types.FieldMapping)9 HashMap (java.util.HashMap)6 HierarchicalType (org.apache.atlas.typesystem.types.HierarchicalType)6 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)5 Test (org.testng.annotations.Test)4 LinkedList (java.util.LinkedList)2 IStruct (org.apache.atlas.typesystem.IStruct)2 Struct (org.apache.atlas.typesystem.Struct)2 TraitType (org.apache.atlas.typesystem.types.TraitType)2 AtlasException (org.apache.atlas.AtlasException)1 CatalogRuntimeException (org.apache.atlas.catalog.exception.CatalogRuntimeException)1 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)1 DataTypes (org.apache.atlas.typesystem.types.DataTypes)1 IDataType (org.apache.atlas.typesystem.types.IDataType)1