com.greenpepper.confluence.actions.server.InstallationAction Maven / Gradle / Ivy
package com.greenpepper.confluence.actions.server;
import java.sql.Connection;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atlassian.confluence.velocity.htmlsafe.HtmlSafe;
import com.greenpepper.confluence.GreenPepperServerConfigurationActivator;
import com.greenpepper.server.GreenPepperServerException;
import com.greenpepper.server.database.SupportedDialects;
import com.greenpepper.util.I18nUtil;
/**
* InstallationAction class.
*
* @author oaouattara
* @version $Id: $Id
*/
@SuppressWarnings("serial")
public class InstallationAction
extends GreenPepperServerAction
{
private static final Logger log = LoggerFactory.getLogger(InstallationAction.class);
private static final String RESOURCE_BUNDLE = InstallationAction.class.getName();
private final ThreadLocal threadLocale = new ThreadLocal();
private ResourceBundle resourceBundle;
private String installType;
private String jndiUrl;
private String hibernateDialect;
private boolean editMode;
/** {@inheritDoc} */
@Override
public String getActionName(String fullClassName) {
return getText("greenpepper.install.title");
}
/**
* Constructor for InstallationAction.
*/
public InstallationAction()
{
}
/**
* config.
*
* @return a {@link java.lang.String} object.
*/
public String config() {
return SUCCESS;
}
/**
* getDialects.
*
* @return a {@link java.util.List} object.
*/
public List getDialects()
{
return Arrays.asList(SupportedDialects.values());
}
//We want to force edit mode if DBMS not ready
/**
* Getter for the field editMode
.
*
* @return a {@link java.lang.Boolean} object.
*/
public Boolean getEditMode() {
return editMode | !(isServerReady());
}
/**
* Setter for the field editMode
.
*
* @param editMode a {@link java.lang.Boolean} object.
*/
public void setEditMode(Boolean editMode) {
this.editMode = editMode;
}
/**
* getIsCustomSetup.
*
* @return a boolean.
*/
public boolean getIsCustomSetup()
{
return isCustomSetup();
}
/**
* isCustomSetup.
*
* @return a boolean.
*/
public boolean isCustomSetup()
{
return getInstallType().equals("customInstall");
}
/**
* Getter for the field installType
.
*
* @return a {@link java.lang.String} object.
*/
public String getInstallType()
{
return installType == null ? (getJndiUrl() == null ? "quickInstall" : "customInstall") : installType;
}
/**
* Setter for the field installType
.
*
* @param installType a {@link java.lang.String} object.
*/
public void setInstallType(String installType)
{
this.installType = installType;
}
/**
* changeInstallationType.
*
* @return a {@link java.lang.String} object.
*/
public String changeInstallationType()
{
return SUCCESS;
}
/**
* Getter for the field jndiUrl
.
*
* @return a {@link java.lang.String} object.
*/
public String getJndiUrl()
{
return jndiUrl == null ? getConfigurationActivator().getConfigJnriUrl() : jndiUrl;
}
/**
* Setter for the field jndiUrl
.
*
* @param jndiUrl a {@link java.lang.String} object.
*/
public void setJndiUrl(String jndiUrl)
{
this.jndiUrl = jndiUrl;
}
/**
* Getter for the field hibernateDialect
.
*
* @return a {@link java.lang.String} object.
*/
public String getHibernateDialect()
{
return hibernateDialect == null ? getConfigurationActivator().getConfigDialect() : hibernateDialect;
}
/**
* Setter for the field hibernateDialect
.
*
* @param hibernateDialect a {@link java.lang.String} object.
*/
public void setHibernateDialect(String hibernateDialect)
{
this.hibernateDialect = hibernateDialect;
}
/**
* {@inheritDoc}
*
* Custom I18n. Based on WebWork i18n.
*/
@HtmlSafe
public String getText(String key)
{
String text = super.getText(key);
if (text.equals(key))
{
text = I18nUtil.getText(key, getResourceBundle());
}
return text;
}
private ResourceBundle getResourceBundle() {
if (resourceBundle == null)
{
Locale locale = threadLocale.get();
if (locale == null)
{
locale = getLocale();
threadLocale.set(locale == null ? Locale.ENGLISH : locale);
}
resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE, locale);
}
return resourceBundle;
}
/**
* isSetupComplete.
*
* @return a boolean.
*/
public boolean isSetupComplete()
{
return gpUtil.isServerSetupComplete();
}
/**
* isServerReady.
*
* @return a boolean.
*/
public boolean isServerReady()
{
return gpUtil.isServerReady();
}
/**
* editDbmsConfiguration.
*
* @return a {@link java.lang.String} object.
*/
public String editDbmsConfiguration()
{
try
{
if (isCustomSetup())
{
if (hibernateDialect != null && jndiUrl != null)
{
if (canConnectToDbms())
{
getConfigurationActivator().initCustomInstallConfiguration(hibernateDialect, jndiUrl);
}
else
{
addActionError("greenpepper.install.dbms.test.failure");
}
}
}
else
{
getConfigurationActivator().initQuickInstallConfiguration();
}
}
catch (GreenPepperServerException ex)
{
addActionError("greenpepper.install.dbms.init.failure");
}
return SUCCESS;
}
/**
* testDbmsConnection.
*
* @return a {@link java.lang.String} object.
*/
public String testDbmsConnection()
{
if (!canConnectToDbms())
{
addActionError("greenpepper.install.dbms.test.failure");
}
return SUCCESS;
}
private boolean canConnectToDbms()
{
try
{
InitialContext context = new InitialContext();
DataSource ds = (DataSource)context.lookup(jndiUrl);
Connection connection = ds.getConnection();
connection.close();
return true;
}
catch (Exception ex)
{
log.error("Testing Dbms Connection using jndi (" + jndiUrl + ")", ex);
return false;
}
}
private GreenPepperServerConfigurationActivator getConfigurationActivator() {
return gpUtil.getGPServerConfigurationActivator();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy