use of org.talend.utils.json.JSONException in project tdi-studio-se by Talend.
the class LoginProjectPage method fillUIBranches.
private void fillUIBranches(final Project project, boolean lastUsedBranch) throws JSONException {
final String storage = getStorage(project);
if (LoginHelper.isRemoteConnection(getConnection())) {
currentProjectSettings = project;
final List<String> projectBranches = new ArrayList<String>();
if ("svn".equals(storage)) {
//$NON-NLS-1$
projectBranches.add("trunk");
branchesViewer.setInput(projectBranches);
//$NON-NLS-1$
branchesViewer.setSelection(new StructuredSelection(new Object[] { "trunk" }));
} else if ("git".equals(storage)) {
//$NON-NLS-1$
//$NON-NLS-1$
String master = "master";
projectBranches.add(master);
branchesViewer.setInput(projectBranches);
if (projectBranches.size() != 0) {
branchesViewer.setSelection(new StructuredSelection(new Object[] { projectBranches.contains(master) ? master : projectBranches.get(0) }));
}
}
branchesViewer.getCombo().setEnabled(false);
if (backgroundGUIUpdate == null) /* || (backgroundGUIUpdate.getState() == Job.NONE) */
{
backgroundGUIUpdate = new //$NON-NLS-1$
Job(//$NON-NLS-1$
"List Branches") {
@Override
protected IStatus run(IProgressMonitor monitor) {
projectBranches.clear();
try {
projectBranches.addAll(loginHelper.getProjectBranches(currentProjectSettings));
} catch (JSONException e) {
// TODO Auto-generated catch block
ExceptionHandler.process(e);
}
return org.eclipse.core.runtime.Status.OK_STATUS;
}
};
Job.getJobManager().addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getJob().equals(backgroundGUIUpdate)) {
if (branchesViewer != null && !branchesViewer.getCombo().isDisposed()) {
branchesViewer.getCombo().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
if (branchesViewer == null || branchesViewer.getControl() == null || branchesViewer.getControl().isDisposed()) {
return;
}
branchesViewer.setInput(projectBranches);
//branchesViewer.setSelection(new StructuredSelection(new Object[] { projectBranches.get(0) })); //$NON-NLS-1$
if ("svn".equals(storage) && projectBranches.size() != 0) {
branchesViewer.setSelection(new StructuredSelection(new Object[] { projectBranches.contains("trunk") ? "trunk" : projectBranches.get(0) }));
} else if ("git".equals(storage) && projectBranches.size() != 0) {
branchesViewer.setSelection(new StructuredSelection(new Object[] { projectBranches.contains("master") ? "master" : projectBranches.get(0) }));
}
// svnBranchCombo.getCombo().setFont(originalFont);
branchesViewer.getCombo().setEnabled(projectViewer.getControl().isEnabled());
}
});
}
}
}
});
branchesViewer.getCombo().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
backgroundGUIUpdate = null;
}
});
}
backgroundGUIUpdate.schedule();
}
}
use of org.talend.utils.json.JSONException 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);
}
}
}
}
}
}
use of org.talend.utils.json.JSONException in project tbd-studio-se by Talend.
the class NoSQLConnectionContextManager method revertPropertiesForContextMode.
/**
* DOC PLV Comment method "revertPropertiesForContextMode".
*
* @param connectionItem
* @param contextType
* @param attributes
*/
public void revertPropertiesForContextMode(ContextType contextType) {
EMap<String, String> connAttributes = connection.getAttributes();
if (connAttributes == null) {
return;
}
for (String attributeName : attributes) {
if (attributeName.equals(IMongoDBAttributes.REPLICA_SET)) {
String replicaSets = connAttributes.get(IMongoDBAttributes.REPLICA_SET);
try {
JSONArray jsa = new JSONArray(replicaSets);
for (int i = 0; i < jsa.length(); i++) {
JSONObject jso = jsa.getJSONObject(i);
String hostValue = jso.getString(IMongoConstants.REPLICA_HOST_KEY);
String portValue = jso.getString(IMongoConstants.REPLICA_PORT_KEY);
String originalHostValue = ContextParameterUtils.getOriginalValue(contextType, hostValue);
String originalPortValue = ContextParameterUtils.getOriginalValue(contextType, portValue);
jso.put(IMongoConstants.REPLICA_HOST_KEY, originalHostValue);
jso.put(IMongoConstants.REPLICA_PORT_KEY, originalPortValue);
}
connAttributes.put(IMongoDBAttributes.REPLICA_SET, jsa.toString());
} catch (JSONException e) {
ExceptionHandler.process(e);
}
} else {
String originalValue = ContextParameterUtils.getOriginalValue(contextType, connAttributes.get(attributeName));
connAttributes.put(attributeName, originalValue);
}
}
// set connection for context mode
connection.setContextMode(false);
connection.setContextId(ConnectionContextHelper.EMPTY);
}
use of org.talend.utils.json.JSONException in project tbd-studio-se by Talend.
the class HCatalogForm method initHadoopProperties.
// private void addHadoopPropertiesFields() {
// // table view
// Composite compositeTable = Form.startNewDimensionnedGridLayout(this, 1, this.getBorderWidth(), 150);
// GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
// gridData.horizontalSpan = 4;
// compositeTable.setLayoutData(gridData);
// CommandStackForComposite commandStack = new CommandStackForComposite(compositeTable);
// properties = new ArrayList<HashMap<String, Object>>();
// initHadoopProperties();
// HadoopPropertiesFieldModel model = new HadoopPropertiesFieldModel(properties, "Hadoop Properties");
// propertiesTableView = new HadoopPropertiesTableView(model, compositeTable);
// propertiesTableView.getExtendedTableViewer().setCommandStack(commandStack);
// final Composite fieldTableEditorComposite = propertiesTableView.getMainComposite();
// gridData = new GridData(GridData.FILL_HORIZONTAL);
// gridData.heightHint = 180;
// fieldTableEditorComposite.setLayoutData(gridData);
// fieldTableEditorComposite.setBackground(null);
// }
private void initHadoopProperties() {
String hadoopProperties = getConnection().getHadoopProperties();
try {
if (StringUtils.isNotEmpty(hadoopProperties)) {
JSONArray jsonArr = new JSONArray(hadoopProperties);
for (int i = 0; i < jsonArr.length(); i++) {
HashMap<String, Object> map = new HashMap();
JSONObject object = jsonArr.getJSONObject(i);
Iterator it = object.keys();
while (it.hasNext()) {
String key = (String) it.next();
map.put(key, object.get(key));
}
properties.add(map);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
use of org.talend.utils.json.JSONException in project tbd-studio-se by Talend.
the class DefaultConfigurationManagerTest method testGetValue_Whole.
@Test
public void testGetValue_Whole() throws JSONException {
JSONObject json = new JSONObject();
json.put("key1", "123");
String value = DefaultConfigurationManager.getValue(json, "");
assertNotNull(value);
JSONObject getJson = null;
try {
getJson = new JSONObject(value);
} catch (JSONException e) {
//
}
assertNotNull("Can't get the whole JSON", getJson);
assertTrue(getJson.has("key1"));
assertEquals("123", getJson.getString("key1"));
}
Aggregations