Skip to content

Commit 767720a

Browse files
🪴 #67 error handling infinite loop issue
1 parent fd333f0 commit 767720a

29 files changed

+1078
-777
lines changed

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<rxjava-source.version>3.1.5</rxjava-source.version>
2525
<retrofit-source.version>2.9.0</retrofit-source.version>
2626
<converter-gson-source.version>2.9.0</converter-gson-source.version>
27-
<loggin.version>4.10.0</loggin.version>
27+
<loggin.version>4.9.2</loggin.version>
2828
<jococo-plugin.version>0.8.5</jococo-plugin.version>
2929
<lombok-source.version>1.18.24</lombok-source.version>
3030
<junit-jupiter.version>5.9.1</junit-jupiter.version>
@@ -197,7 +197,8 @@
197197
</execution>
198198
</executions>
199199
</plugin>
200-
200+
<!--Generate overview.html file-->
201+
<!-- -overview "/Users/shaileshmishra/Documents/workspace/contentstack/javaspace/contentstack-java/src/main/overview.html" -bottom "<b>Copyright © 2012-2022 Contentstack </b><sup>TM</sup>" -->
201202
<plugin>
202203
<groupId>org.apache.maven.plugins</groupId>
203204
<artifactId>maven-javadoc-plugin</artifactId>
@@ -279,7 +280,7 @@
279280
<plugin>
280281
<groupId>org.sonatype.plugins</groupId>
281282
<artifactId>nexus-staging-maven-plugin</artifactId>
282-
<version>${nexus-staging-maven-plugin-version}</version>
283+
<version>${nexus-staging-maven-plugin.version}</version>
283284
<extensions>true</extensions>
284285
<configuration>
285286
<serverId>ossrh</serverId>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) {
102102
* @param headerKey
103103
* the header key
104104
*
105-
*
106105
* <br>
107106
* <br>
108107
* <b>Example :</b><br>

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import static com.contentstack.sdk.Constants.ENVIRONMENT;
1111

1212
/**
13-
* The type Asset library.
13+
* The Asset library is used to get list of assets available in the stack, We can apply filters on the assets also.
14+
* The Get all assets request fetches the list of all the assets of a particular stack. It returns the content of each
15+
* asset in JSON format.
1416
*/
1517
public class AssetLibrary implements INotifyClass {
1618

@@ -34,8 +36,10 @@ protected void setStackInstance(@NotNull Stack stack) {
3436
/**
3537
* Sets header.
3638
*
37-
* @param headerKey the header key
38-
* @param headerValue the header value
39+
* @param headerKey
40+
* the header key
41+
* @param headerValue
42+
* the header value
3943
*/
4044
public void setHeader(@NotNull String headerKey, @NotNull String headerValue) {
4145
this.headers.put(headerKey, headerValue);
@@ -44,7 +48,8 @@ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) {
4448
/**
4549
* Remove header.
4650
*
47-
* @param headerKey the header key
51+
* @param headerKey
52+
* the header key
4853
*/
4954
public void removeHeader(@NotNull String headerKey) {
5055
if (!headerKey.isEmpty()) {
@@ -55,8 +60,10 @@ public void removeHeader(@NotNull String headerKey) {
5560
/**
5661
* Sort asset library.
5762
*
58-
* @param keyOrderBy the key order by
59-
* @param orderby the orderby
63+
* @param keyOrderBy
64+
* the key order by
65+
* @param orderby
66+
* the orderby
6067
* @return the asset library
6168
*/
6269
public AssetLibrary sort(String keyOrderBy, ORDERBY orderby) {
@@ -89,14 +96,13 @@ public AssetLibrary includeRelativeUrl() {
8996
}
9097

9198
/**
92-
* Retrieve the published content of the fallback locale if an entry is not
93-
* localized in specified locale
99+
* Retrieve the published content of the fallback locale if an entry is not localized in specified locale
94100
*
95101
* @return {@link AssetLibrary} object, so you can chain this call. <br>
96-
* <br>
97-
* <b>Example :</b><br>
98-
*
99-
* <pre class="prettyprint">
102+
* <br>
103+
* <b>Example :</b><br>
104+
*
105+
* <pre class="prettyprint">
100106
* Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
101107
* AssetLibrary assetLibObject = stack.assetLibrary();
102108
* AssetLibrary.includeFallback();
@@ -119,7 +125,8 @@ public int getCount() {
119125
/**
120126
* Fetch all.
121127
*
122-
* @param callback the callback
128+
* @param callback
129+
* the callback
123130
*/
124131
public void fetchAll(FetchAssetsCallback callback) {
125132
this.callback = callback;
@@ -128,7 +135,7 @@ public void fetchAll(FetchAssetsCallback callback) {
128135
}
129136

130137
private void fetchFromNetwork(String url, JSONObject urlQueries, LinkedHashMap<String, Object> headers,
131-
FetchAssetsCallback callback) {
138+
FetchAssetsCallback callback) {
132139
if (callback != null) {
133140
HashMap<String, Object> urlParams = getUrlParams(urlQueries);
134141
new CSBackgroundTask(this, stackInstance, Constants.FETCHALLASSETS, url, headers, urlParams,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import org.json.JSONObject;
66

77
import java.net.Proxy;
8-
import java.util.ArrayList;
8+
import java.util.List;
99
import java.util.concurrent.TimeUnit;
1010

1111

1212
/**
13-
* The type Config. enables optional parameters while passing from stack
13+
* The Config enables optional parameters while passing from stack. You can set different configs params to the stack
14+
* like host, version, livePreview, endpoint, region, branch etc
1415
*/
1516
public class Config {
1617

@@ -30,7 +31,7 @@ public class Config {
3031
protected Proxy proxy = null;
3132
protected ConnectionPool connectionPool = new ConnectionPool();
3233

33-
protected ArrayList<ContentstackPlugin> plugins = null;
34+
protected List<ContentstackPlugin> plugins = null;
3435

3536
public String getBranch() {
3637
return branch;
@@ -110,12 +111,11 @@ protected String getEndpoint() {
110111
return endpoint + "/" + getVersion() + "/";
111112
}
112113

113-
protected String setEndpoint(@NotNull String endpoint) {
114+
protected void setEndpoint(@NotNull String endpoint) {
114115
this.endpoint = endpoint;
115-
return this.endpoint;
116116
}
117117

118-
public void setPlugins(ArrayList<ContentstackPlugin> plugins) {
118+
public void setPlugins(List<ContentstackPlugin> plugins) {
119119
this.plugins = plugins;
120120
}
121121

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

Lines changed: 44 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.contentstack.sdk;
22

3-
import java.text.ParseException;
4-
import java.text.SimpleDateFormat;
5-
import java.util.*;
6-
import java.util.logging.Level;
3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.time.Instant;
6+
import java.time.LocalDateTime;
7+
import java.time.ZoneId;
8+
import java.time.ZonedDateTime;
9+
import java.time.format.DateTimeFormatter;
10+
import java.util.Calendar;
11+
import java.util.TimeZone;
712
import java.util.logging.Logger;
813

914
/**
@@ -16,7 +21,7 @@
1621
public class Constants {
1722

1823
private static final Logger logger = Logger.getLogger(Constants.class.getSimpleName());
19-
protected static final String SDK_VERSION = "1.10.1";
24+
protected static final String SDK_VERSION = "1.10.2";
2025
protected static final String ENVIRONMENT = "environment";
2126
protected static final String CONTENT_TYPE_UID = "content_type_uid";
2227
protected static final String ENTRY_UID = "entry_uid";
@@ -66,71 +71,53 @@ public enum REQUEST_CONTROLLER {
6671
public static final String QUERY_EXCEPTION = "Please provide valid params.";
6772

6873

69-
7074
/**
71-
* Parse date calendar.
72-
*
73-
* @param date
74-
* the date
75-
* @param timeZone
76-
* the time zone
77-
* @return the calendar
75+
* @param dateString
76+
* the date in string format
77+
* @param zoneId
78+
* the string zoneId
79+
* @return Calendar
7880
*/
79-
public static Calendar parseDate(String date, TimeZone timeZone) {
80-
ArrayList<String> knownPatterns = new ArrayList<>();
81-
knownPatterns.add("yyyy-MM-dd'T'HH:mm:ssZ");
82-
knownPatterns.add("yyyy-MM-dd'T'HH:mm:ss'Z'");
83-
knownPatterns.add("yyyy-MM-dd'T'HH:mm.ss'Z'");
84-
knownPatterns.add("yyyy-MM-dd'T'HH:mmZ");
85-
knownPatterns.add("yyyy-MM-dd'T'HH:mm'Z'");
86-
knownPatterns.add("yyyy-MM-dd'T'HH:mm'Z'");
87-
knownPatterns.add("yyyy-MM-dd'T'HH:mm:ss");
88-
knownPatterns.add("yyyy-MM-dd' 'HH:mm:ss");
89-
knownPatterns.add("yyyy-MM-dd");
90-
knownPatterns.add("HH:mm:ssZ");
91-
knownPatterns.add("HH:mm:ss'Z'");
92-
93-
for (String formatString : knownPatterns) {
94-
try {
95-
return parseDate(date, formatString, timeZone);
96-
} catch (ParseException e) {
97-
logger.log(Level.WARNING, e.getLocalizedMessage(), e);
98-
}
99-
}
100-
return null;
81+
public static Calendar parseDateToTimeZone(@NotNull String dateString, @NotNull String zoneId) {
82+
//String dateString = "2016-12-16T12:36:33.961Z";
83+
Instant instant = Instant.parse(dateString);
84+
// Define the target time zone
85+
ZoneId targetTimeZone = ZoneId.of(zoneId);
86+
// Convert the instant to the target time zone
87+
ZonedDateTime dateTime = instant.atZone(targetTimeZone);
88+
// Extract the year, month, day, hour, minute, and second
89+
Calendar cal = Calendar.getInstance();
90+
cal.set(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth(), dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond());
91+
return cal;
92+
}
93+
94+
private static Calendar toCalendar(@NotNull String date) {
95+
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
96+
LocalDateTime dt = LocalDateTime.parse(date, formatter);
97+
Calendar cal = Calendar.getInstance();
98+
cal.set(dt.getYear(), dt.getMonthValue(), dt.getDayOfMonth(), dt.getHour(), dt.getMinute(), dt.getSecond());
99+
return cal;
101100
}
102101

102+
103103
/**
104-
* Parse date calendar.
105-
*
106104
* @param date
107-
* the date
108-
* @param dateFormat
109-
* the date format
105+
* The date in string format like (String dateString = "2016-12-16T12:36:33.961Z";)
110106
* @param timeZone
111-
* the time zone
112-
* @return the calendar
113-
* @throws ParseException
114-
* the parse exception
107+
* the time zone as string
108+
* @return calendar @{@link Calendar}
115109
*/
116-
public static Calendar parseDate(String date, String dateFormat, TimeZone timeZone) throws ParseException {
117-
Calendar cal = Calendar.getInstance();
118-
SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
119-
Date dateObject = dateFormatter.parse(date);
120-
String month = new SimpleDateFormat("MM").format(dateObject);
121-
String day = new SimpleDateFormat("dd").format(dateObject);
122-
String year = new SimpleDateFormat("yyyy").format(dateObject);
123-
String hourOfDay = new SimpleDateFormat("HH").format(dateObject);
124-
String min = new SimpleDateFormat("mm").format(dateObject);
125-
String sec = new SimpleDateFormat("ss").format(dateObject);
126-
110+
public static Calendar parseDate(@NotNull String date, TimeZone timeZone) {
111+
// Use the ISO-8601 format to parse the date string
112+
if (date.isEmpty()){
113+
return null;
114+
}
115+
Calendar cal = toCalendar(date);
127116
if (timeZone != null) {
128117
cal.setTimeZone(timeZone);
129118
} else {
130119
cal.setTimeZone(TimeZone.getDefault());
131120
}
132-
cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day), Integer.parseInt(hourOfDay),
133-
Integer.parseInt(min), Integer.parseInt(sec));
134121
return cal;
135122
}
136123

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.contentstack.sdk;
22

3+
/**
4+
* The callback for Content Types that contains ContentTypesModel and Error
5+
*/
36
public abstract class ContentTypesCallback implements ResultCallBack {
47

58
public abstract void onCompletion(ContentTypesModel contentTypesModel, Error error);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import org.json.JSONArray;
44
import org.json.JSONObject;
55

6+
/**
7+
* The ContentTypesModel that contains content type response
8+
*/
69
public class ContentTypesModel {
710

811
private Object response;

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

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

77
public interface ContentstackPlugin {
88

9-
void onRequest(Stack stack, Request request);
9+
default void onRequest(Stack stack, Request request) {
10+
}
1011

11-
Response<ResponseBody> onResponse(Stack stack, Request request, Response response);
12+
default Response<ResponseBody> onResponse(Stack stack, Request request, Response<ResponseBody> response) {
13+
return response;
14+
}
1215
}

0 commit comments

Comments
 (0)