def remove_tag_of_property(data): request_data = json.loads(data) user_email = putil.validate_for_user_id_exists(request_data.get("user_id")) user_data = frappe.db.get_value("User", {"email": user_email}, "user_type", as_dict=True) if user_data.get("user_type") == "System User": try: es = ElasticSearchController() response = es.search_document_for_given_id( "property", request_data.get("property_id"), [], []) get_modified_datetime(response, user_email) update_query = get_update_tag_query(request_data, request_data.get('tags')[0], response) es = ElasticSearchController() update_response = es.update_docuemnt( "property", request_data.get("property_id"), update_query) es = ElasticSearchController() es.refresh_index() return { "operation": "update", "user_id": request_data.get("user_id"), "message": "Property Tags Updated Successfully" } except elasticsearch.TransportError: raise DoesNotExistError("Property Id does not exists") except elasticsearch.ElasticsearchException, e: raise ElasticSearchException(e.error)
def post_project(data): try: request_data = json.loads(data) if isinstance(data, unicode) else data user_email = putil.validate_for_user_id_exists( request_data.get("user_id")) user_data = frappe.db.get_value("User", {"email": user_email}, "user_type", as_dict=True) if user_data.get("user_type") == "System User": project_data = putil.validate_property_posting_data( request_data, "property_json/project_post_mapper.json") property_details = putil.validate_project_posting_data( project_data.get("property_details"), "property_json/project_child_table.json") project_data["property_details"] = property_details project_id = init_for_project_posting(project_data, user_email, request_data.get("user_id")) init_for_project_photo_upload(request_data, project_data) response_dict = { "operation": "Create", "user_id": request_data.get("user_id") } es = ElasticSearchController() response_data = es.index_document("project", project_data, project_data["project_id"]) try: init_for_property_posting(project_data) response_dict["message"] = "Project Posted Successfully" except Exception, e: response_dict[ "message"] = "Project Posted Successfully but Property Posting Failed" response_dict["project_id"] = project_id return response_dict else:
def update_project(request_data): user_email = putil.validate_for_user_id_exists( request_data.get("fields").get("user_id")) try: field_dict = putil.validate_property_posting_data( request_data.get("fields"), "property_json/project_post_mapper.json") get_modified_datetime(field_dict, user_email) es = ElasticSearchController() update_project_photos(field_dict, request_data.get("fields"), request_data.get("project_id"), es) field_dict["possession_status"] = "Immediate" if field_dict.get( "possession") else field_dict.get("possession_date") search_query = {"doc": field_dict} update_response = es.update_docuemnt("project", request_data.get("project_id"), search_query) percent_script = get_percent_completion_script( project_mandatory_fields) per_response = es.update_docuemnt("project", request_data.get("project_id"), percent_script) return {"opeartion": "Update", "message": "Project details Updated"} except elasticsearch.TransportError: raise DoesNotExistError("Project Id does not exists") except elasticsearch.ElasticsearchException, e: raise ElasticSearchException(e.error)
def get_alerts_based_on_last_request(request_data, email): """ Generate search query from last search request of that user & check for properties which are posted from last month only. """ try: search_query = { "sort": [{ "posted_datetime": { "order": "desc" }}], "query":{ "bool":{ "must":[ {"match":{ "user_id":request_data.get("user_id") } } ] } } } es = ElasticSearchController() response_data, total_records = es.search_document(["request"], search_query, 1, 1) if response_data: last_month_date = add_months(datetime.datetime.now() ,-1).strftime("%Y-%m-%d %H:%M:%S") property_search_query = response_data[0].get("search_query") property_search_query = ast.literal_eval(property_search_query.encode("utf8")) new_query = property_search_query.get("query").get("bool").get("must") new_query.append({ "range" : { "modified_datetime" : { "gte":last_month_date, } } }) property_search_query["query"]["bool"]["must"] = new_query uom = response_data[0].get("unit_of_area") uom = "Sq.Ft." if uom not in ["Sq.Ft.", "Acres", "Hectares"] else uom return property_search_query, uom else: raise OperationFailed("No Alerts and Request Id found against User {0}".format(email)) except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error)
def add_photo_to_property(data): request_data = json.loads(data) prop_dict = {"user_id":request_data.get("user_id"), "sid":request_data.get("sid"), "property_id":request_data.get("property_id"), "fields":["thumbnails", "full_size_images", "property_photo"]} field_dict = {} prop_response = get_property_details(json.dumps(prop_dict)) if request_data.get("property_photos"): photo_dict = store_property_photos_in_propshikari(request_data.get("property_photos"),request_data.get("property_id")) photo_dict.get("full_size").extend(prop_response.get("data").get("full_size_images", [])) photo_dict.get("thumbnails").extend(prop_response.get("data").get("thumbnails", [])) field_dict["full_size_images"] = photo_dict.get("full_size") field_dict["thumbnails"] = photo_dict.get("thumbnails") field_dict["property_photo"] = field_dict.get("thumbnails")[0] if len(field_dict.get("thumbnails")) else "" search_query = {"doc": field_dict } es = ElasticSearchController() update_response = es.update_docuemnt("property", request_data.get("property_id"), search_query) prop_response = get_property_details(json.dumps(prop_dict)) return { "message":"Property Photos Updated successfully", "full_size_images":prop_response.get("data").get("full_size_images", []), "thumbnails":prop_response.get("data").get("thumbnails", []), "property_photo":prop_response.get("data").get("property_photo", []) } else: raise DoesNotExistError("Images not Attached")
def get_property_of_particular_tag(request_data): if request_data: request_data = json.loads(request_data) if not request_data.get("tag"): raise MandatoryError("Mandatory Field Tag missing") try: exclude_list = ["agent_name", "agent_no", "contact_no", "contact_person", "created_by", "modified_by", "creation_date", "modified_date", "posted_datetime", "modified_datetime"] must_clause_list = [{ "match":{ "tag":request_data.get("tag") } }, { "match":{ "status":"Active" } } ] search_query = { "query":{ "bool":{ "must":must_clause_list } } } es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",40),exclude_list) putil.show_amenities_with_yes_status(response_data) msg = "Property found for specfied criteria" if len(response_data) else "Property not found" response_dict = putil.init_pagination_and_response_generatrion(request_data, response_data, msg, total_records) response_dict["tag"] = request_data.get("tag") return response_dict except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Get Tagged Property Operation Failed")
def share_property(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) user_name = frappe.db.get_value("User", {"user_id":request_data.get("user_id")}, ["first_name", "last_name"],as_dict=True) putil.validate_property_data(request_data, ["comments", "email_id"]) try: property_ids_list = { comment.get("property_id"):comment.get("comment","") for comment in request_data.get("comments") if comment.get("property_id")} search_query = { "query":{ "ids":{ "values":property_ids_list.keys() } }} es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",40)) if response_data: for response in response_data: response["comments"] = property_ids_list.get(response.get("property_id"),"") args = { "title":"Property Shared by {0}".format(email) , "property_data":response_data ,"first_name":user_name.get("first_name"), "last_name":user_name.get("last_name")} send_email(request_data.get("email_id"), "Propshikari properties shared with you", "/templates/share_property_template.html", args) return { "operation":"Share", "message":"Property Shared"} else: raise DoesNotExistError("Property Id does not exists in elastic search") except frappe.OutgoingEmailError: raise OutgoingEmailError("Email can not be sent,Outgoing email error") except elasticsearch.TransportError: raise DoesNotExistError("Property Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Share Property Operation Failed")
def get_builder_projects(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) search_query = { "query": { "match": { "posted_by": request_data.get("user_id") } } } try: es = ElasticSearchController() size = get_count_of_project_records(es) response_data, total_records = es.search_document( ["project"], search_query, request_data.get("page_number", 1), size) # response data & pagination logic msg = "User Project Found" if len( response_data) else "User Project not found" return putil.init_pagination_and_response_generatrion( request_data, response_data, msg, total_records) except elasticsearch.ElasticsearchException, e: raise ElasticSearchException(e.error) except Exception, e: raise OperationFailed("Get Builder Properties Operation Failed")
def get_similar_properties(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["request_type", "id"]) search_dict = {"property_id":get_search_query_of_property_id ,"request_id":get_search_query_of_request_id} if request_data.get("request_type") not in ["property_id", "request_id"]: raise InvalidDataError("Request type contains Invalid Data") search_query, uom = search_dict.get(request_data.get("request_type"))(request_data) try: sp_include_fields = ["property_photo", "property_id", "location", "address", "city", "carpet_area", "price","property_title"] es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",4), [], sp_include_fields) uom = "Sq.Ft." if uom not in ["Sq.Ft.", "Acres", "Hectares"] else uom putil.convert_area_according_to_uom(response_data, uom) response_msg = "Similar Property Found" if response_data else "Similar property not found" return { "operation":"Search", "message":response_msg , "total_records":len(response_data), "data":response_data, "user_id":request_data.get("user_id") } except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Get Similar property Operation Failed")
def get_user_properties(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) search_query = { "query": { "match":{ "posted_by":request_data.get("user_id") } } } try: # fields_to_be_excluded from response and resultset generation include_list = ["property_photo", "city", "location", "carpet_area", "amenities", "no_of_floors", "price", "status", "floor_no", "price_per_sq_ft", "property_id", "property_title", "tag", "possession_status", "property_subtype_option"] es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",40), [], include_list) response_data = check_for_shortlisted_property(response_data, request_data.get("user_id")) putil.show_amenities_with_yes_status(response_data) # response data & pagination logic msg = "User Property Found" if len(response_data) else "User Property not found" return putil.init_pagination_and_response_generatrion(request_data, response_data, msg, total_records) except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Get User Properties Operation Failed")
def get_property_of_given_id(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) try: exclude_list = [ "agent_name", "agent_no", "created_by", "modified_by", "creation_date", "modified_date", "posted_datetime", "modified_datetime" ] es = ElasticSearchController() response = es.search_document_for_given_id( "property", request_data.get("property_id"), exclude_list) return { "operation": "Search", "message": "Property found" if len(response) else "Property Not Found", "user_id": request_data.get("user_id"), "data": response } except elasticsearch.TransportError: raise DoesNotExistError("Property Id does not exists") except Exception, e: raise GetPropertyOperationFailed("Get Property Operation Failed")
def delete_multiple_photos(data): data = json.loads(data) full_size_img = [img_url.replace("thumbnail", "regular") for img_url in data.get("img_list")] prop_dict = {"user_id":data.get("user_id"), "sid":data.get("sid"), "property_id":data.get("property_id")} doc = get_property_details(json.dumps(prop_dict)) property_photo = get_property_photo(data.get("img_list"),doc.get("data").get("thumbnails")) update_query = get_script_query_for_multiple(full_size_img,data.get("img_list"),property_photo) if not doc.get("data").get("project_id",""): map(lambda img_url:delete_photo_from_propshikari(img_url),data.get("img_list")) es = ElasticSearchController() response = es.update_docuemnt("property", data.get("property_id"), update_query) prop_dict = {"user_id":data.get("user_id"), "sid":data.get("sid"), "property_id":data.get("property_id"), "fields":["thumbnails", "full_size_images", "property_photo"]} prop_response = get_property_details(json.dumps(prop_dict)) return { "message":"Property Photo deleted successfully", "full_size_images":prop_response.get("data").get("full_size_images", []), "thumbnails":prop_response.get("data").get("thumbnails", []), "property_photo":prop_response.get("data").get("property_photo", []) }
def get_shortlisted_property(request_data): if request_data: request_data = json.loads(request_data) # Check if shortlisted property existed against user email = putil.validate_for_user_id_exists(request_data.get("user_id")) property_ids_list = frappe.db.get_values("Shortlisted Property", {"user_id":request_data.get("user_id"), "status":"Active"}, "property_id") if not property_ids_list: return {"operation":"Search", "message":"No Single Shortlisted property found", "user_id":request_data.get("user_id")} property_ids_list = [ property_id[0] for property_id in property_ids_list if property_id] try: # generate search_query and resultset & fields to be included in response sp_include_fields= ["property_photo", "city", "location", "carpet_area", "amenities", "no_of_floors", "price", "status","floor_no", "price_per_sq_ft", "property_id", "property_title", "tag", "possession_status", "property_subtype_option", "unit_of_area", "property_age"] search_query = { "query":{ "ids":{ "values":property_ids_list } } } es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",40), [], sp_include_fields) # response data & pagination logic append_shortlisted_tag(response_data) msg = "Shortlisted Property Found" if len(response_data) else "Shortlsited Property not found" return putil.init_pagination_and_response_generatrion(request_data, response_data, msg, total_records) except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Get Shortlisted Property Operation Failed")
def store_request_in_elastic_search(property_data, search_query, request_type, adv_search_query=None): request_id = "REQ-" + cstr(int(time.time())) + '-' + cstr(random.randint(100000,999999)) request_dict = { "user_id":property_data.get("user_id"), "request_id":request_id, "operation":property_data.get("operation"), "property_type":property_data.get("property_type"), "property_subtype":property_data.get("property_subtype"), "project_type":property_data.get("project_type"), "project_subtype":property_data.get("project_subtype"), "location":property_data.get("location"), "property_subtype_option":property_data.get("property_subtype_option"), "min_area":property_data.get("min_area"), "max_area":property_data.get("max_area"), "min_budget":property_data.get("min_budget"), "max_budget":property_data.get("max_budget"), "city":property_data.get("city"), "unit_of_area":property_data.get("unit_of_area"), "search_query":cstr(search_query), "adv_search_query":cstr(adv_search_query), "request_type":request_type, } meta_dict = add_meta_fields_before_posting(property_data) request_dict.update(meta_dict) es = ElasticSearchController() es_result = es.index_document("request",request_dict, request_id) return request_id
def get_location_details_for_map(request_data): request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["request_id"]) try: es = ElasticSearchController() response = es.search_document_for_given_id("request",request_data.get("request_id"),[], ["search_query", "unit_of_area", "adv_search_query"]) search_query = ast.literal_eval(response.get("adv_search_query").encode("utf8")) uom = response.get("unit_of_area") include_fields = ["property_title", "property_id", "location", "property_subtype_option", "operation", "carpet_area", "price", "geo_location_lat", "geo_location_lon" ] size = get_count_of_property_records(es) response_data, total_records = es.search_document(["property"], search_query, 1, size, [], include_fields) uom = "Sq.Ft." if uom not in ["Sq.Ft.", "Acres", "Hectares"] else uom putil.convert_area_according_to_uom(response_data, uom) response_msg = "User Property Found" if response_data else "User property not found" return { "operation":"Search", "user_id":request_data.get("user_id"), "message":response_msg, "data":response_data } except elasticsearch.TransportError: raise DoesNotExistError("Request Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error)
def delete_property_photo(doc, img_url): full_size_img = img_url.replace("thumbnail", "regular") update_query = get_script_query(full_size_img, img_url) if not doc.get("project_id", "") or (img_url.find("PROP") != -1): delete_photo_from_propshikari(img_url) es = ElasticSearchController() response = es.update_docuemnt("property", doc.get("property_id"), update_query) prop_dict = { "user_id": doc.get("user_id"), "sid": doc.get("sid"), "property_id": doc.get("property_id"), "fields": ["thumbnails", "full_size_images", "property_photo"] } prop_response = get_property_details(json.dumps(prop_dict)) return { "message": "Property Photo deleted successfully", "full_size": ','.join(prop_response.get("data").get("full_size_images", [])), "thumbnails": ','.join(prop_response.get("data").get("thumbnails", [])), "photo": prop_response.get("data").get("property_photo", []) }
def search_unpublished_property(data): property_data = json.loads(data) try: # generate search query & result generation & list of fields which should be excluded. exclude_list = putil.get_exclude_list_for_search(property_data.get("request_source", "")) #must_clause_list.append([{"match":{ "published_status": "Unpublished" } }, { "match": { "status": "Deactivated" }}]) must_clause_list= [{"match":{ "published_status": "Unpublished" } }] search_query = { "query":{ "bool":{ "must":must_clause_list } }, "sort": [{ "posted_datetime": { "order": "desc" }}] } es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, property_data.get("page_number",1), property_data.get("records_per_page",40), exclude_list) if property_data.get("user_id") != "Guest": response_data = check_for_shortlisted_property(response_data,property_data.get("user_id")) response_data = putil.get_date_diff_and_count_from_posting(response_data) putil.convert_area_according_to_uom(response_data, property_data.get("unit_of_area", "Sq.Ft.")) putil.show_amenities_with_yes_status(response_data) # response data & pagination logic msg = "Property found for specfied criteria" if len(response_data) else "Property not found" response_dict = putil.init_pagination_and_response_generatrion(property_data, response_data, msg, total_records) return response_dict except elasticsearch.RequestError,e: raise ElasticInvalidInputFormatError(e.error)
def get_search_query_of_request_id(request_data): try: es = ElasticSearchController() response = es.search_document_for_given_id("request",request_data.get("id"),[],["search_query", "unit_of_area"]) search_query = ast.literal_eval(response.get("search_query").encode("utf8")) return search_query, response.get("unit_of_area") except elasticsearch.TransportError: raise DoesNotExistError("Request Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error)
def get_search_query_of_property_id(request_data): try: es = ElasticSearchController() response = es.search_document_for_given_id("property",request_data.get("id")) search_query = putil.generate_search_query_from_property_data(response) return search_query, "Sq.Ft." except elasticsearch.TransportError: raise DoesNotExistError("Property Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error)
def get_project_details(request_data): user_email = putil.validate_for_user_id_exists(request_data.get("user_id")) include_list = request_data.get("fields",[]) try: es = ElasticSearchController() response = es.search_document_for_given_id("project",request_data.get("project_id"), [], include_list) return {"opeartion":"Search", "message":"Project details Found", "data":response} except elasticsearch.TransportError: raise DoesNotExistError("Project Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error)
def delete_project_photo(doc, img_url): full, thumbnails, photo = init_for_photo_list_operation(doc, img_url) es = ElasticSearchController() search_query = {"doc":{ "full_size_images":full, "thumbnails":thumbnails, "project_photo":photo }} response = es.update_docuemnt("project", doc.get("project_id"), search_query) init_for_property_photo_update(es, img_url, doc.get("project_id")) return { "message":"Project Photo deleted successfully", "full_size":','.join(full), "thumbnails":','.join(thumbnails), "photo":photo }
def update_property_fields(data): request_data = json.loads(data) user_email = putil.validate_for_user_id_exists(request_data.get("user_id")) try: field_dict = get_updated_fields_dict(request_data, user_email) search_query = {"doc": field_dict } es = ElasticSearchController() update_response = es.update_docuemnt("property", request_data.get("property_id"), search_query) return {"opeartion":"Update", "message":"Property details Updated"} except elasticsearch.TransportError: raise DoesNotExistError("Property Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error)
def update_unpublished_property_flag(request_data): if request_data: try: property_data = prepare_query_of_published_properties(request_data.get("property_ids")) es = ElasticSearchController() response = es.bulk_upload(property_data) es.refresh_index() return {"operation":"Update" , "message":"Unpublished property status changed" if response else "upublished Status not changed", "user_id":request_data.get("user_id")} except elasticsearch.TransportError: raise DoesNotExistError("Property Id does not exists") except elasticsearch.ElasticsearchException,e: raise e except Exception,e: raise OperationFailed("Update Property Status Operation Failed")
def init_for_property_posting(project_data): property_data = prepare_property_posting_data(project_data) es = ElasticSearchController() property_list = [] for prop in property_data: new_prop = {} custom_id = "PROP-" + cstr(int(time.time())) + '-' + cstr(random.randint(10000,99999)) prop["_op_type"] = "index" prop["_index"] = "propshikari" prop["_type"] = "property" prop["_id"] = custom_id prop["property_id"] = custom_id new_prop.update(prop) property_list.append(new_prop) response_data = es.bulk_upload(property_list)
def create_snapshot(): snapshot_repo = frappe.get_hooks("snapshot_repo", app_name="propshikari")[0] snapshot_name = get_datetime().strftime("%Y%m%d_%H%M%S") es = ElasticSearchController() print now() try: response = es.create_snapshot(snapshot_repo, snapshot_name) if not response.get("state") == "SUCCESS": send_email(["*****@*****.**"], "Propshikari Elastic Backup Operation Error", "/templates/elastic_backup_notification.html", {"error_log":response}) return response except Exception,e: print "Elastic Backup Operation Failed" print frappe.get_traceback() print "Error Occured : ",e send_email(["*****@*****.**", "*****@*****.**"], "Propshikari Elastic Backup Operation Error", "/templates/elastic_backup_notification.html", {"error_log":frappe.get_traceback()})
def upadate_project_status(request_data): email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["project_id"]) try: search_query = {"doc":{ "status":request_data.get("project_status") }} es = ElasticSearchController() response = es.update_docuemnt("project", request_data.get("project_id"), search_query) return { "operation":"Update" , "message":"Project status changed" if response else "Project Status not changed", "user_id":request_data.get("user_id") } except elasticsearch.TransportError: raise DoesNotExistError("Project Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error)
def get_property_images(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) if not request_data.get("property_id"): raise MandatoryError("Property Id not provided") try: es = ElasticSearchController() response = es.search_document_for_given_id("property",request_data.get("property_id"),[],["full_size_images", "thumbnails"]) return { "operation":"Search", "message":"Property Images Found" if response else "Property Images Not Found", "user_id":request_data.get("user_id"), "data":response } except elasticsearch.TransportError: raise DoesNotExistError("Property Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Get Property Images Operation Failed")
def get_project_of_given_id(request_data): request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) if not request_data.get("project_id"): raise MandatoryError("Project id does not exists") try: exclude_list = putil.get_exclude_list_for_search("Hunterscamp") es = ElasticSearchController() response = es.search_document_for_given_id("project", request_data.get("project_id"), exclude_list) response_data = putil.get_date_diff_and_count_from_posting([response]) # putil.show_amenities_with_yes_status(response_data) return {"operation":"Search", "message":"Project details found" if len(response) else "Project Not Found", "user_id":request_data.get("user_id"), "data":response_data[0]} except elasticsearch.TransportError: raise DoesNotExistError("Project Id does not exists") except Exception,e: raise OperationFailed("Get Project Operation Failed")
def post_property(data): try: request_data = json.loads(data) property_data, email, subs_doc = validate_data_before_property_posting(request_data) custom_id = process_property_data_before_posting(property_data, request_data, email) es = ElasticSearchController() response_data = es.index_document("property",property_data, custom_id) subscription = get_subscription_of_user(subs_doc, response_data, email) response_msg = "Property posted successfully" if response_data.get("created",False) else "Property posting failed" return { "operation":"Create", "message":response_msg, "property_id":response_data.get("_id"), "user_id":request_data.get("user_id"), "data":{"subscriptions":subscription} } except elasticsearch.RequestError,e: raise ElasticInvalidInputFormatError(e.error)
def get_all_projects(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) search_query = { } try: include_list = ["project_id", "project_name"] es = ElasticSearchController() size = get_count_of_project_records(es) response_data, total_records = es.search_document(["project"], search_query, request_data.get("page_number",1), size, [], include_list) # response data & pagination logic msg = "Projects Found" if len(response_data) else "Projects not found" return putil.init_pagination_and_response_generatrion(request_data, response_data, msg, total_records) except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Get All Projects Operation Failed")