@SuppressWarnings("unchecked") @Test void testHandleRequest() { HttpServletRequest request = mock(HttpServletRequest.class); BindingResult bindingResult = mock(BindingResult.class); ImportWizard wizard = mock(ImportWizard.class); when(wizard.getMetadataImportOption()).thenReturn(UPSERT.toString().toLowerCase()); when(wizard.getDataImportOption()).thenReturn(ADD.toString().toLowerCase()); Map<String, Collection<String>> result = new HashMap<>(); result.put("test", null); when(wizard.getFieldsAvailable()).thenReturn(result); when(wizard.getFieldsDetected()).thenReturn(result); when(wizard.getFieldsRequired()).thenReturn(result); when(wizard.getFieldsUnknown()).thenReturn(result); when(request.getParameter("selectedPackage")).thenReturn("pack1"); packageWizardPage.handleRequest(request, bindingResult, wizard); ArgumentCaptor<HashMap> argumentCaptor1 = ArgumentCaptor.forClass(HashMap.class); verify(wizard).setFieldsAvailable(argumentCaptor1.capture()); assertTrue(argumentCaptor1.getValue().keySet().contains("pack1_test")); ArgumentCaptor<HashMap> argumentCaptor2 = ArgumentCaptor.forClass(HashMap.class); verify(wizard).setFieldsAvailable(argumentCaptor2.capture()); assertTrue(argumentCaptor2.getValue().keySet().contains("pack1_test")); ArgumentCaptor<HashMap> argumentCaptor3 = ArgumentCaptor.forClass(HashMap.class); verify(wizard).setFieldsAvailable(argumentCaptor3.capture()); assertTrue(argumentCaptor3.getValue().keySet().contains("pack1_test")); ArgumentCaptor<HashMap> argumentCaptor4 = ArgumentCaptor.forClass(HashMap.class); verify(wizard).setFieldsAvailable(argumentCaptor4.capture()); assertTrue(argumentCaptor4.getValue().keySet().contains("pack1_test")); }
@Override public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) { ImportWizardUtil.validateImportWizard(wizard); ImportWizard importWizard = (ImportWizard) wizard; String metadataImportOption = importWizard.getMetadataImportOption(); String dataImportOption = importWizard.getDataImportOption(); if (dataImportOption != null) { try { MetadataAction metadataAction = ImportWizardUtil.toMetadataAction(metadataImportOption); if (metadataAction == null) { throw new IOException("unknown metadata action: " + metadataImportOption); } DataAction entityDbAction = ImportWizardUtil.toDataAction(dataImportOption); if (entityDbAction == null) { throw new IOException("unknown data action: " + dataImportOption); } RepositoryCollection repositoryCollection = getFileRepositoryCollectionFactory() .createFileRepositoryCollection(importWizard.getFile()); ImportService importService = getImportServiceFactory() .getImportService(importWizard.getFile(), repositoryCollection); if (metadataAction != MetadataAction.IGNORE && !importWizard.getEntitiesImportable().containsValue(false)) { String selectedPackage = request.getParameter("selectedPackage"); Map<String, Boolean> entitiesImportable = importService.determineImportableEntities( getMetadataService(), repositoryCollection, selectedPackage); updateFieldReports(importWizard, selectedPackage, entitiesImportable); importWizard.setEntitiesImportable(entitiesImportable); List<String> entitiesNotImportable = entitiesImportable.entrySet().stream() .filter(entity -> !entity.getValue()) .map(Map.Entry::getKey) .collect(toList()); if (!entitiesNotImportable.isEmpty()) { throw new MolgenisDataException( "You are trying to upload entities that are not compatible with the already existing entities: " + entitiesNotImportable.toString()); } } } catch (RuntimeException | IOException e) { ImportWizardUtil.handleException(e, importWizard, result, LOG, dataImportOption); } } return null; }
PackageWizardPage extends AbstractWizardPage { @Override public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) { ImportWizardUtil.validateImportWizard(wizard); ImportWizard importWizard = (ImportWizard) wizard; String metadataImportOption = importWizard.getMetadataImportOption(); String dataImportOption = importWizard.getDataImportOption(); if (dataImportOption != null) { try { MetadataAction metadataAction = ImportWizardUtil.toMetadataAction(metadataImportOption); if (metadataAction == null) { throw new IOException("unknown metadata action: " + metadataImportOption); } DataAction entityDbAction = ImportWizardUtil.toDataAction(dataImportOption); if (entityDbAction == null) { throw new IOException("unknown data action: " + dataImportOption); } RepositoryCollection repositoryCollection = getFileRepositoryCollectionFactory() .createFileRepositoryCollection(importWizard.getFile()); ImportService importService = getImportServiceFactory() .getImportService(importWizard.getFile(), repositoryCollection); if (metadataAction != MetadataAction.IGNORE && !importWizard.getEntitiesImportable().containsValue(false)) { String selectedPackage = request.getParameter("selectedPackage"); Map<String, Boolean> entitiesImportable = importService.determineImportableEntities( getMetadataService(), repositoryCollection, selectedPackage); updateFieldReports(importWizard, selectedPackage, entitiesImportable); importWizard.setEntitiesImportable(entitiesImportable); List<String> entitiesNotImportable = entitiesImportable.entrySet().stream() .filter(entity -> !entity.getValue()) .map(Map.Entry::getKey) .collect(toList()); if (!entitiesNotImportable.isEmpty()) { throw new MolgenisDataException( "You are trying to upload entities that are not compatible with the already existing entities: " + entitiesNotImportable.toString()); } } } catch (RuntimeException | IOException e) { ImportWizardUtil.handleException(e, importWizard, result, LOG, dataImportOption); } } return null; } }
PackageWizardPage extends AbstractWizardPage { @Override public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) { ImportWizardUtil.validateImportWizard(wizard); ImportWizard importWizard = (ImportWizard) wizard; String metadataImportOption = importWizard.getMetadataImportOption(); String dataImportOption = importWizard.getDataImportOption(); if (dataImportOption != null) { try { MetadataAction metadataAction = ImportWizardUtil.toMetadataAction(metadataImportOption); if (metadataAction == null) { throw new IOException("unknown metadata action: " + metadataImportOption); } DataAction entityDbAction = ImportWizardUtil.toDataAction(dataImportOption); if (entityDbAction == null) { throw new IOException("unknown data action: " + dataImportOption); } RepositoryCollection repositoryCollection = getFileRepositoryCollectionFactory() .createFileRepositoryCollection(importWizard.getFile()); ImportService importService = getImportServiceFactory() .getImportService(importWizard.getFile(), repositoryCollection); if (metadataAction != MetadataAction.IGNORE && !importWizard.getEntitiesImportable().containsValue(false)) { String selectedPackage = request.getParameter("selectedPackage"); Map<String, Boolean> entitiesImportable = importService.determineImportableEntities( getMetadataService(), repositoryCollection, selectedPackage); updateFieldReports(importWizard, selectedPackage, entitiesImportable); importWizard.setEntitiesImportable(entitiesImportable); List<String> entitiesNotImportable = entitiesImportable.entrySet().stream() .filter(entity -> !entity.getValue()) .map(Map.Entry::getKey) .collect(toList()); if (!entitiesNotImportable.isEmpty()) { throw new MolgenisDataException( "You are trying to upload entities that are not compatible with the already existing entities: " + entitiesNotImportable.toString()); } } } catch (RuntimeException | IOException e) { ImportWizardUtil.handleException(e, importWizard, result, LOG, dataImportOption); } } return null; } PackageWizardPage(
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory,
      ImportServiceFactory importServiceFactory,
      MetaDataService metadataService); }
