Search in sources :

Example 16 with RDB$FIELDS

use of org.jooq.meta.firebird.rdb.Tables.RDB$FIELDS in project atlasmap by atlasmap.

the class AtlasKafkaConnectModelFactory method createKafkaConnectDocument.

/**
 * Creates the Kafka Connect Document.
 * @return Document
 */
public static KafkaConnectDocument createKafkaConnectDocument() {
    KafkaConnectDocument kafkaConnectDocument = new KafkaConnectDocument();
    kafkaConnectDocument.setFields(new Fields());
    return kafkaConnectDocument;
}
Also used : Fields(io.atlasmap.v2.Fields)

Example 17 with RDB$FIELDS

use of org.jooq.meta.firebird.rdb.Tables.RDB$FIELDS in project atlasmap by atlasmap.

the class SchemaInspector method doInspect.

private void doInspect(InputStream is) throws Exception {
    xmlDocument = AtlasXmlModelFactory.createXmlDocument();
    Fields fields = new Fields();
    xmlDocument.setFields(fields);
    namespaceContext = new AtlasXmlNamespaceContext();
    rootNamespace = null;
    XSOMParser parser = new XSOMParser(SAXParserFactory.newInstance());
    parser.setAnnotationParser(new DomAnnotationParserFactory());
    parser.setErrorHandler(new XSOMErrorHandler());
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = dbf.newDocumentBuilder().parse(is);
    Element root = doc.getDocumentElement();
    if (root == null) {
        throw new XmlInspectionException("XML schema document is empty");
    } else if ("SchemaSet".equals(root.getLocalName())) {
        XPath xpath = XPathFactory.newInstance().newXPath();
        xpath.setNamespaceContext(namespaceContext);
        NodeList subSchemas = (NodeList) xpath.evaluate(String.format("/%s:SchemaSet/%s:AdditionalSchemas/%s:schema", NS_PREFIX_SCHEMASET, NS_PREFIX_SCHEMASET, NS_PREFIX_XMLSCHEMA), doc, XPathConstants.NODESET);
        for (int i = 0; i < subSchemas.getLength(); i++) {
            Element e = (Element) subSchemas.item(i);
            inheritNamespaces(e, false);
            parser.parse(toInputStream(transformer, e));
        }
        Element rootSchema = (Element) xpath.evaluate(String.format("/%s:SchemaSet/%s:schema", NS_PREFIX_SCHEMASET, NS_PREFIX_XMLSCHEMA), doc, XPathConstants.NODE);
        if (rootSchema == null) {
            throw new XmlInspectionException("The root schema '/SchemaSet/schema' must be specified once and only once");
        }
        rootNamespace = getTargetNamespace(rootSchema);
        if (rootNamespace != null && !rootNamespace.isEmpty()) {
            namespaceContext.add("tns", rootNamespace);
        }
        inheritNamespaces(rootSchema, true);
        parser.parse(toInputStream(transformer, rootSchema));
    } else if ("schema".equals(root.getLocalName())) {
        parser.parse(toInputStream(transformer, root));
        rootNamespace = getTargetNamespace(root);
        if (rootNamespace != null && !rootNamespace.isEmpty()) {
            namespaceContext.add("tns", rootNamespace);
        }
    } else {
        throw new XmlInspectionException(String.format("Unsupported document element '%s': root element must be 'schema' or 'SchemaSet'", root.getLocalName()));
    }
    XSSchemaSet schemaSet = parser.getResult();
    printSchemaSet(schemaSet);
    populateNamespaces();
}
Also used : XPath(javax.xml.xpath.XPath) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) Transformer(javax.xml.transform.Transformer) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) XmlDocument(io.atlasmap.xml.v2.XmlDocument) XmlFields(io.atlasmap.xml.v2.XmlFields) Fields(io.atlasmap.v2.Fields) DomAnnotationParserFactory(com.sun.xml.xsom.util.DomAnnotationParserFactory)

Example 18 with RDB$FIELDS

use of org.jooq.meta.firebird.rdb.Tables.RDB$FIELDS in project atlasmap by atlasmap.

the class CsvFieldReader method readSchema.

/**
 * Reads only the first row of the document.
 *
 * If firstRecordAsHeader is set to true it uses column names for field names, otherwise it uses an index
 * starting from 0.
 *
 * @return {@link Document} built from CSV
 * @throws AtlasException if it fails
 */
