def create_or_replace(uid, stream=None, **kwargs): ''' Create or replace a resource with a specified UID. If the resource already exists, all user-provided properties of the existing resource are deleted. If the resource exists and the provided content is empty, an exception is raised (not sure why, but that's how FCREPO4 handles it). @param uid (string) UID of the resource to be created or updated. @param stream (BytesIO) Content stream. If empty, an empty container is created. @param **kwargs Other parameters are passed to the LdpFactory.from_provided method. Please see the documentation for that method for explanation of individual parameters. @return string Event type: whether the resource was created or updated. ''' rsrc = LdpFactory.from_provided(uid, stream=stream, **kwargs) if not stream and rsrc.is_stored: raise InvalidResourceError( rsrc.uid, 'Resource {} already exists and no data set was provided.') return rsrc.create_or_replace_rsrc()
def create(parent, slug, **kwargs): r""" Mint a new UID and create a resource. The UID is computed from a given parent UID and a "slug", a proposed path relative to the parent. The application will attempt to use the suggested path but it may use a different one if a conflict with an existing resource arises. :param str parent: UID of the parent resource. :param str slug: Tentative path relative to the parent UID. :param \*\*kwargs: Other parameters are passed to the :py:meth:`~lakesuperior.model.ldp_factory.LdpFactory.from_provided` method. :rtype: str :return: UID of the new resource. """ uid = LdpFactory.mint_uid(parent, slug) logger.debug('Minted UID for new resource: {}'.format(uid)) rsrc = LdpFactory.from_provided(uid, **kwargs) rsrc.create_or_replace(create_only=True) return uid
def create_or_replace(uid, **kwargs): r""" Create or replace a resource with a specified UID. :param string uid: UID of the resource to be created or updated. :param \*\*kwargs: Other parameters are passed to the :py:meth:`~lakesuperior.model.ldp_factory.LdpFactory.from_provided` method. :rtype: str :return: Event type: whether the resource was created or updated. """ return LdpFactory.from_provided(uid, **kwargs).create_or_replace()
def create(parent, slug, **kwargs): ''' Mint a new UID and create a resource. The UID is computed from a given parent UID and a "slug", a proposed path relative to the parent. The application will attempt to use the suggested path but it may use a different one if a conflict with an existing resource arises. @param parent (string) UID of the parent resource. @param slug (string) Tentative path relative to the parent UID. @param **kwargs Other parameters are passed to the LdpFactory.from_provided method. Please see the documentation for that method for explanation of individual parameters. @return string UID of the new resource. ''' uid = LdpFactory.mint_uid(parent, slug) logger.debug('Minted UID for new resource: {}'.format(uid)) rsrc = LdpFactory.from_provided(uid, **kwargs) rsrc.create_or_replace_rsrc(create_only=True) return uid