Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<lombok-source.version>1.18.36</lombok-source.version>
<junit-jupiter.version>5.11.4</junit-jupiter.version>
<junit-jupiter-engine.version>5.10.1</junit-jupiter-engine.version>
<gson.version>2.11.0</gson.version>
<gson.version>2.12.1</gson.version>
<maven-site-plugin.version>3.3</maven-site-plugin.version>
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
Expand Down Expand Up @@ -149,7 +149,7 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>25.0.0</version>
<version>26.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -208,12 +208,12 @@
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.18.3</version>
<version>1.19.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>2.1.0</version>
<version>2.1.10</version>
</dependency>
</dependencies>

Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/contentstack/cms/stack/Asset.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected Asset(Retrofit instance, Map<String, Object> header, String uid) {
* object as its value.
* @return instance of Asset
*/
@Override
public Asset addParam(@NotNull String key, @NotNull Object value) {
this.params.put(key, value);
return this;
Expand All @@ -74,6 +75,7 @@ public Asset addParam(@NotNull String key, @NotNull Object value) {
* header.
* @return instance of Asset
*/
@Override
public Asset addHeader(@NotNull String key, @NotNull String value) {
this.headers.put(key, value);
return this;
Expand All @@ -86,6 +88,7 @@ public Asset addHeader(@NotNull String key, @NotNull String value) {
* representing the header value.
* @return instance of Asset
*/
@Override
public Asset addHeaders(@NotNull HashMap<String, String> headers) {
this.headers.putAll(headers);
return this;
Expand All @@ -98,6 +101,7 @@ public Asset addHeaders(@NotNull HashMap<String, String> headers) {
* annotated with @NotNull, indicating that it cannot be null.
* @return instance of Asset
*/
@Override
public Asset addParams(@NotNull HashMap<String, Object> headers) {
this.params.putAll(headers);
return this;
Expand Down Expand Up @@ -198,6 +202,10 @@ public Call<ResponseBody> find() {
return this.service.fetch(this.headers, this.params);
}

public Call<AssetListResponse> findAsPojo() {
return this.service.fetchPojo(this.headers, this.params);
}

/**
* The Get an asset call returns comprehensive information about a specific
* version of an asset of a stack
Expand All @@ -221,6 +229,11 @@ public Call<ResponseBody> fetch() {
return this.service.single(this.headers, this.assetUid, this.params);
}

public Call<AssetResponse> fetchAsPojo() { // New method for POJO conversion
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
return this.service.singlePojo(this.headers, this.assetUid, this.params);
}

/**
* The Get assets of a specific folder retrieves all assets of a specific asset
* folder; however, it doesn't retrieve
Expand All @@ -241,6 +254,11 @@ public Call<ResponseBody> byFolderUid(@NotNull String folderUid) {
return this.service.specificFolder(this.headers, this.params);
}

public Call<AssetListResponse> byFolderUidAsPojo(@NotNull String folderUid) {
this.params.put("folder", folderUid);
return this.service.specificFolderPojo(this.headers, this.params);
}

/**
* The Get assets and folders of a parent folder retrieves details of both
* assets and asset sub-folders within a
Expand All @@ -264,6 +282,13 @@ public Call<ResponseBody> subfolder(
return this.service.subfolder(this.headers, this.params);
}

public Call<AssetListResponse> subfolderAsPojo(
@NotNull String folderUid, Boolean isIncludeFolders) {
this.params.put("folder", folderUid);
this.params.put("include_folders", isIncludeFolders);
return this.service.subfolderPojo(this.headers, this.params);
}

/**
* The <b>Upload asset</b> request uploads an asset file to your stack.
* <p>
Expand Down Expand Up @@ -731,6 +756,10 @@ public Call<ResponseBody> getSingleFolderByName() {
return this.service.singleFolderByName(this.headers, this.params);
}

public Call<AssetListResponse> getSingleFolderByNameAsPojo() {
return this.service.singleFolderByNamePojo(this.headers, this.params);
}

/**
* Get sub-folders of a parent folder request retrieves the details of only the
* sub-folders of a specific asset
Expand All @@ -750,6 +779,10 @@ public Call<ResponseBody> getSubfolder() {
return this.service.getSubfolder(this.headers, this.params);
}

public Call<AssetListResponse> getSubfolderAsPojo() {
return this.service.getSubfolderPojo(this.headers, this.params);
}

protected Asset removeParam(String key) {
this.params.remove(key);
return this;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/contentstack/cms/stack/AssetListResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.contentstack.cms.stack;

import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;

public class AssetListResponse {

@SerializedName("assets")
private List<Map<String, Object>> rawJson;

private transient List<AssetPojo> assets;

public List<AssetPojo> getAssets() {
if (assets == null && rawJson != null) {
assets = new Gson().fromJson(new Gson().toJsonTree(rawJson), new TypeToken<List<AssetPojo>>(){}.getType());
}
return assets;
}

public List<Map<String, Object>> getRawJson() {
return rawJson;
}

@Override
public String toString() {
return new com.google.gson.GsonBuilder().setPrettyPrinting().create().toJson(this);
}
}
47 changes: 47 additions & 0 deletions src/main/java/com/contentstack/cms/stack/AssetPojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.contentstack.cms.stack;
import com.google.gson.annotations.SerializedName;

public class AssetPojo {

@SerializedName("uid")
protected String uid;

@SerializedName("title")
protected String title;

@SerializedName("content_type")
protected String contentType;

@SerializedName("file_size")
protected String fileSize;

@SerializedName("filename")
protected String filename;

@SerializedName("url")
protected String url;

@SerializedName("description")
protected String description;

@SerializedName("_version")
protected int version;

@SerializedName("is_dir")
protected boolean isDir;

@SerializedName("tags")
protected String[] tags;

@SerializedName("name")
protected String name;

// Getters
public String getTitle() {
if (contentType.equals("application/vnd.contenstack.folder")) {
return name;
}
return title; }

}

27 changes: 27 additions & 0 deletions src/main/java/com/contentstack/cms/stack/AssetResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.contentstack.cms.stack;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import java.util.Map;

public class AssetResponse {
@SerializedName("asset")
private Map<String, Object> rawJson; // Store the full asset JSON

private AssetPojo assetPojo;

public AssetPojo getAssetPojo() {
if (assetPojo == null && rawJson != null) {
assetPojo = new Gson().fromJson(new Gson().toJson(rawJson), AssetPojo.class);
}
return assetPojo;
}
public Map<String, Object> getRawJson() {
return rawJson;
}
@Override
public String toString() {
return new com.google.gson.GsonBuilder().setPrettyPrinting().create().toJson(this);
}
}


39 changes: 38 additions & 1 deletion src/main/java/com/contentstack/cms/stack/AssetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,44 @@ public interface AssetService {
Call<ResponseBody> fetch(
@HeaderMap Map<String, Object> headers,
@QueryMap(encoded = true) Map<String, Object> query);

@GET("assets")
Call<AssetListResponse> fetchPojo(
@HeaderMap Map<String, Object> headers,
@QueryMap(encoded = true) Map<String, Object> query);

@GET("assets/{asset_uid}")
Call<ResponseBody> single(
@HeaderMap Map<String, Object> headers,
@Path("asset_uid") String uid,
@QueryMap(encoded = true) Map<String, Object> query);

@GET("assets/{asset_uid}")
Call<AssetResponse> singlePojo(
@HeaderMap Map<String, Object> headers,
@Path("asset_uid") String assetUid,
@QueryMap(encoded = true) Map<String, Object> params);

@GET("assets")
Call<ResponseBody> specificFolder(
@HeaderMap Map<String, Object> headers,
@QueryMap(encoded = true) Map<String, Object> query);

@GET("assets")
Call<AssetListResponse> specificFolderPojo(
@HeaderMap Map<String, Object> headers,
@QueryMap(encoded = true) Map<String, Object> query);

@GET("assets")
Call<ResponseBody> subfolder(
@HeaderMap Map<String, Object> headers,
@QueryMap(encoded = true) Map<String, Object> query);

@GET("assets")
Call<AssetListResponse> subfolderPojo(
@HeaderMap Map<String, Object> headers,
@QueryMap(encoded = true) Map<String, Object> query);

@POST("assets")
Call<ResponseBody> uploadAsset(
@HeaderMap Map<String, Object> headers,
Expand Down Expand Up @@ -88,7 +109,7 @@ Call<ResponseBody> deleteVersionName(
@HeaderMap Map<String, Object> headers,
@Path("asset_uid") String assetUid,
@Path("version_number") int versionNumber);

// check this if possible to support
@GET("assets/{asset_uid}/references")
Call<ResponseBody> getReferences(
@HeaderMap Map<String, Object> headers,
Expand Down Expand Up @@ -124,16 +145,32 @@ Call<ResponseBody> singleFolder(
@Path("folder_uid") String folderUid,
@QueryMap Map<String, Object> query);

@GET("assets/folders/{folder_uid}")
Call<AssetResponse> singleFolderPojo(
@HeaderMap Map<String, Object> headers,
@Path("folder_uid") String folderUid,
@QueryMap Map<String, Object> query);

@GET("assets")
Call<ResponseBody> singleFolderByName(
@HeaderMap Map<String, Object> headers,
@QueryMap(encoded = true) Map<String, Object> query);

@GET("assets")
Call<AssetListResponse> singleFolderByNamePojo(
@HeaderMap Map<String, Object> headers,
@QueryMap(encoded = true) Map<String, Object> query);

@GET("assets")
Call<ResponseBody> getSubfolder(
@HeaderMap Map<String, Object> headers,
@QueryMap(encoded = true) Map<String, Object> query);

@GET("assets")
Call<AssetListResponse> getSubfolderPojo(
@HeaderMap Map<String, Object> headers,
@QueryMap(encoded = true) Map<String, Object> query);

@POST("assets/folders")
Call<ResponseBody> createFolder(
@HeaderMap Map<String, Object> headers,
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/contentstack/cms/stack/ContentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ public Entry entry(@NotNull String entryUid) {
public Call<ResponseBody> find() {
return service.fetch(this.headers, this.params);
}

public Call<ContentTypesResponse> findAsPojo() {
return service.fetchPojo(this.headers, this.params);
}

/**
* <b>Get Single Content Type</b>
Expand Down Expand Up @@ -248,6 +252,11 @@ public Call<ResponseBody> fetch() {
return service.single(this.headers, this.contentTypeUid, this.params);
}

public Call<ContentTypeResponse> fetchAsPojo() {
Objects.requireNonNull(this.contentTypeUid, "Content Type Uid Is Required");
return service.singlePojo(this.headers, this.contentTypeUid, this.params);
}

/**
* <b>Create Content Type</b>
* <p>
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/contentstack/cms/stack/ContentTypePojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.contentstack.cms.stack;
import java.util.Map;
import org.json.simple.JSONArray;
import com.google.gson.annotations.SerializedName;

public class ContentTypePojo {

@SerializedName("title")
protected String title;

@SerializedName("uid")
protected String uid;

@SerializedName("schema")
protected JSONArray schema;

@SerializedName("field_rules")
protected JSONArray fieldRules;

@SerializedName("_version")
protected int version;

@SerializedName("description")
protected String description;

@SerializedName("options")
protected Map<String, Object> options;

}
Loading