use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project java-dlp by googleapis.
the class DeIdentifyTableConditionMasking method deIdentifyTableConditionMasking.
public static void deIdentifyTableConditionMasking() throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
Table tableToDeIdentify = Table.newBuilder().addHeaders(FieldId.newBuilder().setName("AGE").build()).addHeaders(FieldId.newBuilder().setName("PATIENT").build()).addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build()).addRows(Row.newBuilder().addValues(Value.newBuilder().setStringValue("101").build()).addValues(Value.newBuilder().setStringValue("Charles Dickens").build()).addValues(Value.newBuilder().setStringValue("95").build()).build()).addRows(Row.newBuilder().addValues(Value.newBuilder().setStringValue("22").build()).addValues(Value.newBuilder().setStringValue("Jane Austen").build()).addValues(Value.newBuilder().setStringValue("21").build()).build()).addRows(Row.newBuilder().addValues(Value.newBuilder().setStringValue("55").build()).addValues(Value.newBuilder().setStringValue("Mark Twain").build()).addValues(Value.newBuilder().setStringValue("75").build()).build()).build();
deIdentifyTableConditionMasking(projectId, tableToDeIdentify);
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project java-dlp by googleapis.
the class DeIdentifyTableInfoTypes method deIdentifyTableInfoTypes.
public static void deIdentifyTableInfoTypes() throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
Table tableToDeIdentify = Table.newBuilder().addHeaders(FieldId.newBuilder().setName("AGE").build()).addHeaders(FieldId.newBuilder().setName("PATIENT").build()).addHeaders(FieldId.newBuilder().setName("HAPPINESS SCORE").build()).addHeaders(FieldId.newBuilder().setName("FACTOID").build()).addRows(Row.newBuilder().addValues(Value.newBuilder().setStringValue("101").build()).addValues(Value.newBuilder().setStringValue("Charles Dickens").build()).addValues(Value.newBuilder().setStringValue("95").build()).addValues(Value.newBuilder().setStringValue("Charles Dickens name was a curse invented by Shakespeare.").build()).build()).addRows(Row.newBuilder().addValues(Value.newBuilder().setStringValue("22").build()).addValues(Value.newBuilder().setStringValue("Jane Austen").build()).addValues(Value.newBuilder().setStringValue("21").build()).addValues(Value.newBuilder().setStringValue("There are 14 kisses in Jane Austen's novels.").build()).build()).addRows(Row.newBuilder().addValues(Value.newBuilder().setStringValue("55").build()).addValues(Value.newBuilder().setStringValue("Mark Twain").build()).addValues(Value.newBuilder().setStringValue("75").build()).addValues(Value.newBuilder().setStringValue("Mark Twain loved cats.").build()).build()).build();
deIdentifyTableInfoTypes(projectId, tableToDeIdentify);
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.
the class ImportDataTask method run.
@Override
public void run() {
this.start();
// create a task for each table
boolean skipped = true;
// create task for the import, including subtasks for each sheet
for (Table table : schema.getTablesSorted()) {
if (tableStore.containsTable(table.getName())) {
ImportTableTask importTableTask = new ImportTableTask(tableStore, table, isStrict());
this.addSubTask(importTableTask);
importTableTask.run();
skipped = false;
}
}
// check what files we skipped
Collection<String> tableNames = schema.getTableNames();
try {
for (String sheet : tableStore.tableNames()) {
if (!sheet.startsWith("_files/") && !"molgenis".equals(sheet) && !"molgenis_settings".equals(sheet) && !"molgenis_members".equals(sheet) && !tableNames.contains(sheet)) {
this.addSubTask("Sheet with name '" + sheet + "' was skipped: no table with that name found").setSkipped();
}
}
} catch (UnsupportedOperationException e) {
// ignore, not important
}
// execute the import tasks
if (skipped) {
this.addSubTask("Import data skipped: No data sheet included").setSkipped();
}
this.complete();
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.
the class SqlTable method insertBatch.
private static int insertBatch(SqlTable table, List<Row> rows, boolean updateOnConflict, Set<String> updateColumns) {
boolean inherit = table.getMetadata().getInherit() != null;
if (inherit) {
SqlTable inheritedTable = table.getInheritedTable();
inheritedTable.insertBatch(inheritedTable, rows, updateOnConflict, updateColumns);
}
// get metadata
Set<Column> columns = table.getColumnsToBeUpdated(updateColumns);
// check that columns exist for validation
checkForMissingVariablesColumns(columns);
List<Column> allColumns = table.getMetadata().getMutationColumns();
List<Field> insertFields = columns.stream().map(c -> c.getJooqField()).collect(Collectors.toList());
if (!inherit) {
insertFields.add(field(name(MG_INSERTEDBY)));
insertFields.add(field(name(MG_INSERTEDON)));
insertFields.add(field(name(MG_UPDATEDBY)));
insertFields.add(field(name(MG_UPDATEDON)));
}
// define the insert step
InsertValuesStepN<org.jooq.Record> step = table.getJooq().insertInto(table.getJooqTable(), insertFields.toArray(new Field[0]));
// add all the rows as steps
String user = table.getSchema().getDatabase().getActiveUser();
if (user == null) {
user = ADMIN_USER;
}
LocalDateTime now = LocalDateTime.now();
for (Row row : rows) {
// get values
Map values = SqlTypeUtils.getValuesAsMap(row, columns);
if (!inherit) {
values.put(MG_INSERTEDBY, user);
values.put(MG_INSERTEDON, now);
values.put(MG_UPDATEDBY, user);
values.put(MG_UPDATEDON, now);
}
// when insert, we should include all columns, not only 'updateColumns'
if (!row.isDraft()) {
checkRequired(row, allColumns);
checkValidation(values, columns);
}
step.values(values.values());
}
// optionally, add conflict clause
if (updateOnConflict) {
InsertOnDuplicateSetStep<org.jooq.Record> step2 = step.onConflict(table.getMetadata().getPrimaryKeyFields().toArray(new Field[0])).doUpdate();
for (Column column : columns) {
step2.set(column.getJooqField(), (Object) field(unquotedName("excluded.\"" + column.getName() + "\"")));
}
if (!inherit) {
step2.set(field(name(MG_UPDATEDBY)), user);
step2.set(field(name(MG_UPDATEDON)), now);
}
}
return step.execute();
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.
the class ZipApi method getZipTable.
static String getZipTable(Request request, Response response) throws IOException {
Table table = getTable(request);
if (table == null)
throw new MolgenisException("Table " + request.params(TABLE) + " unknown");
Path tempDir = Files.createTempDirectory(MolgenisWebservice.TEMPFILES_DELETE_ON_EXIT);
tempDir.toFile().deleteOnExit();
try (OutputStream outputStream = response.raw().getOutputStream()) {
Path zipFile = tempDir.resolve("download.zip");
MolgenisIO.toZipFile(zipFile, table);
outputStream.write(Files.readAllBytes(zipFile));
response.type("application/zip");
response.header("Content-Disposition", "attachment; filename=" + table.getSchema().getMetadata().getName() + "_" + table.getName() + System.currentTimeMillis() + ".zip");
return "Export success";
} finally {
try (Stream<Path> files = Files.walk(tempDir)) {
files.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
}
}
Aggregations