@Test void testImportFileMetadataActionUnknown() throws IOException, URISyntaxException { HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); String filename = "example.xlsx"; MultipartFile multipartFile = createMultipartFile(filename); String entityTypeId = null; String packageId = null; String metadataAction = "unknownAction"; String action = "add"; Boolean notify = null; String tmpFileName = "tmp-example.xlsx"; File tmpFile = mock(File.class); when(tmpFile.getName()).thenReturn(tmpFileName); when(fileStore.store(any(), eq("example.xlsx"))).thenReturn(tmpFile); @SuppressWarnings("ConstantConditions") ResponseEntity<String> responseEntity = importWizardController.importFile( httpServletRequest, multipartFile, entityTypeId, packageId, metadataAction, action, notify); assertEquals( badRequest() .contentType(TEXT_PLAIN) .body("Invalid action:[UNKNOWNACTION] valid values: [ADD, UPDATE, UPSERT, IGNORE]"), responseEntity); verify(fileStore).store(any(), eq(filename)); verifyZeroInteractions(executorService); }
@PostMapping("/importFile") public ResponseEntity<String> importFile( HttpServletRequest request, @RequestParam(value = "file") MultipartFile file, @RequestParam(value = "entityTypeId", required = false) String entityTypeId, @RequestParam(value = "packageId", required = false) String packageId, @RequestParam(value = "metadataAction", required = false) String metadataAction, @RequestParam(value = "action", required = false) String action, @RequestParam(value = "notify", required = false) Boolean notify) throws URISyntaxException { ImportRun importRun; String filename; try { filename = getFilename(file.getOriginalFilename(), entityTypeId); File tmpFile; try (InputStream inputStream = file.getInputStream()) { tmpFile = fileStore.store(inputStream, filename); } if (packageId != null && !dataService.getMeta().getPackage(packageId).isPresent()) { return ResponseEntity.badRequest() .contentType(TEXT_PLAIN) .body(MessageFormat.format("Package [{0}] does not exist.", packageId)); } importRun = importFile(request, tmpFile, metadataAction, action, notify, packageId); } catch (Exception e) { LOG.error(e.getMessage()); return ResponseEntity.badRequest().contentType(TEXT_PLAIN).body(e.getMessage()); } return createCreatedResponseEntity(importRun); }
ImportWizardController extends AbstractWizardController { @PostMapping("/importFile") public ResponseEntity<String> importFile( HttpServletRequest request, @RequestParam(value = "file") MultipartFile file, @RequestParam(value = "entityTypeId", required = false) String entityTypeId, @RequestParam(value = "packageId", required = false) String packageId, @RequestParam(value = "metadataAction", required = false) String metadataAction, @RequestParam(value = "action", required = false) String action, @RequestParam(value = "notify", required = false) Boolean notify) throws URISyntaxException { ImportRun importRun; String filename; try { filename = getFilename(file.getOriginalFilename(), entityTypeId); File tmpFile; try (InputStream inputStream = file.getInputStream()) { tmpFile = fileStore.store(inputStream, filename); } if (packageId != null && !dataService.getMeta().getPackage(packageId).isPresent()) { return ResponseEntity.badRequest() .contentType(TEXT_PLAIN) .body(MessageFormat.format("Package [{0}] does not exist.", packageId)); } importRun = importFile(request, tmpFile, metadataAction, action, notify, packageId); } catch (Exception e) { LOG.error(e.getMessage()); return ResponseEntity.badRequest().contentType(TEXT_PLAIN).body(e.getMessage()); } return createCreatedResponseEntity(importRun); } }
ImportWizardController extends AbstractWizardController { @PostMapping("/importFile") public ResponseEntity<String> importFile( HttpServletRequest request, @RequestParam(value = "file") MultipartFile file, @RequestParam(value = "entityTypeId", required = false) String entityTypeId, @RequestParam(value = "packageId", required = false) String packageId, @RequestParam(value = "metadataAction", required = false) String metadataAction, @RequestParam(value = "action", required = false) String action, @RequestParam(value = "notify", required = false) Boolean notify) throws URISyntaxException { ImportRun importRun; String filename; try { filename = getFilename(file.getOriginalFilename(), entityTypeId); File tmpFile; try (InputStream inputStream = file.getInputStream()) { tmpFile = fileStore.store(inputStream, filename); } if (packageId != null && !dataService.getMeta().getPackage(packageId).isPresent()) { return ResponseEntity.badRequest() .contentType(TEXT_PLAIN) .body(MessageFormat.format("Package [{0}] does not exist.", packageId)); } importRun = importFile(request, tmpFile, metadataAction, action, notify, packageId); } catch (Exception e) { LOG.error(e.getMessage()); return ResponseEntity.badRequest().contentType(TEXT_PLAIN).body(e.getMessage()); } return createCreatedResponseEntity(importRun); } @Autowired  ImportWizardController(
      UploadWizardPage uploadWizardPage,
      OptionsWizardPage optionsWizardPage,
      PackageWizardPage packageWizardPage,
      ValidationResultWizardPage validationResultWizardPage,
      ImportResultsWizardPage importResultsWizardPage,
      DataService dataService,
      ImportServiceFactory importServiceFactory,
      FileStore fileStore,
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory,
      ImportRunService importRunService);  ImportWizardController(
      UploadWizardPage uploadWizardPage,
      OptionsWizardPage optionsWizardPage,
      PackageWizardPage packageWizardPage,
      ValidationResultWizardPage validationResultWizardPage,
      ImportResultsWizardPage importResultsWizardPage,
      DataService dataService,
      ImportServiceFactory importServiceFactory,
      FileStore fileStore,
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory,
      ImportRunService importRunService,
      ExecutorService executorService); }
ImportWizardController extends AbstractWizardController { @PostMapping("/importFile") public ResponseEntity<String> importFile( HttpServletRequest request, @RequestParam(value = "file") MultipartFile file, @RequestParam(value = "entityTypeId", required = false) String entityTypeId, @RequestParam(value = "packageId", required = false) String packageId, @RequestParam(value = "metadataAction", required = false) String metadataAction, @RequestParam(value = "action", required = false) String action, @RequestParam(value = "notify", required = false) Boolean notify) throws URISyntaxException { ImportRun importRun; String filename; try { filename = getFilename(file.getOriginalFilename(), entityTypeId); File tmpFile; try (InputStream inputStream = file.getInputStream()) { tmpFile = fileStore.store(inputStream, filename); } if (packageId != null && !dataService.getMeta().getPackage(packageId).isPresent()) { return ResponseEntity.badRequest() .contentType(TEXT_PLAIN) .body(MessageFormat.format("Package [{0}] does not exist.", packageId)); } importRun = importFile(request, tmpFile, metadataAction, action, notify, packageId); } catch (Exception e) { LOG.error(e.getMessage()); return ResponseEntity.badRequest().contentType(TEXT_PLAIN).body(e.getMessage()); } return createCreatedResponseEntity(importRun); } @Autowired  ImportWizardController(
      UploadWizardPage uploadWizardPage,
      OptionsWizardPage optionsWizardPage,
      PackageWizardPage packageWizardPage,
      ValidationResultWizardPage validationResultWizardPage,
      ImportResultsWizardPage importResultsWizardPage,
      DataService dataService,
      ImportServiceFactory importServiceFactory,
      FileStore fileStore,
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory,
      ImportRunService importRunService);  ImportWizardController(
      UploadWizardPage uploadWizardPage,
      OptionsWizardPage optionsWizardPage,
      PackageWizardPage packageWizardPage,
      ValidationResultWizardPage validationResultWizardPage,
      ImportResultsWizardPage importResultsWizardPage,
      DataService dataService,
      ImportServiceFactory importServiceFactory,
      FileStore fileStore,
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory,
      ImportRunService importRunService,
      ExecutorService executorService); @SuppressWarnings("javasecurity:S2083") @PostMapping("/importByUrl") @ResponseBody ResponseEntity<String> importFileByUrl(
      HttpServletRequest request,
      @RequestParam("url") String url,
      @RequestParam(value = "entityTypeId", required = false) String entityTypeId,
      @RequestParam(value = "packageId", required = false) String packageId,
      @RequestParam(value = "metadataAction", required = false) String metadataAction,
      @RequestParam(value = "action", required = false) String action,
      @RequestParam(value = "notify", required = false) Boolean notify); @PostMapping("/importFile") ResponseEntity<String> importFile(
      HttpServletRequest request,
      @RequestParam(value = "file") MultipartFile file,
      @RequestParam(value = "entityTypeId", required = false) String entityTypeId,
      @RequestParam(value = "packageId", required = false) String packageId,
      @RequestParam(value = "metadataAction", required = false) String metadataAction,
      @RequestParam(value = "action", required = false) String action,
      @RequestParam(value = "notify", required = false) Boolean notify); static String getUriPath(ImportRun importRun); }
