Package de.innovationgate.eclipse.wgadesigner.wizards.export.webapp

Source Code of de.innovationgate.eclipse.wgadesigner.wizards.export.webapp.CheckWebApplicationExportPreconditionsPage

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/

package de.innovationgate.eclipse.wgadesigner.wizards.export.webapp;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.activation.DataSource;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.utils.ui.MultiTaskStatusControl;
import de.innovationgate.eclipse.utils.ui.ValidatedWizardPage;
import de.innovationgate.eclipse.utils.ui.model.TaskStatus;
import de.innovationgate.eclipse.utils.ui.model.TaskStatusModel;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.actions.StartWGARuntime;
import de.innovationgate.eclipse.wgadesigner.models.WGARemoteServer;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntime;
import de.innovationgate.eclipse.wgadesigner.tomcat.TomcatUtils;
import de.innovationgate.wga.config.ContentStore;
import de.innovationgate.wga.config.Domain;
import de.innovationgate.wga.config.WGAConfiguration;
import de.innovationgate.wgaservices.WGAServiceException;
import de.innovationgate.wgaservices.types.DatabaseServerInfo;
import de.innovationgate.wgaservices.types.Version;

public class CheckWebApplicationExportPreconditionsPage extends ValidatedWizardPage {

    private static final String  RUNTIME_STARTED_TASK = "runtime_started";
   
    private static final String  CONNECTION_TASK = "connection";
   
    private static final String REMOTE_VERSION_TASK = "remoteVersion";

    private static final String CONFIGURATION_TASK = "configuration";

    private static final String WEBAPP_TASK = "webapp";

    private static final String DOMAIN_TASK = "domain";

    private static final String DBSERVER_TASK = "dbserver";
   
    private WGARuntime _runtime;
    private WGARemoteServer _server;
    private String _webApplication;
    private Composite _container;
    private MultiTaskStatusControl _multiTaskStatusControl;
    private Map<String, TaskStatus> _taskStatusMap;

    private WGAConfiguration _config;
   

    private ArrayList<DatabaseServerInfo> _filteredServers;

   
    public CheckWebApplicationExportPreconditionsPage() {
        super("CheckWebApplicationExportPreconditionsPage");
        setTitle("Check of preconditions for application export");
    }

    @Override
    public void computeResponse() {       
    }

    @Override
    public List<IStatus> validate() {
        return null;
    }

    public void createControl(Composite parent) {
        _container = new Composite(parent, SWT.NULL);
        GridLayout layout = new GridLayout();
        layout.numColumns = 1;
        _container.setLayout(layout);

        _multiTaskStatusControl = new MultiTaskStatusControl(_container, SWT.NONE);
       
        _multiTaskStatusControl.setLayoutData(new GridData(GridData.FILL_BOTH));
       
        _taskStatusMap = new LinkedHashMap<String, TaskStatus>();
        _taskStatusMap.put(RUNTIME_STARTED_TASK, new TaskStatus("Local runtime started"));
        _taskStatusMap.put(CONNECTION_TASK, new TaskStatus("Remote server connection established"));     
        _taskStatusMap.put(REMOTE_VERSION_TASK, new TaskStatus("Remote server version >= 5.3"));
        _taskStatusMap.put(CONFIGURATION_TASK,new TaskStatus("Remote server configuration retrieved"));
        _taskStatusMap.put(WEBAPP_TASK,new TaskStatus("Database key for new web application available"));
        _taskStatusMap.put(DOMAIN_TASK,new TaskStatus("Domain for web application available"));
        _taskStatusMap.put(DBSERVER_TASK,new TaskStatus("Remote database servers for content store creation available"));
       
        List<TaskStatus> statusList = new ArrayList<TaskStatus>();
        statusList.addAll(_taskStatusMap.values());
        _multiTaskStatusControl.init(statusList);

        _multiTaskStatusControl.getRefreshButton().addSelectionListener(new SelectionListener() {
           
            public void widgetSelected(SelectionEvent e) {
                performCheck();              
            }
           
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
       
        GridData statusLayoutData = new GridData(GridData.FILL_BOTH);
        _multiTaskStatusControl.setLayoutData(statusLayoutData);
       
        setControl(_container);
    }

    private void performCheck() {
        setPageComplete(false);
        getShell().getDisplay().asyncExec(new Runnable() {
               
                public void run() {
                   
                    for (TaskStatus status : _taskStatusMap.values()) {
                        status.reset();
                        _multiTaskStatusControl.update(status);
                    }
                }
        });
       
        getShell().getDisplay().asyncExec(new Runnable() {

            public void run() {              
               
                boolean canFinish = true;
               
               
               
                TaskStatus taskStatus = _taskStatusMap.get(RUNTIME_STARTED_TASK);               
                // runtime started
                try {
                    if (TomcatUtils.getInstance().isRunning(_runtime)) {
                        taskStatus.setSeverity(TaskStatus.OK);
                        taskStatus.setMessage("running");
                        //taskStatus.setSeverityLabel("started");
                    } else {
                        taskStatus.setSeverity(TaskStatus.ERROR);
                        taskStatus.setMessage("Local runtime must be started to perform a web application export.");
                        //taskStatus.setSeverityLabel("not started");
                        canFinish = false;
                    }
                }
                catch (Exception e) {
                   taskStatus.setSeverity(TaskStatus.ERROR);
                   taskStatus.setMessage("Unable to check if local runtime is started.");
                   taskStatus.setException(e);
                   return;
                } finally {
                    _multiTaskStatusControl.update(taskStatus);
                }
               
                taskStatus = _taskStatusMap.get(CONNECTION_TASK);               
                // connect to server
                try {
                    _server.connectToServer();
                    taskStatus.setSeverity(TaskStatus.OK);
                    taskStatus.setMessage("OK");
                    //taskStatus.setSeverityLabel("established");
                }
                catch (Exception e) {
                   taskStatus.setSeverity(TaskStatus.ERROR);
                   taskStatus.setMessage("Connection to server failed.");
                   taskStatus.setException(e);
                   return;
                } finally {
                    _multiTaskStatusControl.update(taskStatus);
                }
               
                // check version
                taskStatus = _taskStatusMap.get(REMOTE_VERSION_TASK);               
                // connect to server
                try {
                    Version remoteWGAVersion = _server.getServices().getWGAVersion(_server.getSession());
                    if (remoteWGAVersion.isAtLeast(5, 3)) {
                        taskStatus.setSeverity(TaskStatus.OK);
                        taskStatus.setMessage("OK");
                    } else {
                        taskStatus.setSeverity(TaskStatus.ERROR);
                        taskStatus.setMessage("Version of remote server is too low ('" + remoteWGAVersion.getMajorVersion() + "." + remoteWGAVersion.getMinorVersion()+ "')");
                        taskStatus.setSeverityLabel("too low ('" + remoteWGAVersion.getMajorVersion() + "." + remoteWGAVersion.getMinorVersion()+ "')");
                        canFinish = false;
                    }
                }
                catch (Exception e) {
                   taskStatus.setSeverity(TaskStatus.ERROR);
                   taskStatus.setMessage("Version of remote server could not be retrieved. Properly a too low OpenWGA version is installed on the remote server.");
                   taskStatus.setSeverityLabel("too low");
                   taskStatus.setException(e);
                   canFinish = false;
                } finally {
                    _multiTaskStatusControl.update(taskStatus);
                }
               
                // retrieve config
                taskStatus = _taskStatusMap.get(CONFIGURATION_TASK);
                _config = null;
                try {
                    DataSource source = _server.getServices().getWGAConfiguration(_server.getSession());
                    _config = WGAConfiguration.read(source.getInputStream());
                    taskStatus.setSeverity(TaskStatus.OK);
                    taskStatus.setMessage("OK");
                    //taskStatus.setSeverityLabel("retrieved");
                    _multiTaskStatusControl.update(taskStatus);                   
                }
                catch (Exception e) {
                    taskStatus.setSeverity(TaskStatus.ERROR);
                    taskStatus.setMessage("Unable to retrieve WGA configuration.");
                    taskStatus.setException(e);                   
                    return;                                              
                } finally {
                    _multiTaskStatusControl.update(taskStatus);
                }
               
                taskStatus = _taskStatusMap.get(WEBAPP_TASK);
                try {
                    // check duplicate webapp
                    if (_config.getContentStore(_webApplication.toLowerCase()) == null) {                   
                        taskStatus.setSeverity(TaskStatus.OK);
                        taskStatus.setMessage("OK");                   
                    } else {
                        taskStatus.setSeverity(TaskStatus.ERROR);
                        taskStatus.setMessage("Web application '" + _webApplication + "' already exists on this server.");
                        //taskStatus.setSeverityLabel("duplicate");
                        canFinish = false;
                    }                   
                }
                catch (Exception e) {
                    taskStatus.setSeverity(TaskStatus.ERROR);
                    taskStatus.setMessage("Error occured during config check.");
                    taskStatus.setException(e);
                } finally {
                    _multiTaskStatusControl.update(taskStatus);
                }
               
                // check domain
                taskStatus = _taskStatusMap.get(DOMAIN_TASK);                  
                try {
                    // retrieve local domain
                    WGAConfiguration localConfig = _runtime.retrieveWGAConfig(false);
                    ContentStore localCS = localConfig.getContentStore(_webApplication.toLowerCase());
                    String localDomainUID = localCS.getDomain();
                    Domain localDomain = localConfig.getDomain(localDomainUID);
                    boolean hasDomain = false;
                    for (Domain remoteDomain : _config.getDomains()) {
                        if (remoteDomain.getName().equals(localDomain.getName())) {
                            hasDomain = true;
                        }
                    }
                    if (hasDomain) {
                        taskStatus.setSeverity(TaskStatus.OK);
                        taskStatus.setMessage("OK");       
                        //taskStatus.setSeverityLabel("exists");
                    } else {
                        taskStatus.setSeverity(TaskStatus.ERROR);
                        taskStatus.setMessage("Domain '" + localDomain.getName() + "' does not exist on server.");
                        //taskStatus.setSeverityLabel("missing");
                        canFinish = false;
                    }
                }
                catch (Exception e) {
                    taskStatus.setSeverity(TaskStatus.ERROR);
                    taskStatus.setMessage("Error occured during config check.");
                    taskStatus.setException(e);
                } finally {
                    _multiTaskStatusControl.update(taskStatus);   
                }
            
                // retrieve content store providing db servers
                taskStatus = _taskStatusMap.get(DBSERVER_TASK);                  
                try {
                    List<DatabaseServerInfo> dbServers = _server.getServices().retrieveContentStoreDatabaseServers(_server.getSession());
                    // filter servers
                    _filteredServers = new ArrayList<DatabaseServerInfo>();
                    for(DatabaseServerInfo info : dbServers) {
                        if (!info.getCreateableContentStoreImplemenations().isEmpty()) {
                            _filteredServers.add(info);
                        }
                    }
                   
                    if (!_filteredServers.isEmpty()) {
                        taskStatus.setSeverity(TaskStatus.OK);
                        taskStatus.setMessage("OK");
                        //taskStatus.setSeverityLabel("retrieved");
                    } else {
                        taskStatus.setSeverity(TaskStatus.ERROR);
                        taskStatus.setMessage("No database server available on remote location for web application export.");
                        //taskStatus.setSeverityLabel("retrieved but empty");
                        canFinish = false;
                    }
                }
                catch (Exception e) {
                    taskStatus.setSeverity(TaskStatus.ERROR);
                    taskStatus.setMessage("Error occured during db server retrieval.");
                    taskStatus.setException(e);                 
                } finally {
                    _multiTaskStatusControl.update(taskStatus);   
                }
               
                ExportWGAApplication wizard = (ExportWGAApplication)getWizard();
                wizard.setRemoteWGAConfiguration(_config);
               
                setPageComplete(canFinish);
            }
        });
                                      
    }

    public void show() {
        ExportWGAApplication wizard = (ExportWGAApplication)getWizard();
        _runtime = wizard.getRuntime();
        _webApplication = wizard.getWebApplication();
        _server = wizard.getRemoteServer();
        performCheck();
    }

    public List<DatabaseServerInfo> getAvailableDatabaseServers() {
        return _filteredServers;
    }
}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.wizards.export.webapp.CheckWebApplicationExportPreconditionsPage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.