Skip to content

Commit 13ab719

Browse files
Taxonomy and Terms
1 parent 0472bc3 commit 13ab719

35 files changed

+2003
-567
lines changed

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<artifactId>cms</artifactId>
88
<packaging>jar</packaging>
99
<name>contentstack-management-java</name>
10-
<version>1.0.0</version>
10+
<version>1.1.0</version>
1111
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
1212
API-first approach
1313
</description>
@@ -165,6 +165,12 @@
165165
<version>${junit-vintage-engine.version}</version>
166166
<scope>test</scope>
167167
</dependency>
168+
<dependency>
169+
<groupId>org.mockito</groupId>
170+
<artifactId>mockito-core</artifactId>
171+
<version>2.8.9</version>
172+
<scope>test</scope>
173+
</dependency>
168174
<dependency>
169175
<groupId>com.googlecode.json-simple</groupId>
170176
<artifactId>json-simple</artifactId>
@@ -328,6 +334,7 @@
328334
<plugin>
329335
<groupId>org.apache.maven.plugins</groupId>
330336
<artifactId>maven-pdf-plugin</artifactId>
337+
<version>1.6.1</version>
331338
<executions>
332339
<execution>
333340
<id>pdf</id>

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
/**
88
* The interface @{@link BaseImplementation}
99
*/
10-
public interface BaseImplementation {
10+
public interface BaseImplementation<T> {
1111

1212
/**
1313
* The function adds a parameter to a collection using a key-value pair.
1414
*
15-
* @param <T> the type of the parameter
1615
* @param key A string representing the key of the parameter. It cannot be
1716
* null and must be
1817
* provided as a non-null value.
@@ -21,12 +20,11 @@ public interface BaseImplementation {
2120
* object as its value.
2221
* @return The method is returning an object of type T.
2322
*/
24-
<T> T addParam(@NotNull String key, @NotNull Object value);
23+
T addParam(@NotNull String key, @NotNull Object value);
2524

2625
/**
2726
* The function adds a header with a key-value pair to a request.
2827
*
29-
* @param <T> the type of the parameter
3028
* @param key The key parameter is a string that represents the name or
3129
* identifier of the header.
3230
* It is used to specify the type of information being sent in the
@@ -35,30 +33,28 @@ public interface BaseImplementation {
3533
* header.
3634
* @return The method is returning an object of type T.
3735
*/
38-
<T> T addHeader(@NotNull String key, @NotNull String value);
36+
T addHeader(@NotNull String key, @NotNull String value);
3937

4038
/**
4139
* The function "addParams" takes a HashMap of String keys and Object values as
4240
* input and returns a
4341
* generic type T.
4442
*
45-
* @param <T> the type of the parameter
4643
* @param params The "params" parameter is a HashMap that maps String keys to
4744
* Object values. It is
4845
* annotated with @NotNull, indicating that it cannot be null.
4946
* @return The method is returning an object of type T.
5047
*/
51-
<T> T addParams(@NotNull HashMap<String, Object> params);
48+
T addParams(@NotNull HashMap<String, Object> params);
5249

5350
/**
5451
* The function adds headers to a HashMap.
5552
*
56-
* @param <T> the type of the parameter
5753
* @param headers A HashMap containing key-value pairs of headers, where the key
5854
* is a String
5955
* representing the header name and the value is a String
6056
* representing the header value.
6157
* @return The method is returning an object of type T.
6258
*/
63-
<T> T addHeaders(@NotNull HashMap<String, String> headers);
59+
T addHeaders(@NotNull HashMap<String, String> headers);
6460
}

src/main/java/com/contentstack/cms/core/CMARuntimeException.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
* @since 2022-10-20
99
*/
1010
public class CMARuntimeException extends Exception {
11-
// The code `public CMARuntimeException(String message) { super(message); }` is
12-
// defining a constructor
13-
// for the `CMARuntimeException` class.
11+
12+
/**
13+
* The code `public CMARuntimeException(String message) { super(message); }` is
14+
* defining a constructor
15+
* for the `CMARuntimeException` class.
16+
*
17+
* @param message the message for exception
18+
*/
1419
public CMARuntimeException(String message) {
1520
super(message);
1621
}

src/main/java/com/contentstack/cms/organization/Organization.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.contentstack.cms.organization;
22

3+
import com.contentstack.cms.BaseImplementation;
34
import okhttp3.ResponseBody;
45
import org.jetbrains.annotations.NotNull;
56
import org.json.simple.JSONObject;
@@ -19,7 +20,7 @@
1920
* @version v0.1.0
2021
* @since 2022-10-20
2122
*/
22-
public class Organization {
23+
public class Organization implements BaseImplementation<Organization> {
2324

2425
private final OrganizationService service;
2526
protected HashMap<String, String> headers;
@@ -65,6 +66,18 @@ public Organization addHeader(@NotNull String key, @NotNull String value) {
6566
return this;
6667
}
6768

69+
@Override
70+
public Organization addParams(@NotNull HashMap<String, Object> params) {
71+
this.params.putAll(params);
72+
return this;
73+
}
74+
75+
@Override
76+
public Organization addHeaders(@NotNull HashMap<String, String> headers) {
77+
this.headers.putAll(headers);
78+
return this;
79+
}
80+
6881
/**
6982
* Sets header for the request
7083
*
@@ -89,17 +102,6 @@ protected Organization clearParams() {
89102
return this;
90103
}
91104

92-
/**
93-
* Sets header for the request
94-
*
95-
* @param key header key for the request
96-
* @return instance of {@link Organization}
97-
*/
98-
public Organization removeParam(@NotNull String key) {
99-
this.params.remove(key);
100-
return this;
101-
}
102-
103105
/**
104106
* <b>Gets all organizations.</b><br>
105107
* The <b>Get all organizations</b> call lists all organizations related to the

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

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.contentstack.cms.stack;
22

3+
import com.contentstack.cms.BaseImplementation;
34
import okhttp3.ResponseBody;
45
import org.jetbrains.annotations.NotNull;
56
import org.json.simple.JSONObject;
@@ -18,12 +19,12 @@
1819
* @author ***REMOVED***
1920
* @version v0.1.0
2021
* @see <a href=
21-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#aliases">About
22-
* Aliases
23-
* </a>
22+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#aliases">About
23+
* Aliases
24+
* </a>
2425
* @since 2022-10-20
2526
*/
26-
public class Alias {
27+
public class Alias implements BaseImplementation<Alias> {
2728

2829
protected final Map<String, Object> headers;
2930
protected Map<String, Object> params;
@@ -57,36 +58,70 @@ protected Alias(Retrofit instance, String aliasUid) {
5758

5859
/**
5960
* The addHeader function adds a key-value pair to the headers map.
60-
*
61+
*
6162
* @param key A string representing the key of the header. This is used to
6263
* identify the header when
6364
* retrieving or modifying it.
6465
* @param value The value parameter is of type Object, which means it can accept
6566
* any type of object as
6667
* its value.
68+
* @return instance of the `Alias` class
6769
*/
68-
public void addHeader(@NotNull String key, @NotNull Object value) {
70+
@Override
71+
public Alias addHeader(@NotNull String key, @NotNull String value) {
6972
this.headers.put(key, value);
73+
return this;
7074
}
7175

7276
/**
7377
* The addParam function adds a key-value pair to a map.
74-
*
78+
*
7579
* @param key A string representing the key for the parameter. It is annotated
7680
* with @NotNull,
7781
* indicating that it cannot be null.
7882
* @param value The value parameter is of type Object, which means it can accept
7983
* any type of object as
8084
* its value.
8185
*/
82-
public void addParam(@NotNull String key, @NotNull Object value) {
86+
@Override
87+
public Alias addParam(@NotNull String key, @NotNull Object value) {
8388
this.params.put(key, value);
89+
return this;
90+
}
91+
92+
/**
93+
* The addParam function adds a key-value pair to Alias
94+
*
95+
* @param params The "params" parameter is a HashMap that maps String keys to
96+
* Object values. It is
97+
* annotated with @NotNull, indicating that it cannot be null.
98+
* @return instance of {@link Alias}
99+
*/
100+
@Override
101+
public Alias addParams(@NotNull HashMap<String, Object> params) {
102+
this.params.putAll(params);
103+
return this;
104+
}
105+
106+
/**
107+
* The removeParam function removes a key-value pair from
108+
*
109+
* @param headers A HashMap containing key-value pairs of headers, where the key
110+
* is a String
111+
* representing the header name and the value is a String
112+
* representing the header value.
113+
* @return instance of Alias
114+
*/
115+
@Override
116+
public Alias addHeaders(@NotNull HashMap<String, String> headers) {
117+
this.headers.putAll(headers);
118+
return this;
84119
}
85120

86121
/**
87122
* The removeParam function removes a parameter from a map using the specified
88123
* key.
89-
*
124+
*
90125
* @param key The parameter "key" is of type String and is used to specify the
91126
* key of the parameter
92127
* that needs to be removed from the "params" collection.
@@ -107,9 +142,9 @@ protected void clearParams() {
107142
* @return Call
108143
* @author ***REMOVED***
109144
* @see <a href=
110-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-aliases">Get
111-
* all
112-
* aliases</a>
145+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-aliases">Get
146+
* all
147+
* aliases</a>
113148
* @since 2022-10-20
114149
*/
115150
public Call<ResponseBody> find() {
@@ -122,12 +157,12 @@ public Call<ResponseBody> find() {
122157
* @return Call
123158
* @author ***REMOVED***
124159
* @see <a href=
125-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-a-single-branch">
126-
* Get a single branch</a>
160+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-a-single-branch">
161+
* Get a single branch</a>
127162
* @since 2022-10-20
128163
*/
129164
public Call<ResponseBody> fetch() {
130-
Objects.requireNonNull(this.uid,"Global Field Uid can not be null or empty");
165+
Objects.requireNonNull(this.uid, "Global Field Uid can not be null or empty");
131166
return this.service.single(this.headers, this.uid);
132167
}
133168

@@ -142,15 +177,14 @@ public Call<ResponseBody> fetch() {
142177
* “Body” section, you need to provide
143178
* the UID of the new target branch that will be associated with the alias.
144179
*
145-
* @param body
146-
* the request body
180+
* @param body the request body
147181
* @return Call
148182
* @author ***REMOVED***
149183
* @see <a href=
150-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#assign-or-update-an-alias">Update
151-
* a
152-
* branch</a>
153-
* @see #addHeader(String, Object) to add headers
184+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#assign-or-update-an-alias">Update
185+
* a
186+
* branch</a>
187+
* @see #addHeader(String, String) to add headers
154188
* @since 2022-10-20
155189
*/
156190
public Call<ResponseBody> update(@NotNull JSONObject body) {
@@ -169,14 +203,14 @@ public Call<ResponseBody> update(@NotNull JSONObject body) {
169203
* @return Call
170204
* @author ***REMOVED***
171205
* @see <a href=
172-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-an-alias">Delete
173-
* a branch</a>
174-
* @see #addHeader(String, Object) to add headers
206+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-an-alias">Delete
207+
* a branch</a>
208+
* @see #addHeader(String, String) to add headers
175209
* @see #addParam(String, Object) to add query params
176210
* @since 2022-10-20
177211
*/
178212
public Call<ResponseBody> delete() {
179-
Objects.requireNonNull(this.uid,"Global Field Uid can not be null or empty");
213+
Objects.requireNonNull(this.uid, "Global Field Uid can not be null or empty");
180214
return this.service.delete(this.headers, this.uid, this.params);
181215
}
182216

0 commit comments

Comments
 (0)