|  | 
| 11 | 11 | /** | 
| 12 | 12 |  * Allows flexible bridging between adapters of different types with compatible functionality. | 
| 13 | 13 |  * | 
| 14 |  | - * @param <From> The container type supported by the available exporter. | 
| 15 |  | - * @param <To>   The container type that's desired. | 
|  | 14 | + * ## Usage | 
|  | 15 | + * | 
|  | 16 | + * DTP transfers data by passing models from an Exporter (producing bytes) | 
|  | 17 | + * to an {@link Importer} (consuming bytes). Models have a 1:1 correspondance to | 
|  | 18 | + * {@link org.datatransferproject.types.common.models.DataVertical} (so a PHOTO | 
|  | 19 | + * vertical is universally assumed in the DTP codebase to be used for | 
|  | 20 | + * PhotosContainerResource transfers). | 
|  | 21 | + * | 
|  | 22 | + * ### Example Usage | 
|  | 23 | + * | 
|  | 24 | + * Given: | 
|  | 25 | + * | 
|  | 26 | + * - a DataVertical.PHOTO transfer | 
|  | 27 | + * - a matching Exporter: an adapter producing {@link PhotosContainerResource} data | 
|  | 28 | + * - a stand-in Importer: a good-enough adapter; something intended for a | 
|  | 29 | + *   semi-compatible but not identical data type (eg: {@link MediaContainerResource}). | 
|  | 30 | + * - a conversion function to go from said PHOTOS objects to DataVertical.MEDIA | 
|  | 31 | + *   objects (eg: {@link MediaContainerResource} data). | 
|  | 32 | + * | 
|  | 33 | + * Then: one can create a synthetic Importer with this class by constructing with said conversion function. | 
|  | 34 | + * | 
|  | 35 | + * @param <StandinImporterType> Container type in which some extant exporter is | 
|  | 36 | + *     providing data. eg: MediaContainerResource. | 
|  | 37 | + * @param <ExportingType> The original container type which is being exported | 
|  | 38 | + *     (that we will convert before arriving at our stand-in importer); eg: | 
|  | 39 | + *     PhotosContainerResource. | 
| 16 | 40 |  */ | 
| 17 | 41 | public class AnyToAnyImporter< | 
| 18 | 42 |     AD extends AuthData, | 
| 19 |  | -    From extends ContainerResource, | 
| 20 |  | -    To extends ContainerResource> implements Importer<AD, To> { | 
|  | 43 | +    StandinImporterType extends ContainerResource, | 
|  | 44 | +    ExportingType extends ContainerResource> implements Importer<AD, ExportingType> { | 
| 21 | 45 | 
 | 
| 22 |  | -  private final Importer<AD, From> importer; | 
| 23 |  | -  private final Function<To, From> converter; | 
|  | 46 | +  private final Importer<AD, StandinImporterType> standinImporter; | 
|  | 47 | +  private final Function<ExportingType, StandinImporterType> modelConverter; | 
| 24 | 48 | 
 | 
| 25 | 49 |   /** | 
| 26 |  | -   * @param importer  existing importer | 
| 27 |  | -   * @param converter function converting between the existing and desired containers. | 
|  | 50 | +   * @param standinImporter  existing importer | 
|  | 51 | +   * @param modelConverter function converting between some existing | 
|  | 52 | +   *    exporters' type to our stand-in importers' container types. | 
| 28 | 53 |    */ | 
| 29 |  | -  public AnyToAnyImporter(Importer<AD, From> importer, Function<To, From> converter) { | 
| 30 |  | -    this.importer = importer; | 
| 31 |  | -    this.converter = converter; | 
|  | 54 | +  public AnyToAnyImporter( | 
|  | 55 | +      Importer<AD, StandinImporterType> standinImporter, | 
|  | 56 | +      Function<ExportingType, StandinImporterType> modelConverter | 
|  | 57 | +    ) { | 
|  | 58 | +    this.standinImporter = standinImporter; | 
|  | 59 | +    this.modelConverter = modelConverter; | 
| 32 | 60 |   } | 
| 33 | 61 | 
 | 
| 34 | 62 |   @Override | 
| 35 |  | -  public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentExecutor, | 
| 36 |  | -      AD authData, To data) throws Exception { | 
| 37 |  | -    return importer.importItem(jobId, idempotentExecutor, authData, converter.apply(data)); | 
|  | 63 | +  public ImportResult importItem( | 
|  | 64 | +      UUID jobId, | 
|  | 65 | +      IdempotentImportExecutor idempotentExecutor, | 
|  | 66 | +      AD authData, | 
|  | 67 | +      ExportingType data | 
|  | 68 | +  ) throws Exception { | 
|  | 69 | +    return standinImporter.importItem(jobId, idempotentExecutor, authData, modelConverter.apply(data)); | 
| 38 | 70 |   } | 
| 39 | 71 | } | 
0 commit comments