Search in sources :

Example 11 with IRepositoryFactory

use of org.talend.core.repository.model.IRepositoryFactory in project tdi-studio-se by Talend.

the class LoginHelper method logIn.

public boolean logIn(ConnectionBean connBean, final Project project) {
    final ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    final boolean needRestartForLocal = needRestartForLocal(connBean);
    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
    prefManipulator.setLastProject(project.getTechnicalLabel());
    saveLastConnBean(connBean);
    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)) {
                    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) {
        CommonExceptionHandler.process(e);
        MessageDialog.openError(getUsableShell(), getUsableShell().getText(), e.getMessage());
        return false;
    }
    final Shell shell = getUsableShell();
    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()) {
        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(), getUsableShell());
        }
        factory.getRepositoryContext().setProject(null);
        // }
        return false;
    } catch (InterruptedException e) {
        // }
        return false;
    }
    return true;
}
Also used : IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) OperationCancelException(org.talend.commons.exception.OperationCancelException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ICoreTisService(org.talend.core.services.ICoreTisService) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) 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)

Aggregations

IRepositoryFactory (org.talend.core.repository.model.IRepositoryFactory)11 PersistenceException (org.talend.commons.exception.PersistenceException)4 LabelText (org.talend.commons.ui.swt.formtools.LabelText)4 LabelledCombo (org.talend.commons.ui.swt.formtools.LabelledCombo)4 Shell (org.eclipse.swt.widgets.Shell)3 LoginException (org.talend.commons.exception.LoginException)3 OperationCancelException (org.talend.commons.exception.OperationCancelException)3 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ConnectionBean (org.talend.core.model.general.ConnectionBean)2 PreferenceManipulator (org.talend.core.prefs.PreferenceManipulator)2 ICoreTisService (org.talend.core.services.ICoreTisService)2 IBrandingService (org.talend.core.ui.branding.IBrandingService)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1