Skip to content

Commit

Permalink
Merge branch 'master' into add-datagateway-and-panosc-modes-#256
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Bozhinov committed Nov 22, 2021
2 parents c23b0e5 + fd53e88 commit 72201a3
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.9.7'
architecture: x64
- name: Checkout DataGateway API
uses: actions/checkout@v2
Expand All @@ -117,7 +117,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.9.7'
architecture: x64
- name: Checkout DataGateway API
uses: actions/checkout@v2
Expand All @@ -137,7 +137,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.9.7'
architecture: x64
- name: Checkout DataGateway API
uses: actions/checkout@v2
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.9.7'
architecture: x64

# ICAT Ansible clone and install dependencies
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

<!--next-version-placeholder-->

## v1.1.0 (2021-11-19)
### Feature
* Add unimplemented endpoint definitions for search API #257 ([`d0e52d9`](https://github.com/ral-facilities/datagateway-api/commit/d0e52d96dd3b94ce54dcc9b81969e777a196922a))

### Documentation
* Rebuild openapi docs #257 ([`de15357`](https://github.com/ral-facilities/datagateway-api/commit/de1535772db64916f75e16d79be3f3fdf10fc47c))

## v1.0.1 (2021-11-15)
### Fix
* Add PID field for study in DB backend #287 ([`18379be`](https://github.com/ral-facilities/datagateway-api/commit/18379becafd23ff2957e556de2bd3fc210a71f5b))
* Add generation of study.pid #287 ([`f6a8ebc`](https://github.com/ral-facilities/datagateway-api/commit/f6a8ebc6c775ba3f5252d5af5cedc4e1e0e79a40))

### Documentation
* Add study PID to swagger docs #287 ([`89a9e27`](https://github.com/ral-facilities/datagateway-api/commit/89a9e27b72dfe1d474d49a721f128a643ef2ae36))

## v1.0.0 (2021-11-03)
### Breaking
* As the API will be approaching production use soon, this seems like a good opportunity to bump the version to 1.0.0. This also serves as a good test that the introduction of automatic versioning actually works ([`ccf6d29`](https://github.com/ral-facilities/datagateway-api/commit/ccf6d2974216f8979a03e3e223f7c9e84ced05cb))
Expand Down
86 changes: 80 additions & 6 deletions datagateway_api/src/api_start_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
from datagateway_api.src.resources.non_entities.sessions_endpoints import (
session_endpoints,
)
from datagateway_api.src.resources.search_api_endpoints import (
get_files_endpoint,
get_number_count_endpoint,
get_number_count_files_endpoint,
get_search_endpoint,
get_single_endpoint,
)
from datagateway_api.src.resources.table_endpoints.table_endpoints import (
count_instrument_facility_cycles_endpoint,
count_instrument_investigation_endpoint,
Expand Down Expand Up @@ -105,7 +112,11 @@ def create_api_endpoints(flask_app, api, spec):
backend,
client_pool=icat_client_pool,
)
api.add_resource(get_endpoint_resource, f"/{entity_name.lower()}")
api.add_resource(
get_endpoint_resource,
f"/{entity_name.lower()}",
endpoint=f"datagateway_get_{entity_name}",
)
spec.path(resource=get_endpoint_resource, api=api)

get_id_endpoint_resource = get_id_endpoint(
Expand All @@ -115,7 +126,9 @@ def create_api_endpoints(flask_app, api, spec):
client_pool=icat_client_pool,
)
api.add_resource(
get_id_endpoint_resource, f"/{entity_name.lower()}/<int:id_>",
get_id_endpoint_resource,
f"/{entity_name.lower()}/<int:id_>",
endpoint=f"datagateway_get_id_{entity_name}",
)
spec.path(resource=get_id_endpoint_resource, api=api)

Expand All @@ -126,7 +139,9 @@ def create_api_endpoints(flask_app, api, spec):
client_pool=icat_client_pool,
)
api.add_resource(
get_count_endpoint_resource, f"/{entity_name.lower()}/count",
get_count_endpoint_resource,
f"/{entity_name.lower()}/count",
endpoint=f"datagateway_count_{entity_name}",
)
spec.path(resource=get_count_endpoint_resource, api=api)

Expand All @@ -137,23 +152,29 @@ def create_api_endpoints(flask_app, api, spec):
client_pool=icat_client_pool,
)
api.add_resource(
get_find_one_endpoint_resource, f"/{entity_name.lower()}/findone",
get_find_one_endpoint_resource,
f"/{entity_name.lower()}/findone",
endpoint=f"datagateway_findone_{entity_name}",
)
spec.path(resource=get_find_one_endpoint_resource, api=api)

