Search in sources :

Example 21 with JSONObject

use of org.talend.utils.json.JSONObject 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();
    }
}
Also used : JSONObject(org.talend.utils.json.JSONObject) HashMap(java.util.HashMap) JSONArray(org.talend.utils.json.JSONArray) Iterator(java.util.Iterator) JSONException(org.talend.utils.json.JSONException) JSONObject(org.talend.utils.json.JSONObject)

Example 22 with JSONObject

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

the class HDFSForm method initHadoopProperties.

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();
    }
}
Also used : JSONObject(org.talend.utils.json.JSONObject) HashMap(java.util.HashMap) JSONArray(org.talend.utils.json.JSONArray) Iterator(java.util.Iterator) JSONException(org.talend.utils.json.JSONException) JSONObject(org.talend.utils.json.JSONObject)

Example 23 with JSONObject

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

the class MongoDBConnectionUtil method getReplicaSetList.

public static List<HashMap<String, Object>> getReplicaSetList(String replicaSetJsonStr, boolean includeQuotes) throws JSONException {
    List<HashMap<String, Object>> replicaSet = new ArrayList<HashMap<String, Object>>();
    if (StringUtils.isNotEmpty(replicaSetJsonStr)) {
        JSONArray jsonArr = new JSONArray(replicaSetJsonStr);
        for (int i = 0; i < jsonArr.length(); i++) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            JSONObject object = jsonArr.getJSONObject(i);
            Iterator<String> it = object.keys();
            while (it.hasNext()) {
                String key = StringUtils.trimToNull(it.next());
                String value = StringUtils.trimToNull(String.valueOf(object.get(key)));
                if (includeQuotes) {
                    value = TalendQuoteUtils.addQuotesIfNotExist(value);
                } else {
                    value = TalendQuoteUtils.removeQuotesIfExist(value);
                }
                if (IMongoConstants.REPLICA_PORT_KEY.equals(key)) {
                    value = TalendQuoteUtils.removeQuotesIfExist(value);
                }
                map.put(key, value);
            }
            replicaSet.add(map);
        }
    }
    return replicaSet;
}
Also used : JSONObject(org.talend.utils.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.talend.utils.json.JSONArray) JSONObject(org.talend.utils.json.JSONObject) ASN1Object(org.bouncycastle.asn1.ASN1Object)

Example 24 with JSONObject

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

the class MongoDBReplicaFieldModel method getBeanListString.

public String getBeanListString() throws JSONException {
    JSONArray jsonArr = new JSONArray();
    for (HashMap<String, Object> map : getBeansList()) {
        JSONObject object = new JSONObject();
        Iterator it = map.keySet().iterator();
        while (it.hasNext()) {
            String key = (String) it.next();
            object.put(key, map.get(key));
        }
        jsonArr.put(object);
    }
    return jsonArr.toString();
}
Also used : JSONObject(org.talend.utils.json.JSONObject) JSONArray(org.talend.utils.json.JSONArray) Iterator(java.util.Iterator) JSONObject(org.talend.utils.json.JSONObject)

Example 25 with JSONObject

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

the class DefaultConfigurationManagerTest method testGetValue_Null.

@Test
public void testGetValue_Null() {
    assertNull(DefaultConfigurationManager.getValue(null));
    assertNull(DefaultConfigurationManager.getValue(null, new String[0]));
    JSONObject json = new JSONObject();
    assertNull(DefaultConfigurationManager.getValue(json, new String[0]));
}
Also used : JSONObject(org.talend.utils.json.JSONObject) Test(org.junit.Test)

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