Repository: corona-warn-app/cwa-server
File: services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/QrCodePosterTemplateStructureProvider.java (Java)

Code before:
   * Returns the publishable archive associated with the QR code poster template for IOS mobile clients.
   */
  public WritableOnDisk getQrCodeTemplateForIos() {
    return constructArchiveToPublish(distributionServiceConfig.getIosQrCodePosterTemplate(),
        this::buildIosProtoStructure,
        distributionServiceConfig.getIosQrCodePosterTemplate().getPublishedArchiveName());
  }

  private <T extends com.google.protobuf.GeneratedMessageV3> WritableOnDisk constructArchiveToPublish(
      QrCodePosterTemplate qrTemplateConfig, Function<QrCodePosterTemplate, T> protoBuilderFunction,
      String archiveName) {
    T templateProto = protoBuilderFunction.apply(qrTemplateConfig);
    ArchiveOnDisk archiveToPublish = new ArchiveOnDisk(archiveName);
    archiveToPublish.addWritable(new FileOnDisk("export.bin", templateProto.toByteArray()));
    return archiveToPublish;
  }

  private QRCodePosterTemplateAndroid buildAndroidProtoStructure(
      QrCodePosterTemplate templateConfig) {
    DescriptionTextBox textBoxConfig = templateConfig.getDescriptionTextBox();
    return QRCodePosterTemplateAndroid.newBuilder().setOffsetX(templateConfig.getOffsetX().floatValue())
        .setOffsetY(templateConfig.getOffsetY().floatValue())
        .setTemplate(qrTemplateLoader.loadAndroidTemplateAsBytes())
        .setQrCodeSideLength(templateConfig.getQrCodeSideLength())
        .setDescriptionTextBox(QRCodeTextBoxAndroid.newBuilder()
            .setOffsetX(textBoxConfig.getOffsetX().intValue()).setOffsetY(textBoxConfig.getOffsetY().intValue())
            .setFontSize(textBoxConfig.getFontSize()).setHeight(textBoxConfig.getHeight())
            .setFontColor(textBoxConfig.getFontColor()).build())
        .build();
  }

  private QRCodePosterTemplateIOS buildIosProtoStructure(QrCodePosterTemplate templateConfig) {
    DescriptionTextBox textBoxConfig = templateConfig.getDescriptionTextBox();
    return QRCodePosterTemplateIOS.newBuilder().setOffsetX(templateConfig.getOffsetX().intValue())
        .setOffsetY(templateConfig.getOffsetY().intValue())
        .setTemplate(qrTemplateLoader.loadIosTemplateAsBytes())
        .setQrCodeSideLength(templateConfig.getQrCodeSideLength())
        .setDescriptionTextBox(QRCodeTextBoxIOS.newBuilder().setOffsetX(textBoxConfig.getOffsetX().intValue())
            .setOffsetY(textBoxConfig.getOffsetY().intValue()).setFontSize(textBoxConfig.getFontSize())
            .setHeight(textBoxConfig.getHeight()).setFontColor(textBoxConfig.getFontColor())
            .build())
        .build();
  }
}


Review comment (suggestion):
```suggestion
            .setOffsetX(textBoxConfig.getOffsetX().floatValue()).setOffsetY(textBoxConfig.getOffsetY().floatValue())
```

Code after:
   * Returns the publishable archive associated with the QR code poster template for IOS mobile clients.
   */
  public WritableOnDisk getQrCodeTemplateForIos() {
    return constructArchiveToPublish(distributionServiceConfig.getIosQrCodePosterTemplate(),
        this::buildIosProtoStructure,
        distributionServiceConfig.getIosQrCodePosterTemplate().getPublishedArchiveName());
  }

  private <T extends com.google.protobuf.GeneratedMessageV3> WritableOnDisk constructArchiveToPublish(
      QrCodePosterTemplate qrTemplateConfig, Function<QrCodePosterTemplate, T> protoBuilderFunction,
      String archiveName) {
    T templateProto = protoBuilderFunction.apply(qrTemplateConfig);
    ArchiveOnDisk archiveToPublish = new ArchiveOnDisk(archiveName);
    archiveToPublish.addWritable(new FileOnDisk("export.bin", templateProto.toByteArray()));
    return archiveToPublish;
  }

  private QRCodePosterTemplateAndroid buildAndroidProtoStructure(
      QrCodePosterTemplate templateConfig) {
    DescriptionTextBox textBoxConfig = templateConfig.getDescriptionTextBox();
    return QRCodePosterTemplateAndroid.newBuilder().setOffsetX(templateConfig.getOffsetX().floatValue())
        .setOffsetY(templateConfig.getOffsetY().floatValue())
        .setTemplate(qrTemplateLoader.loadAndroidTemplateAsBytes())
        .setQrCodeSideLength(templateConfig.getQrCodeSideLength())
        .setDescriptionTextBox(QRCodeTextBoxAndroid.newBuilder()
            .setOffsetX(textBoxConfig.getOffsetX().floatValue()).setOffsetY(textBoxConfig.getOffsetY().floatValue())
            .setFontSize(textBoxConfig.getFontSize()).setHeight(textBoxConfig.getHeight())
            .setFontColor(textBoxConfig.getFontColor()).build())
        .build();
  }

  private QRCodePosterTemplateIOS buildIosProtoStructure(QrCodePosterTemplate templateConfig) {
    DescriptionTextBox textBoxConfig = templateConfig.getDescriptionTextBox();
    return QRCodePosterTemplateIOS.newBuilder().setOffsetX(templateConfig.getOffsetX().intValue())
        .setOffsetY(templateConfig.getOffsetY().intValue())
        .setTemplate(qrTemplateLoader.loadIosTemplateAsBytes())
        .setQrCodeSideLength(templateConfig.getQrCodeSideLength())
        .setDescriptionTextBox(QRCodeTextBoxIOS.newBuilder().setOffsetX(textBoxConfig.getOffsetX().intValue())
            .setOffsetY(textBoxConfig.getOffsetY().intValue()).setFontSize(textBoxConfig.getFontSize())
            .setHeight(textBoxConfig.getHeight()).setFontColor(textBoxConfig.getFontColor())
            .build())
        .build();
  }
}