Skip to content

Commit 5d23c6e

Browse files
updated dependencies
1 parent b8693b1 commit 5d23c6e

File tree

10 files changed

+179
-129
lines changed

10 files changed

+179
-129
lines changed

pom.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34

45
<modelVersion>4.0.0</modelVersion>
56
<groupId>com.contentstack.sdk</groupId>
67
<artifactId>java</artifactId>
7-
<version>1.10.0-SNAPSHOT</version>
8+
<version>1.10.2-SNAPSHOT</version>
89
<packaging>jar</packaging>
910
<name>contentstack-java</name>
1011
<description>Java SDK for Contentstack Content Delivery API</description>
@@ -20,28 +21,28 @@
2021
<surefire-report-plugin.version>2.22.0</surefire-report-plugin.version>
2122
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
2223
<maven-javadoc-plugin.version>3.3.2</maven-javadoc-plugin.version>
23-
<dotenv-source.version>2.2.3</dotenv-source.version>
24-
<rxjava-source.version>3.1.4</rxjava-source.version>
24+
<dotenv-source.version>2.2.4</dotenv-source.version>
25+
<rxjava-source.version>3.1.5</rxjava-source.version>
2526
<retrofit-source.version>2.9.0</retrofit-source.version>
2627
<converter-gson-source.version>2.9.0</converter-gson-source.version>
27-
<loggin.version>4.9.3</loggin.version>
28+
<loggin.version>4.10.0</loggin.version>
2829
<jococo-plugin.version>0.8.5</jococo-plugin.version>
2930
<lombok-source.version>1.18.24</lombok-source.version>
30-
<junit-jupiter.version>5.8.2</junit-jupiter.version>
31+
<junit-jupiter.version>5.9.0</junit-jupiter.version>
3132
<junit-jupiter-engine.version>5.8.0-M1</junit-jupiter-engine.version>
32-
<junit-vintage-engine.version>5.8.2</junit-vintage-engine.version>
33+
<junit-vintage-engine.version>5.9.0</junit-vintage-engine.version>
3334
<gson.version>2.8.8</gson.version>
3435
<json-simple-version>1.1.1</json-simple-version>
3536
<maven-site-plugin.version>3.3</maven-site-plugin.version>
3637
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
3738
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
3839
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
3940
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
40-
<json-version>20220320</json-version>
41+
<json-version>20220924</json-version>
4142
<jacoco-maven-plugin-version>0.8.7</jacoco-maven-plugin-version>
4243
<maven-release-plugin-version>2.5.3</maven-release-plugin-version>
4344
<nexus-staging-maven-plugin-version>1.6.7</nexus-staging-maven-plugin-version>
44-
<contentstack-utils-version>1.1.1</contentstack-utils-version>
45+
<contentstack-utils-version>1.2.0</contentstack-utils-version>
4546
</properties>
4647

4748
<parent>
@@ -342,6 +343,7 @@
342343
<exclude>src/main/java/com/contentstack/sdk/FetchResultCallback.class</exclude>
343344
<exclude>src/main/java/com/contentstack/sdk/EntryResultCallBack.class</exclude>
344345
<exclude>src/main/java/com/contentstack/sdk/FetchResultCallback.class</exclude>
346+
<exclude>src/main/java/com/contentstack/sdk/TestLivePreview.class</exclude>
345347
</excludes>
346348
</configuration>
347349
</plugin>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected CSBackgroundTask(Query queryInstance, Stack stackInstance, String cont
3636
csConnectionRequest.setQueryInstance(queryInstance);
3737
csConnectionRequest.setURLQueries(urlQueries);
3838
this.service = stackInstance.service;
39-
csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback, this.service);
39+
csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback, this.service, stackInstance.config);
4040

4141
}
4242

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CSConnectionRequest implements IRequestModelHTTP {
2020
private INotifyClass notifyClass;
2121
private AssetLibrary assetLibrary;
2222
private APIService service;
23+
private Config config;
2324
private Entry entryInstance;
2425
private Asset assetInstance;
2526
private Stack stackInstance;
@@ -74,6 +75,9 @@ public void setParams(Object... objects) {
7475
resultCallBack = (ResultCallBack) objects[4];
7576
}
7677
this.service = (APIService) objects[5];
78+
if (objects.length > 6) {
79+
this.config = (Config) objects[6];
80+
}
7781
sendRequest();
7882
}
7983

