def convert_item_metadata(self, index_obj): """ 1. Convert Item Metadata 2. Inject index tree id to dict 3. Set Publish Status :param index_obj: :return: dc """ # if this item has been deleted self.delete_es_index_attempt(self.pid) try: actions = index_obj.get('actions', 'private') datastore = RedisStore(redis.StrictRedis.from_url( current_app.config['CACHE_REDIS_URL'])) cache_key = current_app.config[ 'WEKO_DEPOSIT_ITEMS_CACHE_PREFIX'].format( pid_value=self.pid.pid_value) data_str = datastore.get(cache_key) datastore.delete(cache_key) data = json.loads(data_str) except: abort(500, 'Failed to register item') # Get index path index_lst = index_obj.get('index', []) plst = Indexes.get_path_list(index_lst) if not plst or len(index_lst) != len(plst): raise PIDResolveRESTError(description='Any tree index has been deleted') index_lst.clear() for lst in plst: index_lst.append(lst.path) # convert item meta data dc, jrc, is_edit = json_loader(data, self.pid) self.data = data self.jrc = jrc self.is_edit = is_edit # Save Index Path on ES jrc.update(dict(path=index_lst)) dc.update(dict(path=index_lst)) pubs = '1' if 'private' in actions else '0' ps = dict(publish_status=pubs) jrc.update(ps) dc.update(ps) return dc
def handle_check_index(list_index: list) -> bool: """Handle check index. :argument list_index -- {list} list index id. :return return -- true if exist. """ result = True index_lst = [] if list_index: index_id_lst = [] for index in list_index: indexes = str(index).split('/') index_id_lst.append(indexes[len(indexes) - 1]) index_lst = index_id_lst plst = Indexes.get_path_list(index_lst) if not plst or len(index_lst) != len(plst): result = False return result
def convert_item_metadata(self, index_obj, data=None): """Convert Item Metadat. 1. Convert Item Metadata 2. Inject index tree id to dict 3. Set Publish Status :param index_obj: :return: dc """ # if this item has been deleted self.delete_es_index_attempt(self.pid) try: actions = index_obj.get('actions', 'private') if not data: datastore = RedisStore( redis.StrictRedis.from_url( current_app.config['CACHE_REDIS_URL'])) cache_key = current_app.config[ 'WEKO_DEPOSIT_ITEMS_CACHE_PREFIX'].format( pid_value=self.pid.pid_value) data_str = datastore.get(cache_key) datastore.delete(cache_key) data = json.loads(data_str.decode('utf-8')) except BaseException: abort(500, 'Failed to register item') # Get index path index_lst = index_obj.get('index', []) # Prepare index id list if the current index_lst is a path list if index_lst: index_id_lst = [] for index in index_lst: indexes = str(index).split('/') index_id_lst.append(indexes[len(indexes) - 1]) index_lst = index_id_lst plst = Indexes.get_path_list(index_lst) if not plst or len(index_lst) != len(plst): raise PIDResolveRESTError( description='Any tree index has been deleted') index_lst.clear() for lst in plst: index_lst.append(lst.path) # convert item meta data dc, jrc, is_edit = json_loader(data, self.pid) self.data = data self.jrc = jrc self.is_edit = is_edit # Save Index Path on ES jrc.update(dict(path=index_lst)) # add at 20181121 start sub_sort = {} for pth in index_lst: # es setting sub_sort[pth[-13:]] = "" jrc.update(dict(custom_sort=sub_sort)) dc.update(dict(custom_sort=sub_sort)) dc.update(dict(path=index_lst)) pubs = '1' if 'private' in actions else '0' ps = dict(publish_status=pubs) jrc.update(ps) dc.update(ps) return dc