use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class AtlasEntityType method collectTypeHierarchyInfo.
/*
* This method should not assume that resolveReferences() has been called on all superTypes.
* this.entityDef is the only safe member to reference here
*/
private void collectTypeHierarchyInfo(AtlasTypeRegistry typeRegistry, Set<String> allSuperTypeNames, Map<String, AtlasAttribute> allAttributes, List<String> visitedTypes) throws AtlasBaseException {
if (visitedTypes.contains(entityDef.getName())) {
throw new AtlasBaseException(AtlasErrorCode.CIRCULAR_REFERENCE, entityDef.getName(), visitedTypes.toString());
}
if (CollectionUtils.isNotEmpty(entityDef.getSuperTypes())) {
visitedTypes.add(entityDef.getName());
for (String superTypeName : entityDef.getSuperTypes()) {
AtlasEntityType superType = typeRegistry.getEntityTypeByName(superTypeName);
if (superType != null) {
superType.collectTypeHierarchyInfo(typeRegistry, allSuperTypeNames, allAttributes, visitedTypes);
}
}
visitedTypes.remove(entityDef.getName());
allSuperTypeNames.addAll(entityDef.getSuperTypes());
}
if (CollectionUtils.isNotEmpty(entityDef.getAttributeDefs())) {
for (AtlasAttributeDef attributeDef : entityDef.getAttributeDefs()) {
AtlasType type = typeRegistry.getType(attributeDef.getTypeName());
allAttributes.put(attributeDef.getName(), new AtlasAttribute(this, attributeDef, type));
}
}
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class AtlasStructType method normalizeAttributeValuesForUpdate.
public void normalizeAttributeValuesForUpdate(AtlasStruct obj) {
if (obj != null) {
for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
String attributeName = attributeDef.getName();
if (obj.hasAttribute(attributeName)) {
Object attributeValue = getNormalizedValueForUpdate(obj.getAttribute(attributeName), attributeDef);
obj.setAttribute(attributeName, attributeValue);
}
}
}
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class AtlasStructType method normalizeAttributeValues.
public void normalizeAttributeValues(AtlasStruct obj) {
if (obj != null) {
for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
String attributeName = attributeDef.getName();
if (obj.hasAttribute(attributeName)) {
Object attributeValue = getNormalizedValue(obj.getAttribute(attributeName), attributeDef);
obj.setAttribute(attributeName, attributeValue);
} else if (!attributeDef.getIsOptional()) {
obj.setAttribute(attributeName, createDefaultValue(attributeDef));
}
}
}
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class AtlasStructType method normalizeAttributeValuesForUpdate.
public void normalizeAttributeValuesForUpdate(Map<String, Object> obj) {
if (obj != null) {
for (AtlasAttributeDef attrDef : structDef.getAttributeDefs()) {
String attrName = attrDef.getName();
Object attrValue = obj.get(attrName);
if (obj.containsKey(attrName)) {
attrValue = getNormalizedValueForUpdate(attrValue, attrDef);
obj.put(attrName, attrValue);
}
}
}
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class AtlasStructType method resolveReferences.
@Override
public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
Map<String, AtlasAttribute> a = new HashMap<>();
for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
AtlasType attrType = typeRegistry.getType(attributeDef.getTypeName());
AtlasAttribute attribute = new AtlasAttribute(this, attributeDef, attrType);
Cardinality cardinality = attributeDef.getCardinality();
if (cardinality == Cardinality.LIST || cardinality == Cardinality.SET) {
if (!(attrType instanceof AtlasArrayType)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_ATTRIBUTE_TYPE_FOR_CARDINALITY, getTypeName(), attributeDef.getName());
}
AtlasArrayType arrayType = (AtlasArrayType) attrType;
arrayType.setMinCount(attributeDef.getValuesMinCount());
arrayType.setMaxCount(attributeDef.getValuesMaxCount());
}
a.put(attributeDef.getName(), attribute);
}
resolveConstraints(typeRegistry);
this.allAttributes = Collections.unmodifiableMap(a);
this.uniqAttributes = getUniqueAttributes(this.allAttributes);
}
Aggregations