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); } }
protected void validateEntity(AtlasEntityExtInfo entityExtInfo, AtlasStruct actual, AtlasStruct expected) throws AtlasBaseException, AtlasException { if (expected == null) { Assert.assertNull(actual, "expected null instance. Found " + actual); return; } Assert.assertNotNull(actual, "found null instance"); AtlasStructType entityType = (AtlasStructType) typeRegistry.getType(actual.getTypeName()); for (String attrName : expected.getAttributes().keySet()) { Object expectedVal = expected.getAttribute(attrName); Object actualVal = actual.getAttribute(attrName); AtlasType attrType = entityType.getAttributeType(attrName); validateAttribute(entityExtInfo, actualVal, expectedVal, attrType, attrName); } }
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()); } }
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); } }
protected void validateEntity(AtlasEntityExtInfo entityExtInfo, AtlasStruct actual, AtlasStruct expected) throws AtlasBaseException, AtlasException { if (expected == null) { Assert.assertNull(actual, "expected null instance. Found " + actual); return; } Assert.assertNotNull(actual, "found null instance"); AtlasStructType entityType = (AtlasStructType) typeRegistry.getType(actual.getTypeName()); for (String attrName : expected.getAttributes().keySet()) { Object expectedVal = expected.getAttribute(attrName); Object actualVal = actual.getAttribute(attrName); AtlasType attrType = entityType.getAttributeType(attrName); validateAttribute(entityExtInfo, actualVal, expectedVal, attrType, attrName); } }
protected AtlasRelatedTermHeader constructRelatedTermId(AtlasRelatedObjectId relatedObjectId) { AtlasRelatedTermHeader ret = new AtlasRelatedTermHeader(); ret.setTermGuid(relatedObjectId.getGuid()); ret.setRelationGuid(relatedObjectId.getRelationshipGuid()); AtlasStruct relationshipAttributes = relatedObjectId.getRelationshipAttributes(); if (relationshipAttributes != null) { ret.setDescription((String) relationshipAttributes.getAttribute("description")); ret.setExpression((String) relationshipAttributes.getAttribute("expression")); ret.setSource((String) relationshipAttributes.getAttribute("source")); ret.setSteward((String) relationshipAttributes.getAttribute("steward")); Object status = relationshipAttributes.getAttribute("status"); if (status instanceof String) { ret.setStatus(AtlasTermRelationshipStatus.valueOf((String) status)); } else if (status instanceof AtlasTermRelationshipStatus) { ret.setStatus((AtlasTermRelationshipStatus) status); } } return ret; }
} else { Object attrValue1 = entry.getValue(); Object attrValue2 = structVal2.getAttribute(attrName);
protected AtlasRelatedTermHeader constructRelatedTermId(AtlasRelatedObjectId relatedObjectId) { AtlasRelatedTermHeader ret = new AtlasRelatedTermHeader(); ret.setTermGuid(relatedObjectId.getGuid()); ret.setRelationGuid(relatedObjectId.getRelationshipGuid()); AtlasStruct relationshipAttributes = relatedObjectId.getRelationshipAttributes(); if (relationshipAttributes != null) { ret.setDescription((String) relationshipAttributes.getAttribute("description")); ret.setExpression((String) relationshipAttributes.getAttribute("expression")); ret.setSource((String) relationshipAttributes.getAttribute("source")); ret.setSteward((String) relationshipAttributes.getAttribute("steward")); Object status = relationshipAttributes.getAttribute("status"); if (status instanceof String) { ret.setStatus(AtlasTermRelationshipStatus.valueOf((String) status)); } else if (status instanceof AtlasTermRelationshipStatus) { ret.setStatus((AtlasTermRelationshipStatus) status); } } 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())) { MetricRecorder metric = RequestContext.get().startMetricRecord("mapAttributes"); 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); RequestContext.get().endMetricRecord(metric); } if (LOG.isDebugEnabled()) { LOG.debug("<== mapAttributes({}, {})", op, struct.getTypeName()); } }
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); } } } }
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); } } } }
protected AtlasTermCategorizationHeader constructTermCategorizationId(final AtlasRelatedObjectId category) { AtlasTermCategorizationHeader ret = new AtlasTermCategorizationHeader(); ret.setCategoryGuid(category.getGuid()); ret.setRelationGuid(category.getRelationshipGuid()); AtlasStruct relationshipAttributes = category.getRelationshipAttributes(); if (relationshipAttributes != null) { ret.setDescription((String) relationshipAttributes.getAttribute("description")); Object status = relationshipAttributes.getAttribute("status"); if (status instanceof AtlasTermRelationshipStatus) { ret.setStatus((AtlasTermRelationshipStatus) status); } else if (status instanceof String) { ret.setStatus(AtlasTermRelationshipStatus.valueOf((String) status)); } } return ret; }
protected AtlasTermCategorizationHeader constructTermCategorizationId(final AtlasRelatedObjectId category) { AtlasTermCategorizationHeader ret = new AtlasTermCategorizationHeader(); ret.setCategoryGuid(category.getGuid()); ret.setRelationGuid(category.getRelationshipGuid()); AtlasStruct relationshipAttributes = category.getRelationshipAttributes(); if (relationshipAttributes != null) { ret.setDescription((String) relationshipAttributes.getAttribute("description")); Object status = relationshipAttributes.getAttribute("status"); if (status instanceof AtlasTermRelationshipStatus) { ret.setStatus((AtlasTermRelationshipStatus) status); } else if (status instanceof String) { ret.setStatus(AtlasTermRelationshipStatus.valueOf((String) status)); } } return ret; }
protected AtlasRelatedCategoryHeader constructRelatedCategoryId(AtlasRelatedObjectId relatedObjectId) { AtlasRelatedCategoryHeader ret = new AtlasRelatedCategoryHeader(); ret.setCategoryGuid(relatedObjectId.getGuid()); ret.setRelationGuid(relatedObjectId.getRelationshipGuid()); AtlasStruct relationshipAttributes = relatedObjectId.getRelationshipAttributes(); if (relationshipAttributes != null) { ret.setDescription((String) relationshipAttributes.getAttribute("description")); } return ret; }
@Override public boolean isValidValue(Object obj) { if (obj != null) { if (obj instanceof AtlasStruct) { AtlasStruct structObj = (AtlasStruct) obj; for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { if (!isAssignableValue(structObj.getAttribute(attributeDef.getName()), attributeDef)) { return false; } } } else if (obj instanceof Map) { Map map = AtlasTypeUtil.toStructAttributes((Map) obj); for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { if (!isAssignableValue(map.get(attributeDef.getName()), attributeDef)) { return false; // no value for non-optinal attribute } } } else { return false; } } return true; }
@Override public boolean isValidValue(Object obj) { if (obj != null) { if (obj instanceof AtlasStruct) { AtlasStruct structObj = (AtlasStruct) obj; for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { if (!isAssignableValue(structObj.getAttribute(attributeDef.getName()), attributeDef)) { return false; } } } else if (obj instanceof Map) { Map map = AtlasTypeUtil.toStructAttributes((Map) obj); for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { if (!isAssignableValue(map.get(attributeDef.getName()), attributeDef)) { return false; // no value for non-optinal attribute } } } else { return false; } } return true; }
protected AtlasRelatedCategoryHeader constructRelatedCategoryId(AtlasRelatedObjectId relatedObjectId) { AtlasRelatedCategoryHeader ret = new AtlasRelatedCategoryHeader(); ret.setCategoryGuid(relatedObjectId.getGuid()); ret.setRelationGuid(relatedObjectId.getRelationshipGuid()); AtlasStruct relationshipAttributes = relatedObjectId.getRelationshipAttributes(); if (relationshipAttributes != null) { ret.setDescription((String) relationshipAttributes.getAttribute("description")); } return ret; }
public void normalizeAttributeValues(AtlasStruct obj) { if (obj != null) { for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { String attributeName = attributeDef.getName(); if (obj.hasAttribute(attributeName)) { Object attributeValue = getNormalizedValue(obj.getAttribute(attributeName), attributeDef); obj.setAttribute(attributeName, attributeValue); } else if (!attributeDef.getIsOptional()) { obj.setAttribute(attributeName, createDefaultValue(attributeDef)); } } } }
public void normalizeAttributeValues(AtlasStruct obj) { if (obj != null) { for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { String attributeName = attributeDef.getName(); if (obj.hasAttribute(attributeName)) { Object attributeValue = getNormalizedValue(obj.getAttribute(attributeName), attributeDef); obj.setAttribute(attributeName, attributeValue); } else if (!attributeDef.getIsOptional()) { obj.setAttribute(attributeName, createDefaultValue(attributeDef)); } } } }
Object value = structObj.getAttribute(attrName); String fieldName = objName + "." + attrName;