use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.
the class ZipApi method postZip.
static String postZip(Request request, Response response) throws MolgenisException, IOException, ServletException {
Long start = System.currentTimeMillis();
Schema schema = getSchema(request);
// get uploaded file
File tempFile = File.createTempFile("temp_", ".tmp");
try {
request.attribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement(tempFile.getAbsolutePath()));
try (InputStream input = request.raw().getPart("file").getInputStream()) {
Files.copy(input, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
// depending on file extension use proper importer
String fileName = request.raw().getPart("file").getSubmittedFileName();
if (fileName.endsWith(".zip")) {
if (request.queryParams("async") != null) {
String id = TaskApi.submit(new ImportCsvZipTask(tempFile.toPath(), schema, false));
return new TaskReference(id, schema).toString();
} else {
MolgenisIO.fromZipFile(tempFile.toPath(), schema, false);
}
} else if (fileName.endsWith(".xlsx")) {
MolgenisIO.importFromExcelFile(tempFile.toPath(), schema, false);
} else {
throw new IOException("File upload failed: extension " + fileName.substring(fileName.lastIndexOf('.')) + " not supported");
}
response.status(200);
return "Import success in " + (System.currentTimeMillis() - start) + "ms";
} finally {
if (request.queryParams("async") == null) {
Files.delete(tempFile.toPath());
}
}
}
use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.
the class RunWebApi method main.
public static void main(String[] args) throws IOException {
// create data source
HikariDataSource dataSource = new HikariDataSource();
String url = "jdbc:postgresql:molgenis";
dataSource.setJdbcUrl(url);
dataSource.setUsername("molgenis");
dataSource.setPassword("molgenis");
dataSource.setPassword("molgenis");
// setup
Database db = TestDatabaseFactory.getTestDatabase();
Schema schema = db.dropCreateSchema("pet store");
new PetStoreLoader().load(schema, true);
MolgenisWebservice.start(8080);
}
use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.
the class ExcelApi method postExcel.
static Object postExcel(Request request, Response response) throws IOException, ServletException {
Long start = System.currentTimeMillis();
Schema schema = getSchema(request);
// get uploaded file
File tempFile = File.createTempFile(MolgenisWebservice.TEMPFILES_DELETE_ON_EXIT, ".tmp");
tempFile.deleteOnExit();
request.attribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement(tempFile.getAbsolutePath()));
try (InputStream input = request.raw().getPart("file").getInputStream()) {
Files.copy(input, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
if (request.queryParams("async") != null) {
String id = TaskApi.submit(new ImportExcelTask(tempFile.toPath(), schema, false));
return new TaskReference(id, schema).toString();
} else {
MolgenisIO.importFromExcelFile(tempFile.toPath(), schema, false);
response.status(200);
return "Import success in " + (System.currentTimeMillis() - start) + "ms";
}
}
use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.
the class TestSettingsAndMembersLoading method testExcelTypesCast.
@Test
public void testExcelTypesCast() {
Database database = TestDatabaseFactory.getTestDatabase();
Schema schema = database.dropCreateSchema(TestSettingsAndMembersLoading.class.getSimpleName());
ClassLoader classLoader = getClass().getClassLoader();
Path path = new File(classLoader.getResource("settings_and_members.xlsx").getFile()).toPath();
new ImportExcelTask(path, schema, true).run();
assertEquals("key1", schema.getTable("table1").getMetadata().getSettings().get(0).key());
assertEquals("value1", schema.getTable("table1").getMetadata().getSettings().get(0).value());
assertEquals("key2", schema.getMetadata().getSettings().get(0).key());
assertEquals("value2", schema.getMetadata().getSettings().get(0).value());
assertEquals(1, schema.getMembers().size());
assertEquals("anonymous", schema.getMembers().get(0).getUser());
assertEquals("Viewer", schema.getMembers().get(0).getRole());
database.dropSchema(schema.getName());
}
use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.
the class CatalogueSiteMapTest method buildSiteMap.
@Test
public void buildSiteMap() {
Schema schema = mock(Schema.class);
Table table = mock(Table.class);
Query query = mock(Query.class);
List<Row> row = Collections.singletonList(new Row("pid", "my-cohort-pid"));
when(schema.getTable("Cohorts")).thenReturn(table);
when(table.select(any())).thenReturn(query);
when(query.retrieveRows()).thenReturn(row);
CatalogueSiteMap catalogueSiteMap = new CatalogueSiteMap(schema, "https://my/base/url");
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" >\n" + " <url>\n" + " <loc>https://my/base/url/ssr-catalogue/Cohorts/my-cohort-pid</loc>\n" + " </url>\n" + "</urlset>";
assertEquals(expected, catalogueSiteMap.buildSiteMap());
}
Aggregations