-
Notifications
You must be signed in to change notification settings - Fork 481
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
Add automatic media job type compatibility #1136
Conversation
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.
sorry for the delay - I hadn't realized I hadn't submitted or finished my comments. Feel free to ping me in chat if my next replies aren't within a day.
*/ | ||
public class TransferCompatibilityProvider { | ||
|
||
private static final String PHOTOS = "PHOTOS"; |
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.
since you're tackling this, please setup a new enum (just to make some micro-progress against #1065's wish to kill these magic strings). eg: org.datatransferproject.spi.transfer.DataVertical
; fwiw I think spi.transfer
is the right place (and not in types.common.models
) because these are have historically been used and developed as "verticals" which are not strictly the same things as models but more of a meta concept. Pulling the enum out this way has two benefits:
- implicitly documents a bit of that distinction I just described
- lets us eventually update the transferextension's maps to use these documented enums as keys instead of the magic strings they take now
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.
Cool, I'll pick it up. I've been frustrated by this issue as well.
* sufficient. | ||
*/ | ||
public AnyToAnyExporter(Exporter<AD, From> exporter, Function<From, To> converter, | ||
Function<ContainerResource, ContainerResource> inputConverter) { |
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.
should inputConverter
's parameterizations be To
and From
respectively?
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.
Unfortunately, no. That's because an Exporter<PhotosContainerResource>
takes ExportInformation<ContainerResource>
as input to its export
method. This container resource can be anything at all, e.g. IdOnlyContainerResource
, DateRangeContainerResource
, PhotosContainerResource
, or even some private resource etc. For some reason, we're not enforcing strict typing in this case.
The From
and To
exporters might support different inputs and still be made compatible via the AnyToAnyExporter
. For example, converting from PhotosExporter
to MediaExporter
might involve passing Id
and DateRange
resources unchanged and converting the PhotosContainerResource
to MediaContainerResource
.
private final Exporter<AD, From> exporter; | ||
private final Function<From, To> converter; | ||
private final Function<ContainerResource, ContainerResource> inputConverter; |
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.
private final Exporter<AD, From> exporter; | |
private final Function<From, To> converter; | |
private final Function<ContainerResource, ContainerResource> inputConverter; | |
private final Exporter<AD, From> exporter; | |
private final Function<From, To> containerResourceConverter; | |
private final Function<ContainerResource, ContainerResource> exportInformationConverter; |
* export call. It's required because exporters often support various | ||
* container resources as part of export information. E.g. photo exporters | ||
* support DateRangeContainerResource, while media adapters might only | ||
* support MediaContainerResource. Oftentimes, Function.identity() is |
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.
Oftentimes, Function.identity() is sufficient.
Maybe we just provide an overloaded constructor for that case then? (eg only takes two params, and automatically uses Function.identity()
for the third arg?)
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.
That is fair, I just don't have any such usages at the moment. I actually had that for the MicrosoftTransferExtension
while it didn't have a dedicated media adapter.
@@ -23,6 +23,7 @@ | |||
*/ | |||
// TODO(#1065) fix primitives-obession causing us to key Providers on "PHOTOS" string rather | |||
// than underlying file types. | |||
@Deprecated |
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.
everywhere you add this annotation, can you comment also what the recommended alternative is, as an inline comment? eg:
@Deprecated // prefer FooBar#baz
|
||
videos = List.of( | ||
new VideoModel("v1", "", null, null, "d4", null, false), | ||
new VideoModel("v2", "", null, null, "d5", "a3", false), |
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.
should the album params on these photo or video models match the params of the media albums above? Or are they intentionally mismatched for testing purpose?
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.
Ah, no reason. The particular data isn't relevant to the test.
videosImporter = (id, ex, ad, data) -> ImportResult.OK; | ||
mediaImporter = new MediaImporterDecorator<>(photosImporter, videosImporter); | ||
|
||
albums = List.of(new MediaAlbum("album1", "name1", "desc1"), |
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.
(optional nitpick) suggestion to make these lines consistent with your others below
albums = List.of(new MediaAlbum("album1", "name1", "desc1"), | |
albums = List.of( | |
new MediaAlbum("album1", "name1", "desc1"), |
* Extracts a new VideosContainerResource from the relevant matching fields in a given | ||
* MediaContainerResource. | ||
*/ | ||
public static VideosContainerResource mediaToVideo(MediaContainerResource mediaContainer) { |
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.
nit: consider adding test coverage of these two new static methods
Do you have a pending PR somewhere that shows the final use of this? (eg: a PR that modifies a transfer extension?) |
In our case, we're creating Media jobs without adding dedicated Media adapters. Essentially, we're leveraging the This way we get to seamlessly support Media jobs without adding any new adapters, in our codebase or the destinations. |
hey @incjo did you accidentally revert this PR via a force-push? I'm not able to find the code we reviewed here and indeed if I click "compare" on this "incjo force-pushed the |
Yep, for some reason Github decides to close the PR if you force push the wrong thing which is exactly what I did. Thanks Github. I don't have permissions to reopen the PR. I've addressed your feedback and will probably just make a new PR with the changes. |
makes progress against #1065 by building on top of #1062 by further expanding support for automatically handling media jobs.
It allows not writing dedicated media adapters in cases where the existing photo/video functionality is satisfactory. It also provides automatic interoperability with destinations that only provide a Media adapter.
Main contributions:
MediaToPhotoConversionImporter
andMediaToPhotoConversionExporter
with generic versions that can support conversion between any two adapters:AnyToAnyImporter
andAnyToAnyExporter
MediaExporterDecorator
andMediaImporterDecorator
which combine existing photo and video adapters to seamlessly cover the media job type.TransferCompatibilityProvider
(perhaps rename toAdapterCompatibilityProvider
?) which attempts to build a substitute adapter upon not finding a real one. E.g. when a media job can't find a media importer, it will combine existing photo and video importers to perform the job.