def call_to_update_assets(request): asset_id = request.data['id'] activate_on = request.data['activate_on'] expire_on = request.data['expire_on'] asset_name = request.data['name'] # tag_name = request.data['tags'] # Update asset_table response_asset = update_asset_table(asset_id, activate_on, expire_on, asset_name) # return Response(response_asset) if (response_asset is 'Id not found to update' or response_asset is None): return "Id not found / Error" else: # create tag and get id # tag_id = create_tag(tag_name) # if(tag_id): # update asset_tags # asset_tag = create_asset_tag(asset_id, tag_id) # print(asset_tag) # Get current existing Tags from Elastic search search_tag = { "query": { "bool": { "must": [{ "term": { "id": { "value": asset_id } } }] } } } index_obj = ElasticSearchGetId(search_tag) elastic_obj = Elastic() res = elastic_obj.primary_search(index_obj) # call elastic search to update elastic_serach_result = call_elastic_search_to_update(response_asset) # return Response("Elastic search updated") return response_asset
def post(self, request, format=None): if "id" and "tag" in request.data: asset_id = request.data['id'] tag_name = request.data['tag'] tag_id = create_tag(tag_name) if (tag_id): asset_tag = create_asset_tag(asset_id, tag_id) # Get current existing Tags from Elastic search search_tag = { "query": { "bool": { "must": [{ "term": { "id": { "value": asset_id } } }] } } } index_obj = ElasticSearchGetId(search_tag) elastic_obj = Elastic() res = elastic_obj.primary_search(index_obj) existing_tags = res["hits"]["hits"][0]["_source"]["metadata"][ "tags"] existing_tags = existing_tags + ',' + tag_name # call elastic search to update elastic_serach_result = call_elastic_search_to_update_tag( existing_tags) # return Response("Elastic search updated") return Response("200 Tags created and search updated") else: return Response("500 Error while creating Tags") else: return Response("Provide valid parameter")