-
Notifications
You must be signed in to change notification settings - Fork 124
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
Create FileSetDescription
to find characterization for FileSets
#4215
Conversation
d0e2ef7
to
49b4584
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Holding this pending rebase on #4225
Use the test adapter in specs by doing: `context 'some context', valkyrie_adapter: :test_adapter do`
Valkyrie-based FileSet objects don't have direct access to characterization information. In ActiveFedora, we used a `#characterization_proxy` to provide that information. Here, we provide a small service that can find the "primary" file (`FileMetadata`) for a given FileSet, and ask it about its description.
The concept of "use" is more properly localized to `FileMetadata` than `FileSet`, since `FileMetadata` holds the actual use (`#type`) attribute.
Rather than using some branching logic in `FileMetadata.for`, take advantage of Valkyrie attributes' default values. When initializing a `FileMetadata`, assume it's an `ORIGINAL_FILE` unless a different use is passed.
return :thumbnail_file if relation.to_s.casecmp(Hyrax::FileSet::THUMBNAIL_USE.to_s) | ||
:original_file | ||
case relation | ||
when Hyrax::FileMetadata::Use::ORIGINAL_FILE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when Hyrax::FileMetadata::Use::ORIGINAL_FILE |
:original_file | ||
case relation | ||
when Hyrax::FileMetadata::Use::ORIGINAL_FILE | ||
:original_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:original_file |
return :thumbnail_file if relation.to_s.casecmp(Hyrax::FileSet::THUMBNAIL_USE.to_s) | ||
:original_file | ||
case relation | ||
when Hyrax::FileMetadata::Use::ORIGINAL_FILE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as noted by suggestions, this branch could be dropped and fall through to the else
instead. i think the existing way is more clear, but only slightly.
This query was added, but never registered. It needs to be added to the `.queries` method for the query handler in order to be picked up by most adapters.
This method is supplanted by a new custom query. Use that query instead whereever `used_for?` was called.
387eb3b
to
e26a38f
Compare
Since `#type` is located in `FileMetadata` and there's a convenient custom query, these methods mostly function to provide `.first`. My feeling is that this is a bit obfuscating; why not encourage queriers to handle the edge case where there are multiple matches in context appropriate ways instead? In some cases that might be `.first`, but not always. This also has the benefit of removing some business logic from the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few questions and notes. But the part I'm not following is how FileSetDescription is going to be used. It is defined in this PR, but I don't see it used anywhere. So it is hard to have the context for why it is needed.
def current_original_file(file_set) | ||
Hyrax.query_service | ||
.custom_queries | ||
.find_many_file_metadata_by_use(resource: file_set, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of what I liked about the #original_file method was that it was simple and had the knowledge that there should be only one, so it was ok to grab the first one returned. I'd hate to see this code block repeated in multiple places. If it doesn't belong in FileSet (for single responsibility reasons), is there somewhere else it can live (to keep it DRY)? And if not, should it be a service. Getting the original file is something that happens a lot in Hyrax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea of a service is a good one. Maybe there should be a navigator?
There already is one. I'll look to make sure it works well and refactor around it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we hold this for a later refactor? i promise to get to it this week, if so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am good with putting this in another PR. Created an issue to track this... #4233
7be1297
to
e185d58
Compare
For valkyrie normalization, take advantage for the new `Hyrax::FileMetadata::Use.uri_for` module method to avoid reproducing logic. When the argument is already a URI, just return it to avoid casting unnecessarily. In the ActiveFedora normalizer, `RDF::URI` already implements equality appropriately, so `#casecmp` isn't needed and we can flatten to a simple switch statement.
The constant previously used an incorrect URI. `Thumbnail` should be `ThumbnailImage`.
Avoid typing `Hyrax.query_service.custom_queries` everywhere. Provide a method on the Hyrax level instead.
self.file_set = file_set | ||
|
||
@primary_file_type_uri = | ||
Hyrax::FileMetadata::Use.uri_for(use: primary_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other places, the file type is sometimes passed as a symbol (e.g. :original_file, :extracted_file, :thumbnail_image), and sometimes passed as a URI for custom types. Do you think that might happen here too? FileActor which calls Hydra::Works::AddFileToFileSet handles both symbol and URI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@no-reply This is an open question for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure i understand the question. this is a new interface, so callers will presumably use it as defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom types do not have a Symbol equivalent. So what happens here if someone wants to pass http://pcdm.org/use#remastered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this PR. I only have one question remaining about whether file type may be either a symbol or a URI. I lean toward moving away from using symbols to only using URIs. Use of symbols was an artifact of AF using them to establish the directly_contains_one relationship from the FileSet to the File.
when Hyrax::FileMetadata::Use::EXTRACTED_TEXT | ||
:extracted_file | ||
when Hyrax::FileMetadata::Use::THUMBNAIL | ||
:thumbnail_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I was exploring inconsistencies documented in Issue #4228, I noticed that these are using symbols that I think are incorrect. I'm pretty sure these should be :extracted_text and :thumbnail.
This part of why I propose putting any conversions between symbol and RDF::URI in a single place (e.g. FileMetadata::Use module).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i also noticed that the symbols were inconsistent across modules. i'm not sure that means they are incorrect(?). these are the symbols that pre-date this PR, right?
unless they got mixed up somewhere else recently, they should be the ones callers are already passing in.
in any case, i do think we should hold changes to behavior around these symbols for resolution as part of #4228. for now, the behavior exists in two places because it behaves slightly differently across them, and the goal here is to preserve that faithfully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like these were incorrectly entered in PR #3746 which was one of the first PRs for valkyrizing files. I don't think they have surfaced as a problem because Hyrax generally already passes relation as a Symbol unless it is a custom relation, so the conversion probably has never been used in a Hyrax app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking back on PR #3746 for this part handling the conversion from URI to Symbol and vice versa, I am somewhat uncomfortable with the default being original file. I'm wondering what happens if a custom file type is passed in for relation.
I'm can update #4228 with this question or create a separate issue. It seems a bit beyond the refactoring for consistency issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: :original_file
i think this is just a straight refactor, and i'd prefer not to let its scope creep.
i'm in favor of wrapping any remaining issues into #4228.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done... #4228 is updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is approved with the acknowledgement that there are several new issues with followup work.
👍 |
For discussion as possible input for #4213
Valkyrie-based FileSet objects don't have direct access to characterization
information. In ActiveFedora, we used a
#characterization_proxy
to providethat information. Here, we provide a small service that can find the "primary"
file (
FileMetadata
) for a given FileSet, and ask it about its description.Closes #4226
@samvera/hyrax-code-reviewers