use of org.molgenis.emx2.io.tablestore.TableStore in project molgenis-emx2 by molgenis.
the class TestEmx2Roles method testRolesIO.
@Test
public void testRolesIO() {
// create user roles
schema.addMember("bofke", "Viewer");
TableStore store = new TableStoreForCsvInMemory();
// export
Emx2Members.outputRoles(store, schema);
// empty the database, verify
schema = schema.getDatabase().dropCreateSchema(TestEmx2Roles.class.getSimpleName());
assertEquals(0, schema.getMembers().size());
// import and see if consistent
Emx2Members.inputRoles(store, schema);
List<Member> members = schema.getMembers();
assertEquals("bofke", members.get(0).getUser());
assertEquals("Viewer", members.get(0).getRole());
}
use of org.molgenis.emx2.io.tablestore.TableStore in project molgenis-emx2 by molgenis.
the class TestReadWriteStores method executeTest.
public static void executeTest(TableStore store) throws IOException, MolgenisException {
List<Row> rows = new ArrayList<>();
int count = 10;
for (int i = 1; i <= count; i++) {
rows.add(new Row().setString("stringCol", "test" + i).setInt("intCol", i).setDecimal("decimalCol", Double.valueOf(i / 2)).setUuid("uuidCol", UUID.randomUUID()).setDate("dateCol", LocalDate.of(2019, 12, 12)).setDateTime("datetimeCol", LocalDateTime.now()).setBool("boolCol", true).setStringArray("stringarrayCol", new String[] { "a", "b,including comma," }).setIntArray("intarrayCol", new Integer[] { 1, 2 }).setDecimalArray("doubleArrayCol", new Double[] { 1.0, 2.0 }).setDecimalArray("doubleArrayCol", new Double[] { 1.0, 2.0 }).setDateArray("dateArray", new LocalDate[] { LocalDate.of(2019, 12, 12), LocalDate.of(2019, 12, 12) }).setDateTimeArray("datetimeArrayCol", new LocalDateTime[] { LocalDateTime.now(), LocalDateTime.now() }).setBoolArray("booleanArrayCol", new Boolean[] { true, false }));
}
StopWatch.start("created some rows");
// write them
store.writeTable("test", List.of(), rows);
store.writeTable("test2", List.of(), rows);
StopWatch.print("wrote them to " + store.getClass().getSimpleName(), count);
List<Row> rows2 = StreamSupport.stream(store.readTable("test2").spliterator(), false).collect(Collectors.toList());
// for (Row r : rows2) System.out.println(r);
StopWatch.print("fromReader them back from " + store.getClass().getSimpleName(), count);
// compare
CompareTools.assertEquals(rows, rows2);
// write another one
store.writeTable("test3", List.of(), rows);
StopWatch.print("wrote them to " + store.getClass().getSimpleName(), count);
rows2 = StreamSupport.stream(store.readTable("test3").spliterator(), false).collect(Collectors.toList());
// for (Row r : rows2) System.out.println(r);
StopWatch.print("fromReader them back from " + store.getClass().getSimpleName(), count);
// compare
CompareTools.assertEquals(rows, rows2);
StopWatch.print("compared succesfully");
// write empty
store.writeTable("test4", List.of("empty"), new ArrayList<>());
// test that reading store that doesn't exist errors properly
try {
store.readTable("fake");
fail("should have failed");
} catch (MolgenisException me) {
System.out.println("errored correctly:" + me);
}
}
use of org.molgenis.emx2.io.tablestore.TableStore in project molgenis-emx2 by molgenis.
the class TestColumnTypeIsFile method testCsvShouldNotIncludeFileColumns.
@Test
public void testCsvShouldNotIncludeFileColumns() throws IOException {
Path tmp = Files.createTempDirectory(null);
Path csvFile = tmp.resolve("User.csv");
MolgenisIO.toExcelFile(csvFile, schema.getTable("User"));
TableStore store = new TableStoreForCsvFile(csvFile);
assertFalse(store.readTable("User").iterator().next().getColumnNames().contains("picture"));
}
use of org.molgenis.emx2.io.tablestore.TableStore in project molgenis-emx2 by molgenis.
the class TestTypesImport method testTsvTypeCast.
@Test
public void testTsvTypeCast() {
ClassLoader classLoader = getClass().getClassLoader();
Path path = new File(classLoader.getResource("TypeTest.tsv").getFile()).toPath();
TableStore store = new TableStoreForCsvFile(path);
for (Row r : store.readTable("Sheet1")) {
assertEquals("1", r.getString("column1"));
assertEquals("2", r.getString("column2"));
}
}
use of org.molgenis.emx2.io.tablestore.TableStore in project molgenis-emx2 by molgenis.
the class Emx1 method loadColumns.
private static List<Emx1Attribute> loadColumns(TableStore store, Map<String, Emx1Entity> entities, SchemaMetadata schema) {
// line 1 is header
int line = 2;
List<Emx1Attribute> attributes = new ArrayList<>();
try {
if (store.containsTable("attributes")) {
for (Row row : store.readTable("attributes")) {
attributes.add(new Emx1Attribute(row));
line++;
}
}
// line 1 is header
line = 2;
for (Emx1Attribute attribute : attributes) {
// create the table, if needed
String entityName = attribute.getEntity();
String tableName = getTableName(entities, entityName);
TableMetadata table = schema.getTableMetadata(tableName);
if (table == null) {
table = schema.create(table(tableName));
}
// create the attribute
ColumnType type = getColumnType(attribute.getDataType());
Column column = column(attribute.getName()).setType(type).setRequired(!attribute.getNillable());
// pkey
if (attribute.getIdAttribute()) {
column.setKey(1);
}
table.add(column);
line++;
}
} catch (MolgenisException me) {
throw new MolgenisException(EMX_1_IMPORT_FAILED + me.getMessage() + ". See 'attributes' line " + line, me);
}
return attributes;
}
Aggregations