public Map<String, Object> getEntityUniqueAttribute(AtlasVertex entityVertex) throws AtlasBaseException { Map<String, Object> ret = null; String typeName = AtlasGraphUtilsV2.getTypeName(entityVertex); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); if (entityType != null && MapUtils.isNotEmpty(entityType.getUniqAttributes())) { for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) { Object val = mapVertexToAttribute(entityVertex, attribute, null, false); if (val != null) { if (ret == null) { ret = new HashMap<>(); } ret.put(attribute.getName(), val); } } } return ret; }
public AtlasObjectId toAtlasObjectId(AtlasEntity entity) { AtlasObjectId ret = null; AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (entityType != null) { Map<String, Object> uniqueAttributes = new HashMap<>(); for (String attributeName : entityType.getUniqAttributes().keySet()) { Object attrValue = entity.getAttribute(attributeName); if (attrValue != null) { uniqueAttributes.put(attributeName, attrValue); } } ret = new AtlasObjectId(entity.getGuid(), entity.getTypeName(), uniqueAttributes); } return ret; }
public AtlasObjectId toAtlasObjectId(AtlasVertex entityVertex) throws AtlasBaseException { AtlasObjectId ret = null; String typeName = entityVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); if (entityType != null) { Map<String, Object> uniqueAttributes = new HashMap<>(); for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) { Object attrValue = getVertexAttribute(entityVertex, attribute); if (attrValue != null) { uniqueAttributes.put(attribute.getName(), attrValue); } } ret = new AtlasObjectId(entityVertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class), typeName, uniqueAttributes); } return ret; }
public AtlasObjectId toAtlasObjectId(AtlasVertex entityVertex) throws AtlasBaseException { AtlasObjectId ret = null; String typeName = entityVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); if (entityType != null) { Map<String, Object> uniqueAttributes = new HashMap<>(); for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) { Object attrValue = getVertexAttribute(entityVertex, attribute); if (attrValue != null) { uniqueAttributes.put(attribute.getName(), attrValue); } } ret = new AtlasObjectId(entityVertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class), typeName, uniqueAttributes); } return ret; }
public String getEntityId(AtlasEntityHeader entity, AtlasTypeRegistry typeRegistry) { Object ret = null; if (entity != null) { AtlasEntityType entityType = typeRegistry == null ? null : typeRegistry.getEntityTypeByName(entity.getTypeName()); Map<String, AtlasAttribute> uniqAttributes = entityType == null ? null : entityType.getUniqAttributes(); if (MapUtils.isEmpty(uniqAttributes)) { ret = entity.getAttribute(DEFAULT_ENTITY_ID_ATTRIBUTE); } else { for (AtlasAttribute uniqAttribute : uniqAttributes.values()) { ret = entity.getAttribute(uniqAttribute.getName()); if (ret != null) { break; } } } } return ret == null ? "" : ret.toString(); }
public AtlasEntityHeader toAtlasEntityHeader(AtlasEntity entity) { AtlasEntityHeader ret = null; String typeName = entity.getTypeName(); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); if (entityType != null) { Map<String, Object> uniqueAttributes = new HashMap<>(); for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) { Object attrValue = entity.getAttribute(attribute.getName()); if (attrValue != null) { uniqueAttributes.put(attribute.getName(), attrValue); } } ret = new AtlasEntityHeader(entity.getTypeName(), entity.getGuid(), uniqueAttributes); if (CollectionUtils.isNotEmpty(entity.getClassifications())) { List<AtlasClassification> classifications = new ArrayList<>(entity.getClassifications().size()); List<String> classificationNames = new ArrayList<>(entity.getClassifications().size()); for (AtlasClassification classification : entity.getClassifications()) { classifications.add(classification); classificationNames.add(classification.getTypeName()); } ret.setClassifications(classifications); ret.setClassificationNames(classificationNames); } if (CollectionUtils.isNotEmpty(entity.getMeanings())) { ret.setMeanings(entity.getMeanings()); ret.setMeaningNames(entity.getMeanings().stream().map(AtlasTermAssignmentHeader::getDisplayText).collect(Collectors.toList())); } } return ret; }
public AtlasEntityHeader toAtlasEntityHeader(AtlasEntity entity) { AtlasEntityHeader ret = null; String typeName = entity.getTypeName(); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); if (entityType != null) { Map<String, Object> uniqueAttributes = new HashMap<>(); for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) { Object attrValue = entity.getAttribute(attribute.getName()); if (attrValue != null) { uniqueAttributes.put(attribute.getName(), attrValue); } } ret = new AtlasEntityHeader(entity.getTypeName(), entity.getGuid(), uniqueAttributes); if (CollectionUtils.isNotEmpty(entity.getClassifications())) { List<AtlasClassification> classifications = new ArrayList<>(entity.getClassifications().size()); List<String> classificationNames = new ArrayList<>(entity.getClassifications().size()); for (AtlasClassification classification : entity.getClassifications()) { classifications.add(classification); classificationNames.add(classification.getTypeName()); } ret.setClassifications(classifications); ret.setClassificationNames(classificationNames); } if (CollectionUtils.isNotEmpty(entity.getMeanings())) { ret.setMeanings(entity.getMeanings()); ret.setMeaningNames(entity.getMeanings().stream().map(AtlasTermAssignmentHeader::getDisplayText).collect(Collectors.toList())); } } return ret; }
/** * For the given type, finds an unique attribute and checks if there is an existing instance with the same * unique value * * @param classType * @param instance * @return * @throws AtlasException */ public AtlasVertex getVertexForInstanceByUniqueAttribute(AtlasEntityType classType, Referenceable instance) throws AtlasException { if (LOG.isDebugEnabled()) { LOG.debug("Checking if there is an instance with the same unique attributes for instance {}", instance.toShortString()); } AtlasVertex result = null; for (AtlasAttribute attributeInfo : classType.getUniqAttributes().values()) { String propertyKey = attributeInfo.getQualifiedName(); try { result = findVertex(propertyKey, instance.get(attributeInfo.getName()), ENTITY_TYPE_PROPERTY_KEY, classType.getTypeName(), STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name()); if (LOG.isDebugEnabled()) { LOG.debug("Found vertex by unique attribute : {}={}", propertyKey, instance.get(attributeInfo.getName())); } } catch (EntityNotFoundException e) { //Its ok if there is no entity with the same unique value } } return result; }
private AtlasEntityHeader constructHeader(AtlasEntity entity, final AtlasEntityType type, AtlasVertex vertex) { AtlasEntityHeader header = new AtlasEntityHeader(entity.getTypeName()); header.setGuid(getIdFromVertex(vertex)); for (AtlasAttribute attribute : type.getUniqAttributes().values()) { header.setAttribute(attribute.getName(), entity.getAttribute(attribute.getName())); } return header; }
for (AtlasAttribute attributeInfo : classType.getUniqAttributes().values()) { String propertyKey = attributeInfo.getQualifiedName(); AttributeValueMap mapForAttribute = new AttributeValueMap();
private AtlasEntityHeader constructHeader(AtlasEntity entity, final AtlasEntityType type, AtlasVertex vertex) { AtlasEntityHeader header = new AtlasEntityHeader(entity.getTypeName()); header.setGuid(getIdFromVertex(vertex)); for (AtlasAttribute attribute : type.getUniqAttributes().values()) { header.setAttribute(attribute.getName(), entity.getAttribute(attribute.getName())); } return header; }
public static AtlasVertex findByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> attrValues) { AtlasVertex vertex = null; final Map<String, AtlasAttribute> uniqueAttributes = entityType.getUniqAttributes(); if (MapUtils.isNotEmpty(uniqueAttributes) && MapUtils.isNotEmpty(attrValues)) { for (AtlasAttribute attribute : uniqueAttributes.values()) { Object attrValue = attrValues.get(attribute.getName()); if (attrValue == null) { continue; } if (canUseIndexQuery(entityType, attribute.getName())) { vertex = AtlasGraphUtilsV2.getAtlasVertexFromIndexQuery(entityType, attribute, attrValue); } else { vertex = AtlasGraphUtilsV2.findByTypeAndPropertyName(entityType.getTypeName(), attribute.getVertexPropertyName(), attrValue); // if no instance of given typeName is found, try to find an instance of type's sub-type if (vertex == null && !entityType.getAllSubTypes().isEmpty()) { vertex = AtlasGraphUtilsV2.findBySuperTypeAndPropertyName(entityType.getTypeName(), attribute.getVertexPropertyName(), attrValue); } } if (vertex != null) { if (LOG.isDebugEnabled()) { LOG.debug("findByUniqueAttributes(type={}, attrName={}, attrValue={}: found vertex {}", entityType.getTypeName(), attribute.getName(), attrValue, vertex); } break; } } } return vertex; }
final Map<String, AtlasAttribute> uniqueAttributes = entityType.getUniqAttributes();