Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nomad-FAIR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nomad-lab
nomad-FAIR
Commits
ddc0b19b
Commit
ddc0b19b
authored
4 years ago
by
Markus Scheidgen
Browse files
Options
Downloads
Patches
Plain Diff
Added accept header handling for dcat API format parameter.
parent
90002052
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!254
Merging these two branches concerning the encylopedia complex search
,
!246
Merge for release
Pipeline
#91932
passed
4 years ago
Stage: build
Stage: test
Stage: release
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
nomad/app/dcat/api.py
+42
-3
42 additions, 3 deletions
nomad/app/dcat/api.py
nomad/app/dcat/catalog.py
+3
-3
3 additions, 3 deletions
nomad/app/dcat/catalog.py
nomad/app/dcat/datasets.py
+3
-2
3 additions, 2 deletions
nomad/app/dcat/datasets.py
with
48 additions
and
8 deletions
nomad/app/dcat/api.py
+
42
−
3
View file @
ddc0b19b
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
# limitations under the License.
# limitations under the License.
#
#
from
flask
import
Blueprint
,
Response
from
flask
import
Blueprint
,
Response
,
request
from
flask_restplus
import
Api
,
reqparse
from
flask_restplus
import
Api
,
reqparse
import
urllib.parse
import
urllib.parse
from
rdflib
import
Graph
from
rdflib
import
Graph
...
@@ -62,13 +62,52 @@ arg_parser.add_argument('format', type=str, choices=[
...
@@ -62,13 +62,52 @@ arg_parser.add_argument('format', type=str, choices=[
'
pretty-xml
'
,
'
pretty-xml
'
,
'
trig
'
])
'
trig
'
])
all_repsonse_types
=
{
'
application/xml
'
:
'
xml
'
,
'
application/rdf+prettyxml
'
:
'
pretty-xml
'
,
'
application/rdf
'
:
'
xml
'
,
'
application/rdf+xml
'
:
'
xml
'
,
'
text/plain
'
:
'
n3
'
,
'
text/turtle
'
:
'
turtle
'
,
'
text/nt
'
:
'
nt
'
,
'
text/n3
'
:
'
n3
'
,
'
text/rdf+n3
'
:
'
n3
'
,
'
text/rdf+nt
'
:
'
nt
'
,
'
text/rdf+turtle
'
:
'
turtle
'
,
'
application/x-trig
'
:
'
trig
'
}
response_types
=
[
'
application/xml
'
,
'
application/rdf+xml
'
,
'
application/rdf+pretty-xml
'
,
'
text/plain
'
,
'
text/turtle
'
,
'
text/rdf+n3
'
,
'
text/rdf+nt
'
,
'
application/x-trig
'
]
def
rdf_respose
(
g
:
Graph
)
->
Response
:
def
rdf_respose
(
g
:
Graph
)
->
Response
:
args
=
arg_parser
.
parse_args
()
args
=
arg_parser
.
parse_args
()
format_
=
args
.
get
(
'
format
'
)
format_
=
args
.
get
(
'
format
'
)
accept_header
=
None
if
format_
is
None
:
if
format_
is
None
:
format_
=
'
pretty-xml
'
accept_header
=
request
.
headers
.
get
(
'
Accept
'
,
None
)
content_type
=
'
application/xml
'
if
format
in
[
'
xml
'
,
'
pretty-xml
'
]
else
'
text/%s
'
%
format_
if
accept_header
is
not
None
:
format_
=
all_repsonse_types
.
get
(
accept_header
,
'
pretty-xml
'
)
else
:
accept_header
=
None
format_
=
'
pretty-xml
'
if
accept_header
is
not
None
:
content_type
=
accept_header
else
:
try
:
content_type
=
next
(
key
for
key
,
value
in
all_repsonse_types
.
items
()
if
value
==
format_
)
except
StopIteration
:
content_type
=
'
application/xml
'
if
format
in
[
'
xml
'
,
'
pretty-xml
'
]
else
'
text/%s
'
%
format_
return
Response
(
return
Response
(
g
.
serialize
(
format
=
format_
).
decode
(
'
utf-8
'
),
200
,
g
.
serialize
(
format
=
format_
).
decode
(
'
utf-8
'
),
200
,
{
'
Content-Type
'
:
content_type
})
{
'
Content-Type
'
:
content_type
})
This diff is collapsed.
Click to expand it.
nomad/app/dcat/catalog.py
+
3
−
3
View file @
ddc0b19b
...
@@ -21,7 +21,7 @@ from elasticsearch_dsl import Q
...
@@ -21,7 +21,7 @@ from elasticsearch_dsl import Q
from
nomad
import
search
from
nomad
import
search
from
.api
import
api
,
arg_parser
,
rdf_respose
from
.api
import
api
,
arg_parser
,
rdf_respose
,
response_types
from
.mapping
import
Mapping
from
.mapping
import
Mapping
ns
=
api
.
namespace
(
'
catalog
'
,
description
=
'
The API for DCAT catalog.
'
)
ns
=
api
.
namespace
(
'
catalog
'
,
description
=
'
The API for DCAT catalog.
'
)
...
@@ -39,13 +39,13 @@ arg_parser.add_argument(
...
@@ -39,13 +39,13 @@ arg_parser.add_argument(
class
Catalog
(
Resource
):
class
Catalog
(
Resource
):
@api.doc
(
'
get_dcat_datasets
'
)
@api.doc
(
'
get_dcat_datasets
'
)
@api.expect
(
arg_parser
)
@api.expect
(
arg_parser
)
@api.produces
([
'
application/xml
'
])
@api.representation
(
'
application/xml
'
)
@api.produces
(
response_types
)
@api.response
(
404
,
'
There is no entry with the given id.
'
)
@api.response
(
404
,
'
There is no entry with the given id.
'
)
@api.response
(
401
,
'
This entry is not publically accessible.
'
)
@api.response
(
401
,
'
This entry is not publically accessible.
'
)
@api.response
(
200
,
'
Data send
'
,
headers
=
{
'
Content-Type
'
:
'
application/xml
'
})
@api.response
(
200
,
'
Data send
'
,
headers
=
{
'
Content-Type
'
:
'
application/xml
'
})
def
get
(
self
):
def
get
(
self
):
'''
Returns a page of DCAT datasets.
'''
'''
Returns a page of DCAT datasets.
'''
args
=
arg_parser
.
parse_args
()
args
=
arg_parser
.
parse_args
()
modified_since
=
args
.
get
(
'
modified_since
'
,
None
)
modified_since
=
args
.
get
(
'
modified_since
'
,
None
)
after
=
args
.
get
(
'
after
'
,
''
)
after
=
args
.
get
(
'
after
'
,
''
)
...
...
This diff is collapsed.
Click to expand it.
nomad/app/dcat/datasets.py
+
3
−
2
View file @
ddc0b19b
...
@@ -20,7 +20,7 @@ from elasticsearch.exceptions import NotFoundError
...
@@ -20,7 +20,7 @@ from elasticsearch.exceptions import NotFoundError
from
nomad
import
search
from
nomad
import
search
from
.api
import
api
,
arg_parser
,
rdf_respose
from
.api
import
api
,
arg_parser
,
rdf_respose
,
response_types
from
.mapping
import
Mapping
from
.mapping
import
Mapping
ns
=
api
.
namespace
(
'
datasets
'
,
description
=
'
The API for DCAT datasets.
'
)
ns
=
api
.
namespace
(
'
datasets
'
,
description
=
'
The API for DCAT datasets.
'
)
...
@@ -30,7 +30,8 @@ ns = api.namespace('datasets', description='The API for DCAT datasets.')
...
@@ -30,7 +30,8 @@ ns = api.namespace('datasets', description='The API for DCAT datasets.')
class
Dataset
(
Resource
):
class
Dataset
(
Resource
):
@api.doc
(
'
get_dcat_dataset
'
)
@api.doc
(
'
get_dcat_dataset
'
)
@api.expect
(
arg_parser
)
@api.expect
(
arg_parser
)
@api.produces
([
'
application/xml
'
])
@api.representation
(
'
application/xml
'
)
@api.produces
(
response_types
)
@api.response
(
404
,
'
There is no entry with the given id.
'
)
@api.response
(
404
,
'
There is no entry with the given id.
'
)
@api.response
(
401
,
'
This entry is not publically accessible.
'
)
@api.response
(
401
,
'
This entry is not publically accessible.
'
)
@api.response
(
200
,
'
Data send
'
,
headers
=
{
'
Content-Type
'
:
'
application/xml
'
})
@api.response
(
200
,
'
Data send
'
,
headers
=
{
'
Content-Type
'
:
'
application/xml
'
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment