Skip to content

Object

Routes for handling stable objects - those with GUIDs in KE EMu.

If someone accesses URL: object/73f450db-46b3-45a0-ac18-f00547be5af1 It will 302 redirect to the specimen, artefact or index lot page (though currently we only support specimens).

If a user requests the object in RDF format: object/73f450db-46b3-45a0-ac18-f00547be5af1.ttl Returns RDF

In both cases, if a version is appended to the end of the URL then that version of the record is returned. For example: object/73f450db-46b3-45a0-ac18-f00547be5af1/1551692486000 otherwise the current version is returned.

Old style /specimen urls are also supported to ensure backwards compatibility.

abyssline_object_redirect(uuid, version)

Temporary fix to allow abyssline object references to resolve to the temp dataset.

Parameters:

Name Type Description Default
uuid

the object's uuid

required
version

the version to get

required
Source code in ckanext/nhm/routes/object.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
def abyssline_object_redirect(uuid, version):
    """
    Temporary fix to allow abyssline object references to resolve to the temp dataset.

    :param uuid: the object's uuid
    :param version: the version to get
    """
    resource_id = toolkit.config.get('ckanext.nhm.abyssline_resource_id')

    # figure out the rounded version
    data_dict = {
        'resource_id': resource_id,
        'version': version,
    }
    version = toolkit.get_action('vds_version_round')(_context(), data_dict)

    # search for the record
    search_data_dict = {'resource_id': resource_id, 'filters': {'catalogNumber': uuid}}

    search_result = toolkit.get_action('datastore_search')(_context(), search_data_dict)
    try:
        data = search_result['records'][0]
        record = Record(data['_id'], version, data, resource_id)
        redirect(record.url(), code=303)
    except IndexError:
        pass

    toolkit.abort(404, toolkit._('Record not found'))

rdf(uuid, _format, version)

Return RDF view of object.

Parameters:

Name Type Description Default
uuid

the object's uuid

required
_format

the format requested

required
version

the version of the record to retrieve, or None if the current version is desired

required

Returns:

Type Description

the data to display

Source code in ckanext/nhm/routes/object.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
@specimen_blueprint.route('/<uuid>.<_format>', defaults={'version': None})
@specimen_blueprint.route('/<uuid>/<int:version>.<_format>')
@blueprint.route('/<uuid>.<_format>', defaults={'version': None})
@blueprint.route('/<uuid>/<int:version>.<_format>')
def rdf(uuid, _format, version):
    """
    Return RDF view of object.

    :param uuid: the object's uuid
    :param _format: the format requested
    :param version: the version of the record to retrieve, or None if the current
        version is desired
    :returns: the data to display
    """
    data_dict = {
        'uuid': uuid,
        'format': _format,
        'version': version,
    }
    try:
        result = toolkit.get_action('object_rdf')(_context(), data_dict)
        return Response(result, mimetype=rdf_content_types[_format])
    except toolkit.ValidationError as e:
        toolkit.abort(409, str(e))

view(uuid, version)

View object. If this is normal HTTP request, this will redirect to the record, otherwise if the request is for RDF (content negotiation) return the rdf.

Parameters:

Name Type Description Default
uuid

the uuid of the object

required
version

the version of the object, or None for current version

required
Source code in ckanext/nhm/routes/object.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@specimen_blueprint.route('/<uuid>', defaults={'version': None})
@specimen_blueprint.route('/<uuid>/<int:version>')
@blueprint.route('/<uuid>', defaults={'version': None})
@blueprint.route('/<uuid>/<int:version>')
def view(uuid, version):
    """
    View object. If this is normal HTTP request, this will redirect to the record,
    otherwise if the request is for RDF (content negotiation) return the rdf.

    :param uuid: the uuid of the object
    :param version: the version of the object, or None for current version
    """
    if uuid in ABYSSLINE_UUIDS:
        abyssline_object_redirect(uuid, version)

    # is the request for a particular format?
    _format = check_access_header()

    if _format:
        # cetaf standards require us to return a 303 redirect to the rdf doc
        url = url_for('object.rdf', uuid=uuid, _format=_format, version=version)
        return redirect(url, code=303)
    else:
        try:
            # get the record at the given version
            record = get_record_by_uuid(uuid, version)
            if record:
                # cetaf standards require us to return a 303 redirect to the html record page
                return redirect(record.url(), code=303)
        except Exception:
            pass

    toolkit.abort(404, toolkit._('Record not found'))