use of com.reprezen.kaizen.oasparser.model3.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.reprezen.kaizen.oasparser.model3.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.reprezen.kaizen.oasparser.model3.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.reprezen.kaizen.oasparser.model3.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());
}
use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.
the class MolgenisSession method getGraphqlForSchema.
public GraphQL getGraphqlForSchema(String schemaName) {
logger.info("getting graphql schema '{}' for user '{}'", schemaName, getSessionUser());
if (graphqlPerSchema.get(schemaName) == null) {
Schema schema = database.getSchema(schemaName);
if (schema == null)
throw new MolgenisException("Schema not found: Schema with name '" + schemaName + "' does not exist or permission denied");
graphqlPerSchema.put(schemaName, new GraphqlApiFactory().createGraphqlForSchema(schema, TaskApi.taskService));
logger.info("created graphql schema '{}' for user '{}'", schemaName, getSessionUser());
}
logger.info("return graphql schema '{}' for user '{}'", schemaName, getSessionUser());
return graphqlPerSchema.get(schemaName);
}
Aggregations