Search in sources :

Example 56 with DataSource

use of io.atlasmap.v2.DataSource in project atlasmap by atlasmap.

the class BaseJsonValidationServiceTest method generateDataSource.

protected DataSource generateDataSource(String uri, DataSourceType type) {
    DataSource ds = new DataSource();
    ds.setUri(uri);
    ds.setDataSourceType(type);
    return ds;
}
Also used : DataSource(io.atlasmap.v2.DataSource)

Example 57 with DataSource

use of io.atlasmap.v2.DataSource in project atlasmap by atlasmap.

the class XmlFieldReader method getSourceNamespaces.

private Optional<XmlNamespaces> getSourceNamespaces(AtlasInternalSession session, Field field) {
    DataSource dataSource = null;
    AtlasMapping mapping = session.getMapping();
    // this is to simplify tests which uses mocks
    if (mapping == null || mapping.getDataSource() == null || field.getDocId() == null) {
        return Optional.empty();
    }
    List<DataSource> dataSources = mapping.getDataSource();
    for (DataSource source : dataSources) {
        if (!source.getDataSourceType().equals(DataSourceType.SOURCE)) {
            continue;
        }
        if (field.getDocId().equals(source.getId())) {
            dataSource = source;
            break;
        }
    }
    if (dataSource == null || !XmlDataSource.class.isInstance(dataSource)) {
        return Optional.empty();
    }
    XmlDataSource xmlDataSource = XmlDataSource.class.cast(dataSource);
    return xmlDataSource.getXmlNamespaces() != null ? Optional.of(xmlDataSource.getXmlNamespaces()) : Optional.empty();
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) DataSource(io.atlasmap.v2.DataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 58 with DataSource

use of io.atlasmap.v2.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)

Example 59 with DataSource

use of io.atlasmap.v2.DataSource in project atlasmap by atlasmap.

the class ADMArchiveHandler method getDataSourceMetadataMap.

/**
 * Gets a map of DataSource metadata.
 * @return a map of DataSource metadata.
 * @throws AtlasException unexpected error
 */
public Map<DataSourceKey, DataSourceMetadata> getDataSourceMetadataMap() throws AtlasException {
    if (this.dataSourceMetadata == null) {
        if (this.gzippedAdmDigestBytes == null) {
            return null;
        }
        try (GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(this.gzippedAdmDigestBytes))) {
            ADMDigest digest = jsonMapperForDigest.readValue(in, ADMDigest.class);
            this.dataSourceMetadata = new HashMap<>();
            for (int i = 0; i < digest.getExportMeta().length; i++) {
                DataSourceMetadata meta = digest.getExportMeta()[i];
                String spec = digest.getExportBlockData()[i].getValue();
                if (meta.getId() == null) {
                    meta.setId(meta.getName());
                }
                meta.setSpecification(spec != null ? spec.getBytes() : null);
                this.dataSourceMetadata.put(new DataSourceKey(meta.getIsSource(), meta.getId()), meta);
            }
        } catch (Exception e) {
            throw new AtlasException(e);
        }
    }
    return Collections.unmodifiableMap(this.dataSourceMetadata);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) DataSourceKey(io.atlasmap.v2.DataSourceKey) DataSourceMetadata(io.atlasmap.v2.DataSourceMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) AtlasException(io.atlasmap.api.AtlasException) AtlasException(io.atlasmap.api.AtlasException) ADMDigest(io.atlasmap.v2.ADMDigest)

Aggregations

DataSource (io.atlasmap.v2.DataSource)54 AtlasMapping (io.atlasmap.v2.AtlasMapping)16 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 AtlasContext (io.atlasmap.api.AtlasContext)5 AtlasSession (io.atlasmap.api.AtlasSession)5 JavaField (io.atlasmap.java.v2.JavaField)5 AtlasException (io.atlasmap.api.AtlasException)4 XmlNamespaces (io.atlasmap.xml.v2.XmlNamespaces)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 AtlasModule (io.atlasmap.spi.AtlasModule)3 HashMap (java.util.HashMap)3 Exchange (org.apache.camel.Exchange)3