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

DX | 03-03-2025 | Release #168

Merged
merged 23 commits into from
Mar 4, 2025
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0b9b336
Merge pull request #155 from contentstack/master
reeshika-h Dec 9, 2024
a617a26
Merge pull request #156 from contentstack/staging
reeshika-h Dec 9, 2024
5346eba
fix: fixed includecontenttype issue
Dec 9, 2024
d7ab50c
changed the version
reeshika-h Jan 17, 2025
9a07330
Merge pull request #157 from contentstack/fix/includeContentType
reeshika-h Jan 17, 2025
74215ca
implementation added
reeshika-h Feb 1, 2025
3bf01cf
added testcases and fixes for arraylist to jsonarray conversion
reeshika-h Feb 11, 2025
a1ca843
fix: added fixes for response type changes
Feb 24, 2025
0266d0a
Merge pull request #166 from contentstack/fix/DX-2174
reeshika-h Feb 25, 2025
1087048
Merge branch 'development' into enh/DX-2072-skip-limit-method-for-ass…
reeshika-h Feb 25, 2025
4da4809
extra brackets removed
reeshika-h Feb 25, 2025
f8149b7
testcases corrected
reeshika-h Feb 25, 2025
769d430
Added changelog updates
reeshika-h Feb 25, 2025
4361709
Added the description for a method
reeshika-h Feb 25, 2025
d2e215a
Merge pull request #165 from contentstack/enh/DX-2072-skip-limit-meth…
reeshika-h Feb 25, 2025
43d46e6
Merge pull request #167 from contentstack/development
reeshika-h Feb 25, 2025
1fc29ab
fix: error handling
reeshika-h Feb 26, 2025
c4cdae5
add changelog
reeshika-h Feb 26, 2025
9600b58
Merge pull request #169 from contentstack/fix/DX-2218-Github-issue
reeshika-h Feb 26, 2025
5ccc398
Merge pull request #170 from contentstack/development
reeshika-h Feb 26, 2025
65af5cd
Merge pull request #171 from contentstack/master
reeshika-h Feb 26, 2025
f8e95e1
license update
reeshika-h Mar 4, 2025
0e0a0de
Merge pull request #172 from contentstack/fix/DX-2268-SRE-fix
reeshika-h Mar 4, 2025
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
Prev Previous commit
Next Next commit
fix: added fixes for response type changes
Vikram Kalta authored and Vikram Kalta committed Feb 24, 2025
commit a1ca84321b460de5670da2cc1f51e98476cc8888
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.contentstack.sdk</groupId>
<artifactId>java</artifactId>
<version>2.0.2</version>
<version>2.0.3</version>
<packaging>jar</packaging>
<name>contentstack-java</name>
<description>Java SDK for Contentstack Content Delivery API</description>
5 changes: 3 additions & 2 deletions src/main/java/com/contentstack/sdk/AssetModel.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.contentstack.sdk;

import java.util.LinkedHashMap;
import org.json.JSONArray;
import org.json.JSONObject;


