use of org.molgenis.oneclickimporter.model.DataCollection in project molgenis by molgenis.
the class OneClickImporterServiceImpl method buildDataCollectionsFromExcel.
@Override
public List<DataCollection> buildDataCollectionsFromExcel(List<Sheet> sheets) {
List<DataCollection> dataCollections = newArrayList();
sheets.forEach(sheet -> {
List<Column> columns = newArrayList();
Row headerRow = sheet.getRow(0);
headerRow.cellIterator().forEachRemaining(cell -> columns.add(createColumnFromCell(sheet, cell)));
dataCollections.add(DataCollection.create(sheet.getSheetName(), columns));
});
return dataCollections;
}
use of org.molgenis.oneclickimporter.model.DataCollection in project molgenis by molgenis.
the class OneClickImportJobTest method testGetEntityTypeWithZip.
@Test
public void testGetEntityTypeWithZip() throws InvalidFormatException, IOException, URISyntaxException, UnknownFileTypeException, EmptySheetException {
Progress progress = mock(Progress.class);
String filename = "simple-valid.zip";
when(oneClickImporterNamingService.createValidIdFromFileName(filename)).thenReturn("simple_valid");
File file = loadFile(OneClickImportJobTest.class, "/" + filename);
when(fileStore.getFile(filename)).thenReturn(file);
File zipFile1 = loadFile(OneClickImportJobTest.class, "/zip_file_1.csv");
when(oneClickImporterNamingService.createValidIdFromFileName("zip_file_1.csv")).thenReturn("zip_file_1");
File zipFile2 = loadFile(OneClickImportJobTest.class, "/zip_file_2.csv");
when(oneClickImporterNamingService.createValidIdFromFileName("zip_file_2.csv")).thenReturn("zip_file_2");
File zipFile3 = loadFile(OneClickImportJobTest.class, "/zip_file_3.csv");
when(oneClickImporterNamingService.createValidIdFromFileName("zip_file_3.csv")).thenReturn("zip_file_3");
File zipFile4 = loadFile(OneClickImportJobTest.class, "/zip_file_4.csv");
when(oneClickImporterNamingService.createValidIdFromFileName("zip_file_4.csv")).thenReturn("zip_file_4");
List<String[]> lines1 = new ArrayList<>();
lines1.add(new String[] { "name,age", "piet,25" });
when(csvService.buildLinesFromFile(zipFile1)).thenReturn(lines1);
List<String[]> lines2 = new ArrayList<>();
lines2.add(new String[] { "name,age", "klaas,30" });
when(csvService.buildLinesFromFile(zipFile2)).thenReturn(lines2);
List<String[]> lines3 = new ArrayList<>();
lines3.add(new String[] { "name,age", "Jan,35" });
when(csvService.buildLinesFromFile(zipFile3)).thenReturn(lines3);
List<String[]> lines4 = new ArrayList<>();
lines4.add(new String[] { "name,age", "Henk,40" });
when(csvService.buildLinesFromFile(zipFile4)).thenReturn(lines4);
DataCollection dataCollection1 = mock(DataCollection.class);
when(dataCollection1.getName()).thenReturn("zip_file_1");
when(oneClickImporterService.buildDataCollectionFromCsv("zip_file_1", lines1)).thenReturn(dataCollection1);
DataCollection dataCollection2 = mock(DataCollection.class);
when(dataCollection2.getName()).thenReturn("zip_file_2");
when(oneClickImporterService.buildDataCollectionFromCsv("zip_file_2", lines2)).thenReturn(dataCollection2);
DataCollection dataCollection3 = mock(DataCollection.class);
when(dataCollection3.getName()).thenReturn("zip_file_3");
when(oneClickImporterService.buildDataCollectionFromCsv("zip_file_3", lines3)).thenReturn(dataCollection3);
DataCollection dataCollection4 = mock(DataCollection.class);
when(dataCollection4.getName()).thenReturn("zip_file_4");
when(oneClickImporterService.buildDataCollectionFromCsv("zip_file_4", lines4)).thenReturn(dataCollection4);
EntityType entityType1 = mock(EntityType.class);
when(entityService.createEntityType(dataCollection1, "simple_valid")).thenReturn(entityType1);
EntityType entityType2 = mock(EntityType.class);
when(entityService.createEntityType(dataCollection2, "simple_valid")).thenReturn(entityType2);
EntityType entityType3 = mock(EntityType.class);
when(entityService.createEntityType(dataCollection3, "simple_valid")).thenReturn(entityType3);
EntityType entityType4 = mock(EntityType.class);
when(entityService.createEntityType(dataCollection4, "simple_valid")).thenReturn(entityType4);
oneClickImporterJob = new OneClickImportJob(excelService, csvService, oneClickImporterService, oneClickImporterNamingService, entityService, fileStore);
oneClickImporterJob.getEntityType(progress, filename);
verify(progress).status("Preparing import");
verify(csvService).buildLinesFromFile(zipFile1);
verify(oneClickImporterService).buildDataCollectionFromCsv("zip_file_1", lines1);
verify(csvService).buildLinesFromFile(zipFile2);
verify(oneClickImporterService).buildDataCollectionFromCsv("zip_file_2", lines2);
verify(csvService).buildLinesFromFile(zipFile3);
verify(oneClickImporterService).buildDataCollectionFromCsv("zip_file_3", lines3);
verify(csvService).buildLinesFromFile(zipFile4);
verify(oneClickImporterService).buildDataCollectionFromCsv("zip_file_4", lines4);
verify(progress).status("Importing [zip_file_1] into package [simple_valid]");
verify(entityService).createEntityType(dataCollection1, "simple_valid");
verify(progress).status("Importing [zip_file_2] into package [simple_valid]");
verify(entityService).createEntityType(dataCollection2, "simple_valid");
verify(progress).status("Importing [zip_file_3] into package [simple_valid]");
verify(entityService).createEntityType(dataCollection3, "simple_valid");
verify(progress).status("Importing [zip_file_4] into package [simple_valid]");
verify(entityService).createEntityType(dataCollection4, "simple_valid");
}
use of org.molgenis.oneclickimporter.model.DataCollection in project molgenis by molgenis.
the class OneClickImportJobTest method testGetEntityTypeWithExcel.
@Test
public void testGetEntityTypeWithExcel() throws InvalidFormatException, IOException, URISyntaxException, UnknownFileTypeException, EmptySheetException {
Progress progress = mock(Progress.class);
String filename = "simple-valid.xlsx";
when(oneClickImporterNamingService.createValidIdFromFileName(filename)).thenReturn("simple_valid");
File file = loadFile(OneClickImportJobTest.class, "/" + filename);
when(fileStore.getFile(filename)).thenReturn(file);
List<Sheet> sheets = new ArrayList<>();
when(excelService.buildExcelSheetsFromFile(file)).thenReturn(sheets);
DataCollection dataCollection = mock(DataCollection.class);
when(dataCollection.getName()).thenReturn("Sheet1");
when(oneClickImporterService.buildDataCollectionsFromExcel(sheets)).thenReturn(newArrayList(dataCollection));
EntityType entityType = mock(EntityType.class);
when(entityService.createEntityType(dataCollection, "simple_valid")).thenReturn(entityType);
oneClickImporterJob = new OneClickImportJob(excelService, csvService, oneClickImporterService, oneClickImporterNamingService, entityService, fileStore);
oneClickImporterJob.getEntityType(progress, filename);
verify(progress).status("Preparing import");
verify(excelService).buildExcelSheetsFromFile(file);
verify(oneClickImporterService).buildDataCollectionsFromExcel(sheets);
verify(progress).status("Importing [Sheet1] into package [simple_valid]");
verify(entityService).createEntityType(dataCollection, "simple_valid");
}
use of org.molgenis.oneclickimporter.model.DataCollection in project molgenis by molgenis.
the class OneClickImporterServiceTest method testBuildDataSheetBuildsColumnsOfEqualLength.
@Test
public void testBuildDataSheetBuildsColumnsOfEqualLength() throws IOException, InvalidFormatException, URISyntaxException, EmptySheetException {
List<Sheet> sheets = loadSheetFromFile(OneClickImporterServiceTest.class, "/valid-with-blank-values.xlsx");
DataCollection actual = oneClickImporterService.buildDataCollectionsFromExcel(sheets).get(0);
Column c1 = Column.create("name", 0, newArrayList("Mark", "Bart", "Tommy", "Sido", "Connor", null));
Column c2 = Column.create("favorite food", 1, newArrayList("Fries", null, "Vegan food", "Pizza", null, "Spinache"));
DataCollection expected = DataCollection.create("Sheet1", newArrayList(c1, c2));
assertEquals(actual, expected);
assertEquals(6, c1.getDataValues().size());
assertEquals(6, c2.getDataValues().size());
}
use of org.molgenis.oneclickimporter.model.DataCollection in project molgenis by molgenis.
the class OneClickImporterServiceTest method testBuildDataSheetWithDates.
@Test
public void testBuildDataSheetWithDates() throws IOException, InvalidFormatException, URISyntaxException, EmptySheetException {
List<Sheet> sheets = loadSheetFromFile(OneClickImporterServiceTest.class, "/valid-with-dates.xlsx");
DataCollection actual = oneClickImporterService.buildDataCollectionsFromExcel(sheets).get(0);
Column c1 = Column.create("dates", 0, newArrayList("2018-01-03T00:00", "2018-01-04T00:00", "2018-01-05T00:00", "2018-01-06T00:00", "2018-01-07T00:00"));
Column c2 = Column.create("event", 1, newArrayList("being cool day", "bike day", "sleep day", "bye bye day", "work day"));
DataCollection expected = DataCollection.create("Sheet1", newArrayList(c1, c2));
assertEquals(actual, expected);
}
Aggregations