Skip to content

Commit

Permalink
Merge branch 'hotfix/compiler_warnings' into hotfix/formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
toburger committed Aug 4, 2022
2 parents 4886224 + 20157f1 commit c58b4b5
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 11 deletions.
1 change: 1 addition & 0 deletions DataModel/SuedtirolDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3487,6 +3487,7 @@ public EventShort()

public string? Id { get; set; }
public string? Source { get; set; }

[SwaggerEnum(new[] { "NOI", "EC" })]
public string? EventLocation { get; set; }

Expand Down
12 changes: 11 additions & 1 deletion Helper/Postgres/PostgresSQLQueryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,17 @@ public static Query TaggingFilter_OR(this Query query, string tagkey, IReadOnlyC
public static Query TaggingFilter_AND(this Query query, string tagkey, IReadOnlyCollection<string> taglist) =>
query.Where(q =>
taglist.Aggregate(q, (q, tag) =>
q.WhereRaw(@$"(data->>'Tags')::jsonb @? '$.{tagkey}\[*\] ? (@.Id == ""{tag}"")'")));
q.WhereRaw(@$"(data->>'Tags')::jsonb @? '$.{tagkey}\[*\] ? (@.Id == ""{tag}"")'")));

public static Query TaggingFilter_OR(this Query query, IDictionary<string,string> tagdict) =>
query.Where(q =>
tagdict.Aggregate(q, (q, tag) =>
q.OrWhereRaw(@$"(data->>'Tags')::jsonb @? '$.{tag.Value}\[*\] ? (@.Id == ""{tag.Key}"")'")));

public static Query TaggingFilter_AND(this Query query, IDictionary<string,string> tagdict) =>
query.Where(q =>
tagdict.Aggregate(q, (q, tag) =>
q.WhereRaw(@$"(data->>'Tags')::jsonb @? '$.{tag.Value}\[*\] ? (@.Id == ""{tag.Key}"")'")));

#endregion

