org.jlot.client.executor.AddLocaleCommandExecutor Maven / Gradle / Ivy
package org.jlot.client.executor;
import java.util.Locale;
import java.util.Properties;
import javax.inject.Inject;
import org.jlot.client.configuration.Console;
import org.jlot.client.configuration.ProjectConfiguration;
import org.jlot.client.executor.spi.AbstractCommandExecutor;
import org.jlot.client.remote.LocalizationAddRestCommand;
import org.jlot.client.remote.rest.RestException;
import org.jlot.core.form.LocalizationForm;
import org.jlot.core.utils.VersionResolver;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@Component
public class AddLocaleCommandExecutor extends AbstractCommandExecutor
{
public static final String PROPERTY_KEY_LOCALE = "locale";
@Inject
private ProjectConfiguration projectConfiguration;
@Inject
private LocalizationAddRestCommand localizationAddRestCommand;
@Inject
private Console console;
@Inject
private VersionResolver versionResolver;
@Override
public boolean executeInternal ( Properties properties ) throws RestException
{
Locale locale = getLocale(properties);
LocalizationForm form = new LocalizationForm();
form.setJlotClientVersion(versionResolver.getJlotVersionName());
form.setProjectName(projectConfiguration.getProjectName());
form.setLocale(locale);
form.updateLastChangesDate();
localizationAddRestCommand.execute(form);
console.prompt("localizationAdd.success", locale.toString());
return true;
}
private Locale getLocale ( Properties properties )
{
String localeString = (String) properties.get(PROPERTY_KEY_LOCALE);
if (localeString == null)
{
localeString = getLocaleFromConsole();
}
Locale locale = StringUtils.parseLocaleString(localeString.trim());
return locale;
}
private String getLocaleFromConsole ( )
{
console.prompt("localizationAdd.locale.help");
return console.readLine("localizationAdd.locale.label");
}
}