Search in sources :

Example 1 with JSONObject

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

the class LoginProjectPage method createFetchLicenseJob.

private Job createFetchLicenseJob(Project proj) {
    final String projLabel = proj.getLabel();
    Job fetchJob = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    Messages.getString("LoginProjectPage.fetchLicense.job", proj.getLabel())) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            ConnectionBean cBean = loginHelper.getCurrentSelectedConnBean();
            try {
                String userId = cBean.getUser();
                String url = getAdminURL();
                JSONObject jsonObj = getRemoteService().getLicenseKey(userId, cBean.getPassword(), url, projLabel);
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String fetchedLicense = jsonObj.getString("customerName") + "_" + jsonObj.getString("licenseKey");
                String key = loginHelper.getLicenseMapKey(url, projLabel, userId);
                loginHelper.putLicense(key, fetchedLicense);
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
            return Status.OK_STATUS;
        }

        @Override
        protected void canceling() {
            Thread thread = this.getThread();
            try {
                // to interrupt the slow network connection
                thread.interrupt();
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    };
    fetchLicenseJobMap.put(proj, fetchJob);
    return fetchJob;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JSONObject(org.talend.utils.json.JSONObject) ConnectionBean(org.talend.core.model.general.ConnectionBean) Job(org.eclipse.core.runtime.jobs.Job) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.talend.commons.exception.SystemException) JSONException(org.talend.utils.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 2 with JSONObject

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

the class ColumnListControllerTest method testreUsedColumnFunctionArrayCheck2.

@Test
public void testreUsedColumnFunctionArrayCheck2() throws Exception {
    //$NON-NLS-1$
    column.setLabel("B");
    column.setTalendType(JavaTypesManager.STRING.getId());
    JSONObject functionInfoObj = new JSONObject();
    JSONArray parametersArr = new JSONArray();
    try {
        functionInfoObj.put(PARAMETER_CLASS_NAME, "");
        functionInfoObj.put(NAME, "...");
        JSONObject parameterObj = new JSONObject();
        parameterObj.put(PARAMETER_NAME, "customize parameter");
        parameterObj.put(PARAMETER_VALUE, "");
        parametersArr.put(parameterObj);
        functionInfoObj.put(PARAMETERS, parametersArr);
    } catch (JSONException e) {
        ExceptionHandler.process(e);
    }
    column.getAdditionalField().put("FUNCTION_INFO", functionInfoObj.toString());
    table.getListColumns().add(column);
    String functioExpression = "";
    testNewLineArrayFunction(functioExpression, column.getLabel());
}
Also used : JSONObject(org.talend.utils.json.JSONObject) JSONArray(org.talend.utils.json.JSONArray) JSONException(org.talend.utils.json.JSONException) Test(org.junit.Test)

Example 3 with JSONObject

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

the class ColumnListControllerTest method testreUsedColumnFunctionArrayCheck1.

@Test
public void testreUsedColumnFunctionArrayCheck1() throws Exception {
    //$NON-NLS-1$
    column.setLabel("A");
    column.setTalendType(JavaTypesManager.STRING.getId());
    JSONObject functionInfoObj = new JSONObject();
    JSONArray parametersArr = new JSONArray();
    try {
        functionInfoObj.put(PARAMETER_CLASS_NAME, "StringHandling");
        functionInfoObj.put(NAME, "CHANGE");
        JSONObject parameterObj1 = new JSONObject();
        parameterObj1.put(PARAMETER_NAME, "oldStr");
        parameterObj1.put(PARAMETER_VALUE, "\"hello world!\" ");
        parametersArr.put(parameterObj1);
        JSONObject parameterObj2 = new JSONObject();
        parameterObj2.put(PARAMETER_NAME, "regex");
        parameterObj2.put(PARAMETER_VALUE, "\"world\" ");
        parametersArr.put(parameterObj2);
        JSONObject parameterObj3 = new JSONObject();
        parameterObj3.put(PARAMETER_NAME, "replacement");
        parameterObj3.put(PARAMETER_VALUE, "\"guy\" ");
        parametersArr.put(parameterObj3);
        functionInfoObj.put(PARAMETERS, parametersArr);
    } catch (JSONException e) {
        ExceptionHandler.process(e);
    }
    column.getAdditionalField().put("FUNCTION_INFO", functionInfoObj.toString());
    table.getListColumns().add(column);
    String functioExpression = "StringHandling.CHANGE(\"hello world!\",\"world\",\"guy\")";
    testNewLineArrayFunction(functioExpression, column.getLabel());
}
Also used : JSONObject(org.talend.utils.json.JSONObject) JSONArray(org.talend.utils.json.JSONArray) JSONException(org.talend.utils.json.JSONException) Test(org.junit.Test)

Example 4 with JSONObject

use of org.talend.utils.json.JSONObject 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);
        }
    }
}
Also used : Context(org.talend.core.context.Context) RepositoryContext(org.talend.core.context.RepositoryContext) RepositoryContext(org.talend.core.context.RepositoryContext) PreferenceManipulator(org.talend.core.prefs.PreferenceManipulator) JSONObject(org.talend.utils.json.JSONObject) JSONObject(org.talend.utils.json.JSONObject)

Example 5 with JSONObject

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

the class LoginHelper method getStorage.

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

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