# Session endpoint
session_endpoint_resource = session_endpoints(
backend, client_pool=icat_client_pool,
)
api.add_resource(session_endpoint_resource, "/sessions")
api.add_resource(
session_endpoint_resource, "/sessions", endpoint="datagateway_sessions",
)
spec.path(resource=session_endpoint_resource, api=api)

# Table specific endpoints
instrument_facility_cycle_resource = instrument_facility_cycles_endpoint(
backend, client_pool=icat_client_pool,
)
api.add_resource(
instrument_facility_cycle_resource, "/instruments/<int:id_>/facilitycycles",
instrument_facility_cycle_resource,
"/instruments/<int:id_>/facilitycycles",
endpoint="datagateway_isis_instrument_facility_cycle",
)
spec.path(resource=instrument_facility_cycle_resource, api=api)

Expand All @@ -163,6 +184,7 @@ def create_api_endpoints(flask_app, api, spec):
api.add_resource(
count_instrument_facility_cycle_res,
"/instruments/<int:id_>/facilitycycles/count",
endpoint="datagateway_isis_count_instrument_facility_cycle",
)
spec.path(resource=count_instrument_facility_cycle_res, api=api)

Expand All @@ -173,6 +195,7 @@ def create_api_endpoints(flask_app, api, spec):
instrument_investigation_resource,
"/instruments/<int:instrument_id>/facilitycycles/<int:cycle_id>"
"/investigations",
endpoint="datagateway_isis_instrument_investigation",
)
spec.path(resource=instrument_investigation_resource, api=api)

Expand All @@ -183,6 +206,7 @@ def create_api_endpoints(flask_app, api, spec):
count_instrument_investigation_res,
"/instruments/<int:instrument_id>/facilitycycles/<int:cycle_id>"
"/investigations/count",
endpoint="datagateway_isis_count_instrument_investigation",
)
spec.path(resource=count_instrument_investigation_res, api=api)

Expand All @@ -191,6 +215,56 @@ def create_api_endpoints(flask_app, api, spec):
api.add_resource(ping_resource, "/ping")
spec.path(resource=ping_resource, api=api)

# Search API endpoints
# TODO - make conditional respect new config style when implemented
if True:
# TODO - Use config value when new config style is implemented
search_api_extension = "search_api"
search_api_entity_endpoints = ["datasets", "documents", "instruments"]

for entity_name in search_api_entity_endpoints:
get_search_endpoint_resource = get_search_endpoint(entity_name)
api.add_resource(
get_search_endpoint_resource,
f"/{search_api_extension}/{entity_name}",
endpoint=f"search_api_get_{entity_name}",
)
spec.path(resource=get_endpoint_resource, api=api)

get_single_endpoint_resource = get_single_endpoint(entity_name)
api.add_resource(
get_single_endpoint_resource,
f"/{search_api_extension}/{entity_name}/<int:pid>",
endpoint=f"search_api_get_single_{entity_name}",
)
spec.path(resource=get_single_endpoint_resource, api=api)

get_number_count_endpoint_resource = get_number_count_endpoint(entity_name)
api.add_resource(
get_number_count_endpoint_resource,
f"/{search_api_extension}/{entity_name}/count",
endpoint=f"search_api_count_{entity_name}",
)
spec.path(resource=get_number_count_endpoint_resource, api=api)

get_files_endpoint_resource = get_files_endpoint("datasets")
api.add_resource(
get_files_endpoint_resource,
f"/{search_api_extension}/datasets/<int:pid>/files",
endpoint="search_api_get_dataset_files",
)
spec.path(resource=get_files_endpoint_resource, api=api)

get_number_count_files_endpoint_resource = get_number_count_files_endpoint(
"datasets",
)
api.add_resource(
get_number_count_files_endpoint_resource,
f"/{search_api_extension}/datasets/<int:pid>/files/count",
endpoint="search_api_count_dataset_files",
)
spec.path(resource=get_number_count_files_endpoint_resource, api=api)


def openapi_config(spec):
# Reorder paths (e.g. get, patch, post) so openapi.yaml only changes when there's a
Expand Down
1 change: 1 addition & 0 deletions datagateway_api/src/datagateway_api/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ class STUDY(Base, EntityHelper, metaclass=EntityMeta):
modId = Column("MOD_ID", String(255), nullable=False)
modTime = Column("MOD_TIME", DateTime, nullable=False)
name = Column("NAME", String(255), nullable=False)
pid = Column("PID", String(255))
startDate = Column("STARTDATE", DateTime)
status = Column("STATUS", Integer)
userID = Column("USER_ID", ForeignKey("USER_.ID"), index=True)
Expand Down
13 changes: 7 additions & 6 deletions datagateway_api/src/resources/search_api_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from flask_restful import Resource


