Search in sources :

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

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project bootique-jdbc by bootique.

the class PostgresBQApp method test2.

// end::getDataSource[]
@Test
public void test2() {
    // tag::getTable[]
    Table myTable = tester.getTable("my_table");
    // end::getTable[]
    // tag::delete[]
    // delete table contents
    myTable.deleteAll();
    // end::delete[]
    // tag::insert[]
    // insert test data
    myTable.insertColumns("id", "c1").values(1, "x1").values(2, "x2").exec();
    // end::insert[]
    // tag::assertOneMatch[]
    // check that data matches expectations
    myTable.matcher().eq("c1", "x1").assertOneMatch();
// end::assertOneMatch[]
}
Also used : Table(io.bootique.jdbc.junit5.Table) Test(org.junit.jupiter.api.Test) BQTest(io.bootique.junit5.BQTest)

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

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project BibleMultiConverter by schierlm.

the class USX3 method doImportBook.

@Override
protected ParatextBook doImportBook(File inputFile) throws Exception {
    if (!inputFile.getName().toLowerCase().endsWith(".usx"))
        return null;
    ValidateXML.validateFileBeforeParsing(getSchema(), inputFile);
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
    XMLInputFactory xif = XMLInputFactory.newFactory();
    XMLStreamReader xsr = xif.createXMLStreamReader(new FileInputStream(inputFile));
    Unmarshaller u = ctx.createUnmarshaller();
    u.setListener(unmarshallerLocationListener);
    unmarshallerLocationListener.setXMLStreamReader(inputFile.getName(), xsr);
    Usx doc = (Usx) u.unmarshal(xsr);
    xsr.close();
    ParatextBook.ParatextID id = ParatextBook.ParatextID.fromIdentifier(doc.getBook().getCode().toUpperCase());
    if (id == null) {
        System.out.println("WARNING: Skipping book with unknown ID: " + doc.getBook().getCode());
        return null;
    }
    ParatextBook result = new ParatextBook(id, doc.getBook().getContent());
    ParatextCharacterContent charContent = null;
    for (Object o : doc.getParaOrTableOrChapter()) {
        if (o instanceof Para) {
            Para para = (Para) o;
            if (BOOK_HEADER_ATTRIBUTE_TAGS.contains(para.getStyle().value())) {
                String value = "";
                for (Object oo : para.getContent()) {
                    if (oo instanceof String) {
                        value += ((String) oo).replaceAll("[ \r\n\t]+", " ");
                    } else {
                        throw new RuntimeException("Unsupported content in attribute: " + oo.getClass());
                    }
                }
                result.getAttributes().put(para.getStyle().value(), value);
                charContent = null;
            } else if (para.getStyle() == ParaStyle.PB) {
                if (charContent == null) {
                    charContent = new ParatextCharacterContent();
                    result.getContent().add(charContent);
                }
                charContent.getContent().add(new ParatextCharacterContent.AutoClosingFormatting(ParatextCharacterContent.AutoClosingFormattingKind.PAGE_BREAK, false));
            } else if (PARA_STYLE_UNSUPPORTED.contains(para.getStyle())) {
                // skip
                charContent = null;
            } else {
                result.getContent().add(new ParatextBook.ParagraphStart(PARA_STYLE_MAP.get(para.getStyle())));
                charContent = null;
                if (!para.getContent().isEmpty()) {
                    charContent = new ParatextCharacterContent();
                    result.getContent().add(charContent);
                    parseCharContent(para.getContent(), charContent);
                }
            }
        } else if (o instanceof Table) {
            Table table = (Table) o;
            for (Row row : table.getRow()) {
                result.getContent().add(new ParatextBook.ParagraphStart(ParatextBook.ParagraphKind.TABLE_ROW));
                for (Object oo : row.getVerseOrCell()) {
                    if (oo instanceof Verse) {
                        Verse verse = (Verse) oo;
                        ParatextCharacterContent.ParatextCharacterContentPart verseStartOrEnd = handleVerse(verse);
                        charContent = new ParatextCharacterContent();
                        result.getContent().add(charContent);
                        charContent.getContent().add(verseStartOrEnd);
                    } else if (oo instanceof Cell) {
                        Cell cell = (Cell) oo;
                        result.getContent().add(new ParatextBook.TableCellStart(cell.getStyle().value()));
                        charContent = new ParatextCharacterContent();
                        result.getContent().add(charContent);
                        parseCharContent(cell.getContent(), charContent);
                    } else {
                        throw new IOException("Unsupported table row element: " + o.getClass().getName());
                    }
                }
            }
            charContent = null;
        } else if (o instanceof Chapter) {
            Chapter chapter = (Chapter) o;
            if (chapter.getSid() != null) {
                // Assume start chapter
                result.getContent().add(new ParatextBook.ChapterStart(new ChapterIdentifier(result.getId(), ((Chapter) o).getNumber().intValue())));
            } else if (chapter.getEid() != null) {
                // Assume end chapter
                ChapterIdentifier location = ChapterIdentifier.fromLocationString(chapter.getEid());
                if (location == null) {
                    throw new IOException("Invalid chapter eid found: " + chapter.getEid());
                }
                result.getContent().add(new ParatextBook.ChapterEnd(location));
            } else {
                throw new IOException("Invalid chapter found, both sid and eid are undefined: " + chapter);
            }
            charContent = null;
        } else if (o instanceof Note) {
            if (charContent == null) {
                charContent = new ParatextCharacterContent();
                result.getContent().add(charContent);
            }
            Note note = (Note) o;
            ParatextCharacterContent.FootnoteXref nx = new ParatextCharacterContent.FootnoteXref(NOTE_STYLE_MAP.get(note.getStyle()), note.getCaller());
            charContent.getContent().add(nx);
            parseCharContent(note.getContent(), nx);
        } else if (o instanceof Sidebar) {
            System.out.println("WARNING: Skipping sidebar (study bible content)");
            charContent = null;
        } else {
            throw new IOException("Unsupported book level element: " + o.getClass().getName());
        }
    }
    return result;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Cell(biblemulticonverter.schema.usx3.Cell) Table(biblemulticonverter.schema.usx3.Table) Para(biblemulticonverter.schema.usx3.Para) Chapter(biblemulticonverter.schema.usx3.Chapter) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Note(biblemulticonverter.schema.usx3.Note) Usx(biblemulticonverter.schema.usx3.Usx) Row(biblemulticonverter.schema.usx3.Row) ChapterIdentifier(biblemulticonverter.format.paratext.model.ChapterIdentifier) XMLInputFactory(javax.xml.stream.XMLInputFactory) Verse(biblemulticonverter.schema.usx3.Verse) Sidebar(biblemulticonverter.schema.usx3.Sidebar)

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

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project BibleMultiConverter by schierlm.

the class USX3 method doExportBook.

@Override
protected void doExportBook(ParatextBook book, File outFile) throws Exception {
    ObjectFactory of = new ObjectFactory();
    Usx usx = of.createUsx();
    usx.setVersion("3.0");
    usx.setBook(of.createBook());
    usx.getBook().setStyle("id");
    usx.getBook().setCode(book.getId().getIdentifier());
    usx.getBook().setContent(book.getBibleName());
    for (Map.Entry<String, String> attr : book.getAttributes().entrySet()) {
        Para para = new Para();
        para.setStyle(ParaStyle.fromValue(attr.getKey()));
        para.getContent().add(attr.getValue());
        usx.getParaOrTableOrChapter().add(para);
    }
    book.accept(new ParatextBook.ParatextBookContentVisitor<IOException>() {

        List<Object> currentContent = null;

        Table currentTable = null;

        @Override
        public void visitChapterStart(ChapterIdentifier location) throws IOException {
            Chapter ch = new Chapter();
            ch.setStyle("c");
            ch.setSid(location.toString());
            ch.setNumber(BigInteger.valueOf(location.chapter));
            usx.getParaOrTableOrChapter().add(ch);
            currentContent = null;
            currentTable = null;
        }

        @Override
        public void visitChapterEnd(ChapterIdentifier location) throws IOException {
            Chapter ch = new Chapter();
            ch.setEid(location.toString());
            usx.getParaOrTableOrChapter().add(ch);
            currentContent = null;
            currentTable = null;
        }

        @Override
        public void visitParagraphStart(ParatextBook.ParagraphKind kind) throws IOException {
            if (kind == ParatextBook.ParagraphKind.TABLE_ROW) {
                if (currentTable == null) {
                    currentTable = new Table();
                    usx.getParaOrTableOrChapter().add(currentTable);
                }
                Row row = new Row();
                row.setStyle("tr");
                currentTable.getRow().add(row);
                currentContent = currentTable.getRow().get(currentTable.getRow().size() - 1).getVerseOrCell();
            } else {
                Para para = new Para();
                para.setStyle(PARA_KIND_MAP.get(kind));
                usx.getParaOrTableOrChapter().add(para);
                currentContent = para.getContent();
                currentTable = null;
            }
        }

        @Override
        public void visitTableCellStart(String tag) throws IOException {
            if (currentTable == null) {
                System.out.println("WARNING: Table cell outside of table");
                return;
            }
            Row currentRow = currentTable.getRow().get(currentTable.getRow().size() - 1);
            Cell cell = new Cell();
            cell.setAlign(tag.contains("r") ? CellAlign.END : CellAlign.START);
            cell.setStyle(CellStyle.fromValue(tag));
            currentRow.getVerseOrCell().add(cell);
            currentContent = cell.getContent();
        }

        @Override
        public void visitParatextCharacterContent(ParatextCharacterContent content) throws IOException {
            if (currentContent == null)
                visitParagraphStart(ParatextBook.ParagraphKind.PARAGRAPH_P);
            content.accept(new USX3.USXCharacterContentVisitor(currentContent));
        }
    });
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
    Marshaller m = ctx.createMarshaller();
    if (!Boolean.getBoolean("biblemulticonverter.skipxmlvalidation"))
        m.setSchema(getSchema());
    m.marshal(usx, new UnifiedScriptureXMLWriter(new FileWriter(outFile), "UTF-8"));
}
Also used : Marshaller(javax.xml.bind.Marshaller) Table(biblemulticonverter.schema.usx3.Table) Para(biblemulticonverter.schema.usx3.Para) UnifiedScriptureXMLWriter(biblemulticonverter.format.paratext.utilities.UnifiedScriptureXMLWriter) FileWriter(java.io.FileWriter) Chapter(biblemulticonverter.schema.usx3.Chapter) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) ObjectFactory(biblemulticonverter.schema.usx3.ObjectFactory) Usx(biblemulticonverter.schema.usx3.Usx) Row(biblemulticonverter.schema.usx3.Row) ChapterIdentifier(biblemulticonverter.format.paratext.model.ChapterIdentifier) Map(java.util.Map) EnumMap(java.util.EnumMap) Cell(biblemulticonverter.schema.usx3.Cell)

