Ejemplo n.º 1
0
def delete_post(self, user_uri, post_uri):
    """
    Delete post record from main store.
    Automatically retries the task if the record is locked.
    The post will be deleted from public store if required.

    Arguments:
        user_uri -- user identifier
        post_uri -- post identifier
    Returns:
        None or an error type:
            EntryAccessError: the user is not allowed to modify the entry

        Unhandled non-catalog errors will result in an exception.
    """
    try:
        with RedisLock(self.lock_db, post_uri):
            with self.main_store as store:
                timestamp = get_timestamp()
                store.delete_post(user_uri, post_uri)

                log_event.apply_async(args=('delete_post', timestamp, user_uri,
                                            None, post_uri, None))

                on_delete_post.send(sender=self,
                                    timestamp=timestamp,
                                    user_uri=user_uri,
                                    post_uri=post_uri)
    except CatalogError as e:
        return error(e)
    except LockedError as e:
        raise self.retry(exc=e, countdown=1)
Ejemplo n.º 2
0
def public_update_post(self, timestamp, user_uri, post_uri, post_data):
    """Update a post record in public store.
    See update_post documentation for description of parameters."""
    try:
        with RedisLock(self.lock_db, "public." + post_uri):
            with self.public_store as store:
                store.update_post(timestamp, user_uri, post_uri, post_data)
    except LockedError as e:
        raise self.retry(exc=e, countdown=5, max_retries=None)
Ejemplo n.º 3
0
def public_create_work(self, timestamp, user_uri, work_uri, work_data):
    """Create a work record in public store.
    See create_work documentation for description of parameters."""
    try:
        with RedisLock(self.lock_db, "public." + work_uri):
            with self.public_store as store:
                store.create_work(timestamp, user_uri, work_uri, work_data)
    except LockedError as e:
        raise self.retry(exc=e, countdown=5, max_retries=None)
Ejemplo n.º 4
0
def public_delete_source(self, timestamp, user_uri, source_uri, unlink=True):
    """Delete a source record in public store.
    See delete_source documentation for description of parameters."""
    try:
        with RedisLock(self.lock_db, "public." + source_uri):
            with self.public_store as store:
                store.delete_source(user_uri, source_uri)
    except EntryNotFoundError:
        pass
    except LockedError as e:
        raise self.retry(exc=e, countdown=5, max_retries=None)
Ejemplo n.º 5
0
def create_work_source(self, user_uri, work_uri, source_uri, source_data):
    """
    Create source related to a work in main store.
    Automatically retries the task if the record is locked.
    The source will be created in public store if the related work is public.

    Arguments:
        user_uri -- user identifier
        work_uri -- work identifier
        source_uri -- source identifier
        source_data -- data as dict, must conform to the Source schema.
        Keys used when creating the record are:
            'id': Numeric source ID
            'metadataGraph': Source metadata as RDF/JSON dict, default empty
            'cachedExternalMetadataGraph': External metadata as RDF/JSON dict, default empty
            'resource': The source URI
    Returns:
        Normalized source record as dict or an error type:
            ParamError: some entry data parameter is missing or invalid
            EntryAccessError: the user is not allowed to modify the entry

        Unhandled non-catalog errors will result in an exception.
    """
    try:
        with RedisLock(self.lock_db, work_uri):
            with self.main_store as store:
                timestamp = get_timestamp()
                source_data = store.create_work_source(timestamp, user_uri,
                                                       work_uri, source_uri,
                                                       source_data)

                log_data = json.dumps(source_data)
                log_event.apply_async(args=('create_work_source', timestamp,
                                            user_uri, work_uri, source_uri,
                                            log_data))

                on_create_work_source.send(sender=self,
                                           timestamp=timestamp,
                                           user_uri=user_uri,
                                           work_uri=work_uri,
                                           source_uri=source_uri,
                                           source_data=source_data)
                return source_data
    except CatalogError as e:
        return error(e)
    except LockedError as e:
        raise self.retry(exc=e, countdown=1)
