Search in sources :

Example 1 with WarningException

use of org.talend.commons.exception.WarningException in project tdi-studio-se by Talend.

the class LoginHelper method getProjects.

public Project[] getProjects(ConnectionBean connBean, ErrorManager errorManager) {
    if (connBean == null) {
        return null;
    }
    Project[] projects = null;
    if (connBean != null) {
        String user2 = connBean.getUser();
        String repositoryId2 = connBean.getRepositoryId();
        String workSpace = connBean.getWorkSpace();
        String name = connBean.getName();
        if (//$NON-NLS-1$ //$NON-NLS-2$
        user2 != null && !"".equals(user2) && repositoryId2 != null && !"".equals(repositoryId2) && workSpace != null && !"".equals(workSpace) && name != null && !"".equals(name)) {
            //$NON-NLS-1$ //$NON-NLS-2$
            boolean valid = false;
            if (isRemoteConnection(connBean)) {
                String url = connBean.getDynamicFields().get(RepositoryConstants.REPOSITORY_URL);
                //$NON-NLS-1$
                valid = url != null && !"".equals(url);
            } else {
                valid = Pattern.matches(RepositoryConstants.MAIL_PATTERN, user2);
            }
            connBean.setComplete(valid);
        }
    }
    ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    repositoryFactory.setRepositoryFactoryFromProvider(RepositoryFactoryProvider.getRepositoriyById(connBean.getRepositoryId()));
    if (!connBean.isComplete()) {
        return projects;
    }
    boolean initialized = false;
    //$NON-NLS-1$
    final String newLine = ":\n";
    try {
        try {
            repositoryFactory.checkAvailability();
        } catch (WarningException e) {
            String warnings = e.getMessage();
            if (warnings != null && !warnings.equals(lastWarnings)) {
                lastWarnings = warnings;
                if (errorManager != null) {
                    errorManager.setWarnMessage(warnings);
                } else {
                    final Shell shell = new Shell(DisplayUtils.getDisplay(), SWT.ON_TOP | SWT.TOP);
                    //$NON-NLS-1$
                    MessageDialog.openWarning(shell, Messages.getString("LoginComposite.warningTitle"), warnings);
                }
            }
        }
        OverTimePopupDialogTask<Boolean> overTimePopupDialogTask = new OverTimePopupDialogTask<Boolean>() {

            @Override
            public Boolean run() throws Throwable {
                ProxyRepositoryFactory.getInstance().initialize();
                return null;
            }
        };
        overTimePopupDialogTask.setNeedWaitingProgressJob(false);
        overTimePopupDialogTask.runTask();
        initialized = true;
    } catch (Throwable e) {
        projects = new Project[0];
        if (errorManager != null) {
            //$NON-NLS-1$
            errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
        } else {
            final Shell shell = new Shell(DisplayUtils.getDisplay(), SWT.ON_TOP | SWT.TOP);
            //$NON-NLS-1$
            MessageDialog.openError(//$NON-NLS-1$
            shell, //$NON-NLS-1$
            Messages.getString("LoginComposite.warningTitle"), //$NON-NLS-1$
            Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
        }
    }
    if (initialized) {
        try {
            OverTimePopupDialogTask<Project[]> overTimePopupDialogTask = new OverTimePopupDialogTask<Project[]>() {

                @Override
                public Project[] run() throws Throwable {
                    return ProxyRepositoryFactory.getInstance().readProject();
                }
            };
            overTimePopupDialogTask.setNeedWaitingProgressJob(false);
            projects = overTimePopupDialogTask.runTask();
            Arrays.sort(projects, new Comparator<Project>() {

                @Override
                public int compare(Project p1, Project p2) {
                    return p1.getLabel().compareTo(p2.getLabel());
                }
            });
        } catch (PersistenceException e) {
            projects = new Project[0];
            if (errorManager != null) {
                //$NON-NLS-1$
                errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            } else {
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                getUsableShell(), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            }
        } catch (BusinessException e) {
            projects = new Project[0];
            if (errorManager != null) {
                //$NON-NLS-1$
                errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            } else {
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                getUsableShell(), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            }
        } catch (Throwable e) {
            projects = new Project[0];
            if (errorManager != null) {
                //$NON-NLS-1$
                errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            } else {
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                getUsableShell(), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            }
        }
    }
    return projects;
}
Also used : WarningException(org.talend.commons.exception.WarningException) Project(org.talend.core.model.general.Project) Shell(org.eclipse.swt.widgets.Shell) BusinessException(org.talend.commons.exception.BusinessException) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) OverTimePopupDialogTask(org.talend.repository.ui.dialog.OverTimePopupDialogTask) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

Shell (org.eclipse.swt.widgets.Shell)1 BusinessException (org.talend.commons.exception.BusinessException)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 WarningException (org.talend.commons.exception.WarningException)1 Project (org.talend.core.model.general.Project)1 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)1 OverTimePopupDialogTask (org.talend.repository.ui.dialog.OverTimePopupDialogTask)1