Commit 666338c15b0f72403a47b3a4eaa0e43bba2e3919
1 parent
72eef90c
Exists in
master
update offset and count
Showing
1 changed file
with
49 additions
and
6 deletions
Show diff stats
src/main/java/sourcecode/MockUp/MockUp.java
| @@ -8,6 +8,7 @@ import java.nio.charset.Charset; | @@ -8,6 +8,7 @@ import java.nio.charset.Charset; | ||
| 8 | import java.nio.charset.StandardCharsets; | 8 | import java.nio.charset.StandardCharsets; |
| 9 | import java.sql.Date; | 9 | import java.sql.Date; |
| 10 | import java.util.ArrayList; | 10 | import java.util.ArrayList; |
| 11 | +import java.util.Arrays; | ||
| 11 | import java.util.HashMap; | 12 | import java.util.HashMap; |
| 12 | import java.util.Iterator; | 13 | import java.util.Iterator; |
| 13 | 14 | ||
| @@ -40,8 +41,8 @@ public class MockUp | @@ -40,8 +41,8 @@ public class MockUp | ||
| 40 | private final static String PUT = "PUT"; | 41 | private final static String PUT = "PUT"; |
| 41 | private final static String DELETE = "DELETE"; | 42 | private final static String DELETE = "DELETE"; |
| 42 | private static int port = 6300; | 43 | private static int port = 6300; |
| 43 | - private static String DBNAME = "coop_mockup"; | ||
| 44 | - private static String DBHOST = "10.1.2.144:27017"; | 44 | + private static String DBNAME = "sdf"; |
| 45 | + private static String DBHOST = "10.1.2.146:27017"; | ||
| 45 | private static String DBUSERNAME = ""; | 46 | private static String DBUSERNAME = ""; |
| 46 | private static String DBPASSWORD = ""; | 47 | private static String DBPASSWORD = ""; |
| 47 | 48 | ||
| @@ -103,6 +104,18 @@ public class MockUp | @@ -103,6 +104,18 @@ public class MockUp | ||
| 103 | 104 | ||
| 104 | } | 105 | } |
| 105 | } | 106 | } |
| 107 | + | ||
| 108 | + int offset = 0; | ||
| 109 | + | ||
| 110 | + if(!getKey("offset", url).equals("")) | ||
| 111 | + { | ||
| 112 | + try{ | ||
| 113 | + offset = Integer.parseInt(getKey("offset", url)); | ||
| 114 | + }catch(Exception e) | ||
| 115 | + { | ||
| 116 | + | ||
| 117 | + } | ||
| 118 | + } | ||
| 106 | 119 | ||
| 107 | 120 | ||
| 108 | String[] fields = new String[0]; | 121 | String[] fields = new String[0]; |
| @@ -253,7 +266,10 @@ public class MockUp | @@ -253,7 +266,10 @@ public class MockUp | ||
| 253 | } | 266 | } |
| 254 | 267 | ||
| 255 | //limit | 268 | //limit |
| 256 | - responsJSON = limitData(responsJSON,limit); | 269 | + if(method.equals(GET) && responsJSON.has("resultCode") && responsJSON.get("resultCode").equals("20000")) { |
| 270 | + responsJSON = offsetData(responsJSON,offset); | ||
| 271 | + responsJSON = limitData(responsJSON,limit); | ||
| 272 | + } | ||
| 257 | 273 | ||
| 258 | //field | 274 | //field |
| 259 | responsJSON = FieldsData(responsJSON,fields); | 275 | responsJSON = FieldsData(responsJSON,fields); |
| @@ -550,8 +566,10 @@ public class MockUp | @@ -550,8 +566,10 @@ public class MockUp | ||
| 550 | //resultData not array | 566 | //resultData not array |
| 551 | size = 1; | 567 | size = 1; |
| 552 | } | 568 | } |
| 553 | - responsJSON.remove("rowCount"); | ||
| 554 | - responsJSON.put("rowCount", size); | 569 | +// responsJSON.remove("rowCount"); |
| 570 | + if(!responsJSON.has("rowCount")) { | ||
| 571 | + responsJSON.put("rowCount", size); | ||
| 572 | + } | ||
| 555 | } | 573 | } |
| 556 | 574 | ||
| 557 | return responsJSON; | 575 | return responsJSON; |
| @@ -690,5 +708,30 @@ public class MockUp | @@ -690,5 +708,30 @@ public class MockUp | ||
| 690 | return value; | 708 | return value; |
| 691 | } | 709 | } |
| 692 | 710 | ||
| 693 | - | 711 | + private static JSONObject offsetData(JSONObject responsJSON, int offset) { |
| 712 | + | ||
| 713 | + try { | ||
| 714 | + System.out.println("Offset : " + offset); | ||
| 715 | + JSONArray JSONArrayData = responsJSON.getJSONArray("resultData"); | ||
| 716 | + | ||
| 717 | + int n = JSONArrayData.length(); | ||
| 718 | + | ||
| 719 | + ArrayList<Object> offsetResultData = new ArrayList<Object>(); | ||
| 720 | + | ||
| 721 | + for (int i = 0; i < n; i++) | ||
| 722 | + { | ||
| 723 | + if (i >= offset) | ||
| 724 | + offsetResultData.add(JSONArrayData.get(i)); | ||
| 725 | + } | ||
| 726 | + | ||
| 727 | + responsJSON.remove("resultData"); | ||
| 728 | + responsJSON.put("resultData",offsetResultData); | ||
| 729 | + | ||
| 730 | + } catch (Exception e) { | ||
| 731 | + // TODO: handle exception | ||
| 732 | + } | ||
| 733 | + | ||
| 734 | + | ||
| 735 | + return responsJSON; | ||
| 736 | + } | ||
| 694 | } | 737 | } |