Search in sources :

Example 11 with ConnectionBean

use of org.talend.core.model.general.ConnectionBean in project tdi-studio-se by Talend.

the class LoginProjectPage method fillUIContents.

protected void fillUIContents() {
    boolean isOnlyRemoteConnection = brandingService.getBrandingConfiguration().isOnlyRemoteConnection();
    List<ConnectionBean> storedConnections = loginHelper.getStoredConnections();
    storedConnections = loginHelper.filterUsableConnections(storedConnections);
    for (ConnectionBean connectionBean : storedConnections) {
        String user2 = connectionBean.getUser();
        String repositoryId2 = connectionBean.getRepositoryId();
        String workSpace = connectionBean.getWorkSpace();
        String name = connectionBean.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 (LoginHelper.isRemoteConnection(connectionBean)) {
                String url = connectionBean.getDynamicFields().get(RepositoryConstants.REPOSITORY_URL);
                //$NON-NLS-1$
                valid = url != null && !"".equals(url);
            } else {
                valid = Pattern.matches(RepositoryConstants.MAIL_PATTERN, user2);
            }
            connectionBean.setComplete(valid);
        }
    }
    if (!isOnlyRemoteConnection) {
        connectionsViewer.setInput(storedConnections);
    } else {
        // feature 8,hide error remote connection for Uniserv after their login validate
        List<ILoginConnectionService> loginConnectionServices = LoginConnectionManager.getRemoteConnectionService();
        List<ConnectionBean> lastRemoteConnections = new ArrayList<ConnectionBean>();
        if (loginConnectionServices.size() > 0) {
            for (ILoginConnectionService loginConncetion : loginConnectionServices) {
                for (ConnectionBean iBean : storedConnections) {
                    String errorMsg = loginConncetion.checkConnectionValidation(iBean.getName(), iBean.getDescription(), iBean.getUser(), iBean.getPassword(), iBean.getWorkSpace(), iBean.getDynamicFields().get(RepositoryConstants.REPOSITORY_URL));
                    if (StringUtils.isEmpty(errorMsg) && iBean.isComplete()) {
                        lastRemoteConnections.add(iBean);
                    }
                }
            }
        }
        if (lastRemoteConnections.size() > 0) {
            storedConnections = lastRemoteConnections;
        }
        connectionsViewer.setInput(storedConnections);
    }
    // Check number of connection available.
    if (storedConnections.size() == 0) {
    //
    } else if (storedConnections.size() == 1) {
        connectionsViewer.setSelection(new StructuredSelection(new Object[] { storedConnections.get(0) }));
    } else {
        // select last connection used
        boolean selected = false;
        // for (ConnectionBean curent : storedConnections) {
        // String stringValue = ((LabelProvider) connectionsViewer.getLabelProvider()).getText(curent);
        // if (curent.getName().equals( lastConnection)) {
        // selectLast(stringValue, connectionsViewer.getCombo());
        // selected = true;
        // }
        // }
        ConnectionBean selectedConnBean = loginHelper.getCurrentSelectedConnBean();
        if (selectedConnBean != null) {
            connectionsViewer.setSelection(new StructuredSelection(new Object[] { selectedConnBean }));
            IStructuredSelection sel = (IStructuredSelection) connectionsViewer.getSelection();
            if (sel.getFirstElement() == selectedConnBean) {
                selected = true;
            }
        }
        if (!selected) {
            connectionsViewer.setSelection(new StructuredSelection(new Object[] { storedConnections.get(0) }));
        }
    }
    ConnectionBean selectedConnBean = getConnection();
    if (selectedConnBean != null) {
        loginHelper.setCurrentSelectedConnBean(selectedConnBean);
    }
    if (getConnection() != null || !validateFields()) {
        setRepositoryContextInContext();
    }
    fillUIProjectListWithBusyCursor();
    refreshNecessaryVisible();
}
Also used : ILoginConnectionService(org.talend.core.repository.services.ILoginConnectionService) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConnectionBean(org.talend.core.model.general.ConnectionBean) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 12 with ConnectionBean

