use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class AtlasArrayFormatConverter method fromV2ToV1.
@Override
public Collection fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
Collection ret = null;
if (v2Obj != null) {
if (v2Obj instanceof List) {
ret = new ArrayList();
} else if (v2Obj instanceof Set) {
ret = new LinkedHashSet();
} else {
throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "List or Set", v2Obj.getClass().getCanonicalName());
}
AtlasArrayType arrType = (AtlasArrayType) type;
AtlasType elemType = arrType.getElementType();
AtlasFormatConverter elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
Collection v2List = (Collection) v2Obj;
for (Object v2Elem : v2List) {
Object convertedVal = elemConverter.fromV2ToV1(v2Elem, elemType, ctx);
ret.add(convertedVal);
}
}
return ret;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class AtlasEntityFormatConverter method fromV1ToV2.
@Override
public AtlasEntity fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext context) throws AtlasBaseException {
AtlasEntity entity = null;
if (v1Obj != null) {
AtlasEntityType entityType = (AtlasEntityType) type;
if (v1Obj instanceof Referenceable) {
Referenceable entRef = (Referenceable) v1Obj;
String guid = entRef.getId().getId();
if (!context.entityExists(guid)) {
entity = new AtlasEntity(entRef.getTypeName(), super.fromV1ToV2(entityType, entRef.getValues(), context));
entity.setGuid(entRef.getId().getId());
entity.setStatus(convertState(entRef.getId().getState()));
if (entRef.getSystemAttributes() != null) {
entity.setCreatedBy(entRef.getSystemAttributes().getCreatedBy());
entity.setCreateTime(entRef.getSystemAttributes().getCreatedTime());
entity.setUpdatedBy(entRef.getSystemAttributes().getModifiedBy());
entity.setUpdateTime(entRef.getSystemAttributes().getModifiedTime());
}
entity.setVersion((long) entRef.getId().getVersion());
if (CollectionUtils.isNotEmpty(entRef.getTraitNames())) {
List<AtlasClassification> classifications = new ArrayList<>();
AtlasFormatConverter traitConverter = converterRegistry.getConverter(TypeCategory.CLASSIFICATION);
for (String traitName : entRef.getTraitNames()) {
Struct trait = entRef.getTraits().get(traitName);
AtlasType classifiType = typeRegistry.getType(traitName);
AtlasClassification classification = (AtlasClassification) traitConverter.fromV1ToV2(trait, classifiType, context);
classifications.add(classification);
}
entity.setClassifications(classifications);
}
}
} else {
throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Referenceable", v1Obj.getClass().getCanonicalName());
}
}
return entity;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class AtlasInstanceConverter method getTrait.
public Struct getTrait(AtlasClassification classification) throws AtlasBaseException {
AtlasFormatConverter converter = instanceFormatters.getConverter(TypeCategory.CLASSIFICATION);
AtlasType classificationType = typeRegistry.getType(classification.getTypeName());
Struct trait = (Struct) converter.fromV2ToV1(classification, classificationType, new ConverterContext());
return trait;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class GraphBackedSearchIndexer method createIndexForAttribute.
private void createIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) {
final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + attributeDef.getName());
AtlasCardinality cardinality = toAtlasCardinality(attributeDef.getCardinality());
boolean isUnique = attributeDef.getIsUnique();
boolean isIndexable = attributeDef.getIsIndexable();
String attribTypeName = attributeDef.getTypeName();
boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName);
boolean isArrayType = AtlasTypeUtil.isArrayType(attribTypeName);
boolean isMapType = AtlasTypeUtil.isMapType(attribTypeName);
try {
AtlasType atlasType = typeRegistry.getType(typeName);
AtlasType attributeType = typeRegistry.getType(attribTypeName);
if (isMapType || isClassificationType(attributeType)) {
LOG.warn("Ignoring non-indexable attribute {}", attribTypeName);
}
if (isArrayType) {
createLabelIfNeeded(management, propertyName, attribTypeName);
}
if (isEntityType(attributeType)) {
createEdgeLabel(management, propertyName);
} else if (isBuiltInType) {
if (isRelationshipType(atlasType)) {
createEdgeIndex(management, propertyName, getPrimitiveClass(attribTypeName), cardinality, false);
} else {
createVertexIndex(management, propertyName, getPrimitiveClass(attribTypeName), isUnique, cardinality, false, isIndexable);
}
} else if (isEnumType(attributeType)) {
if (isRelationshipType(atlasType)) {
createEdgeIndex(management, propertyName, String.class, cardinality, false);
} else {
createVertexIndex(management, propertyName, String.class, isUnique, cardinality, false, isIndexable);
}
} else if (isStructType(attributeType)) {
AtlasStructDef structDef = typeRegistry.getStructDefByName(attribTypeName);
updateIndexForTypeDef(management, structDef);
}
} catch (AtlasBaseException e) {
LOG.error("No type exists for {}", attribTypeName, e);
}
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class EntityDiscoveryService method isRelationshipAttribute.
private boolean isRelationshipAttribute(AtlasAttribute attribute) throws AtlasBaseException {
boolean ret = true;
AtlasType attrType = attribute.getAttributeType();
if (attrType.getTypeCategory() == ARRAY) {
attrType = ((AtlasArrayType) attrType).getElementType();
} else if (attrType.getTypeCategory() == MAP) {
attrType = ((AtlasMapType) attrType).getValueType();
}
if (attrType.getTypeCategory() != OBJECT_ID_TYPE) {
ret = false;
}
return ret;
}
Aggregations