PackageWizardPage extends AbstractWizardPage { @Override public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) { ImportWizardUtil.validateImportWizard(wizard); ImportWizard importWizard = (ImportWizard) wizard; String metadataImportOption = importWizard.getMetadataImportOption(); String dataImportOption = importWizard.getDataImportOption(); if (dataImportOption != null) { try { MetadataAction metadataAction = ImportWizardUtil.toMetadataAction(metadataImportOption); if (metadataAction == null) { throw new IOException("unknown metadata action: " + metadataImportOption); } DataAction entityDbAction = ImportWizardUtil.toDataAction(dataImportOption); if (entityDbAction == null) { throw new IOException("unknown data action: " + dataImportOption); } RepositoryCollection repositoryCollection = getFileRepositoryCollectionFactory() .createFileRepositoryCollection(importWizard.getFile()); ImportService importService = getImportServiceFactory() .getImportService(importWizard.getFile(), repositoryCollection); if (metadataAction != MetadataAction.IGNORE && !importWizard.getEntitiesImportable().containsValue(false)) { String selectedPackage = request.getParameter("selectedPackage"); Map<String, Boolean> entitiesImportable = importService.determineImportableEntities( getMetadataService(), repositoryCollection, selectedPackage); updateFieldReports(importWizard, selectedPackage, entitiesImportable); importWizard.setEntitiesImportable(entitiesImportable); List<String> entitiesNotImportable = entitiesImportable.entrySet().stream() .filter(entity -> !entity.getValue()) .map(Map.Entry::getKey) .collect(toList()); if (!entitiesNotImportable.isEmpty()) { throw new MolgenisDataException( "You are trying to upload entities that are not compatible with the already existing entities: " + entitiesNotImportable.toString()); } } } catch (RuntimeException | IOException e) { ImportWizardUtil.handleException(e, importWizard, result, LOG, dataImportOption); } } return null; } PackageWizardPage(
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory,
      ImportServiceFactory importServiceFactory,
      MetaDataService metadataService); @Override String getTitle(); @Override String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard); }
