Java Code Examples for org.json.simple.JSONArray#addAll()

The following examples show how to use org.json.simple.JSONArray#addAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONUtil.java    From Indra with MIT License 6 votes vote down vote up
private static JSONObject toJSONObject(Map<String, Object> map) {
    JSONObject object = new JSONObject();

    for (String key : map.keySet()) {
        Object content = map.get(key);
        if (content instanceof Collection) {
            JSONArray array = new JSONArray();
            array.addAll((Collection<?>) content);
            object.put(key, array);
        } else if (content instanceof Map) {
            object.put(key, toJSONObject((Map<String, Object>) content));
        } else {
            object.put(key, content);
        }
    }

    return object;
}
 
Example 2
Source File: ReportUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
public static void loadDefaultTheme(JSONObject obj) {
    try {
        appSett.putAll(System.getProperties());
        Object Theme = appSett.get(RDS.TestSet.THEME);
        if (Theme == null || Theme.toString().isEmpty()) {
            Theme = getFirstTheme();
        }
        obj.put(RDS.TestSet.THEME, Theme.toString());
        if (appSett.get(RDS.TestSet.THEMES) != null) {
            String[] themes = appSett.get(RDS.TestSet.THEMES).toString().split(",");
            JSONArray jsthemes = new JSONArray();
            jsthemes.addAll(Arrays.asList(themes));
            obj.put(RDS.TestSet.THEMES, jsthemes);
        }
    } catch (Exception ex) {
        Logger.getLogger(ReportUtils.class.getName()).log(Level.WARNING, null, ex);
    }
}
 
Example 3
Source File: JDBCTestUtils.java    From jdbc-cb with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static JSONArray sortJsonArray(JSONArray array) {
   	if(array.size() == 0){
   		return array;
   	}
       ArrayList<JSONObject> jsons = new ArrayList<JSONObject>();
       for (int i = 0; i < array.size(); i++) {
           jsons.add((JSONObject)array.get(i));
       }
       for(Object field:((JSONObject)array.get(0)).keySet()){
       	final Object field_val = field;
        Collections.sort(jsons, new Comparator<JSONObject>() {
        	@Override
            public int compare(JSONObject lhs, JSONObject rhs) {
                String lid = (String) lhs.get(field_val);
                String rid = (String) rhs.get(field_val);
                // Here you could parse string id to integer and then compare.
                return lid.compareTo(rid);
            }
       
       });}
       JSONArray returnValue = new JSONArray();
       returnValue.addAll(jsons);
       return returnValue;
   }
 
Example 4
Source File: SqoopIDFUtils.java    From sqoop-on-spark with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static String toCSVList(Object[] list, Column column) {
  List<Object> elementList = new ArrayList<Object>();
  for (int n = 0; n < list.length; n++) {
    Column listType = ((AbstractComplexListType) column).getListType();
    // 2 level nesting supported
    if (isColumnListType(listType)) {
      Object[] listElements = (Object[]) list[n];
      JSONArray subArray = new JSONArray();
      for (int i = 0; i < listElements.length; i++) {
        subArray.add(listElements[i]);
      }
      elementList.add(subArray);
    } else {
      elementList.add(list[n]);
    }
  }
  JSONArray array = new JSONArray();
  array.addAll(elementList);
  return encloseWithQuotes(array.toJSONString());
}
 
Example 5
Source File: APIAuthenticationAdminClient.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Removes given usernames that is cached on the API Gateway
 *
 * @param username_list - The list of usernames to be removed from the gateway cache.
 */
public void invalidateCachedUsernames(String[] username_list) {

    JSONArray userArray = new JSONArray();
    userArray.addAll(Arrays.asList(username_list));
    Object[] objectData = new Object[]{APIConstants.GATEWAY_USERNAME_CACHE_NAME, userArray.toJSONString()};
    Event event = new Event(APIConstants.CACHE_INVALIDATION_STREAM_ID, System.currentTimeMillis(),
            null, null, objectData);
    APIUtil.publishEventToEventHub(null, event);
}
 
Example 6
Source File: RecipeMerger.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
private JSONArray getAllZones(JSONArray acts) {
    JSONArray allZones = new JSONArray();
    for (JSONObject act : (Iterable<JSONObject>) acts) {
        JSONArray zonesInAct = (JSONArray) act.get("zones");
        allZones.addAll(zonesInAct);
    }
    return allZones;
}
 
Example 7
Source File: APIAuthenticationAdminClient.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the active tokens that are cached on the API Gateway
 * @param activeTokens - The active access tokens to be removed from the gateway cache.
 */
public void invalidateCachedTokens(Set<String> activeTokens) {

    JSONArray tokenArray = new JSONArray();
    tokenArray.addAll(activeTokens);
    Object[] objectData = new Object[]{APIConstants.GATEWAY_KEY_CACHE_NAME, tokenArray.toJSONString()};
    Event event = new Event(APIConstants.CACHE_INVALIDATION_STREAM_ID, System.currentTimeMillis(),
            null, null, objectData);
    APIUtil.publishEventToEventHub(null, event);
}
 
Example 8
Source File: UltimateFancy.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public UltimateFancy appendAtFirst(JSONObject json) {
    JSONArray jarray = new JSONArray();
    jarray.add(json);
    jarray.addAll(getStoredElements());
    this.constructor = jarray;
    return this;
}
 
Example 9
Source File: UltimateFancy.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Root text to show on chat, but in first position.
 *
 * @param text
 * @return instance of same {@link UltimateFancy}.
 */
public UltimateFancy textAtStart(String text) {
    JSONArray jarray = new JSONArray();
    jarray.addAll(parseColors(text));
    jarray.addAll(getStoredElements());
    this.constructor = jarray;
    return this;
}
 
Example 10
Source File: UltimateFancy.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
public UltimateFancy appendAtFirst(JSONObject json) {
    JSONArray jarray = new JSONArray();
    jarray.add(json);
    jarray.addAll(getStoredElements());
    this.constructor = jarray;
    return this;
}
 
Example 11
Source File: UltimateFancy.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Root text to show on chat, but in first position.
 *
 * @param text
 * @return instance of same {@link UltimateFancy}.
 */
public UltimateFancy textAtStart(String text) {
    JSONArray jarray = new JSONArray();
    jarray.addAll(parseColors(text));
    jarray.addAll(getStoredElements());
    this.constructor = jarray;
    return this;
}
 
Example 12
Source File: TimeseriesField.java    From TomboloDigitalConnector with MIT License 5 votes vote down vote up
@Override
public JSONObject jsonValueForSubject(Subject subject, Boolean timeStamp) throws IncomputableFieldException {
    List<TimedValue> timedValues = TimedValueUtils.getBySubjectAndAttribute(subject, getAttribute());
    if (timedValues.isEmpty()) {
        throw new IncomputableFieldException(String.format("No TimedValue found for attribute %s", getAttribute().getLabel()));
    }
    JSONArray arr = new JSONArray();
    arr.addAll(timedValues.stream().map(timedValue -> {
        JSONObject pair = new JSONObject();
        pair.put("timestamp", timedValue.getId().getTimestamp().format(TimedValueId.DATE_TIME_FORMATTER));
        pair.put("value", timedValue.getValue());
        return pair;
        }).collect(Collectors.toList()));
    return withinMetadata(arr);
}
 