@@ -84,6 +88,7 @@ public void sendRequest() {
8488
connection.setHeaders(header);
8589
connection.setInfo(requestInfo);
8690
connection.setAPIService(this.service);
91+
connection.setConfig(this.config);
8792
connection.setCallBackObject(resultCallBack);
8893
if (urlQueries != null && urlQueries.size() > 0) {
8994
connection.setFormParams(urlQueries);

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Map;
1717
import java.util.logging.Level;
1818
import java.util.logging.Logger;
19+
import java.util.stream.IntStream;
1920

2021
import static com.contentstack.sdk.Constants.*;
2122

@@ -28,6 +29,7 @@ public class CSHttpConnection implements IURLRequestHTTP {
2829
private LinkedHashMap<String, Object> headers;
2930
private String info;
3031
private APIService service;
32+
private Config config;
3133
private ResultCallBack callBackObject;
3234
private JSONObject responseJSON;
3335
private HashMap<String, Object> formParams;
@@ -187,8 +189,12 @@ private void getService(String requestUrl) throws IOException {
187189
Response<ResponseBody> response = this.service.getRequest(requestUrl, this.headers).execute();
188190
if (response.isSuccessful()) {
189191
assert response.body() != null;
190-
String resp = response.body().string();
191-
responseJSON = new JSONObject(resp);
192+
// String resp = response.body().string();
193+
responseJSON = new JSONObject(response.body().string());
194+
// LivePreviewAgent to validate If LivePreview Response is there for mapping
195+
if (this.config.livePreviewEntry != null) {
196+
livePreviewAgent();
197+
}
192198
connectionRequest.onRequestFinished(CSHttpConnection.this);
193199
} else {
194200
assert response.errorBody() != null;
@@ -197,6 +203,30 @@ private void getService(String requestUrl) throws IOException {
197203

198204
}
199205

206+
private void livePreviewAgent() {
207+
if (!responseJSON.isEmpty() && responseJSON.has("entries")) {
208+
mapLPreviewToQuery(responseJSON.optJSONArray("entries"));
209+
}
210+
if (responseJSON.has("entry")) {
211+
mapLPreviewToEntry(responseJSON.optJSONObject("entry"), 0);
212+
}
213+
// TODO: responseJSON
214+
}
215+
216+
private void mapLPreviewToEntry(JSONObject entry, int idx) {
217+
System.out.println(entry);
218+
if (entry.opt("uid").equals(this.config.livePreviewEntry.opt("uid"))){
219+
System.out.println("Equal------");
220+
}
221+
}
222+
223+
private void mapLPreviewToQuery(JSONArray entries) {
224+
IntStream.range(0, entries.length())
225+
.forEach(idx -> mapLPreviewToEntry((JSONObject) entries.get(idx), idx)
226+
);
227+
}
228+
229+
200230
void setError(String errResp) {
201231
logger.info(errResp);
202232
responseJSON = new JSONObject(errResp); // Parse error string to JSONObject
@@ -210,4 +240,8 @@ void setError(String errResp) {
210240
public void setAPIService(APIService service) {
211241
this.service = service;
212242
}
243+
244+
public void setConfig(Config config) {
245+
this.config = config;
246+
}
213247
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import okhttp3.ConnectionPool;
44
import org.jetbrains.annotations.NotNull;
5+
import org.json.JSONObject;
56

67
import java.net.Proxy;
78
import java.util.concurrent.TimeUnit;
@@ -14,12 +15,14 @@ public class Config {
1415

1516
protected String livePreviewHash = null;
1617
protected String livePreviewContentType = null;
18+
protected String livePreviewEntryUid = null;
1719
protected String host = "cdn.contentstack.io";
1820
protected String version = "v3";
1921
protected String scheme = "https://";
2022
protected String endpoint;
2123
protected boolean enableLivePreview = false;
2224
protected String livePreviewHost;
25+
protected JSONObject livePreviewEntry = null;
2326
protected ContentstackRegion region = ContentstackRegion.US;
2427
protected String managementToken;
2528
protected String branch;
@@ -43,9 +46,8 @@ public void setBranch(String branch) {
4346
* <br><br><b>Example:</b><br><br>
4447
* <code>
4548
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", "proxyPort"));
46-
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("sl.theproxyvpn.io", 80));
47-
* Config config = new Config();
48-
* config.setProxy(proxy);
49+
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("sl.theproxyvpn.io", 80)); Config
50+
* config = new Config(); config.setProxy(proxy);
4951
* </code>
5052
*/
5153
public void setProxy(Proxy proxy) {
@@ -164,6 +166,11 @@ public Config setLivePreviewHost(@NotNull String livePreviewHost) {
164166
return this;
165167
}
166168

169+
protected Config setLivePreviewEntry(@NotNull JSONObject livePreviewEntry) {
170+
this.livePreviewEntry = livePreviewEntry;
171+
return this;
172+
}
173+
167174
/**
168175
* Sets management token.
169176
*

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public class Constants {
1515
protected static final String SDK_VERSION = "1.10.0";
1616
protected static final String ENVIRONMENT = "environment";
1717
protected static final String CONTENT_TYPE_UID = "content_type_uid";
18+
protected static final String ENTRY_UID = "entry_uid";
19+
protected static final String LIVE_PREVIEW = "live_preview";
20+
1821
protected static final String SYNCHRONISATION = "stacks/sync";
1922
// Errors
2023
protected static final String ERROR_CODE = "error_code";

0 commit comments

Comments
 (0)