Commit 08ac11c0 by Madhan Neethiraj

ATLAS-2346: fix V1 REST API to include AttributeDefinition.dataTypeName field in type details

parent 413aa88e
......@@ -33,7 +33,6 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_
@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
......
......@@ -360,7 +360,7 @@ public final class TypeConverterUtil {
for (AtlasAttributeDef attrDef : attrDefs) {
AtlasAttribute attribute = structType.getAttribute(attrDef.getName());
AttributeDefinition oldAttrDef = AtlasStructDefStoreV1.toAttributeDefintion(attribute);
AttributeDefinition oldAttrDef = AtlasStructDefStoreV1.toAttributeDefinition(attribute);
ret.add(new AttributeDefinition(oldAttrDef.getName(), oldAttrDef.getDataTypeName(), new Multiplicity(oldAttrDef.getMultiplicity()), oldAttrDef.getIsComposite(), oldAttrDef.getIsUnique(), oldAttrDef.getIsIndexable(), oldAttrDef.getReverseAttributeName()));
}
......
......@@ -33,6 +33,7 @@ import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
import org.apache.atlas.v1.model.typedef.Multiplicity;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
......@@ -544,10 +545,43 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1<AtlasStructDe
return ret;
}
public static AttributeDefinition toAttributeDefintion(AtlasAttribute attribute) {
String jsonString = toJsonFromAttribute(attribute);
public static Multiplicity getMultiplicity(AtlasAttributeDef attributeDef) {
final int lower;
final int upper;
final boolean isUnique = AtlasAttributeDef.Cardinality.SET.equals(attributeDef.getCardinality());
AttributeDefinition ret = AtlasType.fromV1Json(jsonString, AttributeDefinition.class);
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 ret = new Multiplicity(lower, upper, isUnique);
return ret;
}
public static AttributeDefinition toAttributeDefinition(AtlasAttribute attribute) {
final AtlasAttributeDef attrDef = attribute.getAttributeDef();
AttributeDefinition ret = new AttributeDefinition();
ret.setName(attrDef.getName());
ret.setDataTypeName(attrDef.getTypeName());
ret.setMultiplicity(getMultiplicity(attrDef));
ret.setIsComposite(attribute.isOwnedRef());
ret.setIsUnique(attrDef.getIsUnique());
ret.setIsIndexable(attrDef.getIsIndexable());
ret.setReverseAttributeName(attribute.getInverseRefAttributeName());
ret.setDescription(attrDef.getDescription());
ret.setDefaultValue(attrDef.getDefaultValue());
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment