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();
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations