Java Code Examples for org.apache.atlas.type.AtlasStructType#getAttribute()

The following examples show how to use org.apache.atlas.type.AtlasStructType#getAttribute() . 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: 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 2
Source File: RestUtilsTest.java    From 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 {
    AtlasTypeDefGraphStoreV2 typeDefStore = makeTypeStore(registry);
    AtlasStructType          structType   = (AtlasStructType) registry.getType(structDef.getName());
    AtlasAttribute           attribute    = structType.getAttribute(attributeDef.getName());
    String                   attribJson   = AtlasStructDefStoreV2.toJsonFromAttribute(attribute);
    Map                      attrInfo     = AtlasType.fromJson(attribJson, Map.class);

    Assert.assertEquals(attrInfo.get("isComposite"), compositeExpected);

    return AtlasStructDefStoreV2.toAttributeDefFromJson(structDef, attrInfo, typeDefStore);
}
 
Example 3
Source File: FullTextMapperV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void mapAttributes(AtlasStructType structType, Map<String, Object> attributes, AtlasEntityExtInfo entityExtInfo, StringBuilder sb,
                           Set<String> processedGuids, Set<String> excludeAttributes, boolean isClassificationOnly) throws AtlasBaseException {
    if (MapUtils.isEmpty(attributes)) {
        return;
    }

    for (Map.Entry<String, Object> attributeEntry : attributes.entrySet()) {
        String attribKey = attributeEntry.getKey();
        Object attrValue = attributeEntry.getValue();

        if (attrValue == null || excludeAttributes.contains(attribKey)) {
            continue;
        }

        if (!followReferences) {
            AtlasAttribute attribute     = structType != null ? structType.getAttribute(attribKey) : null;
            AtlasType      attributeType = attribute != null ? attribute.getAttributeType() : null;

            if (attributeType == null) {
                continue;
            }

            if (attributeType instanceof AtlasArrayType) {
                attributeType = ((AtlasArrayType) attributeType).getElementType();
            }

            if (attributeType instanceof AtlasEntityType || attributeType instanceof AtlasBuiltInTypes.AtlasObjectIdType) {
                continue;
            }
        }


        sb.append(attribKey).append(FULL_TEXT_DELIMITER);

        mapAttribute(attrValue, entityExtInfo, sb, processedGuids, isClassificationOnly);
    }
}
 
Example 4
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 5
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 6
Source File: AtlasStructFormatConverter.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
protected Map<String, Object> fromV1ToV2(AtlasStructType structType, Map attributes, ConverterContext context) throws AtlasBaseException {
    Map<String, Object> ret = null;

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

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

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

            AtlasType attrType = attr.getAttributeType();

            AtlasFormatConverter attrConverter = converterRegistry.getConverter(attrType.getTypeCategory());
            Object               v1Value       = attributes.get(attr.getName());
            Object               v2Value       = attrConverter.fromV1ToV2(v1Value, attrType, context);

            ret.put(attr.getAttributeDef().getName(), v2Value);
        }
    }

    return ret;
}
 
Example 7
Source File: TypeConverterUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private static AttributeDefinition[] getAttributes(AtlasStructType structType, AtlasTypeRegistry registry) throws AtlasBaseException {
    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());

            ret.add(AtlasStructDefStoreV1.toAttributeDefintion(attribute));
        }
    }

    return ret.toArray(new AttributeDefinition[ret.size()]);
}
 
Example 8
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());
}