Exemple #1
0
        /// <summary>
        /// Adds extended data to point of interest object
        /// </summary>
        /// <param name="featureCollection">The features to convert</param>
        /// <param name="language">the user interface language</param>
        /// <returns></returns>
        protected async Task <PointOfInterestExtended> ConvertToPoiExtended(FeatureCollection featureCollection, string language)
        {
            var mainFeature = featureCollection.Features.Count == 1
                ? featureCollection.Features.First()
                : featureCollection.Features.First(f => f.Geometry is LineString);
            var poiItem = await ConvertToPoiItem <PointOfInterestExtended>(mainFeature, language);

            await SetDataContainerAndLength(poiItem, featureCollection);

            poiItem.References = GetReferences(mainFeature, language);
            poiItem.ImagesUrls = mainFeature.Attributes.GetNames()
                                 .Where(n => n.StartsWith(FeatureAttributes.IMAGE_URL))
                                 .Select(n => mainFeature.Attributes[n].ToString())
                                 .Where(n => !string.IsNullOrWhiteSpace(n))
                                 .ToArray();
            poiItem.Description = mainFeature.Attributes.GetByLanguage(FeatureAttributes.DESCRIPTION, language);
            poiItem.Rating      = await _elasticSearchGateway.GetRating(poiItem.Id, poiItem.Source);

            poiItem.IsEditable   = false;
            poiItem.Contribution = GetContribution(mainFeature.Attributes);
            var featureFromDatabase = await _elasticSearchGateway.GetPointOfInterestById(mainFeature.Attributes[FeatureAttributes.ID].ToString(), Source);

            if (featureFromDatabase != null)
            {
                poiItem.CombinedIds = featureFromDatabase.GetIdsFromCombinedPoi();
            }
            return(poiItem);
        }
        private async Task UpdatePointsOfInterest(OsmChange changes)
        {
            var deleteTasks            = new List <Task>();
            var relevantTagsDictionary = _tagsHelper.GetAllTags();

            foreach (var poiToRemove in changes.Delete)
            {
                var task = _elasticSearchGateway.DeleteOsmPointOfInterestById(poiToRemove.Type.ToString().ToLower() + "_" + poiToRemove.Id);
                deleteTasks.Add(task);
            }
            await Task.WhenAll(deleteTasks);

            var updateTasks = new List <Task <ICompleteOsmGeo> >();

            foreach (var poiToUpdate in changes.Modify
                     .Concat(changes.Create)
                     .Where(o => IsRelevantPointOfInterest(o, relevantTagsDictionary)))
            {
                var task = _osmGateway.GetCompleteElement(poiToUpdate.Id.Value, poiToUpdate.Type);
                updateTasks.Add(task);
            }
            var allElemets = await Task.WhenAll(updateTasks);

            var osmNamesDictionary = allElemets.GroupBy(e => e.Tags.GetName()).ToDictionary(g => g.Key, g => g.ToList());
            var features           = _osmGeoJsonPreprocessorExecutor.Preprocess(osmNamesDictionary);

            foreach (var poiToUpdate in changes.Modify
                     .Where(o => IsRelevantPointOfInterest(o, relevantTagsDictionary)))
            {
                var featureFromDb = await _elasticSearchGateway.GetPointOfInterestById(poiToUpdate.Type.ToString().ToLower() + "_" + poiToUpdate.Id, Sources.OSM);

                if (featureFromDb == null)
                {
                    continue;
                }
                var featureToUpdate = features.First(f => f.GetId().Equals(featureFromDb.GetId()));
                foreach (var attributeKey in featureFromDb.Attributes.GetNames().Where(n => n.StartsWith(FeatureAttributes.POI_PREFIX)))
                {
                    featureToUpdate.Attributes.AddOrUpdate(attributeKey, featureFromDb.Attributes[attributeKey]);
                }
                if (featureToUpdate.Geometry.OgcGeometryType == OgcGeometryType.Point &&
                    featureFromDb.Geometry.OgcGeometryType != OgcGeometryType.Point)
                {
                    featureToUpdate.Geometry = featureFromDb.Geometry;
                }
            }
            await _elasticSearchGateway.UpdatePointsOfInterestData(features);
        }
        public void TestUpdate_OsmChangeFileWithModification_ShouldUpdateDatabaseUsingPoiPrefixFromDatabase()
        {
            var way = new CompleteWay()
            {
                Id   = 1,
                Tags = new TagsCollection {
                    { "highway", "track" }, { "route", "bicycle" }
                },
                Nodes = new Node[0]
            };
            var changes = new OsmChange
            {
                Create = new OsmGeo[0],
                Modify = new OsmGeo[] { way.ToSimple() },
                Delete = new OsmGeo[0]
            };
            var wayFeature = new Feature(new LineString(new Coordinate[0]), new AttributesTable {
                { FeatureAttributes.ID, "1" },
                { FeatureAttributes.POI_SOURCE, Sources.OSM }
            });

            wayFeature.SetId();
            var wayFeatureInDatabase = new Feature(new LineString(new Coordinate[0]), new AttributesTable {
                { FeatureAttributes.ID, "1" },
                { FeatureAttributes.POI_CATEGORY, Categories.HISTORIC },
                { FeatureAttributes.POI_SOURCE, Sources.OSM }
            });

            wayFeatureInDatabase.SetId();
            var list = new List <Feature> {
                wayFeature
            };

            _geoJsonPreprocessorExecutor
            .Preprocess(Arg.Is <Dictionary <string, List <ICompleteOsmGeo> > >(x => x.Values.Count == 1))
            .Returns(list);
            _geoJsonPreprocessorExecutor
            .Preprocess(Arg.Is <List <CompleteWay> >(x => x.Count == 1))
            .Returns(list);
            _osmGateway.GetCompleteWay(1).Returns(way);
            _elasticSearchGateway.GetPointOfInterestById("way_1", Sources.OSM).Returns(wayFeatureInDatabase);

            _service.Update(changes).Wait();

            _elasticSearchGateway.Received(1).UpdatePointsOfInterestData(Arg.Is <List <Feature> >(x => x.Count == 1 && x.First().Attributes.Exists(FeatureAttributes.POI_CATEGORY)));
        }
