Beispiel #1
0
        public async Task <IActionResult> Delete(
            [FromServices] AddressCrabEditClient editClient,
            [FromServices] IStreamStore streamStore,
            [FromServices] LegacyContext context,
            [FromRoute] string lokaleIdentificator,
            CancellationToken cancellationToken)
        {
            // TODO: Turn this into proper VBR API Validation
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var persistentLocalId = int.Parse(lokaleIdentificator);

            // todo: should become position from bus.Dispatch
            var position = await streamStore.ReadHeadPosition(cancellationToken);

            var addressId = context
                            .CrabIdToPersistentLocalIds
                            .SingleOrDefault(item => item.PersistentLocalId == persistentLocalId);

            CrabEditResponse deleteResponse = addressId != null
                ? await editClient.Delete(addressId, cancellationToken)
                : CrabEditResponse.NothingExecuted;

            return(AcceptedWithPosition(
                       position,
                       deleteResponse.ExecutionTime));
        }
Beispiel #2
0
        public async Task <IActionResult> Count(
            [FromServices] LegacyContext context,
            [FromServices] SyndicationContext syndicationContext,
            CancellationToken cancellationToken = default)
        {
            var filtering  = Request.ExtractFilteringRequest <StreetNameFilter>();
            var sorting    = Request.ExtractSortingRequest();
            var pagination = new NoPaginationRequest();

            if (_useProjectionsV2Toggle.FeatureEnabled)
            {
                return(Ok(
                           new TotaalAantalResponse
                {
                    Aantal = await new StreetNameListOsloQuery <StreetNameListItemV2>(context, syndicationContext)
                             .Fetch <StreetNameListItemV2, StreetNameListItemV2>(filtering, sorting, pagination)
                             .Items
                             .CountAsync(cancellationToken)
                }));
            }

            return(Ok(
                       new TotaalAantalResponse
            {
                Aantal = filtering.ShouldFilter
                        ? await new StreetNameListOsloQuery <StreetNameListItem>(context, syndicationContext)
                         .Fetch <StreetNameListItem, StreetNameListItem>(filtering, sorting, pagination)
                         .Items
                         .CountAsync(cancellationToken)
                        : Convert.ToInt32((await context
                                           .StreetNameListViewCount
                                           .FirstAsync(cancellationToken: cancellationToken))
                                          .Count)
            }));
        }