Example 13
Source File: SchemaSerialization.java    From sqoop-on-spark with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static JSONObject extractColumn(Column column) {
  JSONObject ret = new JSONObject();

  ret.put(NAME, column.getName());
  ret.put(NULLABLE, column.isNullable());
  ret.put(TYPE, column.getType().name());

  switch (column.getType()) {
  case MAP:
    JSONObject map = new JSONObject();
    ret.put(MAP, map);
    map.put(KEY, extractColumn(((Map) column).getKey()));
    map.put(VALUE, extractColumn(((Map) column).getValue()));
    break;
  case ENUM:
    JSONObject enumList = new JSONObject();
    ret.put(LIST, enumList);
    JSONArray optionsArray = new JSONArray();
    optionsArray.addAll(((Enum)column).getOptions());
    enumList.put(ENUM_OPTIONS, optionsArray);
    break;
  case SET:
    JSONObject set = new JSONObject();
    ret.put(LIST, set);
    set.put(LIST_TYPE, extractColumn(((AbstractComplexListType) column).getListType()));
    break;
  case ARRAY:
    JSONObject arrayList = new JSONObject();
    ret.put(LIST, arrayList);
    arrayList.put(SIZE, ((Array) column).getSize());
    arrayList.put(LIST_TYPE, extractColumn(((Array) column).getListType()));
    break;
  case BINARY:
  case TEXT:
    ret.put(CHAR_SIZE, ((AbstractString) column).getCharSize());
    break;
  case DATE_TIME:
    ret.put(FRACTION, ((DateTime) column).hasFraction());
    ret.put(TIMEZONE, ((DateTime) column).hasTimezone());
    break;
  case DECIMAL:
    ret.put(PRECISION, ((Decimal) column).getPrecision());
    ret.put(SCALE, ((Decimal) column).getScale());
    break;
  case FIXED_POINT:
    ret.put(BYTE_SIZE, ((FixedPoint) column).getByteSize());
    ret.put(SIGNED, ((FixedPoint) column).isSigned());
    break;
  case FLOATING_POINT:
    ret.put(BYTE_SIZE, ((FloatingPoint) column).getByteSize());
    break;
  case TIME:
    ret.put(FRACTION, ((Time) column).hasFraction());
    break;
  case UNKNOWN:
    ret.put(JDBC_TYPE, ((Unknown) column).getJdbcType());
    break;
  case DATE:
  case BIT:
    break;
  default:
    // TODO(jarcec): Throw an exception of unsupported type?
  }

  return ret;
}
 
Example 14
Source File: UserDataListTest.java    From io with Apache License 2.0 4 votes vote down vote up
/**
 * UserDataの一覧でDouble配列型プロパティにnullを含むデータを取得できること.
 */
@SuppressWarnings("unchecked")
@Test
public final void UserDataの一覧でDouble配列型プロパティにnullを含むデータを取得できること() {
    String propName = "arrayDoubleTypeProperty";
    String userDataId = "userdata001";
    // リクエスト実行
    try {
        // Edm.Double配列のプロパティを作成
        PropertyUtils.create(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName,
                EdmSimpleType.DOUBLE.getFullyQualifiedTypeName(),
                true, null, "List", false, null, HttpStatus.SC_CREATED);
        // リクエストボディを設定
        JSONObject body = new JSONObject();
        JSONArray arrayBody = new JSONArray();
        arrayBody.addAll(Arrays.asList(new Double[] {1.1, null, -1.2 }));
        body.put("__id", userDataId);
        body.put(propName, arrayBody);
        // ユーザデータ作成
        TResponse respons = createUserData(body, HttpStatus.SC_CREATED);

        Map<String, String> etagList = new HashMap<String, String>();
        etagList.put("userdata001", respons.getHeader(HttpHeaders.ETAG));

        // ユーザデータの一覧取得
        TResponse response = Http.request("box/odatacol/list.txt")
                .with("cell", cellName)
                .with("box", boxName)
                .with("collection", colName)
                .with("entityType", entityTypeName)
                .with("query", "")
                .with("accept", MediaType.APPLICATION_JSON)
                .with("token", DcCoreConfig.getMasterToken())
                .returns()
                .statusCode(HttpStatus.SC_OK)
                .debug();

        Map<String, String> uri = new HashMap<String, String>();
        uri.put(userDataId, UrlUtils.userData(cellName, boxName, colName, entityTypeName
                + "('" + userDataId + "')"));

        // プロパティ
        Map<String, Map<String, Object>> additional = new HashMap<String, Map<String, Object>>();
        Map<String, Object> additionalprop = new HashMap<String, Object>();
        additional.put(userDataId, additionalprop);
        additionalprop.put("__id", userDataId);
        additionalprop.put(propName, arrayBody);

        String nameSpace = getNameSpace(entityTypeName);
        ODataCommon
                .checkResponseBodyList(response.bodyAsJson(), uri, nameSpace, additional, "__id", null, etagList);

    } finally {
        // ユーザデータ削除
        deleteUserData(userDataId);
        // プロパティ削除
        PropertyUtils.delete(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName, -1);
    }
}
 
Example 15
Source File: UserDataListTest.java    From io with Apache License 2.0 4 votes vote down vote up
/**
 * UserDataの一覧でInt32配列型プロパティにnullを含むデータを取得できること.
 */
@SuppressWarnings("unchecked")
@Test
public final void UserDataの一覧でInt32配列型プロパティにnullを含むデータを取得できること() {
    String propName = "arrayIntTypeProperty";
    String userDataId = "userdata001";
    // リクエスト実行
    try {
        // Edm.Double配列のプロパティを作成
        PropertyUtils.create(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName,
                EdmSimpleType.INT32.getFullyQualifiedTypeName(),
                true, null, "List", false, null, HttpStatus.SC_CREATED);
        // リクエストボディを設定
        JSONObject body = new JSONObject();
        JSONArray arrayBody = new JSONArray();
        arrayBody.addAll(Arrays.asList(new Integer[] {1, null, -1 }));
        body.put("__id", userDataId);
        body.put(propName, arrayBody);
        // ユーザデータ作成
        TResponse respons = createUserData(body, HttpStatus.SC_CREATED);

        Map<String, String> etagList = new HashMap<String, String>();
        etagList.put("userdata001", respons.getHeader(HttpHeaders.ETAG));

        // ユーザデータの一覧取得
        TResponse response = Http.request("box/odatacol/list.txt")
                .with("cell", cellName)
                .with("box", boxName)
                .with("collection", colName)
                .with("entityType", entityTypeName)
                .with("query", "")
                .with("accept", MediaType.APPLICATION_JSON)
                .with("token", DcCoreConfig.getMasterToken())
                .returns()
                .statusCode(HttpStatus.SC_OK)
                .debug();

        Map<String, String> uri = new HashMap<String, String>();
        uri.put(userDataId, UrlUtils.userData(cellName, boxName, colName, entityTypeName
                + "('" + userDataId + "')"));

        // プロパティ
        Map<String, Map<String, Object>> additional = new HashMap<String, Map<String, Object>>();
        Map<String, Object> additionalprop = new HashMap<String, Object>();
        additional.put(userDataId, additionalprop);
        additionalprop.put("__id", userDataId);
        additionalprop.put(propName, arrayBody);

        String nameSpace = getNameSpace(entityTypeName);
        ODataCommon
                .checkResponseBodyList(response.bodyAsJson(), uri, nameSpace, additional, "__id", null, etagList);

    } finally {
        // ユーザデータ削除
        deleteUserData(userDataId);
        // プロパティ削除
        PropertyUtils.delete(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName, -1);
    }
}
 
Example 16
Source File: UserDataListTest.java    From io with Apache License 2.0 4 votes vote down vote up
/**
 * UserDataの一覧でBoolean配列型プロパティにnullを含むデータを取得できること.
 */
@SuppressWarnings("unchecked")
@Test
public final void UserDataの一覧でBoolean配列型プロパティにnullを含むデータを取得できること() {
    String propName = "arrayIntTypeProperty";
    String userDataId = "userdata001";
    // リクエスト実行
    try {
        // Edm.Double配列のプロパティを作成
        PropertyUtils.create(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName,
                EdmSimpleType.BOOLEAN.getFullyQualifiedTypeName(),
                true, null, "List", false, null, HttpStatus.SC_CREATED);
        // リクエストボディを設定
        JSONObject body = new JSONObject();
        JSONArray arrayBody = new JSONArray();
        arrayBody.addAll(Arrays.asList(new Boolean[] {true, null, false }));
        body.put("__id", userDataId);
        body.put(propName, arrayBody);
        // ユーザデータ作成
        TResponse respons = createUserData(body, HttpStatus.SC_CREATED);

        Map<String, String> etagList = new HashMap<String, String>();
        etagList.put("userdata001", respons.getHeader(HttpHeaders.ETAG));

        // ユーザデータの一覧取得
        TResponse response = Http.request("box/odatacol/list.txt")
                .with("cell", cellName)
                .with("box", boxName)
                .with("collection", colName)
                .with("entityType", entityTypeName)
                .with("query", "")
                .with("accept", MediaType.APPLICATION_JSON)
                .with("token", DcCoreConfig.getMasterToken())
                .returns()
                .statusCode(HttpStatus.SC_OK)
                .debug();

        Map<String, String> uri = new HashMap<String, String>();
        uri.put(userDataId, UrlUtils.userData(cellName, boxName, colName, entityTypeName
                + "('" + userDataId + "')"));

        // プロパティ
        Map<String, Map<String, Object>> additional = new HashMap<String, Map<String, Object>>();
        Map<String, Object> additionalprop = new HashMap<String, Object>();
        additional.put(userDataId, additionalprop);
        additionalprop.put("__id", userDataId);
        additionalprop.put(propName, arrayBody);

        String nameSpace = getNameSpace(entityTypeName);
        ODataCommon
                .checkResponseBodyList(response.bodyAsJson(), uri, nameSpace, additional, "__id", null, etagList);

    } finally {
        // ユーザデータ削除
        deleteUserData(userDataId);
        // プロパティ削除
        PropertyUtils.delete(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName, -1);
    }
}
 
Example 17
Source File: UserDataListTest.java    From io with Apache License 2.0 4 votes vote down vote up
/**
 * UserDataの一覧で文字列配列型プロパティにnullを含むデータを取得できること.
 */
@SuppressWarnings("unchecked")
@Test
public final void UserDataの一覧で文字列配列型プロパティにnullを含むデータを取得できること() {
    String propName = "arrayIntTypeProperty";
    String userDataId = "userdata001";
    // リクエスト実行
    try {
        // Edm.Double配列のプロパティを作成
        PropertyUtils.create(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName,
                EdmSimpleType.STRING.getFullyQualifiedTypeName(),
                true, null, "List", false, null, HttpStatus.SC_CREATED);
        // リクエストボディを設定
        JSONObject body = new JSONObject();
        JSONArray arrayBody = new JSONArray();
        arrayBody.addAll(Arrays.asList(new String[] {"abc", null, "xyz", "null" }));
        body.put("__id", userDataId);
        body.put(propName, arrayBody);
        // ユーザデータ作成
        TResponse respons = createUserData(body, HttpStatus.SC_CREATED);

        Map<String, String> etagList = new HashMap<String, String>();
        etagList.put("userdata001", respons.getHeader(HttpHeaders.ETAG));

        // ユーザデータの一覧取得
        TResponse response = Http.request("box/odatacol/list.txt")
                .with("cell", cellName)
                .with("box", boxName)
                .with("collection", colName)
                .with("entityType", entityTypeName)
                .with("query", "")
                .with("accept", MediaType.APPLICATION_JSON)
                .with("token", DcCoreConfig.getMasterToken())
                .returns()
                .statusCode(HttpStatus.SC_OK)
                .debug();

        Map<String, String> uri = new HashMap<String, String>();
        uri.put(userDataId, UrlUtils.userData(cellName, boxName, colName, entityTypeName
                + "('" + userDataId + "')"));

        // プロパティ
        Map<String, Map<String, Object>> additional = new HashMap<String, Map<String, Object>>();
        Map<String, Object> additionalprop = new HashMap<String, Object>();
        additional.put(userDataId, additionalprop);
        additionalprop.put("__id", userDataId);
        additionalprop.put(propName, arrayBody);

        String nameSpace = getNameSpace(entityTypeName);
        ODataCommon
                .checkResponseBodyList(response.bodyAsJson(), uri, nameSpace, additional, "__id", null, etagList);

    } finally {
        // ユーザデータ削除
        deleteUserData(userDataId);
        // プロパティ削除
        PropertyUtils.delete(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName, -1);
    }
}
 
Example 18
Source File: SocketServer.java    From Much-Assembly-Required with GNU General Public License v3.0 3 votes vote down vote up
private JSONArray intListToJSON(List<Integer> ints) {

        JSONArray jsonInts = new JSONArray();
        jsonInts.addAll(ints);

        return jsonInts;
    }