use of org.talend.commons.exception.BusinessException 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.commons.exception.BusinessException in project tdi-studio-se by Talend.
the class TOSLoginComposite method addListener.
private void addListener() {
createButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Project project = null;
ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
NewProjectWizard newPrjWiz = new NewProjectWizard(null);
WizardDialog newProjectDialog = new WizardDialog(getShell(), newPrjWiz);
//$NON-NLS-1$
newProjectDialog.setTitle(Messages.getString("LoginDialog.newProjectTitle"));
if (newProjectDialog.open() == Window.OK) {
project = newPrjWiz.getProject();
refresh();
ArrayList<String> allProjects = (ArrayList<String>) projectListViewer.getInput();
int index = 0;
Collections.sort(allProjects);
for (int i = 0; i < allProjects.size(); i++) {
String projectName = allProjects.get(i);
if (project.getLabel().equals(projectName)) {
index = i;
break;
}
}
projectListViewer.getList().select(index);
projectListViewer.refresh();
}
}
});
deleteButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Shell activeShell = Display.getCurrent().getActiveShell();
SelectDeleteProjectDialog dialog = new SelectDeleteProjectDialog(activeShell, true);
if (dialog.open() == Dialog.OK) {
CorePlugin.getDefault().getRepositoryLocalProviderService().resetXmiResourceSet();
java.util.List<Object> delList = dialog.getDelList();
if (delList.size() != 0) {
for (Object obj : delList) {
if (obj instanceof IProject) {
IProject p = (IProject) obj;
if (projectsMap.containsKey(p.getName())) {
projectsMap.remove(p.getName());
String name = convertorMapper.get(p.getName());
if (name != null) {
convertorMapper.remove(p.getName());
TOSLoginComposite.this.projectListViewer.getList().remove(name);
}
if (TOSLoginComposite.this.projectListViewer.getList().getItemCount() == 0) {
enableOpenAndDelete(false);
} else if (TOSLoginComposite.this.projectListViewer.getSelection().isEmpty()) {
TOSLoginComposite.this.projectListViewer.getList().select(0);
}
try {
setStatusArea();
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
}
}
}
}
}
}
refresh();
}
});
importButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ImportDemoProjectAction.getInstance().setShell(getShell());
ImportProjectAsAction.getInstance().run();
String newProject = ImportProjectAsAction.getInstance().getProjectName();
if (newProject != null) {
ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
Project[] projects = null;
try {
projects = repositoryFactory.readProject();
} catch (PersistenceException e1) {
e1.printStackTrace();
} catch (BusinessException e1) {
e1.printStackTrace();
}
if (!projectsMap.containsKey(newProject.toUpperCase())) {
for (Project project : projects) {
if (project.getLabel().toUpperCase().equals(newProject.toUpperCase())) {
projectsMap.put(newProject.toUpperCase(), project);
convertorMapper.put(newProject.toUpperCase(), newProject);
enableOpenAndDelete(true);
try {
setStatusArea();
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
}
}
}
TOSLoginComposite.this.projectListViewer.setInput(new ArrayList(convertorMapper.values()));
}
}
try {
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
ProxyRepositoryFactory.getInstance().initialize();
} catch (PersistenceException e) {
throw new InvocationTargetException(e);
}
}
};
new ProgressMonitorDialog(getShell()).run(true, false, op);
refresh();
} catch (InvocationTargetException e1) {
e1.getTargetException();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
changeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dirDialog = new DirectoryDialog(dialog.getShell());
String path = dirDialog.open();
if (path == null || "".equals(path)) {
//$NON-NLS-1$
workspaceText.setText(getRecentWorkSpace());
loginComposite.getConnection().setWorkSpace(getRecentWorkSpace());
} else {
workspaceText.setText(path);
loginComposite.getConnection().setWorkSpace(path);
if (!path.equals(oldPath)) {
oldPath = path;
restartBut.setVisible(true);
openButton.setEnabled(false);
deleteButton.setEnabled(false);
createButton.setEnabled(false);
importButton.setEnabled(false);
demoProjectButton.setEnabled(false);
changeButton.setEnabled(false);
}
}
java.util.List<ConnectionBean> list = new ArrayList<ConnectionBean>();
list.add(loginComposite.getConnection());
loginComposite.storedConnections = list;
perReader.saveConnections(loginComposite.storedConnections);
if (!loginComposite.isWorkSpaceSame()) {
try {
setStatusArea();
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
}
}
}
});
restartBut.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
LoginComposite.isRestart = true;
ConnectionBean connection = loginComposite.getConnection();
perReader.saveLastConnectionBean(connection);
// update the restart command line to specify the workspace to launch
// if relaunch, should delete the "disableLoginDialog" argument in eclipse data for bug TDI-19214
//$NON-NLS-1$
EclipseCommandLine.updateOrCreateExitDataPropertyWithCommand("-data", connection.getWorkSpace(), false);
// store the workspace in the eclipse history so that it is rememebered on next studio launch
//$NON-NLS-1$
ChooseWorkspaceData workspaceData = new ChooseWorkspaceData("");
workspaceData.workspaceSelected(connection.getWorkSpace());
workspaceData.writePersistedData();
dialog.okPressed();
}
});
openButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
loginComposite.setRepositoryContextInContext();
if (!TOSLoginComposite.this.projectListViewer.getSelection().isEmpty()) {
String selection = TOSLoginComposite.this.projectListViewer.getList().getSelection()[0];
if (selection != null && !selection.equals("")) {
Project project = (Project) projectsMap.get(selection.toUpperCase());
boolean flag = dialog.logIn(project);
if (flag) {
dialog.okPressed();
}
}
}
}
});
demoProjectButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ImportDemoProjectAction action = ImportDemoProjectAction.getInstance();
action.setShell(getShell());
action.run();
refresh();
}
});
}
use of org.talend.commons.exception.BusinessException in project tdi-studio-se by Talend.
the class TOSLoginComposite method refresh.
private void refresh() {
ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
Project[] projects = null;
try {
projects = repositoryFactory.readProject();
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
} catch (BusinessException e1) {
ExceptionHandler.process(e1);
}
this.projectListViewer.getList().removeAll();
projectsMap.clear();
convertorMapper.clear();
if (projects != null) {
for (Project pro : projects) {
convertorMapper.put(pro.getTechnicalLabel(), pro.getLabel());
projectsMap.put(pro.getTechnicalLabel(), pro);
enableOpenAndDelete(true);
}
this.projectListViewer.setInput(new ArrayList(convertorMapper.values()));
}
try {
setStatusArea();
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
}
}
use of org.talend.commons.exception.BusinessException in project tdi-studio-se by Talend.
the class CodeGeneratorEmittersPoolFactory method initializeEmittersPool.
/**
* real pool initialization.
*
* @param monitorWrap
*
* @return
* @throws JETException
*/
private static void initializeEmittersPool(List<JetBean> components, ECodeLanguage codeLanguage, IProgressMonitor monitorWrap) {
IProgressMonitor monitor = new NullProgressMonitor();
IProgressMonitor sub = new SubProgressMonitor(monitor, 1);
int monitorBuffer = 0;
HashMap<String, String> globalClasspath = new HashMap<String, String>();
for (JetBean jetBean : components) {
globalClasspath.putAll(jetBean.getClassPath());
// compute the CRC
jetBean.setCrc(extractTemplateHashCode(jetBean));
}
emitterPool = new HashMap<JetBean, JETEmitter>();
List<JetBean> alreadyCompiledEmitters = new ArrayList<JetBean>();
// try {
TalendJetEmitter dummyEmitter = null;
try {
dummyEmitter = new TalendJetEmitter(null, null, sub, globalClasspath, !ComponentCompilations.getMarkers());
} catch (JETException e) {
//$NON-NLS-1$
log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.jetEmitterInitialException") + e.getMessage(), e);
}
boolean isSkeletonChanged = JetSkeletonManager.updateSkeletonPersistenceData();
if (!isSkeletonChanged) {
try {
alreadyCompiledEmitters = loadEmfPersistentData(EmfEmittersPersistenceFactory.getInstance(codeLanguage).loadEmittersPool(), components, monitorWrap);
for (JetBean jetBean : alreadyCompiledEmitters) {
TalendJetEmitter emitter = new TalendJetEmitter(jetBean, dummyEmitter.getTalendEclipseHelper());
emitterPool.put(jetBean, emitter);
monitorBuffer++;
if (monitorBuffer % 100 == 0) {
monitorWrap.worked(100);
monitorBuffer = 0;
}
}
} catch (BusinessException e) {
// error already loggued
emitterPool = new HashMap<JetBean, JETEmitter>();
}
} else {
ComponentCompilations.deleteMarkers();
}
synchronizedComponent(components, sub, alreadyCompiledEmitters, dummyEmitter, monitorBuffer, monitorWrap);
monitorWrap.worked(monitorBuffer);
try {
EmfEmittersPersistenceFactory.getInstance(codeLanguage).saveEmittersPool(extractEmfPersistenData(alreadyCompiledEmitters));
} catch (BusinessException e) {
//$NON-NLS-1$
log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.PersitentData.Error") + e.getMessage(), e);
}
}
use of org.talend.commons.exception.BusinessException in project tdi-studio-se by Talend.
the class CodeGeneratorEmittersPoolFactory method loadEmfPersistentData.
private static List<JetBean> loadEmfPersistentData(List<LightJetBean> datas, List<JetBean> completeJetBeanList, IProgressMonitor monitorWrap) throws BusinessException {
List<JetBean> toReturn = new ArrayList<JetBean>();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
//$NON-NLS-1$
IProject project = workspace.getRoot().getProject(".JETEmitters");
URL url = null;
try {
IFile file = project.getFile(Path.fromOSString("runtime"));
url = file.getLocationURI().toURL();
int lightBeanIndex = 0;
LightJetBean lightBean = null;
LightJetBean myLightJetBean = null;
//$NON-NLS-1$
String unitTemplateFullURI = "";
long unitTemplateHashCode = 0;
HashMap<String, LightJetBean> mapOnName = new HashMap<String, LightJetBean>();
boolean forceMethodLoad = ComponentCompilations.getMarkers();
if (forceMethodLoad) {
// init specific map based on component name : mapOnName
for (LightJetBean ljb : datas) {
//$NON-NLS-1$
mapOnName.put(ljb.getTemplateRelativeUri().substring(ljb.getTemplateRelativeUri().lastIndexOf("/")), ljb);
}
}
int monitorBuffer = 0;
for (JetBean unit : completeJetBeanList) {
monitorBuffer++;
if (monitorBuffer % 200 == 0) {
monitorWrap.worked(200);
monitorBuffer = 0;
}
unitTemplateFullURI = unit.getTemplateRelativeUri();
unitTemplateHashCode = unit.getCrc();
myLightJetBean = new LightJetBean(unitTemplateFullURI, unit.getVersion(), unitTemplateHashCode);
if (((lightBeanIndex = datas.indexOf(myLightJetBean)) > -1) || forceMethodLoad) {
if (!forceMethodLoad) {
lightBean = datas.get(lightBeanIndex);
} else {
lightBean = mapOnName.get(myLightJetBean.getTemplateRelativeUri().substring(//$NON-NLS-1$
myLightJetBean.getTemplateRelativeUri().lastIndexOf("/")));
}
if (lightBean != null && lightBean.getCrc() == unit.getCrc()) {
unit.setClassName(lightBean.getClassName());
unit.setMethodName(lightBean.getMethodName());
toReturn.add(unit);
}
}
}
monitorWrap.worked(monitorBuffer);
} catch (MalformedURLException e) {
//$NON-NLS-1$
log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.JETEmitters.NoPresent"));
throw new BusinessException(e);
}
return toReturn;
}
Aggregations