Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions CosmosClone/CosmicCloneUI/DataAnonymizationPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ void AddRuleWithData(WrapPanel parentStackPanel, int ruleIndex, ScrubRule scrubR
scrubTypeSP.Orientation = Orientation.Horizontal;
scrubTypeSP.Margin = new Thickness(0, 5, 0, 2);

StackPanel findValueSP = new StackPanel();
findValueSP.Orientation = Orientation.Horizontal;
findValueSP.Margin = new Thickness(0, 5, 0, 2);

StackPanel scrubValueSP = new StackPanel();
scrubValueSP.Orientation = Orientation.Horizontal;
scrubValueSP.Margin = new Thickness(0, 5, 0, 2);
Expand Down Expand Up @@ -197,6 +201,19 @@ void AddRuleWithData(WrapPanel parentStackPanel, int ruleIndex, ScrubRule scrubR

ScrubTypeCB.SelectionChanged += new SelectionChangedEventHandler(scrubTypeComboBox_SelectedIndexChanged);

TextBlock FindValueLabel = new TextBlock();
FindValueLabel.Text = "Find";
FindValueLabel.FontSize = 15;
FindValueLabel.VerticalAlignment = VerticalAlignment.Center;
FindValueLabel.Margin = new Thickness(10, 0, 0, 5);

TextBox FindValueTB = new TextBox();
FindValueTB.Name = "FindValue" + ruleIndex;
FindValueTB.Width = 150;
FindValueTB.HorizontalContentAlignment = HorizontalAlignment.Left;
FindValueTB.VerticalAlignment = VerticalAlignment.Center;
FindValueTB.Margin = new Thickness(20, 0, 0, 0);

TextBlock ScrubValueLabel = new TextBlock();
ScrubValueLabel.Text = "Replace with";
ScrubValueLabel.FontSize = 15;
Expand All @@ -217,6 +234,8 @@ void AddRuleWithData(WrapPanel parentStackPanel, int ruleIndex, ScrubRule scrubR
ScrubTypeLabel.Width = 120;
ScrubTypeCB.Width = 150;
ScrubValueLabel.Width = 120;
FindValueTB.Width = 150;
FindValueLabel.Width = 120;

filterSP.Children.Add(FilterLabel);
filterSP.Children.Add(FilterTB);
Expand All @@ -227,6 +246,10 @@ void AddRuleWithData(WrapPanel parentStackPanel, int ruleIndex, ScrubRule scrubR
scrubTypeSP.Children.Add(ScrubTypeLabel);
scrubTypeSP.Children.Add(ScrubTypeCB);

findValueSP.Children.Add(FindValueLabel);
findValueSP.Children.Add(FindValueTB);
findValueSP.Visibility = Visibility.Collapsed;

scrubValueSP.Children.Add(ScrubValueLabel);
scrubValueSP.Children.Add(ScrubValueTB);
scrubValueSP.Children.Add(RuleIdLabel);
Expand All @@ -235,6 +258,7 @@ void AddRuleWithData(WrapPanel parentStackPanel, int ruleIndex, ScrubRule scrubR
sp.Children.Add(attributeSP);
sp.Children.Add(filterSP);
sp.Children.Add(scrubTypeSP);
sp.Children.Add(findValueSP);
sp.Children.Add(scrubValueSP);

exp.Content = sp;
Expand All @@ -245,6 +269,7 @@ void AddRuleWithData(WrapPanel parentStackPanel, int ruleIndex, ScrubRule scrubR
AttributeScrubTB.Text = scrubRule.PropertyName;
if(scrubRule.Type!=null) ScrubTypeCB.SelectedIndex = (int)scrubRule.Type;
ScrubValueTB.Text = scrubRule.UpdateValue;
FindValueTB.Text = scrubRule.FindValue;
}
parentStackPanel.Children.Add(exp);
if(!SaveRuleButton.IsEnabled)
Expand All @@ -263,13 +288,23 @@ private void scrubTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
var parentPanel = (StackPanel)cbox.Parent;
var gpPanel = (StackPanel)parentPanel.Parent;
gpPanel.Children[3].Visibility = Visibility.Collapsed;
gpPanel.Children[4].Visibility = Visibility.Visible;
}
else if (scrubType == RuleType.FindAndReplace.ToString())
{
var parentPanel = (StackPanel)cbox.Parent;
var gpPanel = (StackPanel)parentPanel.Parent;

gpPanel.Children[3].Visibility = Visibility.Visible;
gpPanel.Children[4].Visibility = Visibility.Visible;
}
else
{
var parentPanel = (StackPanel)cbox.Parent;
var gpPanel = (StackPanel)parentPanel.Parent;
gpPanel.Children[3].Visibility = Visibility.Hidden;
gpPanel.Children[3].Visibility = Visibility.Collapsed;
gpPanel.Children[4].Visibility = Visibility.Hidden;
}
}

Expand Down Expand Up @@ -353,6 +388,10 @@ public List<ScrubRule> getScrubRules()
{
sr.UpdateValue = tb.Text.Trim();
}
else if (tb.Name.StartsWith("FindValue"))
{
sr.FindValue = tb.Text.Trim();
}
}

if (uiElement.GetType().Name == "ComboBox")
Expand Down Expand Up @@ -414,7 +453,11 @@ public bool validateInput()
{
validationMessages.Add($"Rule:{rule.RuleId} - Filter condition starts improperly. Sample c.EntityType=\"document\" ");
}
}
}
if (rule.Type == RuleType.FindAndReplace && string.IsNullOrEmpty(rule.FindValue))
{
validationMessages.Add($"Rule:{rule.RuleId} - Find is empty");
}
}
if(validationMessages.Count > 0)
{
Expand Down
3 changes: 2 additions & 1 deletion CosmosClone/CosmosCloneCommon/Model/ScrubRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ScrubRule
public int RuleId { get; set; }
public string FilterCondition { get; set; }
public string PropertyName { get; set; }
public string FindValue { get; set; }
public string UpdateValue { get; set; }

public RuleType? Type { get; set; }
Expand All @@ -38,5 +39,5 @@ public ScrubRule(string filterCondition, string propertyName, RuleType type, str

}

public enum RuleType { SingleValue, NullValue, Shuffle, PartialMaskFromLeft, PartialMaskFromRight };//Can add random rule type later if required.
public enum RuleType { SingleValue, NullValue, Shuffle, PartialMaskFromLeft, PartialMaskFromRight, FindAndReplace };//Can add random rule type later if required.
}
23 changes: 15 additions & 8 deletions CosmosClone/CosmosCloneCommon/Utility/ObjectScrubber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public List<JToken> ScrubObjectList(List<string> srcList, ScrubRule scrubRule)
//var scrubbedObjects = new List<string>();
var scrubbedObjects = new List<JToken>();
var propNames = scrubRule.PropertyName.Split('.').ToList();
if(scrubRule.Type == RuleType.NullValue || scrubRule.Type == RuleType.SingleValue || scrubRule.Type == RuleType.PartialMaskFromLeft || scrubRule.Type == RuleType.PartialMaskFromRight)
if(scrubRule.Type == RuleType.NullValue || scrubRule.Type == RuleType.SingleValue || scrubRule.Type == RuleType.PartialMaskFromLeft || scrubRule.Type == RuleType.PartialMaskFromRight || scrubRule.Type == RuleType.FindAndReplace)
{
foreach (var strObj in srcList)
{
try
{
JToken jToken = GetUpdatedJsonArrayValue((JToken)JObject.Parse(strObj), propNames, scrubRule.UpdateValue, scrubRule.Type);
JToken jToken = GetUpdatedJsonArrayValue((JToken)JObject.Parse(strObj), propNames, scrubRule.FindValue, scrubRule.UpdateValue, scrubRule.Type);
scrubbedObjects.Add(jToken);
}
catch(Exception ex)
Expand Down Expand Up @@ -205,7 +205,7 @@ public JToken GetDocumentShuffledToken(JToken token, List<string> propNames, ref
return jTokenResult;
}

public JToken GetUpdatedJsonArrayValue(JToken token, List<string> propNames, string overwritevalue, RuleType? ruleType)
public JToken GetUpdatedJsonArrayValue(JToken token, List<string> propNames, string findvalue, string overwritevalue, RuleType? ruleType)
{
if (token == null || token.Type == JTokenType.Null) return null;

Expand All @@ -227,15 +227,15 @@ public JToken GetUpdatedJsonArrayValue(JToken token, List<string> propNames, str
{
if (jArray[k][currentProperty] != null && jArray[k][currentProperty].Type != JTokenType.Null)
{
jArray[k][currentProperty] = ScrubTokenValue(ruleType, jArray[k][currentProperty], overwritevalue);
jArray[k][currentProperty] = ScrubTokenValue(ruleType, jArray[k][currentProperty], findvalue, overwritevalue);
}
continue;
}
else
{
if (jArray[k] != null && jArray[k][currentProperty].Type != JTokenType.Null)
{
jArray[k] = GetUpdatedJsonArrayValue(jArray[k], propNames.GetRange(1, propNames.Count - 1), overwritevalue, ruleType);
jArray[k] = GetUpdatedJsonArrayValue(jArray[k], propNames.GetRange(1, propNames.Count - 1), findvalue, overwritevalue, ruleType);
continue;
}
//else return null;
Expand All @@ -251,14 +251,14 @@ public JToken GetUpdatedJsonArrayValue(JToken token, List<string> propNames, str
{
if (jObj[currentProperty] != null && jObj[currentProperty].Type != JTokenType.Null)
{
jObj[currentProperty] = ScrubTokenValue(ruleType, jObj[currentProperty], overwritevalue);
jObj[currentProperty] = ScrubTokenValue(ruleType, jObj[currentProperty], findvalue, overwritevalue);
}
}
else
{
if (jObj[currentProperty] != null && jObj[currentProperty].Type != JTokenType.Null)
{
jObj[currentProperty] = GetUpdatedJsonArrayValue((JToken)jObj[currentProperty], propNames.GetRange(1, propNames.Count - 1), overwritevalue, ruleType);
jObj[currentProperty] = GetUpdatedJsonArrayValue((JToken)jObj[currentProperty], propNames.GetRange(1, propNames.Count - 1), findvalue, overwritevalue, ruleType);
}
//else return null;
}
Expand All @@ -274,7 +274,7 @@ public JToken GetUpdatedJsonArrayValue(JToken token, List<string> propNames, str
return jTokenResult;
}

private JToken ScrubTokenValue(RuleType? ruleType, JToken tokenToBeScrubbed, string overwriteValue)
private JToken ScrubTokenValue(RuleType? ruleType, JToken tokenToBeScrubbed, string findValue, string overwriteValue)
{
if (ruleType.HasValue)
{
Expand All @@ -301,6 +301,13 @@ private JToken ScrubTokenValue(RuleType? ruleType, JToken tokenToBeScrubbed, str
tokenToBeScrubbed = string.Concat(oldValue.Remove(oldValue.Length - overwriteValue.Length, overwriteValue.Length), overwriteValue);
}
}
else if (ruleType == RuleType.FindAndReplace)
{
if (oldValue.Contains(findValue))
{
tokenToBeScrubbed = oldValue.Replace(findValue, overwriteValue);
}
}
else
{
tokenToBeScrubbed = overwriteValue;
Expand Down