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;
}
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());
}
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());
}
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);
}
}
}
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;
}
Aggregations