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

The following examples show how to use org.apache.atlas.AtlasErrorCode#UNKNOWN_TYPENAME . 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: SearchContext.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void validateAttributes(final AtlasStructType structType, final String... attributeNames) throws AtlasBaseException {
    for (String attributeName : attributeNames) {
        if (StringUtils.isNotEmpty(attributeName) && (structType == null || structType.getAttributeType(attributeName) == null)) {
            if (structType == null) {
                throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, "NULL");
            }

            String name = structType.getTypeName();
            if (name.equals(MATCH_ALL_ENTITY_TYPES.getTypeName())) {
                name = ALL_ENTITY_TYPES;
            } else if (name.equals(MATCH_ALL_CLASSIFICATION_TYPES.getTypeName())) {
                name = ALL_CLASSIFICATION_TYPES;
            }
            throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attributeName, name);
        }
    }
}
 
Example 2
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
@GraphTransaction
public List<String> getEntityGUIDS(final String typename) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getEntityGUIDS({})", typename);
    }

    if (StringUtils.isEmpty(typename) || !typeRegistry.isRegisteredType(typename)) {
        throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME);
    }

    List<String> ret = AtlasGraphUtilsV2.findEntityGUIDsByType(graph, typename);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getEntityGUIDS({})", typename);
    }

    return ret;
}
 
Example 3
Source File: SearchContext.java    From atlas with Apache License 2.0 5 votes vote down vote up
private Set<AtlasEntityType> getEntityTypes(String typeName) throws AtlasBaseException {

        Set<AtlasEntityType> entityTypes = null;
        //split multiple typeNames by comma
        if (StringUtils.isNotEmpty(typeName)) {

            String[] types        = typeName.split(TYPENAME_DELIMITER);
            Set<String> typeNames = new HashSet<>(Arrays.asList(types));
            entityTypes           = typeNames.stream().map(n ->
                                    getEntityType(n)).filter(Objects::nonNull).collect(Collectors.toSet());

            // Validate if the type name is incorrect
            if (CollectionUtils.isEmpty(entityTypes) || entityTypes.size() != typeNames.size()) {
                if (CollectionUtils.isNotEmpty(entityTypes)) {
                    Set<String> validEntityTypes = new HashSet<>();
                    for (AtlasEntityType entityType : entityTypes) {
                        String name = entityType.getTypeName();
                        if (name.equals(MATCH_ALL_ENTITY_TYPES.getTypeName())) {
                            validEntityTypes.add(ALL_ENTITY_TYPES);
                            continue;
                        }
                        validEntityTypes.add(entityType.getTypeName());
                    }

                    typeNames.removeAll(validEntityTypes);
                }

                throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, String.join(TYPENAME_DELIMITER, typeNames));
            }

        }

        return entityTypes;
    }
 
Example 4
Source File: StartEntityFetchByExportRequest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private List<String> getEntitiesForMatchTypeUsingUniqueAttributes(AtlasObjectId item, String matchType) throws AtlasBaseException {
    final String          queryTemplate = getQueryTemplateForMatchType(matchType);
    final String          typeName      = item.getTypeName();
    final AtlasEntityType entityType    = typeRegistry.getEntityTypeByName(typeName);

    Set<String> ret = new HashSet<>();
    if (entityType == null) {
        throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, typeName);
    }

    for (Map.Entry<String, Object> e : item.getUniqueAttributes().entrySet()) {
        String attrName  = e.getKey();
        Object attrValue = e.getValue();

        AtlasStructType.AtlasAttribute attribute = entityType.getAttribute(attrName);
        if (attribute == null || attrValue == null) {
            continue;
        }

        List<String> guids = executeGremlinQuery(queryTemplate,
                                getBindingsForObjectId(typeName, attribute.getQualifiedName(), e.getValue()));

        if (!CollectionUtils.isNotEmpty(guids)) {
            continue;
        }

        ret.addAll(guids);
    }

    return new ArrayList<>(ret);
}
 
Example 5
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public EntityMutationResponse updateEntity(AtlasObjectId objectId, AtlasEntityWithExtInfo updatedEntityInfo, boolean isPartialUpdate) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> updateEntity({}, {}, {})", objectId, updatedEntityInfo, isPartialUpdate);
    }

    if (objectId == null || updatedEntityInfo == null || updatedEntityInfo.getEntity() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "null entity-id/entity");
    }

    final String guid;

    if (AtlasTypeUtil.isAssignedGuid(objectId.getGuid())) {
        guid = objectId.getGuid();
    } else {
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(objectId.getTypeName());

        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, objectId.getTypeName());
        }

        guid = AtlasGraphUtilsV2.getGuidByUniqueAttributes(graph, typeRegistry.getEntityTypeByName(objectId.getTypeName()), objectId.getUniqueAttributes());
    }

    AtlasEntity entity = updatedEntityInfo.getEntity();

    entity.setGuid(guid);

    return createOrUpdate(new AtlasEntityStream(updatedEntityInfo), isPartialUpdate, false, false);
}
 
Example 6
Source File: ExportService.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
private List<AtlasEntityWithExtInfo> getStartingEntity(AtlasObjectId item, ExportContext context) throws AtlasBaseException {
    List<AtlasEntityWithExtInfo> ret = new ArrayList<>();

    if (StringUtils.isNotEmpty(item.getGuid())) {
        AtlasEntityWithExtInfo entity = entityGraphRetriever.toAtlasEntityWithExtInfo(item);

        if (entity != null) {
            ret = Collections.singletonList(entity);
        }
    } else if (StringUtils.isNotEmpty(item.getTypeName()) && MapUtils.isNotEmpty(item.getUniqueAttributes())) {
        String          typeName   = item.getTypeName();
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);

        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, typeName);
        }

        final String queryTemplate;
        if (StringUtils.equalsIgnoreCase(context.matchType, MATCH_TYPE_STARTS_WITH)) {
            queryTemplate = gremlinQueryProvider.getQuery(AtlasGremlinQuery.EXPORT_TYPE_STARTS_WITH);
        } else if (StringUtils.equalsIgnoreCase(context.matchType, MATCH_TYPE_ENDS_WITH)) {
            queryTemplate = gremlinQueryProvider.getQuery(AtlasGremlinQuery.EXPORT_TYPE_ENDS_WITH);
        } else if (StringUtils.equalsIgnoreCase(context.matchType, MATCH_TYPE_CONTAINS)) {
            queryTemplate = gremlinQueryProvider.getQuery(AtlasGremlinQuery.EXPORT_TYPE_CONTAINS);
        } else if (StringUtils.equalsIgnoreCase(context.matchType, MATCH_TYPE_MATCHES)) {
            queryTemplate = gremlinQueryProvider.getQuery(AtlasGremlinQuery.EXPORT_TYPE_MATCHES);
        } else { // default
            queryTemplate = gremlinQueryProvider.getQuery(AtlasGremlinQuery.EXPORT_TYPE_DEFAULT);
        }

        for (Map.Entry<String, Object> e : item.getUniqueAttributes().entrySet()) {
            String attrName  = e.getKey();
            Object attrValue = e.getValue();

            AtlasAttribute attribute = entityType.getAttribute(attrName);

            if (attribute == null || attrValue == null) {
                continue;
            }

            context.bindings.clear();
            context.bindings.put("typeName", typeName);
            context.bindings.put("attrName", attribute.getQualifiedName());
            context.bindings.put("attrValue", attrValue);

            List<String> guids = executeGremlinQueryForGuids(queryTemplate, context);

            if (CollectionUtils.isNotEmpty(guids)) {
                for (String guid : guids) {
                    AtlasEntityWithExtInfo entityWithExtInfo = entityGraphRetriever.toAtlasEntityWithExtInfo(guid);

                    if (entityWithExtInfo == null) {
                        continue;
                    }

                    ret.add(entityWithExtInfo);
                }
            }

            break;
        }

        LOG.info("export(item={}; matchType={}, fetchType={}): found {} entities", item, context.matchType, context.fetchType, ret.size());
    }

    return ret;
}