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;
}
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();
}
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;
}
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);
}
Aggregations