@Test void testHandleRequestNoFileSelected() { HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); BindingResult bindingResult = mock(BindingResult.class); ImportWizard wizard = mock(ImportWizard.class); assertNull(uploadWizardPage.handleRequest(httpServletRequest, bindingResult, wizard)); verify(bindingResult).addError(new ObjectError("wizard", "No file selected")); }
@Override public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) { ImportWizardUtil.validateImportWizard(wizard); ImportWizard importWizard = (ImportWizard) wizard; String dataImportOption = request.getParameter("data-option"); try { File file = null; Part part = request.getPart("upload"); if (part != null) { file = FileUploadUtils.saveToTempFolder(part); } if (file == null) { result.addError(new ObjectError("wizard", "No file selected")); } else { importWizard.setFile(file); RepositoryCollection repositoryCollection = getFileRepositoryCollectionFactory().createFileRepositoryCollection(file); ImportService importService = getImportServiceFactory().getImportService(file, repositoryCollection); importWizard.setSupportedMetadataActions(importService.getSupportedMetadataActions()); importWizard.setSupportedDataActions(importService.getSupportedDataActions()); importWizard.setMustChangeEntityName(importService.getMustChangeEntityName()); } } catch (Exception e) { ImportWizardUtil.handleException(e, importWizard, result, LOG, dataImportOption); } return null; }
UploadWizardPage extends AbstractWizardPage { @Override public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) { ImportWizardUtil.validateImportWizard(wizard); ImportWizard importWizard = (ImportWizard) wizard; String dataImportOption = request.getParameter("data-option"); try { File file = null; Part part = request.getPart("upload"); if (part != null) { file = FileUploadUtils.saveToTempFolder(part); } if (file == null) { result.addError(new ObjectError("wizard", "No file selected")); } else { importWizard.setFile(file); RepositoryCollection repositoryCollection = getFileRepositoryCollectionFactory().createFileRepositoryCollection(file); ImportService importService = getImportServiceFactory().getImportService(file, repositoryCollection); importWizard.setSupportedMetadataActions(importService.getSupportedMetadataActions()); importWizard.setSupportedDataActions(importService.getSupportedDataActions()); importWizard.setMustChangeEntityName(importService.getMustChangeEntityName()); } } catch (Exception e) { ImportWizardUtil.handleException(e, importWizard, result, LOG, dataImportOption); } return null; } }
UploadWizardPage extends AbstractWizardPage { @Override public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) { ImportWizardUtil.validateImportWizard(wizard); ImportWizard importWizard = (ImportWizard) wizard; String dataImportOption = request.getParameter("data-option"); try { File file = null; Part part = request.getPart("upload"); if (part != null) { file = FileUploadUtils.saveToTempFolder(part); } if (file == null) { result.addError(new ObjectError("wizard", "No file selected")); } else { importWizard.setFile(file); RepositoryCollection repositoryCollection = getFileRepositoryCollectionFactory().createFileRepositoryCollection(file); ImportService importService = getImportServiceFactory().getImportService(file, repositoryCollection); importWizard.setSupportedMetadataActions(importService.getSupportedMetadataActions()); importWizard.setSupportedDataActions(importService.getSupportedDataActions()); importWizard.setMustChangeEntityName(importService.getMustChangeEntityName()); } } catch (Exception e) { ImportWizardUtil.handleException(e, importWizard, result, LOG, dataImportOption); } return null; } UploadWizardPage(
      ImportServiceFactory importServiceFactory,
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory); }
UploadWizardPage extends AbstractWizardPage { @Override public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) { ImportWizardUtil.validateImportWizard(wizard); ImportWizard importWizard = (ImportWizard) wizard; String dataImportOption = request.getParameter("data-option"); try { File file = null; Part part = request.getPart("upload"); if (part != null) { file = FileUploadUtils.saveToTempFolder(part); } if (file == null) { result.addError(new ObjectError("wizard", "No file selected")); } else { importWizard.setFile(file); RepositoryCollection repositoryCollection = getFileRepositoryCollectionFactory().createFileRepositoryCollection(file); ImportService importService = getImportServiceFactory().getImportService(file, repositoryCollection); importWizard.setSupportedMetadataActions(importService.getSupportedMetadataActions()); importWizard.setSupportedDataActions(importService.getSupportedDataActions()); importWizard.setMustChangeEntityName(importService.getMustChangeEntityName()); } } catch (Exception e) { ImportWizardUtil.handleException(e, importWizard, result, LOG, dataImportOption); } return null; } UploadWizardPage(
      ImportServiceFactory importServiceFactory,
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory); @Override String getTitle(); @Override String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard); }
UploadWizardPage extends AbstractWizardPage { @Override public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) { ImportWizardUtil.validateImportWizard(wizard); ImportWizard importWizard = (ImportWizard) wizard; String dataImportOption = request.getParameter("data-option"); try { File file = null; Part part = request.getPart("upload"); if (part != null) { file = FileUploadUtils.saveToTempFolder(part); } if (file == null) { result.addError(new ObjectError("wizard", "No file selected")); } else { importWizard.setFile(file); RepositoryCollection repositoryCollection = getFileRepositoryCollectionFactory().createFileRepositoryCollection(file); ImportService importService = getImportServiceFactory().getImportService(file, repositoryCollection); importWizard.setSupportedMetadataActions(importService.getSupportedMetadataActions()); importWizard.setSupportedDataActions(importService.getSupportedDataActions()); importWizard.setMustChangeEntityName(importService.getMustChangeEntityName()); } } catch (Exception e) { ImportWizardUtil.handleException(e, importWizard, result, LOG, dataImportOption); } return null; } UploadWizardPage(
      ImportServiceFactory importServiceFactory,
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory); @Override String getTitle(); @Override String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard);  }