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

SLING-9745 Sling Uri Mapping SPI #25

Closed

Conversation

ghenzler
Copy link
Contributor

@ghenzler ghenzler commented Sep 30, 2020

* @return the intermediate mappings
*/
@NotNull
Map<String, SlingUri> getIntermediateMappings();
Copy link
Contributor

@cziegeler cziegeler Oct 1, 2020

Choose a reason for hiding this comment

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

Why is this a map and not a list? What is the key for the values?
I assume this map is immutable?

Copy link
Contributor Author

@ghenzler ghenzler Oct 1, 2020

Choose a reason for hiding this comment

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

So currently the key is the classname of the SlingUriMapper that produced the result, it would probably be better to use type Class<? extends SlingUriMapper> as key, that would make it automatically clearer. Most clients will only need the values (and they can get it with values(), but sometimes it might be useful to check if a certain mapper produced a mapping result, and that can be done by getIntermediateMappings().containsKey() with the current API.

The map is immutable as the constructor call
https://github.com/apache/sling-org-apache-sling-resourceresolver/blob/4ab43acf49dfd9cd25119b74054980b3c4144918/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/PathToUriMappingServiceImpl.java#L108
uses Collections.unmodifiableMap(intermediateMappings)
https://github.com/apache/sling-org-apache-sling-resourceresolver/blob/4ab43acf49dfd9cd25119b74054980b3c4144918/src/main/java/org/apache/sling/resourceresolver/impl/urimapping/MappingChainContextInternal.java#L54

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that a class name is a good key - in theory there could be a factory component for SlingUriMapper with different configurations - sharing the same class name.
As this is ordered, it probably should be a list. So how about a list of some type of object, which has two getter methods, one to get the SlingUri, the other to get some info about the SlingUriMapper. We could add a default method to SlingUriMapper like getName() which by default returns the class name. But this way, the contract is at least more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the getIntermediateMappings() method in 43f5804 (for now left out SlingUriMapper.getName(), I think this can be autogenerated and if needed, be overwritten by a OSGI service property like we do it for HCs, that's maybe cleaner than forcing everybody to implement getName())

* @return the URI mappings
*/
@NotNull
Map<String, SlingUri> getIntermediateMappings();
Copy link
Contributor

Choose a reason for hiding this comment

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

same as with Result? Why a map, immutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see above

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be changed to List ?

@ghenzler ghenzler force-pushed the feature/SLING-9662-Introduce-SlingUri-Mapping-SPI-v3 branch from f149adc to 855191c Compare October 8, 2020 21:59
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 8, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

warning The version of Java (1.8.0_252) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
Read more here

@ghenzler
Copy link
Contributor Author

ghenzler commented Oct 8, 2020

An aspect that was missing is that sometimes, independent of if you have a request at hand or not, you need to force an absolute URI to be generated. E.g. while producing an html rendering with HTL, most links may remain relative to host (starting with /) but one link could be rendered in a data attribute to be consumed by a third-party REST API (that expects a full absolute URI). For this I added a parameter forceAbsoluteUri in 21dc4a2 . I think this is needed to cover all use cases (especially from HTL where this can be an additional attribute on URIs), but also for API calls from elsewhere. @cziegeler WDYT?

@cziegeler cziegeler closed this Nov 15, 2023
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