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

org.zodiac.autoconfigure.application.DefaultApplicatuonBootstrapAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.application;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.zodiac.autoconfigure.web.HttpContextProperties;
import org.zodiac.commons.api.ErrorPromptMessageBuilder;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.commons.util.lang.Strings;

@SpringBootConfiguration
@Order(value = Ordered.HIGHEST_PRECEDENCE)
@EnableAspectJAutoProxy(proxyTargetClass = true)
// @AutoConfigureOrder(value = Ordered.HIGHEST_PRECEDENCE)
@ConditionalOnProperty(name = SystemPropertiesConstants.Zodiac.SPRING_MAIN_DEFAULT_BOOT_CONFIGURER,
    havingValue = "true", matchIfMissing = true)
public class DefaultApplicatuonBootstrapAutoConfiguration implements InitializingBean {

    /**
     * API prompt max length.
     */
    private static final int DEFAULT_PROMPT_MAX_LENGTH = 12;

    private final ApplicationContext applicationContext;
    private final HttpContextProperties httpContextProperties;

    public DefaultApplicatuonBootstrapAutoConfiguration(ApplicationContext applicationContext,
        ObjectProvider httpContextPropertiesProvider) {
        this.applicationContext = applicationContext;
        this.httpContextProperties = httpContextPropertiesProvider.getIfAvailable();
    }

    public void afterPropertiesSet() throws Exception {
        /*Sets API message prompt*/
        initializeErrorPrompt();
    }

    protected void initializeErrorPrompt() {
        Environment env = applicationContext.getEnvironment();
        String prompt = env.getProperty(SystemPropertiesConstants.Spring.SPRING_APP_NAME);
        if (Strings.blank(prompt)) {
            if (null != httpContextProperties) {
                prompt = httpContextProperties.getErrorPrompt();
            }
        }
        int promptMaxLength = null != httpContextProperties && 0 < httpContextProperties.getErrorPromptMaxLength()
            ? httpContextProperties.getErrorPromptMaxLength() : DEFAULT_PROMPT_MAX_LENGTH;
        if (prompt.length() < promptMaxLength) {
            ErrorPromptMessageBuilder.setPrompt(prompt);
        } else {
            ErrorPromptMessageBuilder.setPrompt(prompt.substring(0, promptMaxLength));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy