Exemple #1
0
        public void UploadRating_AddNewRating_ShouldReturnNewRating()
        {
            var poiId     = "poiId";
            var osmUserId = "42";
            var source    = "source";

            _controller.SetupIdentity(osmUserId);
            _elasticSearchGateway.GetRating(poiId, source).Returns(new Rating {
                Raters = new List <Rater>()
            });
            var resutls = _controller.UploadRating(new Rating {
                Id = poiId, Source = source, Raters = new List <Rater> {
                    new Rater {
                        Id = osmUserId, Value = 1
                    }
                }
            }).Result as OkObjectResult;

            Assert.IsNotNull(resutls);
            var returnedRating = resutls.Value as Rating;

            Assert.IsNotNull(returnedRating);
            Assert.AreEqual(1, returnedRating.Raters.Count);
            _elasticSearchGateway.Received(1).UpdateRating(Arg.Any <Rating>());
        }
Exemple #2
0
 public async Task <IActionResult> GetRating(string id, string source)
 {
     if (string.IsNullOrWhiteSpace(source))
     {
         return(BadRequest("Source is missing."));
     }
     if (string.IsNullOrWhiteSpace(id))
     {
         return(BadRequest("Id is missing."));
     }
     return(Ok(await _elasticSearchGateway.GetRating(id, source)));
 }
        /// <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");

            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(new Coordinate().FromLatLng(coordinate));
            }
            poiItem.Url        = GetWebsiteUrl(feature);
            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 = false;
        }
        /// <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;
        }
Exemple #5
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);
        }
Exemple #6
0
        /// <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;
        }