Search in sources :

Example 21 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource in project atlasmap by atlasmap.

the class XmlFieldReaderTest method mockDataSources.

private void mockDataSources(String docId, AtlasInternalSession session) {
    AtlasMapping atlasMapping = mock(AtlasMapping.class);
    List<DataSource> dataSources = new ArrayList<>();
    XmlDataSource xmlDataSource = new XmlDataSource();
    xmlDataSource.setId(docId);
    xmlDataSource.setDataSourceType(DataSourceType.SOURCE);
    XmlNamespaces atlasNamespaces = new XmlNamespaces();
    XmlNamespace xmlNamespaceQ = new XmlNamespace();
    xmlNamespaceQ.setAlias("q");
    xmlNamespaceQ.setUri("http://www.example.com/q/");
    XmlNamespace xmlNamespaceX = new XmlNamespace();
    xmlNamespaceX.setAlias("");
    xmlNamespaceX.setUri("http://www.example.com/x/");
    XmlNamespace xmlNamespaceY = new XmlNamespace();
    xmlNamespaceY.setAlias("y");
    xmlNamespaceY.setUri("http://www.example.com/y/");
    atlasNamespaces.getXmlNamespace().add(xmlNamespaceQ);
    atlasNamespaces.getXmlNamespace().add(xmlNamespaceX);
    atlasNamespaces.getXmlNamespace().add(xmlNamespaceY);
    xmlDataSource.setXmlNamespaces(atlasNamespaces);
    dataSources.add(xmlDataSource);
    when(atlasMapping.getDataSource()).thenReturn(dataSources);
    when(session.getMapping()).thenReturn(atlasMapping);
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) ArrayList(java.util.ArrayList) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces) DataSource(io.atlasmap.v2.DataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 22 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method processSources.

/**
 * Gets list of output data shapes for preceding steps.
 *
 * @param precedingSteps
 * @return
 */
private List<DataSource> processSources(List<StepDefinition> precedingSteps) {
    List<DataSource> sources = new ArrayList<>();
    for (StepDefinition s : precedingSteps) {
        DataShape outDataShape = s.getConnectorDescriptor().get().getOutputDataShape().get();
        sources.add(createDataSource(outDataShape, s, DataSourceType.SOURCE));
    }
    return sources;
}
Also used : ArrayList(java.util.ArrayList) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) DataShape(io.syndesis.common.model.DataShape) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 23 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method createDataSource.

/**
 * Used to generate data source elements for atlasMapping. There are three types of them: Java, Json, XML.
 *
 * TODO(tplevko): update also for XML
 *
 * @param dataShape
 * @param step
 * @param dataSourceType
 * @return
 */
private DataSource createDataSource(DataShape dataShape, StepDefinition step, DataSourceType dataSourceType) {
    DataShapeKinds dataShapeKind = dataShape.getKind();
    DataSource source = null;
    if (dataShapeKind.toString().contains("json")) {
        source = new JsonDataSource();
        source.setUri("atlas:" + "json:" + step.getStep().getId().get());
    } else if (dataShapeKind.toString().contains("java")) {
        source = new DataSource();
        source.setUri("atlas:" + "java:" + step.getStep().getId().get() + "?className=" + dataShape.getType());
    } else if (dataShapeKind.toString().contains("xml")) {
        source = new XmlDataSource();
    // TODO(tplevko): find out how should look the XML datasource definition
    }
    source.setId(step.getStep().getId().get());
    source.setDataSourceType(dataSourceType);
    return source;
}
Also used : JsonDataSource(io.atlasmap.json.v2.JsonDataSource) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 24 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource in project atlasmap by atlasmap.

the class ConcurrencyChaosMonkeyTest method generateMappingURI.

protected URI generateMappingURI() throws Exception {
    AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
    mapping.setName("mockMapping");
    DataSource src = new DataSource();
    src.setDataSourceType(DataSourceType.SOURCE);
    src.setUri("atlas:java?className=twitter4j.Status");
    DataSource tgt = new DataSource();
    tgt.setDataSourceType(DataSourceType.TARGET);
    tgt.setUri("atlas:java?className=org.apache.camel.salesforce.dto.Contact");
    mapping.getDataSource().add(src);
    mapping.getDataSource().add(tgt);
    Mapping sepMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
    JavaField jNameField = new JavaField();
    jNameField.setName("Name");
    jNameField.setPath("User.name");
    jNameField.setGetMethod("getName");
    jNameField.setFieldType(FieldType.STRING);
    JavaField jFirstNameField = new JavaField();
    jFirstNameField.setName("FirstName");
    jFirstNameField.setPath("FirstName");
    jFirstNameField.setSetMethod("setFirstName");
    jFirstNameField.setFieldType(FieldType.STRING);
    jFirstNameField.setIndex(0);
    JavaField jLastNameField = new JavaField();
    jLastNameField.setName("LastName");
    jLastNameField.setPath("LastName");
    jLastNameField.setSetMethod("setLastName");
    jLastNameField.setFieldType(FieldType.STRING);
    jLastNameField.setIndex(1);
    sepMapping.getInputField().add(jNameField);
    sepMapping.getOutputField().add(jFirstNameField);
    sepMapping.getOutputField().add(jLastNameField);
    mapping.getMappings().getMapping().add(sepMapping);
    Mapping textDescMapping = AtlasModelFactory.createMapping(MappingType.MAP);
    JavaField jTextField = new JavaField();
    jTextField.setName("Text");
    jTextField.setPath("Text");
    jTextField.setGetMethod("getText");
    jTextField.setFieldType(FieldType.STRING);
    JavaField jDescField = new JavaField();
    jDescField.setName("Description");
    jDescField.setPath("description");
    jDescField.setSetMethod("setDescription");
    jDescField.setFieldType(FieldType.STRING);
    textDescMapping.getInputField().add(jTextField);
    textDescMapping.getOutputField().add(jDescField);
    mapping.getMappings().getMapping().add(textDescMapping);
    Mapping screenTitleMapping = AtlasModelFactory.createMapping(MappingType.MAP);
    JavaField jScreenField = new JavaField();
    jScreenField.setName("ScreenName");
    jScreenField.setPath("User.screenName");
    jScreenField.setGetMethod("getScreenName");
    jScreenField.setFieldType(FieldType.STRING);
    JavaField jTitleField = new JavaField();
    jTitleField.setName("Title");
    jTitleField.setPath("Title");
    jTitleField.setSetMethod("setTitle");
    jTitleField.setFieldType(FieldType.STRING);
    screenTitleMapping.getInputField().add(jScreenField);
    screenTitleMapping.getOutputField().add(jTitleField);
    mapping.getMappings().getMapping().add(screenTitleMapping);
    File mappingFile = new File("target/junit-atlasmapping.xml");
    atlasContextFactory.getMappingService().saveMappingAsFile(mapping, mappingFile);
    return mappingFile.toURI();
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) File(java.io.File) DataSource(io.atlasmap.v2.DataSource)

Example 25 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource in project atlasmap by atlasmap.

the class BaseModuleValidationService method validateMapping.

@Override
public List<Validation> validateMapping(AtlasMapping mapping) {
    List<Validation> validations = new ArrayList<>();
    if (getMode() == AtlasModuleMode.UNSET) {
        Validation validation = new Validation();
        validation.setMessage(String.format("No mode specified for %s/%s, skipping module validations", this.getModuleDetail().name(), this.getClass().getSimpleName()));
    }
    if (mapping != null && mapping.getMappings() != null && mapping.getMappings().getMapping() != null && !mapping.getMappings().getMapping().isEmpty()) {
        validateMappingEntries(mapping.getMappings().getMapping(), validations);
    }
    boolean found = false;
    for (DataSource ds : mapping.getDataSource()) {
        if (ds.getUri() != null && ds.getUri().startsWith(getModuleDetail().uri())) {
            found = true;
            break;
        }
    }
    if (!found) {
        Validation validation = new Validation();
        validation.setScope(ValidationScope.DATA_SOURCE);
        validation.setMessage(String.format("No DataSource with '%s' uri specified", getModuleDetail().uri()));
        validation.setStatus(ValidationStatus.ERROR);
        validations.add(validation);
    }
    return validations;
}
Also used : Validation(io.atlasmap.v2.Validation) ArrayList(java.util.ArrayList) DataSource(io.atlasmap.v2.DataSource)

Aggregations

DataSource (io.atlasmap.v2.DataSource)54 AtlasMapping (io.atlasmap.v2.AtlasMapping)15 ArrayList (java.util.ArrayList)14 Mapping (io.atlasmap.v2.Mapping)11 XmlDataSource (io.atlasmap.xml.v2.XmlDataSource)10 Mappings (io.atlasmap.v2.Mappings)8 JsonDataSource (io.atlasmap.json.v2.JsonDataSource)7 Test (org.junit.Test)7 File (java.io.File)6 JavaField (io.atlasmap.java.v2.JavaField)5 AtlasContext (io.atlasmap.api.AtlasContext)4 AtlasSession (io.atlasmap.api.AtlasSession)4 XmlNamespaces (io.atlasmap.xml.v2.XmlNamespaces)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 AtlasException (io.atlasmap.api.AtlasException)3 DataSourceType (io.atlasmap.v2.DataSourceType)3 HashMap (java.util.HashMap)3 AtlasContextFactory (io.atlasmap.api.AtlasContextFactory)2 ADM (io.atlasmap.api.AtlasContextFactory.Format.ADM)2