Exemplo n.º 1
0
    def patch(self, coverage_id):
        coverage = models.Coverage.get(coverage_id)
        if coverage is None:
            raise ObjectNotFound(
                "Coverage '{}' not found.".format(coverage_id))
        if 'id' in request.json and coverage.id != request.json['id']:
            raise InvalidArguments(
                'The modification of the id is not possible')
        coverage_schema = schema.CoverageSchema(partial=True)
        errors = coverage_schema.validate(request.json, partial=True)
        if errors:
            raise InvalidArguments(errors)

        logging.debug(request.json)
        try:
            coverage = models.Coverage.update(coverage_id, request.json)
        except PyMongoError:
            raise InternalServerError(
                'Impossible to update coverage with dataset {}'.format(
                    request.json))

        return {
            'coverages': schema.CoverageSchema().dump([coverage],
                                                      many=True).data
        }, 200
Exemplo n.º 2
0
    def get(self, coverage_id=None):
        if coverage_id:
            c = models.Coverage.get(coverage_id)
            if c is None:
                abort(404)
            return {'coverage': schema.CoverageSchema().dump(c)}, 200

        return {
            'coverages':
            schema.CoverageSchema(many=True).dump(list(models.Coverage.find()))
        }, 200
Exemplo n.º 3
0
    def get(self, coverage_id=None):
        if coverage_id:
            c = models.Coverage.get(coverage_id)
            if c is None:
                raise ObjectNotFound(
                    "Coverage '{}' not found.".format(coverage_id))

            result = schema.CoverageSchema().dump(c)
            return {'coverages': [result.data]}, 200

        coverages = models.Coverage.all()

        return {
            'coverages': schema.CoverageSchema(many=True).dump(coverages).data
        }, 200
    def post(self, coverage_id):
        coverage = models.Coverage.get(coverage_id)
        if coverage is None:
            raise ObjectNotFound("Coverage {} not found.".format(coverage_id))

        if 'id' not in request.json:
            raise InvalidArguments(
                'Missing data_source_id attribute in request body.')

        data_source_id = request.json['id']

        data_sources = models.DataSource.get(data_source_id=data_source_id)
        if data_sources is None:
            raise ObjectNotFound(
                "Data source {} not found.".format(data_source_id))

        if coverage.has_data_source(data_sources[0]):
            raise DuplicateEntry(
                'Data source id {} already exists in coverage {}.'.format(
                    data_source_id, coverage_id))

        coverage.add_data_source(data_sources[0])

        try:
            coverage = models.Coverage.update(
                coverage_id, {"data_sources": coverage.data_sources})
        except (PyMongoError, ValueError) as e:
            raise InternalServerError(
                'Impossible to update coverage {} with data_source {}.'.format(
                    coverage_id, data_source_id))

        return {
            'coverages': schema.CoverageSchema().dump([coverage],
                                                      many=True).data
        }, 200
Exemplo n.º 5
0
    def post(self):
        coverage_schema = schema.CoverageSchema(strict=True)
        try:
            coverage = coverage_schema.load(request.json).data
        except ValidationError as err:
            raise InvalidArguments(err.messages)

        try:
            coverage.save()
        except DuplicateKeyError:
            raise DuplicateEntry("Coverage {} already exists.".format(
                request.json['id']))
        except PyMongoError as e:
            raise InternalServerError('Impossible to add coverage.')

        return {
            'coverages': coverage_schema.dump([coverage], many=True).data
        }, 201
Exemplo n.º 6
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('id',
                            required=True,
                            help='id is required',
                            location='json')
        parser.add_argument('name',
                            required=True,
                            help='name is required',
                            location='json')

        args = parser.parse_args()

        coverage = models.Coverage(_id=args['id'], name=args['name'])
        try:
            coverage.save()
        except PyMongoError as e:
            logging.getLogger(__name__).exception(
                'impossible to add coverage {}'.format(coverage))
            return {'error': str(e)}, 400

        return {'coverage': schema.CoverageSchema().dump(coverage)}, 201