Example 9 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 DeIdentifyTableBucketing method deIdentifyTableBucketing.

public static void deIdentifyTableBucketing() 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();
    deIdentifyTableBucketing(projectId, tableToDeIdentify);
}
Also used : Table(com.google.privacy.dlp.v2.Table)

Example 10 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 DeIdentifyTableConditionInfoTypes method deIdentifyTableConditionInfoTypes.

public static Table deIdentifyTableConditionInfoTypes(String projectId, Table tableToDeIdentify) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DlpServiceClient dlp = DlpServiceClient.create()) {
        // Specify what content you want the service to de-identify.
        ContentItem contentItem = ContentItem.newBuilder().setTable(tableToDeIdentify).build();
        // Specify how the content should be de-identified.
        // Select type of info to be replaced.
        InfoType infoType = InfoType.newBuilder().setName("PERSON_NAME").build();
        // Specify that findings should be replaced with corresponding info type name.
        ReplaceWithInfoTypeConfig replaceWithInfoTypeConfig = ReplaceWithInfoTypeConfig.getDefaultInstance();
        PrimitiveTransformation primitiveTransformation = PrimitiveTransformation.newBuilder().setReplaceWithInfoTypeConfig(replaceWithInfoTypeConfig).build();
        // Associate info type with the replacement strategy
        InfoTypeTransformation infoTypeTransformation = InfoTypeTransformation.newBuilder().addInfoTypes(infoType).setPrimitiveTransformation(primitiveTransformation).build();
        InfoTypeTransformations infoTypeTransformations = InfoTypeTransformations.newBuilder().addTransformations(infoTypeTransformation).build();
        // Specify fields to be de-identified.
        List<FieldId> fieldIds = Stream.of("PATIENT", "FACTOID").map(id -> FieldId.newBuilder().setName(id).build()).collect(Collectors.toList());
        // Specify when the above fields should be de-identified.
        Condition condition = Condition.newBuilder().setField(FieldId.newBuilder().setName("AGE").build()).setOperator(RelationalOperator.GREATER_THAN).setValue(Value.newBuilder().setIntegerValue(89).build()).build();
        // Apply the condition to records
        RecordCondition recordCondition = RecordCondition.newBuilder().setExpressions(Expressions.newBuilder().setConditions(Conditions.newBuilder().addConditions(condition).build()).build()).build();
        // Associate the de-identification and conditions with the specified fields.
        FieldTransformation fieldTransformation = FieldTransformation.newBuilder().setInfoTypeTransformations(infoTypeTransformations).addAllFields(fieldIds).setCondition(recordCondition).build();
        RecordTransformations transformations = RecordTransformations.newBuilder().addFieldTransformations(fieldTransformation).build();
        DeidentifyConfig deidentifyConfig = DeidentifyConfig.newBuilder().setRecordTransformations(transformations).build();
        // Combine configurations into a request for the service.
        DeidentifyContentRequest request = DeidentifyContentRequest.newBuilder().setParent(LocationName.of(projectId, "global").toString()).setItem(contentItem).setDeidentifyConfig(deidentifyConfig).build();
        // Send the request and receive response from the service.
        DeidentifyContentResponse response = dlp.deidentifyContent(request);
        // Print the results.
        System.out.println("Table after de-identification: " + response.getItem().getTable());
        return response.getItem().getTable();
    }
}
Also used : InfoTypeTransformations(com.google.privacy.dlp.v2.InfoTypeTransformations) Conditions(com.google.privacy.dlp.v2.RecordCondition.Conditions) RelationalOperator(com.google.privacy.dlp.v2.RelationalOperator) PrimitiveTransformation(com.google.privacy.dlp.v2.PrimitiveTransformation) Row(com.google.privacy.dlp.v2.Table.Row) DeidentifyConfig(com.google.privacy.dlp.v2.DeidentifyConfig) RecordCondition(com.google.privacy.dlp.v2.RecordCondition) Expressions(com.google.privacy.dlp.v2.RecordCondition.Expressions) FieldId(com.google.privacy.dlp.v2.FieldId) DeidentifyContentResponse(com.google.privacy.dlp.v2.DeidentifyContentResponse) DlpServiceClient(com.google.cloud.dlp.v2.DlpServiceClient) Value(com.google.privacy.dlp.v2.Value) LocationName(com.google.privacy.dlp.v2.LocationName) InfoTypeTransformations(com.google.privacy.dlp.v2.InfoTypeTransformations) InfoTypeTransformation(com.google.privacy.dlp.v2.InfoTypeTransformations.InfoTypeTransformation) Table(com.google.privacy.dlp.v2.Table) FieldTransformation(com.google.privacy.dlp.v2.FieldTransformation) ContentItem(com.google.privacy.dlp.v2.ContentItem) InfoType(com.google.privacy.dlp.v2.InfoType) IOException(java.io.IOException) DeidentifyContentRequest(com.google.privacy.dlp.v2.DeidentifyContentRequest) Collectors(java.util.stream.Collectors) Condition(com.google.privacy.dlp.v2.RecordCondition.Condition) List(java.util.List) Stream(java.util.stream.Stream) RecordTransformations(com.google.privacy.dlp.v2.RecordTransformations) ReplaceWithInfoTypeConfig(com.google.privacy.dlp.v2.ReplaceWithInfoTypeConfig) RecordCondition(com.google.privacy.dlp.v2.RecordCondition) Condition(com.google.privacy.dlp.v2.RecordCondition.Condition) DeidentifyContentRequest(com.google.privacy.dlp.v2.DeidentifyContentRequest) PrimitiveTransformation(com.google.privacy.dlp.v2.PrimitiveTransformation) RecordCondition(com.google.privacy.dlp.v2.RecordCondition) RecordTransformations(com.google.privacy.dlp.v2.RecordTransformations) DlpServiceClient(com.google.cloud.dlp.v2.DlpServiceClient) FieldId(com.google.privacy.dlp.v2.FieldId) DeidentifyConfig(com.google.privacy.dlp.v2.DeidentifyConfig) ReplaceWithInfoTypeConfig(com.google.privacy.dlp.v2.ReplaceWithInfoTypeConfig) InfoTypeTransformation(com.google.privacy.dlp.v2.InfoTypeTransformations.InfoTypeTransformation) InfoType(com.google.privacy.dlp.v2.InfoType) ContentItem(com.google.privacy.dlp.v2.ContentItem) DeidentifyContentResponse(com.google.privacy.dlp.v2.DeidentifyContentResponse) FieldTransformation(com.google.privacy.dlp.v2.FieldTransformation)

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