Expand Down
8 changes: 4 additions & 4 deletions Helper/Postgres/PostgresSQLWhereBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public static Query ODHActivityPoiWhereExpression(
IReadOnlyCollection<string> categorycodeslist, IReadOnlyCollection<string> dishcodeslist, IReadOnlyCollection<string> ceremonycodeslist, IReadOnlyCollection<string> facilitycodeslist,
IReadOnlyCollection<string> activitytypelist, IReadOnlyCollection<string> poitypelist, IReadOnlyCollection<string> difficultylist,
bool distance, int distancemin, int distancemax, bool duration, int durationmin, int durationmax, bool altitude, int altitudemin, int altitudemax,
string tagbehaviour, IReadOnlyCollection<string> taglist,
string tagbehaviour, IDictionary<string, IDictionary<string,string>> tagdict,
IReadOnlyCollection<string> publishedonlist, string? searchfilter, string? language, string? lastchange, bool filterClosedData, bool reducedData)
{
LogMethodInfo(
Expand Down Expand Up @@ -309,9 +309,9 @@ public static Query ODHActivityPoiWhereExpression(
.DistanceFilter(distance, distancemin, distancemax)
.DurationFilter(duration, durationmin, durationmax)
.AltitudeFilter(altitude, altitudemin, altitudemax)
.PublishedOnFilter(publishedonlist)
.When(taglist is { } && taglist.Count > 0 && tagbehaviour == "and", q => q.TaggingFilter_AND("idm", taglist!))
.When(taglist is { } && taglist.Count > 0 && tagbehaviour == "or", q => q.TaggingFilter_OR("idm", taglist!))
.PublishedOnFilter(publishedonlist)
.When(tagdict != null && tagdict.ContainsKey("and") && tagdict["and"].Count > 0, q => q.TaggingFilter_AND(tagdict["and"]))
.When(tagdict != null && tagdict.ContainsKey("or") && tagdict["or"].Count > 0, q => q.TaggingFilter_OR(tagdict["or"]))
.SearchFilter(TitleFieldsToSearchFor(language), searchfilter)
.LastChangedFilter_GeneratedColumn(lastchange)
//.When(filterClosedData, q => q.FilterClosedData_GeneratedColumn());
Expand Down
3 changes: 2 additions & 1 deletion OdhApiCore/Controllers/api/ODHActivityPoiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public ODHActivityPoiController(IWebHostEnvironment env, ISettings settings, ILo
/// <param name="altitudefilter">Altitude Range Filter (Separator ',' example Value: 500,1000 Altitude from 500 up to 1000 metres), (default:'null')</param>
/// <param name="durationfilter">Duration Range Filter (Separator ',' example Value: 1,3 Duration from 1 to 3 hours), (default:'null')</param>
/// <param name="difficultyfilter">Difficulty Filter (possible values: '1' = easy, '2' = medium, '3' = difficult), (default:'null')</param>
/// <param name="tagfilter">Filter on Tags. Syntax =and/or(TagSource.TagId,TagSource.TagId) example or(idm.summer,lts.hiking) and(idm.themed hikes,lts.family hikings), default: 'null')</param>
/// <param name="publishedon">Published On Filter (Separator ',' List of publisher IDs), (default:'null')</param>
/// <param name="updatefrom">Returns data changed after this date Format (yyyy-MM-dd), (default: 'null')</param>
/// <param name="language">Language field selector, displays data and fields available in the selected language (default:'null' all languages are displayed)</param>
Expand Down Expand Up @@ -269,7 +270,7 @@ private Task<IActionResult> GetFiltered(string[] fields, string? language, uint
difficultylist: myodhactivitypoihelper.difficultylist, distance: myodhactivitypoihelper.distance,
distancemin: myodhactivitypoihelper.distancemin, distancemax: myodhactivitypoihelper.distancemax, duration: myodhactivitypoihelper.duration, durationmin: myodhactivitypoihelper.durationmin,
durationmax: myodhactivitypoihelper.durationmax, altitude: myodhactivitypoihelper.altitude, altitudemin: myodhactivitypoihelper.altitudemin, altitudemax: myodhactivitypoihelper.altitudemax,
tagbehaviour: myodhactivitypoihelper.tagfilterbehaviour, taglist: myodhactivitypoihelper.taglist, publishedonlist: myodhactivitypoihelper.publishedonlist,
tagbehaviour: myodhactivitypoihelper.tagfilterbehaviour, tagdict: myodhactivitypoihelper.tagdict, publishedonlist: myodhactivitypoihelper.publishedonlist,
searchfilter: searchfilter, language: language, lastchange: myodhactivitypoihelper.lastchange,
filterClosedData: FilterClosedData, reducedData: ReducedData)
.ApplyRawFilter(rawfilter)
Expand Down
63 changes: 62 additions & 1 deletion OdhApiCore/Controllers/helper/GenericHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -41,6 +42,66 @@ public static async Task<IEnumerable<string>> RetrieveLocFilterDataAsync(
where region.TourismvereinIds != null
from tid in region.TourismvereinIds ?? Enumerable.Empty<string>()
select tid).Distinct().ToList();
}
}

#region Tag Filter

public static IDictionary<string,IDictionary<string,string>> RetrieveTagFilter(string tagfilter)
{
try
{
if (tagfilter == null)
return null;

var tagstofilter = new Dictionary<string, IDictionary<string, string>>();

//Examples
//tagfilter = and(idm.Winter,idm.Sommer)
//tagfilter = or(lts.Winter,lts.Sommer)
//tagfilter = or(lts.Winter,idm.Sommer)and(lts.Winter,idm.Sommer) not wokring at the moment

//Get Tagoperator
string tagoperator = tagfilter.Split('(').First();

//Get data inside brackets
var bracketdatalist = GetSubStrings(tagfilter, "(", ")");

foreach(var bracketdata in bracketdatalist)
{
var splittedelements = bracketdata.Split(",");

var splitdict = new Dictionary<string, string>();

foreach (var splittedelement in splittedelements)
{
var splittedtag = splittedelement.Split(".");
if (splittedtag.Length > 1)
{
splitdict.Add(splittedtag[1], splittedtag[0]);
}
}

tagstofilter.Add(tagoperator, splitdict);
}



return tagstofilter;
}
catch(Exception ex)
{
return null;
}
}

private static IEnumerable<string> GetSubStrings(string input, string start, string end)
{
Regex r = new Regex(Regex.Escape(start) + "(.*?)" + Regex.Escape(end));
MatchCollection matches = r.Matches(input);
foreach (Match match in matches)
yield return match.Groups[1].Value;
}

#endregion
}
}
4 changes: 4 additions & 0 deletions OdhApiCore/Controllers/helper/ODHActivityPoiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class ODHActivityPoiHelper