Beispiel #3
0
        public static async Task CreateNewAddressVersion <T>(
            this LegacyContext context,
            Guid addressId,
            Envelope <T> message,
            Action <AddressVersion> applyEventInfoOn,
            CancellationToken ct) where T : IHasProvenance
        {
            var addressVersion = await context
                                 .AddressVersions
                                 .LatestPosition(addressId, ct);

            if (addressVersion == null)
            {
                throw DatabaseItemNotFound(addressId);
            }

            var provenance = message.Message.Provenance;

            var newAddressVersion = addressVersion.CloneAndApplyEventInfo(
                message.Position,
                applyEventInfoOn);

            newAddressVersion.ApplyProvenance(provenance);

            await context
            .AddressVersions
            .AddAsync(newAddressVersion, ct);
        }
        public async Task <IActionResult> Get(
            [FromServices] LegacyContext context,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            [FromRoute] string postalCode,
            CancellationToken cancellationToken = default)
        {
            var postalInformation = await context
                                    .PostalInformation
                                    .AsNoTracking()
                                    .Include(item => item.PostalNames)
                                    .SingleOrDefaultAsync(item => item.PostalCode == postalCode, cancellationToken);

            if (postalInformation == null)
            {
                throw new ApiException("Onbestaande postcode.", StatusCodes.Status404NotFound);
            }

            return(Ok(
                       new PostalInformationOsloResponse(
                           responseOptions.Value.Naamruimte,
                           responseOptions.Value.ContextUrlDetail,
                           postalCode,
                           postalInformation.VersionTimestamp.ToBelgianDateTimeOffset(),
                           postalInformation.IsRetired
                        ? PostInfoStatus.Gehistoreerd
                        : PostInfoStatus.Gerealiseerd)
            {
                Postnamen = postalInformation
                            .PostalNames?
                            .Select(name => new Postnaam(new GeografischeNaam(name.Name, name.Language.ConvertFromLanguage())))
                            .ToList()
            }));
        }
        public async Task <IActionResult> Post(
            [FromServices] LegacyContext legacyContext,
            [FromServices] SyndicationContext syndicationContext,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            [FromBody] BosaStreetNameRequest request,
            CancellationToken cancellationToken = default)
        {
            if (Request.ContentLength.HasValue && Request.ContentLength > 0 && request == null)
            {
                return(Ok(new StreetNameBosaResponse()));
            }

            var filter = new StreetNameNameFilter(request);

            if (_useProjectionsV2Toggle.FeatureEnabled)
            {
                var streetNameBosaResponseV2 = await
                                               new StreetNameBosaQueryV2(
                    legacyContext,
                    syndicationContext,
                    responseOptions)
                                               .FilterAsync(filter, cancellationToken);

                return(Ok(streetNameBosaResponseV2));
            }

            var streetNameBosaResponse = await
                                         new StreetNameBosaQuery(
                legacyContext,
                syndicationContext,
                responseOptions)
                                         .FilterAsync(filter, cancellationToken);

            return(Ok(streetNameBosaResponse));
        }
        public async Task <IActionResult> List(
            [FromServices] LegacyContext legacyContext,
            [FromServices] IHostingEnvironment hostingEnvironment,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            [FromRoute] int persistentLocalId,
            CancellationToken cancellationToken = default)
        {
            var streetNameVersions =
                await legacyContext
                .StreetNameVersions
                .AsNoTracking()
                .Where(p => !p.Removed && p.PersistentLocalId == persistentLocalId)
                .ToListAsync(cancellationToken);

            if (!streetNameVersions.Any())
            {
                throw new ApiException("Onbestaande straatnaam.", StatusCodes.Status404NotFound);
            }

            return(Ok(
                       new StreetNameVersionListResponse
            {
                StraatnaamVersies = streetNameVersions
                                    .Select(m => new StreetNameVersionResponse(
                                                m.VersionTimestampAsDateTimeOffset,
                                                responseOptions.Value.DetailUrl,
                                                persistentLocalId))
                                    .ToList()
            }));
        }
        public async Task <IActionResult> Sync(
            [FromServices] IConfiguration configuration,
            [FromServices] LegacyContext context,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            CancellationToken cancellationToken = default)
        {
            var filtering  = Request.ExtractFilteringRequest <PostalInformationSyndicationFilter>();
            var sorting    = Request.ExtractSortingRequest();
            var pagination = Request.ExtractPaginationRequest();

            var pagedPostalInformationSet = new PostalInformationSyndicationQuery(
                context,
                filtering.Filter?.ContainsEvent ?? false,
                filtering.Filter?.ContainsObject ?? false)
                                            .Fetch(filtering, sorting, pagination);

            Response.AddPagedQueryResultHeaders(pagedPostalInformationSet);

            return(new ContentResult
            {
                Content = await BuildAtomFeed(pagedPostalInformationSet, responseOptions, configuration),
                ContentType = MediaTypeNames.Text.Xml,
                StatusCode = StatusCodes.Status200OK
            });
        }
        public async Task <IActionResult> Sync(
            [FromServices] IConfiguration configuration,
            [FromServices] LegacyContext context,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            CancellationToken cancellationToken = default)
        {
            var filtering  = Request.ExtractFilteringRequest <StreetNameSyndicationFilter>();
            var sorting    = Request.ExtractSortingRequest();
            var pagination = Request.ExtractPaginationRequest();

            var lastFeedUpdate = await context
                                 .StreetNameSyndication
                                 .AsNoTracking()
                                 .OrderByDescending(item => item.Position)
                                 .Select(item => item.SyndicationItemCreatedAt)
                                 .FirstOrDefaultAsync(cancellationToken);

            if (lastFeedUpdate == default)
            {
                lastFeedUpdate = new DateTimeOffset(2020, 1, 1, 0, 0, 0, TimeSpan.Zero);
            }

            var pagedStreetNames =
                new StreetNameSyndicationQuery(
                    context,
                    filtering.Filter?.Embed)
                .Fetch(filtering, sorting, pagination);

            return(new ContentResult
            {
                Content = await BuildAtomFeed(lastFeedUpdate, pagedStreetNames, responseOptions, configuration),
                ContentType = MediaTypeNames.Text.Xml,
                StatusCode = StatusCodes.Status200OK
            });
        }
Beispiel #9
0
        public static async Task Assert(this ConnectedProjectionTestSpecification <LegacyContext> specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException(nameof(specification));
            }

            var options = new DbContextOptionsBuilder <LegacyContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            using (var context = new LegacyContext(options))
            {
                context.Database.EnsureCreated();

                foreach (var message in specification.Messages)
                {
                    await new ConnectedProjector <LegacyContext>(specification.Resolver)
                    .ProjectAsync(context, message);

                    await context.SaveChangesAsync();
                }

                var result = await specification.Verification(context, CancellationToken.None);

                if (result.Failed)
                {
                    throw new AssertionFailedException(result.Message);
                }
            }
        }
