use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class DefaultAtlasContext method process.
/**
* Process session lifecycle
*/
@Override
public void process(AtlasSession userSession) throws AtlasException {
if (!(userSession instanceof DefaultAtlasSession)) {
throw new AtlasException(String.format("Unsupported session class '%s'", userSession.getClass().getName()));
}
if (!this.equals(userSession.getAtlasContext())) {
throw new AtlasException("Cannot execute AtlasSession created by the other AtlasContext");
}
DefaultAtlasSession session = (DefaultAtlasSession) userSession;
if (LOG.isDebugEnabled()) {
LOG.debug("Begin process {}", (session == null ? null : session.toString()));
}
session.head().unset();
session.getAudits().getAudit().clear();
session.getValidations().getValidation().clear();
processValidation(session);
for (Validation v : session.getValidations().getValidation()) {
AtlasUtil.addAudit(session, v);
}
if (session.hasErrors()) {
if (LOG.isDebugEnabled()) {
LOG.error("Aborting due to {} errors in pre-validation", session.errorCount());
}
return;
}
for (AtlasModule module : getSourceModules().values()) {
module.processPreSourceExecution(session);
}
for (AtlasModule module : getTargetModules().values()) {
module.processPreTargetExecution(session);
}
if (session.hasErrors()) {
if (LOG.isDebugEnabled()) {
LOG.error("Aborting due to {} errors in pre-execution", session.errorCount());
}
return;
}
for (BaseMapping baseMapping : session.getMapping().getMappings().getMapping()) {
for (Mapping mapping : extractCollectionMappings(session, baseMapping)) {
session.head().setMapping(mapping).setLookupTable(lookupTables.get(mapping.getLookupTableName()));
if (mapping.getOutputField() == null || mapping.getOutputField().isEmpty()) {
AtlasUtil.addAudit(session, null, String.format("Mapping does not contain at least one output field: alias=%s desc=%s", mapping.getAlias(), mapping.getDescription()), null, AuditStatus.WARN, null);
continue;
}
if (mapping.getInputField() == null || mapping.getInputField().isEmpty()) {
AtlasUtil.addAudit(session, null, String.format("Mapping does not contain at least one source field: alias=%s desc=%s", mapping.getAlias(), mapping.getDescription()), null, AuditStatus.WARN, null);
} else {
processSourceFieldMappings(session, mapping.getInputField());
}
processTargetFieldMappings(session, mapping);
}
}
for (AtlasModule module : getSourceModules().values()) {
module.processPostValidation(session);
}
for (AtlasModule module : getTargetModules().values()) {
module.processPostValidation(session);
}
for (AtlasModule module : getSourceModules().values()) {
module.processPostSourceExecution(session);
}
for (AtlasModule module : getTargetModules().values()) {
module.processPostTargetExecution(session);
}
if (LOG.isDebugEnabled()) {
LOG.debug("End process {}", session == null ? null : session.toString());
}
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class DefaultAtlasContext method processCombineField.
private Field processCombineField(DefaultAtlasSession session, Mapping mapping, List<Field> sourceFields, Field targetField) throws AtlasException {
Map<Integer, String> combineValues = null;
for (Field sourceField : sourceFields) {
if (sourceField.getIndex() == null || sourceField.getIndex() < 0) {
AtlasUtil.addAudit(session, targetField.getDocId(), String.format("Combine requires zero or positive Index value to be set on all sourceFields sourceField.path=%s", sourceField.getPath()), targetField.getPath(), AuditStatus.WARN, null);
continue;
}
if (combineValues == null) {
// We need to support a sorted map w/ null values
combineValues = new HashMap<>();
}
if ((sourceField.getFieldType() != null) || (sourceField.getValue() != null)) {
String sourceValue;
try {
sourceValue = (String) factory.getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), FieldType.STRING, null);
} catch (AtlasConversionException e) {
AtlasUtil.addAudit(session, targetField.getDocId(), String.format("Suitable converter for sourceField.path=%s hasn't been found", sourceField.getPath()), targetField.getPath(), AuditStatus.WARN, null);
sourceValue = sourceField.getValue() != null ? sourceField.getValue().toString() : null;
}
combineValues.put(sourceField.getIndex(), sourceValue);
continue;
}
}
String combinedValue = null;
StringDelimiter delimiter = StringDelimiter.fromName(mapping.getDelimiter());
if (delimiter != null) {
combinedValue = session.getAtlasContext().getContextFactory().getCombineStrategy().combineValues(combineValues, delimiter);
} else {
combinedValue = session.getAtlasContext().getContextFactory().getCombineStrategy().combineValues(combineValues);
}
Field answer = AtlasModelFactory.cloneFieldToSimpleField(sourceFields.get(0));
if (combinedValue == null || combinedValue.trim().isEmpty()) {
LOG.debug(String.format("Empty combined string for Combine mapping targetField.path=%s", targetField.getPath()));
} else {
answer.setValue(combinedValue);
}
return answer;
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class DefaultAtlasContext method processSeparateField.
private List<Field> processSeparateField(DefaultAtlasSession session, Mapping mapping, Field sourceField) throws AtlasException {
List<Field> answer = new ArrayList<>();
String sourceValue;
try {
sourceValue = (String) factory.getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), FieldType.STRING, null);
} catch (AtlasConversionException e) {
AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Suitable converter for sourceField.path=%s hasn't been found", sourceField.getPath()), sourceField.getPath(), AuditStatus.WARN, null);
sourceValue = sourceField.getValue().toString();
}
List<String> separatedValues = null;
StringDelimiter delimiter = StringDelimiter.fromName(mapping.getDelimiter());
if (mapping.getDelimiter() != null) {
separatedValues = session.getAtlasContext().getContextFactory().getSeparateStrategy().separateValue(sourceValue, delimiter);
} else {
separatedValues = session.getAtlasContext().getContextFactory().getSeparateStrategy().separateValue(sourceValue);
}
if (separatedValues == null || separatedValues.isEmpty()) {
LOG.debug(String.format("Empty string for Separate mapping sourceField.path=%s", sourceField.getPath()));
} else {
for (String separatedValue : separatedValues) {
SimpleField simpleField = AtlasModelFactory.cloneFieldToSimpleField(sourceField);
simpleField.setValue(separatedValue);
simpleField.setFieldType(FieldType.STRING);
answer.add(simpleField);
}
}
return answer;
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class DefaultAtlasValidationService method validateMapMapping.
private void validateMapMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
for (Mapping fieldMapping : fieldMappings) {
String mappingId = fieldMapping.getId();
validateMappingId(mappingId, usedIds, validations);
Validators.MAP_INPUT_NOT_NULL.get().validate(fieldMapping.getInputField(), validations, mappingId);
if (fieldMapping.getInputField() != null) {
Validators.MAP_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId);
}
Validators.MAP_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
if (fieldMapping.getOutputField() != null) {
Validators.MAP_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
}
}
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class DefaultAtlasValidationService method validateCombineMapping.
private void validateCombineMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
for (Mapping fieldMapping : fieldMappings) {
String mappingId = fieldMapping.getId();
validateMappingId(mappingId, usedIds, validations);
Validators.COMBINE_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId);
if (fieldMapping.getOutputField() != null) {
Validators.COMBINE_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId);
// source must be a String type
}
Validators.COMBINE_INPUT_NOT_NULL.get().validate(fieldMapping.getInputField(), validations, mappingId, ValidationStatus.WARN);
Validators.COMBINE_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId, ValidationStatus.WARN);
if (fieldMapping.getInputField() != null) {
for (Field field : fieldMapping.getInputField()) {
Validators.COMBINE_INPUT_FIELD_NOT_NULL.get().validate(field, validations, mappingId);
if (field.getIndex() == null || field.getIndex() < 0) {
Validators.COMBINE_INPUT_FIELD_FIELD_ACTION_INDEX_POSITIVE.get().validate(field.getIndex(), validations, mappingId);
}
}
}
}
}
Aggregations