Java Code Examples for org.apache.atlas.AtlasErrorCode#UNEXPECTED_TYPE
The following examples show how to use
org.apache.atlas.AtlasErrorCode#UNEXPECTED_TYPE .
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: AtlasStructFormatConverter.java From atlas with Apache License 2.0 | 5 votes |
@Override public Object fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException { AtlasStruct ret = null; if (v1Obj != null) { AtlasStructType structType = (AtlasStructType)type; if (v1Obj instanceof Map) { final Map v1Map = (Map) v1Obj; final Map v1Attribs = (Map) v1Map.get(ATTRIBUTES_PROPERTY_KEY); if (MapUtils.isNotEmpty(v1Attribs)) { ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, v1Attribs, converterContext)); } else { ret = new AtlasStruct(type.getTypeName()); } } else if (v1Obj instanceof Struct) { Struct struct = (Struct) v1Obj; ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, struct.getValues(), converterContext)); } else { throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or Struct", v1Obj.getClass().getCanonicalName()); } } return ret; }
Example 2
Source File: AtlasMapFormatConverter.java From atlas with Apache License 2.0 | 5 votes |
@Override public Map fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException { Map ret = null; if (v1Obj != null) { if (v1Obj instanceof Map) { AtlasMapType mapType = (AtlasMapType)type; AtlasType keyType = mapType.getKeyType(); AtlasType valueType = mapType.getValueType(); AtlasFormatConverter keyConverter = converterRegistry.getConverter(keyType.getTypeCategory()); AtlasFormatConverter valueConverter = converterRegistry.getConverter(valueType.getTypeCategory()); Map v1Map = (Map)v1Obj; ret = new HashMap<>(); for (Object key : v1Map.keySet()) { Object value = v1Map.get(key); Object v2Key = keyConverter.fromV1ToV2(key, keyType, ctx); Object v2Value = valueConverter.fromV1ToV2(value, valueType, ctx); ret.put(v2Key, v2Value); } } else { throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map", v1Obj.getClass().getCanonicalName()); } } return ret; }
Example 3
Source File: AtlasMapFormatConverter.java From atlas with Apache License 2.0 | 5 votes |
@Override public Map fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException { Map ret = null; if (v2Obj != null) { if (v2Obj instanceof Map) { AtlasMapType mapType = (AtlasMapType)type; AtlasType keyType = mapType.getKeyType(); AtlasType valueType = mapType.getValueType(); AtlasFormatConverter keyConverter = converterRegistry.getConverter(keyType.getTypeCategory()); AtlasFormatConverter valueConverter = converterRegistry.getConverter(valueType.getTypeCategory()); Map v2Map = (Map)v2Obj; ret = new HashMap<>(); for (Object key : v2Map.keySet()) { Object value = v2Map.get(key); Object v2Key = keyConverter.fromV2ToV1(key, keyType, ctx); Object v2Value = valueConverter.fromV2ToV1(value, valueType, ctx); ret.put(v2Key, v2Value); } } else { throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map", v2Obj.getClass().getCanonicalName()); } } return ret; }
Example 4
Source File: AtlasMapFormatConverter.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Override public Map fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException { Map ret = null; if (v1Obj != null) { if (v1Obj instanceof Map) { AtlasMapType mapType = (AtlasMapType)type; AtlasType keyType = mapType.getKeyType(); AtlasType valueType = mapType.getValueType(); AtlasFormatConverter keyConverter = converterRegistry.getConverter(keyType.getTypeCategory()); AtlasFormatConverter valueConverter = converterRegistry.getConverter(valueType.getTypeCategory()); Map v1Map = (Map)v1Obj; ret = new HashMap<>(); for (Object key : v1Map.keySet()) { Object value = v1Map.get(key); Object v2Key = keyConverter.fromV1ToV2(key, keyType, ctx); Object v2Value = valueConverter.fromV1ToV2(value, valueType, ctx); ret.put(v2Key, v2Value); } } else { throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map", v1Obj.getClass().getCanonicalName()); } } return ret; }
Example 5
Source File: AtlasMapFormatConverter.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Override public Map fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException { Map ret = null; if (v2Obj != null) { if (v2Obj instanceof Map) { AtlasMapType mapType = (AtlasMapType)type; AtlasType keyType = mapType.getKeyType(); AtlasType valueType = mapType.getValueType(); AtlasFormatConverter keyConverter = converterRegistry.getConverter(keyType.getTypeCategory()); AtlasFormatConverter valueConverter = converterRegistry.getConverter(valueType.getTypeCategory()); Map v2Map = (Map)v2Obj; ret = new HashMap<>(); for (Object key : v2Map.keySet()) { Object value = v2Map.get(key); Object v2Key = keyConverter.fromV2ToV1(key, keyType, ctx); Object v2Value = valueConverter.fromV2ToV1(value, valueType, ctx); ret.put(v2Key, v2Value); } } else { throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map", v2Obj.getClass().getCanonicalName()); } } return ret; }
Example 6
Source File: DataAccess.java From atlas with Apache License 2.0 | 4 votes |
public <T extends AtlasBaseModelObject> T load(T obj, boolean loadDeleted) throws AtlasBaseException { Objects.requireNonNull(obj, "Can't load a null object"); AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataAccess.load()"); } DataTransferObject<T> dto = (DataTransferObject<T>) dtoRegistry.get(obj.getClass()); AtlasEntityWithExtInfo entityWithExtInfo; String guid = obj.getGuid(); // GUID can be null/empty/-ve if (StringUtils.isNotEmpty(guid) && guid.charAt(0) != '-') { if (LOG.isDebugEnabled()) { LOG.debug("Load using GUID"); } entityWithExtInfo = entityStore.getById(guid); } else { if (LOG.isDebugEnabled()) { LOG.debug("Load using unique attributes"); } entityWithExtInfo = entityStore.getByUniqueAttributes(dto.getEntityType(), dto.getUniqueAttributes(obj)); } // Since GUID alone can't be used to determine what ENTITY TYPE is loaded from the graph String actualTypeName = entityWithExtInfo.getEntity().getTypeName(); String expectedTypeName = dto.getEntityType().getTypeName(); if (!actualTypeName.equals(expectedTypeName)) { throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, expectedTypeName, actualTypeName); } if (!loadDeleted && entityWithExtInfo.getEntity().getStatus() == AtlasEntity.Status.DELETED) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_DELETED, guid); } return dto.from(entityWithExtInfo); } finally { AtlasPerfTracer.log(perf); } }