Search in sources :

Example 31 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdi-studio-se by Talend.

the class LoginHelper method getProjects.

public Project[] getProjects(ConnectionBean connBean, ErrorManager errorManager) {
    if (connBean == null) {
        return null;
    }
    Project[] projects = null;
    if (connBean != null) {
        String user2 = connBean.getUser();
        String repositoryId2 = connBean.getRepositoryId();
        String workSpace = connBean.getWorkSpace();
        String name = connBean.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 (isRemoteConnection(connBean)) {
                String url = connBean.getDynamicFields().get(RepositoryConstants.REPOSITORY_URL);
                //$NON-NLS-1$
                valid = url != null && !"".equals(url);
            } else {
                valid = Pattern.matches(RepositoryConstants.MAIL_PATTERN, user2);
            }
            connBean.setComplete(valid);
        }
    }
    ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    repositoryFactory.setRepositoryFactoryFromProvider(RepositoryFactoryProvider.getRepositoriyById(connBean.getRepositoryId()));
    if (!connBean.isComplete()) {
        return projects;
    }
    boolean initialized = false;
    //$NON-NLS-1$
    final String newLine = ":\n";
    try {
        try {
            repositoryFactory.checkAvailability();
        } catch (WarningException e) {
            String warnings = e.getMessage();
            if (warnings != null && !warnings.equals(lastWarnings)) {
                lastWarnings = warnings;
                if (errorManager != null) {
                    errorManager.setWarnMessage(warnings);
                } else {
                    final Shell shell = new Shell(DisplayUtils.getDisplay(), SWT.ON_TOP | SWT.TOP);
                    //$NON-NLS-1$
                    MessageDialog.openWarning(shell, Messages.getString("LoginComposite.warningTitle"), warnings);
                }
            }
        }
        OverTimePopupDialogTask<Boolean> overTimePopupDialogTask = new OverTimePopupDialogTask<Boolean>() {

            @Override
            public Boolean run() throws Throwable {
                ProxyRepositoryFactory.getInstance().initialize();
                return null;
            }
        };
        overTimePopupDialogTask.setNeedWaitingProgressJob(false);
        overTimePopupDialogTask.runTask();
        initialized = true;
    } catch (Throwable e) {
        projects = new Project[0];
        if (errorManager != null) {
            //$NON-NLS-1$
            errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
        } else {
            final Shell shell = new Shell(DisplayUtils.getDisplay(), SWT.ON_TOP | SWT.TOP);
            //$NON-NLS-1$
            MessageDialog.openError(//$NON-NLS-1$
            shell, //$NON-NLS-1$
            Messages.getString("LoginComposite.warningTitle"), //$NON-NLS-1$
            Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
        }
    }
    if (initialized) {
        try {
            OverTimePopupDialogTask<Project[]> overTimePopupDialogTask = new OverTimePopupDialogTask<Project[]>() {

                @Override
                public Project[] run() throws Throwable {
                    return ProxyRepositoryFactory.getInstance().readProject();
                }
            };
            overTimePopupDialogTask.setNeedWaitingProgressJob(false);
            projects = overTimePopupDialogTask.runTask();
            Arrays.sort(projects, new Comparator<Project>() {

                @Override
                public int compare(Project p1, Project p2) {
                    return p1.getLabel().compareTo(p2.getLabel());
                }
            });
        } catch (PersistenceException e) {
            projects = new Project[0];
            if (errorManager != null) {
                //$NON-NLS-1$
                errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            } else {
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                getUsableShell(), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            }
        } catch (BusinessException e) {
            projects = new Project[0];
            if (errorManager != null) {
                //$NON-NLS-1$
                errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            } else {
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                getUsableShell(), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            }
        } catch (Throwable e) {
            projects = new Project[0];
            if (errorManager != null) {
                //$NON-NLS-1$
                errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            } else {
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                getUsableShell(), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            }
        }
    }
    return projects;
}
Also used : WarningException(org.talend.commons.exception.WarningException) Project(org.talend.core.model.general.Project) Shell(org.eclipse.swt.widgets.Shell) BusinessException(org.talend.commons.exception.BusinessException) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) OverTimePopupDialogTask(org.talend.repository.ui.dialog.OverTimePopupDialogTask) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 32 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdi-studio-se by Talend.

the class LoginAgreementPage method addListeners.

