use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class EntityGraphRetriever method mapVertexToArray.
private List<Object> mapVertexToArray(AtlasVertex entityVertex, AtlasArrayType arrayType, String propertyName, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasRelationshipEdgeDirection edgeDirection) throws AtlasBaseException {
AtlasType arrayElementType = arrayType.getElementType();
List<Object> arrayElements = GraphHelper.getArrayElementsProperty(arrayElementType, entityVertex, propertyName);
if (CollectionUtils.isEmpty(arrayElements)) {
return null;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Mapping array attribute {} for vertex {}", arrayElementType.getTypeName(), entityVertex);
}
List arrValues = new ArrayList(arrayElements.size());
String edgeLabel = EDGE_LABEL_PREFIX + propertyName;
for (Object element : arrayElements) {
Object arrValue = mapVertexToCollectionEntry(entityVertex, arrayElementType, element, edgeLabel, entityExtInfo, isOwnedAttribute, edgeDirection);
if (arrValue != null) {
arrValues.add(arrValue);
}
}
return arrValues;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class EntityGraphRetriever method mapVertexToMap.
private Map<String, Object> mapVertexToMap(AtlasVertex entityVertex, AtlasMapType atlasMapType, final String propertyName, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasRelationshipEdgeDirection edgeDirection) throws AtlasBaseException {
List<String> mapKeys = GraphHelper.getListProperty(entityVertex, propertyName);
if (CollectionUtils.isEmpty(mapKeys)) {
return null;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Mapping map attribute {} for vertex {}", atlasMapType.getTypeName(), entityVertex);
}
Map<String, Object> ret = new HashMap<>(mapKeys.size());
AtlasType mapValueType = atlasMapType.getValueType();
for (String mapKey : mapKeys) {
final String keyPropertyName = propertyName + "." + mapKey;
final String edgeLabel = EDGE_LABEL_PREFIX + keyPropertyName;
final Object keyValue = GraphHelper.getMapValueProperty(mapValueType, entityVertex, keyPropertyName);
Object mapValue = mapVertexToCollectionEntry(entityVertex, mapValueType, keyValue, edgeLabel, entityExtInfo, isOwnedAttribute, edgeDirection);
if (mapValue != null) {
ret.put(mapKey, mapValue);
}
}
return ret;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class AtlasRelationshipDefStoreV1 method updateByName.
@Override
public AtlasRelationshipDef updateByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasRelationshipDefStoreV1.updateByName({}, {})", name, relationshipDef);
}
AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByName(name);
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-def ", name);
validateType(relationshipDef);
AtlasType type = typeRegistry.getType(relationshipDef.getName());
if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
}
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP);
if (vertex == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
}
preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex);
AtlasRelationshipDef ret = toRelationshipDef(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasRelationshipDefStoreV1.updateByName({}, {}): {}", name, relationshipDef, ret);
}
return ret;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class AtlasRelationshipDefStoreV1 method preCreate.
@Override
public AtlasVertex preCreate(AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasRelationshipDefStoreV1.preCreate({})", relationshipDef);
}
validateType(relationshipDef);
AtlasType type = typeRegistry.getType(relationshipDef.getName());
if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
}
AtlasVertex relationshipDefVertex = typeDefStore.findTypeVertexByName(relationshipDef.getName());
if (relationshipDefVertex != null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, relationshipDef.getName());
}
relationshipDefVertex = typeDefStore.createTypeVertex(relationshipDef);
updateVertexPreCreate(relationshipDef, (AtlasRelationshipType) type, relationshipDefVertex);
final AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
final AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
final String type1 = endDef1.getType();
final String type2 = endDef2.getType();
final String name1 = endDef1.getName();
final String name2 = endDef2.getName();
final AtlasVertex end1TypeVertex = typeDefStore.findTypeVertexByName(type1);
final AtlasVertex end2TypeVertex = typeDefStore.findTypeVertexByName(type2);
if (end1TypeVertex == null) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type1);
}
if (end2TypeVertex == null) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type2);
}
// create an edge between the relationshipDef and each of the entityDef vertices.
AtlasEdge edge1 = typeDefStore.getOrCreateEdge(relationshipDefVertex, end1TypeVertex, AtlasGraphUtilsV1.RELATIONSHIPTYPE_EDGE_LABEL);
if (type1.equals(type2) && name1.equals(name2)) {
if (LOG.isDebugEnabled()) {
LOG.debug("AtlasRelationshipDefStoreV1.preCreate({}): created relationshipDef vertex {}," + " and one edge as {}, because end1 and end2 have the same type and name", relationshipDef, relationshipDefVertex, edge1);
}
} else {
AtlasEdge edge2 = typeDefStore.getOrCreateEdge(relationshipDefVertex, end2TypeVertex, AtlasGraphUtilsV1.RELATIONSHIPTYPE_EDGE_LABEL);
if (LOG.isDebugEnabled()) {
LOG.debug("AtlasRelationshipDefStoreV1.preCreate({}): created relationshipDef vertex {}," + " edge1 as {}, edge2 as {} ", relationshipDef, relationshipDefVertex, edge1, edge2);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasRelationshipDefStoreV1.preCreate({}): {}", relationshipDef, relationshipDefVertex);
}
return relationshipDefVertex;
}
use of org.apache.atlas.type.AtlasType in project atlas by apache.
the class AtlasEntityStoreV1Test method validateEntity.
private 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);
}
}
Aggregations