/// <summary> /// Adds extended data to point of interest object /// </summary> /// <param name="poiItem">The object to add properties to</param> /// <param name="feature">The feature for reference</param> /// <param name="language">he user interface language</param> /// <returns></returns> protected async Task AddExtendedData(PointOfInterestExtended poiItem, IFeature feature, string language) { foreach (var coordinate in feature.Geometry.Coordinates) { coordinate.Z = await _elevationDataStorage.GetElevation(coordinate); } poiItem.DataContainer = await _dataContainerConverterService.ToDataContainer(new FeatureCollection(new Collection <IFeature> { feature }).ToBytes(), poiItem.Title + ".geojson"); poiItem.Url = feature.Attributes.GetNames().Contains(FeatureAttributes.WEBSITE) ? feature.Attributes[FeatureAttributes.WEBSITE].ToString() : string.Empty; poiItem.ImagesUrls = feature.Attributes.GetNames() .Where(n => n.StartsWith(FeatureAttributes.IMAGE_URL)) .Select(n => feature.Attributes[n].ToString()) .ToArray(); poiItem.SourceImageUrl = feature.Attributes.GetNames().Contains(FeatureAttributes.SOURCE_IMAGE_URL) ? feature.Attributes[FeatureAttributes.SOURCE_IMAGE_URL].ToString() : string.Empty; poiItem.Description = GetAttributeByLanguage(feature.Attributes, FeatureAttributes.DESCRIPTION, language); poiItem.Rating = await _elasticSearchGateway.GetRating(poiItem.Id, poiItem.Source); poiItem.IsEditable = true; }
private void SetWebsiteUrl(TagsCollectionBase tags, PointOfInterestExtended pointOfInterest) { var regexp = new Regex("((https?://)|^)([a-z]+).wikipedia.org/wiki/(.*)"); var nonWikipediaUrls = new List <string>(); foreach (var url in pointOfInterest.References.Select(r => r.Url)) { var match = regexp.Match(url ?? string.Empty); if (!match.Success) { nonWikipediaUrls.Add(url); continue; } var language = match.Groups[3].Value; var pageTitle = Uri.UnescapeDataString(match.Groups[4].Value.Replace("_", " ")); var key = FeatureAttributes.WIKIPEDIA + ":" + language; tags.AddOrReplace(key, pageTitle); key = FeatureAttributes.WIKIPEDIA; pageTitle = language + ":" + pageTitle; if (tags.ContainsKey(key) == false) { tags.Add(key, pageTitle); } } SetMultipleValuesForTag(tags, FeatureAttributes.WEBSITE, nonWikipediaUrls.ToArray()); }
/// <inheritdoc /> public async Task <PointOfInterestExtended> AddPointOfInterest(PointOfInterestExtended pointOfInterest, TokenAndSecret tokenAndSecret, string language) { var osmGateway = _httpGatewayFactory.CreateOsmGateway(tokenAndSecret); var changesetId = await osmGateway.CreateChangeset("Add POI interface from IHM site."); var node = new Node { Latitude = pointOfInterest.Location.lat, Longitude = pointOfInterest.Location.lng, Tags = new TagsCollection { { FeatureAttributes.WEBSITE, pointOfInterest.Url } } }; for (var imageIndex = 0; imageIndex < pointOfInterest.ImagesUrls.Length; imageIndex++) { var imageUrl = pointOfInterest.ImagesUrls[imageIndex]; var tagName = imageIndex == 0 ? FeatureAttributes.IMAGE_URL : FeatureAttributes.IMAGE_URL + imageIndex; node.Tags.Add(tagName, imageUrl); } SetTagByLanguage(node.Tags, FeatureAttributes.NAME, pointOfInterest.Title, language); SetTagByLanguage(node.Tags, FeatureAttributes.DESCRIPTION, pointOfInterest.Description, language); AddTagsByIcon(node.Tags, pointOfInterest.Icon); RemoveEmptyTags(node.Tags); var id = await osmGateway.CreateElement(changesetId, node); node.Id = long.Parse(id); await osmGateway.CloseChangeset(changesetId); var feature = await UpdateElasticSearch(node, pointOfInterest.Title); return(await FeatureToExtendedPoi(feature, language)); }
public void UpdatePoint_SyncImages() { var gateway = SetupHttpFactory(); var pointOfInterest = new PointOfInterestExtended { ImagesUrls = new[] { "imageurl2", "imageurl1", "imageurl4" }, Id = "1", Icon = "oldIcon", Type = OsmGeoType.Node.ToString().ToLower() }; _dataContainerConverterService.ToDataContainer(Arg.Any <byte[]>(), Arg.Any <string>()).Returns(new DataContainer { routes = new List <RouteData>() }); gateway.GetNode(pointOfInterest.Id).Returns(new Node { Id = 1, Tags = new TagsCollection { new Tag("image", "imageurl1"), new Tag("image1", "imageurl3"), } }); var results = _adapter.UpdatePointOfInterest(pointOfInterest, null, "en").Result; CollectionAssert.AreEqual(pointOfInterest.ImagesUrls.OrderBy(i => i).ToArray(), results.ImagesUrls.OrderBy(i => i).ToArray()); }
public void UploadPointOfInterest_WithImageInRepository_ShouldNotUploadImage() { var user = new User { DisplayName = "DisplayName" }; _controller.SetupIdentity(_cache); _osmGateway.GetUserDetails().Returns(user); var poi = new PointOfInterestExtended { Title = "title", Source = Sources.OSM, Id = "1", Location = new LatLng(5, 6), ImagesUrls = new[] { "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//" + "8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", "http://link.com" } }; _imagesUrlsStorageExecutor.GetImageUrlIfExists(Arg.Any <MD5>(), Arg.Any <byte[]>()).Returns("some-url"); _controller.UploadPointOfInterest(poi, "he").Wait(); _wikimediaCommonGateway.DidNotReceive().UploadImage(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <Stream>(), Arg.Any <Coordinate>()); _wikimediaCommonGateway.DidNotReceive().GetImageUrl(Arg.Any <string>()); }
private async Task SetDataContainerAndLength(PointOfInterestExtended poiItem, Feature feature) { foreach (var coordinate in feature.Geometry.Coordinates) { coordinate.Z = await _elevationDataStorage.GetElevation(coordinate); } poiItem.FeatureCollection = new FeatureCollection { feature }; poiItem.DataContainer = await _dataContainerConverterService.ToDataContainer( poiItem.FeatureCollection.ToBytes(), poiItem.Title + ".geojson"); foreach (var coordinate in poiItem.DataContainer.Routes .SelectMany(r => r.Segments) .SelectMany(s => s.Latlngs) .Where(l => l.Alt == null || l.Alt.Value == 0)) { coordinate.Alt = await _elevationDataStorage.GetElevation(coordinate.ToCoordinate()); } foreach (var route in poiItem.DataContainer.Routes) { var itmRoute = route.Segments.SelectMany(s => s.Latlngs) .Select(l => _wgs84ItmMathTransform.Transform(l.ToCoordinate().ToDoubleArray())) .Select(c => c.ToCoordinate()).ToArray(); var skip1 = itmRoute.Skip(1); poiItem.LengthInKm += itmRoute.Zip(skip1, (curr, prev) => curr.Distance(prev)).Sum() / 1000; } }
public void UpdatePoint_SyncImages() { var gateway = SetupHttpFactory(); var pointOfInterest = new PointOfInterestExtended { ImagesUrls = new[] { "imageurl2", "imageurl1", "imageurl4" }, Id = "Node_1", Icon = "oldIcon", References = new Reference[0] }; _dataContainerConverterService.ToDataContainer(Arg.Any <byte[]>(), Arg.Any <string>()).Returns(new DataContainer { Routes = new List <RouteData>() }); gateway.GetNode(1).Returns(new Node { Id = 1, Tags = new TagsCollection { new Tag("image", "imageurl1"), new Tag("image1", "imageurl3"), } }); _elasticSearchGateway.GetContainers(Arg.Any <Coordinate>()).Returns(new List <Feature>()); var results = _adapter.UpdatePointOfInterest(pointOfInterest, new TokenAndSecret("", ""), "en").Result; CollectionAssert.AreEqual(pointOfInterest.ImagesUrls.OrderBy(i => i).ToArray(), results.ImagesUrls.OrderBy(i => i).ToArray()); }
public void UpdatePoint_DoNotUpdateInCaseTagsAreEqual() { var gateway = SetupHttpFactory(); var pointOfInterest = new PointOfInterestExtended { ImagesUrls = new[] { "imageurl2", "imageurl1" }, Id = "Node_1", Icon = "oldIcon", References = new Reference[0] }; _dataContainerConverterService.ToDataContainer(Arg.Any <byte[]>(), Arg.Any <string>()).Returns(new DataContainer { Routes = new List <RouteData>() }); gateway.GetNode(1).Returns(new Node { Id = 1, Tags = new TagsCollection { new Tag("image", "imageurl2"), new Tag("image1", "imageurl1"), } }); _elasticSearchGateway.GetContainers(Arg.Any <Coordinate>()).Returns(new List <Feature>()); _adapter.UpdatePointOfInterest(pointOfInterest, new TokenAndSecret("", ""), "en").Wait(); _elasticSearchGateway.DidNotReceive().UpdatePointsOfInterestData(Arg.Any <List <Feature> >()); gateway.DidNotReceive().CreateChangeset(Arg.Any <TagsCollection>()); gateway.DidNotReceive().CloseChangeset(Arg.Any <long>()); }
public void UpdatePointWithTwoIcon_ShouldUpdate() { var gateway = SetupHttpFactory(); var pointOfInterest = new PointOfInterestExtended { ImagesUrls = new string[0], Id = "Node_1", Icon = "icon-cave", Description = "new description", References = new Reference[0] }; _dataContainerConverterService.ToDataContainer(Arg.Any <byte[]>(), Arg.Any <string>()).Returns(new DataContainer { Routes = new List <RouteData>() }); gateway.GetNode(1).Returns(new Node { Id = 1, Tags = new TagsCollection { new Tag("historic", "archaeological_site"), new Tag("natural", "cave_entrance"), } }); _elasticSearchGateway.GetContainers(Arg.Any <Coordinate>()).Returns(new List <Feature>()); var results = _adapter.UpdatePointOfInterest(pointOfInterest, new TokenAndSecret("", ""), "en").Result; CollectionAssert.AreEqual(pointOfInterest.ImagesUrls.OrderBy(i => i).ToArray(), results.ImagesUrls.OrderBy(i => i).ToArray()); }
public void AddPointOfInterest_WikipediaMobildLink_ShouldUpdateOsmAndElasticSearch() { var gateway = SetupHttpFactory(); var language = "he"; gateway.CreateElement(Arg.Any <long>(), Arg.Any <Node>()).Returns(42); var pointOfInterestToAdd = new PointOfInterestExtended { Location = new LatLng(), ImagesUrls = new[] { "image1", "image2" }, Icon = _tagsHelper.GetCategoriesByType(Categories.POINTS_OF_INTEREST).First().Icon, References = new[] { new Reference { Url = "https://he.m.wikipedia.org/wiki/%D7%96%D7%95%D7%94%D7%A8_(%D7%9E%D7%95%D7%A9%D7%91)" } } }; _dataContainerConverterService.ToDataContainer(Arg.Any <byte[]>(), Arg.Any <string>()).Returns(new DataContainer { Routes = new List <RouteData>() }); _elasticSearchGateway.GetContainers(Arg.Any <Coordinate>()).Returns(new List <Feature>()); _wikipediaGateway.GetReference(Arg.Any <string>(), language).Returns(new Reference { Url = "Some-Url" }); var resutls = _adapter.AddPointOfInterest(pointOfInterestToAdd, new TokenAndSecret("", ""), language).Result; Assert.IsNotNull(resutls); _elasticSearchGateway.Received(1).UpdatePointsOfInterestData(Arg.Any <List <Feature> >()); gateway.Received().CreateElement(Arg.Any <long>(), Arg.Is <OsmGeo>(x => x.Tags[FeatureAttributes.WIKIPEDIA + ":" + language].Contains("זוהר"))); }
public void UpdatePoint_CreateWikipediaTag() { var gateway = SetupHttpFactory(); var pointOfInterest = new PointOfInterestExtended { ImagesUrls = new string[0], Id = "Node_1", Icon = "oldIcon", References = new[] { new Reference { Url = "http://en.wikipedia.org/wiki/Literary_Hall" } } }; _dataContainerConverterService.ToDataContainer(Arg.Any <byte[]>(), Arg.Any <string>()).Returns(new DataContainer { Routes = new List <RouteData>() }); gateway.GetElement("1", OsmGeoType.Node.ToString()).Returns(new Node { Id = 1, Tags = new TagsCollection { { FeatureAttributes.DESCRIPTION, "description" } } }); _elasticSearchGateway.GetContainers(Arg.Any <Coordinate>()).Returns(new List <Feature>()); _adapter.UpdatePointOfInterest(pointOfInterest, null, "en").Wait(); gateway.Received().UpdateElement(Arg.Any <string>(), Arg.Is <ICompleteOsmGeo>(x => x.Tags.ContainsKey(FeatureAttributes.WIKIPEDIA + ":en") && x.Tags.Contains(FeatureAttributes.WIKIPEDIA, "en:Literary Hall"))); }
/// <inheritdoc /> public async Task <PointOfInterestExtended> UpdatePointOfInterest(PointOfInterestExtended pointOfInterest, TokenAndSecret tokenAndSecret, string language) { var osmGateway = _httpGatewayFactory.CreateOsmGateway(tokenAndSecret); var id = pointOfInterest.Id; ICompleteOsmGeo completeOsmGeo = await osmGateway.GetElement(GeoJsonExtensions.GetOsmId(id), GeoJsonExtensions.GetOsmType(id)); var featureBeforeUpdate = ConvertOsmToFeature(completeOsmGeo, pointOfInterest.Title); var oldIcon = featureBeforeUpdate.Attributes[FeatureAttributes.ICON].ToString(); var oldTags = completeOsmGeo.Tags.ToArray(); SetWebsiteUrl(completeOsmGeo.Tags, pointOfInterest); SetTagByLanguage(completeOsmGeo.Tags, FeatureAttributes.NAME, pointOfInterest.Title, language); SetTagByLanguage(completeOsmGeo.Tags, FeatureAttributes.DESCRIPTION, pointOfInterest.Description, language); SyncImages(completeOsmGeo.Tags, pointOfInterest.ImagesUrls); if (pointOfInterest.Icon != oldIcon && pointOfInterest.Icon != SEARCH_ICON) { RemoveTagsByIcon(completeOsmGeo.Tags, oldIcon); AddTagsByIcon(completeOsmGeo.Tags, pointOfInterest.Icon); } RemoveEmptyTags(completeOsmGeo.Tags); if (AreTagsCollectionEqual(oldTags, completeOsmGeo.Tags.ToArray())) { return(pointOfInterest); } var changesetId = await osmGateway.CreateChangeset($"Updated {pointOfInterest.Title} using IsraelHiking.osm.org.il"); await osmGateway.UpdateElement(changesetId, completeOsmGeo); await osmGateway.CloseChangeset(changesetId); var featureToReturn = await UpdateElasticSearch(completeOsmGeo, pointOfInterest.Title); return(await FeatureToExtendedPoi(featureToReturn, language)); }
/// <inheritdoc /> public async Task <PointOfInterestExtended> AddPointOfInterest(PointOfInterestExtended pointOfInterest, TokenAndSecret tokenAndSecret, string language) { var osmGateway = CreateOsmGateway(tokenAndSecret); var changesetId = await osmGateway.CreateChangeset($"Added {pointOfInterest.Title} using IsraelHiking.osm.org.il"); var node = new Node { Latitude = pointOfInterest.Location.Lat, Longitude = pointOfInterest.Location.Lng, Tags = new TagsCollection() }; SetWebsiteUrl(node.Tags, pointOfInterest); SetMultipleValuesForTag(node.Tags, FeatureAttributes.IMAGE_URL, pointOfInterest.ImagesUrls); SetTagByLanguage(node.Tags, FeatureAttributes.NAME, pointOfInterest.Title, language); SetTagByLanguage(node.Tags, FeatureAttributes.DESCRIPTION, pointOfInterest.Description, language); AddTagsByIcon(node.Tags, pointOfInterest.Icon); RemoveEmptyTags(node.Tags); node.Id = await osmGateway.CreateElement(changesetId, node); await osmGateway.CloseChangeset(changesetId); var feature = await UpdateElasticSearch(node, pointOfInterest.Title); return(await FeatureToExtendedPoi(feature, language)); }
public async Task <IActionResult> UploadPointOfInterest([FromBody] PointOfInterestExtended pointOfInterest, [FromQuery] string language) { if (!pointOfInterest.Source.Equals(Sources.OSM, StringComparison.InvariantCultureIgnoreCase)) { return(BadRequest("OSM is the only supported source for this action...")); } if ((pointOfInterest.Description?.Length ?? 0) > 255) { return(BadRequest("Description must not be more than 255 characters...")); } if ((pointOfInterest.Title?.Length ?? 0) > 255) { return(BadRequest("Title must not be more than 255 characters...")); } var tokenAndSecret = _cache.Get(User.Identity.Name); var osmGateway = _clientsFactory.CreateOAuthClient(_options.OsmConfiguration.ConsumerKey, _options.OsmConfiguration.ConsumerSecret, tokenAndSecret.Token, tokenAndSecret.TokenSecret); var user = await osmGateway.GetUserDetails(); var imageUrls = pointOfInterest.ImagesUrls ?? new string[0]; for (var urlIndex = 0; urlIndex < imageUrls.Length; urlIndex++) { var fileName = string.IsNullOrWhiteSpace(pointOfInterest.Title) ? pointOfInterest.Icon.Replace("icon-", "") : pointOfInterest.Title; var file = _base64ImageConverter.ConvertToFile(imageUrls[urlIndex], fileName); if (file == null) { continue; } using (var md5 = MD5.Create()) { var imageUrl = await _imageUrlStoreExecutor.GetImageUrlIfExists(md5, file.Content); if (imageUrl != null) { imageUrls[urlIndex] = imageUrl; continue; } using (var memoryStream = new MemoryStream(file.Content)) { var imageName = await _wikimediaCommonGateway.UploadImage(pointOfInterest.Title, pointOfInterest.Description, user.DisplayName, file.FileName, memoryStream, pointOfInterest.Location.ToCoordinate()); imageUrls[urlIndex] = await _wikimediaCommonGateway.GetImageUrl(imageName); await _imageUrlStoreExecutor.StoreImage(md5, file.Content, imageUrls[urlIndex]); } } } if (string.IsNullOrWhiteSpace(pointOfInterest.Id)) { return(Ok(await _pointsOfInterestProvider.AddPointOfInterest(pointOfInterest, tokenAndSecret, language))); } return(Ok(await _pointsOfInterestProvider.UpdatePointOfInterest(pointOfInterest, tokenAndSecret, language))); }
public void UploadPointOfInterest_WrongSource_ShouldReturnBadRequest() { var poi = new PointOfInterestExtended { Source = "wrong source" }; var result = _controller.UploadPointOfInterest(poi, "he").Result as BadRequestObjectResult; Assert.IsNotNull(result); }
public void UploadPointOfInterest_IdExists_ShouldUpdate() { _controller.SetupIdentity(); var poi = new PointOfInterestExtended { Source = Sources.OSM, Id = "1" }; var result = _controller.UploadPointOfInterest(poi, "he").Result as OkObjectResult; Assert.IsNotNull(result); _pointsOfInterestProvider.Received(1).UpdatePointOfInterest(Arg.Any <PointOfInterestExtended>(), Arg.Any <TokenAndSecret>(), Arg.Any <string>()); }
private void SetWebsiteUrl(TagsCollectionBase tags, PointOfInterestExtended pointOfInterest) { var regexp = new Regex("((https?://)|^)([a-z]+).wikipedia.org/wiki/(.*)"); var match = regexp.Match(pointOfInterest.Url ?? string.Empty); if (match.Success) { tags.Add(FeatureAttributes.WIKIPEDIA, match.Groups[3].Value + ":" + WebUtility.UrlDecode(match.Groups[4].Value.Replace("_", " "))); } else { tags.Add(FeatureAttributes.WEBSITE, pointOfInterest.Url); } }
/// <summary> /// Adds extended data to point of interest object /// </summary> /// <param name="poiItem">The object to add properties to</param> /// <param name="feature">The feature for reference</param> /// <param name="language">he user interface language</param> /// <returns></returns> protected async Task AddExtendedData(PointOfInterestExtended poiItem, IFeature feature, string language) { poiItem.FeatureCollection = new FeatureCollection(new Collection <IFeature> { feature }); poiItem.Url = feature.Attributes.GetNames().Contains(FeatureAttributes.WEBSITE) ? feature.Attributes[FeatureAttributes.WEBSITE].ToString() : string.Empty; poiItem.ImageUrl = feature.Attributes.GetNames().Contains(FeatureAttributes.IMAGE_URL) ? feature.Attributes[FeatureAttributes.IMAGE_URL].ToString() : string.Empty; poiItem.Description = GetAttributeByLanguage(feature.Attributes, FeatureAttributes.DESCRIPTION, language); poiItem.Rating = await _elasticSearchGateway.GetRating(poiItem.Id, poiItem.Source); poiItem.IsEditable = true; }
public async Task <IActionResult> UploadPointOfInterest([FromBody] PointOfInterestExtended pointOfInterest, string language = "") { if (_adapters.ContainsKey(pointOfInterest.Source) == false) { return(BadRequest($"{pointOfInterest.Source} is not a know POIs source...")); } var adapter = _adapters[pointOfInterest.Source]; var tokenAndSecret = _cache.Get(User.Identity.Name); if (string.IsNullOrWhiteSpace(pointOfInterest.Id)) { return(Ok(await adapter.AddPointOfInterest(pointOfInterest, tokenAndSecret, language))); } return(Ok(await adapter.UpdatePointOfInterest(pointOfInterest, tokenAndSecret, language))); }
/// <inheritdoc /> public async Task <PointOfInterestExtended> UpdatePointOfInterest(PointOfInterestExtended pointOfInterest, TokenAndSecret tokenAndSecret, string language) { var osmGateway = _httpGatewayFactory.CreateOsmGateway(tokenAndSecret); var id = pointOfInterest.Id; ICompleteOsmGeo completeOsmGeo; if (pointOfInterest.Type == OsmGeoType.Node.ToString().ToLower()) { completeOsmGeo = await osmGateway.GetNode(id); } else if (pointOfInterest.Type == OsmGeoType.Way.ToString().ToLower()) { completeOsmGeo = await osmGateway.GetCompleteWay(id); } else if (pointOfInterest.Type == OsmGeoType.Relation.ToString().ToLower()) { completeOsmGeo = await osmGateway.GetCompleteRelation(id); } else { throw new ArgumentException(nameof(pointOfInterest.Type) + " is not known: " + pointOfInterest.Type); } var featureBeforeUpdate = ConvertOsmToFeature(completeOsmGeo, pointOfInterest.Title); var oldIcon = featureBeforeUpdate.Attributes[FeatureAttributes.ICON].ToString(); completeOsmGeo.Tags[FeatureAttributes.WEBSITE] = pointOfInterest.Url; SetTagByLanguage(completeOsmGeo.Tags, FeatureAttributes.NAME, pointOfInterest.Title, language); SetTagByLanguage(completeOsmGeo.Tags, FeatureAttributes.DESCRIPTION, pointOfInterest.Description, language); SyncImages(completeOsmGeo.Tags, pointOfInterest.ImagesUrls); if (pointOfInterest.Icon != oldIcon) { RemoveTagsByIcon(completeOsmGeo.Tags, oldIcon); AddTagsByIcon(completeOsmGeo.Tags, pointOfInterest.Icon); } RemoveEmptyTags(completeOsmGeo.Tags); var changesetId = await osmGateway.CreateChangeset("Update POI interface from IHM site."); await osmGateway.UpdateElement(changesetId, completeOsmGeo); await osmGateway.CloseChangeset(changesetId); var featureToReturn = await UpdateElasticSearch(completeOsmGeo, pointOfInterest.Title); return(await FeatureToExtendedPoi(featureToReturn, language)); }
/// <inheritdoc /> public async Task <PointOfInterestExtended> UpdatePointOfInterest(PointOfInterestExtended pointOfInterest, TokenAndSecret tokenAndSecret, string language) { var osmGateway = _httpGatewayFactory.CreateOsmGateway(tokenAndSecret); var feature = await _elasticSearchGateway.GetPointOfInterestById(pointOfInterest.Id, Sources.OSM); var id = pointOfInterest.Id; ICompleteOsmGeo completeOsmGeo; if (feature.Geometry is Point) { completeOsmGeo = await osmGateway.GetNode(id); } else if (feature.Geometry is LineString || feature.Geometry is Polygon) { completeOsmGeo = await osmGateway.GetCompleteWay(id); } else { completeOsmGeo = await osmGateway.GetCompleteRelation(id); } SetTagByLanguage(completeOsmGeo.Tags, FeatureAttributes.NAME, pointOfInterest.Title, language); SetTagByLanguage(completeOsmGeo.Tags, FeatureAttributes.DESCRIPTION, pointOfInterest.Description, language); completeOsmGeo.Tags[FeatureAttributes.IMAGE_URL] = pointOfInterest.ImageUrl; completeOsmGeo.Tags[FeatureAttributes.WEBSITE] = pointOfInterest.Url; var oldIcon = feature.Attributes[FeatureAttributes.ICON].ToString(); if (pointOfInterest.Icon != oldIcon) { RemoveTagsByIcon(completeOsmGeo.Tags, oldIcon); AddTagsByIcon(completeOsmGeo.Tags, pointOfInterest.Icon); } RemoveEmptyTags(completeOsmGeo.Tags); var changesetId = await osmGateway.CreateChangeset("Update POI interface from IHM site."); await osmGateway.UpdateElement(changesetId, completeOsmGeo); await osmGateway.CloseChangeset(changesetId); var featureToReturn = await UpdateElasticSearch(completeOsmGeo, pointOfInterest.Title); return(await FeatureToExtendedPoi(featureToReturn, language)); }
public async Task <IActionResult> UploadPointOfInterest([FromBody] PointOfInterestExtended pointOfInterest, [FromQuery] string language) { if (!pointOfInterest.Source.Equals(Sources.OSM, StringComparison.InvariantCultureIgnoreCase)) { return(BadRequest("OSM is the only supported source for this action...")); } var tokenAndSecret = _cache.Get(User.Identity.Name); var osmGateway = _httpGatewayFactory.CreateOsmGateway(tokenAndSecret); var user = await osmGateway.GetUser(); var imageUrls = pointOfInterest.ImagesUrls ?? new string[0]; for (var urlIndex = 0; urlIndex < imageUrls.Length; urlIndex++) { var url = imageUrls[urlIndex]; var fileName = string.IsNullOrWhiteSpace(pointOfInterest.Title) ? pointOfInterest.Icon.Replace("icon-", "") : pointOfInterest.Title; var file = _base64ImageConverter.ConvertToFile(url, fileName); if (file == null) { continue; } using (var memoryStream = new MemoryStream(file.Content)) { var imageName = await _wikimediaCommonGateway.UploadImage(pointOfInterest.Title, pointOfInterest.Description, user.DisplayName, file.FileName, memoryStream, new Coordinate().FromLatLng(pointOfInterest.Location)); url = await _wikimediaCommonGateway.GetImageUrl(imageName); imageUrls[urlIndex] = url; } } if (string.IsNullOrWhiteSpace(pointOfInterest.Id)) { return(Ok(await _pointsOfInterestProvider.AddPointOfInterest(pointOfInterest, tokenAndSecret, language))); } return(Ok(await _pointsOfInterestProvider.UpdatePointOfInterest(pointOfInterest, tokenAndSecret, language))); }
public void AddPointOfInterest_ShouldUpdateOsmAndElasticSearch() { var gateway = SetupHttpFactory(); gateway.CreateElement(Arg.Any <string>(), Arg.Any <Node>()).Returns("42"); var pointOfInterestToAdd = new PointOfInterestExtended { Location = new LatLng(), ImagesUrls = new string[0], Icon = _tagsHelper.GetIconsPerCategoryByType(Categories.POINTS_OF_INTEREST).Values.First().First().Icon }; _dataContainerConverterService.ToDataContainer(Arg.Any <byte[]>(), Arg.Any <string>()).Returns(new DataContainer { routes = new List <RouteData>() }); var resutls = _adapter.AddPointOfInterest(pointOfInterestToAdd, null, "he").Result; Assert.IsNotNull(resutls); _elasticSearchGateway.Received(1).UpdateNamesData(Arg.Any <Feature>()); }
public void UploadPointOfInterest_WithImageIdExists_ShouldUpdate() { var user = new User { DisplayName = "DisplayName" }; _controller.SetupIdentity(); _osmGateway.GetUser().Returns(user); var poi = new PointOfInterestExtended { Title = "title", Source = Sources.OSM, Id = "1", Location = new LatLng(5, 6), ImagesUrls = new [] { "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//" + "8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", "http://link.com" } }; _controller.UploadPointOfInterest(poi, "he").Wait(); _wikimediaCommonGateway.Received(1).UploadImage(poi.Title, poi.Description, user.DisplayName, "title.png", Arg.Any <Stream>(), Arg.Any <Coordinate>()); _wikimediaCommonGateway.Received(1).GetImageUrl(Arg.Any <string>()); }
/// <inheritdoc /> public Task <PointOfInterestExtended> UpdatePointOfInterest(PointOfInterestExtended pointOfInterest, TokenAndSecret tokenAndSecret, string language) { throw new Exception("OffRoad does not support updating."); }
/// <inheritdoc /> public Task <PointOfInterestExtended> UpdatePointOfInterest(PointOfInterestExtended pointOfInterest, TokenAndSecret tokenAndSecret, string language) { throw new Exception("Wikipedia does not support updating from this site."); }
/// <inheritdoc /> public Task <PointOfInterestExtended> UpdatePointOfInterest(PointOfInterestExtended pointOfInterest, TokenAndSecret tokenAndSecret, string language) { // Not supported throw new NotImplementedException(); }
/// <inheritdoc /> public Task <PointOfInterestExtended> AddPointOfInterest(PointOfInterestExtended pointOfInterest, TokenAndSecret tokenAndSecret, string language) { throw new Exception("Nakeb does not support adding."); }