use of org.apache.atlas.v1.model.instance.AtlasSystemAttributes in project atlas by apache.
the class AtlasEntityFormatConverter method fromV2ToV1.
@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext context) throws AtlasBaseException {
Object ret = null;
if (v2Obj != null) {
AtlasEntityType entityType = (AtlasEntityType) type;
if (v2Obj instanceof Map) {
Map v2Map = (Map) v2Obj;
String idStr = (String) v2Map.get(AtlasObjectId.KEY_GUID);
String typeName = type.getTypeName();
if (StringUtils.isEmpty(idStr)) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
final Map v2Attribs = (Map) v2Map.get(ATTRIBUTES_PROPERTY_KEY);
if (MapUtils.isEmpty(v2Attribs)) {
ret = new Id(idStr, 0, typeName);
} else {
ret = new Referenceable(idStr, typeName, super.fromV2ToV1(entityType, v2Attribs, context));
}
} else if (v2Obj instanceof AtlasEntity) {
AtlasEntity entity = (AtlasEntity) v2Obj;
Status status = entity.getStatus();
if (status == null) {
status = Status.ACTIVE;
}
Referenceable referenceable = new Referenceable(entity.getGuid(), entity.getTypeName(), status.name(), fromV2ToV1(entityType, entity.getAttributes(), context), new AtlasSystemAttributes(entity.getCreatedBy(), entity.getUpdatedBy(), entity.getCreateTime(), entity.getUpdateTime()));
if (CollectionUtils.isNotEmpty(entity.getClassifications())) {
for (AtlasClassification classification : entity.getClassifications()) {
String traitName = classification.getTypeName();
AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(traitName);
AtlasFormatConverter formatConverter = classificationType != null ? converterRegistry.getConverter(classificationType.getTypeCategory()) : null;
Struct trait = formatConverter != null ? (Struct) formatConverter.fromV2ToV1(classification, classificationType, context) : null;
if (trait != null) {
referenceable.getTraitNames().add(trait.getTypeName());
referenceable.getTraits().put(trait.getTypeName(), trait);
}
}
}
ret = referenceable;
} else if (v2Obj instanceof AtlasObjectId) {
// transient-id
AtlasEntity entity = context.getById(((AtlasObjectId) v2Obj).getGuid());
if (entity == null) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Could not find entity ", v2Obj.toString());
}
ret = this.fromV2ToV1(entity, typeRegistry.getType(((AtlasObjectId) v2Obj).getTypeName()), context);
} else {
throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or AtlasEntity or String", v2Obj.getClass().getCanonicalName());
}
}
return ret;
}
Aggregations