Skip to content

Commit 482f607

Browse files
committed
Add Lombok annotations and enhance data handling in models
1 parent 77020d5 commit 482f607

File tree

6 files changed

+79
-2
lines changed

6 files changed

+79
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.jetbrains.annotations.NotNull;
44
import org.json.JSONObject;
55
import retrofit2.Retrofit;
6+
import lombok.Getter;
7+
import lombok.Setter;
68

79
import java.util.Calendar;
810
import java.util.HashMap;
@@ -29,6 +31,8 @@
2931
* @version 1.0.0
3032
* @since 01-11-2017
3133
*/
34+
@Getter
35+
@Setter
3236
public class Asset {
3337

3438
protected static final Logger logger = Logger.getLogger(Asset.class.getSimpleName());

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
import java.util.LinkedHashMap;
44
import org.json.JSONArray;
55
import org.json.JSONObject;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
import lombok.NoArgsConstructor;
69

710

811
/**
912
* The type Asset model.
1013
*/
14+
@Getter
15+
@Setter
16+
@NoArgsConstructor
1117
class AssetModel {
1218

1319
String uploadedUid;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55

66
import org.json.JSONArray;
77
import org.json.JSONObject;
8+
import lombok.Getter;
9+
import lombok.Setter;
10+
import lombok.NoArgsConstructor;
811

912
/**
1013
* The type Assets model.
1114
*/
15+
@Getter
16+
@Setter
17+
@NoArgsConstructor
1218
class AssetsModel {
1319

1420
List<Object> objects = new ArrayList<>();

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import org.jetbrains.annotations.NotNull;
44
import org.json.JSONObject;
5-
5+
import org.json.JSONArray;
6+
import lombok.Getter;
7+
import lombok.Setter;
68
import java.util.HashMap;
79
import java.util.Iterator;
810
import java.util.LinkedHashMap;
@@ -20,13 +22,23 @@
2022
* @version 1.0.0
2123
* @since 01-11-2017
2224
*/
25+
26+
@Getter
27+
@Setter
2328
public class ContentType {
2429

2530
protected static final Logger logger = Logger.getLogger(ContentType.class.getSimpleName());
2631
protected String contentTypeUid;
2732
protected Stack stackInstance = null;
2833
protected LinkedHashMap<String, Object> headers = null;
2934

35+
// NEW: Content type data fields for POJO access (public for Lombok-generated getters)
36+
public String title;
37+
public String description;
38+
public String uid;
39+
public JSONArray schema;
40+
public JSONObject contentTypeData;
41+
3042
protected ContentType() throws IllegalAccessException {
3143
throw new IllegalAccessException("Can Not Access Private Modifier");
3244
}
@@ -156,7 +168,17 @@ private void fetchContentTypes(String urlString, JSONObject params, HashMap<Stri
156168
if (callback != null) {
157169
HashMap<String, Object> urlParams = getUrlParams(params);
158170
new CSBackgroundTask(this, stackInstance, Constants.FETCHCONTENTTYPES, urlString, headers, urlParams,
159-
Constants.REQUEST_CONTROLLER.CONTENTTYPES.toString(), callback);
171+
// Constants.REQUEST_CONTROLLER.CONTENTTYPES.toString(), callback);
172+
Constants.REQUEST_CONTROLLER.CONTENTTYPES.toString(), new ContentTypesCallback() {
173+
@Override
174+
public void onCompletion(ContentTypesModel model, Error error) {
175+
if (error == null) {
176+
// NEW: Store content type data in this instance for POJO access
177+
model.setContentTypeData(ContentType.this);
178+
}
179+
callback.onCompletion(model, error);
180+
}
181+
});
160182
}
161183
}
162184

@@ -173,4 +195,20 @@ private HashMap<String, Object> getUrlParams(JSONObject urlQueriesJSON) {
173195
return hashMap;
174196
}
175197

198+
/**
199+
* Set content type data from JSON response.
200+
* This method is called internally by ContentTypesModel.
201+
*
202+
* @param ctData the content type data JSONObject
203+
*/
204+
protected void setContentTypeData(JSONObject ctData) {
205+
if (ctData != null) {
206+
this.title = ctData.optString("title");
207+
this.description = ctData.optString("description");
208+
this.uid = ctData.optString("uid");
209+
this.schema = ctData.optJSONArray("schema");
210+
this.contentTypeData = ctData;
211+
}
212+
}
213+
176214
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
import java.util.List;
66
import org.json.JSONArray;
77
import org.json.JSONObject;
8+
import lombok.Getter;
9+
import lombok.Setter;
10+
import lombok.NoArgsConstructor;
811

912

1013

1114
/**
1215
* The ContentTypesModel that contains content type response
1316
*/
17+
@Getter
18+
@Setter
19+
@NoArgsConstructor
1420
public class ContentTypesModel {
1521

1622
private Object response;
@@ -58,4 +64,17 @@ public Object getResponse() {
5864
public JSONArray getResultArray() {
5965
return responseJSONArray;
6066
}
67+
68+
/**
69+
* Set content type data in the ContentType instance for POJO access.
70+
* This method is called internally after fetching content type data.
71+
*
72+
* @param contentType the ContentType instance to set data in
73+
*/
74+
public void setContentTypeData(ContentType contentType) {
75+
if (response instanceof JSONObject) {
76+
JSONObject ctData = (JSONObject) response;
77+
contentType.setContentTypeData(ctData);
78+
}
79+
}
6180
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
import java.util.Map;
55
import org.json.JSONArray;
66
import org.json.JSONObject;
7+
import lombok.Getter;
8+
import lombok.Setter;
79

810

11+
@Getter
12+
@Setter
913
class EntryModel {
1014

1115
private static final String PUBLISH_DETAIL_KEY = "publish_details";

0 commit comments

Comments
 (0)