Skip to content

Commit 96cd42b

Browse files
Merge pull request #29 from contentstack/querying_with_null
Querying with null
2 parents 9ad0569 + 26eaf9e commit 96cd42b

File tree

7 files changed

+57
-49
lines changed

7 files changed

+57
-49
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
# CHANGELOG
12

2-
## CHANGELOG
3+
## Version 1.5.7
4+
###### Date: 20-Feb-2021
5+
Document updated
6+
7+
#23 Fixed Issue: Querying content with `null` field
8+
• Query: query content by specifying fields as null
39

410
## Version 1.5.6
511
###### Date: 27-Jan-2021

README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ To use the Contentstack Java SDK to your existing project, perform the steps giv
2020
<dependency>
2121
<groupId>com.contentstack.sdk</groupId>
2222
<artifactId>java</artifactId>
23-
<version>1.5.6</version>
23+
<version>1.5.7</version>
2424
</dependency>
2525
```
2626

2727
2. **Gradle**
2828
```java
29-
implementation 'com.contentstack.sdk:java:1.5.6'
29+
implementation 'com.contentstack.sdk:java:1.5.7'
3030
```
3131

3232
### Key Concepts for using Contentstack
@@ -59,7 +59,7 @@ A publishing environment corresponds to one or more deployment servers or a cont
5959

6060
To initialize the SDK, specify application API key, access token, and environment name of the stack as shown in the snippet given below:
6161
```java
62-
Stack stack = Contentstack.stack( "apiKey", "accessToken", "environment_name");
62+
Stack stack = Contentstack.stack( "APIKey", "accessToken", "environment_name");
6363
```
6464
To get the API credentials mentioned above, log in to your Contentstack account and then in your top panel navigation, go to Settings &gt; Stack to view the API Key and Access Token.
6565

@@ -73,13 +73,13 @@ To retrieve a single entry from a content type use the code snippet given below:
7373
ContentType contentType = stack.contentType("content_type_uid");
7474
Entry blogEntry = contentType.entry("entry_uid");
7575
blogEntry.fetch(new EntryResultCallBack() {
76-
@Override
77-
public void onCompletion(ResponseType responseType, Error error) {
78-
if (error == null) {
79-
[Success block]
80-
} else {
81-
[Error block]
82-
}}
76+
@Override
77+
public void onCompletion(ResponseType responseType, Error error) {
78+
if (error == null) {
79+
//Success block
80+
} else {
81+
//Error block
82+
}}
8383
});
8484
```
8585
##### Get Multiple Entries
@@ -90,13 +90,14 @@ To retrieve multiple entries of a particular content type, use the code snippet
9090
//stack is an instance of Stack class
9191
Query blogQuery = stack.contentType("content_type_uid").query();
9292
blogQuery.find(new QueryResultsCallBack() {
93-
@Override
94-
publicvoidonCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
95-
if(error == null){
96-
[Success block]
97-
}else{
98-
[Error block]
99-
}}});
93+
@Override
94+
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
95+
if(error == null){
96+
//Success block
97+
}else{
98+
//Error block
99+
}}
100+
});
100101
```
101102

102103

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.contentstack.sdk</groupId>
88
<artifactId>java</artifactId>
9-
<version>1.5.6</version>
9+
<version>1.5.7</version>
1010
<packaging>jar</packaging>
1111
<name>contentstack-java</name>
1212
<description>Java SDK for Contentstack Content Delivery API, Contentstack is a headless CMS with an API-first approach

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,22 +222,22 @@ public void send() {
222222

223223
private void sendGET(String GET_URL) throws IOException, JSONException {
224224
URL obj = new URL(GET_URL);
225-
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
226-
con.setRequestMethod("GET");
225+
HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
226+
conn.setRequestMethod("GET");
227227
if (this.headers.containsKey("api_key")){
228-
con.setRequestProperty("api_key", headers.get("api_key").toString());
228+
conn.setRequestProperty("api_key", headers.get("api_key").toString());
229229
}
230230
if (this.headers.containsKey("access_token")){
231-
con.setRequestProperty("access_token", headers.get("access_token").toString());
231+
conn.setRequestProperty("access_token", headers.get("access_token").toString());
232232
}
233233
if (this.headers.containsKey("environment")){
234-
con.setRequestProperty("environment", headers.get("environment").toString());
234+
conn.setRequestProperty("environment", headers.get("environment").toString());
235235
}
236-
con.setRequestProperty("X-User-Agent", defaultUserAgent()+"/"+ CSAppConstants.SDK_VERSION);
237-
con.setRequestProperty("Content-Type", "application/json");
238-
int responseCode = con.getResponseCode();
236+
conn.setRequestProperty("X-User-Agent", defaultUserAgent()+"/"+ CSAppConstants.SDK_VERSION);
237+
conn.setRequestProperty("Content-Type", "application/json");
238+
int responseCode = conn.getResponseCode();
239239
if (responseCode == HttpURLConnection.HTTP_OK) { // success
240-
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8));
240+
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
241241
String inputLine;
242242
StringBuilder response = new StringBuilder();
243243
while ((inputLine = in.readLine()) != null) {
@@ -248,7 +248,7 @@ private void sendGET(String GET_URL) throws IOException, JSONException {
248248
connectionRequest.onRequestFinished(CSHttpConnection.this);
249249
} else {
250250
// Setting up error details, like error_message, error_code, error_details
251-
settingErrorInfo(con);
251+
settingErrorInfo(conn);
252252
}
253253

254254
}

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Query implements INotifyClass {
1919
protected LinkedHashMap<String, Object> formHeader = null;
2020
private JSONObject mainJSON = null;
2121
private String formName = null;
22-
private JSONObject urlQueries = null;
22+
protected JSONObject urlQueries = null;
2323
private LinkedHashMap<String, Object> localHeader = null;
2424
private QueryResultsCallBack queryResultCallback;
2525
private SingleQueryResultCallback singleQueryResultCallback;
@@ -1521,7 +1521,6 @@ private LinkedHashMap<String, Object> getUrlParams(JSONObject jsonMain) {
15211521
e.printStackTrace();
15221522
}
15231523
}
1524-
15251524
return hashMap;
15261525
}
15271526

@@ -1611,26 +1610,28 @@ private LinkedHashMap<String, Object> getHeader(LinkedHashMap<String, Object> lo
16111610

16121611
/**
16131612
* This method adds key and value to an Entry.
1613+
* Parameters:
1614+
*
1615+
* @param key: The key as string which needs to be added to the Query
1616+
* @param value: The value as string which needs to be added to the Query
1617+
* @return - Query
16141618
*
1615-
* @param key The key as string which needs to be added to the Query
1616-
* @param value The value as string which needs to be added to the Query
1617-
* @return {@link Query}
16181619
* <br><br><b>Example :</b><br>
16191620
* <pre class="prettyprint">
16201621
* Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
1621-
* Query csQuery = stack.contentType("contentType_name").query();<br>
1622+
* Query csQuery = stack.contentType("contentType_name").query();
16221623
* csQuery.addParam("key", "some_value");
1623-
* csQuery.findOne(new QueryResultsCallBack() {<br>
1624+
* csQuery.findOne(new QueryResultsCallBack() {
16241625
* &#64;Override
1625-
* public void onCompletion(ResponseType responseType, ENTRY entry, Error error) {<br>
1626+
* public void onCompletion(ResponseType responseType, ENTRY entry, Error error) {
16261627
* }
1627-
* });<br>
1628+
* });
16281629
* </pre>
16291630
*/
16301631
public Query addParam(String key, String value) {
16311632
try {
1632-
if (key != null && value != null) {
1633-
urlQueries.put(key, value);
1633+
if (key != null) {
1634+
urlQueries.put(key, value == null ? JSONObject.NULL : value);
16341635
} else {
16351636
throwException("and", CSAppConstants.ErrorMessage_QueryFilterException, null);
16361637
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected Asset asset(){
111111

112112
/**
113113
* assetLibrary returns AssetLibrary instance
114-
* @return @{@link AssetLibrary}
114+
* @return AssetLibrary
115115
*/
116116
public AssetLibrary assetLibrary(){
117117
AssetLibrary library = new AssetLibrary();
@@ -122,21 +122,21 @@ public AssetLibrary assetLibrary(){
122122

123123
/**
124124
* Returns apiKey of particular stack
125-
* @return @{@link String} stack api key
125+
* @return stack api key
126126
*/
127127
public String getApplicationKey(){ return stackApiKey;}
128128

129129

130130
/**
131131
* Returns accessToken of particular stack
132-
* @return @{@link String} access token of particular stack
132+
* @return access token of particular stack
133133
*/
134134
public String getAccessToken(){ return localHeader != null ? (String)localHeader.get("access_token") : null;};
135135

136136

137137
/**
138138
* Removes Header by key
139-
* @param key @{@link String} header key
139+
* @param key header key
140140
* <br><br><b>Example :</b><br>
141141
* stack.removeHeader("delivery_token");
142142
* <br><br>
@@ -151,11 +151,11 @@ public void removeHeader(String key){
151151

152152
/**
153153
* Adds header to the stack by key and value
154-
* @param key @{@link String} header key
155-
* @param value @{@link String} header value
154+
* @param key header key
155+
* @param value header value
156156
* <p>
157-
* Example
158-
* stack.setHeader("delivery_token","blt843748744");
157+
* Example
158+
* stack.setHeader("delivery_token","blt843748744");
159159
* </p>
160160
*/
161161
public void setHeader(String key, String value) {

src/main/java/com/contentstack/sdk/utility/CSAppConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class CSAppConstants {
88

9-
public static final String SDK_VERSION = "1.5.6";
9+
public static final String SDK_VERSION = "1.5.7";
1010

1111
public static enum RequestMethod
1212
{

0 commit comments

Comments
 (0)