@Override public boolean validateValue(Object obj, String objName, List<String> messages) { boolean ret = true; if (obj != null) { if (obj instanceof Map) { Map<Object, Objects> map = (Map<Object, Objects>) obj; for (Map.Entry e : map.entrySet()) { Object key = e.getKey(); if (!keyType.isValidValue(key)) { ret = false; messages.add(objName + "." + key + ": invalid key for type " + getTypeName()); } else { Object value = e.getValue(); ret = valueType.validateValue(value, objName + "." + key, messages) && ret; } } } else { ret = false; messages.add(objName + "=" + obj + ": invalid value for type " + getTypeName()); } } return ret; }
@Override public boolean validateValueForUpdate(Object obj, String objName, List<String> messages) { boolean ret = true; if (obj != null) { if (obj instanceof Map) { Map<Object, Objects> map = (Map<Object, Objects>) obj; for (Map.Entry e : map.entrySet()) { Object key = e.getKey(); if (!keyType.isValidValueForUpdate(key)) { ret = false; messages.add(objName + "." + key + ": invalid key for type " + getTypeName()); } else { Object value = e.getValue(); ret = valueType.validateValueForUpdate(value, objName + "." + key, messages) && ret; } } } else { ret = false; messages.add(objName + "=" + obj + ": invalid value for type " + getTypeName()); } } return ret; }
@Override public boolean validateValue(Object obj, String objName, List<String> messages) { boolean ret = true; if (obj != null) { if (obj instanceof Map) { Map<Object, Objects> map = (Map<Object, Objects>) obj; for (Map.Entry e : map.entrySet()) { Object key = e.getKey(); if (!keyType.isValidValue(key)) { ret = false; messages.add(objName + "." + key + ": invalid key for type " + getTypeName()); } else { Object value = e.getValue(); ret = valueType.validateValue(value, objName + "." + key, messages) && ret; } } } else { ret = false; messages.add(objName + "=" + obj + ": invalid value for type " + getTypeName()); } } return ret; }
@Override public boolean validateValueForUpdate(Object obj, String objName, List<String> messages) { boolean ret = true; if (obj != null) { if (obj instanceof Map) { Map<Object, Objects> map = (Map<Object, Objects>) obj; for (Map.Entry e : map.entrySet()) { Object key = e.getKey(); if (!keyType.isValidValueForUpdate(key)) { ret = false; messages.add(objName + "." + key + ": invalid key for type " + getTypeName()); } else { Object value = e.getValue(); ret = valueType.validateValueForUpdate(value, objName + "." + key, messages) && ret; } } } else { ret = false; messages.add(objName + "=" + obj + ": invalid value for type " + getTypeName()); } } return ret; }
@Override public AtlasType getTypeForAttribute() { AtlasType keyAttributeType = keyType.getTypeForAttribute(); AtlasType valueAttributeType = valueType.getTypeForAttribute(); if (keyAttributeType == keyType && valueAttributeType == valueType) { return this; } else { AtlasType attributeType = new AtlasMapType(keyAttributeType, valueAttributeType); if (LOG.isDebugEnabled()) { LOG.debug("getTypeForAttribute(): {} ==> {}", getTypeName(), attributeType.getTypeName()); } return attributeType; } }
@Override public AtlasType getTypeForAttribute() { AtlasType keyAttributeType = keyType.getTypeForAttribute(); AtlasType valueAttributeType = valueType.getTypeForAttribute(); if (keyAttributeType == keyType && valueAttributeType == valueType) { return this; } else { AtlasType attributeType = new AtlasMapType(keyAttributeType, valueAttributeType); if (LOG.isDebugEnabled()) { LOG.debug("getTypeForAttribute(): {} ==> {}", getTypeName(), attributeType.getTypeName()); } return attributeType; } } }
private Map<String, Object> mapVertexToMap(AtlasVertex entityVertex, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasAttribute attribute, final boolean isMinExtInfo) throws AtlasBaseException { Map<String, Object> ret = null; AtlasMapType mapType = (AtlasMapType) attribute.getAttributeType(); AtlasType mapValueType = mapType.getValueType(); if (LOG.isDebugEnabled()) { LOG.debug("Mapping map attribute {} for vertex {}", mapType.getTypeName(), entityVertex); } if (isReference(mapValueType)) { Map<String, Object> currentMap = getReferenceMap(entityVertex, attribute); if (MapUtils.isNotEmpty(currentMap)) { ret = new HashMap<>(); for (Map.Entry<String, Object> entry : currentMap.entrySet()) { String mapKey = entry.getKey(); Object keyValue = entry.getValue(); Object mapValue = mapVertexToCollectionEntry(entityVertex, mapValueType, keyValue, attribute.getRelationshipEdgeLabel(), entityExtInfo, isOwnedAttribute, attribute.getRelationshipEdgeDirection(), isMinExtInfo); if (mapValue != null) { ret.put(mapKey, mapValue); } } } } else { ret = getPrimitiveMap(entityVertex, attribute.getVertexPropertyName()); } if (MapUtils.isEmpty(ret)) { ret = null; } return ret; }
private Map<String, Object> mapVertexToMap(AtlasVertex entityVertex, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasAttribute attribute, final boolean isMinExtInfo) throws AtlasBaseException { Map<String, Object> ret = null; AtlasMapType mapType = (AtlasMapType) attribute.getAttributeType(); AtlasType mapValueType = mapType.getValueType(); if (LOG.isDebugEnabled()) { LOG.debug("Mapping map attribute {} for vertex {}", mapType.getTypeName(), entityVertex); } if (isReference(mapValueType)) { Map<String, Object> currentMap = getReferenceMap(entityVertex, attribute); if (MapUtils.isNotEmpty(currentMap)) { ret = new HashMap<>(); for (Map.Entry<String, Object> entry : currentMap.entrySet()) { String mapKey = entry.getKey(); Object keyValue = entry.getValue(); Object mapValue = mapVertexToCollectionEntry(entityVertex, mapValueType, keyValue, attribute.getRelationshipEdgeLabel(), entityExtInfo, isOwnedAttribute, attribute.getRelationshipEdgeDirection(), isMinExtInfo); if (mapValue != null) { ret.put(mapKey, mapValue); } } } } else { ret = getPrimitiveMap(entityVertex, attribute.getVertexPropertyName()); } if (MapUtils.isEmpty(ret)) { ret = null; } return ret; }