Search in sources :

Example 1 with CountrySelectingStateController

use of uk.gov.ida.hub.policy.domain.controller.CountrySelectingStateController in project verify-hub by alphagov.

the class CountriesService method setSelectedCountry.

public void setSelectedCountry(SessionId sessionId, String countryCode) {
    ensureTransactionSupportsEidas(sessionId);
    List<EidasCountryDto> supportedCountries = getCountries(sessionId);
    Optional<EidasCountryDto> selectedCountry = supportedCountries.stream().filter(country -> country.getSimpleId().equals(countryCode)).findFirst();
    if (!selectedCountry.isPresent()) {
        throw new EidasCountryNotSupportedException(sessionId, countryCode);
    }
    Class<? extends State> expectedStateClass = SessionStartedState.class;
    if (sessionRepository.isSessionInState(sessionId, CountrySelectedState.class)) {
        expectedStateClass = CountrySelectedState.class;
    }
    CountrySelectingStateController countrySelectingStateController = (CountrySelectingStateController) sessionRepository.getStateController(sessionId, expectedStateClass);
    countrySelectingStateController.selectCountry(selectedCountry.get().getEntityId());
}
Also used : SessionId(uk.gov.ida.hub.policy.domain.SessionId) TransactionsConfigProxy(uk.gov.ida.hub.policy.proxy.TransactionsConfigProxy) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) CountrySelectedState(uk.gov.ida.hub.policy.domain.state.CountrySelectedState) EidasCountryDto(uk.gov.ida.hub.policy.domain.EidasCountryDto) CountrySelectingStateController(uk.gov.ida.hub.policy.domain.controller.CountrySelectingStateController) Collectors(java.util.stream.Collectors) SessionRepository(uk.gov.ida.hub.policy.domain.SessionRepository) Inject(javax.inject.Inject) EidasCountryNotSupportedException(uk.gov.ida.hub.policy.exception.EidasCountryNotSupportedException) List(java.util.List) State(uk.gov.ida.hub.policy.domain.State) Optional(java.util.Optional) CountrySelectingStateController(uk.gov.ida.hub.policy.domain.controller.CountrySelectingStateController) EidasCountryNotSupportedException(uk.gov.ida.hub.policy.exception.EidasCountryNotSupportedException) EidasCountryDto(uk.gov.ida.hub.policy.domain.EidasCountryDto) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState)

Aggregations

List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 EidasCountryDto (uk.gov.ida.hub.policy.domain.EidasCountryDto)1 SessionId (uk.gov.ida.hub.policy.domain.SessionId)1 SessionRepository (uk.gov.ida.hub.policy.domain.SessionRepository)1 State (uk.gov.ida.hub.policy.domain.State)1 CountrySelectingStateController (uk.gov.ida.hub.policy.domain.controller.CountrySelectingStateController)1 CountrySelectedState (uk.gov.ida.hub.policy.domain.state.CountrySelectedState)1 SessionStartedState (uk.gov.ida.hub.policy.domain.state.SessionStartedState)1 EidasCountryNotSupportedException (uk.gov.ida.hub.policy.exception.EidasCountryNotSupportedException)1 TransactionsConfigProxy (uk.gov.ida.hub.policy.proxy.TransactionsConfigProxy)1