use of org.talend.core.model.general.ConnectionBean in project tdi-studio-se by Talend.

the class LoginProjectPage method validateFields.

private boolean validateFields() {
    boolean valid = true;
    ConnectionBean connection = getConnection();
    boolean isRemote = LoginHelper.isRemoteConnection(connection);
    boolean serverIsLocal = !isAuthenticationNeeded();
    if (valid && getConnection() == null) {
        valid = false;
    } else if (valid && !getConnection().isComplete()) {
        valid = false;
    } else if (valid && !serverIsLocal && connection.getUser().length() == 0) {
        valid = false;
    } else if (valid && !isRemote && !Pattern.matches(RepositoryConstants.MAIL_PATTERN, getUser().getLogin())) {
        valid = false;
    }
    if (valid && !serverIsLocal && connection.getPassword().length() == 0) {
        valid = false;
    }
    return valid;
}
Also used : ConnectionBean(org.talend.core.model.general.ConnectionBean)

Example 13 with ConnectionBean

use of org.talend.core.model.general.ConnectionBean in project tdi-studio-se by Talend.

the class LoginProjectPage method refreshLicenseIfNeeded.

/**
     * 
     * @return if false: user cancel login
     */
private boolean refreshLicenseIfNeeded() {
    ConnectionBean conn = loginHelper.getCurrentSelectedConnBean();
    Project proj = getProject();
    if (LoginHelper.isRemoteConnection(conn)) {
        String url = getAdminURL();
        String projLabel = proj.getLabel();
        String userId = conn.getUser();
        try {
            String key = loginHelper.getLicenseMapKey(url, projLabel, userId);
            String license = loginHelper.getLicense(key);
            if (license == null || license.isEmpty()) {
                Job fetchJob = fetchLicenseJobMap.get(proj);
                if (fetchJob == null || fetchJob.getResult() != null) {
                    // if result is not null, means fetchJob has already finished but no license fetched
                    fetchJob = fetchLicense(proj);
                }
                final Job fJob = fetchJob;
                if (fJob != null) {
                    final AtomicBoolean isInterupted = new AtomicBoolean(false);
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
                    dialog.run(true, true, new IRunnableWithProgress() {

                        @Override
                        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                            monitor.setTaskName(fJob.getName());
                            while (true) {
                                if (monitor.isCanceled()) {
                                    /**
                                         * If network is slow, maybe just wait the fetch job finish, but still can click
                                         * the Refresh button to cancel all fetch jobs
                                         */
                                    // fJob.cancel();
                                    isInterupted.set(true);
                                    break;
                                }
                                IStatus result = fJob.getResult();
                                if (result != null) {
                                    break;
                                }
                                try {
                                    Thread.sleep(250);
                                } catch (Exception e) {
                                // nothing to do
                                }
                            }
                        }
                    });
                    if (isInterupted.get()) {
                        return false;
                    }
                }
                license = loginHelper.getLicense(key);
            }
            if (license == null || license.isEmpty()) {
                //$NON-NLS-1$
                throw new Exception(Messages.getString("LoginProjectPage.fetchLicense.error.failed"));
            }
        // will do save in CoreTisService if needed
        // ICoreTisService tisService = (ICoreTisService) GlobalServiceRegister.getDefault()
        // .getService(ICoreTisService.class);
        // File remoteLicense = tisService.getRemoteLicenseFile();
        // tisService.storeLicenseFile(remoteLicense, license);
        } catch (Exception e) {
            //$NON-NLS-1$
            ExceptionMessageDialog.openError(//$NON-NLS-1$
            getShell(), //$NON-NLS-1$
            Messages.getString("LoginProjectPage.fetchLicense.error.title"), Messages.getString("LoginProjectPage.fetchLicense.error.msg"), //$NON-NLS-1$
            e);
            return false;
        }
    }
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.talend.commons.exception.SystemException) JSONException(org.talend.utils.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Project(org.talend.core.model.general.Project) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConnectionBean(org.talend.core.model.general.ConnectionBean) Job(org.eclipse.core.runtime.jobs.Job)

Example 14 with ConnectionBean

use of org.talend.core.model.general.ConnectionBean in project tdi-studio-se by Talend.

the class LoginProjectPage method validateUpdate.

protected void validateUpdate() throws JSONException {
    final ConnectionBean currentBean = getConnection();
    String repositoryId = null;
    // at 1st time open the studio there are no bean at all,so need avoid NPE
    if (currentBean != null) {
        repositoryId = currentBean.getRepositoryId();
    }
    try {
        if (currentBean != null && isSVNProviderPluginLoadedRemote() && isWorkSpaceSame()) {
            if (afterUpdate) {
                refreshProjectOperationAreaEnable(false);
                //$NON-NLS-1$
                errorManager.setErrMessage(Messages.getString("LoginProjectPage.archivaFinish"));
                changeFinishButtonAction(FINISH_ACTION_RESTART);
            } else {
                OverTimePopupDialogTask<Boolean> overTimePopupDialogTask = new OverTimePopupDialogTask<Boolean>() {

                    @Override
                    public Boolean run() throws Throwable {
                        return LoginHelper.isStudioNeedUpdate(currentBean);
                    }
                };
                overTimePopupDialogTask.setNeedWaitingProgressJob(false);
                boolean needUpdate = overTimePopupDialogTask.runTask();
                if (needUpdate && isWorkSpaceSame()) {
                    refreshProjectOperationAreaEnable(false);
                    //$NON-NLS-1$
                    errorManager.setErrMessage(Messages.getString("LoginProjectPage.updateArchiva"));
                    changeFinishButtonAction(FINISH_ACTION_UPDATE);
                }
            }
        }
    } catch (PersistenceException e) {
        CommonExceptionHandler.process(e);
    } catch (SystemException e) {
        updateArchivaErrorButton();
    } catch (Throwable e) {
        CommonExceptionHandler.process(e);
    }
}
Also used : OverTimePopupDialogTask(org.talend.repository.ui.dialog.OverTimePopupDialogTask) SystemException(org.talend.commons.exception.SystemException) PersistenceException(org.talend.commons.exception.PersistenceException) ConnectionBean(org.talend.core.model.general.ConnectionBean) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 15 with ConnectionBean

use of org.talend.core.model.general.ConnectionBean in project tdi-studio-se by Talend.

the class LoginProjectPage method isSVNProviderPluginLoadedRemote.

/**
     * svn provider plugin loaded && a remote connection
     * 
     * @return
     */
protected boolean isSVNProviderPluginLoadedRemote() {
    boolean isRemote = false;
    if (PluginChecker.isSVNProviderPluginLoaded()) {
        StructuredSelection selection = (StructuredSelection) connectionsViewer.getSelection();
        Object firstElement = selection.getFirstElement();
        if (firstElement instanceof ConnectionBean) {
            isRemote = LoginHelper.isRemoteConnection((ConnectionBean) firstElement);
        }
    }
    return isRemote;
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) JSONObject(org.talend.utils.json.JSONObject) ConnectionBean(org.talend.core.model.general.ConnectionBean)

Aggregations

ConnectionBean (org.talend.core.model.general.ConnectionBean)23 PersistenceException (org.talend.commons.exception.PersistenceException)8 ArrayList (java.util.ArrayList)7 Project (org.talend.core.model.general.Project)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 JSONException (org.talend.utils.json.JSONException)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Shell (org.eclipse.swt.widgets.Shell)4 SystemException (org.talend.commons.exception.SystemException)4 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)4 IBrandingService (org.talend.core.ui.branding.IBrandingService)4 List (java.util.List)3 User (org.talend.core.model.properties.User)3 JSONObject (org.talend.utils.json.JSONObject)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IProject (org.eclipse.core.resources.IProject)2 Job (org.eclipse.core.runtime.jobs.Job)2