private String getLegacyEdgeLabel(AtlasEntityType entityType, String attributeName) { String ret = null; AtlasAttribute attribute = entityType.getAttribute(attributeName); if (attribute != null) { ret = "__" + attribute.getQualifiedName(); } return ret; } }
private String getLegacyEdgeLabel(AtlasEntityType entityType, String attributeName) { String ret = null; AtlasAttribute attribute = entityType.getAttribute(attributeName); if (attribute != null) { ret = "__" + attribute.getQualifiedName(); } return ret; }
private Object getDisplayText(AtlasVertex entityVertex, String entityTypeName) throws AtlasBaseException { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName); Object ret = null; if (entityType != null) { ret = getVertexAttribute(entityVertex, entityType.getAttribute(NAME)); if (ret == null) { ret = getVertexAttribute(entityVertex, entityType.getAttribute(DISPLAY_NAME)); } if (ret == null) { ret = getVertexAttribute(entityVertex, entityType.getAttribute(QUALIFIED_NAME)); } } return ret; }
private Object getDisplayText(AtlasVertex entityVertex, String entityTypeName) throws AtlasBaseException { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName); Object ret = null; if (entityType != null) { ret = getVertexAttribute(entityVertex, entityType.getAttribute(NAME)); if (ret == null) { ret = getVertexAttribute(entityVertex, entityType.getAttribute(DISPLAY_NAME)); } if (ret == null) { ret = getVertexAttribute(entityVertex, entityType.getAttribute(QUALIFIED_NAME)); } } return ret; }
@Override public String getRelationshipEdgeLabel(GremlinQueryComposer.Context context, String attributeName) { AtlasEntityType et = context.getActiveEntityType(); if(et == null) { return ""; } AtlasStructType.AtlasAttribute attr = et.getAttribute(attributeName); return (attr != null) ? attr.getRelationshipEdgeLabel() : ""; }
@Override public String getRelationshipEdgeLabel(GremlinQueryComposer.Context context, String attributeName) { AtlasEntityType et = context.getActiveEntityType(); if(et == null) { return ""; } AtlasStructType.AtlasAttribute attr = et.getAttribute(attributeName); return (attr != null) ? attr.getRelationshipEdgeLabel() : ""; }
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(); } }
@Override public boolean hasAttribute(GremlinQueryComposer.Context context, String typeName) { return (context.getActiveEntityType() != null) && (isSystemAttribute(typeName) || context.getActiveEntityType().getAttribute(typeName) != null); }
@Override public boolean hasAttribute(GremlinQueryComposer.Context context, String typeName) { return (context.getActiveEntityType() != null) && (isSystemAttribute(typeName) || context.getActiveEntityType().getAttribute(typeName) != null); }
private AtlasVertex getGlossaryTermVertex(String termName) { AtlasVertex ret = null; if (StringUtils.isNotEmpty(termName)) { AtlasEntityType termType = getTermEntityType(); AtlasAttribute attrName = termType.getAttribute(TermSearchProcessor.ATLAS_GLOSSARY_TERM_ATTR_QNAME); AtlasGraphQuery query = graph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, termType.getTypeName()) .has(attrName.getVertexPropertyName(), termName) .has(Constants.STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); Iterator<AtlasVertex> results = query.vertices().iterator(); ret = results.hasNext() ? results.next() : null; } return ret; }
private String getRelationshipEdgeLabel(String typeName, String relationshipTypeName) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); AtlasRelationshipDef relationshipDef = relationshipType.getRelationshipDef(); AtlasEntityType end1Type = relationshipType.getEnd1Type(); AtlasEntityType end2Type = relationshipType.getEnd2Type(); Set<String> vertexTypes = getTypeAndAllSuperTypes(typeName); AtlasAttribute attribute = null; if (vertexTypes.contains(end1Type.getTypeName())) { String attributeName = relationshipDef.getEndDef1().getName(); attribute = (attributeName != null) ? end1Type.getAttribute(attributeName) : null; } else if (vertexTypes.contains(end2Type.getTypeName())) { String attributeName = relationshipDef.getEndDef2().getName(); attribute = (attributeName != null) ? end2Type.getAttribute(attributeName) : null; } return (attribute != null) ? attribute.getRelationshipEdgeLabel() : null; }
private String getRelationshipEdgeLabel(String typeName, String relationshipTypeName) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); AtlasRelationshipDef relationshipDef = relationshipType.getRelationshipDef(); AtlasEntityType end1Type = relationshipType.getEnd1Type(); AtlasEntityType end2Type = relationshipType.getEnd2Type(); Set<String> vertexTypes = getTypeAndAllSuperTypes(typeName); AtlasAttribute attribute = null; if (vertexTypes.contains(end1Type.getTypeName())) { String attributeName = relationshipDef.getEndDef1().getName(); attribute = (attributeName != null) ? end1Type.getAttribute(attributeName) : null; } else if (vertexTypes.contains(end2Type.getTypeName())) { String attributeName = relationshipDef.getEndDef2().getName(); attribute = (attributeName != null) ? end2Type.getAttribute(attributeName) : null; } return (attribute != null) ? attribute.getRelationshipEdgeLabel() : null; } }
@Override public String getTypeFromEdge(GremlinQueryComposer.Context context, String item) { AtlasEntityType et = context.getActiveEntityType(); if(et == null) { return ""; } AtlasStructType.AtlasAttribute attr = et.getAttribute(item); if(attr == null) { return null; } AtlasType at = attr.getAttributeType(); switch (at.getTypeCategory()) { case ARRAY: AtlasArrayType arrType = ((AtlasArrayType)at); return getCollectionElementType(arrType.getElementType()); case MAP: AtlasMapType mapType = ((AtlasMapType)at); return getCollectionElementType(mapType.getValueType()); } return context.getActiveEntityType().getAttribute(item).getTypeName(); }
@Override void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferencesPhase2(typeRegistry); for (AtlasAttribute attribute : allAttributes.values()) { if (attribute.getInverseRefAttributeName() == null) { continue; } // Set the inverse reference attribute. AtlasType referencedType = typeRegistry.getType(attribute.getAttributeDef().getTypeName()); AtlasEntityType referencedEntityType = getReferencedEntityType(referencedType); AtlasAttribute inverseReference = referencedEntityType.getAttribute(attribute.getInverseRefAttributeName()); attribute.setInverseRefAttribute(inverseReference); } }
@Override public String getTypeFromEdge(GremlinQueryComposer.Context context, String item) { AtlasEntityType et = context.getActiveEntityType(); if(et == null) { return ""; } AtlasStructType.AtlasAttribute attr = et.getAttribute(item); if(attr == null) { return null; } AtlasType at = attr.getAttributeType(); switch (at.getTypeCategory()) { case ARRAY: AtlasArrayType arrType = ((AtlasArrayType)at); return getCollectionElementType(arrType.getElementType()); case MAP: AtlasMapType mapType = ((AtlasMapType)at); return getCollectionElementType(mapType.getValueType()); } return context.getActiveEntityType().getAttribute(item).getTypeName(); }
@Override public void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferencesPhase2(typeRegistry); for (AtlasAttribute attribute : allAttributes.values()) { if (attribute.getInverseRefAttributeName() == null) { continue; } // Set the inverse reference attribute. AtlasType referencedType = typeRegistry.getType(attribute.getAttributeDef().getTypeName()); AtlasEntityType referencedEntityType = getReferencedEntityType(referencedType); AtlasAttribute inverseReference = referencedEntityType.getAttribute(attribute.getInverseRefAttributeName()); attribute.setInverseRefAttribute(inverseReference); } }
@Test public void testValidConstraints() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); String failureMsg = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDef()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); AtlasEntityType typeTable = ttr.getEntityTypeByName(TYPE_TABLE); AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN); assertTrue(typeTable.getAttribute(ATTR_COLUMNS).isOwnedRef()); assertNull(typeTable.getAttribute(ATTR_COLUMNS).getInverseRefAttributeName()); assertFalse(typeColumn.getAttribute(ATTR_TABLE).isOwnedRef()); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttributeName(), ATTR_COLUMNS); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttribute(), typeTable.getAttribute(ATTR_COLUMNS)); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN); }
private void addRelationshipAttributeToEndType(AtlasRelationshipEndDef endDef, AtlasEntityType entityType, String attrTypeName, AtlasTypeRegistry typeRegistry, String relationshipLabel) throws AtlasBaseException { String attrName = (endDef != null) ? endDef.getName() : null; if (StringUtils.isEmpty(attrName)) { return; } AtlasAttribute attribute = entityType.getAttribute(attrName); // if relationshipLabel is null, then legacyLabel is mentioned at both ends, // use the respective end's legacyLabel as relationshipLabel if (relationshipLabel == null) { relationshipLabel = getLegacyEdgeLabel(entityType, attrName); } if (attribute == null) { //attr doesn't exist in type - is a new relationship attribute if (endDef.getCardinality() == Cardinality.SET) { attrTypeName = AtlasBaseTypeDef.getArrayTypeName(attrTypeName); } attribute = new AtlasAttribute(entityType, new AtlasAttributeDef(attrName, attrTypeName), typeRegistry.getType(attrTypeName), relationshipLabel); } else { // attribute already exists (legacy attribute which is also a relationship attribute) // add relationshipLabel information to existing attribute attribute.setRelationshipEdgeLabel(relationshipLabel); } entityType.addRelationshipAttribute(attrName, attribute); entityType.addRelationshipAttributeType(attrName, this); }
private void addRelationshipAttributeToEndType(AtlasRelationshipEndDef endDef, AtlasEntityType entityType, String attrTypeName, AtlasTypeRegistry typeRegistry, String relationshipLabel) throws AtlasBaseException { String attrName = (endDef != null) ? endDef.getName() : null; if (StringUtils.isEmpty(attrName)) { return; } AtlasAttribute attribute = entityType.getAttribute(attrName); // if relationshipLabel is null, then legacyLabel is mentioned at both ends, // use the respective end's legacyLabel as relationshipLabel if (relationshipLabel == null) { relationshipLabel = getLegacyEdgeLabel(entityType, attrName); } if (attribute == null) { //attr doesn't exist in type - is a new relationship attribute if (endDef.getCardinality() == Cardinality.SET) { attrTypeName = AtlasBaseTypeDef.getArrayTypeName(attrTypeName); } attribute = new AtlasAttribute(entityType, new AtlasAttributeDef(attrName, attrTypeName), typeRegistry.getType(attrTypeName), relationshipLabel); } else { // attribute already exists (legacy attribute which is also a relationship attribute) // add relationshipLabel information to existing attribute attribute.setRelationshipEdgeLabel(relationshipLabel); } entityType.addRelationshipAttribute(attrName, attribute); entityType.addRelationshipAttributeType(attrName, this); }
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()); } } } if (isClassificationEdge(edge)) { AtlasVertex classificationVertex = edge.getInVertex(); AtlasGraphUtilsV2.setEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_STATUS, DELETED.name()); } deleteEdge(edge, force); }