Skip to content

Commit 334c1fd

Browse files
Live Preview
1 parent c2bb618 commit 334c1fd

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

src/main/java/com/contentstack/sdk/CSHttpConnection.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,22 @@ private void getService(String requestUrl) throws IOException {
203203

204204

205205
void handleJSONArray() {
206-
JSONArray entries = new JSONArray();
207206
if (responseJSON.has("entries") && !responseJSON.optJSONArray("entries").isEmpty()) {
208-
entries = responseJSON.optJSONArray("entries");
207+
JSONArray finalEntries = responseJSON.optJSONArray("entries");
208+
IntStream.range(0, finalEntries.length()).forEach(idx -> {
209+
JSONObject objJSON = (JSONObject) finalEntries.get(idx);
210+
handleJSONObject(finalEntries, objJSON, idx);
211+
});
209212
}
210-
JSONArray finalEntries = entries;
211-
IntStream.range(0, entries.length()).forEach(idx -> {
212-
JSONObject objJSON = (JSONObject) finalEntries.get(idx);
213-
handleJSONObject(finalEntries, objJSON, idx);
214-
});
213+
if (responseJSON.has("entry") && !responseJSON.optJSONObject("entry").isEmpty()) {
214+
JSONObject entry = responseJSON.optJSONObject("entry");
215+
if (!entry.isEmpty()) {
216+
if (entry.has("uid") && entry.opt("uid").equals(this.config.livePreviewEntry.opt("uid"))) {
217+
responseJSON = new JSONObject().put("entry", this.config.livePreviewEntry);
218+
}
219+
}
220+
}
221+
215222
}
216223

217224
void handleJSONObject(JSONArray arrayEntry, JSONObject jsonObj, int idx) {
@@ -223,23 +230,6 @@ void handleJSONObject(JSONArray arrayEntry, JSONObject jsonObj, int idx) {
223230
responseJSON = new JSONObject().put("entries", arrayEntry);
224231
}
225232

226-
private void deepMergeElse(JSONArray arrayEntry, JSONObject jsonObj, int idx) {
227-
228-
do {
229-
String k = jsonObj.keySet().iterator().next();
230-
if (jsonObj.opt(k) instanceof JSONArray) {
231-
JSONArray subArray = (JSONArray) jsonObj.opt(k);
232-
IntStream.range(0, subArray.length()).forEach(pos -> {
233-
JSONObject objJSON = (JSONObject) subArray.get(pos);
234-
handleJSONObject(subArray, objJSON, pos);
235-
});
236-
}
237-
if (jsonObj.opt(k) instanceof JSONObject) {
238-
handleJSONObject(arrayEntry, ((JSONObject) jsonObj.opt(k)), idx);
239-
}
240-
} while (jsonObj.keySet().iterator().hasNext());
241-
}
242-
243233

244234
void setError(String errResp) {
245235
logger.info(errResp);

src/main/java/com/contentstack/sdk/Utils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,7 @@ public <T> T merge(T local, T remote) throws IllegalAccessException, Instantiati
6161
}
6262
return (T) merged;
6363
}
64+
65+
66+
6467
}

0 commit comments

Comments
 (0)