Java Code Examples for org.apache.atlas.AtlasErrorCode#MISSING_MANDATORY_ATTRIBUTE

The following examples show how to use org.apache.atlas.AtlasErrorCode#MISSING_MANDATORY_ATTRIBUTE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasStructDefStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static void updateVertexPreCreate(AtlasStructDef structDef, AtlasStructType structType,
                                         AtlasVertex vertex, AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException {
    List<String> attrNames = new ArrayList<>(structDef.getAttributeDefs().size());

    for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
        // Validate the mandatory features of an attribute (compatibility with legacy type system)
        if (StringUtils.isEmpty(attributeDef.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, structDef.getName(), "name");
        }
        if (StringUtils.isEmpty(attributeDef.getTypeName())) {
            throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, structDef.getName(), "typeName");
        }

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

        AtlasGraphUtilsV1.setProperty(vertex, propertyKey, toJsonFromAttribute(structType.getAttribute(attributeDef.getName())));

        attrNames.add(attributeDef.getName());
    }
    AtlasGraphUtilsV1.setProperty(vertex, AtlasGraphUtilsV1.getTypeDefPropertyKey(structDef), attrNames);
}
 
Example 2
Source File: AtlasEnumDefStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void toVertex(AtlasEnumDef enumDef, AtlasVertex vertex) throws AtlasBaseException {
    if (CollectionUtils.isEmpty(enumDef.getElementDefs())) {
        throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, enumDef.getName(), "values");
    }

    List<String> values = new ArrayList<>(enumDef.getElementDefs().size());

    for (AtlasEnumElementDef element : enumDef.getElementDefs()) {
        // Validate the enum element
        if (StringUtils.isEmpty(element.getValue()) || null == element.getOrdinal()) {
            throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, enumDef.getName(), "elementValue");
        }

        String elemKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef, element.getValue());

        AtlasGraphUtilsV2.setProperty(vertex, elemKey, element.getOrdinal());

        if (StringUtils.isNotBlank(element.getDescription())) {
            String descKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(elemKey, "description");

            AtlasGraphUtilsV2.setProperty(vertex, descKey, element.getDescription());
        }

        values.add(element.getValue());
    }
    AtlasGraphUtilsV2.setProperty(vertex, AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef), values);

    String defaultValueKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef, "defaultValue");
    AtlasGraphUtilsV2.setProperty(vertex, defaultValueKey, enumDef.getDefaultValue());

}
 
Example 3
Source File: AtlasStructDefStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static void updateVertexPreCreate(AtlasStructDef structDef, AtlasStructType structType,
                                         AtlasVertex vertex, AtlasTypeDefGraphStoreV2 typeDefStore) throws AtlasBaseException {
    List<String> attrNames = new ArrayList<>(structDef.getAttributeDefs().size());

    for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
        // Validate the mandatory features of an attribute (compatibility with legacy type system)
        if (StringUtils.isEmpty(attributeDef.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, structDef.getName(), "name");
        }

        if (StringUtils.isEmpty(attributeDef.getTypeName())) {
            throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, structDef.getName(), "typeName");
        }

        String propertyKey        = AtlasGraphUtilsV2.getTypeDefPropertyKey(structDef, attributeDef.getName());
        String encodedPropertyKey = AtlasGraphUtilsV2.encodePropertyKey(propertyKey);

        vertex.setProperty(encodedPropertyKey, toJsonFromAttribute(structType.getAttribute(attributeDef.getName())));

        attrNames.add(attributeDef.getName());
    }

    String typeNamePropertyKey        = AtlasGraphUtilsV2.getTypeDefPropertyKey(structDef);
    String encodedtypeNamePropertyKey = AtlasGraphUtilsV2.encodePropertyKey(typeNamePropertyKey);

    vertex.setProperty(encodedtypeNamePropertyKey, attrNames);
}
 
Example 4
Source File: AtlasEnumDefStoreV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void toVertex(AtlasEnumDef enumDef, AtlasVertex vertex) throws AtlasBaseException {
    if (CollectionUtils.isEmpty(enumDef.getElementDefs())) {
        throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, enumDef.getName(), "values");
    }

    List<String> values = new ArrayList<>(enumDef.getElementDefs().size());

    for (AtlasEnumElementDef element : enumDef.getElementDefs()) {
        // Validate the enum element
        if (StringUtils.isEmpty(element.getValue()) || null == element.getOrdinal()) {
            throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, enumDef.getName(), "elementValue");
        }

        String elemKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(enumDef, element.getValue());

        AtlasGraphUtilsV1.setProperty(vertex, elemKey, element.getOrdinal());

        if (StringUtils.isNotBlank(element.getDescription())) {
            String descKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(elemKey, "description");

            AtlasGraphUtilsV1.setProperty(vertex, descKey, element.getDescription());
        }

        values.add(element.getValue());
    }
    AtlasGraphUtilsV1.setProperty(vertex, AtlasGraphUtilsV1.getTypeDefPropertyKey(enumDef), values);
}
 
Example 5
Source File: AtlasBusinessMetadataType.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
    super.resolveReferences(typeRegistry);

    Map<String, AtlasBusinessAttribute> a = new HashMap<>();

    for (AtlasAttribute attribute : super.allAttributes.values()) {
        AtlasAttributeDef attributeDef = attribute.getAttributeDef();
        String            attrName     = attribute.getName();
        AtlasType         attrType     = attribute.getAttributeType();

        if (attrType instanceof AtlasArrayType) {
            attrType = ((AtlasArrayType) attrType).getElementType();
        } else if (attrType instanceof AtlasMapType) {
            attrType = ((AtlasMapType) attrType).getValueType();
        }

        // check if attribute type is not struct/classification/entity/business-metadata
        if (attrType instanceof AtlasStructType) {
            throw new AtlasBaseException(AtlasErrorCode.BUSINESS_METADATA_DEF_ATTRIBUTE_TYPE_INVALID, getTypeName(), attrName);
        }

        Set<String>          entityTypeNames = attribute.getOptionSet(ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
        Set<AtlasEntityType> entityTypes     = new HashSet<>();

        if (CollectionUtils.isNotEmpty(entityTypeNames)) {
            for (String entityTypeName : entityTypeNames) {
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);

                if (entityType == null) {
                    throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, entityTypeName);
                }

                entityTypes.add(entityType);
            }
        }

        AtlasBusinessAttribute bmAttribute;
        if (attrType instanceof AtlasBuiltInTypes.AtlasStringType) {
            Integer maxStringLength = attribute.getOptionInt(ATTR_MAX_STRING_LENGTH);
            if (maxStringLength == null) {
                throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, attributeDef.getName(), "options." + ATTR_MAX_STRING_LENGTH);
            }

            String validPattern = attribute.getOptionString(ATTR_VALID_PATTERN);
            bmAttribute = new AtlasBusinessAttribute(attribute, entityTypes, maxStringLength, validPattern);
        } else {
            bmAttribute = new AtlasBusinessAttribute(attribute, entityTypes);
        }

        a.put(attrName, bmAttribute);
    }

    super.allAttributes = Collections.unmodifiableMap(a);
}