Search in sources :

Example 81 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory 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 82 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class LoginHelper method logIn.

public boolean logIn(ConnectionBean connBean, final Project project) {
    final ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    final boolean needRestartForLocal = needRestartForLocal(connBean);
    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
    prefManipulator.setLastProject(project.getTechnicalLabel());
    saveLastConnBean(connBean);
    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)) {
                    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) {
        CommonExceptionHandler.process(e);
        MessageDialog.openError(getUsableShell(), getUsableShell().getText(), e.getMessage());
        return false;
    }
    final Shell shell = getUsableShell();
    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()) {
        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(), getUsableShell());
        }
        factory.getRepositoryContext().setProject(null);
        // }
        return false;
    } catch (InterruptedException e) {
        // }
        return false;
    }
    return true;
}
Also used : IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) OperationCancelException(org.talend.commons.exception.OperationCancelException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ICoreTisService(org.talend.core.services.ICoreTisService) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException)

Example 83 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tmdm-studio-se by Talend.

the class RepositoryResourceUtilTest method testCreateFolderViewObject.

@Test
public void testCreateFolderViewObject() throws Exception {
    boolean isSystem = false;
    String folderName = "folderName";
    PowerMockito.mockStatic(ProjectManager.class);
    ProjectManager mockProjectManager = mock(ProjectManager.class);
    Project mockProject = mock(Project.class);
    IProject mockIProject = mock(IProject.class);
    when(ProjectManager.getInstance()).thenReturn(mockProjectManager);
    when(ProjectManager.getInstance().getCurrentProject()).thenReturn(mockProject);
    IFolder mockFolder = mock(IFolder.class);
    PowerMockito.mockStatic(ResourceUtils.class);
    when(ResourceUtils.getProject(mockProject)).thenReturn(mockIProject);
    when(mockIProject.getFolder(Mockito.anyString())).thenReturn(mockFolder);
    when(mockFolder.exists()).thenReturn(false);
    PowerMockito.doNothing().when(ResourceUtils.class, "createFolder", mockFolder);
    ItemState mockItemState = mock(ItemState.class);
    when(mockItemState.getPath()).thenReturn("mocked_path");
    Item mockParentItem = mock(Item.class);
    when(mockParentItem.getState()).thenReturn(mockItemState);
    String processFolder = "process";
    PowerMockito.mockStatic(ERepositoryObjectType.class);
    ERepositoryObjectType mockType = mock(ERepositoryObjectType.class);
    when(mockType.getType()).thenReturn("mockType");
    when(ERepositoryObjectType.getFolderName(mockType)).thenReturn(processFolder);
    PowerMockito.mockStatic(ProxyRepositoryFactory.class);
    ProxyRepositoryFactory proxyRepositoryFactory = mock(ProxyRepositoryFactory.class);
    when(ProxyRepositoryFactory.getInstance()).thenReturn(proxyRepositoryFactory);
    Folder mockTalendFolder = mock(Folder.class);
    when(proxyRepositoryFactory.createFolder(any(Project.class), any(ERepositoryObjectType.class), any(IPath.class), anyString())).thenReturn(mockTalendFolder);
    IRepositoryViewObject folderViewObject = RepositoryResourceUtil.createFolderViewObject(mockType, folderName, mockParentItem, isSystem);
    assertNotNull(folderViewObject);
    verify(proxyRepositoryFactory, times(1)).createFolder(any(Project.class), any(ERepositoryObjectType.class), any(IPath.class), anyString());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Folder(org.talend.core.model.repository.Folder) IFolder(org.eclipse.core.resources.IFolder) IProject(org.eclipse.core.resources.IProject) ProjectManager(org.talend.repository.ProjectManager) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) Item(org.talend.core.model.properties.Item) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IFolder(org.eclipse.core.resources.IFolder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 84 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdq-studio-se by Talend.

the class CorePlugin method initProxyRepository.

/**
 * DOC zshen Comment method "initProxyRepository".
 */
public ReturnCode initProxyRepository() {
    ReturnCode rc = new ReturnCode();
    Project project = null;
    RepositoryContext repositoryContext = (RepositoryContext) org.talend.core.runtime.CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
    if (repositoryContext != null) {
        project = repositoryContext.getProject();
        User user = repositoryContext.getUser();
        ReponsitoryContextBridge.initialized(project.getEmfProject(), user);
    } else {
        // else project is null, then we are in TOP only
        Location instanceLoc = Platform.getInstanceLocation();
        try {
            if (instanceLoc.isLocked()) {
                // $NON-NLS-1$
                rc.setMessage(DefaultMessagesImpl.getString("CorePlugin.workspaceInUse"));
                rc.setOk(false);
                return rc;
            } else {
                instanceLoc.lock();
            }
        } catch (IOException e) {
            log.error(e, e);
        }
        ProxyRepositoryFactory proxyRepository = ProxyRepositoryFactory.getInstance();
        IRepositoryFactory repository = RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID);
        if (repository == null) {
            // $NON-NLS-1$
            log.fatal(DefaultMessagesImpl.getString("CorePlugin.noLocalRepositoryFound"));
            // $NON-NLS-1$
            rc.setMessage(DefaultMessagesImpl.getString("CorePlugin.noLocalRepositoryFound"));
            rc.setOk(false);
            return rc;
        }
        proxyRepository.setRepositoryFactoryFromProvider(repository);
        try {
            proxyRepository.checkAvailability();
            proxyRepository.initialize();
            XmiResourceManager xmiResourceManager = proxyRepository.getRepositoryFactoryFromProvider().getResourceManager();
            IProject rootProject = ResourceManager.getRootProject();
            if (rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()) {
                // Initialize TDQ EMF model packages.
                new EMFUtil();
                project = new Project(xmiResourceManager.loadProject(rootProject));
            } else {
                // $NON-NLS-1$
                String username = "talend@talend.com";
                // $NON-NLS-1$
                String password = "talend@talend.com";
                User user = PropertiesFactoryImpl.eINSTANCE.createUser();
                user.setLogin(username);
                user.setPassword(password.getBytes());
                String projectName = ResourceManager.getRootProjectName();
                String projectDesc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName).getComment();
                Project projectInfor = ProjectHelper.createProject(projectName, projectDesc, ECodeLanguage.JAVA.getName(), user);
                // MOD zshen create project by proxyRepository
                checkFileName(projectInfor.getLabel(), RepositoryConstants.PROJECT_PATTERN);
                project = proxyRepository.getRepositoryFactoryFromProvider().createProject(user, password, projectInfor);
            }
            if (project != null) {
                initRepositoryContext(project);
                // add status
                // $NON-NLS-1$
                String defaultTechnicalStatusList = "DEV development;TEST testing;PROD production";
                List<Status> statusList = StatusHelper.parse(defaultTechnicalStatusList);
                proxyRepository.setTechnicalStatus(statusList);
                // 'maven_user_settings.xml').before set, must check user setting first.
                if (org.talend.commons.utils.platform.PluginChecker.isOnlyTopLoaded()) {
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IMavenUIService.class)) {
                        IMavenUIService mavenUIService = (IMavenUIService) GlobalServiceRegister.getDefault().getService(IMavenUIService.class);
                        if (mavenUIService != null) {
                            mavenUIService.checkUserSettings(new NullProgressMonitor());
                            mavenUIService.updateMavenResolver(false);
                            mavenUIService.addMavenConfigurationChangeListener();
                        }
                    }
                    // deploy libraries and maven index here
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
                        ILibrariesService librariesService = (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
                        if (librariesService != null) {
                            librariesService.syncLibraries();
                            // TDQ-9529 check libararies install status at here,so that
                            // "Optional third-party libraries" is displayed in the "Additional Talend Package"
                            // dialog.
                            librariesService.checkLibraries();
                        }
                    }
                }
                CWMPlugin.getDefault().createLibFolderIfNotExist();
                // TDQ-11348 the readOnlyUser property is false for TOP.
                // $NON-NLS-1$
                System.getProperties().put("ReadOnlyUser", new Boolean(false).toString());
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            rc.setMessage(e.getMessage());
            rc.setOk(false);
            return rc;
        }
    }
    return rc;
}
Also used : Status(org.talend.core.model.properties.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RepositoryContext(org.talend.core.context.RepositoryContext) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ReturnCode(org.talend.utils.sugars.ReturnCode) User(org.talend.core.model.properties.User) ILibrariesService(org.talend.core.model.general.ILibrariesService) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EMFUtil(org.talend.commons.emf.EMFUtil) PersistenceException(org.talend.commons.exception.PersistenceException) IMavenUIService(org.talend.core.runtime.services.IMavenUIService) Location(org.eclipse.osgi.service.datalocation.Location)

Example 85 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdq-studio-se by Talend.

the class UnitTestBuildHelper method initProxyRepository.

/**
 * DOC talend Comment method "initProxyRepository".
 */
public static void initProxyRepository(IProject rootProject) {
    Project project = null;
    ProxyRepositoryFactory proxyRepository = ProxyRepositoryFactory.getInstance();
    IRepositoryFactory repository = RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID);
    if (repository == null) {
        log.fatal(DefaultMessagesImpl.getString(// $NON-NLS-1$
        "No local Repository found! Probably due to a missing plugin in the product."));
    }
    proxyRepository.setRepositoryFactoryFromProvider(repository);
    try {
        proxyRepository.checkAvailability();
        proxyRepository.setFullLogonFinished(false);
        // proxyRepository.initialize();
        XmiResourceManager xmiResourceManager = new XmiResourceManager();
        if (rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()) {
            // Initialize TDQ EMF model packages.
            new EMFUtil();
            project = new Project(xmiResourceManager.loadProject(rootProject));
        } else {
            User user = org.talend.core.model.properties.impl.PropertiesFactoryImpl.eINSTANCE.createUser();
            // $NON-NLS-1$
            user.setLogin("talend@talend.com");
            // $NON-NLS-1$
            user.setPassword("talend@talend.com".getBytes());
            String projectName = rootProject.getName();
            String projectDesc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName).getComment();
            Project projectInfor = ProjectHelper.createProject(projectName, projectDesc, ECodeLanguage.JAVA.getName(), user);
            // MOD zshen create project by proxyRepository
            checkFileName(projectInfor.getLabel(), RepositoryConstants.PROJECT_PATTERN);
            project = proxyRepository.getRepositoryFactoryFromProvider().createProject(projectInfor);
        }
        if (project != null) {
            initRepositoryContext(project);
            // add status
            // $NON-NLS-1$
            String defaultTechnicalStatusList = "DEV development;TEST testing;PROD production";
            List<Status> statusList = StatusHelper.parse(defaultTechnicalStatusList);
            proxyRepository.setTechnicalStatus(statusList);
        }
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : Status(org.talend.core.model.properties.Status) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) User(org.talend.core.model.properties.User) EMFUtil(org.talend.commons.emf.EMFUtil) PersistenceException(org.talend.commons.exception.PersistenceException) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager)

Aggregations

ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)92 PersistenceException (org.talend.commons.exception.PersistenceException)40 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)25 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)22 Project (org.talend.core.model.general.Project)20 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)17 EList (org.eclipse.emf.common.util.EList)15 IProject (org.eclipse.core.resources.IProject)14 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)14 IRepositoryFactory (org.talend.core.repository.model.IRepositoryFactory)12 User (org.talend.core.model.properties.User)11 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)11 Path (org.eclipse.core.runtime.Path)10 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)9 ArrayList (java.util.ArrayList)8 BusinessException (org.talend.commons.exception.BusinessException)8 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 EMFUtil (org.talend.commons.emf.EMFUtil)6