Search in sources :

Example 11 with JSONArray

use of org.json.simple.JSONArray in project hadoop by apache.

the class FSOperations method aclStatusToJSON.

/** Converts an <code>AclStatus</code> object into a JSON object.
   *
   * @param aclStatus AclStatus object
   *
   * @return The JSON representation of the ACLs for the file
   */
@SuppressWarnings({ "unchecked" })
private static Map<String, Object> aclStatusToJSON(AclStatus aclStatus) {
    Map<String, Object> json = new LinkedHashMap<String, Object>();
    Map<String, Object> inner = new LinkedHashMap<String, Object>();
    JSONArray entriesArray = new JSONArray();
    inner.put(HttpFSFileSystem.OWNER_JSON, aclStatus.getOwner());
    inner.put(HttpFSFileSystem.GROUP_JSON, aclStatus.getGroup());
    inner.put(HttpFSFileSystem.ACL_STICKY_BIT_JSON, aclStatus.isStickyBit());
    for (AclEntry e : aclStatus.getEntries()) {
        entriesArray.add(e.toString());
    }
    inner.put(HttpFSFileSystem.ACL_ENTRIES_JSON, entriesArray);
    json.put(HttpFSFileSystem.ACL_STATUS_JSON, inner);
    return json;
}
Also used : JSONArray(org.json.simple.JSONArray) AclEntry(org.apache.hadoop.fs.permission.AclEntry) JSONObject(org.json.simple.JSONObject) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with JSONArray

use of org.json.simple.JSONArray in project hadoop by apache.

the class FSOperations method toJson.

/**
   * @param fileStatuses list of FileStatus objects
   * @return JSON map suitable for wire transport
   */
