use of io.atlasmap.v2.LookupEntry in project atlasmap by atlasmap.
the class TargetValueConverter method populateEnumValue.
@SuppressWarnings("unchecked")
private Object populateEnumValue(AtlasInternalSession session, LookupTable lookupTable, JavaEnumField sourceField, JavaEnumField targetField) {
if (sourceField == null || sourceField.getValue() == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Input enum field or value is null, field: " + sourceField);
}
return null;
}
String sourceValue = ((Enum<?>) sourceField.getValue()).name();
String targetValue = sourceValue;
if (lookupTable != null) {
for (LookupEntry e : lookupTable.getLookupEntry()) {
if (e.getSourceValue().equals(sourceValue)) {
targetValue = e.getTargetValue();
break;
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Mapped input enum value '" + sourceValue + "' to output enum value '" + targetValue + "'.");
}
if (targetValue == null) {
return null;
}
@SuppressWarnings("rawtypes") Class enumClass = null;
try {
enumClass = Class.forName(targetField.getClassName());
} catch (Exception e) {
AtlasUtil.addAudit(session, targetField.getDocId(), String.format("Could not find class for output field class '%s': %s", targetField.getClassName(), e.getMessage()), targetField.getPath(), AuditStatus.ERROR, targetValue);
return null;
}
try {
return Enum.valueOf(enumClass, targetValue);
} catch (IllegalArgumentException e) {
AtlasUtil.addAudit(session, targetField.getDocId(), String.format("No enum entry found for value '%s': %s", targetValue, e.getMessage()), targetField.getPath(), AuditStatus.ERROR, targetValue);
return null;
}
}
Aggregations