public void normalizeRelationshipAttributeValues(Map<String, Object> obj) { if (obj != null) { for (AtlasAttribute attribute : relationshipAttributes.values()) { String attributeName = attribute.getName(); AtlasAttributeDef attributeDef = attribute.getAttributeDef(); if (obj.containsKey(attributeName)) { Object attributeValue = getNormalizedValue(obj.get(attributeName), attributeDef); obj.put(attributeName, attributeValue); } } } }
protected Map<String, AtlasAttribute> getUniqueAttributes(Map<String, AtlasAttribute> attributes) { Map<String, AtlasAttribute> ret = new HashMap<>(); if (MapUtils.isNotEmpty(attributes)) { for (AtlasAttribute attribute : attributes.values()) { if (attribute.getAttributeDef().getIsUnique()) { ret.put(attribute.getName(), attribute); } } } return Collections.unmodifiableMap(ret); }
protected Map<String, AtlasAttribute> getUniqueAttributes(Map<String, AtlasAttribute> attributes) { Map<String, AtlasAttribute> ret = new HashMap<>(); if (MapUtils.isNotEmpty(attributes)) { for (AtlasAttribute attribute : attributes.values()) { if (attribute.getAttributeDef().getIsUnique()) { ret.put(attribute.getName(), attribute); } } } return Collections.unmodifiableMap(ret); }
@VisibleForTesting public static String toJsonFromAttribute(AtlasAttribute attribute) { AtlasAttributeDef attributeDef = attribute.getAttributeDef(); Map<String, Object> attribInfo = new HashMap<>();
public static AttributeDefinition toV1AttributeDefinition(AtlasStructType.AtlasAttribute attribute) { AtlasAttributeDef attributeDef = attribute.getAttributeDef(); AttributeDefinition ret = new AttributeDefinition();
private boolean validateRelationshipAttributes(Object obj) { if (obj != null && MapUtils.isNotEmpty(relationshipAttributes)) { if (obj instanceof AtlasEntity) { AtlasEntity entityObj = (AtlasEntity) obj; for (AtlasAttribute attribute : relationshipAttributes.values()) { Object attributeValue = entityObj.getRelationshipAttribute(attribute.getName()); AtlasAttributeDef attributeDef = attribute.getAttributeDef(); if (!isAssignableValue(attributeValue, attributeDef)) { return false; } } } else if (obj instanceof Map) { Map map = AtlasTypeUtil.toRelationshipAttributes((Map) obj); for (AtlasAttribute attribute : relationshipAttributes.values()) { Object attributeValue = map.get(attribute.getName()); AtlasAttributeDef attributeDef = attribute.getAttributeDef(); if (!isAssignableValue(attributeValue, attributeDef)) { return false; } } } else { return false; } } return true; }
ret = mapVertexToPrimitive(entityVertex, attribute.getVertexPropertyName(), attribute.getAttributeDef()); break; case ENUM:
private void mapAttribute(AtlasAttribute attribute, Object attrValue, AtlasVertex vertex, EntityOperation op, EntityMutationContext context) throws AtlasBaseException { if (attrValue == null) { AtlasAttributeDef attributeDef = attribute.getAttributeDef(); AtlasType attrType = attribute.getAttributeType(); if (attrType.getTypeCategory() == TypeCategory.PRIMITIVE) { if (attributeDef.getDefaultValue() != null) { attrValue = attrType.createDefaultValue(attributeDef.getDefaultValue()); } else { if (attribute.getAttributeDef().getIsOptional()) { attrValue = attrType.createOptionalDefaultValue(); } else { attrValue = attrType.createDefaultValue(); } } } } AttributeMutationContext ctx = new AttributeMutationContext(op, vertex, attribute, attrValue); mapToVertexByTypeCategory(ctx, context); }
private void mapAttribute(AtlasAttribute attribute, Object attrValue, AtlasVertex vertex, EntityOperation op, EntityMutationContext context) throws AtlasBaseException { if (attrValue == null) { AtlasAttributeDef attributeDef = attribute.getAttributeDef(); AtlasType attrType = attribute.getAttributeType(); if (attrType.getTypeCategory() == TypeCategory.PRIMITIVE) { if (attributeDef.getDefaultValue() != null) { attrValue = attrType.createDefaultValue(attributeDef.getDefaultValue()); } else { if (attribute.getAttributeDef().getIsOptional()) { attrValue = attrType.createOptionalDefaultValue(); } else { attrValue = attrType.createDefaultValue(); } } } } AttributeMutationContext ctx = new AttributeMutationContext(op, vertex, attribute, attrValue); mapToVertexByTypeCategory(ctx, context); }
@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); } }
public AtlasAttributeDef getAttributeDef() { return attribute.getAttributeDef(); }
private void mapAttributes(AtlasEdge edge, AtlasRelationshipWithExtInfo relationshipWithExtInfo) throws AtlasBaseException { AtlasRelationship relationship = relationshipWithExtInfo.getRelationship(); AtlasType objType = typeRegistry.getType(relationship.getTypeName()); if (!(objType instanceof AtlasRelationshipType)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, relationship.getTypeName()); } AtlasRelationshipType relationshipType = (AtlasRelationshipType) objType; for (AtlasAttribute attribute : relationshipType.getAllAttributes().values()) { // mapping only primitive attributes Object attrValue = mapVertexToPrimitive(edge, attribute.getVertexPropertyName(), attribute.getAttributeDef()); relationship.setAttribute(attribute.getName(), attrValue); } } }
public static AttributeDefinition toAttributeDefinition(AtlasAttribute attribute) { final AtlasAttributeDef attrDef = attribute.getAttributeDef(); AttributeDefinition ret = new AttributeDefinition(); ret.setName(attrDef.getName()); ret.setDataTypeName(attrDef.getTypeName()); ret.setMultiplicity(getMultiplicity(attrDef)); ret.setIsComposite(attribute.isOwnedRef()); ret.setIsUnique(attrDef.getIsUnique()); ret.setIsIndexable(attrDef.getIsIndexable()); ret.setReverseAttributeName(attribute.getInverseRefAttributeName()); ret.setDescription(attrDef.getDescription()); ret.setDefaultValue(attrDef.getDefaultValue()); return ret; } }
public AtlasAttributeDef getAttributeDef(String attributeName) { AtlasAttribute attribute = getAttribute(attributeName); return attribute != null ? attribute.getAttributeDef() : null; }
@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); } }
private void mapAttributes(AtlasEdge edge, AtlasRelationshipWithExtInfo relationshipWithExtInfo) throws AtlasBaseException { AtlasRelationship relationship = relationshipWithExtInfo.getRelationship(); AtlasType objType = typeRegistry.getType(relationship.getTypeName()); if (!(objType instanceof AtlasRelationshipType)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, relationship.getTypeName()); } AtlasRelationshipType relationshipType = (AtlasRelationshipType) objType; for (AtlasAttribute attribute : relationshipType.getAllAttributes().values()) { // mapping only primitive attributes Object attrValue = mapVertexToPrimitive(edge, attribute.getVertexPropertyName(), attribute.getAttributeDef()); relationship.setAttribute(attribute.getName(), attrValue); } } }
public AtlasAttributeDef getAttributeDef() { return attribute.getAttributeDef(); }
public AtlasAttributeDef getAttributeDef(String attributeName) { AtlasAttribute attribute = getAttribute(attributeName); return attribute != null ? attribute.getAttributeDef() : null; }
public static AttributeDefinition toAttributeDefinition(AtlasAttribute attribute) { final AtlasAttributeDef attrDef = attribute.getAttributeDef(); AttributeDefinition ret = new AttributeDefinition(); ret.setName(attrDef.getName()); ret.setDataTypeName(attrDef.getTypeName()); ret.setMultiplicity(AtlasTypeUtil.getMultiplicity(attrDef)); ret.setIsComposite(attribute.isOwnedRef()); ret.setIsUnique(attrDef.getIsUnique()); ret.setIsIndexable(attrDef.getIsIndexable()); ret.setReverseAttributeName(attribute.getInverseRefAttributeName()); ret.setDescription(attrDef.getDescription()); ret.setDefaultValue(attrDef.getDefaultValue()); return ret; } }
private void normalizeRelationshipAttributeValues(AtlasStruct obj) { if (obj != null && obj instanceof AtlasEntity) { AtlasEntity entityObj = (AtlasEntity) obj; for (AtlasAttribute attribute : relationshipAttributes.values()) { String attributeName = attribute.getName(); AtlasAttributeDef attributeDef = attribute.getAttributeDef(); if (((AtlasEntity) obj).hasRelationshipAttribute(attributeName)) { Object attributeValue = getNormalizedValue(entityObj.getAttribute(attributeName), attributeDef); obj.setAttribute(attributeName, attributeValue); } } } }