def get_url_pair_by_long_url(shortUrl):
    url_pair_data_mapper = DataMapperRegistry.get(UrlPair)
    document = url_pair_data_mapper.get_by_long_url(shortUrl)

    if document:
        return UrlPair(document)

    return None
def get_user_by_id(user_id):
    user_data_mapper = DataMapperRegistry.get(User)
    document = user_data_mapper.get_by_id(user_id)

    if document:
        return User(document)

    return None
def configure_data_mapper_registry():
    logger.debug("Configuring data mapper registry")

    DataMapperRegistry.register(AvailableWordsForSource,
                                AvailableWordsForSourceMongoDbDataMapper())
    DataMapperRegistry.register(UrlPair, UrlPairMongoDbDataMapper())
    DataMapperRegistry.register(User, UserMongoDbDataMapper())
    def setUp(self):
        self.url_pair_data_mapper = UrlPairInMemoryDataMapper()
        self.user_data_mapper = UserInMemoryDataMapper()
        self.available_words_for_source_data_mapper = (
            AvailableWordsForSourceInMemoryDataMapper())

        DataMapperRegistry.register(UrlPair, self.url_pair_data_mapper)
        DataMapperRegistry.register(User, self.user_data_mapper)
        DataMapperRegistry.register(
            AvailableWordsForSource,
            self.available_words_for_source_data_mapper)
Beispiel #5
0
def get_random_available_word(source):
    available_words_for_source_data_mapper = DataMapperRegistry.get(
        AvailableWordsForSource)
    return available_words_for_source_data_mapper.get_random_available_word_from_source(
        source)
Beispiel #6
0
def get_remaining_available_words_count(source):
    available_words_for_source_data_mapper = DataMapperRegistry.get(
        AvailableWordsForSource)

    return available_words_for_source_data_mapper.get_available_words_count()
Beispiel #7
0
def get_random_available_asgardian_word():
    available_words_for_source_data_mapper = DataMapperRegistry.get(
        AvailableWordsForSource)

    return available_words_for_source_data_mapper.get_random_available_asgardian_word(
    )
def invalidate_url_pair(url_pair, reason):
    url_pair_data_mapper = DataMapperRegistry.get(UrlPair)
    url_pair_data_mapper.invalidate(url_pair, reason)
def update_number_of_times_accessed_record(url_pair, times_accessed):
    url_pair_data_mapper = DataMapperRegistry.get(UrlPair)
    url_pair_data_mapper.update_number_of_times_accessed(
        url_pair, times_accessed)
def insert_url_pair(url_pair):
    url_pair_data_mapper = DataMapperRegistry.get(UrlPair)
    url_pair_data_mapper.insert(url_pair)
def get_all_url_pairs_for_user(user_id):
    url_pair_data_mapper = DataMapperRegistry.get(UrlPair)
    documents = url_pair_data_mapper.get_by_user_id(user_id)

    return documents
def insert_user(user):
    user_data_mapper = DataMapperRegistry.get(User)
    document = user_data_mapper.create_user(user)