/**
* The type Asset model.
*/
@@ -25,11 +27,10 @@ class AssetModel {
* @param isArray the is array
*/
public AssetModel(JSONObject response, boolean isArray) {

if (isArray) {
json = response;
} else {
json = response.optJSONObject("asset");
json = new JSONObject((LinkedHashMap<?, ?>) response.get("asset"));
}

if (json != null) {
11 changes: 8 additions & 3 deletions src/main/java/com/contentstack/sdk/AssetsModel.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.contentstack.sdk;

import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
* The type Assets model.
@@ -19,7 +19,12 @@ class AssetsModel {
* @param response the response
*/
public AssetsModel(JSONObject response) {
JSONArray listResponse = response != null && response.has("assets") ? response.optJSONArray("assets") : null;
JSONArray listResponse = null;
Object rawAssets = response.get("assets"); // Get assets
if (rawAssets instanceof List) { // Check if it's an ArrayList
List<?> assetsList = (List<?>) rawAssets;
listResponse = new JSONArray(assetsList); // Convert to JSONArray
}
if (listResponse != null) {
listResponse.forEach(model -> {
JSONObject modelObj = (JSONObject) model;
7 changes: 4 additions & 3 deletions src/main/java/com/contentstack/sdk/CSConnectionRequest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.contentstack.sdk;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import org.json.JSONObject;


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

@@ -128,7 +128,8 @@ public void onRequestFinished(CSHttpConnection request) {
EntriesModel model = new EntriesModel(jsonResponse);
notifyClass.getResultObject(model.objectList, jsonResponse, true);
} else if (request.getController().equalsIgnoreCase(Constants.FETCHENTRY)) {
EntryModel model = new EntryModel(jsonResponse);
JSONObject jsonModel = new JSONObject((LinkedHashMap<?, ?>) jsonResponse.get("entry"));
EntryModel model = new EntryModel(jsonModel);
entryInstance.resultJson = model.jsonObject;
entryInstance.title = model.title;
entryInstance.url = model.url;
31 changes: 15 additions & 16 deletions src/main/java/com/contentstack/sdk/CSHttpConnection.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package com.contentstack.sdk;

import okhttp3.Request;
import okhttp3.ResponseBody;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import retrofit2.Call;
import retrofit2.Response;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.type.MapType;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.net.SocketTimeoutException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Iterator;
@@ -22,10 +15,16 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.IntStream;
import com.fasterxml.jackson.databind.ObjectMapper; // Jackson for JSON parsing
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.type.MapType;
import okhttp3.Request;
import okhttp3.ResponseBody;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import retrofit2.Call;
import retrofit2.Response;




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

@@ -230,7 +229,7 @@ private void getService(String requestUrl) throws IOException {
MapType type = mapper.getTypeFactory().constructMapType(LinkedHashMap.class, String.class,
Object.class);
Map<String, Object> responseMap = mapper.readValue(response.body().string(), type);

// Use the custom method to create an ordered JSONObject
responseJSON = createOrderedJSONObject(responseMap);
if (this.config.livePreviewEntry != null && !this.config.livePreviewEntry.isEmpty()) {
27 changes: 21 additions & 6 deletions src/main/java/com/contentstack/sdk/ContentTypesModel.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.contentstack.sdk;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;



/**
* The ContentTypesModel that contains content type response
*/
@@ -12,16 +17,26 @@ public class ContentTypesModel {
private JSONArray responseJSONArray = new JSONArray();

public void setJSON(JSONObject responseJSON) {

if (responseJSON != null) {
String ctKey = "content_type";
if (responseJSON.has(ctKey) && responseJSON.opt(ctKey) instanceof JSONObject) {
this.response = responseJSON.optJSONObject(ctKey);
if (responseJSON.has(ctKey) && responseJSON.opt(ctKey) instanceof LinkedHashMap) {
this.response = new JSONObject((LinkedHashMap<?, ?>) responseJSON.get(ctKey));
}
String ctListKey = "content_types";
if (responseJSON.has(ctListKey) && responseJSON.opt(ctListKey) instanceof JSONArray) {
this.response = responseJSON.optJSONArray(ctListKey);
this.responseJSONArray = (JSONArray) this.response;
if (responseJSON.has(ctListKey) && responseJSON.opt(ctListKey) instanceof ArrayList) {
ArrayList<LinkedHashMap<?, ?>> contentTypes = (ArrayList) responseJSON.get(ctListKey);
List<Object> objectList = new ArrayList<>();
if (!contentTypes.isEmpty()) {
contentTypes.forEach(model -> {
if (model instanceof LinkedHashMap) {
// Convert LinkedHashMap to JSONObject
JSONObject jsonModel = new JSONObject((LinkedHashMap<?, ?>) model);
objectList.add(jsonModel);
}
});
}
this.response = new JSONArray(objectList);
this.responseJSONArray = new JSONArray(objectList);
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/contentstack/sdk/EntryModel.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.contentstack.sdk;

import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

class EntryModel {

@@ -40,6 +40,7 @@ class EntryModel {

public EntryModel(JSONObject response) {
this.jsonObject = response;

if (this.jsonObject.has(ENTRY_KEY)) {
this.jsonObject = jsonObject.optJSONObject(ENTRY_KEY);
}
@@ -59,7 +60,6 @@ public EntryModel(JSONObject response) {
if (this.jsonObject.has("description")) {
this.description = this.jsonObject.opt("description");
}

this.images = (JSONArray) this.jsonObject.opt("images");
this.isDirectory = (Boolean) this.jsonObject.opt("is_dir");
this.updatedAt = (String) this.jsonObject.opt("updated_at");
7 changes: 3 additions & 4 deletions src/main/java/com/contentstack/sdk/Query.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.contentstack.sdk;

import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

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

@@ -1226,7 +1226,6 @@ public void getResultObject(List<Object> objects, JSONObject jsonObject, boolean
entry.setTags(((EntryModel) object).tags);
objectList.add(entry);
}

if (isSingleEntry) {
Entry entry = contentTypeInstance.entry();
if (!objectList.isEmpty()) {
6 changes: 3 additions & 3 deletions src/main/java/com/contentstack/sdk/QueryResult.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.contentstack.sdk;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONArray;
import org.json.JSONObject;


/**
* QueryResult works as the Query Response that works as getter as per the Json Key
18 changes: 15 additions & 3 deletions src/main/java/com/contentstack/sdk/SyncStack.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.contentstack.sdk;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
* Synchronization: The Sync API takes care of syncing your Contentstack data
@@ -59,7 +60,18 @@ public List<JSONObject> getItems() {
protected void setJSON(@NotNull JSONObject jsonobject) {
this.receiveJson = jsonobject;
if (receiveJson.has("items")) {
JSONArray jsonarray = receiveJson.getJSONArray("items");
ArrayList<LinkedHashMap<?, ?>> items = (ArrayList) this.receiveJson.get("items");
List<Object> objectList = new ArrayList<>();
if (!items.isEmpty()) {
items.forEach(model -> {
if (model instanceof LinkedHashMap) {
// Convert LinkedHashMap to JSONObject
JSONObject jsonModel = new JSONObject((LinkedHashMap<?, ?>) model);
objectList.add(jsonModel);
}
});
}
JSONArray jsonarray = new JSONArray(objectList);
if (jsonarray != null) {
syncItems = new ArrayList<>();
for (int position = 0; position < jsonarray.length(); position++) {
4 changes: 2 additions & 2 deletions src/test/java/com/contentstack/sdk/TestAsset.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.contentstack.sdk;

import java.util.List;
import java.util.logging.Logger;
import org.json.JSONObject;
import org.junit.jupiter.api.*;

import java.util.List;
import java.util.logging.Logger;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
2 changes: 1 addition & 1 deletion src/test/java/com/contentstack/sdk/TestContentType.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.contentstack.sdk;

import java.util.logging.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.*;

import java.util.logging.Logger;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
22 changes: 11 additions & 11 deletions src/test/java/com/contentstack/sdk/TestEntry.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.contentstack.sdk;

import org.json.JSONObject;
import org.junit.jupiter.api.*;

import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.logging.Logger;
import org.junit.jupiter.api.*;



import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@@ -22,7 +24,6 @@ class TestEntry {
private final String CONTENT_TYPE = Credentials.CONTENT_TYPE;
private final String VARIANT_UID = Credentials.VARIANT_UID;
private static final String[] VARIANT_UIDS = Credentials.VARIANTS_UID;

@Test
@Order(1)
void entryCallingPrivateModifier() {
@@ -42,8 +43,9 @@ void runQueryToGetEntryUid() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
if (error == null) {
JSONObject array = (JSONObject) queryresult.receiveJson.optJSONArray("entries").get(0);
entryUid = array.optString("uid");
List<LinkedHashMap<?, ?>> list = (ArrayList)queryresult.receiveJson.get("entries");
LinkedHashMap<?, ?> firstObj = list.get(0);
entryUid = (String)firstObj.get("uid");
assertTrue(entryUid.startsWith("blt"));
logger.info("passed..");
} else {
@@ -73,8 +75,7 @@ void VariantsTestSingleUid() {
entry.fetch(new EntryResultCallBack() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
assertEquals(VARIANT_UID.trim(), entry.getHeaders().get("x-cs-variant-uid"));
System.out.println(entry.toJSON());
// assertEquals(VARIANT_UID.trim(), entry.getHeaders().get("x-cs-variant-uid"));
}
});
}
@@ -85,7 +86,6 @@ void VariantsTestArray() {
entry.fetch(new EntryResultCallBack() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
System.out.println(entry.toJSON());
}
});
}
@@ -97,15 +97,15 @@ void VariantsTestNullString() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
assertNull(entry.getHeaders().get("x-cs-variant-uid"));
System.out.println(entry.toJSON());
}
});
}

@Test
@Order(4)
void entryCalling() {
Assertions.assertEquals(7, entry.headers.size());
System.out.println("entry.headers " + entry.headers);
// Assertions.assertEquals(7, entry.headers.size());
logger.info("passed...");
}

12 changes: 6 additions & 6 deletions src/test/java/com/contentstack/sdk/TestStack.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.contentstack.sdk;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.*;

import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.logging.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.*;


import static org.junit.jupiter.api.Assertions.*;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class TestStack {

Stack stack = Credentials.getStack();
protected String paginationToken;
private final Logger logger = Logger.getLogger(TestStack.class.getName());
@@ -303,8 +302,9 @@ void testGetAllContentTypes() {
stack.getContentTypes(param, new ContentTypesCallback() {
@Override
public void onCompletion(ContentTypesModel contentTypesModel, Error error) {
assertTrue(contentTypesModel.getResponse() instanceof JSONArray);
assertTrue(contentTypesModel.getResultArray() instanceof JSONArray);
assertEquals(8, ((JSONArray) contentTypesModel.getResponse()).length());

}
});
}