コード例 #1
0
  private static String toJsonFromAttributeDef(
      AtlasAttributeDef attributeDef, AtlasStructType structType) {
    boolean isForeignKey = structType.isForeignKeyAttribute(attributeDef.getName());
    boolean isMappedFromRef = structType.isMappedFromRefAttribute(attributeDef.getName());
    String reverseAttribName = null;

    if (isForeignKey) { // check if the referenced entity has foreignKeyRef to this attribute
      AtlasType attribType = structType.getAttributeType(attributeDef.getName());

      if (attribType.getTypeCategory() == AtlasType.TypeCategory.ARRAY) {
        attribType = ((AtlasArrayType) attribType).getElementType();
      }

      if (attribType.getTypeCategory() == AtlasType.TypeCategory.ENTITY) {
        reverseAttribName =
            ((AtlasStructType) attribType)
                .getMappedFromRefAttribute(structType.getTypeName(), attributeDef.getName());
      }
    }

    boolean isComposite =
        isMappedFromRef || (isForeignKey && StringUtils.isBlank(reverseAttribName));

    Map<String, Object> attribInfo = new HashMap<>();

    attribInfo.put("name", attributeDef.getName());
    attribInfo.put("dataType", attributeDef.getTypeName());
    attribInfo.put("isUnique", attributeDef.isUnique());
    attribInfo.put("isIndexable", attributeDef.isIndexable());
    attribInfo.put("isComposite", isComposite);
    attribInfo.put("reverseAttributeName", reverseAttribName);
    Map<String, Object> multiplicity = new HashMap<>();
    multiplicity.put("lower", attributeDef.getValuesMinCount());
    multiplicity.put("upper", attributeDef.getValuesMaxCount());
    multiplicity.put(
        "isUnique", AtlasAttributeDef.Cardinality.SET.equals(attributeDef.getCardinality()));

    attribInfo.put("multiplicity", AtlasType.toJson(multiplicity));

    return AtlasType.toJson(attribInfo);
  }