Java Code Examples for org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef#getName()

The following examples show how to use org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasStructDefStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static void addReferencesForAttribute(AtlasVertex vertex, AtlasAttributeDef attributeDef,
                                              AtlasTypeDefGraphStoreV2 typeDefStore) throws AtlasBaseException {
    Set<String> referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName());

    String typeName = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);

    for (String referencedTypeName : referencedTypeNames) {
        if (!AtlasTypeUtil.isBuiltInType(referencedTypeName)) {
            AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName);

            if (referencedTypeVertex == null) {
                throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, referencedTypeName, typeName, attributeDef.getName());
            }

            String label = AtlasGraphUtilsV2.getEdgeLabel(typeName, attributeDef.getName());

            typeDefStore.getOrCreateEdge(vertex, referencedTypeVertex, label);
        }
    }
}
 
Example 2
Source File: AtlasStructDefStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private static void addReferencesForAttribute(AtlasVertex vertex, AtlasAttributeDef attributeDef,
                                              AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException {
    Set<String> referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName());

    String typeName = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);

    for (String referencedTypeName : referencedTypeNames) {
        if (!AtlasTypeUtil.isBuiltInType(referencedTypeName)) {
            AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName);

            if (referencedTypeVertex == null) {
                throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, referencedTypeName, typeName, attributeDef.getName());
            }

            String label = AtlasGraphUtilsV1.getEdgeLabel(typeName, attributeDef.getName());

            typeDefStore.getOrCreateEdge(vertex, referencedTypeVertex, label);
        }
    }
}
 
Example 3
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 4
Source File: AtlasTypeDefStoreInitializer.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void addOrUpdateAttributes(AtlasStructDef structDef, List<AtlasAttributeDef> attributesToUpdate) {
    for (AtlasAttributeDef attributeToUpdate : attributesToUpdate) {
        String attrName = attributeToUpdate.getName();

        if (structDef.hasAttribute(attrName)) {
            structDef.removeAttribute(attrName);
        }

        structDef.addAttribute(attributeToUpdate);
    }
}
 
Example 5
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValues(Map<String, Object> obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();

            if (obj.containsKey(attributeName)) {
                Object attributeValue = getNormalizedValue(obj.get(attributeName), attributeDef);

                obj.put(attributeName, attributeValue);
            } else if (!attributeDef.getIsOptional()) {
                obj.put(attributeName, createDefaultValue(attributeDef));
            }
        }
    }
}
 
Example 6
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 7
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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));
            }
        }
    }
}
 
Example 8
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: AtlasEntityType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void resolveReferencesPhase3(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
    for (AtlasAttributeDef attributeDef : getStructDef().getAttributeDefs()) {
        String          attributeName       = attributeDef.getName();
        AtlasType       attributeType       = typeRegistry.getType(attributeDef.getTypeName());
        AtlasEntityType attributeEntityType = getReferencedEntityType(attributeType);

        // validate if RelationshipDefs is defined for all entityDefs
        if (attributeEntityType != null && !hasRelationshipAttribute(attributeName)) {
            LOG.warn("No RelationshipDef defined between {} and {} on attribute: {}.{}", getTypeName(),
                      attributeEntityType.getTypeName(), getTypeName(), attributeName);
        }
    }

    for (String superTypeName : allSuperTypes) {
        AtlasEntityType superType = typeRegistry.getEntityTypeByName(superTypeName);

        Map<String, AtlasAttribute> superTypeRelationshipAttributes = superType.getRelationshipAttributes();

        if (MapUtils.isNotEmpty(superTypeRelationshipAttributes)) {
            relationshipAttributes.putAll(superTypeRelationshipAttributes);
        }

        Map<String, List<AtlasRelationshipType>> superTypeRelationshipAttributesType = superType.getRelationshipAttributesType();

        if (MapUtils.isNotEmpty(superTypeRelationshipAttributesType)) {
            relationshipAttributesType.putAll(superTypeRelationshipAttributesType);
        }
    }

    allSubTypes                = Collections.unmodifiableSet(allSubTypes);
    typeAndAllSubTypes         = Collections.unmodifiableSet(typeAndAllSubTypes);
    typeAndAllSubTypesQryStr   = ""; // will be computed on next access
    relationshipAttributes     = Collections.unmodifiableMap(relationshipAttributes);
    relationshipAttributesType = Collections.unmodifiableMap(relationshipAttributesType);
}
 
Example 10
Source File: AtlasTypeDefStoreInitializer.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void addOrUpdateAttributes(AtlasStructDef structDef, List<AtlasAttributeDef> attributesToUpdate) {
    for (AtlasAttributeDef attributeToUpdate : attributesToUpdate) {
        String attrName = attributeToUpdate.getName();

        if (structDef.hasAttribute(attrName)) {
            structDef.removeAttribute(attrName);
        }

        structDef.addAttribute(attributeToUpdate);
    }
}
 
Example 11
Source File: AtlasStructType.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static String generateVertexPropertyName(AtlasStructDef structDef, AtlasAttributeDef attrDef, String qualifiedName) {
    String vertexPropertyName = qualifiedName;
    String attrName           = attrDef.getName();
    if (isRootType(structDef)) {
        return attrName;
    } else {
        if(!attrDef.getName().contains(".") &&
            AtlasAttributeDef.IndexType.STRING.equals(attrDef.getIndexType()) &&
            ATLAS_TYPE_STRING.equalsIgnoreCase(attrDef.getTypeName())) {
            vertexPropertyName = String.format("%s.%s%s", structDef.getName(), VERTEX_PROPERTY_PREFIX_STRING_INDEX_TYPE, attrDef.getName());
        }
    }
    return encodePropertyKey(vertexPropertyName);
}
 
Example 12
Source File: AtlasStructType.java    From atlas with Apache License 2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 13
Source File: AtlasStructType.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValues(Map<String, Object> obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();

            if (obj.containsKey(attributeName)) {
                Object attributeValue = getNormalizedValue(obj.get(attributeName), attributeDef);

                obj.put(attributeName, attributeValue);
            } else if (!attributeDef.getIsOptional()) {
                obj.put(attributeName, createDefaultValue(attributeDef));
            }
        }
    }
}
 
Example 14
Source File: AtlasStructType.java    From atlas with Apache License 2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 15
Source File: AtlasStructType.java    From atlas with Apache License 2.0 5 votes vote down vote up
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));
            }
        }
    }
}
 
Example 16
Source File: AtlasBusinessMetadataType.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
    super.resolveReferences(typeRegistry);

    Map<String, AtlasBusinessAttribute> a = new HashMap<>();

    for (AtlasAttribute attribute : super.allAttributes.values()) {
        AtlasAttributeDef attributeDef = attribute.getAttributeDef();
        String            attrName     = attribute.getName();
        AtlasType         attrType     = attribute.getAttributeType();

        if (attrType instanceof AtlasArrayType) {
            attrType = ((AtlasArrayType) attrType).getElementType();
        } else if (attrType instanceof AtlasMapType) {
            attrType = ((AtlasMapType) attrType).getValueType();
        }

        // check if attribute type is not struct/classification/entity/business-metadata
        if (attrType instanceof AtlasStructType) {
            throw new AtlasBaseException(AtlasErrorCode.BUSINESS_METADATA_DEF_ATTRIBUTE_TYPE_INVALID, getTypeName(), attrName);
        }

        Set<String>          entityTypeNames = attribute.getOptionSet(ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
        Set<AtlasEntityType> entityTypes     = new HashSet<>();

        if (CollectionUtils.isNotEmpty(entityTypeNames)) {
            for (String entityTypeName : entityTypeNames) {
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);

                if (entityType == null) {
                    throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, entityTypeName);
                }

                entityTypes.add(entityType);
            }
        }

        AtlasBusinessAttribute bmAttribute;
        if (attrType instanceof AtlasBuiltInTypes.AtlasStringType) {
            Integer maxStringLength = attribute.getOptionInt(ATTR_MAX_STRING_LENGTH);
            if (maxStringLength == null) {
                throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, attributeDef.getName(), "options." + ATTR_MAX_STRING_LENGTH);
            }

            String validPattern = attribute.getOptionString(ATTR_VALID_PATTERN);
            bmAttribute = new AtlasBusinessAttribute(attribute, entityTypes, maxStringLength, validPattern);
        } else {
            bmAttribute = new AtlasBusinessAttribute(attribute, entityTypes);
        }

        a.put(attrName, bmAttribute);
    }

    super.allAttributes = Collections.unmodifiableMap(a);
}
 
Example 17
Source File: AtlasStructType.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
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());
            arrayType.setCardinality(cardinality);
        }

        //check if attribute type is not classification
        if (attrType instanceof AtlasArrayType) {
            attrType = ((AtlasArrayType) attrType).getElementType();
        } else if (attrType instanceof AtlasMapType) {
            attrType = ((AtlasMapType) attrType).getValueType();
        }

        if (attrType instanceof AtlasClassificationType) {
            throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_TYPE_INVALID, getTypeName(), attributeDef.getName());
        }

        if (attrType instanceof AtlasBusinessMetadataType) {
            throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_TYPE_INVALID, getTypeName(), attributeDef.getName());
        }

        a.put(attributeDef.getName(), attribute);
    }

    resolveConstraints(typeRegistry);

    this.allAttributes  = Collections.unmodifiableMap(a);
    this.uniqAttributes = getUniqueAttributes(this.allAttributes);
}