Search in sources :

Example 6 with ConnectionBean

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

the class LoginProjectPage method createFetchLicenseJob.

private Job createFetchLicenseJob(Project proj) {
    final String projLabel = proj.getLabel();
    Job fetchJob = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    Messages.getString("LoginProjectPage.fetchLicense.job", proj.getLabel())) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            ConnectionBean cBean = loginHelper.getCurrentSelectedConnBean();
            try {
                String userId = cBean.getUser();
                String url = getAdminURL();
                JSONObject jsonObj = getRemoteService().getLicenseKey(userId, cBean.getPassword(), url, projLabel);
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String fetchedLicense = jsonObj.getString("customerName") + "_" + jsonObj.getString("licenseKey");
                String key = loginHelper.getLicenseMapKey(url, projLabel, userId);
                loginHelper.putLicense(key, fetchedLicense);
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
            return Status.OK_STATUS;
        }

        @Override
        protected void canceling() {
            Thread thread = this.getThread();
            try {
                // to interrupt the slow network connection
                thread.interrupt();
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    };
    fetchLicenseJobMap.put(proj, fetchJob);
    return fetchJob;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JSONObject(org.talend.utils.json.JSONObject) ConnectionBean(org.talend.core.model.general.ConnectionBean) Job(org.eclipse.core.runtime.jobs.Job) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.talend.commons.exception.SystemException) JSONException(org.talend.utils.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 7 with ConnectionBean

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

the class ConnectionsListComposite method getClonedList.

protected List<ConnectionBean> getClonedList(List<ConnectionBean> source) {
    if (source == null) {
        return null;
    }
    List<ConnectionBean> target = new ArrayList<ConnectionBean>(source.size());
    Iterator<ConnectionBean> iter = source.iterator();
    while (iter.hasNext()) {
        ConnectionBean sourceBean = iter.next();
        try {
            ConnectionBean targetBean = sourceBean.clone();
            target.add(targetBean);
        } catch (CloneNotSupportedException e) {
            CommonExceptionHandler.process(e);
        }
    }
    return target;
}
Also used : ArrayList(java.util.ArrayList) ConnectionBean(org.talend.core.model.general.ConnectionBean)

Example 8 with ConnectionBean

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

the class ConnectionFormComposite method validateFields.

private boolean validateFields() {
    String errorMsg = null;
    boolean valid = true;
    if (dialog.getOKButton() != null) {
        dialog.getOKButton().setEnabled(true);
    }
    IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    boolean isOnlyRemoteConnection = brandingService.getBrandingConfiguration().isOnlyRemoteConnection();
    boolean usesMailCheck = brandingService.getBrandingConfiguration().isUseMailLoginCheck();
    LabelText emptyUrl = null;
    if (getRepository() != null) {
        for (LabelText currentUrlLabel : dynamicRequiredControls.get(getRepository()).values()) {
            if (valid && currentUrlLabel.getText().length() == 0) {
                emptyUrl = currentUrlLabel;
            }
        }
    }
    if (valid && getRepository() == null) {
        //$NON-NLS-1$
        errorMsg = Messages.getString("connections.form.emptyField.repository");
    } else if (valid && getTextName().length() == 0) {
        //$NON-NLS-1$
        errorMsg = Messages.getString("connections.form.emptyField.connname");
    } else if (valid && getUser().length() == 0) {
        //$NON-NLS-1$
        errorMsg = Messages.getString("connections.form.emptyField.username");
    } else if (valid && isLocalConnection() && !Pattern.matches(RepositoryConstants.MAIL_PATTERN, getUser())) {
        //$NON-NLS-1$
        errorMsg = Messages.getString("connections.form.malformedField.username");
    } else if (valid && emptyUrl != null) {
        //$NON-NLS-1$
        errorMsg = Messages.getString("connections.form.dynamicFieldEmpty", emptyUrl.getLabel());
    } else if (valid && !this.isValidatedWorkspace(this.getWorkspace())) {
        //$NON-NLS-1$
        errorMsg = Messages.getString("ConnectionFormComposite.workspaceInvalid");
    } else if (valid && isOnlyRemoteConnection) {
        // Uniserv feature 8,Add new Extension point to allow Uniserv to add some custom controls during TAC
        // connection check
        List<ILoginConnectionService> loginConnections = LoginConnectionManager.getRemoteConnectionService();
        for (ILoginConnectionService loginConncetion : loginConnections) {
            errorMsg = loginConncetion.checkConnectionValidation(getTextName(), getDesc(), getUser(), getPassword(), getWorkspace(), connection.getDynamicFields().get(RepositoryConstants.REPOSITORY_URL));
        }
    } else if (valid && getTextName() != null) {
        List<ConnectionBean> connectionBeanList = dialog.getConnections();
        if (connectionBeanList != null && connectionBeanList.size() > 1) {
            for (ConnectionBean connectionBean : connectionBeanList) {
                String connectionBeanName = connectionBean.getName();
                if (connectionBeanName != null) {
                    if (this.connection != connectionBean) {
                        if (connectionBeanName.equals(getTextName())) {
                            //$NON-NLS-1$
                            errorMsg = Messages.getString("ConnectionFormComposite.connectionNameInvalid");
                        }
                    }
                }
            }
        }
    }
    if (errorMsg != null && !errorMsg.equals("")) {
        //$NON-NLS-1$
        valid = false;
    }
    if (!valid) {
        dialog.setErrorMessage(errorMsg);
        if (dialog.getOKButton() != null) {
            dialog.getOKButton().setEnabled(false);
        }
    } else {
        dialog.setErrorMessage(null);
    }
    if (connection != null) {
        connection.setComplete(valid);
        connectionsListComposite.refresh(connection);
    }
    return valid;
}
Also used : ILoginConnectionService(org.talend.core.repository.services.ILoginConnectionService) LabelText(org.talend.commons.ui.swt.formtools.LabelText) List(java.util.List) ArrayList(java.util.ArrayList) ConnectionBean(org.talend.core.model.general.ConnectionBean) IBrandingService(org.talend.core.ui.branding.IBrandingService)

Example 9 with ConnectionBean

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

the class LoginDialog method logIn.

/**
     * DOC smallet Comment method "logIn".
     * 
     * @param project
     * @throws Exception
     */
protected boolean logIn(final Project project) {
    final ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    ConnectionBean connBean = loginComposite.getConnection();
    final boolean needRestartForLocal = loginComposite.needRestartForLocal();
    if (connBean == null || project == null || project.getLabel() == null) {
        return false;
    }
    try {
        if (!project.getEmfProject().isLocal() && factory.isLocalConnectionProvider()) {
            List<IRepositoryFactory> rfList = RepositoryFactoryProvider.getAvailableRepositories();
            IRepositoryFactory remoteFactory = null;
            for (IRepositoryFactory rf : rfList) {
                if (!rf.isLocalConnectionProvider()) {
                    remoteFactory = rf;
                    break;
                }
            }
            if (remoteFactory != null) {
                factory.setRepositoryFactoryFromProvider(remoteFactory);
                factory.getRepositoryContext().setOffline(true);
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    // Save last used parameters
    PreferenceManipulator prefManipulator = new PreferenceManipulator(CorePlugin.getDefault().getPreferenceStore());
    prefManipulator.setLastProject(project.getTechnicalLabel());
    saveLastConnBean(connBean);
    // check for Talendforge
    if (PluginChecker.isExchangeSystemLoaded() && !TalendPropertiesUtil.isHideExchange()) {
        IPreferenceStore prefStore = PlatformUI.getPreferenceStore();
        boolean checkTisVersion = prefStore.getBoolean(ITalendCorePrefConstants.EXCHANGE_CHECK_TIS_VERSION);
        IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
        if (!checkTisVersion && brandingService.isPoweredbyTalend()) {
            int count = prefStore.getInt(TalendForgeDialog.LOGINCOUNT);
            if (count < 0) {
                count = 1;
            }
            ExchangeUser exchangeUser = project.getExchangeUser();
            boolean isExchangeLogon = exchangeUser.getLogin() != null && !exchangeUser.getLogin().equals("");
            boolean isUserPassRight = true;
            if (isExchangeLogon) {
                IExchangeService service = (IExchangeService) GlobalServiceRegister.getDefault().getService(IExchangeService.class);
                if (service.checkUserAndPass(exchangeUser.getUsername(), exchangeUser.getPassword()) != null) {
                    isUserPassRight = false;
                }
            }
            if (!isExchangeLogon || !isUserPassRight) {
                if ((count + 1) % 4 == 0) {
                    // if (Platform.getOS().equals(Platform.OS_LINUX)) {
                    // TalendForgeDialog tfDialog = new TalendForgeDialog(this.getShell(), project);
                    // tfDialog.open();
                    // } else {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            String userEmail = null;
                            if (project.getAuthor() != null) {
                                userEmail = project.getAuthor().getLogin();
                            }
                            TalendForgeDialog tfDialog = new TalendForgeDialog(getShell(), userEmail);
                            tfDialog.setBlockOnOpen(true);
                            tfDialog.open();
                        }
                    });
                }
                prefStore.setValue(TalendForgeDialog.LOGINCOUNT, count + 1);
            }
        }
    }
    try {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ICoreTisService.class)) {
            final ICoreTisService service = (ICoreTisService) GlobalServiceRegister.getDefault().getService(ICoreTisService.class);
            if (service != null) {
                // if in TIS then update the bundle status according to the project type
                if (!service.validProject(project, needRestartForLocal)) {
                    LoginComposite.isRestart = true;
                    return true;
                }
            }
        // else not in TIS so ignor caus we may not have a licence so we do not know which bundles belong to
        // DI, DQ or MDM
        }
    } catch (PersistenceException e) {
        e.printStackTrace();
        loginComposite.populateProjectList();
        MessageDialog.openError(getShell(), getShell().getText(), e.getMessage());
        return false;
    }
    final Shell shell = this.getShell();
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            // monitorWrap = new EventLoopProgressMonitor(monitor);
            try {
                factory.logOnProject(project, monitor);
            } catch (LoginException e) {
                throw new InvocationTargetException(e);
            } catch (PersistenceException e) {
                throw new InvocationTargetException(e);
            } catch (OperationCanceledException e) {
                throw new InterruptedException(e.getLocalizedMessage());
            }
            monitor.done();
        }
    };
    try {
        dialog.run(true, true, runnable);
    } catch (final InvocationTargetException e) {
        if (PluginChecker.isSVNProviderPluginLoaded()) {
            loginComposite.populateProjectList();
            if (e.getTargetException() instanceof OperationCancelException) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.getString("LoginDialog.logonCanceled"), e.getTargetException().getLocalizedMessage());
                    }
                });
            } else {
                MessageBoxExceptionHandler.process(e.getTargetException(), getShell());
            }
        } else {
            loginComposite.populateTOSProjectList();
            MessageBoxExceptionHandler.process(e.getTargetException(), getShell());
        }
        return false;
    } catch (InterruptedException e) {
        if (PluginChecker.isSVNProviderPluginLoaded()) {
            loginComposite.populateProjectList();
        } else {
            loginComposite.populateTOSProjectList();
        }
        return false;
    }
    return true;
}
Also used : PreferenceManipulator(org.talend.core.prefs.PreferenceManipulator) OperationCancelException(org.talend.commons.exception.OperationCancelException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ICoreTisService(org.talend.core.services.ICoreTisService) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IExchangeService(org.talend.core.service.IExchangeService) Shell(org.eclipse.swt.widgets.Shell) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IBrandingService(org.talend.core.ui.branding.IBrandingService) ExchangeUser(org.talend.core.model.properties.ExchangeUser) Point(org.eclipse.swt.graphics.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) ConnectionBean(org.talend.core.model.general.ConnectionBean) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) TalendForgeDialog(org.talend.registration.wizards.register.TalendForgeDialog)

