2
2
3
3
import org .jetbrains .annotations .NotNull ;
4
4
import org .json .JSONObject ;
5
-
5
+ import org .json .JSONArray ;
6
+ import lombok .Getter ;
7
+ import lombok .Setter ;
6
8
import java .util .HashMap ;
7
9
import java .util .Iterator ;
8
10
import java .util .LinkedHashMap ;
20
22
* @version 1.0.0
21
23
* @since 01-11-2017
22
24
*/
25
+
26
+ @ Getter
27
+ @ Setter
23
28
public class ContentType {
24
29
25
30
protected static final Logger logger = Logger .getLogger (ContentType .class .getSimpleName ());
26
31
protected String contentTypeUid ;
27
32
protected Stack stackInstance = null ;
28
33
protected LinkedHashMap <String , Object > headers = null ;
29
34
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
+
30
42
protected ContentType () throws IllegalAccessException {
31
43
throw new IllegalAccessException ("Can Not Access Private Modifier" );
32
44
}
@@ -156,7 +168,17 @@ private void fetchContentTypes(String urlString, JSONObject params, HashMap<Stri
156
168
if (callback != null ) {
157
169
HashMap <String , Object > urlParams = getUrlParams (params );
158
170
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
+ });
160
182
}
161
183
}
162
184
@@ -173,4 +195,20 @@ private HashMap<String, Object> getUrlParams(JSONObject urlQueriesJSON) {
173
195
return hashMap ;
174
196
}
175
197
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
+
176
214
}
0 commit comments