def _get_case_mock(project, params): # this is mostly copy/paste/modified from CommCareCaseResource es_query = es_search_by_params(params, project) query_set = ElasticAPIQuerySet( payload=es_query, model=ESCase, es_client=CaseES(project), ).order_by('server_modified_on') return MockApi(query_set, CommCareCaseResource(), CommCareCaseSerializer())
def _get_case_mock(project, params): # this is mostly copy/paste/modified from CommCareCaseResource filters = CaseListFilters(params).filters query = ElasticCaseQuery(project, filters).get_query() if 'from' in query: del query['from'] if 'size' in query: del query['size'] query_set = ElasticAPIQuerySet( payload=query, model=ESCase, es_client=CaseES(project), ).order_by('server_modified_on') return MockApi(query_set, CommCareCaseResource(), CommCareCaseSerializer())
def obj_get_list(self, bundle, domain, **kwargs): filters = v0_3.CaseListFilters(bundle.request.GET).filters # Since tastypie handles the "from" and "size" via slicing, we have to wipe them out here # since ElasticCaseQuery adds them. I believe other APIs depend on the behavior of ElasticCaseQuery # hence I am not modifying that query = ElasticCaseQuery(domain, filters).get_query() if 'from' in query: del query['from'] if 'size' in query: del query['size'] return ESQuerySet( payload=query, model=lambda jvalue: dict_object( CommCareCase.wrap(jvalue).get_json()), es_client=CaseES(domain) ) # Not that XFormES is used only as an ES client, for `run_query` against the proper index
def get_case_by_identifier(domain, identifier): # circular import from corehq.apps.api.es import CaseES case_es = CaseES(domain) def _query_by_type(i_type): q = case_es.base_query(terms={ i_type: identifier, }, fields=['_id', i_type], size=1) response = case_es.run_query(q) raw_docs = response['hits']['hits'] if raw_docs: return CommCareCase.get(raw_docs[0]['_id']) # Try by any of the allowed identifiers for identifier_type in ALLOWED_CASE_IDENTIFIER_TYPES: case = _query_by_type(identifier_type) if case is not None: return case
def case_es(self, domain): return MOCK_CASE_ES or CaseES(domain)
def case_es(self): return CaseES(self.domain)
def case_es(self, domain): # Note that CaseES is used only as an ES client, for `run_query` against the proper index return MOCK_CASE_ES or CaseES(domain)