Search in sources :

Example 1 with StartupFormValidator

use of org.motechproject.server.web.validator.StartupFormValidator 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)1 MotechSettings (org.motechproject.config.domain.MotechSettings)1 StartupFormValidator (org.motechproject.server.web.validator.StartupFormValidator)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1