protected AtlasRelatedObjectId termIdToRelatedObjectId(AtlasRelatedTermHeader relatedTermId) { AtlasRelatedObjectId ret = new AtlasRelatedObjectId(); ret.setGuid(relatedTermId.getTermGuid()); ret.setRelationshipGuid(relatedTermId.getRelationGuid()); AtlasStruct relationshipAttributes = new AtlasStruct(); relationshipAttributes.setAttribute("description", relatedTermId.getDescription()); relationshipAttributes.setAttribute("expression", relatedTermId.getExpression()); relationshipAttributes.setAttribute("source", relatedTermId.getSource()); relationshipAttributes.setAttribute("steward", relatedTermId.getSteward()); relationshipAttributes.setAttribute("status", relatedTermId.getStatus().name()); ret.setRelationshipAttributes(relationshipAttributes); return ret; }
private void mapAttributes(AtlasStruct struct, AtlasVertex vertex, EntityOperation op, EntityMutationContext context) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> mapAttributes({}, {})", op, struct.getTypeName()); } if (MapUtils.isNotEmpty(struct.getAttributes())) { AtlasStructType structType = getStructType(struct.getTypeName()); if (op.equals(CREATE)) { for (AtlasAttribute attribute : structType.getAllAttributes().values()) { Object attrValue = struct.getAttribute(attribute.getName()); mapAttribute(attribute, attrValue, vertex, op, context); } } else if (op.equals(UPDATE)) { for (String attrName : struct.getAttributes().keySet()) { AtlasAttribute attribute = structType.getAttribute(attrName); if (attribute != null) { Object attrValue = struct.getAttribute(attrName); mapAttribute(attribute, attrValue, vertex, op, context); } else { LOG.warn("mapAttributes(): invalid attribute {}.{}. Ignored..", struct.getTypeName(), attrName); } } } updateModificationMetadata(vertex); } if (LOG.isDebugEnabled()) { LOG.debug("<== mapAttributes({}, {})", op, struct.getTypeName()); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; AtlasEntityHeader that = (AtlasEntityHeader) o; return Objects.equals(guid, that.guid) && status == that.status && Objects.equals(displayText, that.displayText) && Objects.equals(classificationNames, that.classificationNames); }
public AtlasStruct(String typeName, String attrName, Object attrValue) { setTypeName(typeName); setAttribute(attrName, attrValue); }
public AtlasStruct(AtlasStruct other) { if (other != null) { setTypeName(other.getTypeName()); setAttributes(new HashMap<>(other.getAttributes())); } }
public void normalizeAttributeValuesForUpdate(AtlasStruct obj) { if (obj != null) { for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { String attributeName = attributeDef.getName(); if (obj.hasAttribute(attributeName)) { Object attributeValue = getNormalizedValueForUpdate(obj.getAttribute(attributeName), attributeDef); obj.setAttribute(attributeName, attributeValue); } } } }
private AtlasStruct getStructFromValue(Object val) { final AtlasStruct ret; if (val instanceof AtlasStruct) { ret = (AtlasStruct) val; } else if (val instanceof Map) { ret = new AtlasStruct((Map) val); } else if (val instanceof String) { Map map = AtlasType.fromJson(val.toString(), Map.class); if (map == null) { ret = null; } else { ret = new AtlasStruct((Map) val); } } else { ret = null; } return ret; }
AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity); Map<String, AtlasStruct> partsMap = new HashMap<>(); partsMap.put("part0", new AtlasStruct(TestUtilsV2.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test")); validateEntity(entitiesInfo, updatedTableDef1); Assert.assertTrue(partsMap.get("part0").equals(((Map<String, AtlasStruct>) updatedTableDef1.getAttribute("partitionsMap")).get("part0"))); partsMap.put("part1", new AtlasStruct(TestUtilsV2.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test1")); tableEntity.setAttribute("partitionsMap", partsMap); Assert.assertTrue(partsMap.get("part1").equals(((Map<String, AtlasStruct>) updatedTableDef2.getAttribute("partitionsMap")).get("part1"))); partsMap.put("part2", new AtlasStruct(TestUtilsV2.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test2")); tableEntity.setAttribute("partitionsMap", partsMap); Assert.assertTrue(partsMap.get("part2").equals(((Map<String, AtlasStruct>) updatedTableDef3.getAttribute("partitionsMap")).get("part2"))); partition2.setAttribute(TestUtilsV2.NAME, "test2Updated"); Assert.assertTrue(partsMap.get("part2").equals(((Map<String, AtlasStruct>) updatedTableDef4.getAttribute("partitionsMap")).get("part2")));
private void updateRelationshipAttributes(AtlasRelationship relationship, AtlasRelatedObjectId relatedObjectId) { AtlasStruct relationshipAttributes = relatedObjectId.getRelationshipAttributes(); if (Objects.nonNull(relationshipAttributes)) { for (Map.Entry<String, Object> attrEntry : relationshipAttributes.getAttributes().entrySet()) { relationship.setAttribute(attrEntry.getKey(), attrEntry.getValue()); } } }
private void mapAttributes(AtlasVertex entityVertex, AtlasStruct struct, AtlasEntityExtInfo entityExtInfo, boolean isMinExtInfo) throws AtlasBaseException { AtlasType objType = typeRegistry.getType(struct.getTypeName()); if (!(objType instanceof AtlasStructType)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, struct.getTypeName()); } AtlasStructType structType = (AtlasStructType) objType; for (AtlasAttribute attribute : structType.getAllAttributes().values()) { Object attrValue = mapVertexToAttribute(entityVertex, attribute, entityExtInfo, isMinExtInfo); struct.setAttribute(attribute.getName(), attrValue); } }
void visitStruct(AtlasStructType structType, AtlasStruct struct) throws AtlasBaseException { for (AtlasAttribute attribute : structType.getAllAttributes().values()) { AtlasType attrType = attribute.getAttributeType(); Object attrVal = struct.getAttribute(attribute.getName()); visitAttribute(attrType, attrVal); } }
@Test public void testStructTypeDefaultValue() { AtlasStruct defValue = structType.createDefaultValue(); assertNotNull(defValue); assertEquals(defValue.getTypeName(), structType.getTypeName()); }
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); } } } }
public void populateDefaultValues(AtlasStruct obj) { if (obj != null) { Map<String, Object> attributes = obj.getAttributes(); if (attributes == null) { attributes = new HashMap<>(); } for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { if (!attributeDef.getIsOptional()) { attributes.put(attributeDef.getName(), createDefaultValue(attributeDef)); } } obj.setAttributes(attributes); } }
@Override public Object createDefaultValue(Object defaultValue) { AtlasStruct ret = new AtlasStruct(structDef.getName()); populateDefaultValues(ret); return ret; }
public void normalizeAttributeValuesForUpdate(AtlasStruct obj) { if (obj != null) { for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { String attributeName = attributeDef.getName(); if (obj.hasAttribute(attributeName)) { Object attributeValue = getNormalizedValueForUpdate(obj.getAttribute(attributeName), attributeDef); obj.setAttribute(attributeName, attributeValue); } } } }
AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity); Map<String, AtlasStruct> partsMap = new HashMap<>(); partsMap.put("part0", new AtlasStruct(TestUtilsV2.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test")); validateEntity(entitiesInfo, updatedTableDef1); Assert.assertTrue(partsMap.get("part0").equals(((Map<String, AtlasStruct>) updatedTableDef1.getAttribute("partitionsMap")).get("part0"))); partsMap.put("part1", new AtlasStruct(TestUtilsV2.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test1")); tableEntity.setAttribute("partitionsMap", partsMap); Assert.assertTrue(partsMap.get("part1").equals(((Map<String, AtlasStruct>) updatedTableDef2.getAttribute("partitionsMap")).get("part1"))); partsMap.put("part2", new AtlasStruct(TestUtilsV2.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test2")); tableEntity.setAttribute("partitionsMap", partsMap); Assert.assertTrue(partsMap.get("part2").equals(((Map<String, AtlasStruct>) updatedTableDef3.getAttribute("partitionsMap")).get("part2"))); partition2.setAttribute(TestUtilsV2.NAME, "test2Updated"); Assert.assertTrue(partsMap.get("part2").equals(((Map<String, AtlasStruct>) updatedTableDef4.getAttribute("partitionsMap")).get("part2")));
private void updateRelationshipAttributes(AtlasRelationship relationship, AtlasRelatedObjectId relatedObjectId) { AtlasStruct relationshipAttributes = relatedObjectId.getRelationshipAttributes(); if (Objects.nonNull(relationshipAttributes)) { for (Map.Entry<String, Object> attrEntry : relationshipAttributes.getAttributes().entrySet()) { relationship.setAttribute(attrEntry.getKey(), attrEntry.getValue()); } } }
private void mapAttributes(AtlasVertex entityVertex, AtlasStruct struct, AtlasEntityExtInfo entityExtInfo, boolean isMinExtInfo) throws AtlasBaseException { AtlasType objType = typeRegistry.getType(struct.getTypeName()); if (!(objType instanceof AtlasStructType)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, struct.getTypeName()); } AtlasStructType structType = (AtlasStructType) objType; for (AtlasAttribute attribute : structType.getAllAttributes().values()) { Object attrValue = mapVertexToAttribute(entityVertex, attribute, entityExtInfo, isMinExtInfo); struct.setAttribute(attribute.getName(), attrValue); } }
public AtlasStruct(AtlasStruct other) { if (other != null) { setTypeName(other.getTypeName()); setAttributes(new HashMap<>(other.getAttributes())); } }