def generate_unique_id_and_name(item): """ Generates and appends unique_id and unique_name to item. :throws IdentifierGenerationError: if unable to generate unique_id """ try: unique_id = update_key("INGEST_SEQ", flag=True) if unique_id: item['unique_id'] = unique_id item['unique_name'] = "#" + str(unique_id) else: raise IdentifierGenerationError() except Exception as e: raise IdentifierGenerationError() from e
def generate_unique_id_and_name(item, repo_type=ARCHIVE): """ Generates and appends unique_id and unique_name to item. :throws IdentifierGenerationError: if unable to generate unique_id """ try: key_name = 'TEST_{}_SEQ'.format(repo_type.upper()) if superdesk.app.config.get('SUPERDESK_TESTING', False) \ else '{}_SEQ'.format(repo_type.upper()) unique_id = update_key(key_name, flag=True) if unique_id: item['unique_id'] = unique_id item['unique_name'] = "#" + str(unique_id) else: raise IdentifierGenerationError() except Exception as e: raise IdentifierGenerationError() from e
def generate_unique_id_and_name(item, repo_type=ARCHIVE): """Generates and appends unique_id and unique_name to item. :throws IdentifierGenerationError: if unable to generate unique_id """ try: unique_id = get_resource_service('sequences').get_next_sequence_number( key_name='{}_SEQ'.format(repo_type.upper())) item['unique_id'] = unique_id item['unique_name'] = "#" + str(unique_id) except Exception as e: raise IdentifierGenerationError() from e