diff --git a/mcm/couchdb_layer/mcm_database.py b/mcm/couchdb_layer/mcm_database.py index 6e4b7830..cd02f751 100644 --- a/mcm/couchdb_layer/mcm_database.py +++ b/mcm/couchdb_layer/mcm_database.py @@ -537,7 +537,8 @@ def full_text_search(self, index_name, query, page=0, limit=20, get_raw=False, i __retries = 3 limit, skip = self.__pagify(int(page), limit=int(limit)) url = "_design/lucene/%s?q=%s" % (index_name, query) - for i in xrange(1, __retries+1): + data = {'rows': []} + for i in xrange(1, __retries + 1): try: options = { 'limit': limit, @@ -549,16 +550,20 @@ def full_text_search(self, index_name, query, page=0, limit=20, get_raw=False, i options['include_fields'] = include_fields if sort != '': options['sort'] = sort - data = self.db.FtiSearch(url, options=options, get_raw=get_raw) #we sort ascending by doc._id field + data = self.db.FtiSearch(url, options=options, get_raw=get_raw) # we sort ascending by doc._id field break except Exception as ex: - self.logger.info("lucene DB query: %s failed %s. retrying: %s out of: %s" % ( - url, ex, i, __retries)) - ##if we are retrying we should wait little bit + self.logger.info("lucene DB query: %s failed %s. retrying: %s out of: %s" % (url, + ex, + i, + __retries)) + # if we are retrying we should wait little bit time.sleep(0.5) + if include_fields != '': - return [ elem["fields"] for elem in data['rows']] - return data if get_raw else [ elem["doc"] for elem in data['rows']] + return [elem["fields"] for elem in data['rows']] + + return data if get_raw else [elem["doc"] for elem in data['rows']] def raw_view_query(self, view_doc, view_name, options={}, cache=True): sequence_id = "%s/%s" % (view_doc, view_name) diff --git a/mcm/json_layer/chained_campaign.py b/mcm/json_layer/chained_campaign.py index 6bc4e157..7de9101c 100644 --- a/mcm/json_layer/chained_campaign.py +++ b/mcm/json_layer/chained_campaign.py @@ -36,7 +36,8 @@ def __str__(self): 'flag': True }, 'history': [], - 'valid': True + 'valid': True, + 'chain_type': 'TaskChain' } def __init__(self, json_input=None): @@ -119,8 +120,9 @@ def generate_request(self, root_request_id): # set values creq.set_attribute('pwg', pwg) - creq.set_attribute('member_of_campaign', self.get_attribute('prepid')) + creq.set_attribute('member_of_campaign', self.get_attribute('prepid')) creq.set_attribute('action_parameters', self.get_attribute('action_parameters')) + creq.set_attribute('chain_type', self.get_attribute('chain_type')) # By default flag should be true creq.get_attribute('action_parameters')['flag'] = True if not creq.get_attribute('prepid'): diff --git a/mcm/rest_api/ChainedRequestActions.py b/mcm/rest_api/ChainedRequestActions.py index b2d742bf..2f2e75d0 100644 --- a/mcm/rest_api/ChainedRequestActions.py +++ b/mcm/rest_api/ChainedRequestActions.py @@ -12,6 +12,7 @@ from tools.user_management import access_rights from flask_restful import reqparse from tools.locker import locker +from ChainedRequestPrepId import ChainedRequestPrepId class CreateChainedRequest(RESTResource): @@ -51,6 +52,14 @@ def import_request(self, data): if not req.get_attribute('prepid'): self.logger.error('prepid returned was None') raise ValueError('Prepid returned was None') + + if 'chain_type' in json_input: + chain_type = json_input['chain_type'] + else: + ccdb = database('chained_campaigns') + chain_type = ccdb.get(json_input['member_of_campaign']).get('chain_type', 'TaskChain') + + req.set_attribute('chain_type', chain_type) self.logger.info('Created new chained_request %s' % cr_id) # update history with the submission details req.update_history({'action': 'created'})