Search in sources :

Example 31 with JSONObject

use of org.talend.utils.json.JSONObject 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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RepositoryContext(org.talend.core.context.RepositoryContext) PreferenceManipulator(org.talend.core.prefs.PreferenceManipulator) User(org.talend.core.model.properties.User) OperationCancelException(org.talend.commons.exception.OperationCancelException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Shell(org.eclipse.swt.widgets.Shell) BusinessException(org.talend.commons.exception.BusinessException) ConnectionUserPerReader(org.talend.repository.ui.login.connections.ConnectionUserPerReader) IContext(org.talend.core.model.process.IContext) RepositoryContext(org.talend.core.context.RepositoryContext) Context(org.talend.core.context.Context) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ISVNProviderService(org.talend.core.services.ISVNProviderService) JSONException(org.talend.utils.json.JSONException) IBrandingService(org.talend.core.ui.branding.IBrandingService) IProject(org.eclipse.core.resources.IProject) IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) JSONObject(org.talend.utils.json.JSONObject) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) ConnectionBean(org.talend.core.model.general.ConnectionBean)

Example 32 with JSONObject

use of org.talend.utils.json.JSONObject in project tdi-studio-se by Talend.

the class FunctionManagerExt method getFunctionFromColumn.

public Function getFunctionFromColumn(MetadataColumnExt column) {
    Function function = null;
    String functionInfo = column.getFunctionInfo();
    if (functionInfo != null) {
        try {
            JSONObject functionObj = new JSONObject(functionInfo);
            String functionName = functionObj.getString(Function.NAME);
            int functionSize = 0;
            JSONArray parametersArray = functionObj.getJSONArray(Function.PARAMETERS);
            if (parametersArray != null) {
                functionSize = parametersArray.length();
            }
            List<Function> funcs = getFunctionsByType(column.getTalendType());
            for (Function func : funcs) {
                if (func.getName().equals(functionName) && func.getParameters().size() == functionSize) {
                    function = func;
                    break;
                }
            }
            if (function != null) {
                function = function.clone(parametersArray);
            }
        } catch (JSONException e) {
            ExceptionHandler.process(e);
        }
    }
    return function;
}
Also used : JSONObject(org.talend.utils.json.JSONObject) JSONArray(org.talend.utils.json.JSONArray) JSONException(org.talend.utils.json.JSONException)

Example 33 with JSONObject

use of org.talend.utils.json.JSONObject in project tdi-studio-se by Talend.

the class LoginHelper method getLocation.

private String getLocation(String url) throws JSONException {
    JSONObject jsonObject = new JSONObject(url);
    //$NON-NLS-1$
    String location = "";
    if (jsonObject.has("location")) {
        //$NON-NLS-1$
        location = jsonObject.getString("location");
    }
    return location;
}
Also used : JSONObject(org.talend.utils.json.JSONObject)

Example 34 with JSONObject

use of org.talend.utils.json.JSONObject in project tdi-studio-se by Talend.

the class LoginProjectPage method getStorage.

private String getStorage(Project project) throws JSONException {
    if (project == null) {
        return "";
    }
    String storage = "";
    if (project != null) {
        String url = project.getEmfProject().getUrl();
        if (url == null) {
            return "";
        }
        JSONObject jsonObj = new JSONObject(url);
        storage = jsonObj.getString("storage");
    }
    return storage;
}
Also used : JSONObject(org.talend.utils.json.JSONObject)

Example 35 with JSONObject

use of org.talend.utils.json.JSONObject in project tdi-studio-se by Talend.

the class ColumnListController method reUsedColumnFunctionArrayCheck.

private static void reUsedColumnFunctionArrayCheck(Map<String, Object> newLine, IElement element, String[] codes) {
    if (element instanceof INode && ((INode) element).getMetadataList().size() > 0 && ((INode) element).getComponent().getName().equals("tRowGenerator")) {
        IMetadataTable table = ((INode) element).getMetadataList().get(0);
        //$NON-NLS-1$
        String lineName = (String) newLine.get("SCHEMA_COLUMN");
        for (IMetadataColumn column : table.getListColumns()) {
            if (lineName != null && lineName.equals(column.getLabel()) && "".equals(newLine.get("ARRAY"))) {
                Map<String, String> columnFunction = column.getAdditionalField();
                String functionInfo = columnFunction.get(FUNCTION_INFO);
                if (functionInfo != null) {
                    try {
                        JSONObject functionInfoObj = new JSONObject(functionInfo);
                        String functionExpression = "";
                        String functionName = functionInfoObj.getString(Function.NAME);
                        if (!functionName.equals("...")) {
                            String className = functionInfoObj.getString(Function.PARAMETER_CLASS_NAME);
                            String parmValueApend = "";
                            functionExpression = className + '.' + functionName + "(";
                            JSONArray parametersArray = functionInfoObj.getJSONArray(Function.PARAMETERS);
                            if (parametersArray != null) {
                                for (int i = 0; i < parametersArray.length(); i++) {
                                    JSONObject parameterObj = parametersArray.getJSONObject(i);
                                    String paramValue = parameterObj.getString(Function.PARAMETER_VALUE);
                                    parmValueApend = parmValueApend + paramValue.trim() + ',';
                                }
                            }
                            if (parmValueApend.endsWith(",")) {
                                parmValueApend = parmValueApend.substring(0, parmValueApend.lastIndexOf(","));
                            }
                            functionExpression = functionExpression + parmValueApend + ')';
                            newLine.put("ARRAY", functionExpression);
                        }
                    } catch (JSONException e) {
                        ExceptionHandler.process(e);
                    }
                }
            }
        }
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) INode(org.talend.core.model.process.INode) JSONObject(org.talend.utils.json.JSONObject) JSONArray(org.talend.utils.json.JSONArray) JSONException(org.talend.utils.json.JSONException) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Point(org.eclipse.swt.graphics.Point)

Aggregations

JSONObject (org.talend.utils.json.JSONObject)36 JSONException (org.talend.utils.json.JSONException)21 JSONArray (org.talend.utils.json.JSONArray)19 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)4 NoSQLConnection (org.talend.repository.model.nosql.NoSQLConnection)4 Iterator (java.util.Iterator)3 List (java.util.List)3 Map (java.util.Map)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 EHadoopParamName (org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SystemException (org.talend.commons.exception.SystemException)2 Context (org.talend.core.context.Context)2 RepositoryContext (org.talend.core.context.RepositoryContext)2 ConnectionBean (org.talend.core.model.general.ConnectionBean)2 Project (org.talend.core.model.general.Project)2 PreferenceManipulator (org.talend.core.prefs.PreferenceManipulator)2