use of org.talend.core.prefs.PreferenceManipulator in project tdi-studio-se by Talend.
the class LoginHelper method saveUpdateStatus.
public void saveUpdateStatus(Project project) throws JSONException {
Context ctx = CoreRuntimePlugin.getInstance().getContext();
RepositoryContext repositoryContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
// reset repositoryContext first, in case switch branch
repositoryContext.setNoUpdateWhenLogon(false);
PreferenceManipulator prefManipulator = new PreferenceManipulator();
if (CommonsPlugin.isHeadless()) {
repositoryContext.setNoUpdateWhenLogon(false);
return;
}
if (!LoginHelper.isRemoteConnection(getCurrentSelectedConnBean())) {
repositoryContext.setNoUpdateWhenLogon(true);
return;
}
String url = project.getEmfProject().getUrl();
if (url == null || !"git".equals(getStorage(url))) {
return;
}
String location = getLocation(url);
String projectName = project.getTechnicalLabel();
String branch = ProjectManager.getInstance().getMainProjectBranch(project);
if (branch == null) {
return;
}
if (branch.startsWith("tags/")) {
repositoryContext.setNoUpdateWhenLogon(true);
return;
}
if (branch.startsWith("branches/")) {
branch = branch.substring("branches/".length());
}
JSONObject json = prefManipulator.getLogonLocalBranchStatus(location, projectName);
if (json != null) {
if (!json.has(branch)) {
// if not store yet, should be remote branch, so keep false value
return;
}
Object noUpdateWhenLogon = json.get(branch);
if (noUpdateWhenLogon != null) {
repositoryContext.setNoUpdateWhenLogon((Boolean) noUpdateWhenLogon);
}
}
}
use of org.talend.core.prefs.PreferenceManipulator in project tdi-studio-se by Talend.
the class LoginHelper method init.
protected void init() {
if (PluginChecker.isSVNProviderPluginLoaded()) {
try {
svnProviderService = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
gitProviderService = (IGITProviderService) GlobalServiceRegister.getDefault().getService(IGITProviderService.class);
} catch (RuntimeException e) {
// nothing to do
}
}
prefManipulator = new PreferenceManipulator(CorePlugin.getDefault().getPreferenceStore());
perReader = ConnectionUserPerReader.getInstance();
readConnectionData();
recordFirstConnection();
}
use of org.talend.core.prefs.PreferenceManipulator in project tdi-studio-se by Talend.
the class RepositoryService method isloginDialogDisabled.
private boolean isloginDialogDisabled() {
//$NON-NLS-1$
boolean reload = Boolean.parseBoolean(System.getProperty("talend.project.reload"));
PreferenceManipulator preferenceManipulator = new PreferenceManipulator();
ConnectionBean lastBean = null;
if (reload) {
final ConnectionUserPerReader instance = ConnectionUserPerReader.getInstance();
instance.forceReadConnections();
final String lastConncetion = ConnectionUserPerReader.getInstance().readLastConncetion();
for (ConnectionBean bean : instance.readConnections()) {
if (bean.getName().equals(lastConncetion)) {
lastBean = bean;
break;
}
}
}
if (ArrayUtils.contains(Platform.getApplicationArgs(), EclipseCommandLine.TALEND_DISABLE_LOGINDIALOG_COMMAND)) {
//$NON-NLS-1$
boolean deleteProjectIfExist = ArrayUtils.contains(Platform.getApplicationArgs(), "--deleteProjectIfExist");
IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
brandingService.getBrandingConfiguration().setUseProductRegistration(false);
ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
//$NON-NLS-1$ //$NON-NLS-2$
String projectName = getAppArgValue("-project", "AUTO_LOGIN_PROJECT");
//$NON-NLS-1$
String language = getAppArgValue("-language", ECodeLanguage.JAVA.getName());
//$NON-NLS-1$ //$NON-NLS-2$
String login = getAppArgValue("-login", "auto@login.com");
//$NON-NLS-1$ //$NON-NLS-2$
String password = getAppArgValue("-loginPass", "");
//$NON-NLS-1$
String tacURL = getAppArgValue("-tacURL", null);
// if tacURL is null, the branch will be no useful.
//$NON-NLS-1$
String branch = getAppArgValue("-branch", null);
// if tacURL is not null, will be remote
final boolean isRemote = tacURL != null;
if (reload && lastBean != null) {
final String lastProject = preferenceManipulator.getLastProject();
if (lastProject != null) {
projectName = lastProject;
}
final String lastUser = lastBean.getUser();
if (lastUser != null) {
login = lastUser;
}
final String lastPass = lastBean.getPassword();
if (lastPass != null) {
password = lastPass;
}
}
User userInfo = PropertiesFactoryImpl.eINSTANCE.createUser();
userInfo.setLogin(login);
try {
userInfo.setPassword(PasswordHelper.encryptPasswd(password));
} catch (NoSuchAlgorithmException e) {
ExceptionHandler.process(e);
}
LoginHelper.isAutoLogonFailed = false;
try {
ConnectionBean bean = null;
if (reload && lastBean != null) {
// reload
bean = lastBean;
} else {
if (tacURL != null && isRemote) {
// remote
bean = ConnectionBean.getDefaultRemoteConnectionBean();
bean.setUser(login);
bean.setPassword(password);
bean.getDynamicFields().put(RepositoryConstants.REPOSITORY_URL, tacURL);
} else {
bean = ConnectionBean.getDefaultConnectionBean();
}
}
Context ctx = CorePlugin.getContext();
RepositoryContext repositoryContext = new RepositoryContext();
ctx.putProperty(Context.REPOSITORY_CONTEXT_KEY, repositoryContext);
repositoryContext.setUser(userInfo);
repositoryContext.setClearPassword(password);
repositoryContext.setFields(bean.getDynamicFields());
repositoryFactory.setRepositoryFactoryFromProvider(RepositoryFactoryProvider.getRepositoriyById(bean.getRepositoryId()));
Project project = null;
for (Project p : repositoryFactory.readProject()) {
if (p.getLabel().equals(projectName) || p.getTechnicalLabel().equals(projectName)) {
project = p;
break;
}
}
if (!reload) {
if (deleteProjectIfExist && project != null) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(project.getTechnicalLabel());
if (eclipseProject.exists()) {
eclipseProject.delete(true, new NullProgressMonitor());
}
}
if (!isRemote && (project == null || deleteProjectIfExist)) {
Project projectInfor = //$NON-NLS-1$
ProjectHelper.createProject(//$NON-NLS-1$
projectName, //$NON-NLS-1$
"", language, userInfo);
project = repositoryFactory.createProject(projectInfor);
}
} else {
if (project != null && !project.getEmfProject().isLocal() && repositoryFactory.isLocalConnectionProvider()) {
List<IRepositoryFactory> rfList = RepositoryFactoryProvider.getAvailableRepositories();
IRepositoryFactory remoteFactory = null;
for (IRepositoryFactory rf : rfList) {
if (!rf.isLocalConnectionProvider()) {
remoteFactory = rf;
break;
}
}
if (remoteFactory != null) {
repositoryFactory.setRepositoryFactoryFromProvider(remoteFactory);
repositoryFactory.getRepositoryContext().setOffline(true);
}
}
}
if (!repositoryFactory.isLocalConnectionProvider()) {
ProjectManager.getInstance().setMainProjectBranch(project, preferenceManipulator.getLastSVNBranch(new JSONObject(project.getEmfProject().getUrl()).getString("location"), project.getTechnicalLabel()));
}
if (project != null && reload && lastBean != null && repositoryFactory.getRepositoryContext().isOffline()) {
if (PluginChecker.isSVNProviderPluginLoaded()) {
ISVNProviderService svnProviderService = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
if (svnProviderService.isSVNProject(project)) {
String projectUrl = svnProviderService.getProjectUrl(project);
String lastBranch = preferenceManipulator.getLastSVNBranch(projectUrl, project.getTechnicalLabel());
ProjectManager.getInstance().setMainProjectBranch(project, lastBranch);
}
}
}
if (project == null) {
//$NON-NLS-1$
throw new LoginException(Messages.getString("RepositoryService.projectNotFound", projectName));
}
repositoryContext.setProject(project);
repositoryFactory.logOnProject(project, new NullProgressMonitor());
} catch (final PersistenceException e) {
if (e instanceof OperationCancelException) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.getString("LoginDialog.logonCanceled"), e.getLocalizedMessage());
}
});
} else {
MessageBoxExceptionHandler.process(e, new Shell());
}
repositoryFactory.logOffProject();
LoginHelper.isAutoLogonFailed = true;
} catch (LoginException e) {
MessageBoxExceptionHandler.process(e, new Shell());
repositoryFactory.logOffProject();
LoginHelper.isAutoLogonFailed = true;
} catch (BusinessException e) {
MessageBoxExceptionHandler.process(e, new Shell());
repositoryFactory.logOffProject();
LoginHelper.isAutoLogonFailed = true;
} catch (CoreException e) {
MessageBoxExceptionHandler.process(e, new Shell());
repositoryFactory.logOffProject();
LoginHelper.isAutoLogonFailed = true;
} catch (JSONException e) {
ExceptionHandler.process(e);
LoginHelper.isAutoLogonFailed = true;
}
if (LoginHelper.isAutoLogonFailed) {
LoginHelper.isRestart = true;
}
return true;
}
return false;
}
use of org.talend.core.prefs.PreferenceManipulator 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;
}
Aggregations