org.apache.atlas.type.AtlasStructType Java Examples

The following examples show how to use org.apache.atlas.type.AtlasStructType. 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: AtlasEntityTestBase.java    From atlas with Apache License 2.0 6 votes vote down vote up
protected void validateEntity(AtlasEntityExtInfo entityExtInfo, AtlasStruct actual, AtlasStruct expected) throws AtlasBaseException, AtlasException {
    if (expected == null) {
        Assert.assertNull(actual, "expected null instance. Found " + actual);

        return;
    }

    Assert.assertNotNull(actual, "found null instance");

    AtlasStructType entityType = (AtlasStructType) typeRegistry.getType(actual.getTypeName());
    for (String attrName : expected.getAttributes().keySet()) {
        Object expectedVal = expected.getAttribute(attrName);
        Object actualVal   = actual.getAttribute(attrName);

        AtlasType attrType = entityType.getAttributeType(attrName);
        validateAttribute(entityExtInfo, actualVal, expectedVal, attrType, attrName);
    }
}
 
Example #2
Source File: DeleteHandlerV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
protected void deleteEdge(AtlasEdge edge, boolean updateInverseAttribute, boolean force) throws AtlasBaseException {
    //update inverse attribute
    if (updateInverseAttribute) {
        AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(edge.getLabel());

        AtlasType parentType = typeRegistry.getType(atlasEdgeLabel.getTypeName());

        if (parentType instanceof AtlasEntityType) {
            AtlasEntityType parentEntityType = (AtlasEntityType) parentType;

            AtlasStructType.AtlasAttribute attribute = parentEntityType.getAttribute(atlasEdgeLabel.getAttributeName());
            if (attribute.getInverseRefAttribute() != null) {
                deleteEdgeBetweenVertices(edge.getInVertex(), edge.getOutVertex(), attribute.getInverseRefAttribute());
            }
        }
    }

    deleteEdge(edge, force);
}
 
Example #3
Source File: SearchContext.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void validateAttributes(final AtlasStructType structType, final String... attributeNames) throws AtlasBaseException {
    for (String attributeName : attributeNames) {
        if (StringUtils.isNotEmpty(attributeName) && (structType == null || structType.getAttributeType(attributeName) == null)) {
            if (structType == null) {
                throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, "NULL");
            }

            String name = structType.getTypeName();
            if (name.equals(MATCH_ALL_ENTITY_TYPES.getTypeName())) {
                name = ALL_ENTITY_TYPES;
            } else if (name.equals(MATCH_ALL_CLASSIFICATION_TYPES.getTypeName())) {
                name = ALL_CLASSIFICATION_TYPES;
            }
            throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attributeName, name);
        }
    }
}
 
Example #4
Source File: AtlasEntityStoreV1Test.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void validateEntity(AtlasEntityExtInfo entityExtInfo, AtlasStruct actual, AtlasStruct expected) throws AtlasBaseException, AtlasException {
    if (expected == null) {
        Assert.assertNull(actual, "expected null instance. Found " + actual);

        return;
    }

    Assert.assertNotNull(actual, "found null instance");

    AtlasStructType entityType = (AtlasStructType) typeRegistry.getType(actual.getTypeName());
    for (String attrName : expected.getAttributes().keySet()) {
        Object expectedVal = expected.getAttribute(attrName);
        Object actualVal   = actual.getAttribute(attrName);

        AtlasType attrType = entityType.getAttributeType(attrName);
        validateAttribute(entityExtInfo, actualVal, expectedVal, attrType, attrName);
    }
}
 
Example #5
Source File: RangerAtlasEntityWithTags.java    From ranger with Apache License 2.0 6 votes vote down vote up
public String getTagAttributeType(String tagTypeName, String tagAttributeName) {
    String ret = DEFAULT_TAG_ATTRIBUTE_TYPE;

    if (typeRegistry != null) {
        AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(tagTypeName);
        if (classificationType != null) {
            AtlasStructType.AtlasAttribute atlasAttribute = classificationType.getAttribute(tagAttributeName);

            if (atlasAttribute != null) {
                ret = atlasAttribute.getTypeName();
            }
        }
    }

    return ret;
}
 
Example #6
Source File: AtlasStructDefStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static void updateVertexPreCreate(AtlasStructDef structDef, AtlasStructType structType,
                                         AtlasVertex vertex, AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException {
    List<String> attrNames = new ArrayList<>(structDef.getAttributeDefs().size());

    for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
        // Validate the mandatory features of an attribute (compatibility with legacy type system)
        if (StringUtils.isEmpty(attributeDef.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, structDef.getName(), "name");
        }
        if (StringUtils.isEmpty(attributeDef.getTypeName())) {
            throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, structDef.getName(), "typeName");
        }

        String propertyKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(structDef, attributeDef.getName());

        AtlasGraphUtilsV1.setProperty(vertex, propertyKey, toJsonFromAttribute(structType.getAttribute(attributeDef.getName())));

        attrNames.add(attributeDef.getName());
    }
    AtlasGraphUtilsV1.setProperty(vertex, AtlasGraphUtilsV1.getTypeDefPropertyKey(structDef), attrNames);
}
 
Example #7
Source File: AtlasEntityGraphDiscoveryV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
void visitStruct(AtlasStructType structType, Object val) throws AtlasBaseException {
    if (structType == null || val == null) {
        return;
    }

    final AtlasStruct struct;

    if (val instanceof AtlasStruct) {
        struct = (AtlasStruct) val;
    } else if (val instanceof Map) {
        Map attributes = AtlasTypeUtil.toStructAttributes((Map) val);

        struct = new AtlasStruct(structType.getTypeName(), attributes);
    } else {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_STRUCT_VALUE, val.toString());
    }

    visitStruct(structType, struct);
}
 
Example #8
Source File: EntityGraphMapper.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private AtlasEdge createInverseReference(AtlasAttribute inverseAttribute, AtlasStructType inverseAttributeType,
                                         AtlasVertex inverseVertex, AtlasVertex vertex) throws AtlasBaseException {

    String propertyName     = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(inverseAttributeType, inverseAttribute.getName());
    String inverseEdgeLabel = AtlasGraphUtilsV1.getEdgeLabel(propertyName);
    AtlasEdge ret;

    try {
        ret = graphHelper.getOrCreateEdge(inverseVertex, vertex, inverseEdgeLabel);

    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }

    return ret;
}
 
Example #9
Source File: TypeConverterUtil.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static TypesDef toTypesDef(AtlasType type, AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
    final TypesDef ret;

    if (type instanceof AtlasEnumType) {
        ret = TypeConverterUtil.enumToTypesDef((AtlasEnumType) type);
    } else if (type instanceof AtlasEntityType) {
        ret = TypeConverterUtil.entityToTypesDef((AtlasEntityType) type, typeRegistry);
    } else if (type instanceof AtlasClassificationType) {
        ret = TypeConverterUtil.classificationToTypesDef((AtlasClassificationType) type, typeRegistry);
    } else if (type instanceof AtlasStructType) {
        ret = TypeConverterUtil.structToTypesDef((AtlasStructType) type, typeRegistry);
    } else {
        ret = new TypesDef();
    }

    return ret;
}
 
Example #10
Source File: TypeConverterUtil.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static List<AttributeDefinition> getAttributes(AtlasStructType structType, AtlasTypeRegistry registry) {
    List<AttributeDefinition> ret      = new ArrayList<>();
    List<AtlasAttributeDef>   attrDefs = structType.getStructDef().getAttributeDefs();

    if (CollectionUtils.isNotEmpty(attrDefs)) {
        for (AtlasAttributeDef attrDef : attrDefs) {
            AtlasAttribute attribute = structType.getAttribute(attrDef.getName());

            AttributeDefinition oldAttrDef = AtlasStructDefStoreV2.toAttributeDefinition(attribute);

            ret.add(new AttributeDefinition(oldAttrDef.getName(),
                                            oldAttrDef.getDataTypeName(),
                                            new Multiplicity(oldAttrDef.getMultiplicity()),
                                            oldAttrDef.getIsComposite(),
                                            oldAttrDef.getIsUnique(),
                                            oldAttrDef.getIsIndexable(),
                                            oldAttrDef.getReverseAttributeName(),
                                            oldAttrDef.getOptions(),
                                            oldAttrDef.getSearchWeight(),
                                            oldAttrDef.getIndexType()));
        }
    }

    return ret;
}
 
Example #11
Source File: EntityGraphMapper.java    From atlas with Apache License 2.0 6 votes vote down vote up
private AtlasEdge createInverseReference(AtlasAttribute inverseAttribute, AtlasStructType inverseAttributeType,
                                         AtlasVertex inverseVertex, AtlasVertex vertex) throws AtlasBaseException {

    String propertyName     = AtlasGraphUtilsV2.getQualifiedAttributePropertyKey(inverseAttributeType, inverseAttribute.getName());
    String inverseEdgeLabel = AtlasGraphUtilsV2.getEdgeLabel(propertyName);
    AtlasEdge ret;

    try {
        ret = graphHelper.getOrCreateEdge(inverseVertex, vertex, inverseEdgeLabel);

    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }

    return ret;
}
 
Example #12
Source File: TypeConverterUtil.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static TypesDef toTypesDef(AtlasType type, AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
    final TypesDef ret;

    if (type instanceof AtlasEnumType) {
        ret = TypeConverterUtil.enumToTypesDef((AtlasEnumType) type);
    } else if (type instanceof AtlasEntityType) {
        ret = TypeConverterUtil.entityToTypesDef((AtlasEntityType) type, typeRegistry);
    } else if (type instanceof AtlasClassificationType) {
        ret = TypeConverterUtil.classificationToTypesDef((AtlasClassificationType) type, typeRegistry);
    } else if (type instanceof AtlasStructType) {
        ret = TypeConverterUtil.structToTypesDef((AtlasStructType) type, typeRegistry);
    } else {
        ret = new TypesDef();
    }

    return ret;
}
 
Example #13
Source File: AtlasEntityGraphDiscoveryV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
void visitStruct(AtlasStructType structType, Object val) throws AtlasBaseException {
    if (structType == null || val == null) {
        return;
    }

    final AtlasStruct struct;

    if (val instanceof AtlasStruct) {
        struct = (AtlasStruct) val;
    } else if (val instanceof Map) {
        Map attributes = AtlasTypeUtil.toStructAttributes((Map) val);

        struct = new AtlasStruct(structType.getTypeName(), attributes);
    } else {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_STRUCT_VALUE, val.toString());
    }

    visitStruct(structType, struct);
}
 
Example #14
Source File: ExportService.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void addType(AtlasType type, ExportContext context) {
    if (type.getTypeCategory() == TypeCategory.PRIMITIVE) {
        return;
    }

    if (type instanceof AtlasArrayType) {
        AtlasArrayType arrayType = (AtlasArrayType)type;

        addType(arrayType.getElementType(), context);
    } else if (type instanceof AtlasMapType) {
        AtlasMapType mapType = (AtlasMapType)type;

        addType(mapType.getKeyType(), context);
        addType(mapType.getValueType(), context);
    } else if (type instanceof AtlasEntityType) {
        addEntityType((AtlasEntityType)type, context);
    } else if (type instanceof AtlasClassificationType) {
        addClassificationType((AtlasClassificationType)type, context);
    } else if (type instanceof AtlasStructType) {
        addStructType((AtlasStructType)type, context);
    } else if (type instanceof AtlasEnumType) {
        addEnumType((AtlasEnumType)type, context);
    }
}
 
Example #15
Source File: AtlasGraphUtilsV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public static String getQualifiedAttributePropertyKey(AtlasStructType fromType, String attributeName) throws AtlasBaseException {
    switch (fromType.getTypeCategory()) {
     case ENTITY:
     case STRUCT:
     case CLASSIFICATION:
         return fromType.getQualifiedAttributeName(attributeName);
    default:
        throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, fromType.getTypeCategory().name());
    }
}
 
Example #16
Source File: DeleteHandlerV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
protected AtlasAttribute getAttributeForEdge(String edgeLabel) throws AtlasBaseException {
    AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(edgeLabel);

    AtlasType parentType = typeRegistry.getType(atlasEdgeLabel.getTypeName());
    AtlasStructType parentStructType = (AtlasStructType) parentType;

    return parentStructType.getAttribute(atlasEdgeLabel.getAttributeName());
}
 
Example #17
Source File: TypesWithCollectionsFinder.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static void addVertexPropertiesForCollectionAttributes(Collection<? extends AtlasStructType> types, Map<String, Map<String, List<String>>> typeAttrMap) {
    for (AtlasStructType type : types) {
        Map<String, List<String>> collectionProperties = getVertexPropertiesForCollectionAttributes(type);

        if(collectionProperties != null && collectionProperties.size() > 0) {
            typeAttrMap.put(type.getTypeName(), collectionProperties);
        }
    }
}
 
Example #18
Source File: AtlasStructDefStoreV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public AtlasStructDef updateByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasStructDefStoreV1.updateByGuid({})", guid);
    }

    validateType(structDef);

    AtlasType type = typeRegistry.getTypeByGuid(guid);

    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.STRUCT) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name());
    }

    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);

    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }

    AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType)type, vertex, typeDefStore);
    AtlasStructDefStoreV1.updateVertexAddReferences(structDef, vertex, typeDefStore);

    AtlasStructDef ret = toStructDef(vertex);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasStructDefStoreV1.updateByGuid({}): {}", guid, ret);
    }

    return ret;
}
 
Example #19
Source File: AtlasStructFormatConverter.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
protected Map<String, Object> fromV2ToV1(AtlasStructType structType, Map<String, Object> attributes, ConverterContext context) throws AtlasBaseException {
    Map<String, Object> ret = null;

    if (MapUtils.isNotEmpty(attributes)) {
        ret = new HashMap<>();

        // Only process the requested/set attributes
        for (String attrName : attributes.keySet()) {
            AtlasAttribute attr = structType.getAttribute(attrName);

            if (attr == null) {
                LOG.warn("ignored unknown attribute {}.{}", structType.getTypeName(), attrName);
                continue;
            }

            AtlasType attrType = attr.getAttributeType();

            Object v2Value = attributes.get(attr.getName());
            Object v1Value;

            AtlasFormatConverter attrConverter = converterRegistry.getConverter(attrType.getTypeCategory());
            v1Value = attrConverter.fromV2ToV1(v2Value, attrType, context);
            ret.put(attr.getName(), v1Value);
        }
    }

    return ret;
}
 
Example #20
Source File: ExportService.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void addStructType(AtlasStructType structType, ExportContext context) {
    if (!context.structTypes.contains(structType.getTypeName())) {
        context.structTypes.add(structType.getTypeName());

        addAttributeTypes(structType, context);
    }
}
 
Example #21
Source File: ModelTestUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public static AtlasStruct newStruct(AtlasStructDef structDef, AtlasTypeRegistry typesRegistry) {
    AtlasStruct ret = null;

    AtlasStructType structType = typesRegistry.getStructTypeByName(structDef.getName());

    if (structType != null) {
        ret = structType.createDefaultValue();
    } else {
        LOG.error("failed to get struct-type {}", structDef.getName());
    }

    return ret;
}
 
Example #22
Source File: SearchProcessor.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private String toSolrExpression(AtlasStructType type, String attrName, SearchParameters.Operator op, String attrVal) {
    String ret = EMPTY_STRING;

    try {
        if (OPERATOR_MAP.get(op) != null) {
            String qualifiedName = type.getQualifiedAttributeName(attrName);

            ret = String.format(OPERATOR_MAP.get(op), qualifiedName, AtlasStructType.AtlasAttribute.escapeIndexQueryValue(attrVal));
        }
    } catch (AtlasBaseException ex) {
        LOG.warn(ex.getMessage());
    }

    return ret;
}
 
