use of org.apache.atlas.typesystem.types.Multiplicity in project incubator-atlas by apache.
the class TypeConverterUtil method toAtlasAttributeDef.
public static AtlasAttributeDef toAtlasAttributeDef(final AttributeDefinition attrDefinition) {
AtlasAttributeDef ret = new AtlasAttributeDef();
ret.setName(attrDefinition.name);
ret.setTypeName(attrDefinition.dataTypeName);
ret.setIsIndexable(attrDefinition.isIndexable);
ret.setIsUnique(attrDefinition.isUnique);
if (attrDefinition.isComposite) {
ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF));
}
if (StringUtils.isNotBlank(attrDefinition.reverseAttributeName)) {
ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {
{
put(CONSTRAINT_PARAM_ATTRIBUTE, attrDefinition.reverseAttributeName);
}
}));
}
// Multiplicity attribute mapping
Multiplicity multiplicity = attrDefinition.multiplicity;
int minCount = multiplicity.lower;
int maxCount = multiplicity.upper;
boolean isUnique = multiplicity.isUnique;
if (minCount == 0) {
ret.setIsOptional(true);
ret.setValuesMinCount(0);
} else {
ret.setIsOptional(false);
ret.setValuesMinCount(minCount);
}
if (maxCount < 2) {
ret.setCardinality(Cardinality.SINGLE);
ret.setValuesMaxCount(1);
} else {
if (!isUnique) {
ret.setCardinality(Cardinality.LIST);
} else {
ret.setCardinality(Cardinality.SET);
}
ret.setValuesMaxCount(maxCount);
}
return ret;
}
Aggregations