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

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

/*******************************************************************************
* 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.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.activation.DataSource;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.layout.GridDataFactory;
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.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;

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.models.WGARemoteServer;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntime;
import de.innovationgate.utils.WGUtils;
import de.innovationgate.wga.config.WGAConfiguration;
import de.innovationgate.wgaservices.WGAServiceException;
import de.innovationgate.wgaservices.types.DatabaseInformation;
import de.innovationgate.wgaservices.types.DatabaseServerInfo;
import de.innovationgate.wgaservices.types.FSDesignResourceState;
import de.innovationgate.wgaservices.types.PluginInfo;

public class WebApplicationExportSummaryPage extends ValidatedWizardPage {

    private static final String DBNAME_TASK = "dbname";

    private static final String DESIGN_TASK = "design";

    private static final String PLUGINS_TASK = "plugins";

    private Composite _container;
    private MultiTaskStatusControl _multiTaskStatusControl;
    private Map<String, TaskStatus> _taskStatusMap;

    private Label _lblLocalRuntime;

    private Label _lblRemoteLocation;

    private Label _lblWebApplication;

    private Label _lblRemoteDatabaseServer;

    private Label _lblRemoteDatabaseName;

    private Button _chkCopyLocalContent;

    private Button _chkIncludeACL;
   
    public WebApplicationExportSummaryPage() {
        super("WebApplicationExportSummaryPage");
        setTitle("Web application export summary");
    }

    @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 = 2;
        _container.setLayout(layout);

        Label label = new Label(_container, SWT.NONE);
        label.setText("Local runtime:");       
        _lblLocalRuntime = new Label(_container, SWT.NONE);
        _lblLocalRuntime.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
       
        label = new Label(_container, SWT.NONE);
        label.setText("Local web application:");       
        _lblWebApplication = new Label(_container, SWT.NONE);
        _lblWebApplication.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));       
       
        label = new Label(_container, SWT.NONE);
        label.setText("Remote location:");       
        _lblRemoteLocation = new Label(_container, SWT.NONE);
        _lblRemoteLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
       
        label = new Label(_container, SWT.NONE);
        label.setText("Remote database server:");       
        _lblRemoteDatabaseServer = new Label(_container, SWT.NONE);
        _lblRemoteDatabaseServer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
       
        label = new Label(_container, SWT.NONE);
        label.setText("Remote database name:");       
        _lblRemoteDatabaseName = new Label(_container, SWT.NONE);
        _lblRemoteDatabaseName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
       
        label = new Label(_container, SWT.NONE);
       
        GridData chkGridData = new GridData(GridData.FILL_HORIZONTAL);       
        _chkCopyLocalContent = new Button(_container, SWT.CHECK);
        _chkCopyLocalContent.setText("copy local content");
        _chkCopyLocalContent.setLayoutData(chkGridData);
        _chkCopyLocalContent.setEnabled(false);
       
        label = new Label(_container, SWT.NONE);
       
        _chkIncludeACL = new Button(_container, SWT.CHECK);
        _chkIncludeACL.setText("include ACL on content copy");
        _chkIncludeACL.setLayoutData(GridDataFactory.copyData(chkGridData));
        _chkIncludeACL.setEnabled(false);
       
        _multiTaskStatusControl = new MultiTaskStatusControl(_container, SWT.NONE);
       
        _multiTaskStatusControl.setLayoutData(new GridData(GridData.FILL_BOTH));
       
        _taskStatusMap = new LinkedHashMap<String, TaskStatus>();
        _taskStatusMap.put(DBNAME_TASK, new TaskStatus("Name for new database is available on database server"));              
        _taskStatusMap.put(DESIGN_TASK,new TaskStatus("WebTML design"));
        _taskStatusMap.put(PLUGINS_TASK,new TaskStatus("Plugin status:"));
       
        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);
        statusLayoutData.horizontalSpan = 2;
        _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;
               
                ExportWGAApplication wizard = (ExportWGAApplication) getWizard();
               
                TaskStatus taskStatus = _taskStatusMap.get(DBNAME_TASK);
                try {
                    DatabaseInformation dbInfo = new DatabaseInformation();
                    dbInfo.setImplementationClass(wizard.getRemoteDatabaseServer().getCreateableContentStoreImplemenations().get(0));
                    dbInfo.getOptions().put(ExportWGAApplication.CS_PATH_OPTION_NAME, wizard.getRemoteDatabaseName());
                    List<DatabaseInformation> dbInfos = wizard.getRemoteServer().getServices().getAvailableDatabases(wizard.getRemoteServer().getSession(), wizard.getRemoteDatabaseServer(), dbInfo.getImplementationClass());
                    if (dbInfos.contains(dbInfo)) {
                        taskStatus.setSeverity(TaskStatus.ERROR);
                        //taskStatus.setSeverityLabel("duplicate database name");
                        taskStatus.setMessage("A database with name '" + dbInfo.getOptions().get(ExportWGAApplication.CS_PATH_OPTION_NAME) + "' already exists on the database server.");
                        canFinish = false;
                    } else {
                        taskStatus.setSeverity(TaskStatus.OK);
                        taskStatus.setMessage("OK");                       
                    }
                } catch (Exception e) {
                    taskStatus.setSeverity(TaskStatus.ERROR);
                    taskStatus.setMessage("Error occured during duplicate database check.");
                    taskStatus.setException(e);
                } finally {
                    _multiTaskStatusControl.update(taskStatus);
                }
               
                taskStatus = _taskStatusMap.get(DESIGN_TASK);
                try {
                    IContainer designContainer = wizard.getRuntime().getConnectedDesignContainers().get(wizard.getWebApplication());
                    List<FSDesignResourceState> state = wizard.getRemoteServer().getServices().retrieveFSDesignResourceState(wizard.getRemoteServer().getSession(), designContainer.getName());
                    if (!state.isEmpty()) {
                        taskStatus.setSeverity(TaskStatus.WARNING);
                        taskStatus.setMessage("Design for web application already exist on remote server. The design will not be committed during this export. Please sync changes via design synchronization dialog after export.");
                        taskStatus.setSeverityLabel("already exists");
                    } else {
                        taskStatus.setSeverity(TaskStatus.OK);
                        taskStatus.setSeverityLabel("will be created");
                    }
                } catch (Exception e) {
                    taskStatus.setSeverity(TaskStatus.ERROR);
                    taskStatus.setMessage("Error occured during design status check.");
                    taskStatus.setException(e);
                } finally {
                    _multiTaskStatusControl.update(taskStatus);
                }
               
                taskStatus = _taskStatusMap.get(PLUGINS_TASK);
                try {
                    WGARemoteServer local = wizard.getRuntime().createRemoteServer();
                    local.connectToServer();
                    List<PluginInfo> localPluginInfos = local.getServices().getPluginInformation(local.getSession());                   
                    List<PluginInfo> remotePluginInfos = wizard.getRemoteServer().getServices().getPluginInformation(wizard.getRemoteServer().getSession());
                   
                    List<PluginInfo> pluginsMissing = new ArrayList<PluginInfo>();
                    Map<PluginInfo, PluginInfo> pluginsDifferent = new HashMap<PluginInfo, PluginInfo>();
                    for (PluginInfo localInfo: localPluginInfos) {
                        if (localInfo.isActive() && localInfo.isValid() && !localInfo.isPlatformPlugin()) {
                            PluginInfo remoteInfo = retrieveActiveByUniqueName(remotePluginInfos, localInfo.getUniqueName());
                            if (remoteInfo == null) {
                                pluginsMissing.add(localInfo);
                            } else {
                                if (!remoteInfo.getVersion().equals(localInfo.getVersion())) {
                                    pluginsDifferent.put(localInfo, remoteInfo);
                                }
                            }
                        }
                    }
                   
                    taskStatus.setSeverityLabel(pluginsMissing.size() + " missing, " + pluginsDifferent.size() + " different");
                    if (!pluginsMissing.isEmpty() || !pluginsDifferent.isEmpty()) {
                        taskStatus.setSeverity(TaskStatus.WARNING);                       
                        StringBuffer status = new StringBuffer();
                        if (!pluginsMissing.isEmpty()) {                           
                            status.append("The following plugins are missing on the remote server:\n");                          
                            for (int i=0; i < pluginsMissing.size(); i++) {
                                PluginInfo info = pluginsMissing.get(i);
                                status.append("- " + info.getUniqueName() + " (" + info.getVersion() ")");
                                status.append("\n");
                            }
                           
                        }
                        if (!pluginsDifferent.isEmpty()) {
                            status.append("The following plugins have different versions on the remote server:\n");
                            Iterator<PluginInfo> localInfos = pluginsDifferent.keySet().iterator();
                            while (localInfos.hasNext()) {
                                PluginInfo info = localInfos.next();
                                PluginInfo remote = pluginsDifferent.get(info);
                                status.append("- " + info.getUniqueName() + " (" + info.getVersion() + " != " + remote.getVersion() + ")");
                                status.append("\n");
                            }
                        }
                        taskStatus.setMessage(status.toString());
                    } else {
                        taskStatus.setSeverity(TaskStatus.OK);
                    }
                } catch (Exception e) {
                    taskStatus.setSeverity(TaskStatus.ERROR);
                    taskStatus.setMessage("Error occured during plugin compare.");
                    taskStatus.setException(e);
                } finally {
                    _multiTaskStatusControl.update(taskStatus);
                }               
               
                setPageComplete(canFinish);
            }

            private PluginInfo retrieveActiveByUniqueName(List<PluginInfo> infos, String uniqueName) {
                for(PluginInfo info : infos) {
                    if (info.getUniqueName().equals(uniqueName) && info.isActive() && info.isValid()) {
                        return info;
                    }
                }
                return null;
            }
        });
                                           
    }

    public void show() {
        ExportWGAApplication wizard = (ExportWGAApplication) getWizard();
        _lblLocalRuntime.setText(wizard.getRuntime().getName());
        _lblRemoteLocation.setText(wizard.getRemoteServer().getUrl().toString());
        _lblWebApplication.setText(wizard.getWebApplication());
        _lblRemoteDatabaseServer.setText(wizard.getRemoteDatabaseServer().getTitle());
        _lblRemoteDatabaseName.setText(wizard.getRemoteDatabaseName());
        _chkCopyLocalContent.setSelection(wizard.isCopyContent());
        _chkIncludeACL.setSelection(wizard.isIncludeACL());
        performCheck();
    }
}
TOP

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

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.