Java Code Examples for org.apache.atlas.type.AtlasStructType#AtlasAttribute
The following examples show how to use
org.apache.atlas.type.AtlasStructType#AtlasAttribute .
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: DeleteHandlerV1.java From incubator-atlas with Apache License 2.0 | 6 votes |
protected void deleteEdge(AtlasEdge edge, boolean updateInverseAttribute, boolean force) throws AtlasBaseException { //update inverse attribute if (updateInverseAttribute) { AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(edge.getLabel()); AtlasType parentType = typeRegistry.getType(atlasEdgeLabel.getTypeName()); if (parentType instanceof AtlasEntityType) { AtlasEntityType parentEntityType = (AtlasEntityType) parentType; AtlasStructType.AtlasAttribute attribute = parentEntityType.getAttribute(atlasEdgeLabel.getAttributeName()); if (attribute.getInverseRefAttribute() != null) { deleteEdgeBetweenVertices(edge.getInVertex(), edge.getOutVertex(), attribute.getInverseRefAttribute()); } } } deleteEdge(edge, force); }
Example 2
Source File: RangerAtlasEntityWithTags.java From ranger with Apache License 2.0 | 6 votes |
public String getTagAttributeType(String tagTypeName, String tagAttributeName) { String ret = DEFAULT_TAG_ATTRIBUTE_TYPE; if (typeRegistry != null) { AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(tagTypeName); if (classificationType != null) { AtlasStructType.AtlasAttribute atlasAttribute = classificationType.getAttribute(tagAttributeName); if (atlasAttribute != null) { ret = atlasAttribute.getTypeName(); } } } return ret; }
Example 3
Source File: ExportTypeProcessor.java From atlas with Apache License 2.0 | 5 votes |
private void addRelationshipTypes(AtlasEntityType entityType, ExportService.ExportContext context) { for (Map.Entry<String, Map<String, AtlasStructType.AtlasAttribute>> entry : entityType.getRelationshipAttributes().entrySet()) { for (String relationshipType : entry.getValue().keySet()) { addRelationshipType(relationshipType, context); } } }
Example 4
Source File: StartEntityFetchByExportRequest.java From atlas with Apache License 2.0 | 5 votes |
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: EntityAuditListener.java From atlas with Apache License 2.0 | 5 votes |
private Map<String, Object> pruneEntityAttributesForAudit(Referenceable entity) throws AtlasException { Map<String, Object> ret = null; Map<String, Object> entityAttributes = entity.getValuesMap(); List<String> excludeAttributes = auditRepository.getAuditExcludeAttributes(entity.getTypeName()); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (CollectionUtils.isNotEmpty(excludeAttributes) && MapUtils.isNotEmpty(entityAttributes) && entityType != null) { for (AtlasStructType.AtlasAttribute attribute : entityType.getAllAttributes().values()) { String attrName = attribute.getName(); Object attrValue = entityAttributes.get(attrName); if (excludeAttributes.contains(attrName)) { if (ret == null) { ret = new HashMap<>(); } ret.put(attrName, attrValue); entityAttributes.remove(attrName); } else if (attribute.isOwnedRef()) { if (attrValue instanceof Collection) { for (Object arrElem : (Collection) attrValue) { if (arrElem instanceof Referenceable) { ret = pruneAttributes(ret, (Referenceable) arrElem); } } } else if (attrValue instanceof Referenceable) { ret = pruneAttributes(ret, (Referenceable) attrValue); } } } } return ret; }
Example 6
Source File: EntityAuditListener.java From atlas with Apache License 2.0 | 5 votes |
private void restoreEntityAttributes(Referenceable entity, Map<String, Object> prunedAttributes) throws AtlasException { if (MapUtils.isEmpty(prunedAttributes)) { return; } AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (entityType != null && MapUtils.isNotEmpty(entityType.getAllAttributes())) { Map<String, Object> entityAttributes = entity.getValuesMap(); for (AtlasStructType.AtlasAttribute attribute : entityType.getAllAttributes().values()) { String attrName = attribute.getName(); Object attrValue = entityAttributes.get(attrName); if (prunedAttributes.containsKey(attrName)) { entity.set(attrName, prunedAttributes.get(attrName)); } else if (attribute.isOwnedRef()) { if (attrValue instanceof Collection) { for (Object arrElem : (Collection) attrValue) { if (arrElem instanceof Referenceable) { restoreAttributes(prunedAttributes, (Referenceable) arrElem); } } } else if (attrValue instanceof Referenceable) { restoreAttributes(prunedAttributes, (Referenceable) attrValue); } } } } }
Example 7
Source File: GremlinQueryComposerTest.java From atlas with Apache License 2.0 | 5 votes |
@Override public AtlasType getType(String typeName) throws AtlasBaseException { AtlasType type; if(typeName.equals("PII") || typeName.equals("Dimension")) { type = mock(AtlasType.class); when(type.getTypeCategory()).thenReturn(TypeCategory.CLASSIFICATION); } else { type = mock(AtlasEntityType.class); when(type.getTypeCategory()).thenReturn(TypeCategory.ENTITY); AtlasStructType.AtlasAttribute attr = mock(AtlasStructType.AtlasAttribute.class); AtlasStructDef.AtlasAttributeDef def = mock(AtlasStructDef.AtlasAttributeDef.class); when(def.getIndexType()).thenReturn(AtlasStructDef.AtlasAttributeDef.IndexType.DEFAULT); when(attr.getAttributeDef()).thenReturn(def); AtlasStructType.AtlasAttribute attr_s = mock(AtlasStructType.AtlasAttribute.class); AtlasStructDef.AtlasAttributeDef def_s = mock(AtlasStructDef.AtlasAttributeDef.class); when(def_s.getIndexType()).thenReturn(AtlasStructDef.AtlasAttributeDef.IndexType.STRING); when(attr_s.getAttributeDef()).thenReturn(def_s); when(((AtlasEntityType) type).getAttribute(anyString())).thenReturn(attr); when(((AtlasEntityType) type).getAttribute(eq("name"))).thenReturn(attr_s); } if(typeName.equals("PIII")) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND); } when(type.getTypeName()).thenReturn(typeName); return type; }
Example 8
Source File: AtlasBusinessMetadataDefStoreV2Test.java From atlas with Apache License 2.0 | 5 votes |
@Test public void createBusinessMetadataDefIsOptionalIsUnique() throws AtlasBaseException { createBusinessMetadataTypesIsOptionalIsUnique(businessMetadataName); AtlasBusinessMetadataType businessMetadataType = typeRegistry.getBusinessMetadataTypeByName(businessMetadataName); AtlasStructType.AtlasAttribute atlasAttribute = businessMetadataType.getAttribute("test_business_attribute1"); AtlasStructDef.AtlasAttributeDef atlasAttributeDef = atlasAttribute.getAttributeDef(); Assert.assertFalse(atlasAttributeDef.getIsOptional()); Assert.assertTrue(atlasAttributeDef.getIsUnique()); }
Example 9
Source File: AtlasBusinessMetadataDefStoreV2Test.java From atlas with Apache License 2.0 | 5 votes |
@Test public void createBusinessMetadataDefMultivaluedAttributes() throws AtlasBaseException { createEnumTypes(); createBusinessMetadataTypesMultivaluedAttributes(businessMetadataName); AtlasBusinessMetadataType businessMetadataType = typeRegistry.getBusinessMetadataTypeByName(businessMetadataName); Assert.assertEquals(businessMetadataType.getAllAttributes().size(), 10); Map<String, AtlasStructType.AtlasAttribute> attributeMap = businessMetadataType.getAllAttributes(); for (Map.Entry<String, AtlasStructType.AtlasAttribute> e : attributeMap.entrySet()) { AtlasStructType.AtlasAttribute atlasAttribute = e.getValue(); AtlasStructDef.AtlasAttributeDef atlasAttributeDef = atlasAttribute.getAttributeDef(); Assert.assertTrue(atlasAttributeDef.getTypeName().startsWith("array<")); } }
Example 10
Source File: DiscoveryREST.java From atlas with Apache License 2.0 | 4 votes |
/** * Retrieve data for the specified attribute search query * * @param attrName Attribute name * @param attrValuePrefix Attibute value to search on * @param typeName limit the result to only entities of specified type or its sub-types * @param limit limit the result set to only include the specified number of entries * @param offset start offset of the result set (useful for pagination) * @return Search results * @throws AtlasBaseException * @HTTP 200 On successful FullText lookup with some results, might return an empty list if execution succeeded * without any results * @HTTP 400 Invalid wildcard or query parameters */ @GET @Path("/attribute") public AtlasSearchResult searchUsingAttribute(@QueryParam("attrName") String attrName, @QueryParam("attrValuePrefix") String attrValuePrefix, @QueryParam("typeName") String typeName, @QueryParam("limit") int limit, @QueryParam("offset") int offset) throws AtlasBaseException { Servlets.validateQueryParamLength("attrName", attrName); Servlets.validateQueryParamLength("attrValuePrefix", attrValuePrefix); Servlets.validateQueryParamLength("typeName", typeName); AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingAttribute(" + attrName + "," + attrValuePrefix + "," + typeName + "," + limit + "," + offset + ")"); } if (StringUtils.isEmpty(attrName) && StringUtils.isEmpty(attrValuePrefix)) { throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, String.format("attrName : %s, attrValue: %s for attribute search.", attrName, attrValuePrefix)); } if (StringUtils.isEmpty(attrName)) { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); if (entityType != null) { String[] defaultAttrNames = new String[] { AtlasClient.QUALIFIED_NAME, AtlasClient.NAME }; for (String defaultAttrName : defaultAttrNames) { AtlasStructType.AtlasAttribute attribute = entityType.getAttribute(defaultAttrName); if (attribute != null) { attrName = defaultAttrName; break; } } } if (StringUtils.isEmpty(attrName)) { attrName = AtlasClient.QUALIFIED_NAME; } } SearchParameters searchParams = new SearchParameters(); FilterCriteria attrFilter = new FilterCriteria(); attrFilter.setAttributeName(StringUtils.isEmpty(attrName) ? AtlasClient.QUALIFIED_NAME : attrName); attrFilter.setOperator(SearchParameters.Operator.STARTS_WITH); attrFilter.setAttributeValue(attrValuePrefix); searchParams.setTypeName(typeName); searchParams.setEntityFilters(attrFilter); searchParams.setOffset(offset); searchParams.setLimit(limit); return searchWithParameters(searchParams); } finally { AtlasPerfTracer.log(perf); } }
Example 11
Source File: GremlinQueryComposer.java From atlas with Apache License 2.0 | 4 votes |
public void addWhere(String lhs, String operator, String rhs) { if (LOG.isDebugEnabled()) { LOG.debug("addWhere(lhs={}, operator={}, rhs={})", lhs, operator, rhs); } String currentType = context.getActiveTypeName(); IdentifierHelper.Info org = null; IdentifierHelper.Info lhsI = createInfo(lhs); if (!lhsI.isPrimitive()) { introduceType(lhsI); org = lhsI; lhsI = createInfo(lhs); lhsI.setTypeName(org.getTypeName()); } if (!context.validator.isValidQualifiedName(lhsI.getQualifiedName(), lhsI.getRaw())) { return; } if (lhsI.isDate()) { rhs = parseDate(rhs); } else if (lhsI.isNumeric()) { rhs = parseNumber(rhs, this.context); } rhs = addQuotesIfNecessary(lhsI, rhs); SearchParameters.Operator op = SearchParameters.Operator.fromString(operator); if (op == SearchParameters.Operator.LIKE) { final AtlasStructType.AtlasAttribute attribute = context.getActiveEntityType().getAttribute(lhsI.getAttributeName()); final AtlasStructDef.AtlasAttributeDef.IndexType indexType = attribute.getAttributeDef().getIndexType(); if (indexType == AtlasStructDef.AtlasAttributeDef.IndexType.STRING || !containsNumberAndLettersOnly(rhs)) { add(GremlinClause.STRING_CONTAINS, getPropertyForClause(lhsI), IdentifierHelper.getFixedRegEx(rhs)); } else { add(GremlinClause.TEXT_CONTAINS, getPropertyForClause(lhsI), IdentifierHelper.getFixedRegEx(rhs)); } } else if (op == SearchParameters.Operator.IN) { add(GremlinClause.HAS_OPERATOR, getPropertyForClause(lhsI), "within", rhs); } else { add(GremlinClause.HAS_OPERATOR, getPropertyForClause(lhsI), op.getSymbols()[1], rhs); } // record that the attribute has been processed so that the select clause doesn't add a attr presence check attributesProcessed.add(lhsI.getQualifiedName()); if (org != null && org.isReferredType()) { add(GremlinClause.DEDUP); if (org.getEdgeDirection() != null) { GremlinClause gremlinClauseForEdgeLabel = org.getEdgeDirection().equals(IN) ? GremlinClause.OUT : GremlinClause.IN; add(gremlinClauseForEdgeLabel, org.getEdgeLabel()); } else { add(GremlinClause.OUT, org.getEdgeLabel()); } context.registerActive(currentType); } }
Example 12
Source File: AtlasServerService.java From atlas with Apache License 2.0 | 4 votes |
private String getVertexPropertyName(AtlasEntity entity, String attributeName) throws AtlasBaseException { AtlasEntityType type = (AtlasEntityType) typeRegistry.getType(entity.getTypeName()); AtlasStructType.AtlasAttribute attribute = type.getAttribute(attributeName); return attribute.getVertexPropertyName(); }
Example 13
Source File: DeleteHandlerV1.java From incubator-atlas with Apache License 2.0 | 4 votes |
/** * Deleting any type vertex. Goes over the complex attributes and removes the references * @param instanceVertex * @throws AtlasException */ protected void deleteTypeVertex(AtlasVertex instanceVertex, boolean force) throws AtlasBaseException { LOG.debug("Deleting {}", string(instanceVertex)); String typeName = GraphHelper.getTypeName(instanceVertex); AtlasType parentType = typeRegistry.getType(typeName); if (parentType instanceof AtlasStructType) { AtlasStructType structType = (AtlasStructType) parentType; boolean isEntityType = (parentType instanceof AtlasEntityType); for (AtlasStructType.AtlasAttribute attributeInfo : structType.getAllAttributes().values()) { LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex)); boolean isOwned = isEntityType && attributeInfo.isOwnedRef(); AtlasType attrType = attributeInfo.getAttributeType(); String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(structType, attributeInfo.getName()); switch (attrType.getTypeCategory()) { case OBJECT_ID_TYPE: //If its class attribute, delete the reference deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isOwned); break; case STRUCT: //If its struct attribute, delete the reference deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), false); break; case ARRAY: //For array attribute, if the element is struct/class, delete all the references AtlasArrayType arrType = (AtlasArrayType) attrType; AtlasType elemType = arrType.getElementType(); if (AtlasGraphUtilsV1.isReference(elemType.getTypeCategory())) { Iterator<AtlasEdge> edges = graphHelper.getOutGoingEdgesByLabel(instanceVertex, edgeLabel); if (edges != null) { while (edges.hasNext()) { AtlasEdge edge = edges.next(); deleteEdgeReference(edge, elemType.getTypeCategory(), isOwned, false); } } } break; case MAP: //For map attribute, if the value type is struct/class, delete all the references AtlasMapType mapType = (AtlasMapType) attrType; AtlasType keyType = mapType.getKeyType(); TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory(); String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(structType, attributeInfo.getName()); if (AtlasGraphUtilsV1.isReference(valueTypeCategory)) { List<Object> keys = EntityGraphMapper.getArrayElementsProperty(keyType, instanceVertex, propertyName); if (keys != null) { for (Object key : keys) { String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, (String) key); deleteEdgeReference(instanceVertex, mapEdgeLabel, valueTypeCategory, isOwned); } } } } } } deleteVertex(instanceVertex, force); }
Example 14
Source File: SearchAggregator.java From atlas with Apache License 2.0 | 2 votes |
/** * returns aggregation metrics for passed in aggregation fields. * @param aggregationFields the set of aggregation attribute names. * @param aggregationAttrbutes the set of aggregationAttributes * @return the result of aggreggations by aggregation fields. */ Map<String, List<AtlasAggregationEntry>> getAggregatedMetrics(Set<String> aggregationFields, Set<AtlasStructType.AtlasAttribute> aggregationAttrbutes);