Загрузка данных


public class DefaultAttachmentProcessor implements AttachmentProcessor {
  protected static final String ATTACHMENT_DIR = "perfeccionista.attachment.dir";
  protected static Properties perfeccionistaProperties;
  protected static Properties systemProperties;
  public static final Logger log = LoggerFactory.getLogger(DefaultAttachmentProcessor.class);
  public static final DateTimeFormatter ID_FORMAT;
  public static final DateTimeFormatter ALL_OS_ISO_LOCAL_TIME;

  public String processAttachment(@NotNull Attachment attachment) {
    String fileAttachmentsDescription = (String)attachment.getAttachmentEntries().filter((entry) -> entry instanceof FileAttachmentEntry).map((entry) -> {
      FileAttachmentEntry<?> fileAttachmentEntry = (FileAttachmentEntry)entry;
      String var10000 = this.createId();
      String fileName = var10000 + "_" + entry.getName() + "." + fileAttachmentEntry.getFileExtension();
      Path filePath = Paths.get(this.getAttachmentDir() + File.separator + fileName);
      if (fileAttachmentEntry instanceof HtmlAttachmentEntry) {
        String content = (String)((HtmlAttachmentEntry)fileAttachmentEntry).getContent().orElse("");
        FileUtils.deleteFileIgnoreExceptions(filePath);
        FileUtils.writeTextFile(filePath, content);
      } else if (fileAttachmentEntry instanceof JsonAttachmentEntry) {
        String content = ((JsonNode)((JsonAttachmentEntry)fileAttachmentEntry).getContent().orElse(JsonUtils.createObjectNode())).toPrettyString();
        FileUtils.deleteFileIgnoreExceptions(filePath);
        FileUtils.writeTextFile(filePath, content);
      } else if (fileAttachmentEntry instanceof ScreenshotAttachmentEntry) {
        Screenshot screenshot = (Screenshot)((ScreenshotAttachmentEntry)entry).getContent().orElseThrow(() -> EmptyAttachment.exception(UtilsMessages.EMPTY_ATTACHMENT_ENTRY.getMessage(new Object[0])));
        FileUtils.deleteFileIgnoreExceptions(filePath);
        FileUtils.writeBinaryFile(filePath, screenshot.getRaw());
      } else if (fileAttachmentEntry instanceof BigTextAttachmentEntry) {
        String content = (String)((BigTextAttachmentEntry)fileAttachmentEntry).getContent().orElse("");
        FileUtils.deleteFileIgnoreExceptions(filePath);
        FileUtils.writeTextFile(filePath, content);
      }

      var10000 = this.getDelimiter(true);
      return var10000 + entry.getName() + " " + filePath.toAbsolutePath();
    }).collect(Collectors.joining("\n"));
    String stringAttachmentsDescription = (String)attachment.getAttachmentEntries().filter((entry) -> entry instanceof TextAttachmentEntry).map((entry) -> {
      String var10000 = this.getDelimiter(true);
      return var10000 + "[" + entry.getName() + "]\n" + entry.getDescription();
    }).collect(Collectors.joining("\n"));
    if (StringUtils.isBlank(fileAttachmentsDescription) && StringUtils.isBlank(stringAttachmentsDescription)) {
      return "";
    } else {
      String var10000 = StringUtils.isBlank(fileAttachmentsDescription) ? "" : fileAttachmentsDescription + "\n";
      String attachmentDescription = "Attachments:\n" + var10000 + (StringUtils.isBlank(stringAttachmentsDescription) ? "" : stringAttachmentsDescription + "\n") + this.getDelimiter(false);
      log.info(attachmentDescription);
      return attachmentDescription;
    }
  }

  protected String createId() {
    return LocalDateTime.now().format(ID_FORMAT);
  }

  protected String getAttachmentDir() {
    systemProperties = System.getProperties();
    if (systemProperties.containsKey("perfeccionista.attachment.dir")) {
      return systemProperties.getProperty("perfeccionista.attachment.dir");
    } else {
      perfeccionistaProperties = (Properties)FileUtils.readOptionalPropertyFileFromClasspath("perfeccionista.properties").orElse(new Properties());
      return perfeccionistaProperties.containsKey("perfeccionista.attachment.dir") ? perfeccionistaProperties.getProperty("perfeccionista.attachment.dir") : "attachments";
    }
  }

  static {
    ALL_OS_ISO_LOCAL_TIME = (new DateTimeFormatterBuilder()).appendValue(ChronoField.HOUR_OF_DAY, 2).appendLiteral('-').appendValue(ChronoField.MINUTE_OF_HOUR, 2).optionalStart().appendLiteral('-').appendValue(ChronoField.SECOND_OF_MINUTE, 2).optionalStart().appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true).toFormatter().withResolverStyle(ResolverStyle.STRICT);
    ID_FORMAT = (new DateTimeFormatterBuilder()).parseCaseInsensitive().appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD).appendValue(ChronoField.MONTH_OF_YEAR, 2).appendValue(ChronoField.DAY_OF_MONTH, 2).appendLiteral('-').append(ALL_OS_ISO_LOCAL_TIME).toFormatter();
  }
}


public class AllureAttachmentProcessor implements AttachmentProcessor {
  public String processAttachment(@NotNull Attachment attachment) {
    attachment.getAttachmentEntries().filter((entry) -> entry instanceof FileAttachmentEntry).forEach((entry) -> {
      FileAttachmentEntry<?> fileAttachmentEntry = (FileAttachmentEntry)entry;
      String fileExtension = fileAttachmentEntry.getFileExtension();
      String var10000 = entry.getName();
      String fileName = var10000 + "." + fileExtension;
      if (fileAttachmentEntry instanceof HtmlAttachmentEntry) {
        String content = (String)((HtmlAttachmentEntry)fileAttachmentEntry).getContent().orElse("");
        Allure.addAttachment(fileName, "text/html", content, fileExtension);
      } else if (fileAttachmentEntry instanceof JsonAttachmentEntry) {
        String content = ((JsonNode)((JsonAttachmentEntry)fileAttachmentEntry).getContent().orElse(JsonUtils.createObjectNode())).toPrettyString();
        Allure.addAttachment(fileName, "application/json", content, fileExtension);
      } else if (fileAttachmentEntry instanceof ScreenshotAttachmentEntry) {
        Screenshot screenshot = (Screenshot)((ScreenshotAttachmentEntry)entry).getContent().orElseThrow(() -> EmptyAttachment.exception(UtilsMessages.EMPTY_ATTACHMENT_ENTRY.getMessage(new Object[0])));
        Allure.addAttachment(fileName, screenshot.getMimeType(), new ByteArrayInputStream(screenshot.getRaw()), screenshot.getFileExtension());
      } else if (fileAttachmentEntry instanceof BigTextAttachmentEntry) {
        String content = (String)((BigTextAttachmentEntry)fileAttachmentEntry).getContent().orElse("");
        Allure.addAttachment(fileName, "text/plain", content, fileExtension);
      }

    });
    attachment.getAttachmentEntries().filter((entry) -> entry instanceof TextAttachmentEntry).forEach((entry) -> Allure.addAttachment(entry.getName(), "text/plain", entry.getDescription()));
    return "";
  }
}