-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAssetModel.java
More file actions
75 lines (66 loc) · 1.93 KB
/
AssetModel.java
File metadata and controls
75 lines (66 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.contentstack.sdk;
import java.util.LinkedHashMap;
import org.json.JSONArray;
import org.json.JSONObject;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
/**
* The type Asset model.
*/
@Getter
@Setter
@NoArgsConstructor
class AssetModel {
String uploadedUid;
String contentType;
String fileSize;
String fileName;
String uploadUrl;
String[] tags;
JSONObject json;
int count = 0;
int totalCount = 0;
/**
* Instantiates a new Asset model.
*
* @param response the response
* @param isArray the is array
*/
public AssetModel(JSONObject response, boolean isArray) {
if (isArray) {
json = response;
} else {
json = new JSONObject((LinkedHashMap<?, ?>) response.get("asset"));
}
if (json != null) {
uploadedUid = (String) json.opt("uid");
contentType = (String) json.opt("content_type");
fileSize = (String) json.opt("file_size");
fileName = (String) json.opt("filename");
uploadUrl = (String) json.opt("url");
if (json.opt("tags") instanceof JSONArray) {
extractTags();
}
if (response.has("count")) {
count = response.optInt("count");
}
if (response.has("objects")) {
totalCount = response.optInt("objects");
}
}
}
private void extractTags() {
JSONArray tagArray = json.optJSONArray("tags");
if (tagArray != null && !tagArray.isEmpty()) {
JSONArray tagsArray = (JSONArray) json.opt("tags");
if (tagsArray.length() > 0) {
int counter = tagsArray.length();
tags = new String[counter];
for (int i = 0; i < counter; i++) {
tags[i] = (String) tagsArray.opt(i);
}
}
}
}
}