use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class AtlasEntityDefStoreV1 method preCreate.
@Override
public AtlasVertex preCreate(AtlasEntityDef entityDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.preCreate({})", entityDef);
}
validateType(entityDef);
AtlasType type = typeRegistry.getType(entityDef.getName());
if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.ENTITY) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name());
}
AtlasVertex ret = typeDefStore.findTypeVertexByName(entityDef.getName());
if (ret != null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, entityDef.getName());
}
ret = typeDefStore.createTypeVertex(entityDef);
updateVertexPreCreate(entityDef, (AtlasEntityType) type, ret);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.preCreate({}): {}", entityDef, ret);
}
return ret;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class AtlasArrayFormatConverter method fromV1ToV2.
@Override
public Collection fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
Collection ret = null;
if (v1Obj != null) {
if (v1Obj instanceof Set) {
ret = new LinkedHashSet();
} else {
ret = new ArrayList();
}
AtlasArrayType arrType = (AtlasArrayType) type;
AtlasType elemType = arrType.getElementType();
AtlasFormatConverter elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
if (v1Obj instanceof Collection) {
Collection v1List = (Collection) v1Obj;
for (Object v1Elem : v1List) {
Object convertedVal = elemConverter.fromV1ToV2(v1Elem, elemType, ctx);
ret.add(convertedVal);
}
} else {
Object convertedVal = elemConverter.fromV1ToV2(v1Obj, elemType, ctx);
ret.add(convertedVal);
}
}
return ret;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class AtlasArrayFormatConverter method isValidValueV1.
@Override
public boolean isValidValueV1(Object v1Obj, AtlasType type) {
boolean ret = false;
if (v1Obj == null) {
return true;
}
if (type instanceof AtlasArrayType) {
AtlasArrayType arrType = (AtlasArrayType) type;
AtlasType elemType = arrType.getElementType();
AtlasFormatConverter elemConverter = null;
try {
elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
} catch (AtlasBaseException excp) {
LOG.warn("failed to get element converter. type={}", type.getTypeName(), excp);
ret = false;
}
if (elemConverter != null) {
if (v1Obj instanceof Collection) {
// for empty array
ret = true;
for (Object v1Elem : (Collection) v1Obj) {
ret = elemConverter.isValidValueV1(v1Elem, elemType);
if (!ret) {
break;
}
}
} else {
ret = elemConverter.isValidValueV1(v1Obj, elemType);
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("AtlasArrayFormatConverter.isValidValueV1(type={}, value={}): {}", (v1Obj != null ? v1Obj.getClass().getCanonicalName() : null), v1Obj, ret);
}
return ret;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class AtlasInstanceConverter method getReferenceable.
public Referenceable getReferenceable(AtlasEntity entity, final ConverterContext ctx) throws AtlasBaseException {
AtlasFormatConverter converter = instanceFormatters.getConverter(TypeCategory.ENTITY);
AtlasType entityType = typeRegistry.getType(entity.getTypeName());
Referenceable ref = (Referenceable) converter.fromV2ToV1(entity, entityType, ctx);
return ref;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class GraphBackedSearchIndexer method cleanupIndexForAttribute.
private void cleanupIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) {
final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + attributeDef.getName());
String attribTypeName = attributeDef.getTypeName();
boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName);
boolean isArrayType = AtlasTypeUtil.isArrayType(attribTypeName);
boolean isMapType = AtlasTypeUtil.isMapType(attribTypeName);
try {
AtlasType atlasType = typeRegistry.getType(attribTypeName);
if (isMapType || isArrayType || isClassificationType(atlasType) || isEntityType(atlasType)) {
LOG.warn("Ignoring non-indexable attribute {}", attribTypeName);
} else if (isBuiltInType || isEnumType(atlasType)) {
cleanupIndex(management, propertyName);
} else if (isStructType(atlasType)) {
AtlasStructDef structDef = typeRegistry.getStructDefByName(attribTypeName);
cleanupIndices(management, structDef);
}
} catch (AtlasBaseException e) {
LOG.error("No type exists for {}", attribTypeName, e);
}
}
Aggregations