Search in sources :

Example 81 with Document

use of com.google.cloud.documentai.v1beta2.Document in project atlasmap by atlasmap.

the class AtlasUtilTest method testExcludeNotRequestedFieldsShouldIncludeTwoLevels.

@Test
public void testExcludeNotRequestedFieldsShouldIncludeTwoLevels() {
    Document document = new Document();
    Fields fields = new Fields();
    fields.getField().add(newField("/A", newField("/A/A", newField("/A/A/A"), newField("/A/A/B")), newField("/A/B", newField("/A/B/A", newField("/A/B/A/A")))));
    document.setFields(fields);
    AtlasUtil.excludeNotRequestedFields(document, Arrays.asList("/A/B"));
    assertEquals("/A{/A/A{}, /A/B{/A/B/A{}, }, }, ", fields.getField().get(0).toString());
}
Also used : Fields(io.atlasmap.v2.Fields) Document(io.atlasmap.v2.Document) Test(org.junit.jupiter.api.Test)

Example 82 with Document

use of com.google.cloud.documentai.v1beta2.Document in project atlasmap by atlasmap.

the class CsvFieldReaderTest method testReadSchemaWithHeaderSpecified.

@Test
public void testReadSchemaWithHeaderSpecified() throws Exception {
    CsvConfig csvConfig = new CsvConfig();
    csvConfig.setHeaders("givenName,familyName");
    CsvFieldReader csvFieldReader = new CsvFieldReader(csvConfig);
    csvFieldReader.setDocument(new ByteArrayInputStream("Bob,Smith\nAndrew,Johnson".getBytes()));
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(AtlasInternalSession.Head.class));
    Document document = csvFieldReader.readSchema();
    CsvComplexType list = (CsvComplexType) document.getFields().getField().get(0);
    assertEquals("givenName", list.getCsvFields().getCsvField().get(0).getName());
    assertEquals("familyName", list.getCsvFields().getCsvField().get(1).getName());
}
Also used : AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) ByteArrayInputStream(java.io.ByteArrayInputStream) CsvComplexType(io.atlasmap.csv.v2.CsvComplexType) Document(io.atlasmap.v2.Document) Test(org.junit.jupiter.api.Test)

Example 83 with Document

use of com.google.cloud.documentai.v1beta2.Document in project cxf by apache.

the class AbstractTypeTestClient2 method testDocument.

@Test
public void testDocument() throws Exception {
    if (!shouldRunTest("Document")) {
        return;
    }
    Document x = new Document();
    x.setValue("content-x");
    x.setID("Hello There");
    Document yOrig = new Document();
    yOrig.setID("Cheerio");
    yOrig.setValue("content-y");
    Holder<Document> y = new Holder<>(yOrig);
    Holder<Document> z = new Holder<>();
    Document ret;
    if (testDocLiteral) {
        ret = docClient.testDocument(x, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testDocument(x, y, z);
    } else {
        ret = rpcClient.testDocument(x, y, z);
    }
    if (!perfTestOnly) {
        equals("testDocument(): Incorrect value for inout param", x, y.value);
        equals("testDocument(): Incorrect value for out param", yOrig, z.value);
        equals("testDocument(): Incorrect return value", x, ret);
    }
    x = new Document();
    yOrig = new Document();
    x.setValue("content-x");
    yOrig.setValue("content-y");
    x.setID(null);
    yOrig.setID(null);
    y = new Holder<>(yOrig);
    z = new Holder<>();
    if (testDocLiteral) {
        ret = docClient.testDocument(x, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testDocument(x, y, z);
    } else {
        ret = rpcClient.testDocument(x, y, z);
    }
    if (!perfTestOnly) {
        equals("testDocument(): Incorrect value for inout param", x, y.value);
        equals("testDocument(): Incorrect value for out param", yOrig, z.value);
        equals("testDocument(): Incorrect return value", x, ret);
        assertNull(y.value.getID());
        assertNull(ret.getID());
    }
}
Also used : Holder(javax.xml.ws.Holder) Document(org.apache.type_test.types1.Document) Test(org.junit.Test)

Example 84 with Document

use of com.google.cloud.documentai.v1beta2.Document in project opentheso by miledrousset.

the class importxml method ouvreFichier2.

/**
 * cette funtion permet de ouvrir un fichier pour comencée a faire une
 * injection de données.
 * Cette funtion c'est la generique
 * @param ds
 * @param archive
 * @throws ClassNotFoundException
 * @throws SQLException
 */
public void ouvreFichier2(HikariDataSource ds, File archive) throws ClassNotFoundException, SQLException {
    LanguageBean langueBean = new LanguageBean();
    SAXBuilder builder = new SAXBuilder();
    ArrayList<Table> toutTables = new ArrayList<>();
    ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
    try {
        // on crée le document a partir du fichier que on a selectioné
        Document document = (Document) builder.build(archive);
        // Se obtiene la raiz 'tables'
        Element rootNode = document.getRootElement();
        // ici on a toutes les tables (les enfants de la racine)
        List list = rootNode.getChildren("table");
        // ici on fait le tour pour les enfants de 'tables'
        for (int i = 0; i < list.size(); i++) {
            // ici on a la première table
            Element tabla = (Element) list.get(i);
            // ici on a le nom de la table
            String nombreTabla = tabla.getAttributeValue("nom");
            // ici c'est la liste des lignes de la table
            List lista_campos = tabla.getChildren();
            // ici on découpe la liste des lignes
            for (int j = 0; j < lista_campos.size(); j++) {
                // ici on a une ligne de la table
                Element campo = (Element) lista_campos.get(j);
                for (Element colonne : campo.getChildren()) {
                    LineOfData lineOfData = new LineOfData();
                    lineOfData.setColomne(colonne.getName());
                    lineOfData.setValue(colonne.getText());
                    lineOfDatas.add(lineOfData);
                }
                insertLine2(ds, lineOfDatas, nombreTabla);
                lineOfDatas.clear();
            }
        // / mettre à jour la table dans la BDD
        }
    } catch (IOException | JDOMException io) {
        System.out.println(io.toString());
    }
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("impBDD.info1")));
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) LineOfData(mom.trd.opentheso.core.exports.privatesdatas.LineOfData) ArrayList(java.util.ArrayList) List(java.util.List) LanguageBean(mom.trd.opentheso.SelectedBeans.LanguageBean)

Example 85 with Document

use of com.google.cloud.documentai.v1beta2.Document in project opentheso by miledrousset.

the class testimportxml method ouvreFichier.

// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
// 
@Test
public void ouvreFichier() {
    HikariDataSource conn = openConnexionPool();
    SAXBuilder builder = new SAXBuilder();
    ArrayList<Table> toutTables = new ArrayList<>();
    ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
    File xmlFile = new File("C:/Users/antonio.perez/Desktop/testbon.xml");
    try {
        // Se crea el documento a traves del archivo
        Document document = (Document) builder.build(xmlFile);
        // Se obtiene la raiz 'tables'
        Element rootNode = document.getRootElement();
        // Se obtiene la lista de hijos de la raiz 'tables'
        // ici on a toutes les tables (les enfants de la racine)
        List list = rootNode.getChildren("table");
        // Se recorre la lista de hijos de 'tables'
        for (int i = 0; i < list.size(); i++) {
            // Se obtiene el elemento 'tabla'
            // ici on a la première table
            Element tabla = (Element) list.get(i);
            // Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            // ici on a le nom de la table
            String nombreTabla = tabla.getAttributeValue("nom");
            System.out.println("Nom de la table : " + nombreTabla);
            // Se obtiene la lista de hijos del tag 'tabla'
            // ici c'est la liste des lignes de la table
            List lista_campos = tabla.getChildren();
            // ici on découpe la liste des lignes
            for (int j = 0; j < lista_campos.size(); j++) {
                // Se obtiene el elemento 'campo'
                // ici on a une ligne de la table
                Element campo = (Element) lista_campos.get(j);
                // System.out.println("nouvelle ligne table "+ nombreTabla);
                for (Element colonne : campo.getChildren()) {
                    LineOfData lineOfData = new LineOfData();
                    // System.out.println("Nom de la colonne = " + colonne.getName());
                    // System.out.println("valeur de la colonne = " + colonne.getText());
                    lineOfData.setColomne(colonne.getName());
                    lineOfData.setValue(colonne.getText());
                    lineOfDatas.add(lineOfData);
                }
                insertLine(conn, lineOfDatas, nombreTabla);
                lineOfDatas.clear();
            }
        // / mettre à jour la table dans la BDD
        }
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) HikariDataSource(com.zaxxer.hikari.HikariDataSource) Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) LineOfData(mom.trd.opentheso.core.exports.privatesdatas.LineOfData) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Aggregations

Document (org.jdom2.Document)559 Element (org.jdom2.Element)330 Test (org.junit.Test)170 SAXBuilder (org.jdom2.input.SAXBuilder)160 IOException (java.io.IOException)146 JDOMException (org.jdom2.JDOMException)94 File (java.io.File)84 XMLOutputter (org.jdom2.output.XMLOutputter)80 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)34 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)32 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)31 MCRContent (org.mycore.common.content.MCRContent)30 MCRObject (org.mycore.datamodel.metadata.MCRObject)30 MCRException (org.mycore.common.MCRException)28 InputStream (java.io.InputStream)27 StringReader (java.io.StringReader)26 Path (java.nio.file.Path)26 URL (java.net.URL)24