Search in sources :

Example 16 with AtlasAttributeDef

use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.

the class AtlasEntityType method collectTypeHierarchyInfo.

/*
     * This method should not assume that resolveReferences() has been called on all superTypes.
     * this.entityDef is the only safe member to reference here
     */
private void collectTypeHierarchyInfo(AtlasTypeRegistry typeRegistry, Set<String> allSuperTypeNames, Map<String, AtlasAttribute> allAttributes, List<String> visitedTypes) throws AtlasBaseException {
    if (visitedTypes.contains(entityDef.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.CIRCULAR_REFERENCE, entityDef.getName(), visitedTypes.toString());
    }
    if (CollectionUtils.isNotEmpty(entityDef.getSuperTypes())) {
        visitedTypes.add(entityDef.getName());
        for (String superTypeName : entityDef.getSuperTypes()) {
            AtlasEntityType superType = typeRegistry.getEntityTypeByName(superTypeName);
            if (superType != null) {
                superType.collectTypeHierarchyInfo(typeRegistry, allSuperTypeNames, allAttributes, visitedTypes);
            }
        }
        visitedTypes.remove(entityDef.getName());
        allSuperTypeNames.addAll(entityDef.getSuperTypes());
    }
    if (CollectionUtils.isNotEmpty(entityDef.getAttributeDefs())) {
        for (AtlasAttributeDef attributeDef : entityDef.getAttributeDefs()) {
            AtlasType type = typeRegistry.getType(attributeDef.getTypeName());
            allAttributes.put(attributeDef.getName(), new AtlasAttribute(this, attributeDef, type));
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)

Example 17 with AtlasAttributeDef

use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.

the class AtlasStructType method normalizeAttributeValuesForUpdate.

public void normalizeAttributeValuesForUpdate(AtlasStruct obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();
            if (obj.hasAttribute(attributeName)) {
                Object attributeValue = getNormalizedValueForUpdate(obj.getAttribute(attributeName), attributeDef);
                obj.setAttribute(attributeName, attributeValue);
            }
        }
    }
}
Also used : AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)

Example 18 with AtlasAttributeDef

use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.

the class AtlasStructType method normalizeAttributeValues.

public void normalizeAttributeValues(AtlasStruct obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();
            if (obj.hasAttribute(attributeName)) {
                Object attributeValue = getNormalizedValue(obj.getAttribute(attributeName), attributeDef);
                obj.setAttribute(attributeName, attributeValue);
            } else if (!attributeDef.getIsOptional()) {
                obj.setAttribute(attributeName, createDefaultValue(attributeDef));
            }
        }
    }
}
Also used : AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)

Example 19 with AtlasAttributeDef

use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.

the class AtlasStructType method normalizeAttributeValuesForUpdate.

public void normalizeAttributeValuesForUpdate(Map<String, Object> obj) {
    if (obj != null) {
        for (AtlasAttributeDef attrDef : structDef.getAttributeDefs()) {
            String attrName = attrDef.getName();
            Object attrValue = obj.get(attrName);
            if (obj.containsKey(attrName)) {
                attrValue = getNormalizedValueForUpdate(attrValue, attrDef);
                obj.put(attrName, attrValue);
            }
        }
    }
}
Also used : AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)

Example 20 with AtlasAttributeDef

use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.

the class AtlasStructType method resolveReferences.

@Override
public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
    Map<String, AtlasAttribute> a = new HashMap<>();
    for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
        AtlasType attrType = typeRegistry.getType(attributeDef.getTypeName());
        AtlasAttribute attribute = new AtlasAttribute(this, attributeDef, attrType);
        Cardinality cardinality = attributeDef.getCardinality();
        if (cardinality == Cardinality.LIST || cardinality == Cardinality.SET) {
            if (!(attrType instanceof AtlasArrayType)) {
                throw new AtlasBaseException(AtlasErrorCode.INVALID_ATTRIBUTE_TYPE_FOR_CARDINALITY, getTypeName(), attributeDef.getName());
            }
            AtlasArrayType arrayType = (AtlasArrayType) attrType;
            arrayType.setMinCount(attributeDef.getValuesMinCount());
            arrayType.setMaxCount(attributeDef.getValuesMaxCount());
        }
        a.put(attributeDef.getName(), attribute);
    }
    resolveConstraints(typeRegistry);
    this.allAttributes = Collections.unmodifiableMap(a);
    this.uniqAttributes = getUniqueAttributes(this.allAttributes);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Cardinality(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality) HashMap(java.util.HashMap) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)

Aggregations

AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)52 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)19 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)17 HashMap (java.util.HashMap)14 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)13 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 ArrayList (java.util.ArrayList)11 Test (org.testng.annotations.Test)10 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)9 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)8 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)7 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)5 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)4 Map (java.util.Map)3 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)3 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)2 ClassType (org.apache.atlas.typesystem.types.ClassType)2