Exemple #4
0
        public void GetPointsOfInterestById_RouteWithMultipleImagesAndDescriptionOnly_ShouldReturnIt()
        {
            var poiId   = "poiId";
            var feature = GetValidFeature(poiId, _adapter.Source);

            feature.Attributes.DeleteAttribute(FeatureAttributes.NAME);
            feature.Attributes.AddAttribute(FeatureAttributes.IMAGE_URL, FeatureAttributes.IMAGE_URL);
            feature.Attributes.AddAttribute(FeatureAttributes.IMAGE_URL + "1", FeatureAttributes.IMAGE_URL + "1");
            feature.Attributes.AddAttribute(FeatureAttributes.DESCRIPTION, FeatureAttributes.DESCRIPTION);
            feature.Attributes.AddAttribute(FeatureAttributes.POI_TYPE, FeatureAttributes.POI_TYPE);
            _elasticSearchGateway.GetPointOfInterestById(poiId, _adapter.Source, Arg.Any <string>()).Returns(feature);
            _dataContainerConverterService.ToDataContainer(Arg.Any <byte[]>(), Arg.Any <string>()).Returns(
                new DataContainer
            {
                routes = new List <RouteData>
                {
                    new RouteData
                    {
                        segments = new List <RouteSegmentData>
                        {
                            new RouteSegmentData(),
                            new RouteSegmentData()
                        }
                    }
                }
            });

            var result = _adapter.GetPointOfInterestById(poiId, null).Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(string.Empty, result.Title);
            Assert.AreEqual(FeatureAttributes.DESCRIPTION, result.Description);
            Assert.AreEqual(2, result.ImagesUrls.Length);
            Assert.AreEqual(FeatureAttributes.IMAGE_URL, result.ImagesUrls.First());
            Assert.IsTrue(result.IsRoute);
        }
        /// <inheritdoc />
        public async Task <PointOfInterestExtended> GetPointOfInterestById(string id, string language, string type = null)
        {
            var feature = await _elasticSearchGateway.GetPointOfInterestById(id, Sources.OSM, type);

            return(await FeatureToExtendedPoi(feature, language));
        }