# TODO - Might need kwargs on get_endpoint(), get_id_endpoint(), get_count_endpoint(),
# get_files_endpoint(), get_count_files_endpoint() for client handling?
def get_endpoint(name):
# TODO - Might need kwargs on get_search_endpoint(), get_single_endpoint(),
# get_number_count_endpoint(), get_files_endpoint(), get_number_count_files_endpoint()
# for client handling?
def get_search_endpoint(name):
"""
TODO - Add docstring
"""
Expand All @@ -30,7 +31,7 @@ def get(self):
return Endpoint


def get_id_endpoint(name):
def get_single_endpoint(name):
"""
TODO - Add docstring
"""
Expand All @@ -46,7 +47,7 @@ def get(self, pid):
return EndpointWithID


def get_count_endpoint(name):
def get_number_count_endpoint(name):
"""
TODO - Add docstring
"""
Expand Down Expand Up @@ -78,7 +79,7 @@ def get(self, pid):
return FilesEndpoint


def get_count_files_endpoint(name):
def get_number_count_files_endpoint(name):
"""
TODO - Add docstring
"""
Expand Down
10 changes: 10 additions & 0 deletions datagateway_api/src/swagger/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,8 @@ components:
type: string
name:
type: string
pid:
type: string
startDate:
format: datetime
type: string
Expand Down Expand Up @@ -11013,5 +11015,13 @@ paths:
summary: Ping API connection method
tags:
- Ping
/search_api/datasets/{pid}: {}
/search_api/datasets/count: {}
/search_api/documents/{pid}: {}
/search_api/documents/count: {}
/search_api/instruments/{pid}: {}
/search_api/instruments/count: {}
/search_api/datasets/{pid}/files: {}
/search_api/datasets/{pid}/files/count: {}
security:
- session_id: []
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "datagateway-api"
version = "1.0.0"
version = "1.1.0"
description = "ICAT API to interface with the DataGateway"
license = "Apache-2.0"
readme = "README.md"
Expand Down
45 changes: 45 additions & 0 deletions test/test_endpoint_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,51 @@ def test_entity_endpoints(self, flask_test_app, endpoint_ending, expected_method
["GET"],
id="count ISIS investigations",
),
pytest.param(
"/search_api/datasets", ["GET"], id="Search API search datasets",
),
pytest.param(
"/search_api/documents", ["GET"], id="Search API search documents",
),
pytest.param(
"/search_api/instruments", ["GET"], id="Search API search instruments",
),
pytest.param(
"/search_api/datasets/<int:pid>",
["GET"],
id="Search API get single dataset",
),
pytest.param(
"/search_api/documents/<int:pid>",
["GET"],
id="Search API get single document",
),
pytest.param(
"/search_api/instruments/<int:pid>",
["GET"],
id="Search API get single instrument",
),
pytest.param(
"/search_api/datasets/count", ["GET"], id="Search API dataset count",
),
pytest.param(
"/search_api/documents/count", ["GET"], id="Search API document count",
),
pytest.param(
"/search_api/instruments/count",
["GET"],
id="Search API instrument count",
),
pytest.param(
"/search_api/datasets/<int:pid>/files",
["GET"],
id="Search API get dataset files",
),
pytest.param(
"/search_api/datasets/<int:pid>/files/count",
["GET"],
id="Search API dataset files count",
),
],
)
def test_non_entity_endpoints(
Expand Down
1 change: 0 additions & 1 deletion test/test_query_filter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest


import datagateway_api.src.common.config as config
from datagateway_api.src.common.exceptions import ApiError
from datagateway_api.src.common.filters import QueryFilter
Expand Down
3 changes: 3 additions & 0 deletions util/icat_db_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ def generate_user_groups(i):
class StudyGenerator(Generator):
tier = 3
amount = UserGenerator.amount
pid_faker = Faker()
pid_faker.seed_instance(SEED)

def generate(self):
for i in range(1, self.amount):
Expand All @@ -431,6 +433,7 @@ def generate_studies(i):
apply_common_attributes(study, i)
study.startDate = get_start_date(i)
study.status = faker.random_int(0, 1)
study.pid = StudyGenerator.pid_faker.isbn10(separator="-")
study.userID = i
post_entity(study)

Expand Down

0 comments on commit 72201a3

Please sign in to comment.