@Test void testFailImportRunTrancatedMessage() { StringBuilder messageBuilder = new StringBuilder(65545); for (int i = 0; i < 65535; ++i) { messageBuilder.append("x"); } String truncated64KbMessage = messageBuilder.toString(); for (int i = 0; i < 10; ++i) { messageBuilder.append("y"); } String moreThan64KbMessage = messageBuilder.toString(); String importRunId = "importRunId"; ImportRun importRun = mock(ImportRun.class); when(dataService.findOneById(IMPORT_RUN, importRunId, ImportRun.class)).thenReturn(importRun); importRunService.failImportRun(importRunId, moreThan64KbMessage); verify(dataService).update(IMPORT_RUN, importRun); verify(importRun).setMessage(truncated64KbMessage); verify(importRun).setStatus("FAILED"); verify(importRun).setEndDate(any()); }
void failImportRun(String importRunId, @Nullable @CheckForNull String message) { ImportRun importRun = dataService.findOneById(IMPORT_RUN, importRunId, ImportRun.class); if (importRun == null) { return; } try { String persistedMessage; if (message == null) { persistedMessage = contextMessageSource.getMessage("import_unknown_error"); } else { if (message.length() > TEXT.getMaxLength()) { persistedMessage = message.substring(0, toIntExact(TEXT.getMaxLength())); } else { persistedMessage = message; } } importRun.setStatus(ImportStatus.FAILED.toString()); importRun.setEndDate(now()); importRun.setMessage(persistedMessage); dataService.update(IMPORT_RUN, importRun); } catch (Exception e) { LOG.error("Error updating run status", e); } if (importRun.getNotify()) { createAndSendStatusMail(importRun); } }
ImportRunService { void failImportRun(String importRunId, @Nullable @CheckForNull String message) { ImportRun importRun = dataService.findOneById(IMPORT_RUN, importRunId, ImportRun.class); if (importRun == null) { return; } try { String persistedMessage; if (message == null) { persistedMessage = contextMessageSource.getMessage("import_unknown_error"); } else { if (message.length() > TEXT.getMaxLength()) { persistedMessage = message.substring(0, toIntExact(TEXT.getMaxLength())); } else { persistedMessage = message; } } importRun.setStatus(ImportStatus.FAILED.toString()); importRun.setEndDate(now()); importRun.setMessage(persistedMessage); dataService.update(IMPORT_RUN, importRun); } catch (Exception e) { LOG.error("Error updating run status", e); } if (importRun.getNotify()) { createAndSendStatusMail(importRun); } } }
ImportRunService { void failImportRun(String importRunId, @Nullable @CheckForNull String message) { ImportRun importRun = dataService.findOneById(IMPORT_RUN, importRunId, ImportRun.class); if (importRun == null) { return; } try { String persistedMessage; if (message == null) { persistedMessage = contextMessageSource.getMessage("import_unknown_error"); } else { if (message.length() > TEXT.getMaxLength()) { persistedMessage = message.substring(0, toIntExact(TEXT.getMaxLength())); } else { persistedMessage = message; } } importRun.setStatus(ImportStatus.FAILED.toString()); importRun.setEndDate(now()); importRun.setMessage(persistedMessage); dataService.update(IMPORT_RUN, importRun); } catch (Exception e) { LOG.error("Error updating run status", e); } if (importRun.getNotify()) { createAndSendStatusMail(importRun); } } ImportRunService(
      DataService dataService,
      MailSender mailSender,
      UserService userService,
      ContextMessageSource contextMessageSource,
      ImportRunFactory importRunFactory); }
ImportRunService { void failImportRun(String importRunId, @Nullable @CheckForNull String message) { ImportRun importRun = dataService.findOneById(IMPORT_RUN, importRunId, ImportRun.class); if (importRun == null) { return; } try { String persistedMessage; if (message == null) { persistedMessage = contextMessageSource.getMessage("import_unknown_error"); } else { if (message.length() > TEXT.getMaxLength()) { persistedMessage = message.substring(0, toIntExact(TEXT.getMaxLength())); } else { persistedMessage = message; } } importRun.setStatus(ImportStatus.FAILED.toString()); importRun.setEndDate(now()); importRun.setMessage(persistedMessage); dataService.update(IMPORT_RUN, importRun); } catch (Exception e) { LOG.error("Error updating run status", e); } if (importRun.getNotify()) { createAndSendStatusMail(importRun); } } ImportRunService(
      DataService dataService,
      MailSender mailSender,
      UserService userService,
      ContextMessageSource contextMessageSource,
      ImportRunFactory importRunFactory); ImportRun addImportRun(String userName, boolean notify); }
ImportRunService { void failImportRun(String importRunId, @Nullable @CheckForNull String message) { ImportRun importRun = dataService.findOneById(IMPORT_RUN, importRunId, ImportRun.class); if (importRun == null) { return; } try { String persistedMessage; if (message == null) { persistedMessage = contextMessageSource.getMessage("import_unknown_error"); } else { if (message.length() > TEXT.getMaxLength()) { persistedMessage = message.substring(0, toIntExact(TEXT.getMaxLength())); } else { persistedMessage = message; } } importRun.setStatus(ImportStatus.FAILED.toString()); importRun.setEndDate(now()); importRun.setMessage(persistedMessage); dataService.update(IMPORT_RUN, importRun); } catch (Exception e) { LOG.error("Error updating run status", e); } if (importRun.getNotify()) { createAndSendStatusMail(importRun); } } ImportRunService(
      DataService dataService,
      MailSender mailSender,
      UserService userService,
      ContextMessageSource contextMessageSource,
      ImportRunFactory importRunFactory); ImportRun addImportRun(String userName, boolean notify);  }