Search in sources :

Example 1 with ConnectionBean

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

the class CreateAutomaticConnectionApplication method splitParameters.

private ConnectionBean splitParameters(String[] args) throws ParameterIncorrectSetException {
    Map<String, String> argMap = new HashMap<String, String>();
    ConnectionBean bean = new ConnectionBean();
    List<String> exceptionMessages = new ArrayList<String>();
    List<String> argsList = Arrays.asList(args);
    int valueIndex = 0;
    //$NON-NLS-N$
    String value = "";
    for (String current : argsList) {
        current = TalendTextUtils.removeQuotes(current);
        if (current.equals(userKey)) {
            valueIndex = argsList.indexOf(userKey) + 1;
            value = argsList.get(valueIndex);
            if (value.startsWith("-")) {
                // no value of this parameter
                String message = "Create Automatic Connection error,parameter " + userKey + "'s value is incorrect.";
                exceptionMessages.add(message);
            }
            argMap.put(userKey, value);
        } else if (current.equals(nameKey)) {
            valueIndex = argsList.indexOf(nameKey) + 1;
            value = argsList.get(valueIndex);
            if (value.startsWith("-")) {
                String message = "Create Automatic Connection error,parameter " + nameKey + "'s value is incorrect.";
                exceptionMessages.add(message);
            }
            argMap.put(nameKey, value);
        } else if (current.equals(descriptionKey)) {
            valueIndex = argsList.indexOf(descriptionKey) + 1;
            value = argsList.get(valueIndex);
            argMap.put(descriptionKey, value);
        } else if (current.equals(passwordKey)) {
            valueIndex = argsList.indexOf(passwordKey) + 1;
            value = argsList.get(valueIndex);
            if (value.startsWith("-")) {
                String message = "Create Automatic Connection error,parameter " + passwordKey + "'s value is incorrect.";
                exceptionMessages.add(message);
            }
            argMap.put(passwordKey, value);
        } else if (current.equals(repositoryIdKey)) {
            valueIndex = argsList.indexOf(repositoryIdKey) + 1;
            value = argsList.get(valueIndex);
            repositoryIdValue = value;
            if (value.startsWith("-")) {
                String message = "Create Automatic Connection error,parameter " + repositoryIdKey + "'s value is incorrect.";
                exceptionMessages.add(message);
            }
            argMap.put(repositoryIdKey, value);
        } else if (current.equals(urlKey)) {
            valueIndex = argsList.indexOf(urlKey) + 1;
            value = argsList.get(valueIndex);
            if (repositoryIdValue != null && repositoryIdValue.equals("Remote") && value.startsWith("-")) {
                String message = "Create Automatic Connection error,parameter " + urlKey + "'s value is incorrect.";
                exceptionMessages.add(message);
            }
            argMap.put(urlKey, value);
        } else if (current.equals(workspaceKey)) {
            valueIndex = argsList.indexOf(workspaceKey) + 1;
            value = argsList.get(valueIndex);
            if (value.startsWith("-")) {
                String message = "Create Automatic Connection error,parameter " + workspaceKey + "'s value is incorrect.";
                exceptionMessages.add(message);
            }
            argMap.put(workspaceKey, value);
        }
    }
    if (!exceptionMessages.isEmpty()) {
        //$NON-NLS-N$
        String exceptionMessage = "";
        StringBuffer sb = new StringBuffer();
        for (String s : exceptionMessages) {
            sb.append(s);
            //$NON-NLS-N$
            sb.append("\n");
        }
        exceptionMessage = sb.toString();
        ParameterIncorrectSetException exception = new ParameterIncorrectSetException(exceptionMessage);
        throw exception;
    }
    bean.setName(argMap.get(nameKey));
    bean.setDescription(argMap.get(descriptionKey));
    bean.setPassword(argMap.get(passwordKey));
    bean.setUser(argMap.get(userKey));
    bean.setRepositoryId(argMap.get(repositoryIdKey));
    bean.setWorkSpace(argMap.get(workspaceKey));
    bean.getDynamicFields().put("url", argMap.get(urlKey));
    bean.setComplete(true);
    return bean;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConnectionBean(org.talend.core.model.general.ConnectionBean)

Example 2 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 3 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 4 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 5 with ConnectionBean

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

the class LoginProjectPage method addListeners.

@Override
protected void addListeners() {
    super.addListeners();
    connectionsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            try {
                resetProjectOperationSelectionWithBusyCursor(false);
                final ConnectionBean connection = getConnection();
                if (connection == null) {
                    checkErrors();
                    return;
                }
                // }
                if (connection == loginHelper.getCurrentSelectedConnBean()) {
                    return;
                } else {
                    loginHelper.setCurrentSelectedConnBean(connection);
                }
                cancelAndClearFetchJobs();
                errorManager.clearAllMessages();
                // beforeConnBean = connection;
                updateServerFields();
                // Validate data
                if (validateFields()) {
                    fillUIProjectListWithBusyCursor();
                    validateProject();
                }
                checkErrors();
                validateUpdate();
            } catch (PersistenceException e) {
                CommonExceptionHandler.process(e);
            } catch (JSONException e) {
                CommonExceptionHandler.process(e);
            }
        }
    });
    selectExistingProject.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (selectExistingProject.getSelection()) {
                // refreshProjectListAreaEnable(true);
                finishButtonAction = FINISH_ACTION_OPEN_PROJECT;
                // changeFinishButtonAction(finishButtonAction);
                try {
                    checkErrors();
                } catch (PersistenceException e1) {
                    CommonExceptionHandler.process(e1);
                }
            } else {
                refreshProjectListAreaEnable(false);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
    createSandBoxProject.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (createSandBoxProject.getSelection()) {
                finishButtonAction = FINISH_ACTION_CREATE_SANDBOX;
                // changeFinishButtonAction(finishButtonAction);
                refreshUIFinishButtonEnable(false);
                executeCreateSandBoxProject.setVisible(true);
                executeCreateSandBoxProject.forceFocus();
            } else {
                executeCreateSandBoxProject.setVisible(false);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
    importDemoProject.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (importDemoProject.getSelection()) {
                finishButtonAction = FINISH_ACTION_IMPORT_DEMO_PROJECT;
                // changeFinishButtonAction(finishButtonAction);
                refreshUIFinishButtonEnable(false);
                executeImportDemoProject.setVisible(true);
                executeImportDemoProject.forceFocus();
            } else {
                executeImportDemoProject.setVisible(false);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
    importLocalProject.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (importLocalProject.getSelection()) {
                finishButtonAction = FINISH_ACTION_IMPORT_LOCAL_PROJECT;
                // changeFinishButtonAction(finishButtonAction);
                refreshUIFinishButtonEnable(false);
                executeImportLocalProject.setVisible(true);
                executeImportLocalProject.forceFocus();
            } else {
                executeImportLocalProject.setVisible(false);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
    createNewProject.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (createNewProject.getSelection()) {
                //$NON-NLS-1$
                createNewProject.setText(Messages.getString("LoginProjectPage.createNewProject.beginCreate"));
                createNewProject.pack();
                FormData formData = (FormData) newProjectName.getLayoutData();
                formData.left = new FormAttachment(createNewProject, createNewProject.getSize().x + TAB_HORIZONTAL_PADDING_LEVEL_2, SWT.LEFT);
                newProjectName.setVisible(true);
                newProjectName.forceFocus();
                executeCreateNewProject.setVisible(true);
                finishButtonAction = FINISH_ACTION_CREATE_NEW_PROJECT;
                // changeFinishButtonAction(finishButtonAction);
                refreshUIFinishButtonEnable(false);
                validateNewProjectName();
            } else {
                //$NON-NLS-1$
                createNewProject.setText(Messages.getString("LoginProjectPage.createNewProject"));
                newProjectName.setVisible(false);
                executeCreateNewProject.setVisible(false);
                getErrorManager().clearCreateNewProjectError();
            // refreshUIFinishButtonEnable();
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
    projectViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            finishButton.setEnabled(false);
            Project project = getProject();
            if (project != null) {
                // last used project will be saved when click finish
                // loginHelper.getPrefManipulator().setLastProject(project.getLabel());
                fetchLicenseIfNeeded(project);
                try {
                    fillUIBranches(project, false);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    ExceptionHandler.process(e);
                }
                setRepositoryContextInContext();
            }
            finishButton.setEnabled(true);
        }
    });
    branchesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
        // last used branch of project will be saved when click finish
        // String branch = getBranch();
        // if (branch == null) {
        // branch = SVNConstant.EMPTY;
        // }
        // Project project = getProject();
        // try {
        // loginHelper.getPrefManipulator().setLastSVNBranch(
        // new JSONObject(project.getEmfProject().getUrl()).getString("location"), project.getTechnicalLabel(),
        // branch);
        // } catch (JSONException e) {
        // // TODO Auto-generated catch block
        // ExceptionHandler.process(e);
        // }
        }
    });
    manageButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                ConnectionsDialog connectionsDialog = new ConnectionsDialog(getShell());
                int open = connectionsDialog.open();
                if (open == Window.OK) {
                    List<ConnectionBean> storedConnections = connectionsDialog.getConnections();
                    loginHelper.setStoredConnections(storedConnections);
                    loginHelper.saveConnections();
                    fillUIContentsWithBusyCursor();
                    final ConnectionBean connection = getConnection();
                    if (connection == null) {
                        checkErrors();
                        return;
                    }
                    // beforeConnBean = connection;
                    updateServerFields();
                    // Validate data
                    if (validateFields()) {
                        fillUIProjectListWithBusyCursor();
                        validateProject();
                    }
                    checkErrors();
                    validateUpdate();
                } else if (!LoginHelper.isRemoteConnection(getConnection())) {
                    fillUIProjectListWithBusyCursor();
                    validateProject();
                    checkErrors();
                }
            // setStatusArea();
            } catch (PersistenceException e1) {
                CommonExceptionHandler.process(e1);
            } catch (JSONException e2) {
                CommonExceptionHandler.process(e2);
            }
        }
    });
    refreshProjectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            cancelAndClearFetchJobs();
            LoginProjectPage.this.selectedProjectBeforeRefresh = getProject() == null ? null : getProject().getLabel();
            // Validate data
            if (validateFields()) {
                fillUIProjectListWithBusyCursor();
                validateProject();
            }
            try {
                checkErrors();
                validateUpdate();
            } catch (PersistenceException e1) {
                CommonExceptionHandler.process(e1);
            } catch (JSONException e1) {
                CommonExceptionHandler.process(e1);
            }
            setRepositoryContextInContext();
            LoginProjectPage.this.selectedProjectBeforeRefresh = null;
        }
    });
    newProjectName.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            validateNewProjectName();
        }
    });
    executeCreateNewProject.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            createNewProjectWithBusyCursor();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
    executeCreateSandBoxProject.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            createSandboxProject();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
    executeImportDemoProject.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            importDemoProject();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
    executeImportLocalProject.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            importProjects();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
    finishButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (FINISH_ACTION_OPEN_PROJECT.equals(finishButtonAction)) {
                setRepositoryContextInContext();
                finishPressed();
            } else if (FINISH_ACTION_RESTART.equals(finishButtonAction)) {
                restartStudio();
            } else if (FINISH_ACTION_UPDATE.equals(finishButtonAction) || FINISH_ACTION_UPDATE_DETAILS.equals(finishButtonAction)) {
                updateStudio();
            } else if (FINISH_ACTION_CREATE_SANDBOX.equals(finishButtonAction)) {
                createSandboxProject();
            } else if (FINISH_ACTION_IMPORT_DEMO_PROJECT.equals(finishButtonAction)) {
                importDemoProject();
            } else if (FINISH_ACTION_IMPORT_LOCAL_PROJECT.equals(finishButtonAction)) {
                importProjects();
            } else if (FINISH_ACTION_CREATE_NEW_PROJECT.equals(finishButtonAction)) {
                createNewProjectWithBusyCursor();
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
}
Also used : FormData(org.eclipse.swt.layout.FormData) ModifyListener(org.eclipse.swt.events.ModifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) JSONException(org.talend.utils.json.JSONException) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Project(org.talend.core.model.general.Project) ModifyEvent(org.eclipse.swt.events.ModifyEvent) PersistenceException(org.talend.commons.exception.PersistenceException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ConnectionBean(org.talend.core.model.general.ConnectionBean) ArrayList(java.util.ArrayList) List(java.util.List) ConnectionsDialog(org.talend.repository.ui.login.connections.ConnectionsDialog) FormAttachment(org.eclipse.swt.layout.FormAttachment) SelectionListener(org.eclipse.swt.events.SelectionListener)

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