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

XWIKI-22681: Provide a relative ResourceReferenceEntityReferenceResolver #3673

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

surli
Copy link
Member

@surli surli commented Nov 22, 2024

Jira URL

https://jira.xwiki.org/browse/XWIKI-22681

TODO

  • Add missing tests for Page/PageAttachment resources

Changes

Description

  • Provide implementation for a RelativeResourceReferenceEntityReferenceResolver
  • Resolution of untyped document references is closely related to resolution performed by the default resolver, except when it's not possible to have info about the parent. We need to ensure we agree on this implem. Note that it also impacts resolution of attachment resources.

Clarifications

Screenshots & Video

Executed Tests

Run mvn clean install -Pquality on module xwiki-platform-rendering-xwiki. Now this component implem is used for #3654 so integration tests are executed in that one.

Expected merging strategy

  • Prefers squash: Yes
  • Backport on branches:
    • 16.10.x since we need that to fix XWIKI-22571

// TODO: check that this assert is ok, we don't get the default page since we don't have any info to properly
// resolve the absolute ref (no wiki, no base reference)
assertEquals(PAGE_ENTITY_REFERENCE,
this.resolver.resolve(documentResource(SPACE + '.' + PAGE, false), null));
Copy link
Member Author

Choose a reason for hiding this comment

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

This assertion is probably the first one we should ensure we agree on.

Copy link
Member

@tmortagne tmortagne Nov 26, 2024

Choose a reason for hiding this comment

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

This does not feel right: when no specific target can be found, an untyped reference is supposed to target a WebHome by default. You don't really need a base reference to know that.

Alternatively, you could decide to return an entity reference of type PAGE, in which case you don't need to worry about WebHome. Unfortunately, it would probably be a bit dangerous to change this behavior to have the same logic in the absolute resolver.

Copy link
Member Author

Choose a reason for hiding this comment

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

This does feel right: when no specific target can be found, an untyped reference is supposed to target a WebHome by default. You don't really need a base reference to know that.

So it does not feel right?

Copy link
Member

Choose a reason for hiding this comment

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

So it does not feel right?

Yes, sorry, I fixed the comment.

}

@Override
protected EntityReference resolveUntyped(ResourceReference resourceReference, EntityReference baseReference)
Copy link
Member

Choose a reason for hiding this comment

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

Looks a lot like DocumentResourceReferenceEntityReferenceResolver#resolveUntyped. It would be better to improve code reuse.

}

@Override
public EntityReference resolve(ResourceReference resourceReference, EntityType entityType, Object... parameters)
Copy link
Member

@tmortagne tmortagne Nov 25, 2024

Choose a reason for hiding this comment

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

This seems to be almost an exact duplicate of the AbstractResourceReferenceEntityReferenceResolver version. I'm sure code reuse can be improved.

The point of convert (which removing it seems to be the reason why you did this whole duplicate) is not to resolve an absolute reference, it's to convert a reference of the DOCUMENT world from/into a reference of the PAGE world, depending of which type was passed to #resolve.

@tmortagne
Copy link
Member

The relations between the relative and absolute versions of EntityReferenceResolver<ResourceReference> seems to be messy. One seems to extend the other, but at the same time duplicate a lot of things that don't seem to really have a different logic. Feels like you should do stuff like introduce a AbstractAbsoluteResourceReferenceEntityReferenceResolver which extends AbstractResourceReferenceEntityReferenceResolver (like AbstractRelativeResourceReferenceEntityReferenceResolver) and distribute a bit better the differences between the relative and the absolute logic.

// resolve the absolute ref (no wiki, no base reference)
assertEquals(PAGE_ENTITY_REFERENCE,
this.resolver.resolve(documentResource(SPACE + '.' + PAGE, false), null));
assertEquals(PAGE_ALONE_ENTITY_REFERENCE,
Copy link
Member

@tmortagne tmortagne Nov 26, 2024

Choose a reason for hiding this comment

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

Now, one problem is that adding a WebHome in the result of that example where you have no space is that it completely change the behavior of the relative -> absolute resolution. As soon as a reference contains a space, it's considered "absolute" in a given wiki, which is not the intent here since the "Page" reference is supposed to be relative to the current space.

Copy link
Member Author

@surli surli Nov 26, 2024

Choose a reason for hiding this comment

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

it completely change the behavior of the relative -> absolute resolution

I'm trying to understand what you mean exactly here. My understanding is that you mean there's an inconsistency between:

  1. Resolving a ResourceReference Space.WebHome to an absolute EntityReference which would result in currentwiki:Space.WebHome
  2. Resolving a ResourceReference Space.WebHome to a relative EntityReference which would result in Space.WebHome and then resolving that one to an absolute EntityReference which would result in defaultwiki:Space.WebHome

Am I understanding it correctly?

Copy link
Member

@tmortagne tmortagne Nov 27, 2024

Choose a reason for hiding this comment

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

I think you understood, but your examples are not accurate since the ResourceReference is Page (Space.WebHome would not be resolved as currentwiki.CurrentSpace.Space.WebHome).

Copy link
Member Author

Choose a reason for hiding this comment

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

I edited my comment to fix the example.
So ok now I think I understand what you were saying last time. We have two solutions here:

  1. We always perform the "absolute" resolution, meaning what I'm doing here is useless basically: the resolver would never return a relative reference for Document type at least
  2. We put an info in the EntityReference that it's relative and that's consumer job of the API to check if the EntityReference is relative or not and to use the proper resolver (current or default), we could probably directly also implement the logic of checking that info.

I think I prefer option 2 even if it's more work, as we provide a true meaning of relative entity reference. If we go for 1 IMO it's almost as if we would never really consider relative references...

Copy link
Member Author

Choose a reason for hiding this comment

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

There's actually a 3rd solution: we accept the inconsistency of getting different results, depending if you resolved directly the ResourceReference to absolute or if you resolved it first to relative and then the EntityReference to absolute

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