use of org.talend.dataquality.semantic.datamasking.ValueDataMasker in project data-prep by Talend.
the class MaskDataByDomain method applyOnColumn.
@Override
public void applyOnColumn(DataSetRow row, ActionContext context) {
final String columnId = context.getColumnId();
final String value = row.get(columnId);
if (StringUtils.isNotBlank(value)) {
try {
final ValueDataMasker masker = context.get(MASKER);
row.set(columnId, masker.maskValue(value));
} catch (Exception e) {
// Nothing to do, we let the original value as is
LOGGER.debug("Unable to process value '{}'.", value, e);
}
}
}
use of org.talend.dataquality.semantic.datamasking.ValueDataMasker in project data-prep by Talend.
the class MaskDataByDomain method compile.
@Override
public void compile(ActionContext actionContext) {
super.compile(actionContext);
if (ActionsUtils.doesCreateNewColumn(actionContext.getParameters(), CREATE_NEW_COLUMN_DEFAULT)) {
ActionsUtils.createNewColumn(actionContext, singletonList(ActionsUtils.additionalColumn()));
}
if (actionContext.getActionStatus() == OK) {
final RowMetadata rowMetadata = actionContext.getRowMetadata();
final String columnId = actionContext.getColumnId();
final ColumnMetadata column = rowMetadata.getById(columnId);
final String domain = column.getDomain();
final Type type = get(column.getType());
LOGGER.trace(">>> type: " + type + " metadata: " + column);
try {
if (DATE.equals(type)) {
final List<PatternFrequency> patternFreqList = column.getStatistics().getPatternFrequencies();
final List<String> dateTimePatternList = //
patternFreqList.stream().map(//
PatternFrequency::getPattern).collect(toList());
actionContext.get(MASKER, p -> new ValueDataMasker(domain, type.getName(), dateTimePatternList));
} else {
actionContext.get(MASKER, p -> new ValueDataMasker(domain, type.getName()));
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
actionContext.setActionStatus(CANCELED);
}
}
}
Aggregations