Search in sources :

Example 1 with ConfigSource

use of org.motechproject.config.core.domain.ConfigSource in project motech by motech.

the class StartupController method getStartupViewData.

@RequestMapping(value = "/startupviewdata", method = RequestMethod.GET)
@ResponseBody
public StartupViewData getStartupViewData(final HttpServletRequest request) {
    StartupViewData viewData = new StartupViewData();
    if (startupManager.canLaunchBundles()) {
        viewData.setRedirectHome(true);
        return viewData;
    } else {
        Locale userLocale = localeService.getUserLocale(request);
        ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI;
        boolean requiresConfigFiles = configSource.isFile() && configurationService.requiresConfigurationFiles();
        StartupForm startupSettings = new StartupForm();
        startupSettings.setLanguage(userLocale.getLanguage());
        viewData.setRequireConfigFiles(requiresConfigFiles);
        viewData.setSuggestions(createSuggestions());
        viewData.setStartupSettings(startupSettings);
        viewData.setLanguages(localeService.getSupportedLanguages());
        viewData.setPageLang(userLocale);
        viewData.setIsFileMode(ConfigSource.FILE.equals(configSource));
        viewData.setIsAdminRegistered(userService.hasActiveMotechAdmin());
        viewData.setRedirectHome(false);
    }
    return viewData;
}
Also used : Locale(java.util.Locale) ConfigSource(org.motechproject.config.core.domain.ConfigSource) StartupForm(org.motechproject.server.web.form.StartupForm) StartupViewData(org.motechproject.server.web.dto.StartupViewData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with ConfigSource

use of org.motechproject.config.core.domain.ConfigSource in project motech by motech.

the class StartupController method submitForm.

@RequestMapping(value = "/startup", method = RequestMethod.POST)
@ResponseBody
public List<String> submitForm(@RequestBody StartupForm startupSettings) throws IOException {
    ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI;
    StartupFormValidator startupFormValidator = startupFormValidatorFactory.getStartupFormValidator(startupSettings, userService);
    List<String> errors = startupFormValidator.validate(startupSettings, configurationService.getConfigSource());
    if (!errors.isEmpty()) {
        return errors;
    } else if (!startupManager.canLaunchBundles()) {
        if (ConfigSource.UI.equals(configSource)) {
            MotechSettings settings = startupManager.getDefaultSettings();
            settings.setLanguage(startupSettings.getLanguage());
            settings.setLoginModeValue(startupSettings.getLoginMode());
            settings.setProviderName(startupSettings.getProviderName());
            settings.setProviderUrl(startupSettings.getProviderUrl());
            configurationService.savePlatformSettings(settings);
            if (LoginMode.REPOSITORY.equals(LoginMode.valueOf(startupSettings.getLoginMode()))) {
                registerMotechAdmin(startupSettings);
            }
        } else {
            registerMotechAdmin(startupSettings);
        }
        startupManager.startup();
    }
    return errors;
}
Also used : ConfigSource(org.motechproject.config.core.domain.ConfigSource) MotechSettings(org.motechproject.config.domain.MotechSettings) StartupFormValidator(org.motechproject.server.web.validator.StartupFormValidator) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ConfigSource (org.motechproject.config.core.domain.ConfigSource)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 Locale (java.util.Locale)1 MotechSettings (org.motechproject.config.domain.MotechSettings)1 StartupViewData (org.motechproject.server.web.dto.StartupViewData)1 StartupForm (org.motechproject.server.web.form.StartupForm)1 StartupFormValidator (org.motechproject.server.web.validator.StartupFormValidator)1