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

Orders members when converting to AF objects. #3697

Merged
merged 8 commits into from
Apr 4, 2019
Merged

Conversation

rotated8
Copy link
Contributor

Adding members via #members= does not add the member to the ordered relation, so that after a save, #member_ids contains objects, but #ordered_member_ids is empty. Since many parts of the code use #ordered_members, the converter should order the members.

@rotated8 rotated8 added the wings label Mar 21, 2019
@rotated8 rotated8 self-assigned this Mar 21, 2019
@@ -81,6 +81,10 @@
it 'converts member_of_collection_ids back to af_object' do
expect(converter.convert.members.map(&:id)).to match_array [work2.id, work3.id]
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to demonstrate the difference between members and ordered_members, you can use match_array here and reverse the order of the ids...

          expect(converter.convert.members.map(&:id)).to match_array [work3.id, work2.id]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -81,6 +81,10 @@
it 'converts member_of_collection_ids back to af_object' do
expect(converter.convert.members.map(&:id)).to match_array [work2.id, work3.id]
end

it 'preserves order across conversion' do
expect(converter.convert.ordered_member_ids).to match_array [work2.id, work3.id]
Copy link
Contributor

@elrayle elrayle Mar 21, 2019

Choose a reason for hiding this comment

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

And this should use .to eq

expect(converter.convert.ordered_member_ids).to eq [work2.id, work3.id]

This confirms the order is maintained.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@elrayle elrayle left a comment

Choose a reason for hiding this comment

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

The change to members is a suggestion. The changed to ordered_members is needed to ensure that order was maintained.

@rotated8 rotated8 force-pushed the wings-ordered-members branch 2 times, most recently from dff6a08 to f7dba2d Compare March 21, 2019 21:07
lsat12357
lsat12357 previously approved these changes Mar 22, 2019
@elrayle elrayle force-pushed the wings-ordered-members branch 2 times, most recently from 6588fea to fcad364 Compare March 25, 2019 21:35
@elrayle
Copy link
Contributor

elrayle commented Mar 25, 2019

Exploring the fileset failures...

  • The failure is on calls to fileset.parent_works which does not exist for resources in Hyrax and therefore, converts the resource to an af_object and passes it to Hydra::Works through the missing_method override for Hyrax resources
  • The expected results are [wk1, wk2] and the actual results are [wk1, wk2, wk2]
  • This happens because parent_works in Hydra::Works combines in_works + member_of_works. in_works returns [wk2] and member_of_works returns [wk1, wk2]
  • Testing with the original af_object before it is converted to the resource, and it had the same problem. This implies that the problem my be at the Hydra::Works level.

What is not clear is why this did not happen before this branch and does with this branch. What is also not clear is why wk2 is repeated, but wk1 is not.

A simple fix would be to apply .uniq to parent_works in Hydra::Works, but I'd like to understand why changing from setting the members with members to setting them with ordered_members would cause this error.

@elrayle
Copy link
Contributor

elrayle commented Mar 28, 2019

Since Hyrax is only interested in one direction, changed parent_works in Hyrax to not depend on parent_works in Hydra::Works. This fixes the problem where parent_works for works and filesets was returning repeated parents.

@elrayle elrayle force-pushed the wings-ordered-members branch 3 times, most recently from 8c4d907 to dff2606 Compare April 2, 2019 16:21
rotated8 and others added 5 commits April 4, 2019 08:18
This solves issues with unordered members not being ordered at all after
conversion.
Use a stricter test for the array returned from #ordered_member_ids
Otherwise, during the transformation back and forth, the members could be put on the transformed resource in the wrong order.  This fixes a randomly failing condition.

Changed wings tests to use ordered_members since that is the relationship used in hyrax.
end

# @param valkyrie [Boolean] Should the returned ids be for Valkyrie or AF objects?
# @return [Enumerable<String> | Enumerable<Valkerie::ID] The ids of the file sets this work contains
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment should be rewritten # @return [Enumerable<String> | Enumerable<Valkyrie::ID>] The ids of the file sets this work contains

# # @return [Enumerable<String> | Enumerable<Valkerie::ID] The ids of the works this work is in
# def parent_work_ids(valkyrie: false)
# parent_works(valkyrie: valkyrie).map(&:id)
# end
Copy link
Contributor

Choose a reason for hiding this comment

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

This commented block needs to be removed.

Copy link
Contributor

@jrgriffiniii jrgriffiniii left a comment

Choose a reason for hiding this comment

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

I can clean the comments, but otherwise this seems to be an excellent solution.

…havior; Fixing a typo. error in the comment for Wings::Pcdm::PcdmValkyrieBehavior#parent_work_ids
@elrayle elrayle dismissed their stale review April 4, 2019 13:51

I added code requiring review by others.

Fixes a random error in find_members test where sometimes the results are in the correct order and sometimes not.
@@ -139,7 +139,7 @@ def parent_works(valkyrie: false)
end

# @param valkyrie [Boolean] Should the returned ids be for Valkyrie or AF objects?
# @return [Enumerable<String> | Enumerable<Valkyrie::ID>] The ids of the file sets this work contains
# @return [Enumerable<String> | Enumerable<Valkerie::ID>] The ids of the works this work is contained in
Copy link
Contributor

Choose a reason for hiding this comment

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

Valkerie?

@elrayle elrayle dismissed jrgriffiniii’s stale review April 4, 2019 15:09

requested changes addressed

@elrayle elrayle merged commit 9192ec0 into master Apr 4, 2019
@elrayle elrayle deleted the wings-ordered-members branch April 4, 2019 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants