All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.muenchen.oss.digiwf.verification.integration.configuration.VerificationConfiguration Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package de.muenchen.oss.digiwf.verification.integration.configuration;

import de.muenchen.oss.digiwf.verification.integration.registration.domain.service.RegistrationService;
import de.muenchen.oss.digiwf.verification.integration.verification.domain.service.VerificationService;
import de.muenchen.oss.digiwf.spring.cloudstream.utils.api.streaming.infrastructure.RoutingCallback;
import de.muenchen.oss.digiwf.spring.cloudstream.utils.api.streaming.message.service.CorrelateMessageService;
import de.muenchen.oss.digiwf.spring.cloudstream.utils.configuration.StreamingConfiguration;
import de.muenchen.oss.digiwf.verification.integration.registration.domain.service.LinkService;
import de.muenchen.oss.digiwf.verification.integration.shared.repository.VerificationRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.function.context.MessageRoutingCallback;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
@RequiredArgsConstructor
@AutoConfigureBefore({StreamingConfiguration.class})
@ComponentScan(basePackages = {"de.muenchen.oss.digiwf.verification.integration"})
@EnableConfigurationProperties({VerificationProperties.class})
public class VerificationConfiguration {

    private final VerificationProperties verificationProperties;

    public static final String TYPE_HEADER_GET_VERIFICATION_LINK = "getVerificationLink";

    /**
     * Configures the {@link LinkService}
     *
     * @return configured LinkService
     */
    @Bean
    @ConditionalOnMissingBean
    public LinkService getLinkService() {
        return new LinkService(verificationProperties.getBaseAddress());
    }

    /**
     * Configures the {@link RegistrationService}
     *
     * @return configured RegistrationService
     */
    @Bean
    @ConditionalOnMissingBean
    public RegistrationService getRegistrationService(final VerificationRepository verificationRepository, final LinkService linkService) {
        return new RegistrationService(verificationRepository, linkService);
    }

    /**
     * Configures the {@link VerificationService}
     *
     * @return configured VerificationService
     */
    @Bean
    @ConditionalOnMissingBean
    public VerificationService getVerificationService(final VerificationRepository verificationRepository, final CorrelateMessageService correlateMessageService) {
        return new VerificationService(verificationRepository, correlateMessageService);
    }

    /**
     * Override the custom router of the digiwf-spring-cloudstream-utils. We only have one type we need to map.
     *
     * @return the custom router
     */
    @Bean
    @ConditionalOnMissingBean
    public MessageRoutingCallback getEventBusRouter() {
        final Map typeMappings = new HashMap<>();
        typeMappings.put(TYPE_HEADER_GET_VERIFICATION_LINK, TYPE_HEADER_GET_VERIFICATION_LINK);
        return new RoutingCallback(typeMappings);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy