Skip to content

Commit 0920f65

Browse files
Merge pull request #12 from contentstack/development
Development
2 parents 6dcc5f6 + 09402c4 commit 0920f65

File tree

12 files changed

+111
-46
lines changed

12 files changed

+111
-46
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33

44
------------------------------------------------
55

6+
## Version 1.5.0
7+
###### Date: 15-Nov-2019
8+
- [Stack]: Added support for function getContentType()
9+
- [ContentType]: updated function fetch()
10+
- [Query]: Updated support of whereIn(String KEY, Query queryObject)
11+
- [Query]: Updated support of whereNotIn(String KEY, Query queryObject)
12+
13+
------------------------------------------------
14+
615
## Version 1.4.2
716
###### Date: 03-Sept-2019
817
- [Config] - Added support for Region in Config.

README.md

Lines changed: 2 additions & 2 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.4.2</version>
23+
<version>1.5.0-SNAPSHOT</version>
2424
</dependency>
2525
```
2626

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

3232
### Key Concepts for using Contentstack

pom.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Written manually.
2-
version=1.4.2
2+
version=1.5.0
33
groupId=com.contentstack.sdk
44
artifactId=java

pom.xml

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

77
<groupId>com.contentstack.sdk</groupId>
88
<artifactId>java</artifactId>
9-
<version>1.4.2</version>
9+
<version>1.5.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

1212
<name>contentstack-java</name>
@@ -43,7 +43,7 @@
4343
<url>https://github.com/contentstack/contentstack-java/tree/master</url>
4444
<connection>scm:git:git://github.com/contentstack/contentstack-java.git</connection>
4545
<developerConnection>scm:git:ssh://github.com:contentstack/contentstack-java.git</developerConnection>
46-
<tag>v1.4.2</tag>
46+
<tag>v1.5.0</tag>
4747
</scm>
4848

4949
<issueManagement>

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,7 @@ public void send() {
255255

256256
try {
257257
sendGET(url);
258-
} catch (IOException e) {
259-
e.printStackTrace();
260-
} catch (JSONException e) {
258+
} catch (IOException | JSONException e) {
261259
e.printStackTrace();
262260
}
263261
}
@@ -286,9 +284,9 @@ private void sendGET(String GET_URL) throws IOException, JSONException {
286284
if (responseCode == HttpURLConnection.HTTP_OK) { // success
287285
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
288286
String inputLine;
289-
StringBuffer response = new StringBuffer();
287+
StringBuilder response = new StringBuilder();
290288
while ((inputLine = in.readLine()) != null) {
291-
response.append(inputLine);
289+
StringBuilder append = response.append(inputLine);
292290
}
293291
in.close();
294292

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ public enum ContentstackRegion { US, EU }
3838

3939
/**
4040
* Sets region allow you to set your region for the Contentstack server.
41-
*
42-
* @param region
41+
* @param region type {@link ContentstackRegion}
42+
* @return ContentstackRegion
4343
*
4444
* <p>
45-
* <b>Note:</b> Default region sets to us </a>
45+
* <b>Note:</b>
46+
* Default region sets to us
4647
*
4748
* <br><br><b>Example :</b><br>
4849
* <pre class="prettyprint">
4950
* config.setRegion(ContentstackRegion.US);
5051
* </pre>
52+
5153
*/
5254

5355
public ContentstackRegion setRegion(ContentstackRegion region) {

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,15 @@ public Query query(){
168168
/**
169169
*
170170
* This call returns information of a specific content type. It returns the content type schema, but does not include its entries.
171+
* @param params query parameters
171172
* @param callback {@link ContentTypesCallback}
172173
* <br><br><b>Example :</b><br>
173174
* <pre class="prettyprint">
174175
* ContentType contentType = stack.contentType("content_type_uid");
175-
* contentType.fetch(new ContentTypesCallback() {
176+
* JSONObject params = new JSONObject();
177+
* params.put("include_snippet_schema", true);
178+
* params.put("limit", 3);
179+
* contentType.fetch(params, new ContentTypesCallback() {
176180
*
177181
* public void onCompletion(ContentTypesModel contentTypesModel, Error error) {
178182
* if (error==null){
@@ -186,19 +190,30 @@ public Query query(){
186190
*/
187191

188192

189-
public void fetch(final ContentTypesCallback callback) {
193+
public void fetch(JSONObject params, final ContentTypesCallback callback) {
190194

191195
try {
192196

193197
String URL = "/" + stackInstance.VERSION + "/content_types/"+contentTypeName;
194198
HashMap<String, Object> headers = getHeader(localHeader);
195-
JSONObject param = new JSONObject();
199+
if (params == null){ params = new JSONObject(); }
200+
201+
Iterator keys = params.keys();
202+
while(keys.hasNext()) {
203+
// loop to get the dynamic key
204+
String key = (String)keys.next();
205+
// get the value of the dynamic key
206+
Object value = params.opt(key);
207+
// do something here with the value...
208+
params.put(key, value);
209+
}
210+
196211
if (headers.containsKey("environment")) {
197-
param.put("environment", headers.get("environment"));
212+
params.put("environment", headers.get("environment"));
198213
}
199214

200-
if (contentTypeName!=null) {
201-
fetchContentTypes(URL, param, headers, callback );
215+
if (contentTypeName!=null && !contentTypeName.isEmpty()) {
216+
fetchContentTypes(URL, params, headers, callback );
202217
}else {
203218
Error error = new Error();
204219
error.setErrorMessage(CSAppConstants.ErrorMessage_JsonNotProper);

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,6 @@ private void setIncludeJSON(JSONObject mainJson, ResultCallBack callBack){
11921192
if(objectUidForOnly!= null && objectUidForOnly.length() > 0){
11931193
mainJson.put("only[BASE][]", objectUidForOnly);
11941194
objectUidForOnly = null;
1195-
11961195
}
11971196

11981197
if(objectUidForExcept != null && objectUidForExcept.length() > 0){
@@ -1332,4 +1331,29 @@ public Entry includeReferenceContentTypeUID(){
13321331
}
13331332

13341333

1334+
/**
1335+
* Include Content Type of all returned objects along with objects themselves.
1336+
* @return {@link Entry} object, so you can chain this call.
1337+
* <br><br><b>Example :</b><br>
1338+
* <pre class="prettyprint">
1339+
* //'blt5d4sample2633b' is a dummy Stack API key
1340+
* //'blt6d0240b5sample254090d' is dummy access token.
1341+
* Stack stack = Contentstack.stack(context, "blt5d4sample2633b", "blt6d0240b5sample254090d", "stag", false);
1342+
* final Entry entry = stack.contentType("user").entry("blt3b0aaebf6f1c3762");
1343+
* entry.includeContentType();
1344+
* </pre>
1345+
*/
1346+
public Entry includeContentType(){
1347+
try {
1348+
if (otherPostJSON.has("include_schema")){
1349+
otherPostJSON.remove("include_schema");
1350+
}
1351+
otherPostJSON.put("include_content_type",true);
1352+
otherPostJSON.put("include_global_field_schema",true);
1353+
} catch (Exception e) {
1354+
e.printStackTrace();
1355+
}
1356+
return this;
1357+
}
1358+
13351359
}

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ public Query includeContentType(){
10931093
urlQueries.remove("include_schema");
10941094
}
10951095
urlQueries.put("include_content_type",true);
1096+
urlQueries.put("include_global_field_schema",true);
10961097
} catch (Exception e) {
10971098
throwException("include_content_type", CSAppConstants.ErrorMessage_QueryFilterException, e);
10981099
}
@@ -1875,28 +1876,32 @@ public Query includeReferenceContentTypUid(){
18751876

18761877

18771878
/**
1878-
* Get entries having values based on referenced fields. This query retrieves all entries that satisfy the query conditions made on referenced fields.
1879+
*
1880+
* Get entries having values based on referenced fields.
1881+
* This query retrieves all entries that satisfy the query conditions made on referenced fields.
18791882
* @param key The key to be constrained
1880-
* @return {@link Query} object, so you can chain this call.
1883+
* @param queryObject {@link Query} object, so you can chain this call
1884+
* @return {@link Query} object, so you can chain this call
18811885
*
18821886
* <br><br><b>Example :</b><br>
18831887
* <pre class="prettyprint">
18841888
* //'blt5d4sample2633b' is a dummy Stack API key
18851889
* //'blt6d0240b5sample254090d' is dummy access token.
18861890
* Stack stack = Contentstack.stack(context, "blt5d4sample2633b", "blt6d0240b5sample254090d", "stag", false);
18871891
* Query csQuery = stack.contentType("contentType_name").query();
1888-
* csQuery.whereIn("due_date");
1892+
* csQuery.whereIn("due_date", csQuery);
18891893
* </pre>
1894+
1895+
18901896
*/
1891-
public Query whereIn(String key){
1897+
public Query whereIn(String key, Query queryObject){
18921898

18931899
if(key != null){
18941900

18951901
try{
18961902

18971903
JSONObject inQueryObj = new JSONObject();
1898-
inQueryObj.put("$in_query", queryValueJSON);
1899-
queryValueJSON = new JSONObject();
1904+
inQueryObj.put("$in_query", queryObject.queryValueJSON.toString());
19001905
queryValueJSON.put(key, inQueryObj);
19011906
}catch(Exception e){
19021907
throwException("in_query",CSAppConstants.ErrorMessage_QueryFilterException, e);
@@ -1912,25 +1917,24 @@ public Query whereIn(String key){
19121917
/**
19131918
* Get entries having values based on referenced fields. This query works the opposite of $in_query and retrieves all entries that does not satisfy query conditions made on referenced fields.
19141919
* @param key The key to be constrained
1915-
* @return {@link Query} object, so you can chain this call.
1920+
* @param queryObject {@link Query} object, so you can chain this call
1921+
* @return {@link Query} object, so you can chain this call
19161922
*
19171923
* <br><br><b>Example :</b><br>
19181924
* <pre class="prettyprint">
19191925
* //'blt5d4sample2633b' is a dummy Stack API key
19201926
* //'blt6d0240b5sample254090d' is dummy access token.
19211927
* Stack stack = Contentstack.stack(context, "blt5d4sample2633b", "blt6d0240b5sample254090d", "stag", false);
19221928
* Query csQuery = stack.contentType("contentType_name").query();
1923-
* csQuery.whereNotIn("due_date");
1929+
* csQuery.whereNotIn("due_date", csQuery);
19241930
* </pre>
19251931
*/
1926-
public Query whereNotIn(String key){
1932+
public Query whereNotIn(String key, Query queryObject){
19271933

19281934
if(key != null){
1929-
19301935
try{
19311936
JSONObject inQueryObj = new JSONObject();
1932-
inQueryObj.put("$nin_query", queryValueJSON);
1933-
queryValueJSON = new JSONObject();
1937+
inQueryObj.put("$nin_query", queryObject.queryValueJSON.toString());
19341938
queryValueJSON.put(key, inQueryObj);
19351939
}catch(Exception e){
19361940
throwException("nin_query",CSAppConstants.ErrorMessage_QueryFilterException, e);

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.contentstack.sdk;
2-
32
import com.contentstack.sdk.utility.CSAppConstants;
43
import com.contentstack.sdk.utility.CSController;
54
import org.apache.log4j.Level;
65
import org.apache.log4j.LogManager;
76
import org.apache.log4j.Logger;
87
import org.json.JSONException;
98
import org.json.JSONObject;
10-
119
import java.io.UnsupportedEncodingException;
1210
import java.net.URLEncoder;
1311
import java.text.DateFormat;
@@ -235,33 +233,49 @@ private String getImageUrl() {
235233

236234

237235
/**
236+
* @param params query parameters
238237
* @param callback ContentTypesCallback
239238
* This call returns comprehensive information of all the content types available in a particular stack in your account.
240239
*
241240
* <br><br><b>Example :</b><br>
242241
* <pre class="prettyprint">
242+
*
243+
* JSONObject params = new JSONObject();
244+
* params.put("include_snippet_schema", true);
245+
* params.put("limit", 3);
243246
* stack.getContentTypes(new ContentTypesCallback() {
244247
* public void onCompletion(ContentTypesModel contentTypesModel, Error error) {
245-
* Stack.log(TAG,"contentTypesModel: "+ contentTypesModel.getResponseJSON());
246-
* include_count = contentTypesModel.getCount();
247-
*
248+
* if (error == null){
249+
* // do your stuff.
250+
* }
248251
* }
249252
* });
250253
*</pre>
251254
*/
252255

253-
public void getContentTypes( final ContentTypesCallback callback) {
256+
public void getContentTypes(JSONObject params, final ContentTypesCallback callback) {
254257

255258
try {
256-
String URL = "/" + this.VERSION + "/content_types/";
259+
String URL = "/" + this.VERSION + "/content_types";
257260
HashMap<String, Object> headers = getHeader(localHeader);
258-
JSONObject content_type_param = new JSONObject();
261+
if (params == null){ params = new JSONObject(); }
262+
263+
Iterator keys = params.keys();
264+
while(keys.hasNext()) {
265+
// loop to get the dynamic key
266+
String key = (String)keys.next();
267+
// get the value of the dynamic key
268+
Object value = params.opt(key);
269+
// do something here with the value...
270+
params.put(key, value);
271+
}
272+
259273
if (headers.containsKey("environment")) {
260-
content_type_param.put("environment", headers.get("environment"));
261-
content_type_param.put("include_count", true);
274+
params.put("environment", headers.get("environment"));
275+
params.put("include_count", true);
262276
}
263277

264-
fetchContentTypes(URL, content_type_param, headers, callback );
278+
fetchContentTypes(URL, params, headers, callback );
265279

266280
}catch (Exception e){
267281

0 commit comments

Comments
 (0)