@SuppressWarnings({ "unchecked" })
private static Map<String, Object> toJson(FileStatus[] fileStatuses) {
    Map<String, Object> json = new LinkedHashMap<>();
    Map<String, Object> inner = new LinkedHashMap<>();
    JSONArray statuses = new JSONArray();
    for (FileStatus f : fileStatuses) {
        statuses.add(toJsonInner(f, false));
    }
    inner.put(HttpFSFileSystem.FILE_STATUS_JSON, statuses);
    json.put(HttpFSFileSystem.FILE_STATUSES_JSON, inner);
    return json;
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with JSONArray

use of org.json.simple.JSONArray in project openhab1-addons by openhab.

the class DigitalSTROMJSONImpl method getMeterList.

@Override
public List<String> getMeterList(String token) {
    List<String> meterList = new LinkedList<String>();
    String response = transport.execute(JSONRequestConstants.JSON_PROPERTY_QUERY + JSONRequestConstants.PARAMETER_TOKEN + token + JSONRequestConstants.INFIX_PARAMETER_QUERY + JSONRequestConstants.QUERY_GET_METERLIST);
    JSONObject responseObj = handler.toJSONObject(response);
    if (handler.checkResponse(responseObj)) {
        JSONObject obj = handler.getResultJSONObject(responseObj);
        if (obj != null && obj.get(JSONApiResponseKeysEnum.DS_METER_QUERY.getKey()) instanceof JSONArray) {
            JSONArray array = (JSONArray) obj.get(JSONApiResponseKeysEnum.DS_METER_QUERY.getKey());
            for (int i = 0; i < array.size(); i++) {
                if (array.get(i) instanceof JSONObject) {
                    JSONObject elem = (JSONObject) array.get(i);
                    @SuppressWarnings("unchecked") Collection<String> k = elem.values();
                    for (String s : k) {
                        meterList.add(s);
                    }
                }
            }
        }
    }
    return meterList;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) LinkedList(java.util.LinkedList)

Example 14 with JSONArray

use of org.json.simple.JSONArray in project openhab1-addons by openhab.

the class DigitalSTROMJSONImpl method getResolutions.

@Override
public List<Integer> getResolutions(String token) {
    String response = null;
    response = transport.execute(JSONRequestConstants.JSON_METERING_GET_RESOLUTIONS + JSONRequestConstants.PARAMETER_TOKEN + token);
    JSONObject responseObj = handler.toJSONObject(response);
    if (handler.checkResponse(responseObj)) {
        JSONObject resObj = handler.getResultJSONObject(responseObj);
        if (resObj != null && resObj.get(JSONApiResponseKeysEnum.METERING_GET_RESOLUTIONS.getKey()) instanceof JSONArray) {
            JSONArray array = (JSONArray) resObj.get(JSONApiResponseKeysEnum.METERING_GET_RESOLUTIONS.getKey());
            List<Integer> resolutionList = new LinkedList<Integer>();
            for (int i = 0; i < array.size(); i++) {
                if (array.get(i) instanceof org.json.simple.JSONObject) {
                    JSONObject jObject = (JSONObject) array.get(i);
                    if (jObject.get(JSONApiResponseKeysEnum.METERING_GET_RESOLUTION.getKey()) != null) {
                        int val = -1;
                        try {
                            val = Integer.parseInt(jObject.get(JSONApiResponseKeysEnum.METERING_GET_RESOLUTION.getKey()).toString());
                        } catch (java.lang.NumberFormatException e) {
                            logger.error("NumberFormatException in getResolutions: " + jObject.get(JSONApiResponseKeysEnum.METERING_GET_RESOLUTION.getKey()).toString());
                        }
                        if (val != -1) {
                            resolutionList.add(val);
                        }
                    }
                }
            }
            return resolutionList;
        }
    }
    return null;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) LinkedList(java.util.LinkedList)

Example 15 with JSONArray

use of org.json.simple.JSONArray in project openhab1-addons by openhab.

the class DigitalSTROMJSONImpl method getLatest.

@Override
public List<CachedMeteringValue> getLatest(String token, MeteringTypeEnum type, String from, MeteringUnitsEnum unit) {
    if (type != null && from != null) {
        String response = null;
        if (unit != null && type != MeteringTypeEnum.consumption) {
            response = transport.execute(JSONRequestConstants.JSON_METERING_GET_LATEST + JSONRequestConstants.PARAMETER_TOKEN + token + JSONRequestConstants.INFIX_PARAMETER_TYPE + type.name() + JSONRequestConstants.INFIX_PARAMETER_FROM + from + JSONRequestConstants.INFIX_PARAMETER_UNIT + unit.name());
        } else {
            response = transport.execute(JSONRequestConstants.JSON_METERING_GET_LATEST + JSONRequestConstants.PARAMETER_TOKEN + token + JSONRequestConstants.INFIX_PARAMETER_TYPE + type.name() + JSONRequestConstants.INFIX_PARAMETER_FROM + from);
        }
        JSONObject responseObj = handler.toJSONObject(response);
        if (handler.checkResponse(responseObj)) {
            JSONObject latestObj = handler.getResultJSONObject(responseObj);
            if (latestObj != null && latestObj.get(JSONApiResponseKeysEnum.METERING_GET_LATEST.getKey()) instanceof JSONArray) {
                JSONArray array = (JSONArray) latestObj.get(JSONApiResponseKeysEnum.METERING_GET_LATEST.getKey());
                List<CachedMeteringValue> list = new LinkedList<CachedMeteringValue>();
                for (int i = 0; i < array.size(); i++) {
                    if (array.get(i) instanceof JSONObject) {
                        list.add(new JSONCachedMeteringValueImpl((JSONObject) array.get(i)));
                    }
                }
                return list;
            }
        }
    }
    return null;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONCachedMeteringValueImpl(org.openhab.binding.digitalstrom.internal.client.entity.impl.JSONCachedMeteringValueImpl) JSONArray(org.json.simple.JSONArray) CachedMeteringValue(org.openhab.binding.digitalstrom.internal.client.entity.CachedMeteringValue) LinkedList(java.util.LinkedList)

Aggregations

JSONArray (org.json.simple.JSONArray)267 JSONObject (org.json.simple.JSONObject)238 JSONParser (org.json.simple.parser.JSONParser)73 Test (org.junit.Test)40 ParseException (org.json.simple.parser.ParseException)23 ArrayList (java.util.ArrayList)21 HttpClient (org.apache.commons.httpclient.HttpClient)21 IOException (java.io.IOException)17 HashMap (java.util.HashMap)17 GetMethod (org.apache.commons.httpclient.methods.GetMethod)17 Transaction (org.xel.Transaction)12 File (java.io.File)11 List (java.util.List)10 HttpResponse (org.apache.http.HttpResponse)10 BlockchainTest (org.xel.BlockchainTest)10 APICall (org.xel.http.APICall)10 Block (org.xel.Block)9 MapLayer (au.org.emii.portal.menu.MapLayer)8 Map (java.util.Map)8 FileReader (java.io.FileReader)6