Search in sources :

Example 16 with JSONArray

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

the class NoSQLRepositoryContextHandlerTest method validateResult.

private void validateResult() throws Exception {
    String dbName = noSqlConnection.getAttributes().get(INoSQLCommonAttributes.DATABASE);
    assertEquals("context.Mongo_Database", dbName);
    String replicaSet = noSqlConnection.getAttributes().get(IMongoDBAttributes.REPLICA_SET);
    assertNotNull(replicaSet);
    JSONArray jsa = new JSONArray(replicaSet);
    assertTrue(jsa.length() > 0);
    JSONObject jso = jsa.getJSONObject(0);
    String contextHostName = jso.getString(IMongoConstants.REPLICA_HOST_KEY);
    String contextPortName = jso.getString(IMongoConstants.REPLICA_PORT_KEY);
    assertEquals("context.Mongo_ReplicaHost_1", contextHostName);
    assertEquals("context.Mongo_ReplicaPort_1", contextPortName);
}
Also used : JSONObject(org.talend.utils.json.JSONObject) JSONArray(org.talend.utils.json.JSONArray)

Example 17 with JSONArray

use of org.talend.utils.json.JSONArray 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 18 with JSONArray

use of org.talend.utils.json.JSONArray 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 19 with JSONArray

use of org.talend.utils.json.JSONArray 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 20 with JSONArray

use of org.talend.utils.json.JSONArray 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)

Aggregations

JSONArray (org.talend.utils.json.JSONArray)20 JSONObject (org.talend.utils.json.JSONObject)20 JSONException (org.talend.utils.json.JSONException)14 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 NoSQLConnection (org.talend.repository.model.nosql.NoSQLConnection)4 Iterator (java.util.Iterator)3 List (java.util.List)3 Map (java.util.Map)3 EHadoopParamName (org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName)3 IConnParamName (org.talend.metadata.managment.ui.model.IConnParamName)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ASN1Object (org.bouncycastle.asn1.ASN1Object)1 EMap (org.eclipse.emf.common.util.EMap)1 Point (org.eclipse.swt.graphics.Point)1 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 JavaType (org.talend.core.model.metadata.types.JavaType)1 IContextParameter (org.talend.core.model.process.IContextParameter)1