ImportWizardController extends AbstractWizardController { @PostMapping("/importFile") public ResponseEntity<String> importFile( HttpServletRequest request, @RequestParam(value = "file") MultipartFile file, @RequestParam(value = "entityTypeId", required = false) String entityTypeId, @RequestParam(value = "packageId", required = false) String packageId, @RequestParam(value = "metadataAction", required = false) String metadataAction, @RequestParam(value = "action", required = false) String action, @RequestParam(value = "notify", required = false) Boolean notify) throws URISyntaxException { ImportRun importRun; String filename; try { filename = getFilename(file.getOriginalFilename(), entityTypeId); File tmpFile; try (InputStream inputStream = file.getInputStream()) { tmpFile = fileStore.store(inputStream, filename); } if (packageId != null && !dataService.getMeta().getPackage(packageId).isPresent()) { return ResponseEntity.badRequest() .contentType(TEXT_PLAIN) .body(MessageFormat.format("Package [{0}] does not exist.", packageId)); } importRun = importFile(request, tmpFile, metadataAction, action, notify, packageId); } catch (Exception e) { LOG.error(e.getMessage()); return ResponseEntity.badRequest().contentType(TEXT_PLAIN).body(e.getMessage()); } return createCreatedResponseEntity(importRun); } @Autowired  ImportWizardController(
      UploadWizardPage uploadWizardPage,
      OptionsWizardPage optionsWizardPage,
      PackageWizardPage packageWizardPage,
      ValidationResultWizardPage validationResultWizardPage,
      ImportResultsWizardPage importResultsWizardPage,
      DataService dataService,
      ImportServiceFactory importServiceFactory,
      FileStore fileStore,
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory,
      ImportRunService importRunService);  ImportWizardController(
      UploadWizardPage uploadWizardPage,
      OptionsWizardPage optionsWizardPage,
      PackageWizardPage packageWizardPage,
      ValidationResultWizardPage validationResultWizardPage,
      ImportResultsWizardPage importResultsWizardPage,
      DataService dataService,
      ImportServiceFactory importServiceFactory,
      FileStore fileStore,
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory,
      ImportRunService importRunService,
      ExecutorService executorService); @SuppressWarnings("javasecurity:S2083") @PostMapping("/importByUrl") @ResponseBody ResponseEntity<String> importFileByUrl(
      HttpServletRequest request,
      @RequestParam("url") String url,
      @RequestParam(value = "entityTypeId", required = false) String entityTypeId,
      @RequestParam(value = "packageId", required = false) String packageId,
      @RequestParam(value = "metadataAction", required = false) String metadataAction,
      @RequestParam(value = "action", required = false) String action,
      @RequestParam(value = "notify", required = false) Boolean notify); @PostMapping("/importFile") ResponseEntity<String> importFile(
      HttpServletRequest request,
      @RequestParam(value = "file") MultipartFile file,
      @RequestParam(value = "entityTypeId", required = false) String entityTypeId,
      @RequestParam(value = "packageId", required = false) String packageId,
      @RequestParam(value = "metadataAction", required = false) String metadataAction,
      @RequestParam(value = "action", required = false) String action,
      @RequestParam(value = "notify", required = false) Boolean notify); static String getUriPath(ImportRun importRun); static final String ID; static final String URI; }