Comments (5)
This is a good question. It is also a part of the ResourceService
interface that I am least happy with. If you have a suggestion for improving this, I will be quite interested.
For some context: the HTTP layer needs a mechanism for generating identifiers both for resources (e.g. POST w/o a Slug header) and for the internal identifiers for Binaries (LDP-NR). The public-facing resource identifiers may very well be structured differently than the internal binary identifiers. (For example, a file-based binary service might need to add intermediate path hierarchies in order to get around limitations of a POSIX filesystem). So, I wanted both the ResourceService
and the BinaryService
each to be able to "configure" a single IdentifierService
object, which is why both ResourceService
and BinaryService
have this sort of getIdentifierSupplier
method.
I can think of at least two (possibly better) approaches -- you may have some other ideas:
-
Change the method name to
generateIdentifier
in both interfaces, each just returning aString
rather than a fullSupplier<String>
. This seems straight-forward and pretty easy. It also allows a particularBinary|ResourceService
to specialize the identifier generation as needed (since those layers should know how those identifiers ought to be structured). -
Remove this method entirely from both, and instead isolate the identifier generation entirely in the HTTP layer. This might involve creating specializations of the IdentifierService interface (e.g. BinaryIdentifierService), but it may also make it possible to use simple ServiceLoader injection of these implementations.
The current design is definitely an example of expediency over clear design, and I would be very interested to think about different ways to structure this.
from trellis.
I think we may have a confusion between two different functions: supplying identifiers, and supplying different types of identifiers. That's how I translate:
the HTTP layer needs a mechanism for generating identifiers both for resources (e.g. POST w/o a Slug header) and for the internal identifiers for Binaries (LDP-NR)…
So I would suggest a type-based solution (to add to the list you already have!): a single identifier service for the whole architecture that looks something like:
IdentifierService extends Supplier<String>, Function<IRI,String> {}
and one uses ::get
when one doesn't care about whatever translation semantics might apply and one uses .apply(type)
to get an identifier that is meet and fit for a certain type of resource, e.g. binaries.
Or, if you want to disconnect supply from service, something like:
IdentifierService {
Supplier<String> getIdentifierSupplier();
Supplier<String> getIdentifierSupplier(IRI type);
}
which is also less concise and easier to read and understand. Do you see what I mean about separating (a little bit) "generating" and "generating different types"? As long as the HTTP layer addresses only the interface, all is well. Then the integrator (who knows all about the different needs of different component impls) selects an appropriate IdentifierService
impl when she wires everything up into a deployable(s).
from trellis.
A type-based solution would be excellent. The suggestion to use:
IdentifierService extends Supplier<String>, Function<IRI,String> {}
seems very promising.
from trellis.
Well, that would be very concise. Honestly, though, I wonder if it is too concise...
from trellis.
I'd like to experiment with this (and your other suggestion) a bit. If one of them seems to fit well with the needs of the HTTP layer, then the choice should be pretty clear.
from trellis.
Related Issues (20)
- Resource type is determined by first link header, as opposed to first Link with rel="type"
- Encode IRIs when used with java.net.URI
- Disallow "unwise" characters from URLs
- Improve support for reserved characters
- Support JSON-LD 1.1 HOT 3
- Replace embedded pgsql test server
- Remove basic auth module
- Rename Event API to Notification
- Remove trellis-specific notification connectors
- Separate reactive API from synchronous API HOT 1
- Upgrade to MicroProfile 4.0
- Client support for NodeJS / other languages? HOT 2
- Positioning / contrast with Jena HOT 8
- 500 response returned from request with Accept: text/html header HOT 2
- Potential misuse of `JsonWebToken` in 2 classes HOT 1
- URI consistency for containers and the trailing slash HOT 1
- Make the `trellis:` constants overwritable
- Specify "MP_JWT_VERIFY_PUBLICKEY" as a requirement or remove the dependency
- Query parameters HOT 1
- Use of mutation testing in trellis - Help needed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trellis.