public string tagfilterbehaviour;
public List<string> taglist;

public IDictionary<string, IDictionary<string,string>> tagdict;

//New Publishedonlist
public List<string> publishedonlist;
Expand Down Expand Up @@ -270,6 +272,8 @@ private ODHActivityPoiHelper(

taglist = Helper.CommonListCreator.CreateIdList(tagfilter);

tagdict = GenericHelper.RetrieveTagFilter(tagfilter);

this.lastchange = lastchange;
}

Expand Down
2 changes: 1 addition & 1 deletion OdhApiCore/Controllers/other/CompatiblityApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ private Task<IActionResult> GetODHActivityPoiReduced(
activitytypelist: helper.activitytypelist, poitypelist: helper.poitypelist, difficultylist: helper.difficultylist, distance: helper.distance,
distancemin: helper.distancemin, distancemax: helper.distancemax, duration: helper.duration, durationmin: helper.durationmin,
durationmax: helper.durationmax, altitude: helper.altitude, altitudemin: helper.altitudemin, altitudemax: helper.altitudemax,
tagbehaviour: helper.tagfilterbehaviour, taglist: helper.taglist, publishedonlist: helper.publishedonlist,
tagbehaviour: helper.tagfilterbehaviour, tagdict: helper.tagdict, publishedonlist: helper.publishedonlist,
searchfilter: searchfilter, language: language, lastchange: null, filterClosedData: FilterClosedData, reducedData: ReducedData
)
.ApplyRawFilter(rawfilter)
Expand Down
2 changes: 1 addition & 1 deletion OdhApiCore/GenericHelpers/STARequestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static async Task GenerateJSONODHActivityPoiForSTA(QueryFactory queryFact
activitytypelist: new List<string>(), poitypelist: new List<string>(), difficultylist: new List<string>(), distance: false,
distancemin: 0, distancemax: 0, duration: false, durationmin: 0,
durationmax: 0, altitude: false, altitudemin: 0, altitudemax: 0,
tagbehaviour: "", taglist: new List<string>(), publishedonlist: new List<string>(),
tagbehaviour: "", tagdict: null, publishedonlist: new List<string>(),
searchfilter: null, language: language, lastchange: null,
filterClosedData: true, reducedData: true)
.OrderByRaw(orderby);
Expand Down
4 changes: 2 additions & 2 deletions OdhApiCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ public void ConfigureServices(IServiceCollection services)
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
var xmlPathdatamodel = Path.Combine(AppContext.BaseDirectory, $"DataModel.xml");
//var xmlPathdatamodel = Path.Combine(AppContext.BaseDirectory, $"DataModel.xml");
c.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
c.IncludeXmlComments(xmlPathdatamodel, includeControllerXmlComments: true);
//c.IncludeXmlComments(xmlPathdatamodel, includeControllerXmlComments: true);
c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Expand Down
3 changes: 3 additions & 0 deletions RawQueryParser/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ in(Features.[*].Id, "a3067617-771a-4b84-b85e-206e5cf4402b") // all entries in
in(Features.[].Id, "a3067617-771a-4b84-b85e-206e5cf4402b") // all entries in an Array with a specific feature ID - alternative notation
```

**Attention**: On the field _ImageGallery _if data is retrieved as anonymous there is a Transformer applied after getting the Result from the DB which cuts out all not CC0 license Images. So there the rawfilter possible can produce false results.


> `<field>` is described [here](#Supported-value-types:)
> `<value>` is described [here](#Field-syntax:)
Expand Down

0 comments on commit c58b4b5

Please sign in to comment.