Example #23
Source File: SearchProcessor.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private String toSolrQuery(AtlasStructType type, FilterCriteria criteria, Set<String> solrAttributes, StringBuilder sb, int level) {
    if (criteria.getCondition() != null && CollectionUtils.isNotEmpty(criteria.getCriterion())) {
        StringBuilder nestedExpression = new StringBuilder();

        for (FilterCriteria filterCriteria : criteria.getCriterion()) {
            String nestedQuery = toSolrQuery(type, filterCriteria, solrAttributes, level + 1);

            if (StringUtils.isNotEmpty(nestedQuery)) {
                if (nestedExpression.length() > 0) {
                    nestedExpression.append(SPACE_STRING).append(criteria.getCondition()).append(SPACE_STRING);
                }
                // todo: when a neq operation is nested and occurs in the beginning of the query, solr has issues
                nestedExpression.append(nestedQuery);
            }
        }

        if (level == 0) {
            return nestedExpression.length() > 0 ? sb.append(nestedExpression).toString() : EMPTY_STRING;
        } else {
            return nestedExpression.length() > 0 ? sb.append(BRACE_OPEN_STR).append(nestedExpression).append(BRACE_CLOSE_STR).toString() : EMPTY_STRING;
        }
    } else if (solrAttributes.contains(criteria.getAttributeName())){
        return toSolrExpression(type, criteria.getAttributeName(), criteria.getOperator(), criteria.getAttributeValue());
    } else {
        return EMPTY_STRING;
    }
}
 
Example #24
Source File: SearchProcessor.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
protected void constructFilterQuery(StringBuilder solrQuery, AtlasStructType type, FilterCriteria filterCriteria, Set<String> solrAttributes) {
    if (filterCriteria != null) {
        LOG.debug("Processing Filters");

        String filterQuery = toSolrQuery(type, filterCriteria, solrAttributes, 0);

        if (StringUtils.isNotEmpty(filterQuery)) {
            if (solrQuery.length() > 0) {
                solrQuery.append(AND_STR);
            }

            solrQuery.append(filterQuery);
        }
    }
}
 
Example #25
Source File: SearchProcessor.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
protected boolean canApplySolrFilter(AtlasStructType structType, FilterCriteria filterCriteria, boolean insideOrCondition) {
    if (filterCriteria == null) {
        return true;
    }

    boolean              ret             = true;
    Condition            filterCondition = filterCriteria.getCondition();
    List<FilterCriteria> criterion       = filterCriteria.getCriterion();
    Set<String>          indexedKeys     = context.getIndexedKeys();


    if (filterCondition != null && CollectionUtils.isNotEmpty(criterion)) {
        insideOrCondition = insideOrCondition || filterCondition == Condition.OR;

        // If we have nested criterion let's find any nested ORs with non-indexed attr
        for (FilterCriteria criteria : criterion) {
            ret = canApplySolrFilter(structType, criteria, insideOrCondition);

            if (!ret) {
                break;
            }
        }
    } else if (StringUtils.isNotEmpty(filterCriteria.getAttributeName())) {
        try {
            String qualifiedName = structType.getQualifiedAttributeName(filterCriteria.getAttributeName());

            if (insideOrCondition && (indexedKeys == null || !indexedKeys.contains(qualifiedName))) {
                ret = false;
            }
        } catch (AtlasBaseException e) {
            LOG.warn(e.getMessage());
        }
    }

    return ret;
}
 
Example #26
Source File: SearchProcessor.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
protected void processSearchAttributes(AtlasStructType structType, FilterCriteria filterCriteria, Set<String> solrFiltered, Set<String> gremlinFiltered, Set<String> allAttributes) {
    if (structType == null || filterCriteria == null) {
        return;
    }

    Condition            filterCondition = filterCriteria.getCondition();
    List<FilterCriteria> criterion       = filterCriteria.getCriterion();

    if (filterCondition != null && CollectionUtils.isNotEmpty(criterion)) {
        for (SearchParameters.FilterCriteria criteria : criterion) {
            processSearchAttributes(structType, criteria, solrFiltered, gremlinFiltered, allAttributes);
        }
    } else if (StringUtils.isNotEmpty(filterCriteria.getAttributeName())) {
        try {
            String      attributeName = filterCriteria.getAttributeName();
            String      qualifiedName = structType.getQualifiedAttributeName(attributeName);
            Set<String> indexedKeys   = context.getIndexedKeys();

            if (indexedKeys != null && indexedKeys.contains(qualifiedName)) {
                solrFiltered.add(attributeName);
            } else {
                LOG.warn("search includes non-indexed attribute '{}'; might cause poor performance", qualifiedName);

                gremlinFiltered.add(attributeName);
            }

            if (structType instanceof AtlasEntityType) {
                // Capture the entity attributes
                context.getEntityAttributes().add(attributeName);
            }

            allAttributes.add(attributeName);
        } catch (AtlasBaseException e) {
            LOG.warn(e.getMessage());
        }
    }
}
 
Example #27
Source File: RestUtilsTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasAttributeDef convertToJsonAndBack(AtlasTypeRegistry registry, AtlasStructDef structDef,
        AtlasAttributeDef attributeDef, boolean compositeExpected) throws AtlasBaseException {

    AtlasTypeDefGraphStoreV1 typeDefStore = makeTypeStore(registry);
    AtlasStructType structType = (AtlasStructType) registry.getType(structDef.getName());
    AtlasAttribute attribute = structType.getAttribute(attributeDef.getName());
    String attribJson = AtlasStructDefStoreV1.toJsonFromAttribute(attribute);

    Map attrInfo = AtlasType.fromJson(attribJson, Map.class);
    Assert.assertEquals(attrInfo.get("isComposite"), compositeExpected);
    return AtlasStructDefStoreV1.toAttributeDefFromJson(structDef, attrInfo, typeDefStore);
}
 
Example #28
Source File: ModelTestUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static AtlasStruct newStruct(AtlasStructDef structDef, AtlasTypeRegistry typesRegistry) {
    AtlasStruct ret = null;

    AtlasStructType structType = typesRegistry.getStructTypeByName(structDef.getName());

    if (structType != null) {
        ret = structType.createDefaultValue();
    } else {
        LOG.error("failed to get struct-type {}", structDef.getName());
    }

    return ret;
}
 
Example #29
Source File: AtlasEntityGraphDiscoveryV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
void visitAttribute(AtlasType attrType, Object val) throws AtlasBaseException {
    if (attrType == null || val == null) {
        return;
    }

    switch (attrType.getTypeCategory()) {
        case PRIMITIVE:
        case ENUM:
            return;

        case ARRAY: {
            AtlasArrayType arrayType = (AtlasArrayType) attrType;
            AtlasType      elemType  = arrayType.getElementType();

            visitCollectionReferences(elemType, val);
        }
        break;

        case MAP: {
            AtlasType keyType   = ((AtlasMapType) attrType).getKeyType();
            AtlasType valueType = ((AtlasMapType) attrType).getValueType();

            visitMapReferences(keyType, valueType, val);
        }
        break;

        case STRUCT:
            visitStruct((AtlasStructType)attrType, val);
        break;

        case OBJECT_ID_TYPE:
            visitReference((AtlasObjectIdType) attrType,  val);
        break;

        default:
            throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, attrType.getTypeCategory().name());
    }
}
 
Example #30
Source File: EntityGraphMapper.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasStructType getStructType(String typeName) throws AtlasBaseException {
    AtlasType objType = typeRegistry.getType(typeName);

    if (!(objType instanceof AtlasStructType)) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, typeName);
    }

    return (AtlasStructType)objType;
}