PackageWizardPage extends AbstractWizardPage { @Override public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) { ImportWizardUtil.validateImportWizard(wizard); ImportWizard importWizard = (ImportWizard) wizard; String metadataImportOption = importWizard.getMetadataImportOption(); String dataImportOption = importWizard.getDataImportOption(); if (dataImportOption != null) { try { MetadataAction metadataAction = ImportWizardUtil.toMetadataAction(metadataImportOption); if (metadataAction == null) { throw new IOException("unknown metadata action: " + metadataImportOption); } DataAction entityDbAction = ImportWizardUtil.toDataAction(dataImportOption); if (entityDbAction == null) { throw new IOException("unknown data action: " + dataImportOption); } RepositoryCollection repositoryCollection = getFileRepositoryCollectionFactory() .createFileRepositoryCollection(importWizard.getFile()); ImportService importService = getImportServiceFactory() .getImportService(importWizard.getFile(), repositoryCollection); if (metadataAction != MetadataAction.IGNORE && !importWizard.getEntitiesImportable().containsValue(false)) { String selectedPackage = request.getParameter("selectedPackage"); Map<String, Boolean> entitiesImportable = importService.determineImportableEntities( getMetadataService(), repositoryCollection, selectedPackage); updateFieldReports(importWizard, selectedPackage, entitiesImportable); importWizard.setEntitiesImportable(entitiesImportable); List<String> entitiesNotImportable = entitiesImportable.entrySet().stream() .filter(entity -> !entity.getValue()) .map(Map.Entry::getKey) .collect(toList()); if (!entitiesNotImportable.isEmpty()) { throw new MolgenisDataException( "You are trying to upload entities that are not compatible with the already existing entities: " + entitiesNotImportable.toString()); } } } catch (RuntimeException | IOException e) { ImportWizardUtil.handleException(e, importWizard, result, LOG, dataImportOption); } } return null; } PackageWizardPage(
      FileRepositoryCollectionFactory fileRepositoryCollectionFactory,
      ImportServiceFactory importServiceFactory,
      MetaDataService metadataService); @Override String getTitle(); @Override String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard);  }