Example 10 with ConnectionBean

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

the class LoginHelper method filterUsableConnections.

protected List<ConnectionBean> filterUsableConnections(List<ConnectionBean> iStoredConnections) {
    if (iStoredConnections == null) {
        return null;
    }
    List<ConnectionBean> filteredConnections = new ArrayList<ConnectionBean>(iStoredConnections);
    boolean isOnlyRemoteConnection = false;
    IBrandingConfiguration brandingConfiguration = brandingService.getBrandingConfiguration();
    if (brandingConfiguration != null) {
        isOnlyRemoteConnection = brandingConfiguration.isOnlyRemoteConnection();
    }
    if (!isOnlyRemoteConnection && PluginChecker.isSVNProviderPluginLoaded()) {
        // if this plugin loaded, then means support remote connections, then no need to filter
        return filteredConnections;
    }
    // can be two case: 1 only local connection, 2 only remote connection
    Iterator<ConnectionBean> connectionBeanIter = filteredConnections.iterator();
    while (connectionBeanIter.hasNext()) {
        boolean isRemoteConnection = LoginHelper.isRemoteConnection(connectionBeanIter.next());
        if (isOnlyRemoteConnection && !isRemoteConnection) {
            // only remote connection, should remove local
            connectionBeanIter.remove();
        } else if (!isOnlyRemoteConnection && isRemoteConnection) {
            // only local connection, should remove remote
            connectionBeanIter.remove();
        }
    }
    return filteredConnections;
}
Also used : IBrandingConfiguration(org.talend.core.ui.branding.IBrandingConfiguration) ArrayList(java.util.ArrayList) 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