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; }
@Override public AtlasStruct createDefaultValue() { AtlasStruct ret = new AtlasStruct(structDef.getName()); populateDefaultValues(ret); return ret; }
@Override public Object createDefaultValue(Object defaultValue) { AtlasStruct ret = new AtlasStruct(structDef.getName()); populateDefaultValues(ret); return ret; }
@Override public AtlasStruct createDefaultValue() { AtlasStruct ret = new AtlasStruct(structDef.getName()); populateDefaultValues(ret); return ret; }
@Override public Object createDefaultValue(Object defaultValue) { AtlasStruct ret = new AtlasStruct(structDef.getName()); populateDefaultValues(ret); return ret; }
@Override public Object fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException { AtlasStruct ret = null; if (v1Obj != null) { AtlasStructType structType = (AtlasStructType)type; if (v1Obj instanceof Map) { final Map v1Map = (Map) v1Obj; final Map v1Attribs = (Map) v1Map.get(ATTRIBUTES_PROPERTY_KEY); if (MapUtils.isNotEmpty(v1Attribs)) { ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, v1Attribs, converterContext)); } else { ret = new AtlasStruct(type.getTypeName()); } } else if (v1Obj instanceof Struct) { Struct struct = (Struct) v1Obj; ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, struct.getValues(), converterContext)); } else { throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or Struct", v1Obj.getClass().getCanonicalName()); } } return ret; }
void visitStruct(AtlasStructType structType, Object val) throws AtlasBaseException { if (structType == null || val == null) { return; } final AtlasStruct struct; if (val instanceof AtlasStruct) { struct = (AtlasStruct) val; } else if (val instanceof Map) { Map attributes = AtlasTypeUtil.toStructAttributes((Map) val); struct = new AtlasStruct(structType.getTypeName(), attributes); } else { throw new AtlasBaseException(AtlasErrorCode.INVALID_STRUCT_VALUE, val.toString()); } visitStruct(structType, struct); }
void visitStruct(AtlasStructType structType, Object val) throws AtlasBaseException { if (structType == null || val == null) { return; } final AtlasStruct struct; if (val instanceof AtlasStruct) { struct = (AtlasStruct) val; } else if (val instanceof Map) { Map attributes = AtlasTypeUtil.toStructAttributes((Map) val); struct = new AtlasStruct(structType.getTypeName(), attributes); } else { throw new AtlasBaseException(AtlasErrorCode.INVALID_STRUCT_VALUE, val.toString()); } visitStruct(structType, struct); }
private AtlasStruct mapVertexToStruct(AtlasVertex entityVertex, String edgeLabel, AtlasEdge edge, AtlasEntityExtInfo entityExtInfo, final boolean isMinExtInfo) throws AtlasBaseException { AtlasStruct ret = null; if (edge == null) { edge = graphHelper.getEdgeForLabel(entityVertex, edgeLabel); } if (GraphHelper.elementExists(edge)) { final AtlasVertex referenceVertex = edge.getInVertex(); ret = new AtlasStruct(getTypeName(referenceVertex)); mapAttributes(referenceVertex, ret, entityExtInfo, isMinExtInfo); } return ret; }
private AtlasStruct mapVertexToStruct(AtlasVertex entityVertex, String edgeLabel, AtlasEdge edge, AtlasEntityExtInfo entityExtInfo, final boolean isMinExtInfo) throws AtlasBaseException { AtlasStruct ret = null; if (edge == null) { edge = graphHelper.getEdgeForLabel(entityVertex, edgeLabel); } if (GraphHelper.elementExists(edge)) { final AtlasVertex referenceVertex = edge.getInVertex(); ret = new AtlasStruct(getTypeName(referenceVertex)); mapAttributes(referenceVertex, ret, entityExtInfo, isMinExtInfo); } return ret; }
protected AtlasRelatedObjectId relatedCategoryIdToRelatedObjectId(AtlasRelatedCategoryHeader relatedCategoryId) { AtlasRelatedObjectId ret = new AtlasRelatedObjectId(); ret.setGuid(relatedCategoryId.getCategoryGuid()); ret.setRelationshipGuid(relatedCategoryId.getRelationGuid()); AtlasStruct relationshipAttributes = new AtlasStruct(); relationshipAttributes.setAttribute("description", relatedCategoryId.getDescription()); ret.setRelationshipAttributes(relationshipAttributes); return ret; }
private AtlasRelatedObjectId mapVertexToRelatedObjectId(AtlasVertex entityVertex, AtlasEdge edge) throws AtlasBaseException { AtlasRelatedObjectId ret = null; if (GraphHelper.elementExists(edge)) { AtlasVertex referenceVertex = edge.getInVertex(); if (StringUtils.equals(getIdFromVertex(referenceVertex), getIdFromVertex(entityVertex))) { referenceVertex = edge.getOutVertex(); } if (referenceVertex != null) { String entityTypeName = getTypeName(referenceVertex); String entityGuid = getGuid(referenceVertex); AtlasEntity.Status entityStatus = GraphHelper.getStatus(referenceVertex); AtlasRelationship relationship = mapEdgeToAtlasRelationship(edge); ret = new AtlasRelatedObjectId(entityGuid, entityTypeName, entityStatus, relationship.getGuid(), relationship.getStatus(), new AtlasStruct(relationship.getTypeName(), relationship.getAttributes())); Object displayText = getDisplayText(referenceVertex, entityTypeName); if (displayText != null) { ret.setDisplayText(displayText.toString()); } } } return ret; }
private AtlasRelatedObjectId mapVertexToRelatedObjectId(AtlasVertex entityVertex, AtlasEdge edge) throws AtlasBaseException { AtlasRelatedObjectId ret = null; if (GraphHelper.elementExists(edge)) { AtlasVertex referenceVertex = edge.getInVertex(); if (StringUtils.equals(getIdFromVertex(referenceVertex), getIdFromVertex(entityVertex))) { referenceVertex = edge.getOutVertex(); } if (referenceVertex != null) { String entityTypeName = getTypeName(referenceVertex); String entityGuid = getGuid(referenceVertex); AtlasEntity.Status entityStatus = GraphHelper.getStatus(referenceVertex); AtlasRelationship relationship = mapEdgeToAtlasRelationship(edge); ret = new AtlasRelatedObjectId(entityGuid, entityTypeName, entityStatus, relationship.getGuid(), relationship.getStatus(), new AtlasStruct(relationship.getTypeName(), relationship.getAttributes())); Object displayText = getDisplayText(referenceVertex, entityTypeName); if (displayText != null) { ret.setDisplayText(displayText.toString()); } } } return ret; }
protected AtlasRelatedObjectId relatedCategoryIdToRelatedObjectId(AtlasRelatedCategoryHeader relatedCategoryId) { AtlasRelatedObjectId ret = new AtlasRelatedObjectId(); ret.setGuid(relatedCategoryId.getCategoryGuid()); ret.setRelationshipGuid(relatedCategoryId.getRelationGuid()); AtlasStruct relationshipAttributes = new AtlasStruct(); relationshipAttributes.setAttribute("description", relatedCategoryId.getDescription()); ret.setRelationshipAttributes(relationshipAttributes); return ret; }
public static AtlasEntityWithExtInfo createTableEntityV2(AtlasEntity dbEntity) { AtlasEntity tblEntity = new AtlasEntity(TABLE_TYPE); tblEntity.setAttribute(NAME, RandomStringUtils.randomAlphanumeric(10)); tblEntity.setAttribute("description", "random table"); tblEntity.setAttribute("type", "type"); tblEntity.setAttribute("tableType", "MANAGED"); tblEntity.setAttribute("database", getAtlasObjectId(dbEntity)); tblEntity.setAttribute("created", new Date()); final AtlasStruct partitionStruct = new AtlasStruct("partition_struct_type", "name", "part0"); tblEntity.setAttribute("partitions", new ArrayList<AtlasStruct>() {{ add(partitionStruct); }}); tblEntity.setAttribute("partitionsMap", new HashMap<String, AtlasStruct>() {{ put("part0", new AtlasStruct("partition_struct_type", "name", "part0")); put("part1", new AtlasStruct("partition_struct_type", "name", "part1")); put("part2", new AtlasStruct("partition_struct_type", "name", "part2")); }}); tblEntity.setAttribute("parametersMap", new java.util.HashMap<String, String>() {{ put("key1", "value1"); }}); AtlasEntityWithExtInfo ret = new AtlasEntityWithExtInfo(tblEntity); ret.addReferredEntity(dbEntity); return ret; }
public static AtlasEntityWithExtInfo createComplexCollectionAttrEntity() { AtlasEntity entity = new AtlasEntity(ENTITY_TYPE_WITH_COMPLEX_COLLECTION_ATTR); entity.setAttribute(NAME, ENTITY_TYPE_WITH_COMPLEX_COLLECTION_ATTR); entity.setAttribute("listOfStructs", Arrays.asList(new AtlasStruct("struct_type", "name", "structArray0"), new AtlasStruct("struct_type", "name", "structArray1"), new AtlasStruct("struct_type", "name", "structArray2"))); entity.setAttribute("mapOfStructs", new HashMap<String, AtlasStruct>() {{ put("key0", new AtlasStruct("struct_type", "name", "structMap0")); put("key1", new AtlasStruct("struct_type", "name", "structMap1")); put("key2", new AtlasStruct("struct_type", "name", "structMap2")); }}); AtlasEntity e1Array = new AtlasEntity(ENTITY_TYPE, new HashMap<String, Object>() {{ put(NAME, "entityArray0"); put("isReplicated", true); }}); AtlasEntity e2Array = new AtlasEntity(ENTITY_TYPE, new HashMap<String, Object>() {{ put(NAME, "entityArray1"); put("isReplicated", false); }}); AtlasEntity e3Array = new AtlasEntity(ENTITY_TYPE, new HashMap<String, Object>() {{ put(NAME, "entityArray2"); put("isReplicated", true); }}); entity.setAttribute("listOfEntities", Arrays.asList(getAtlasObjectId(e1Array), getAtlasObjectId(e2Array), getAtlasObjectId(e3Array))); AtlasEntity e1MapValue = new AtlasEntity(ENTITY_TYPE, new HashMap<String, Object>() {{ put(NAME, "entityMapValue0"); put("isReplicated", false); }}); AtlasEntity e2MapValue = new AtlasEntity(ENTITY_TYPE, new HashMap<String, Object>() {{ put(NAME, "entityMapValue1"); put("isReplicated", true); }}); AtlasEntity e3MapValue = new AtlasEntity(ENTITY_TYPE, new HashMap<String, Object>() {{ put(NAME, "entityMapValue2"); put("isReplicated", false); }}); entity.setAttribute("mapOfEntities", new HashMap<String, Object>() {{ put("key0", getAtlasObjectId(e1MapValue)); put("key1", getAtlasObjectId(e2MapValue)); put("key2", getAtlasObjectId(e3MapValue)); }}); AtlasEntityWithExtInfo ret = new AtlasEntityWithExtInfo(entity); ret.addReferredEntity(e1Array); ret.addReferredEntity(e2Array); ret.addReferredEntity(e3Array); ret.addReferredEntity(e1MapValue); ret.addReferredEntity(e2MapValue); ret.addReferredEntity(e3MapValue); return ret; }
public static AtlasEntity createTableEntity(AtlasEntity dbEntity, String name) { AtlasEntity entity = new AtlasEntity(TABLE_TYPE); entity.setAttribute(NAME, name); entity.setAttribute("description", "random table"); entity.setAttribute("type", "type"); entity.setAttribute("tableType", "MANAGED"); entity.setAttribute("database", getAtlasObjectId(dbEntity)); entity.setAttribute("created", new Date()); Map<String, Object> partAttributes = new HashMap<String, Object>() {{ put("name", "part0"); }}; final AtlasStruct partitionStruct = new AtlasStruct("partition_struct_type", partAttributes); entity.setAttribute("partitions", new ArrayList<AtlasStruct>() {{ add(partitionStruct); }}); entity.setAttribute("parametersMap", new java.util.HashMap<String, String>() {{ put("key1", "value1"); }}); return entity; }
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; }
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; }
@Test(dependsOnMethods = "testCreate") public void testStructs() throws Exception { AtlasEntity databaseEntity = dbEntity.getEntity(); AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity()); AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity); AtlasStruct serdeInstance = new AtlasStruct(TestUtilsV2.SERDE_TYPE, TestUtilsV2.NAME, "serde1Name"); serdeInstance.setAttribute("serde", "test"); serdeInstance.setAttribute("description", "testDesc"); tableEntity.setAttribute("serde1", serdeInstance); tableEntity.setAttribute("database", new AtlasObjectId(databaseEntity.getTypeName(), TestUtilsV2.NAME, databaseEntity.getAttribute(TestUtilsV2.NAME))); init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); AtlasEntityHeader updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); //update struct attribute serdeInstance.setAttribute("serde", "testUpdated"); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); //set to null tableEntity.setAttribute("description", null); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); Assert.assertNull(updatedTable.getAttribute("description")); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); }