public Document readSchema() throws AtlasException {
    CSVFormat csvFormat = csvConfig.newCsvFormat();
    CSVParser parser;
    try {
        document.mark(Integer.MAX_VALUE);
        parser = csvFormat.parse(new InputStreamReader(document));
    } catch (IOException e) {
        throw new AtlasException(e);
    }
    List<CsvField> fields = new ArrayList<>();
    if (csvConfig.isFirstRecordAsHeader()) {
        for (String headerName : parser.getHeaderNames()) {
            CsvField field = new CsvField();
            field.setName(headerName);
            field.setPath("/<>/" + headerName);
            field.setFieldType(FieldType.STRING);
            fields.add(field);
        }
    } else {
        CSVRecord record = parser.iterator().next();
        for (int i = 0; i < record.size(); i++) {
            CsvField field = new CsvField();
            if (parser.getHeaderNames() != null && parser.getHeaderNames().size() > i) {
                field.setName(parser.getHeaderNames().get(i));
            } else {
                field.setColumn(i);
                field.setName(String.valueOf(i));
            }
            field.setPath("/<>/" + field.getName());
            field.setFieldType(FieldType.STRING);
            fields.add(field);
        }
    }
    try {
        document.reset();
    } catch (IOException e) {
        throw new AtlasException(e);
    }
    CsvFields csvFields = new CsvFields();
    csvFields.getCsvField().addAll(fields);
    CsvComplexType csvComplexType = new CsvComplexType();
    csvComplexType.setFieldType(FieldType.COMPLEX);
    csvComplexType.setCollectionType(CollectionType.LIST);
    csvComplexType.setPath("/<>");
    csvComplexType.setName("");
    csvComplexType.setCsvFields(csvFields);
    Fields documentFields = new Fields();
    documentFields.getField().add(csvComplexType);
    Document document = new Document();
    document.setFields(documentFields);
    return document;
}
Also used : InputStreamReader(java.io.InputStreamReader) CsvComplexType(io.atlasmap.csv.v2.CsvComplexType) CsvFields(io.atlasmap.csv.v2.CsvFields) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AtlasException(io.atlasmap.api.AtlasException) Document(io.atlasmap.v2.Document) CsvFields(io.atlasmap.csv.v2.CsvFields) Fields(io.atlasmap.v2.Fields) CsvField(io.atlasmap.csv.v2.CsvField) CSVParser(org.apache.commons.csv.CSVParser) CSVFormat(org.apache.commons.csv.CSVFormat) CSVRecord(org.apache.commons.csv.CSVRecord)

Example 19 with RDB$FIELDS

use of org.jooq.meta.firebird.rdb.Tables.RDB$FIELDS in project atlasmap by atlasmap.

the class XmlInstanceInspector method inspect.

/**
 * Inspects the XML instance.
 * @param document XML instance
 */
public void inspect(Document document) {
    xmlDocument.setFields(new Fields());
    parseDocument(document.getDocumentElement());
}
Also used : XmlFields(io.atlasmap.xml.v2.XmlFields) Fields(io.atlasmap.v2.Fields)

Example 20 with RDB$FIELDS

use of org.jooq.meta.firebird.rdb.Tables.RDB$FIELDS in project atlasmap by atlasmap.

the class XmlSchemaInspector method doInspect.

private void doInspect(InputStream is) throws Exception {
    xmlDocument = AtlasXmlModelFactory.createXmlDocument();
    Fields fields = new Fields();
    xmlDocument.setFields(fields);
    AtlasXmlSchemaSetParser parser = new AtlasXmlSchemaSetParser(this.classLoader);
    XSSchemaSet schemaSet = parser.parse(is);
    this.namespaceContext = parser.getNamespaceContext();
    this.rootNamespace = parser.getRootNamespace();
    printSchemaSet(schemaSet);
    populateNamespaces();
}
Also used : XmlFields(io.atlasmap.xml.v2.XmlFields) XmlEnumFields(io.atlasmap.xml.v2.XmlEnumFields) Fields(io.atlasmap.v2.Fields) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) AtlasXmlSchemaSetParser(io.atlasmap.xml.core.schema.AtlasXmlSchemaSetParser)

Aggregations

Fields (io.atlasmap.v2.Fields)15 Record (org.jooq.Record)11 Document (io.atlasmap.v2.Document)8 ArrayList (java.util.ArrayList)8 Test (org.junit.jupiter.api.Test)7 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)5 Rdb$fields (org.jooq.meta.firebird.rdb.tables.Rdb$fields)5 XmlFields (io.atlasmap.xml.v2.XmlFields)4 TableDefinition (org.jooq.meta.TableDefinition)4 Rdb$relationConstraints (org.jooq.meta.firebird.rdb.tables.Rdb$relationConstraints)4 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)3 SchemaDefinition (org.jooq.meta.SchemaDefinition)3 DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)3 Rdb$fields (org.jooq.util.firebird.rdb.tables.Rdb$fields)3 XSSchemaSet (com.sun.xml.xsom.XSSchemaSet)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Result (org.jooq.Result)2 Rdb$functionArguments (org.jooq.meta.firebird.rdb.tables.Rdb$functionArguments)2