Skip to content

Commit

Permalink
Removing custom exception and moving logic into filterfactory
Browse files Browse the repository at this point in the history
  • Loading branch information
harrieoriowo committed May 30, 2024
1 parent 46113e7 commit 274791e
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 159 deletions.
54 changes: 0 additions & 54 deletions src/Common/Helpers/EventGridException.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -185,29 +185,11 @@ private FiltersConfiguration GetFiltersConfiguration(List<Dictionary<string, str

foreach (Dictionary<string, string> i in filters)
{
var operatorType = i["Operator"].ToString();
var value = i["Value"].ToString();
var key = i["Key"].ToString();

if (operatorType.Equals("Boolean equals")) { eventGridFilterFactory.AddFilterForBoolEquals(key, value); };
if (operatorType.Equals("String is in")) { eventGridFilterFactory.AddFilterForStringIn(key, value); };
if (operatorType.Equals("String is not in")) { eventGridFilterFactory.AddFilterForStringNotIn(key, value); };
if (operatorType.Equals("String contains")) { eventGridFilterFactory.AddFilterForStringContains(key, value); };
if (operatorType.Equals("String does not contain")) { eventGridFilterFactory.AddFilterForStringNotContains(key, value); };
if (operatorType.Equals("String begins with")) { eventGridFilterFactory.AddFilterForStringBeginsWith(key, value); };
if (operatorType.Equals("String does not begin with")) { eventGridFilterFactory.AddFilterForStringNotBeginsWith(key, value); };
if (operatorType.Equals("String ends with")) { eventGridFilterFactory.AddFilterForStringEndsWith(key, value); };
if (operatorType.Equals("String does not end with")) { eventGridFilterFactory.AddFilterForStringNotEndsWith(key, value); };
if (operatorType.Equals("Number is less than")) { eventGridFilterFactory.AddFilterForNumberLessThan(key, value); };
if (operatorType.Equals("Number is greater than")) { eventGridFilterFactory.AddFilterForNumberGreaterThan(key, value); };
if (operatorType.Equals("Number is less than or equal to")) { eventGridFilterFactory.AddFilterForNumberLessThanOrEquals(key, value); };
if (operatorType.Equals("Number is greater than or equal to")) { eventGridFilterFactory.AddFilterForNumberGreaterThanOrEquals(key, value); };
if (operatorType.Equals("Number is in")) { eventGridFilterFactory.AddFilterForNumberIn(key, value); };
if (operatorType.Equals("Number is not in")) { eventGridFilterFactory.AddFilterForNumberNotIn(key, value); };
if (operatorType.Equals("Number is in range")) { eventGridFilterFactory.AddFilterForNumberInRange(key, value); };
if (operatorType.Equals("Number is not in range")) { eventGridFilterFactory.AddFilterForNumberNotInRange(key, value); };
if (operatorType.Equals("Is null or undefined")) { eventGridFilterFactory.AddFilterForIsNullOrUndefined( key); };
if (operatorType.Equals("Is not null")) { eventGridFilterFactory.AddFilterForIsNotNull(key); };
eventGridFilterFactory.Key = i["Key"].ToString();
eventGridFilterFactory.Value = i["Value"].ToString();
eventGridFilterFactory.OperatorType = i["Operator"].ToString();

eventGridFilterFactory.FilterSelection();
}

if (eventTypes.Count > 0)
Expand Down
140 changes: 84 additions & 56 deletions src/EventGridExplorerLibrary/Management/EventGridFilterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace EventGridExplorerLibrary
public class EventGridFilterFactory
{
private FiltersConfiguration filtersConfiguration;

/// <summary>
/// Initializes a new instance of the <see cref="EventGridFilterFactory"/> class.
/// </summary>
Expand All @@ -23,22 +23,45 @@ public EventGridFilterFactory(FiltersConfiguration filtersConfiguration)
this.filtersConfiguration = filtersConfiguration;
}

public void FilterSelection()
{
if (OperatorType.Equals("Boolean equals")) { AddFilterForBoolEquals(); };
if (OperatorType.Equals("String is in")) { AddFilterForStringIn(); };
if (OperatorType.Equals("String is not in")) { AddFilterForStringNotIn(); };
if (OperatorType.Equals("String contains")) { AddFilterForStringContains(); };
if (OperatorType.Equals("String does not contain")) { AddFilterForStringNotContains(); };
if (OperatorType.Equals("String begins with")) { AddFilterForStringBeginsWith(); };
if (OperatorType.Equals("String does not begin with")) { AddFilterForStringNotBeginsWith(); };
if (OperatorType.Equals("String ends with")) { AddFilterForStringEndsWith(); };
if (OperatorType.Equals("String does not end with")) { AddFilterForStringNotEndsWith(); };
if (OperatorType.Equals("Number is less than")) { AddFilterForNumberLessThan(); };
if (OperatorType.Equals("Number is greater than")) { AddFilterForNumberGreaterThan(); };
if (OperatorType.Equals("Number is less than or equal to")) { AddFilterForNumberLessThanOrEquals(); };
if (OperatorType.Equals("Number is greater than or equal to")) { AddFilterForNumberGreaterThanOrEquals(); };
if (OperatorType.Equals("Number is in")) { AddFilterForNumberIn(); };
if (OperatorType.Equals("Number is not in")) { AddFilterForNumberNotIn(); };
if (OperatorType.Equals("Number is in range")) { AddFilterForNumberInRange(); };
if (OperatorType.Equals("Number is not in range")) { AddFilterForNumberNotInRange(); };
if (OperatorType.Equals("Is null or undefined")) { AddFilterForIsNullOrUndefined(); };
if (OperatorType.Equals("Is not null")) { AddFilterForIsNotNull(); };
}

/// <inheritdoc/>
public void AddFilterForBoolEquals(string key, string value)
public void AddFilterForBoolEquals()
{
var filter = new BoolEqualsFilter
{
Key = key,
Value = bool.Parse(value)
Key = Key,
Value = bool.Parse(Value)
};

this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForStringIn(string key, string value)
public void AddFilterForStringIn()
{
var filter = new StringInFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new StringInFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
Expand All @@ -47,10 +70,10 @@ public void AddFilterForStringIn(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForStringNotIn(string key, string value)
public void AddFilterForStringNotIn()
{
var filter = new StringNotInFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new StringNotInFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
Expand All @@ -59,10 +82,10 @@ public void AddFilterForStringNotIn(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForStringContains(string key, string value)
public void AddFilterForStringContains()
{
var filter = new StringContainsFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new StringContainsFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
Expand All @@ -71,10 +94,10 @@ public void AddFilterForStringContains(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForStringNotContains(string key, string value)
public void AddFilterForStringNotContains()
{
var filter = new StringNotContainsFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new StringNotContainsFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
Expand All @@ -83,10 +106,10 @@ public void AddFilterForStringNotContains(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForStringBeginsWith(string key, string value)
public void AddFilterForStringBeginsWith()
{
var filter = new StringBeginsWithFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new StringBeginsWithFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
Expand All @@ -95,10 +118,10 @@ public void AddFilterForStringBeginsWith(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForStringNotBeginsWith(string key, string value)
public void AddFilterForStringNotBeginsWith()
{
var filter = new StringNotBeginsWithFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new StringNotBeginsWithFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
Expand All @@ -107,10 +130,10 @@ public void AddFilterForStringNotBeginsWith(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForStringEndsWith(string key, string value)
public void AddFilterForStringEndsWith()
{
var filter = new StringEndsWithFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new StringEndsWithFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
Expand All @@ -119,10 +142,10 @@ public void AddFilterForStringEndsWith(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForStringNotEndsWith(string key, string value)
public void AddFilterForStringNotEndsWith()
{
var filter = new StringNotEndsWithFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new StringNotEndsWithFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
Expand All @@ -131,54 +154,54 @@ public void AddFilterForStringNotEndsWith(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForNumberLessThan(string key, string value)
public void AddFilterForNumberLessThan()
{
var filter = new NumberLessThanFilter
{
Key = key,
Value = double.Parse(value)
Key = Key,
Value = double.Parse(Value)
};

this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForNumberGreaterThan(string key, string value)
public void AddFilterForNumberGreaterThan()
{
var filter = new NumberGreaterThanFilter
{
Key = key,
Value = double.Parse(value)
Key = Key,
Value = double.Parse(Value)
};

this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForNumberLessThanOrEquals(string key, string value)
public void AddFilterForNumberLessThanOrEquals()
{
var filter = new NumberLessThanOrEqualsFilter
{
Key = key,
Value = double.Parse(value)
Key = Key,
Value = double.Parse(Value)
};

this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForNumberGreaterThanOrEquals(string key, string value)
public void AddFilterForNumberGreaterThanOrEquals()
{
var filter = new NumberGreaterThanOrEqualsFilter
{
Key = key,
Value = double.Parse(value)
Key = Key,
Value = double.Parse(Value)
};

this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForNumberIn(string key, string value)
public void AddFilterForNumberIn()
{
var filter = new NumberInFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new NumberInFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(double.Parse(filterValue));
Expand All @@ -187,10 +210,10 @@ public void AddFilterForNumberIn(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForNumberNotIn(string key, string value)
public void AddFilterForNumberNotIn()
{
var filter = new NumberNotInFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new NumberNotInFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(double.Parse(filterValue));
Expand All @@ -199,10 +222,10 @@ public void AddFilterForNumberNotIn(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForNumberNotInRange(string key, string value)
public void AddFilterForNumberNotInRange()
{
var filter = new NumberNotInRangeFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new NumberNotInRangeFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
List<double> doubleRangeValues = new List<double>();
Expand All @@ -217,10 +240,10 @@ public void AddFilterForNumberNotInRange(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForNumberInRange(string key, string value)
public void AddFilterForNumberInRange()
{
var filter = new NumberInRangeFilter { Key = key };
string[] filterValuesList = value.Split(',');
var filter = new NumberInRangeFilter { Key = Key };
string[] filterValuesList = Value.Split(',');
foreach (string filterValue in filterValuesList)
{
List<double> doubleRangeValues = new List<double>();
Expand All @@ -235,17 +258,22 @@ public void AddFilterForNumberInRange(string key, string value)
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForIsNullOrUndefined(string key)
public void AddFilterForIsNullOrUndefined()
{
var filter = new IsNullOrUndefinedFilter { Key = key };
var filter = new IsNullOrUndefinedFilter { Key = Key };
this.filtersConfiguration.Filters.Add(filter);
}

public void AddFilterForIsNotNull(string key)
public void AddFilterForIsNotNull()
{
var filter = new IsNotNullFilter { Key = key };
var filter = new IsNotNullFilter { Key = Key };
this.filtersConfiguration.Filters.Add(filter);
}

public string Key { get; set; }

public string Value { get; set; }

public string OperatorType { get; set; }
}
}
Loading

0 comments on commit 274791e

Please sign in to comment.