Skip to content

Commit a96efc8

Browse files
authored
Merge pull request #176 from contentstack/feat/DX-2214-timeline-preview-impl
Feat/dx 2214 timeline preview impl
2 parents ddcd1e5 + e3a2b15 commit a96efc8

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class Config {
3131
protected Proxy proxy = null;
3232
protected String[] earlyAccess = null;
3333
protected ConnectionPool connectionPool = new ConnectionPool();
34+
public String releaseId;
35+
public String previewTimestamp;
36+
3437

3538
protected List<ContentstackPlugin> plugins = null;
3639

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

+11
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ public Stack livePreviewQuery(Map<String, String> query) throws IOException {
142142
config.livePreviewEntryUid = query.get(ENTRY_UID);
143143
config.livePreviewContentType = query.get(CONTENT_TYPE_UID);
144144

145+
if(query.get("release_id") != null){
146+
config.releaseId = query.get("release_id");
147+
}else{
148+
config.releaseId = null;
149+
}
150+
if(query.get("preview_timestamp") != null){
151+
config.previewTimestamp = query.get("preview_timestamp");
152+
}else{
153+
config.previewTimestamp = null;
154+
}
155+
145156
String livePreviewUrl = this.livePreviewEndpoint.concat(config.livePreviewContentType).concat("/entries/" + config.livePreviewEntryUid);
146157
if (livePreviewUrl.contains("/null/")) {
147158
throw new IllegalStateException("Malformed Query Url");

src/test/java/com/contentstack/sdk/TestLivePreview.java

+42
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.io.IOException;
1212
import java.util.HashMap;
13+
import java.util.Map;
1314
import java.util.logging.Level;
1415
import java.util.logging.Logger;
1516

@@ -223,4 +224,45 @@ void testLivePreviewDisabled() throws IllegalAccessException, IOException {
223224
"Expected exception message does not match");
224225
}
225226

227+
@Test
228+
void testTimelinePreview() throws IllegalAccessException, IOException {
229+
Config config = new Config()
230+
.enableLivePreview(true)
231+
.setLivePreviewHost("rest-preview.contentstack.com")
232+
.setPreviewToken("preview_token");
233+
234+
Stack stack = Contentstack.stack("stackApiKey", "deliveryToken", "env1", config);
235+
236+
HashMap<String, String> hashMap = new HashMap<>();
237+
hashMap.put("live_preview", "hash167673");
238+
hashMap.put("content_type_uid", "page");
239+
hashMap.put("entry_uid", "entryUid");
240+
hashMap.put("release_id", "12345");
241+
hashMap.put("preview_timestamp", "2025-09-25 17:45:30.005");
242+
243+
244+
stack.livePreviewQuery(hashMap);
245+
Entry entry = stack.contentType("page").entry("entry_uid");
246+
entry.fetch(null);
247+
Assertions.assertNotNull(entry);
248+
}
249+
250+
@Test
251+
void testLivePreviewQueryWithoutReleaseId() throws Exception {
252+
Config config = new Config().enableLivePreview(true)
253+
.setLivePreviewHost("rest-preview.contentstack.com")
254+
.setPreviewToken("previewToken");
255+
Stack stack = Contentstack.stack("api_key", "access_token", "env", config);
256+
257+
Map<String, String> queryParams = new HashMap<>();
258+
queryParams.put("content_type_uid", "blog");
259+
queryParams.put("entry_uid", "entry_123");
260+
queryParams.put("preview_timestamp", "1710800000");
261+
262+
stack.livePreviewQuery(queryParams);
263+
264+
Assertions.assertNull(config.releaseId);
265+
Assertions.assertEquals("1710800000", config.previewTimestamp);
266+
}
267+
226268
}

0 commit comments

Comments
 (0)