Esempio n. 1
0
    def get(self, portalid, datasetid):
        if request.headers.get('Accept-Datetime'):
            acc_dt = request.headers['Accept-Datetime']
            sn = getSnapshotfromTime(parse_rfc1123(acc_dt))
        else:
            sn = getCurrentSnapshot()

        session = current_app.config['dbsession']

        q = session.query(DatasetData) \
            .join(Dataset, DatasetData.md5 == Dataset.md5) \
            .filter(Dataset.snapshot == sn) \
            .filter(Dataset.portalid == portalid) \
            .filter(Dataset.id == datasetid)
        data = q.first()
        p = session.query(Portal).filter(Portal.id == portalid).first()
        doc = dcat_to_schemadotorg.convert(p, data.raw)
        timegate = '<' + HOST + '/' + portalid + '/' + datasetid + '/schemadotorg>'
        resp = add_memento_header(jsonify(doc), '<' + doc['@id'] + '>', timegate, sn)

        resp.headers['Vary'] = 'accept-datetime'
        d = tofirstdayinisoweek(sn)
        full_url = '<' + HOST + '/' + portalid + '/' + d.strftime("%y%m%d") + '/' + datasetid + '/schemadotorg>'
        resp.headers['Content-Location'] = full_url
        return resp
Esempio n. 2
0
    def get(self, portalid, snapshot, datasetid):
        with Timer(key="PortalDatasetData.get",verbose=True):
            session=current_app.config['dbsession']

            q=session.query(DatasetData) \
                .join(Dataset, DatasetData.md5 == Dataset.md5) \
                .filter(Dataset.snapshot==snapshot)\
                .filter(Dataset.portalid==portalid)\
                .filter(Dataset.id == datasetid)
            data=q.first()
            p = session.query(Portal).filter(Portal.id==portalid).first()
            doc = dcat_to_schemadotorg.convert(p, data.raw)
            return jsonify(doc)
Esempio n. 3
0
    def _get_schema(self, args, data, filename):
        try:
            default_url = 'http://missing.portal.url.com'
            portal_url = args.get('portal_url', default_url)
            if not portal_url:
                portal_url = default_url

            default_country = 'undefined'
            country = args.get('country', default_country)
            if not country:
                country = default_country

            if 'software' in args:
                software = args['software']
                g = rdflib.Graph()

                # stub portal class
                class Portal:
                    def __init__(self, software, uri, iso):
                        self.software = software
                        self.apiuri = uri
                        self.iso = iso
                        self.uri = uri

                p = Portal(software, portal_url, country)

                doc = dcat_to_schemadotorg.convert(p, data)
                resp = jsonify(doc)
                filename = secure_filename(filename).split('/')[-1]
                return makeResponse(resp, filename)
            else:
                e = 'Portal software parameter required for conversion. ' \
                    '"software" should be "CKAN", "Socrata", or "OpenDataSoft".'
        except Exception as ex:
            e = ex.message

        resp = jsonify({'error': 'Could not parse JSON', 'message': e})
        resp.status_code = 406
        return resp
Esempio n. 4
0
    def get(self, portalid, date, datasetid):
        d = parseDate(date)
        sn = getSnapshotfromTime(d)

        session=current_app.config['dbsession']
        q=session.query(DatasetData) \
            .join(Dataset, DatasetData.md5 == Dataset.md5) \
            .filter(Dataset.snapshot<=sn)\
            .filter(Dataset.portalid==portalid)\
            .filter(Dataset.id == datasetid) \
            .order_by(Dataset.snapshot.desc())
        data = q.first()

        if data:
            p = session.query(Portal).filter(Portal.id == portalid).first()
            doc = dcat_to_schemadotorg.convert(p, data.raw)
            timegate = '<' + HOST + '/' + portalid + '/' + datasetid + '/schemadotorg>'
            return add_memento_header(jsonify(doc), '<' + doc['@id'] + '>', timegate, sn)
        else:
            resp = jsonify({'error': 'There is no version of dataset ' + datasetid + ' available that is older than ' + str(d), 'portalid': portalid})
            resp.status_code = 404
            return resp