Skip to content

Commit 3382812

Browse files
v1.0.0 - Removed Support Of Marketplace
1 parent 7f7f39c commit 3382812

14 files changed

+697
-674
lines changed

src/main/java/com/contentstack/cms/BaseImplementation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ public interface BaseImplementation {
5959
* representing the header name and the value is a String
6060
* representing the header value.
6161
*/
62-
<T> void addHeaders(@NotNull HashMap<String, String> headers);
62+
<T> T addHeaders(@NotNull HashMap<String, String> headers);
6363
}

src/main/java/com/contentstack/cms/stack/Alias.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.util.HashMap;
1010
import java.util.Map;
11+
import java.util.Objects;
1112

1213
/**
1314
* An alias acts as a pointer to a particular branch. You can specify the alias
@@ -29,10 +30,6 @@ public class Alias {
2930
protected final AliasService service;
3031
private String uid;
3132

32-
void validate() {
33-
if (this.uid == null)
34-
throw new IllegalStateException("Global Field Uid can not be null or empty");
35-
}
3633

3734
// The `protected Alias(Retrofit instance)` constructor is used to create an
3835
// instance of the `Alias`
@@ -132,7 +129,7 @@ public Call<ResponseBody> find() {
132129
* @since 2022-10-20
133130
*/
134131
public Call<ResponseBody> fetch() {
135-
validate();
132+
Objects.requireNonNull(this.uid,"Global Field Uid can not be null or empty");
136133
return this.service.single(this.headers, this.uid);
137134
}
138135

