Exemple #1
0
 def create(self, validated_data):
     node = self.context['view'].get_node()
     auth = get_user_auth(self.context['request'])
     if validated_data.get('category', None) == 'doi':
         if node.get_identifier('doi'):
             raise exceptions.ValidationError(
                 'A DOI already exists for this resource.')
         try:
             identifiers = get_or_create_identifiers(node)
         except HTTPError:
             raise exceptions.ValidationError('Error response from client.')
         except TypeError:
             raise ServiceUnavailableError()
         for category, value in identifiers.items():
             node.set_identifier_value(category, value)
         node.add_log(
             NodeLog.EXTERNAL_IDS_ADDED,
             params={
                 'parent_node': node.parent_id,
                 'node': node._id,
                 'identifiers': identifiers,
             },
             auth=auth,
         )
         return node.identifiers.get(category='doi')
     else:
         raise exceptions.ValidationError(
             'You can only mint a DOI, not a different type of identifier.')
def node_identifiers_post(auth, node, **kwargs):
    """Create identifier pair for a node. Node must be a public registration.
    """
    # TODO this functionality exists in APIv2. When front end is entirely using
    # v2 for minting DOI's, remove this view.
    if not node.is_public or node.is_retracted:
        raise HTTPError(http_status.HTTP_400_BAD_REQUEST)
    if node.get_identifier('doi') or node.get_identifier('ark'):
        raise HTTPError(http_status.HTTP_400_BAD_REQUEST)
    try:
        identifiers = get_or_create_identifiers(node)
    except HTTPError:
        raise HTTPError(http_status.HTTP_400_BAD_REQUEST)
    for category, value in identifiers.items():
        node.set_identifier_value(category, value)
    node.add_log(
        NodeLog.EXTERNAL_IDS_ADDED,
        params={
            'parent_node': node.parent_id,
            'node': node._id,
            'identifiers': identifiers,
        },
        auth=auth,
    )
    return identifiers, http_status.HTTP_201_CREATED
 def create(self, validated_data):
     node = self.context['view'].get_node()
     auth = get_user_auth(self.context['request'])
     if validated_data.get('category', None) == 'doi':
         if node.get_identifier('doi'):
             raise exceptions.ValidationError('A DOI already exists for this resource.')
         try:
             identifiers = get_or_create_identifiers(node)
         except HTTPError:
             raise exceptions.ValidationError('Error response from client.')
         except TypeError:
             raise ServiceUnavailableError()
         for category, value in identifiers.items():
             node.set_identifier_value(category, value)
         node.add_log(
             NodeLog.EXTERNAL_IDS_ADDED,
             params={
                 'parent_node': node.parent_id,
                 'node': node._id,
                 'identifiers': identifiers,
             },
             auth=auth,
         )
         return node.identifiers.get(category='doi')
     else:
         raise exceptions.ValidationError('You can only mint a DOI, not a different type of identifier.')
Exemple #4
0
def node_identifiers_post(auth, node, **kwargs):
    """Create identifier pair for a node. Node must be a public registration.
    """
    if not node.is_public or node.is_retracted:
        raise HTTPError(http.BAD_REQUEST)
    if node.get_identifier('doi') or node.get_identifier('ark'):
        raise HTTPError(http.BAD_REQUEST)
    try:
        identifiers = get_or_create_identifiers(node)
    except HTTPError:
        raise HTTPError(http.BAD_REQUEST)
    for category, value in identifiers.iteritems():
        node.set_identifier_value(category, value)
    node.add_log(
        NodeLog.EXTERNAL_IDS_ADDED,
        params={
            'parent_node': node.parent_id,
            'node': node._id,
            'identifiers': identifiers,
        },
        auth=auth,
    )
    return identifiers, http.CREATED
Exemple #5
0
def node_identifiers_post(auth, node, **kwargs):
    """Create identifier pair for a node. Node must be a public registration.
    """
    if not node.is_public or node.is_retracted:
        raise HTTPError(http.BAD_REQUEST)
    if node.get_identifier('doi') or node.get_identifier('ark'):
        raise HTTPError(http.BAD_REQUEST)
    try:
        identifiers = get_or_create_identifiers(node)
    except HTTPError:
        raise HTTPError(http.BAD_REQUEST)
    for category, value in identifiers.items():
        node.set_identifier_value(category, value)
    node.add_log(
        NodeLog.EXTERNAL_IDS_ADDED,
        params={
            'parent_node': node.parent_id,
            'node': node._id,
            'identifiers': identifiers,
        },
        auth=auth,
    )
    return identifiers, http.CREATED