Пример #1
0
    def get(self, request, registry_id):
        """Retrieve a Registry (Data provider)

        Args:

            request: HTTP request
            registry_id: ObjectId

        Returns:

            - code: 200
              content: Registry
            - code: 404
              content: Object was not found
            - code: 500
              content: Internal server error
        """
        try:
            registry = oai_registry_api.get_by_id(registry_id)
            serializer = serializers.RegistrySerializer(
                registry, context={"request": request})

            return Response(serializer.data, status=status.HTTP_200_OK)
        except exceptions.DoesNotExist:
            content = OaiPmhMessage.get_message_labelled(
                "No registry 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 post(self, request):
        """Create a Registry (Data provider)

        Parameters:

            {
                "url" : "value",
                "harvest_rate" : "number",
                "harvest" : "True or False"
            }

        Args:

            request: HTTP request

        Returns:

            - code: 201
              content: Created Registry
            - code: 400
              content: Validation error
            - code: 500
              content: Internal server error
        """
        try:
            # Build serializer
            serializer = serializers.RegistrySerializer(
                data=request.data, context={"request": request})
            # Validate data
            serializer.is_valid(True)
            # Save data
            registry = serializer.save()
            content = OaiPmhMessage.get_message_labelled(
                "Registry {0} added with success.".format(registry.name))

            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(str(e))
            return Response(content,
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Пример #3
0
    def get(self, request):
        """ Get all Registries (Data provider)

        Args:

            request: HTTP request

        Returns:

            - code: 200
              content: List of Registries
            - code: 500
              content: Internal server error
        """
        try:
            registry = oai_registry_api.get_all()
            serializer = serializers.RegistrySerializer(registry, 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)