Search in sources :

Example 11 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

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);
}
Also used : Table(com.google.privacy.dlp.v2.Table)

Example 12 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

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);
}
Also used : Table(com.google.privacy.dlp.v2.Table)

Example 13 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

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

Example 14 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

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();
}
Also used : EvaluateExpressions.checkValidation(org.molgenis.emx2.sql.EvaluateExpressions.checkValidation) java.util(java.util) DSL(org.jooq.impl.DSL) Logger(org.slf4j.Logger) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) Constants(org.molgenis.emx2.Constants) org.molgenis.emx2(org.molgenis.emx2) Collectors(java.util.stream.Collectors) EvaluateExpressions.checkForMissingVariablesColumns(org.molgenis.emx2.sql.EvaluateExpressions.checkForMissingVariablesColumns) ADMIN_USER(org.molgenis.emx2.sql.SqlDatabase.ADMIN_USER) Query(org.molgenis.emx2.Query) MutationType(org.molgenis.emx2.MutationType) StringReader(java.io.StringReader) Table(org.molgenis.emx2.Table) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) org.jooq(org.jooq) Writer(java.io.Writer) BaseConnection(org.postgresql.core.BaseConnection) CopyManager(org.postgresql.copy.CopyManager) SqlTypeUtils.getTypedValue(org.molgenis.emx2.sql.SqlTypeUtils.getTypedValue) Row(org.molgenis.emx2.Row) LocalDateTime(java.time.LocalDateTime) Row(org.molgenis.emx2.Row)

Example 15 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

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);
        }
    }
}
Also used : Path(java.nio.file.Path) MolgenisWebservice.getTable(org.molgenis.emx2.web.MolgenisWebservice.getTable) Table(org.molgenis.emx2.Table) OutputStream(java.io.OutputStream) MolgenisException(org.molgenis.emx2.MolgenisException) File(java.io.File)

Aggregations

Test (org.junit.Test)40 Table (com.google.privacy.dlp.v2.Table)23 Table (org.molgenis.emx2.Table)23 Table (com.google.bigtable.admin.v2.Table)21 ByteString (com.google.protobuf.ByteString)18 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)17 ArrayList (java.util.ArrayList)14 AbstractMessage (com.google.protobuf.AbstractMessage)13 HashMap (java.util.HashMap)13 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)11 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)10 Row (org.molgenis.emx2.Row)10 IOException (java.io.IOException)9 List (java.util.List)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum)7 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)6