コード例 #1
0
  public static void updateVertexPreUpdate(
      AtlasStructDef structDef,
      AtlasStructType structType,
      AtlasVertex vertex,
      AtlasTypeDefGraphStoreV1 typeDefStore)
      throws AtlasBaseException {

    List<String> attrNames = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(structDef.getAttributeDefs())) {
      for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
        attrNames.add(attributeDef.getName());
      }
    }

    List<String> currAttrNames =
        vertex.getProperty(AtlasGraphUtilsV1.getPropertyKey(structDef), List.class);

    // delete attributes that are not present in updated structDef
    if (CollectionUtils.isNotEmpty(currAttrNames)) {
      for (String currAttrName : currAttrNames) {
        if (!attrNames.contains(currAttrName)) {
          throw new AtlasBaseException(
              AtlasErrorCode.ATTRIBUTE_DELETION_NOT_SUPPORTED, structDef.getName(), currAttrName);
        }
      }
    }

    typeDefStore.updateTypeVertex(structDef, vertex);

    // add/update attributes that are present in updated structDef
    if (CollectionUtils.isNotEmpty(structDef.getAttributeDefs())) {
      for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
        if (CollectionUtils.isEmpty(currAttrNames)
            || !currAttrNames.contains(attributeDef.getName())) {
          // new attribute - only allow if optional
          if (!attributeDef.isOptional()) {
            throw new AtlasBaseException(
                AtlasErrorCode.CANNOT_ADD_MANDATORY_ATTRIBUTE,
                structDef.getName(),
                attributeDef.getName());
          }
        }

        String propertyKey = AtlasGraphUtilsV1.getPropertyKey(structDef, attributeDef.getName());

        AtlasGraphUtilsV1.setProperty(
            vertex, propertyKey, toJsonFromAttributeDef(attributeDef, structType));
      }
    }

    AtlasGraphUtilsV1.setProperty(vertex, AtlasGraphUtilsV1.getPropertyKey(structDef), attrNames);
  }