Skip to content

Commit

Permalink
Move to STJ #1837 - Second major commit
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Jan 31, 2023
1 parent 08e559f commit eef995a
Show file tree
Hide file tree
Showing 58 changed files with 324 additions and 340 deletions.
6 changes: 3 additions & 3 deletions IsraelHiking.API/Controllers/PointsOfInterestController.cs
Expand Up @@ -87,12 +87,12 @@ public IEnumerable<Category> GetCategoriesByGroup(string categoriesGroup)
/// <returns>A list of GeoJSON features</returns>
[Route("")]
[HttpGet]
public async Task<Feature[]> GetPointsOfInterest(string northEast, string southWest, string categories,
public async Task<IFeature[]> GetPointsOfInterest(string northEast, string southWest, string categories,
string language = "")
{
if (string.IsNullOrWhiteSpace(categories))
{
return Array.Empty<Feature>();
return Array.Empty<IFeature>();
}
var categoriesArray = categories.Split(',').Select(f => f.Trim()).ToArray();
var northEastCoordinate = northEast.ToCoordinate();
Expand Down Expand Up @@ -232,7 +232,7 @@ private string ValidateFeature(Feature feature, string language)
/// <returns></returns>
[HttpGet]
[Route("closest")]
public Task<Feature> GetClosestPoint(string location, string source, string language)
public Task<IFeature> GetClosestPoint(string location, string source, string language)
{
return _pointsOfInterestProvider.GetClosestPoint(location.ToCoordinate(), source, language);
}
Expand Down
6 changes: 3 additions & 3 deletions IsraelHiking.API/Controllers/SearchController.cs
Expand Up @@ -44,7 +44,7 @@ public async Task<IEnumerable<SearchResultsPointOfInterest>> GetSearchResults(st
(term.EndsWith("\"") || term.StartsWith("״")))
{
var exactFeatures = await _searchRepository.SearchExact(term.Substring(1, term.Length - 2), language);
return await Task.WhenAll(exactFeatures.OfType<IFeature>().ToList().Select(f => ConvertFromFeature(f, language)));
return await Task.WhenAll(exactFeatures.ToList().Select(f => ConvertFromFeature(f, language)));
}
if (term.Count(c => c == ',') == 1)
{
Expand All @@ -57,11 +57,11 @@ public async Task<IEnumerable<SearchResultsPointOfInterest>> GetSearchResults(st
var envelope = placesFeatures.First().Geometry.EnvelopeInternal;
var featuresWithinPlaces = await _searchRepository.SearchByLocation(
new Coordinate(envelope.MaxX, envelope.MaxY), new Coordinate(envelope.MinX, envelope.MinY), term, language);
return await Task.WhenAll(featuresWithinPlaces.OfType<IFeature>().ToList().Select(f => ConvertFromFeature(f,language)));
return await Task.WhenAll(featuresWithinPlaces.ToList().Select(f => ConvertFromFeature(f,language)));
}
}
var features = await _searchRepository.Search(term, language);
return await Task.WhenAll(features.OfType<IFeature>().ToList().Select(f => ConvertFromFeature(f, language)));
return await Task.WhenAll(features.ToList().Select(f => ConvertFromFeature(f, language)));
}

private async Task<SearchResultsPointOfInterest> ConvertFromFeature(IFeature feature, string language)
Expand Down
1 change: 0 additions & 1 deletion IsraelHiking.API/Controllers/UpdateController.cs
Expand Up @@ -2,7 +2,6 @@
using IsraelHiking.Common.Api;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Text.Json.Serialization;
using System.Net;
using System.Text.Json;
using System.Threading;
Expand Down
2 changes: 1 addition & 1 deletion IsraelHiking.API/Converters/IOsmGeoJsonConverter.cs
Expand Up @@ -13,6 +13,6 @@ public interface IOsmGeoJsonConverter
/// </summary>
/// <param name="completeOsmGeo">The OSM element to convert</param>
/// <returns>The GeoJson data</returns>
Feature ToGeoJson(ICompleteOsmGeo completeOsmGeo);
IFeature ToGeoJson(ICompleteOsmGeo completeOsmGeo);
}
}
2 changes: 1 addition & 1 deletion IsraelHiking.API/Converters/OsmGeoJsonConverter.cs
Expand Up @@ -31,7 +31,7 @@ public OsmGeoJsonConverter(GeometryFactory geometryFactory)
}

/// <inheritdoc />
public Feature ToGeoJson(ICompleteOsmGeo completeOsmGeo)
public IFeature ToGeoJson(ICompleteOsmGeo completeOsmGeo)
{
if (completeOsmGeo?.Tags == null || completeOsmGeo.Tags.Count == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion IsraelHiking.API/Executors/ElevationSetterHelper.cs
Expand Up @@ -73,7 +73,7 @@ public static void SetElevation(Geometry geometry, IElevationGateway elevationGa
/// </summary>
/// <param name="features">The features to update</param>
/// <param name="elevationGateway">The elevation gateway</param>
public static void SetElevation(IEnumerable<Feature> features, IElevationGateway elevationGateway)
public static void SetElevation(IEnumerable<IFeature> features, IElevationGateway elevationGateway)
{
foreach (var feature in features)
{
Expand Down
3 changes: 1 addition & 2 deletions IsraelHiking.API/Executors/ExternalSourceUpdaterExecutor.cs
Expand Up @@ -71,14 +71,13 @@ public async Task RebuildSource(string currentSource)
_logger.LogInformation($"Finished rebuilding {currentSource}, indexed {features.Count} points.");
}

private void UpdateAltitude(List<Feature> features)
private void UpdateAltitude(List<IFeature> features)
{
var coordinates = features.Select(f => f.GetLocation()).ToArray();
var elevationValues = _elevationGateway.GetElevation(coordinates).Result;
for (var index = 0; index < features.Count; index++)
{
var feature = features[index];
var geoLocationCoordinate = feature.GetLocation();
feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ALT, elevationValues[index]);
}
}
Expand Down
52 changes: 26 additions & 26 deletions IsraelHiking.API/Executors/FeaturesMergeExecutor.cs
Expand Up @@ -20,9 +20,9 @@ namespace IsraelHiking.API.Executors
/// Features that are ordered first will be the target of the merge
/// while features that are ordered last will be the source of the merge.
/// </summary>
internal class FeatureComparer : IComparer<Feature>
internal class FeatureComparer : IComparer<IFeature>
{
public int Compare(Feature x, Feature y)
public int Compare(IFeature x, IFeature y)
{
if (x.Geometry is Point && y.Geometry is Point)
{
Expand Down Expand Up @@ -72,7 +72,7 @@ public class FeaturesMergeExecutor : IFeaturesMergeExecutor
}

/// <inheritdoc />
public List<Feature> Merge(List<Feature> osmFeatures, List<Feature> externalFeatures)
public List<IFeature> Merge(List<IFeature> osmFeatures, List<IFeature> externalFeatures)
{
AddAlternativeTitleToNatureReserves(osmFeatures);
externalFeatures = MergeWikipediaToOsmByWikipediaTags(osmFeatures, externalFeatures);
Expand All @@ -93,7 +93,7 @@ public List<Feature> Merge(List<Feature> osmFeatures, List<Feature> externalFeat
return all;
}

private List<Feature> MergeOsmElementsByName(List<Feature> orderedOsmFeatures, string nameAttribute)
private List<IFeature> MergeOsmElementsByName(List<IFeature> orderedOsmFeatures, string nameAttribute)
{
_logger.LogInformation($"Starting OSM merging by {nameAttribute}.");
var featureIdsToRemove = new ConcurrentBag<string>();
Expand Down Expand Up @@ -137,11 +137,11 @@ private List<Feature> MergeOsmElementsByName(List<Feature> orderedOsmFeatures, s
return orderedOsmFeatures;
}

private List<Feature> MergeExternalFeaturesToOsm(List<Feature> osmFeatures, List<Feature> externalFeatures)
private List<IFeature> MergeExternalFeaturesToOsm(List<IFeature> osmFeatures, List<IFeature> externalFeatures)
{
var featureIdsToRemove = new HashSet<string>();
_logger.LogInformation("Starting external features merging by title into OSM.");
var titlesDictionary = new Dictionary<string, List<Feature>>();
var titlesDictionary = new Dictionary<string, List<IFeature>>();
foreach (var osmFeature in osmFeatures)
{
foreach (var title in osmFeature.GetTitles())
Expand All @@ -152,7 +152,7 @@ private List<Feature> MergeExternalFeaturesToOsm(List<Feature> osmFeatures, List
}
else
{
titlesDictionary[title] = new List<Feature> { osmFeature };
titlesDictionary[title] = new List<IFeature> { osmFeature };
}
}
}
Expand All @@ -176,7 +176,7 @@ private List<Feature> MergeExternalFeaturesToOsm(List<Feature> osmFeatures, List
return externalFeatures;
}

private List<Feature> MergePlaceNodes(List<Feature> osmFeatures)
private List<IFeature> MergePlaceNodes(List<IFeature> osmFeatures)
{
var featureIdsToRemove = new ConcurrentBag<string>();
var containers = osmFeatures.Where(IsPlaceContainer).OrderBy(f => f.Geometry.Area).ToList();
Expand All @@ -200,9 +200,9 @@ private List<Feature> MergePlaceNodes(List<Feature> osmFeatures)
return osmFeatures.Where(f => list.Contains(f.GetId()) == false).ToList();
}

private bool IsPlaceContainer(Feature feature)
private bool IsPlaceContainer(IFeature feature)
{
if (!(feature.Geometry is Polygon) && !(feature.Geometry is MultiPolygon))
if (feature.Geometry is not Polygon && feature.Geometry is not MultiPolygon)
{
return false;
}
Expand All @@ -225,7 +225,7 @@ private bool IsPlaceContainer(Feature feature)
return false;
}

private List<Feature> UpdatePlacesGeometry(Feature feature, List<Feature> places)
private List<IFeature> UpdatePlacesGeometry(IFeature feature, List<IFeature> places)
{
var placeContainers = places.Where(c => IsPlaceContainerContainsFeature(c, feature))
.OrderBy(f => f.Geometry.Area)
Expand All @@ -243,7 +243,7 @@ private List<Feature> UpdatePlacesGeometry(Feature feature, List<Feature> places
return placeContainers;
}

private bool IsPlaceContainerContainsFeature(Feature container, Feature feature)
private bool IsPlaceContainerContainsFeature(IFeature container, IFeature feature)
{
try
{
Expand All @@ -270,7 +270,7 @@ private bool IsPlaceContainerContainsFeature(Feature container, Feature feature)
return false;
}

private void SimplifyGeometriesCollection(List<Feature> results)
private void SimplifyGeometriesCollection(List<IFeature> results)
{
foreach (var feature in results)
{
Expand Down Expand Up @@ -366,7 +366,7 @@ private void SimplifyGeometriesCollection(List<Feature> results)
}
}

private void WriteToReport(Feature featureToMergeTo, Feature feature)
private void WriteToReport(IFeature featureToMergeTo, IFeature feature)
{
if (!_options.WriteMergeReport)
{
Expand All @@ -386,7 +386,7 @@ private void WriteToReport(Feature featureToMergeTo, Feature feature)
_reportLogger.LogInformation(from + " " + to);
}

private string GetWebsite(Feature feature)
private string GetWebsite(IFeature feature)
{
if (feature.Attributes.Exists(FeatureAttributes.WEBSITE))
{
Expand All @@ -402,7 +402,7 @@ private string GetWebsite(Feature feature)
return string.Empty;
}

private void MergeFeatures(Feature featureToMergeTo, Feature feature)
private void MergeFeatures(IFeature featureToMergeTo, IFeature feature)
{
if (featureToMergeTo.GetId().Equals(feature.GetId()))
{
Expand Down Expand Up @@ -447,7 +447,7 @@ private void MergeFeatures(Feature featureToMergeTo, Feature feature)
WriteToReport(featureToMergeTo, feature);
}

private bool CanMerge(Feature target, Feature source)
private bool CanMerge(IFeature target, IFeature source)
{
if (target.GetId().Equals(source.GetId()))
{
Expand Down Expand Up @@ -514,15 +514,15 @@ private bool CanMerge(Feature target, Feature source)
/// <param name="source"></param>
/// <param name="tagName"></param>
/// <returns></returns>
private bool IsFeaturesTagsMismatched(Feature target, Feature source, string tagName) {
private bool IsFeaturesTagsMismatched(IFeature target, IFeature source, string tagName) {
return target.Attributes[FeatureAttributes.POI_SOURCE].Equals(Sources.OSM) &&
(target.Attributes.GetNames().Contains(tagName) &&
!source.Attributes.GetNames().Contains(tagName) ||
!target.Attributes.GetNames().Contains(tagName) &&
source.Attributes.GetNames().Contains(tagName));
}

private List<Feature> MergeWikipediaToOsmByWikipediaTags(List<Feature> osmFeatures, List<Feature> externalFeatures)
private List<IFeature> MergeWikipediaToOsmByWikipediaTags(List<IFeature> osmFeatures, List<IFeature> externalFeatures)
{
WriteToBothLoggers("Starting joining Wikipedia markers.");
var featureIdsToRemove = new HashSet<string>();
Expand Down Expand Up @@ -550,7 +550,7 @@ private List<Feature> MergeWikipediaToOsmByWikipediaTags(List<Feature> osmFeatur
return externalFeatures.Where(f => featureIdsToRemove.Contains(f.GetId()) == false).ToList();
}

private void AddAlternativeTitleToNatureReserves(List<Feature> features)
private void AddAlternativeTitleToNatureReserves(List<IFeature> features)
{
WriteToBothLoggers("Starting adding alternative names to nature reserves");
var natureReserveFeatures = features.Where(f => f.Attributes[FeatureAttributes.POI_ICON].Equals("icon-nature-reserve")).ToList();
Expand Down Expand Up @@ -595,7 +595,7 @@ private void WriteToBothLoggers(string message)
_reportLogger.LogInformation(message + "<br/>");
}

private void MergeTitles(Feature target, Feature source)
private void MergeTitles(IFeature target, IFeature source)
{
if (!(target.Attributes[FeatureAttributes.POI_NAMES] is AttributesTable targetTitlesByLanguage))
{
Expand Down Expand Up @@ -625,7 +625,7 @@ private void MergeTitles(Feature target, Feature source)
/// </summary>
/// <param name="target"></param>
/// <param name="source"></param>
private void MergeDescriptionAndAuthor(Feature target, Feature source)
private void MergeDescriptionAndAuthor(IFeature target, IFeature source)
{
foreach (var languagePostfix in Languages.Array.Select(s => ":" + s).Concat(new[] { string.Empty }))
{
Expand All @@ -648,15 +648,15 @@ private void MergeDescriptionAndAuthor(Feature target, Feature source)
}
}

private void MergeDates(Feature target, Feature source)
private void MergeDates(IFeature target, IFeature source)
{
if (target.GetLastModified() < source.GetLastModified())
{
target.SetLastModified(source.GetLastModified());
}
}

private void MergeWebsite(Feature target, Feature source)
private void MergeWebsite(IFeature target, IFeature source)
{
var websiteUrls = target.Attributes.GetNames().Where(n => n.StartsWith(FeatureAttributes.WEBSITE))
.Select(key => target.Attributes[key]).ToList();
Expand Down Expand Up @@ -690,7 +690,7 @@ private void MergeWebsite(Feature target, Feature source)
}
}

private void MergeImages(Feature target, Feature source)
private void MergeImages(IFeature target, IFeature source)
{
var imagesUrls = target.Attributes.GetNames().Where(n => n.StartsWith(FeatureAttributes.IMAGE_URL))
.Select(key => target.Attributes[key]).ToList();
Expand All @@ -713,7 +713,7 @@ private void MergeImages(Feature target, Feature source)
}
}

private void CopyKeysIfExist(Feature target, Feature source, params string[] attributeKeys)
private void CopyKeysIfExist(IFeature target, IFeature source, params string[] attributeKeys)
{
foreach (var key in attributeKeys)
{
Expand Down
2 changes: 1 addition & 1 deletion IsraelHiking.API/Executors/IFeaturesMergeExecutor.cs
Expand Up @@ -14,6 +14,6 @@ public interface IFeaturesMergeExecutor
/// <param name="osmFeatures"></param>
/// <param name="externalFeatures"></param>
/// <returns></returns>
List<Feature> Merge(List<Feature> osmFeatures, List<Feature> externalFeatures);
List<IFeature> Merge(List<IFeature> osmFeatures, List<IFeature> externalFeatures);
}
}
4 changes: 2 additions & 2 deletions IsraelHiking.API/Executors/IOsmGeoJsonPreprocessorExecutor.cs
Expand Up @@ -14,12 +14,12 @@ public interface IOsmGeoJsonPreprocessorExecutor
/// </summary>
/// <param name="osmEntities"></param>
/// <returns>a list of preprocessed features</returns>
List<Feature> Preprocess(List<ICompleteOsmGeo> osmEntities);
List<IFeature> Preprocess(List<ICompleteOsmGeo> osmEntities);
/// <summary>
/// Preprocess highways into features - line strings
/// </summary>
/// <param name="highways"></param>
/// <returns></returns>
List<Feature> Preprocess(List<CompleteWay> highways);
List<IFeature> Preprocess(List<CompleteWay> highways);
}
}
Expand Up @@ -12,12 +12,12 @@ public interface IPointsOfInterestFilesCreatorExecutor
/// This function creates the sitemap.xml file inside the wwwroot folder
/// </summary>
/// <param name="features"></param>
void CreateSiteMapXmlFile(List<Feature> features);
void CreateSiteMapXmlFile(List<IFeature> features);

/// <summary>
/// This function creates the pois-slim.geojson file inside the wwwroot folder
/// </summary>
/// <param name="features"></param>
void CreateOfflinePoisFile(List<Feature> features);
void CreateOfflinePoisFile(List<IFeature> features);
}
}

0 comments on commit eef995a

Please sign in to comment.