Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push metadata representation to representation layer #698

Merged
merged 2 commits into from
Oct 19, 2023

Conversation

MrCreosote
Copy link
Member

Regarding object information user metadata, workspace methods may

  • Always return the user metadata
  • Never return it
  • Give the user a choice

This is because the metadata may be much bigger than the rest of the object information.

The way this is implemented is that each method has a list of MongoDB fields it asks for when querying the DB. If it doesn't want metadata, it doesn't include the field containing the metadata, and so in the returned data the metadata will be effectively null. If the method asks for metadata and there's none available, an empty map will be returned from the DB since that's what's stored in the metadata field when none is supplied when saving objects.

This is a problem for admin metadata, since older objects will have null for the admin metadata whether the field is requested or not. This means without changes, if a method requests metadata they'll get null rather than the expected emtpy map.

I first tried to fix this by passing a boolean around to the point at which the ObjectInformation class is built telling it whether to translate nulls to empty maps but that was a huge mess.

Instead, I updated ObjectInfomation to treat nulls and empty maps the same - an absence of metadata. The representation layer can then be responsible for deciding whether the absent metadata representation should be null (for no metadata requested) or an empty map.

Note that none of the API tests that test the representation layer needed changes.

Regarding object information user metadata, workspace methods may

* Always return the user metadata
* Never return it
* Give the user a choice

This is because the metadata may be much bigger than the rest of the
object information.

The way this is implemented is that each method has a list of MongoDB
fields it asks for when querying the DB. If it doesn't want metadata, it
doesn't include the field containing the metadata, and so in the
returned data the metadata will be effectively null. If the method asks
for metadata and there's none available, an empty map will be returned
from the DB since that's what's stored in the metadata field when none
is supplied when saving objects.

This is a problem for admin metadata, since older objects will have null
for the admin metadata whether the field is requested or not. This means
without changes, if a method requests metadata they'll get null rather
than the expected emtpy map.

I first tried to fix this by passing a boolean around to the point at
which the ObjectInformation class is built telling it whether to
translate nulls to empty maps but that was a huge mess.

Instead, I updated ObjectInfomation to treat nulls and empty maps the
same - an absence of metadata. The representation layer can then be
responsible for deciding whether the absent metadata representation
should be null (for no metadata requested) or an empty map.

Note that none of the API tests that test the representation layer
needed changes.
@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Merging #698 (fe8df81) into develop (20415a8) will increase coverage by 0.00%.
Report is 8 commits behind head on develop.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #698   +/-   ##
==========================================
  Coverage      87.45%   87.46%           
- Complexity      5215     5221    +6     
==========================================
  Files            224      224           
  Lines          17320    17326    +6     
  Branches        2553     2560    +7     
==========================================
+ Hits           15148    15154    +6     
  Misses          1706     1706           
  Partials         466      466           

* or null if no user metadata was provided.
/** Returns the user supplied and automatically generated metadata for the object as a map.
*
* @param nullIfEmpty return null rather than an empty map if there is no metadata available.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the @return description below need to be updated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@MrCreosote MrCreosote merged commit 2cf8e87 into kbase:develop Oct 19, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants