Пример #1
0
    def get(self, request, set_id):
        """Get a OaiProviderSet

        Args:

            request: HTTP request
            set_id: ObjectId

        Returns:

            - code: 200
              content: Registry
            - code: 404
              content: Object was not found
            - code: 500
              content: Internal server error
        """
        try:
            set_ = oai_provider_set_api.get_by_id(set_id)
            serializer = serializers.OaiProviderSetSerializer(
                set_, context={"request": request}
            )

            return Response(serializer.data, status=status.HTTP_200_OK)
        except exceptions.DoesNotExist:
            content = OaiPmhMessage.get_message_labelled(
                "No Set found with the given id."
            )
            return Response(content, status=status.HTTP_404_NOT_FOUND)
        except exceptions_oai.OAIAPIException as e:
            return e.response()
        except Exception as e:
            content = OaiPmhMessage.get_message_labelled(str(e))
            return Response(content, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Пример #2
0
    def patch(self, request, set_id):
        """ Update a OaiProviderSet

        Parameters:

            {
                "set_spec":"value",
                "set_name":"value",
                "templates_manager": ["id1", "id2"],
                "description":"value"
            }

        Args:

            request: HTTP request

        Returns:

            - code: 200
              content: Success message
            - code: 400
              content: Validation error
            - code: 404
              content: Object was not found
            - code: 500
              content: Internal server error
        """
        try:
            set_ = oai_provider_set_api.get_by_id(set_id)
            # Build serializer
            serializer = serializers.OaiProviderSetSerializer(
                instance=set_, data=request.data)
            # Validate data
            serializer.is_valid(True)
            # Save data
            serializer.save()
            content = OaiPmhMessage.get_message_labelled(
                'Set updated with success.')

            return Response(content, status=status.HTTP_200_OK)
        except ValidationError as validation_exception:
            content = OaiPmhMessage.get_message_labelled(
                validation_exception.detail)
            return Response(content, status=status.HTTP_400_BAD_REQUEST)
        except exceptions.DoesNotExist:
            content = OaiPmhMessage.get_message_labelled(
                'No Set found with the given id.')
            return Response(content, status=status.HTTP_404_NOT_FOUND)
        except exceptions_oai.OAIAPIException as e:
            return e.response()
        except Exception as e:
            content = OaiPmhMessage.get_message_labelled(e.message)
            return Response(content,
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Пример #3
0
    def post(self, request):
        """ Create a OaiProviderSet

        Parameters:

            {
                "set_spec": "value", 
                "set_name":"value", 
                "templates_manager": ["id1", "id2"], 
                "description":"value"
            }

        Args:

            request: HTTP request

        Returns:

            - code: 201
              content: Success Label
            - code: 400
              content: Validation error
            - code: 500
              content: Internal server error
        """
        try:
            # Build serializer
            serializer = serializers.OaiProviderSetSerializer(
                data=request.data)
            # Validate data
            serializer.is_valid(True)
            # Save data
            serializer.save()
            content = OaiPmhMessage.get_message_labelled(
                'Set added with success.')

            return Response(content, status=status.HTTP_201_CREATED)
        except ValidationError as validation_exception:
            content = OaiPmhMessage.get_message_labelled(
                validation_exception.detail)
            return Response(content, status=status.HTTP_400_BAD_REQUEST)
        except exceptions_oai.OAIAPIException as e:
            return e.response()
        except Exception as e:
            content = OaiPmhMessage.get_message_labelled(e.message)
            return Response(content,
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Пример #4
0
    def get(self, request):
        """ Get all OaiProviderSet

        Args:

            request: HTTP request

        Returns:

            - code: 200
              content: List of OaiProviderSet
            - code: 500
              content: Internal server error
        """
        try:
            sets = oai_provider_set_api.get_all()
            serializer = serializers.OaiProviderSetSerializer(sets, many=True)

            return Response(serializer.data, status=status.HTTP_200_OK)
        except Exception as e:
            content = OaiPmhMessage.get_message_labelled(e.message)
            return Response(content,
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)