@Override
public void addListeners() {
    acceptButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            try {
                LicenseManagement.acceptLicense();
            } catch (BusinessException e) {
                ErrorDialogWidthDetailArea errorDialog = new ErrorDialogWidthDetailArea(getShell(), RegistrationPlugin.PLUGIN_ID, "", //$NON-NLS-1$
                e.getMessage());
                System.exit(0);
            }
            AbstractActionPage iNextPage = getNextPage();
            if (iNextPage == null) {
                return;
            }
            try {
                gotoNextPage();
            } catch (Throwable e1) {
                CommonExceptionHandler.process(e1);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing need to do
        }
    });
}
Also used : BusinessException(org.talend.commons.exception.BusinessException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ErrorDialogWidthDetailArea(org.talend.commons.ui.swt.dialogs.ErrorDialogWidthDetailArea) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 33 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdi-studio-se by Talend.

the class ComponentsLocalProviderService method validateComponent.

public boolean validateComponent(String componentFolder, ECodeLanguage language) {
    if (componentFolder != null && language != null) {
        File folder = new File(componentFolder);
        if (folder.exists() && folder.isDirectory()) {
            try {
                ComponentFileChecker.checkComponentFolder(folder, language.getName().toLowerCase());
                // It's ok
                return true;
            } catch (BusinessException e) {
                final BusinessException tempE = e;
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        Status status = new Status(IStatus.ERROR, CodeGeneratorActivator.PLUGIN_ID, 1, tempE.getMessage(), tempE.getCause());
                        ErrorDialog dlg = new ErrorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.getString("ComponentsLocalProviderService.talendExchangeError"), Messages.getString("ComponentsLocalProviderService.componentLoadError"), status, //$NON-NLS-1$ //$NON-NLS-2$
                        IStatus.ERROR);
                        dlg.open();
                    }
                });
            }
        }
    }
    return false;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) BusinessException(org.talend.commons.exception.BusinessException) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) File(java.io.File)

Example 34 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdi-studio-se by Talend.

the class ComponentsFactory method getComponentsLocation.

/**
     * DOC smallet Comment method "checkComponentFolder".
     * 
     * @param currentFolder
     * @return
     * @throws BusinessException
     */
private File getComponentsLocation(String folder) {
    String componentsPath = IComponentsFactory.COMPONENTS_LOCATION;
    IBrandingService breaningService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    if (breaningService.isPoweredOnlyCamel()) {
        componentsPath = IComponentsFactory.CAMEL_COMPONENTS_LOCATION;
    }
    Bundle b = Platform.getBundle(componentsPath);
    File file = null;
    try {
        URL url = FileLocator.find(b, new Path(folder), null);
        if (url == null) {
            return null;
        }
        URL fileUrl = FileLocator.toFileURL(url);
        file = new File(fileUrl.getPath());
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    return file;
}
Also used : Path(org.eclipse.core.runtime.Path) ComponentBundleToPath(org.talend.designer.core.model.components.ComponentBundleToPath) Bundle(org.osgi.framework.Bundle) ResourceBundle(java.util.ResourceBundle) IBrandingService(org.talend.core.ui.branding.IBrandingService) File(java.io.File) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) BusinessException(org.talend.commons.exception.BusinessException) IOException(java.io.IOException)

Example 35 with BusinessException

use of org.talend.commons.exception.BusinessException in project tmdm-studio-se by Talend.

the class RenameViewAction method moveToAnotherNode.

public void moveToAnotherNode(IRepositoryViewObject parent, IRepositoryViewObject viewObj) {
    MDMServerObjectItem item = (MDMServerObjectItem) viewObj.getProperty().getItem();
    waitSomeTime(viewObj);
    IProxyRepositoryFactory factory = getFactory();
    try {
        if (factory.isEditableAndLockIfPossible(item)) {
            String path = item.getState().getPath();
            IPath ipath = new Path(path);
            factory.moveObject(viewObj, ipath);
            IRepositoryViewObject iRepositoryViewObject = ContainerCacheService.get(viewObj.getRepositoryObjectType(), path);
            commonViewer.refresh(iRepositoryViewObject);
            commonViewer.refresh(parent);
        }
    } catch (PersistenceException e) {
        log.error(e.getMessage(), e);
    } catch (BusinessException e) {
        log.error(e.getMessage(), e);
    } finally {
        try {
            factory.unlock(item);
        } catch (PersistenceException e) {
            log.error(e.getMessage(), e);
        } catch (LoginException e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) BusinessException(org.talend.commons.exception.BusinessException) IPath(org.eclipse.core.runtime.IPath) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

BusinessException (org.talend.commons.exception.BusinessException)46 PersistenceException (org.talend.commons.exception.PersistenceException)21 IPath (org.eclipse.core.runtime.IPath)9 Path (org.eclipse.core.runtime.Path)9 Project (org.talend.core.model.general.Project)9 Item (org.talend.core.model.properties.Item)9 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 ArrayList (java.util.ArrayList)8 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 IFile (org.eclipse.core.resources.IFile)6 IProject (org.eclipse.core.resources.IProject)6 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)5 File (java.io.File)4 HashMap (java.util.HashMap)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 ReturnCode (org.talend.utils.sugars.ReturnCode)4 IOException (java.io.IOException)3 IWorkspace (org.eclipse.core.resources.IWorkspace)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3