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); } } } }
@Test public void testEntityTypeGetNormalizedValue() { assertNull(entityType.getNormalizedValue(null), "value=" + null); for (Object value : validValues) { if (value == null) { continue; } Object normalizedValue = entityType.getNormalizedValue(value); assertNotNull(normalizedValue, "value=" + value); } for (Object value : invalidValues) { assertNull(entityType.getNormalizedValue(value), "value=" + value); } }
@Test public void testEntityTypeGetNormalizedValue() { assertNull(entityType.getNormalizedValue(null), "value=" + null); for (Object value : validValues) { if (value == null) { continue; } Object normalizedValue = entityType.getNormalizedValue(value); assertNotNull(normalizedValue, "value=" + value); } for (Object value : invalidValues) { assertNull(entityType.getNormalizedValue(value), "value=" + value); } }
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); } } } }
@Override public void validateAndNormalize(AtlasEntity entity) throws AtlasBaseException { List<String> messages = new ArrayList<>(); if (! AtlasTypeUtil.isValidGuid(entity.getGuid())) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid()); } AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (type == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName()); } type.validateValue(entity, entity.getTypeName(), messages); if (!messages.isEmpty()) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages); } type.getNormalizedValue(entity); }
@Override public void validateAndNormalize(AtlasEntity entity) throws AtlasBaseException { List<String> messages = new ArrayList<>(); if (! AtlasTypeUtil.isValidGuid(entity.getGuid())) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid()); } AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (type == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName()); } type.validateValue(entity, entity.getTypeName(), messages); if (!messages.isEmpty()) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages); } type.getNormalizedValue(entity); }