Skip to content

Commit

Permalink
Merge branch 'feature/improve-logging-icat-backend-#164' into feature…
Browse files Browse the repository at this point in the history
…/remove-sql-dependency-from-backends-#154
  • Loading branch information
MRichards99 committed Jan 4, 2021
2 parents 864e020 + 4acfc92 commit adc1f40
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 80 deletions.
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**Description**:
Add a description here

**Acceptance criteria**:
- [ ] A checklist
- [ ] of criteria to accept this story as done
15 changes: 15 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This PR will close #{issue number}

## Description
Enter a description of the changes here

## Testing instructions
Add a set up instructions describing how the reviewer should test the code

- [ ] Review code
- [ ] Check Travis build
- [ ] Review changes to test coverage
- [ ] {more steps here}

## Agile board tracking
connect to #{issue number}
107 changes: 50 additions & 57 deletions common/icat/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get_session_details_helper,
logout_icat_client,
refresh_client_session,
create_client,
get_entity_by_id,
update_entity_by_id,
delete_entity_by_id,
Expand All @@ -36,130 +37,122 @@ class PythonICATBackend(Backend):
"""

def __init__(self):
# Client object is created here as well as in login() to avoid uncaught
# exceptions where the object is None. This could happen where a user tries to
# use an endpoint before logging in. Also helps to give a bit of certainty to
# what's stored here
self.client = icat.client.Client(
config.get_icat_url(), checkCert=config.get_icat_check_cert()
)
pass

def login(self, credentials):
log.info("Logging in to get session ID")
# Client object is re-created here so session IDs aren't overwritten in the
# database
self.client = icat.client.Client(
config.get_icat_url(), checkCert=config.get_icat_check_cert()
)
client = create_client()

# Syntax for Python ICAT
login_details = {
"username": credentials["username"],
"password": credentials["password"],
}
try:
session_id = self.client.login(credentials["mechanism"], login_details)
session_id = client.login(credentials["mechanism"], login_details)
return session_id
except ICATSessionError:
raise AuthenticationError("User credentials are incorrect")

@requires_session_id
def get_session_details(self, session_id):
def get_session_details(self, session_id, **kwargs):
log.info("Getting session details for session: %s", session_id)
self.client.sessionId = session_id
return get_session_details_helper(self.client)
client = kwargs["client"] if kwargs["client"] else create_client()
return get_session_details_helper(client)

@requires_session_id
def refresh(self, session_id):
def refresh(self, session_id, **kwargs):
log.info("Refreshing session: %s", session_id)
self.client.sessionId = session_id
return refresh_client_session(self.client)
client = kwargs["client"] if kwargs["client"] else create_client()
return refresh_client_session(client)

@requires_session_id
@queries_records
def logout(self, session_id):
self.client.sessionId = session_id
return logout_icat_client(self.client)
def logout(self, session_id, **kwargs):
log.info("Logging out of the Python ICAT client")
client = kwargs["client"] if kwargs["client"] else create_client()
return logout_icat_client(client)

@requires_session_id
@queries_records
def get_with_filters(self, session_id, entity_type, filters):
self.client.sessionId = session_id
return get_entity_with_filters(self.client, entity_type, filters)
def get_with_filters(self, session_id, entity_type, filters, **kwargs):
client = kwargs["client"] if kwargs["client"] else create_client()
return get_entity_with_filters(client, entity_type, filters)

@requires_session_id
@queries_records
def create(self, session_id, entity_type, data):
self.client.sessionId = session_id
return create_entities(self.client, entity_type, data)
def create(self, session_id, entity_type, data, **kwargs):
client = kwargs["client"] if kwargs["client"] else create_client()
return create_entities(client, entity_type, data)

@requires_session_id
@queries_records
def update(self, session_id, entity_type, data):
self.client.sessionId = session_id
return update_entities(self.client, entity_type, data)
def update(self, session_id, entity_type, data, **kwargs):
client = kwargs["client"] if kwargs["client"] else create_client()
return update_entities(client, entity_type, data)

@requires_session_id
@queries_records
def get_one_with_filters(self, session_id, entity_type, filters):
self.client.sessionId = session_id
return get_first_result_with_filters(self.client, entity_type, filters)
def get_one_with_filters(self, session_id, entity_type, filters, **kwargs):
client = kwargs["client"] if kwargs["client"] else create_client()
return get_first_result_with_filters(client, entity_type, filters)

@requires_session_id
@queries_records
def count_with_filters(self, session_id, entity_type, filters):
self.client.sessionId = session_id
return get_count_with_filters(self.client, entity_type, filters)
def count_with_filters(self, session_id, entity_type, filters, **kwargs):
client = kwargs["client"] if kwargs["client"] else create_client()
return get_count_with_filters(client, entity_type, filters)

@requires_session_id
@queries_records
def get_with_id(self, session_id, entity_type, id_):
return get_entity_by_id(self.client, entity_type, id_, True)
def get_with_id(self, session_id, entity_type, id_, **kwargs):
client = kwargs["client"] if kwargs["client"] else create_client()
return get_entity_by_id(client, entity_type, id_, True)

@requires_session_id
@queries_records
def delete_with_id(self, session_id, entity_type, id_):
return delete_entity_by_id(self.client, entity_type, id_)
def delete_with_id(self, session_id, entity_type, id_, **kwargs):
client = kwargs["client"] if kwargs["client"] else create_client()
return delete_entity_by_id(client, entity_type, id_)

@requires_session_id
@queries_records
def update_with_id(self, session_id, entity_type, id_, data):
return update_entity_by_id(self.client, entity_type, id_, data)
def update_with_id(self, session_id, entity_type, id_, data, **kwargs):
client = kwargs["client"] if kwargs["client"] else create_client()
return update_entity_by_id(client, entity_type, id_, data)

@requires_session_id
@queries_records
def get_facility_cycles_for_instrument_with_filters(
self, session_id, instrument_id, filters
self, session_id, instrument_id, filters, **kwargs,
):
self.client.sessionId = session_id
return get_facility_cycles_for_instrument(self.client, instrument_id, filters)
client = kwargs["client"] if kwargs["client"] else create_client()
return get_facility_cycles_for_instrument(client, instrument_id, filters)

@requires_session_id
@queries_records
def get_facility_cycles_for_instrument_count_with_filters(
self, session_id, instrument_id, filters
self, session_id, instrument_id, filters, **kwargs,
):
self.client.sessionId = session_id
return get_facility_cycles_for_instrument_count(
self.client, instrument_id, filters
)
client = kwargs["client"] if kwargs["client"] else create_client()
return get_facility_cycles_for_instrument_count(client, instrument_id, filters)

@requires_session_id
@queries_records
def get_investigations_for_instrument_in_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters
self, session_id, instrument_id, facilitycycle_id, filters, **kwargs,
):
self.client.sessionId = session_id
client = kwargs["client"] if kwargs["client"] else create_client()
return get_investigations_for_instrument_in_facility_cycle(
self.client, instrument_id, facilitycycle_id, filters
client, instrument_id, facilitycycle_id, filters
)

@requires_session_id
@queries_records
def get_investigations_for_instrument_in_facility_cycle_count_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters
self, session_id, instrument_id, facilitycycle_id, filters, **kwargs,
):
self.client.sessionId = session_id
client = kwargs["client"] if kwargs["client"] else create_client()
return get_investigations_for_instrument_in_facility_cycle_count(
self.client, instrument_id, facilitycycle_id, filters
client, instrument_id, facilitycycle_id, filters
)
Loading

0 comments on commit adc1f40

Please sign in to comment.