(Context context, String user, String password, String command, JSONObject jrequest)
| 589 | // Lower level |
| 590 | |
| 591 | public static JSONObject call(Context context, String user, String password, String command, JSONObject jrequest) |
| 592 | throws GeneralSecurityException, JSONException, IOException, InvalidCipherTextException { |
| 593 | EntityLog.log(context, EntityLog.Type.Cloud, "Cloud command=" + command); |
| 594 | |
| 595 | jrequest.put("command", command); |
| 596 | List<JSONObject> responses = new ArrayList<>(); |
| 597 | for (JSONArray batch : partition(jrequest.getJSONArray("items"))) { |
| 598 | jrequest.put("items", batch); |
| 599 | responses.add(_call(context, user, password, jrequest)); |
| 600 | } |
| 601 | if (responses.size() == 1) |
| 602 | return responses.get(0); |
| 603 | else { |
| 604 | JSONArray jall = new JSONArray(); |
| 605 | for (JSONObject response : responses) |
| 606 | if (response.has("items")) { |
| 607 | JSONArray jitems = response.getJSONArray("items"); |
| 608 | for (int i = 0; i < jitems.length(); i++) |
| 609 | jall.put(jitems.getJSONObject(i)); |
| 610 | } |
| 611 | JSONObject jresponse = responses.get(0); |
| 612 | jresponse.put("items", jall); |
| 613 | return jresponse; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | private static byte[] getSalt(String user) throws NoSuchAlgorithmException { |
| 618 | return MessageDigest.getInstance("SHA256").digest(user.getBytes()); |
no test coverage detected