use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.
the class TypeConverterUtil method toAtlasStructDefs.
private static List<AtlasStructDef> toAtlasStructDefs(List<StructTypeDefinition> structTypeDefinitions) {
List<AtlasStructDef> ret = new ArrayList<>();
for (StructTypeDefinition structType : structTypeDefinitions) {
List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>();
if (CollectionUtils.isNotEmpty(structType.getAttributeDefinitions())) {
for (AttributeDefinition attrDefinition : structType.getAttributeDefinitions()) {
attrDefs.add(toAtlasAttributeDef(attrDefinition));
}
}
AtlasStructDef structDef = new AtlasStructDef(structType.getTypeName(), structType.getTypeDescription(), structType.getTypeVersion(), attrDefs);
ret.add(structDef);
}
return ret;
}
use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.
the class AtlasTypeUtil method toV1AttributeDefinition.
public static AttributeDefinition toV1AttributeDefinition(AtlasStructType.AtlasAttribute attribute) {
AtlasAttributeDef attributeDef = attribute.getAttributeDef();
AttributeDefinition ret = new AttributeDefinition();
ret.setName(attributeDef.getName());
ret.setDataTypeName(attributeDef.getTypeName());
ret.setIsUnique(attributeDef.getIsUnique());
ret.setIsIndexable(attributeDef.getIsIndexable());
ret.setIsComposite(attribute.isOwnedRef());
ret.setReverseAttributeName(attribute.getInverseRefAttributeName());
ret.setDefaultValue(attributeDef.getDefaultValue());
ret.setDescription(attributeDef.getDescription());
final int lower;
final int upper;
if (attributeDef.getCardinality() == AtlasAttributeDef.Cardinality.SINGLE) {
lower = attributeDef.getIsOptional() ? 0 : 1;
upper = 1;
} else {
if (attributeDef.getIsOptional()) {
lower = 0;
} else {
lower = attributeDef.getValuesMinCount() < 1 ? 1 : attributeDef.getValuesMinCount();
}
upper = attributeDef.getValuesMaxCount() < 2 ? Integer.MAX_VALUE : attributeDef.getValuesMaxCount();
}
Multiplicity multiplicity = new Multiplicity();
multiplicity.setLower(lower);
multiplicity.setUpper(upper);
multiplicity.setIsUnique(AtlasAttributeDef.Cardinality.SET.equals(attributeDef.getCardinality()));
ret.setMultiplicity(multiplicity);
return ret;
}
use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.
the class AtlasTypeUtil method toClassTypeDefinition.
public static ClassTypeDefinition toClassTypeDefinition(final AtlasEntityType entityType) {
ClassTypeDefinition ret = null;
if (entityType != null) {
AtlasEntityDef entityDef = entityType.getEntityDef();
ret = new ClassTypeDefinition();
ret.setTypeName(entityDef.getName());
ret.setTypeDescription(entityDef.getDescription());
ret.setTypeVersion(entityDef.getTypeVersion());
ret.setSuperTypes(entityDef.getSuperTypes());
if (MapUtils.isNotEmpty(entityType.getAllAttributes())) {
List<AttributeDefinition> attributeDefinitions = entityType.getAllAttributes().entrySet().stream().map(e -> toV1AttributeDefinition(e.getValue())).collect(Collectors.toList());
ret.setAttributeDefinitions(attributeDefinitions);
}
}
return ret;
}
Aggregations