@@ -183,7 +180,7 @@ public Call<ResponseBody> update(@NotNull JSONObject body) {
183180
* @since 2022-10-20
184181
*/
185182
public Call<ResponseBody> delete() {
186-
validate();
183+
Objects.requireNonNull(this.uid,"Global Field Uid can not be null or empty");
187184
return this.service.delete(this.headers, this.uid, this.params);
188185
}
189186

src/main/java/com/contentstack/cms/stack/Asset.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import retrofit2.Retrofit;
1111

1212
import java.io.File;
13+
import java.io.IOException;
14+
import java.net.URLConnection;
1315
import java.util.HashMap;
1416
import java.util.Map;
1517
import java.util.Objects;
@@ -47,10 +49,6 @@ protected Asset(Retrofit instance, Map<String, Object> header, String uid) {
4749
this.service = instance.create(AssetService.class);
4850
}
4951

50-
void validate() {
51-
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
52-
}
53-
5452

5553
public Asset addParam(String key, Object value) {
5654
this.params.put(key, value);
@@ -182,7 +180,7 @@ public Call<ResponseBody> find() {
182180
* @since 2022-10-20
183181
*/
184182
public Call<ResponseBody> fetch() {
185-
this.validate();
183+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
186184
return this.service.single(this.headers, this.assetUid, this.params);
187185
}
188186

@@ -366,13 +364,30 @@ private MultipartBody.Part createMultipartBody(String filePath, String parentUid
366364
* @since 2022-10-20
367365
*/
368366
public Call<ResponseBody> replace(@NotNull String filePath, @NotNull String description) {
369-
this.validate();
370-
MultipartBody.Part assetPath = createMultipartBody(filePath, null, null, null, null);
367+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
368+
MultipartBody.Part assetPath = uploadFile(filePath);
371369
RequestBody body = RequestBody.create(MediaType.parse(String.valueOf(MultipartBody.FORM)), description);
372370
return this.service.replace(this.headers, this.assetUid, assetPath, body, this.params);
373371
}
374372

375373

374+
private MultipartBody.Part uploadFile(@NotNull String filePath) {
375+
if (!filePath.isEmpty()) {
376+
File file = new File(filePath);
377+
URLConnection connection = null;
378+
try {
379+
connection = file.toURL().openConnection();
380+
} catch (IOException e) {
381+
throw new RuntimeException(e);
382+
}
383+
if (file.exists()) {
384+
RequestBody body = RequestBody.create(MediaType.parse(connection.getContentType()), file);
385+
return MultipartBody.Part.createFormData("asset[upload]", file.getName(), body);
386+
}
387+
}
388+
return null;
389+
}
390+
376391
/**
377392
* Generate Permanent Asset URL request allows you to generate a permanent URL
378393
* for an asset. This URL remains
@@ -402,7 +417,7 @@ public Call<ResponseBody> replace(@NotNull String filePath, @NotNull String desc
402417
* @since 2022-10-20
403418
*/
404419
public Call<ResponseBody> generatePermanentUrl(JSONObject body) {
405-
this.validate();
420+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
406421
return this.service.generatePermanentUrl(this.headers, this.assetUid, body);
407422
}
408423

@@ -432,7 +447,7 @@ public Call<ResponseBody> generatePermanentUrl(JSONObject body) {
432447
* @since 2022-10-20
433448
*/
434449
public Call<ResponseBody> getPermanentUrl(String slugUrl) {
435-
this.validate();
450+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
436451
return this.service.downloadPermanentUrl(this.headers, this.assetUid, slugUrl, this.params);
437452
}
438453

@@ -449,7 +464,7 @@ public Call<ResponseBody> getPermanentUrl(String slugUrl) {
449464
* @since 0.1.0
450465
*/
451466
public Call<ResponseBody> delete() {
452-
this.validate();
467+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
453468
return this.service.delete(this.headers, this.assetUid);
454469
}
455470

@@ -539,7 +554,7 @@ public Call<ResponseBody> setVersionName(int versionNumber,
539554
* @since 0.1.0
540555
*/
541556
public Call<ResponseBody> getVersionNameDetails() {
542-
this.validate();
557+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
543558
return this.service.getVersionNameDetails(this.headers, this.assetUid, this.params);
544559
}
545560

@@ -560,7 +575,7 @@ public Call<ResponseBody> getVersionNameDetails() {
560575
* @since 0.1.0
561576
*/
562577
public Call<ResponseBody> deleteVersionName(int versionNumber) {
563-
this.validate();
578+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
564579
return this.service.deleteVersionName(this.headers, this.assetUid, versionNumber);
565580
}
566581

@@ -577,7 +592,7 @@ public Call<ResponseBody> deleteVersionName(int versionNumber) {
577592
* @since 0.1.0
578593
*/
579594
public Call<ResponseBody> getReferences() {
580-
validate();
595+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
581596
return this.service.getReferences(this.headers, this.assetUid);
582597
}
583598

@@ -635,7 +650,7 @@ public Call<ResponseBody> getByType(@NotNull String assetType) {
635650
* @since 0.1.0
636651
*/
637652
public Call<ResponseBody> updateDetails(JSONObject requestBody) {
638-
validate();
653+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
639654
return this.service.updateDetails(this.headers, this.assetUid, this.params, requestBody);
640655
}
641656

@@ -661,7 +676,7 @@ public Call<ResponseBody> updateDetails(JSONObject requestBody) {
661676
* @since 0.1.0
662677
*/
663678
public Call<ResponseBody> publish(@NotNull JSONObject requestBody) {
664-
validate();
679+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
665680
return this.service.publish(this.headers, this.assetUid, requestBody);
666681
}
667682

@@ -687,7 +702,7 @@ public Call<ResponseBody> publish(@NotNull JSONObject requestBody) {
687702
*/
688703
public Call<ResponseBody> unpublish(
689704
@NotNull JSONObject requestBody) {
690-
this.validate();
705+
Objects.requireNonNull(this.assetUid, "Asset Uid Can Not Be Null OR Empty");
691706
return this.service.unpublish(this.headers, this.assetUid, requestBody);
692707
}
693708

src/main/java/com/contentstack/cms/stack/AuditLog.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import retrofit2.Retrofit;
77

88
import java.util.HashMap;
9+
import java.util.Objects;
910

1011
/**
1112
* Audit log displays a record of all the activities performed in a stack and
@@ -48,18 +49,11 @@ protected AuditLog(Retrofit retrofit, String uid) {
4849
this.service = retrofit.create(AuditLogService.class);
4950
}
5051

51-
void validate() {
52-
if (this.logItemUid == null || this.logItemUid.isEmpty())
53-
throw new IllegalStateException("LogItem Uid can not be null or empty");
54-
}
55-
5652
/**
5753
* Sets header for the request
5854
*
59-
* @param key
60-
* header key for the request
61-
* @param value
62-
* header value for the request
55+
* @param key header key for the request
56+
* @param value header value for the request
6357
*/
6458
public void addHeader(@NotNull String key, @NotNull Object value) {
6559
this.headers.put(key, value);
@@ -68,10 +62,8 @@ public void addHeader(@NotNull String key, @NotNull Object value) {
6862
/**
6963
* Sets header for the request
7064
*
71-
* @param key
72-
* header key for the request
73-
* @param value
74-
* header value for the request
65+
* @param key header key for the request
66+
* @param value header value for the request
7567
*/
7668
public void addParam(@NotNull String key, @NotNull Object value) {
7769
this.params.put(key, value);
@@ -80,8 +72,7 @@ public void addParam(@NotNull String key, @NotNull Object value) {
8072
/**
8173
* Sets header for the request
8274
*
83-
* @param key
84-
* header key for the request
75+
* @param key header key for the request
8576
*/
8677
public void removeParam(@NotNull String key) {
8778
this.params.remove(key);
@@ -113,7 +104,7 @@ public Call<ResponseBody> find() {
113104
* @return Call
114105
*/
115106
public Call<ResponseBody> fetch() {
116-
validate();
107+
Objects.requireNonNull(this.logItemUid, "Log Item uid can not be null or empty");
117108
return this.service.fetch(this.headers, this.logItemUid);
118109
}
119110

src/main/java/com/contentstack/cms/stack/Branch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ public Branch addParams(@NotNull HashMap params) {
114114
* @throws NullPointerException if the key or value argument is null
115115
*/
116116
@Override
117-
public void addHeaders(HashMap headers) {
117+
public Branch addHeaders(HashMap headers) {
118118
this.headers.putAll(headers);
119+
return this;
119120
}
120121

121122
/**

src/main/java/com/contentstack/cms/stack/BulkOperation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ public BulkOperation addParams(@NotNull HashMap params) {
253253
* @throws NullPointerException if the params argument is null
254254
*/
255255
@Override
256-
public void addHeaders(@NotNull HashMap headers) {
256+
public BulkOperation addHeaders(@NotNull HashMap headers) {
257257
this.headers.putAll(headers);
258+
return this;
258259
}
259260

260261
}

0 commit comments

Comments
 (0)