Search in sources :

Example 46 with Schema

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());
        }
    }
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) InputStream(java.io.InputStream) MolgenisWebservice.getSchema(org.molgenis.emx2.web.MolgenisWebservice.getSchema) Schema(org.molgenis.emx2.Schema) IOException(java.io.IOException) ImportCsvZipTask(org.molgenis.emx2.io.ImportCsvZipTask) File(java.io.File)

Example 47 with Schema

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);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) Schema(org.molgenis.emx2.Schema) Database(org.molgenis.emx2.Database) PetStoreLoader(org.molgenis.emx2.datamodels.PetStoreLoader)

Example 48 with Schema

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";
    }
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) ImportExcelTask(org.molgenis.emx2.io.ImportExcelTask) InputStream(java.io.InputStream) MolgenisWebservice.getSchema(org.molgenis.emx2.web.MolgenisWebservice.getSchema) Schema(org.molgenis.emx2.Schema) File(java.io.File)

Example 49 with Schema

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());
}
Also used : Path(java.nio.file.Path) Schema(org.molgenis.emx2.Schema) Database(org.molgenis.emx2.Database) File(java.io.File) Test(org.junit.Test)

Example 50 with Schema

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());
}
Also used : Table(org.molgenis.emx2.Table) Query(org.molgenis.emx2.Query) Schema(org.molgenis.emx2.Schema) Row(org.molgenis.emx2.Row) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)65 Schema (com.google.pubsub.v1.Schema)38 Schema (org.molgenis.emx2.Schema)38 ByteString (com.google.protobuf.ByteString)19 SchemaServiceClient (com.google.cloud.pubsub.v1.SchemaServiceClient)18 AbstractMessage (com.google.protobuf.AbstractMessage)18 QName (javax.xml.namespace.QName)16 SchemaName (com.google.pubsub.v1.SchemaName)15 File (java.io.File)15 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)15 ProjectName (com.google.pubsub.v1.ProjectName)14 IOException (java.io.IOException)14 URL (java.net.URL)14 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)14 StringWriter (java.io.StringWriter)13 Schema (org.oasisopen.odata.csdl.v4.Schema)13 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)12 StatusRuntimeException (io.grpc.StatusRuntimeException)12 Schema (com.reprezen.kaizen.oasparser.model3.Schema)11 JAXBElement (javax.xml.bind.JAXBElement)10