use of org.apache.atlas.AtlasException in project incubator-atlas by apache.
the class AtlasInstanceConverter method toAtlasEntity.
public AtlasEntitiesWithExtInfo toAtlasEntity(IReferenceableInstance referenceable) throws AtlasBaseException {
AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) instanceFormatters.getConverter(TypeCategory.ENTITY);
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(referenceable.getTypeName());
if (entityType == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), referenceable.getTypeName());
}
// validate
try {
metadataService.validateAndConvertToTypedInstance(referenceable, entityType.getTypeName());
} catch (AtlasException excp) {
throw toAtlasBaseException(excp);
}
ConverterContext ctx = new ConverterContext();
AtlasEntity entity = converter.fromV1ToV2(referenceable, entityType, ctx);
ctx.addEntity(entity);
return ctx.getEntities();
}
use of org.apache.atlas.AtlasException in project incubator-atlas by apache.
the class StructType method output.
@Override
public void output(Appendable buf, Set<String> typesInProcess) throws AtlasException {
if (typesInProcess == null) {
typesInProcess = new HashSet<>();
} else if (typesInProcess.contains(name)) {
// Avoid infinite recursion on bi-directional reference attributes.
try {
buf.append(name);
} catch (IOException e) {
throw new AtlasException(e);
}
return;
}
typesInProcess.add(name);
try {
buf.append(getClass().getSimpleName());
buf.append("{name=").append(name);
buf.append(", description=").append(description);
buf.append(", fieldMapping.fields=[");
Iterator<AttributeInfo> it = fieldMapping.fields.values().iterator();
while (it.hasNext()) {
AttributeInfo attrInfo = it.next();
attrInfo.output(buf, typesInProcess);
if (it.hasNext()) {
buf.append(", ");
} else {
buf.append(']');
}
}
buf.append("}");
} catch (IOException e) {
throw new AtlasException(e);
} finally {
typesInProcess.remove(name);
}
}
use of org.apache.atlas.AtlasException in project incubator-atlas by apache.
the class HierarchicalType method constructFieldMapping.
protected Pair<FieldMapping, ImmutableMap<String, String>> constructFieldMapping(ImmutableSet<String> superTypes, AttributeInfo... fields) throws AtlasException {
Map<String, AttributeInfo> fieldsMap = new LinkedHashMap();
Map<String, Integer> fieldPos = new HashMap();
Map<String, Integer> fieldNullPos = new HashMap();
Map<String, String> attributeNameToType = new HashMap<>();
int numBools = 0;
int numBytes = 0;
int numShorts = 0;
int numInts = 0;
int numLongs = 0;
int numFloats = 0;
int numDoubles = 0;
int numBigInts = 0;
int numBigDecimals = 0;
int numDates = 0;
int numStrings = 0;
int numArrays = 0;
int numMaps = 0;
int numStructs = 0;
int numReferenceables = 0;
setupSuperTypesGraph(superTypes);
Iterator<Path> pathItr = pathIterator();
while (pathItr.hasNext()) {
Path currentPath = pathItr.next();
ST superType = Objects.equals(currentPath.typeName, getName()) ? (ST) this : typeSystem.getDataType(superTypeClass, currentPath.typeName);
ImmutableList<AttributeInfo> superTypeFields = superType == this ? ImmutableList.copyOf(fields) : superType.immediateAttrs;
Set<String> immediateFields = new HashSet<>();
for (AttributeInfo i : superTypeFields) {
if (superType == this) {
if (immediateFields.contains(i.name)) {
throw new AtlasException(String.format("Struct defintion cannot contain multiple fields with the" + " same name %s", i.name));
}
immediateFields.add(i.name);
}
String attrName = i.name;
if (fieldsMap.containsKey(attrName)) {
attrName = currentPath.addOverrideAttr(attrName);
}
attributeNameToType.put(attrName, superType.getName());
fieldsMap.put(attrName, i);
fieldNullPos.put(attrName, fieldNullPos.size());
if (i.dataType() == DataTypes.BOOLEAN_TYPE) {
fieldPos.put(attrName, numBools);
numBools++;
} else if (i.dataType() == DataTypes.BYTE_TYPE) {
fieldPos.put(attrName, numBytes);
numBytes++;
} else if (i.dataType() == DataTypes.SHORT_TYPE) {
fieldPos.put(attrName, numShorts);
numShorts++;
} else if (i.dataType() == DataTypes.INT_TYPE) {
fieldPos.put(attrName, numInts);
numInts++;
} else if (i.dataType() == DataTypes.LONG_TYPE) {
fieldPos.put(attrName, numLongs);
numLongs++;
} else if (i.dataType() == DataTypes.FLOAT_TYPE) {
fieldPos.put(attrName, numFloats);
numFloats++;
} else if (i.dataType() == DataTypes.DOUBLE_TYPE) {
fieldPos.put(attrName, numDoubles);
numDoubles++;
} else if (i.dataType() == DataTypes.BIGINTEGER_TYPE) {
fieldPos.put(attrName, numBigInts);
numBigInts++;
} else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) {
fieldPos.put(attrName, numBigDecimals);
numBigDecimals++;
} else if (i.dataType() == DataTypes.DATE_TYPE) {
fieldPos.put(attrName, numDates);
numDates++;
} else if (i.dataType() == DataTypes.STRING_TYPE) {
fieldPos.put(attrName, numStrings);
numStrings++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ENUM) {
fieldPos.put(i.name, numInts);
numInts++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
fieldPos.put(attrName, numArrays);
numArrays++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
fieldPos.put(attrName, numMaps);
numMaps++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT || i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
fieldPos.put(attrName, numStructs);
numStructs++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
fieldPos.put(attrName, numReferenceables);
numReferenceables++;
} else {
throw new AtlasException(String.format("Unknown datatype %s", i.dataType()));
}
}
}
this.superTypePaths = ImmutableMap.copyOf(superTypePaths);
this.pathNameToPathMap = ImmutableMap.copyOf(pathNameToPathMap);
FieldMapping fm = new FieldMapping(fieldsMap, fieldPos, fieldNullPos, numBools, numBytes, numShorts, numInts, numLongs, numFloats, numDoubles, numBigInts, numBigDecimals, numDates, numStrings, numArrays, numMaps, numStructs, numReferenceables);
return new Pair(fm, ImmutableMap.copyOf(attributeNameToType));
}
use of org.apache.atlas.AtlasException in project incubator-atlas by apache.
the class HierarchicalType method output.
@Override
public void output(Appendable buf, Set<String> typesInProcess) throws AtlasException {
if (typesInProcess == null) {
typesInProcess = new HashSet<>();
} else if (typesInProcess.contains(name)) {
// Avoid infinite recursion on bi-directional reference attributes.
try {
buf.append(name);
} catch (IOException e) {
throw new AtlasException(e);
}
return;
}
typesInProcess.add(name);
try {
buf.append(getClass().getSimpleName()).append('{');
buf.append("name=").append(name);
buf.append(", description=").append(description);
buf.append(", superTypes=").append(superTypes.toString());
buf.append(", immediateAttrs=[");
UnmodifiableIterator<AttributeInfo> it = immediateAttrs.iterator();
while (it.hasNext()) {
AttributeInfo attrInfo = it.next();
attrInfo.output(buf, typesInProcess);
if (it.hasNext()) {
buf.append(", ");
} else {
buf.append(']');
}
}
buf.append("}");
} catch (IOException e) {
throw new AtlasException(e);
} finally {
typesInProcess.remove(name);
}
}
use of org.apache.atlas.AtlasException in project incubator-atlas by apache.
the class StructType method constructFieldMapping.
protected FieldMapping constructFieldMapping(AttributeInfo... fields) throws AtlasException {
Map<String, AttributeInfo> fieldsMap = new LinkedHashMap<>();
Map<String, Integer> fieldPos = new HashMap<>();
Map<String, Integer> fieldNullPos = new HashMap<>();
int numBools = 0;
int numBytes = 0;
int numShorts = 0;
int numInts = 0;
int numLongs = 0;
int numFloats = 0;
int numDoubles = 0;
int numBigInts = 0;
int numBigDecimals = 0;
int numDates = 0;
int numStrings = 0;
int numArrays = 0;
int numMaps = 0;
int numStructs = 0;
int numReferenceables = 0;
for (AttributeInfo i : fields) {
if (fieldsMap.containsKey(i.name)) {
throw new AtlasException(String.format("Struct defintion cannot contain multiple fields with the same " + "name %s", i.name));
}
fieldsMap.put(i.name, i);
fieldNullPos.put(i.name, fieldNullPos.size());
if (i.dataType() == DataTypes.BOOLEAN_TYPE) {
fieldPos.put(i.name, numBools);
numBools++;
} else if (i.dataType() == DataTypes.BYTE_TYPE) {
fieldPos.put(i.name, numBytes);
numBytes++;
} else if (i.dataType() == DataTypes.SHORT_TYPE) {
fieldPos.put(i.name, numShorts);
numShorts++;
} else if (i.dataType() == DataTypes.INT_TYPE) {
fieldPos.put(i.name, numInts);
numInts++;
} else if (i.dataType() == DataTypes.LONG_TYPE) {
fieldPos.put(i.name, numLongs);
numLongs++;
} else if (i.dataType() == DataTypes.FLOAT_TYPE) {
fieldPos.put(i.name, numFloats);
numFloats++;
} else if (i.dataType() == DataTypes.DOUBLE_TYPE) {
fieldPos.put(i.name, numDoubles);
numDoubles++;
} else if (i.dataType() == DataTypes.BIGINTEGER_TYPE) {
fieldPos.put(i.name, numBigInts);
numBigInts++;
} else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) {
fieldPos.put(i.name, numBigDecimals);
numBigDecimals++;
} else if (i.dataType() == DataTypes.DATE_TYPE) {
fieldPos.put(i.name, numDates);
numDates++;
} else if (i.dataType() == DataTypes.STRING_TYPE) {
fieldPos.put(i.name, numStrings);
numStrings++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ENUM) {
fieldPos.put(i.name, numInts);
numInts++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
fieldPos.put(i.name, numArrays);
numArrays++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
fieldPos.put(i.name, numMaps);
numMaps++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT || i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
fieldPos.put(i.name, numStructs);
numStructs++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
fieldPos.put(i.name, numReferenceables);
numReferenceables++;
} else {
throw new AtlasException(String.format("Unknown datatype %s", i.dataType()));
}
}
return new FieldMapping(fieldsMap, fieldPos, fieldNullPos, numBools, numBytes, numShorts, numInts, numLongs, numFloats, numDoubles, numBigInts, numBigDecimals, numDates, numStrings, numArrays, numMaps, numStructs, numReferenceables);
}
Aggregations