Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dx 2214 timeline preview impl #176

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/contentstack/sdk/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class Config {
protected Proxy proxy = null;
protected String[] earlyAccess = null;
protected ConnectionPool connectionPool = new ConnectionPool();
public String releaseId;
public String previewTimestamp;


protected List<ContentstackPlugin> plugins = null;

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/contentstack/sdk/Stack.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ public Stack livePreviewQuery(Map<String, String> query) throws IOException {
config.livePreviewEntryUid = query.get(ENTRY_UID);
config.livePreviewContentType = query.get(CONTENT_TYPE_UID);

if(query.get("release_id") != null){
config.releaseId = query.get("release_id");
}else{
config.releaseId = null;
}
if(query.get("preview_timestamp") != null){
config.previewTimestamp = query.get("preview_timestamp");
}else{
config.previewTimestamp = null;
}

String livePreviewUrl = this.livePreviewEndpoint.concat(config.livePreviewContentType).concat("/entries/" + config.livePreviewEntryUid);
if (livePreviewUrl.contains("/null/")) {
throw new IllegalStateException("Malformed Query Url");
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/com/contentstack/sdk/TestLivePreview.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

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

@Test
void testTimelinePreview() throws IllegalAccessException, IOException {
Config config = new Config()
.enableLivePreview(true)
.setLivePreviewHost("rest-preview.contentstack.com")
.setPreviewToken("preview_token");

Stack stack = Contentstack.stack("stackApiKey", "deliveryToken", "env1", config);

HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("live_preview", "hash167673");
hashMap.put("content_type_uid", "page");
hashMap.put("entry_uid", "entryUid");
hashMap.put("release_id", "12345");
hashMap.put("preview_timestamp", "2025-09-25 17:45:30.005");


stack.livePreviewQuery(hashMap);
Entry entry = stack.contentType("page").entry("entry_uid");
entry.fetch(null);
Assertions.assertNotNull(entry);
}

@Test
void testLivePreviewQueryWithoutReleaseId() throws Exception {
Config config = new Config().enableLivePreview(true)
.setLivePreviewHost("rest-preview.contentstack.com")
.setPreviewToken("previewToken");
Stack stack = Contentstack.stack("api_key", "access_token", "env", config);

Map<String, String> queryParams = new HashMap<>();
queryParams.put("content_type_uid", "blog");
queryParams.put("entry_uid", "entry_123");
queryParams.put("preview_timestamp", "1710800000");

stack.livePreviewQuery(queryParams);

Assertions.assertNull(config.releaseId);
Assertions.assertEquals("1710800000", config.previewTimestamp);
}

}
Loading