Beispiel #10
0
        public void MigrateAll()
        {
            using (var context = new LegacyContext())
            {
                Func <DateTime, IEnumerable <WeatherStation> > query = (l) =>
                                                                       from r in context.WeatherStation.Where(RecordRangeFilter.BuildDateTimeRangeFilter(l))
                                                                       orderby r.Id ascending
                                                                       select(WeatherStation) r;

                DateTime last = WeatherService.GetLastTimestamp();
                if (last != DateTime.MinValue)
                {
                    last -= new TimeSpan(1, 0, 0, 0);
                }
                foreach (var l in query(last))
                {
                    WeatherService.Update(new Weather
                    {
                        Timestamp          = l.ConvertDateTime(),
                        WindDirection      = (int)l.WindDirection,
                        WindGust           = (float)l.WindGust,
                        WindSpeed          = (float)l.WindSpeed,
                        SolarRadiation     = (float)l.SolarRadiation,
                        RelativeHumidity   = (float)l.RelativeHumidity,
                        Temperature        = (float)l.Temperature,
                        Precipitation      = (float)l.Precipitation,
                        LeafWetnessCounts  = (float)l.LeafWetnessCounts,
                        LeafWetnessMinutes = (float)l.LeafWetnessMinutes
                    });
                }
            }
        }
        public async Task <IActionResult> List(
            [FromServices] LegacyContext context,
            [FromServices] IOptions <ResponseOptions> reponseOptions,
            CancellationToken cancellationToken = default)
        {
            var filtering  = Request.ExtractFilteringRequest <ParcelFilter>();
            var sorting    = Request.ExtractSortingRequest();
            var pagination = Request.ExtractPaginationRequest();

            var pagedParcels = new ParcelListQuery(context)
                               .Fetch(filtering, sorting, pagination);

            Response.AddPagedQueryResultHeaders(pagedParcels);

            var response = new ParcelListResponse
            {
                Percelen = await pagedParcels.Items
                           .Select(m => new ParcelListItemResponse(
                                       m.PersistentLocalId,
                                       reponseOptions.Value.Naamruimte,
                                       reponseOptions.Value.DetailUrl,
                                       m.VersionTimestamp.ToBelgianDateTimeOffset()))
                           .ToListAsync(cancellationToken),
                Volgende = BuildVolgendeUri(pagedParcels.PaginationInfo, reponseOptions.Value.VolgendeUrl)
            };

            return(Ok(response));
        }
        public async Task <IActionResult> Get(
            [FromServices] LegacyContext context,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            [FromRoute] string nisCode,
            CancellationToken cancellationToken = default)
        {
            var municipality =
                await context
                .MunicipalityDetail
                .AsNoTracking()
                .SingleOrDefaultAsync(item => item.NisCode == nisCode, cancellationToken);

            if (municipality == null)
            {
                throw new ApiException("Onbestaande gemeente.", StatusCodes.Status404NotFound);
            }

            return(Ok(
                       new MunicipalityResponse(
                           responseOptions.Value.Naamruimte,
                           municipality.Status.ConvertFromMunicipalityStatus(),
                           municipality.NisCode,
                           municipality.OfficialLanguages,
                           municipality.FacilitiesLanguages,
                           municipality.NameDutch,
                           municipality.NameFrench,
                           municipality.NameGerman,
                           municipality.NameEnglish,
                           municipality.VersionTimestamp.ToBelgianDateTimeOffset())));
        }
        public static async Task CreateNewParcelSyndicationItem <T>(
            this LegacyContext context,
            Guid parcelId,
            Envelope <T> message,
            Action <ParcelSyndicationItem> applyEventInfoOn,
            CancellationToken ct) where T : IHasProvenance
        {
            var parcelSyndicationItem = await context.LatestPosition(parcelId, ct);

            if (parcelSyndicationItem == null)
            {
                throw DatabaseItemNotFound(parcelId);
            }

            var provenance = message.Message.Provenance;

            var newParcelSyndicationItem = parcelSyndicationItem.CloneAndApplyEventInfo(
                message.Position,
                message.EventName,
                provenance.Timestamp,
                applyEventInfoOn);

            newParcelSyndicationItem.ApplyProvenance(provenance);
            newParcelSyndicationItem.SetEventData(message.Message);

            await context
            .ParcelSyndication
            .AddAsync(newParcelSyndicationItem, ct);
        }
        public async Task <IActionResult> Post(
            [FromServices] LegacyContext context,
            [FromServices] IOptions <ResponseOptions> reponseOptions,
            [FromBody] BosaMunicipalityRequest request,
            CancellationToken cancellationToken = default)
        {
            if (Request.ContentLength.HasValue && Request.ContentLength > 0 && request == null)
            {
                return(Ok(new MunicipalityBosaResponse()));
            }

            var filtering  = new MunicipalityBosaFilter(request);
            var sorting    = new SortingHeader(string.Empty, SortOrder.Ascending);
            var pagination = new PaginationRequest(0, 1000);

            var filteredMunicipalities = new MunicipalityBosaQuery(context).Fetch(
                new FilteringHeader <MunicipalityBosaFilter>(filtering),
                sorting,
                pagination);

            return(Ok(
                       new MunicipalityBosaResponse
            {
                Gemeenten = await filteredMunicipalities
                            .Items
                            .Select(m =>
                                    new MunicipalityBosaItemResponse(
                                        m.NisCode,
                                        reponseOptions.Value.Naamruimte,
                                        m.Version,
                                        GetGemeentenamenByLanguage(m, filtering.Language)))
                            .ToListAsync(cancellationToken),
            }));
        }
        public async Task <IActionResult> List(
            [FromServices] LegacyContext context,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            Taal?taal,
            CancellationToken cancellationToken = default)
        {
            var filtering  = Request.ExtractFilteringRequest <MunicipalityListFilter>();
            var sorting    = Request.ExtractSortingRequest();
            var pagination = Request.ExtractPaginationRequest();

            var pagedMunicipalities = new MunicipalityListQuery(context).Fetch(filtering, sorting, pagination);

            Response.AddPagedQueryResultHeaders(pagedMunicipalities);

            return(Ok(
                       new MunicipalityListResponse
            {
                Gemeenten = await pagedMunicipalities
                            .Items
                            .Select(m => new MunicipalityListItemResponse(
                                        m.NisCode,
                                        responseOptions.Value.Naamruimte,
                                        responseOptions.Value.DetailUrl,
                                        m.VersionTimestamp.ToBelgianDateTimeOffset(),
                                        new GeografischeNaam(m.DefaultName, m.OfficialLanguages.FirstOrDefault().ConvertFromLanguage()),
                                        m.Status))
                            .ToListAsync(cancellationToken),
                Volgende = BuildNextUri(pagedMunicipalities.PaginationInfo, responseOptions.Value.VolgendeUrl)
            }));
        }
 public async Task <IActionResult> Get(
     [FromServices] LegacyContext legacyContext,
     [FromServices] SyndicationContext syndicationContext,
     [FromServices] IOptions <ResponseOptions> responseOptions,
     [FromRoute] int persistentLocalId,
     CancellationToken cancellationToken = default)
 => Ok(await new StreetNameDetailQuery(legacyContext, syndicationContext, responseOptions).FilterAsync(persistentLocalId, cancellationToken));
        public async Task <IActionResult> List(
            [FromServices] SyndicationContext syndicationContext,
            [FromServices] LegacyContext legacyContext,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            Taal?taal,
            CancellationToken cancellationToken = default)
        {
            var filtering  = Request.ExtractFilteringRequest <StreetNameFilter>();
            var sorting    = Request.ExtractSortingRequest();
            var pagination = Request.ExtractPaginationRequest();

            var pagedStreetNames = new StreetNameListQuery(legacyContext, syndicationContext)
                                   .Fetch(filtering, sorting, pagination);

            Response.AddPagedQueryResultHeaders(pagedStreetNames);

            return(Ok(
                       new StreetNameListResponse
            {
                Straatnamen = await pagedStreetNames
                              .Items
                              .Select(m => new StreetNameListItemResponse(
                                          m.PersistentLocalId,
                                          responseOptions.Value.Naamruimte,
                                          responseOptions.Value.DetailUrl,
                                          GetGeografischeNaamByTaal(m, m.PrimaryLanguage),
                                          GetHomoniemToevoegingByTaal(m, m.PrimaryLanguage),
                                          m.Status.ConvertFromStreetNameStatus(),
                                          m.VersionTimestamp.ToBelgianDateTimeOffset()))
                              .ToListAsync(cancellationToken),
                Volgende = BuildNextUri(pagedStreetNames.PaginationInfo, responseOptions.Value.VolgendeUrl)
            }));
        }
 public StreetNameSyndicationQuery(
     LegacyContext context,
     SyncEmbedValue embed)
 {
     _context     = context;
     _embedEvent  = embed?.Event ?? false;
     _embedObject = embed?.Object ?? false;
 }
 public StreetNameSyndicationQuery(
     LegacyContext context,
     bool embedEvent,
     bool embedObject)
 {
     _context     = context;
     _embedEvent  = embedEvent;
     _embedObject = embedObject;
 }
 public StreetNameBosaQuery(
     LegacyContext legacyContext,
     SyndicationContext syndicationContext,
     IOptions <ResponseOptions> responseOptionsProvider)
 {
     _legacyContext           = legacyContext;
     _syndicationContext      = syndicationContext;
     _responseOptionsProvider = responseOptionsProvider;
 }
 public StreetNameDetailQuery(
     LegacyContext legacyContext,
     SyndicationContext syndicationContext,
     IOptions <ResponseOptions> responseOptionsProvider)
 {
     _legacyContext      = legacyContext;
     _syndicationContext = syndicationContext;
     _responseOptions    = responseOptionsProvider.Value;
 }
 public async Task <IActionResult> Count(
     [FromServices] LegacyContext context,
     CancellationToken cancellationToken = default)
 {
     return(Ok(
                new TotaalAantalResponse
     {
         Aantal = new CrabHouseNumberQuery(context).Count()
     }));
 }
Beispiel #23
0
        public async Task <IActionResult> PostBosaAddressRepresentations(
            [FromServices] LegacyContext context,
            [FromServices] SyndicationContext syndicationContext,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            [FromBody] BosaAddressRepresentationRequest request,
            CancellationToken cancellationToken = default)
        {
            if (Request.ContentLength.HasValue && Request.ContentLength > 0 && request == null)
            {
                return(Ok(new AddressRepresentationBosaResponse()));
            }

            if (string.IsNullOrEmpty(request?.AdresCode?.ObjectId) || !int.TryParse(request.AdresCode.ObjectId, out var addressId))
            {
                return(BadRequest("Valid objectId is required"));
            }

            var address = await context.AddressDetail.FirstOrDefaultAsync(x => x.PersistentLocalId == addressId, cancellationToken);

            if (address == null)
            {
                return(NotFound());
            }

            var streetName = await syndicationContext
                             .StreetNameBosaItems
                             .FirstOrDefaultAsync(x => x.StreetNameId == address.StreetNameId, cancellationToken);

            var municipality = await syndicationContext
                               .MunicipalityBosaItems
                               .FirstOrDefaultAsync(x => x.NisCode == streetName.NisCode, cancellationToken);

            var response = new AddressRepresentationBosaResponse
            {
                Identificator = new AdresIdentificator(responseOptions.Value.Naamruimte, address.PersistentLocalId.ToString(), address.VersionTimestamp.ToBelgianDateTimeOffset())
            };

            if (!request.Taal.HasValue || request.Taal.Value == municipality.PrimaryLanguage)
            {
                response.AdresVoorstellingen = new List <BosaAddressRepresentation>
                {
                    new BosaAddressRepresentation(
                        municipality.PrimaryLanguage.Value,
                        address.HouseNumber,
                        address.BoxNumber,
                        AddressMapper.GetVolledigAdres(address.HouseNumber, address.BoxNumber, address.PostalCode, streetName, municipality).GeografischeNaam.Spelling,
                        AddressMapper.GetDefaultMunicipalityName(municipality).Value,
                        AddressMapper.GetDefaultStreetNameName(streetName, municipality.PrimaryLanguage).Value,
                        address.PostalCode)
                };
            }

            return(Ok(response));
        }
 public static async Task <ParcelSyndicationItem> LatestPosition(
     this LegacyContext context,
     Guid parcelId,
     CancellationToken ct)
 => context
 .ParcelSyndication
 .Local
 .Where(x => x.ParcelId == parcelId)
 .OrderByDescending(x => x.Position)
 .FirstOrDefault()
 ?? await context
 .ParcelSyndication
 .Where(x => x.ParcelId == parcelId)
 .OrderByDescending(x => x.Position)
 .FirstOrDefaultAsync(ct);
 public static async Task <MunicipalityVersion> LatestPosition(
     this LegacyContext context,
     Guid municipalityId,
     CancellationToken ct)
 => context
 .MunicipalityVersions
 .Local
 .Where(x => x.MunicipalityId == municipalityId)
 .OrderByDescending(x => x.Position)
 .FirstOrDefault()
 ?? await context
 .MunicipalityVersions
 .Where(x => x.MunicipalityId == municipalityId)
 .OrderByDescending(x => x.Position)
 .FirstOrDefaultAsync(ct);
Beispiel #26
0
 public static async Task <PostalInformationSyndicationItem> LatestPosition(
     this LegacyContext context,
     string postalCode,
     CancellationToken ct)
 => context
 .PostalInformationSyndication
 .Local
 .Where(x => x.PostalCode == postalCode)
 .OrderByDescending(x => x.Position)
 .FirstOrDefault()
 ?? await context
 .PostalInformationSyndication
 .Where(x => x.PostalCode == postalCode)
 .OrderByDescending(x => x.Position)
 .FirstOrDefaultAsync(ct);
Beispiel #27
0
 public static async Task <StreetNameSyndicationItem> LatestPosition(
     this LegacyContext context,
     int persistentLocalId,
     CancellationToken ct)
 => context
 .StreetNameSyndication
 .Local
 .Where(x => x.PersistentLocalId == persistentLocalId)
 .OrderByDescending(x => x.Position)
 .FirstOrDefault()
 ?? await context
 .StreetNameSyndication
 .Where(x => x.PersistentLocalId == persistentLocalId)
 .OrderByDescending(x => x.Position)
 .FirstOrDefaultAsync(ct);
 public static async Task <StreetNameVersion> LatestPosition(
     this LegacyContext context,
     Guid streetNameId,
     CancellationToken ct)
 => context
 .StreetNameVersions
 .Local
 .Where(x => x.StreetNameId == streetNameId)
 .OrderByDescending(x => x.Position)
 .FirstOrDefault()
 ?? await context
 .StreetNameVersions
 .Where(x => x.StreetNameId == streetNameId)
 .OrderByDescending(x => x.Position)
 .FirstOrDefaultAsync(ct);
        public async Task <IActionResult> Get(
            [FromServices] LegacyContext legacyContext,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            [FromRoute] int persistentLocalId,
            [FromRoute] DateTimeOffset versie,
            CancellationToken cancellationToken = default)
        {
            var streetName = await legacyContext
                             .StreetNameVersions
                             .AsNoTracking()
                             .Where(x => !x.Removed)
                             .SingleOrDefaultAsync(item => item.PersistentLocalId == persistentLocalId && item.VersionTimestampAsDateTimeOffset == versie, cancellationToken);

            if (streetName != null && streetName.Removed)
            {
                throw new ApiException("Straatnaam verwijderd.", StatusCodes.Status410Gone);
            }

            if (streetName == null || !streetName.Complete)
            {
                throw new ApiException("Onbestaande straatnaam.", StatusCodes.Status404NotFound);
            }

            var gemeente = new StraatnaamDetailGemeente
            {
                ObjectId = streetName.NisCode,
                Detail   = string.Format(responseOptions.Value.GemeenteDetailUrl, streetName.NisCode),
                // TODO: get the name for this nisCode's municipality.
                // Not feasible yet, at least not yet without calling the Municipality Api.
                Gemeentenaam = new Gemeentenaam(new GeografischeNaam(null, Taal.NL))
            };

            return(Ok(
                       new StreetNameResponse(
                           responseOptions.Value.Naamruimte,
                           persistentLocalId,
                           streetName.Status.ConvertFromStreetNameStatus(),
                           gemeente,
                           streetName.VersionTimestampAsDateTimeOffset.Value,
                           streetName.NameDutch,
                           streetName.NameFrench,
                           streetName.NameGerman,
                           streetName.NameEnglish,
                           streetName.HomonymAdditionDutch,
                           streetName.HomonymAdditionFrench,
                           streetName.HomonymAdditionGerman,
                           streetName.HomonymAdditionEnglish)));
        }
Beispiel #30
0
        public static async Task CreateNewStreetNameSyndicationItem <T>(
            this LegacyContext context,
            int persistentLocalId,
            Envelope <T> message,
            Action <StreetNameSyndicationItem> applyEventInfoOn,
            CancellationToken ct) where T : IHasProvenance
        {
            var streetNameSyndicationItem = await context.LatestPosition(persistentLocalId, ct);

            if (streetNameSyndicationItem == null)
            {
                throw DatabaseItemNotFound(persistentLocalId);
            }

            await CreateNewSyndicationItem(context, message, applyEventInfoOn, streetNameSyndicationItem, ct);
        }