Ejemplo n.º 6
0
def create_work(self, user_uri, work_uri, work_data):
    """
    Create a work record in main store.
    The work will be created in public store if it is visible for public.
    Automatically retries the task if the record is locked.

    Arguments:
        user_uri -- user identifier
        work_uri -- work identifier
        work_data -- data as dict, must conform to the Work schema.
        Keys looked for when storing the record:
            'id':           Numeric ID for work
            'visible':      Possible values: 'private', 'group', 'public'
                            Default: 'private'
            'state':        Possible values: 'draft', 'published'
                            Default: 'draft'
            'metadataGraph': Work metadata as RDF/JSON dict, default empty
    Returns:
        Normalized work record as dict or an error type:
            ParamError: some entry data parameter is missing or invalid

        Unhandled non-catalog errors will result in an exception.
    """
    try:
        with RedisLock(self.lock_db, work_uri):
            with self.main_store as store:
                timestamp = get_timestamp()
                work_data = store.create_work(timestamp, user_uri, work_uri,
                                              work_data)

                log_data = json.dumps(work_data)
                log_event.apply_async(args=('create_work', timestamp, user_uri,
                                            work_uri, None, log_data))

                on_create_work.send(sender=self,
                                    timestamp=timestamp,
                                    user_uri=user_uri,
                                    work_uri=work_uri,
                                    work_data=work_data)
                return work_data
    except CatalogError as e:
        return error(e)
    except LockedError as e:
        raise self.retry(exc=e, countdown=1)
Ejemplo n.º 7
0
def update_source(self, user_uri, source_uri, source_data):
    """
    Update a source record (stock or work source) in main store.
    Automatically retries the task if record is locked.
    The source will be updated in public store if it's a work source and the related work is public.

    Arguments:
        user_uri -- user identifier
        source_uri -- source identifier
        source_data -- data as dict, must conform to the Source schema.
        Only the included properties will be updated:
            'metadataGraph': Source metadata as RDF/JSON dict
            'cachedExternalMetadataGraph': External metadata as RDF/JSON dict
            'resource': The source URI
    Returns:
        Normalized source record as dict or an error type:
            ParamError: some entry data parameter is missing or invalid
            EntryAccessError: the user is not allowed to modify the entry

        Unhandled non-catalog errors will result in an exception.
    """
    try:
        with RedisLock(self.lock_db, source_uri):
            with self.main_store as store:
                timestamp = get_timestamp()
                source_data = store.update_source(timestamp, user_uri,
                                                  source_uri, source_data)

                log_data = json.dumps(source_data)
                log_event.apply_async(args=('update_source', timestamp,
                                            user_uri, None, source_uri,
                                            log_data))

                on_update_source.send(sender=self,
                                      timestamp=timestamp,
                                      user_uri=user_uri,
                                      source_uri=source_uri,
                                      source_data=source_data)
                return source_data
    except CatalogError as e:
        return error(e)
    except LockedError as e:
        raise self.retry(exc=e, countdown=1)
Ejemplo n.º 8
0
def update_work(self, user_uri, work_uri, work_data):
    """Update work record in main store.
    The work will be updated in public store if it's visible is public after updating.
    Automatically retries the task if the record is locked.

    Arguments:
        user_uri -- user identifier
        work_uri -- work identifier
        work_data -- data as dict, must conform to the Work schema.
        Only listed properties will be updated:
            'visible':   Possible values: 'private', 'group', 'public'
            'state':        Possible values: 'draft', 'published'
            'metadataGraph': Work metadata as RDF/JSON dict, default empty
    Returns:
        Normalized work record as dict or an error type:
            ParamError: some entry data parameter is missing or invalid
            EntryAccessError: the user is not allowed to modify the entry

        Unhandled non-catalog errors will result in an exception.
    """
    try:
        with RedisLock(self.lock_db, work_uri):
            with self.main_store as store:
                timestamp = get_timestamp()
                work_data = store.update_work(timestamp, user_uri, work_uri,
                                              work_data)

                log_data = json.dumps(work_data)
                log_event.apply_async(args=('update_work', timestamp, user_uri,
                                            work_uri, None, log_data))

                on_update_work.send(sender=self,
                                    timestamp=timestamp,
                                    user_uri=user_uri,
                                    work_uri=work_uri,
                                    work_data=work_data)
                return work_data
    except CatalogError as e:
        return error(e)
    except LockedError as e:
        raise self.retry(exc=e, countdown=1)