Skip to content

Commit 12af137

Browse files
[CS-36689] compare merge branch
1 parent 339c877 commit 12af137

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3585
-1225
lines changed

README.md

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22

33
## Contentstack Management Java SDK
44

5-
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. All you have to do is build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
6-
7-
This SDK uses the [Content Management API](https://www.contentstack.com/docs/developers/apis/content-management-api/) (CMA). The CMA is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account. To use the CMA, you will need to authenticate your users with a [Management Token](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens) or an [Authtoken](https://www.contentstack.com/docs/developers/apis/content-management-api/#how-to-get-authtoken). Read more about it in [Authentication](https://www.contentstack.com/docs/developers/apis/content-management-api/#authentication).
8-
9-
Note: By using CMA, you can execute GET requests for fetching content. However, we strongly recommend that you always use the [Content Delivery API](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) to deliver content to your web or mobile properties.
5+
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful
6+
cross-platform applications in their favorite languages. All you have to do is build your application frontend, and
7+
Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
8+
9+
This SDK uses the [Content Management API](https://www.contentstack.com/docs/developers/apis/content-management-api/) (
10+
CMA). The CMA is used to manage the content of your Contentstack account. This includes creating, updating, deleting,
11+
and fetching content of your account. To use the CMA, you will need to authenticate your users with
12+
a [Management Token](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens) or
13+
an [Authtoken](https://www.contentstack.com/docs/developers/apis/content-management-api/#how-to-get-authtoken). Read
14+
more about it
15+
in [Authentication](https://www.contentstack.com/docs/developers/apis/content-management-api/#authentication).
16+
17+
Note: By using CMA, you can execute GET requests for fetching content. However, we strongly recommend that you always
18+
use the [Content Delivery API](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) to deliver
19+
content to your web or mobile properties.
1020

1121
### Prerequisite
1222

@@ -18,54 +28,56 @@ Install it via maven:
1828

1929
```java
2030
<dependency>
21-
<groupId>com.contentstack.sdk</groupId>
22-
<artifactId>cms</artifactId>
23-
<version>{version}</version>
31+
<groupId>com.contentstack.sdk</groupId>
32+
<artifactId>cms</artifactId>
33+
<version>{version}</version>
2434
</dependency>
2535
```
2636

2737
Install it via gradle:
2838

2939
```java
30-
implementation 'com.contentstack.sdk:cms:{version}'
40+
implementation'com.contentstack.sdk:cms:{version}'
3141
```
3242

3343
To import the SDK, use the following command:
3444

3545
```java
36-
package com.contentstack.cms;
37-
38-
Contentstack contentstack = new Contentstack.Builder().build();
46+
package com.contentstack.cms;
47+
Contentstack contentstack=new Contentstack.Builder().build();
3948
```
4049

4150
### Authentication
4251

43-
To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (stack-level token).
52+
To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (
53+
stack-level token).
4454

4555
### Authtoken
4656

47-
An [Authtoken](https://www.contentstack.com/docs/developers/create-tokens/types-of-tokens/#authentication-tokens-authtokens-) is a read-write token used to make authorized CMA requests, and it is a **user-specific** token.
57+
An [Authtoken](https://www.contentstack.com/docs/developers/create-tokens/types-of-tokens/#authentication-tokens-authtokens-)
58+
is a read-write token used to make authorized CMA requests, and it is a **user-specific** token.
4859

4960
```java
50-
Contentstack contentstack = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
61+
Contentstack contentstack=new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
5162
```
5263

5364
### Login
5465

5566
To Login to Contentstack by using credentials, you can use the following lines of code:
5667

5768
```java
58-
Contentstack contentstack = new Contentstack.Builder().build();
59-
contentstack.login("EMAIL", "PASSWORD");
69+
Contentstack contentstack=new Contentstack.Builder().build();
70+
contentstack.login("EMAIL","PASSWORD");
6071
```
6172

6273
### Management Token
6374

64-
[Management Tokens](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens/) are **stack-level** tokens, with no users attached to them.
75+
[Management Tokens](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens/) are *
76+
*stack-level** tokens, with no users attached to them.
6577

6678
```java
67-
Contentstack contentstack = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
68-
Stack stack = contentstack.stack("API_KEY", "MANAGEMENT_TOKEN");
79+
Contentstack contentstack=new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
80+
Stack stack=contentstack.stack("API_KEY","MANAGEMENT_TOKEN");
6981
```
7082

7183
### Contentstack Management Java SDK: 5-minute Quickstart
@@ -75,46 +87,46 @@ Stack stack = contentstack.stack("API_KEY", "MANAGEMENT_TOKEN");
7587
To use the Java CMA SDK, you need to first initialize it. To do this, use the following code:
7688

7789
```java
78-
Contentstack contentstack = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
90+
Contentstack contentstack=new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
7991
```
8092

8193
#### Fetch Stack Detail
8294

8395
Use the following lines of code to fetch your stack detail using this SDK:
8496

8597
```java
86-
Stack stack = contentstack.stack("API_KEY");
87-
Response<ResponseBody> response = stack.fetch().execute();
98+
Stack stack=contentstack.stack("API_KEY");
99+
Response<ResponseBody> response=stack.fetch().execute();
88100
```
89101

90102
#### Create Entry
91103

92104
To create an entry in a specific content type of a stack, use the following lines of code:
93105

94106
```java
95-
Contentstack contentstack = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
96-
Stack stack = contentstack.stack("API_KEY");
97-
JSONObject body = ....
98-
Response<ResponseBody> response = entry.create(body).execute();
99-
if (response.isSuccessful()){
100-
System.out.println(response.body());
101-
}
107+
Contentstack contentstack=new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
108+
Stack stack=contentstack.stack("API_KEY");
109+
JSONObject body=....
110+
Response<ResponseBody> response=entry.create(body).execute();
111+
if(response.isSuccessful()){
112+
System.out.println(response.body());
113+
}
102114
```
103115

104116
#### Create Asset
105117

106118
The following lines of code can be used to upload assets to your stack:
107119

108120
```java
109-
Contentstack contentstack = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
110-
Stack stack = contentstack.stack("API_KEY");
111-
Asset asset = stack.asset();
112-
Response<ResponseBody> response = asset.uploadAsset("filePath", "description").execute();
113-
if (response.isSuccessful()){
114-
System.out.println(response.body());
115-
}else {
116-
System.out.println(response.errorBody());
117-
}
121+
Contentstack contentstack=new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
122+
Stack stack=contentstack.stack("API_KEY");
123+
Asset asset=stack.asset();
124+
Response<ResponseBody> response=asset.uploadAsset("filePath","description").execute();
125+
if(response.isSuccessful()){
126+
System.out.println(response.body());
127+
}else{
128+
System.out.println(response.errorBody());
129+
}
118130
```
119131

120132
### Helpful Links
@@ -127,8 +139,14 @@ if (response.isSuccessful()){
127139

128140
Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved
129141

130-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
131-
132-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
133-
134-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
142+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
143+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
144+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
145+
persons to whom the Software is furnished to do so, subject to the following conditions:
146+
147+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
148+
Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
149+
TO THE
150+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
151+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
152+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

changelog.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
## v1.0.0
44

5-
### 30-APR-2023
5+
### 30-June-2023
66

7-
- Added support for marketplace API
7+
- Bug Fixed For Unlocalize An Entry
88
- General improvements
9-
- code coverage improvements
10-
- code quality improvements
9+
- Code coverage improvements
10+
- Code quality improvements
11+
- Fixed Timeout Issue
1112

1213
## v0.1.0
1314

15+
### Initial Release
16+
1417
### 20-OCT-2022
1518

1619
Initial release for Contentstack CMA base Java management SDK

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<artifactId>cms</artifactId>
77
<packaging>jar</packaging>
88
<name>contentstack-management-java</name>
9-
<version>1.0.0</version>
9+
<version>1.0.0-SNAPSHOT</version>
1010
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
1111
API-first approach
1212
</description>
1313
<url>https://github.com/contentstack/contentstack-management-java/</url>
1414

15-
<!-- release the package using mvn clean deploy -->
15+
<!-- Release the package using mvn clean deploy -->
1616
<parent>
1717
<groupId>org.sonatype.oss</groupId>
1818
<artifactId>oss-parent</artifactId>
@@ -97,6 +97,7 @@
9797
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
9898
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
9999
</properties>
100+
100101
<dependencies>
101102
<dependency>
102103
<groupId>com.google.code.gson</groupId>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.net.Proxy;
21+
import java.time.Duration;
2122
import java.util.HashMap;
2223
import java.util.Map;
2324
import java.util.logging.Logger;
@@ -447,6 +448,7 @@ public static class Builder {
447448
*/
448449
protected Proxy proxy;
449450
private AuthInterceptor authInterceptor;
451+
450452
private String authtoken; // authtoken for client
451453
private Retrofit instance; // client instance
452454
private String hostname = Util.HOST; // Default Host for Contentstack API (default: api.contentstack.io)
@@ -554,6 +556,7 @@ public Builder setAuthtoken(String authtoken) {
554556
return this;
555557
}
556558

559+
557560
/**
558561
* Build contentstack.
559562
*
@@ -578,6 +581,7 @@ private OkHttpClient httpClient(Contentstack contentstack, Boolean retryOnFailur
578581
return new OkHttpClient.Builder().addInterceptor(this.authInterceptor)
579582
.addInterceptor(logger())
580583
.proxy(this.proxy)
584+
.connectTimeout(Duration.ofSeconds(this.timeout))
581585
.retryOnConnectionFailure(retryOnFailure)
582586
.build();
583587
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface Parametron {
2121
* the value
2222
* @return the t
2323
*/
24-
public <T> T addParam(@NotNull String key, @NotNull String value);
24+
public <T> T addParam(@NotNull String key, @NotNull Object value);
2525

2626
/**
2727
* Add header t.
@@ -46,7 +46,7 @@ public interface Parametron {
4646
* the params
4747
* @return the t
4848
*/
49-
public <T> T addParams(@NotNull HashMap params);
49+
public <T> T addParams(@NotNull HashMap<String, Object> params);
5050

5151

5252
/**
@@ -58,5 +58,5 @@ public interface Parametron {
5858
* the headers
5959
* @return the t
6060
*/
61-
public <T> T addHeaders(@NotNull HashMap headers);
61+
public <T> T addHeaders(@NotNull HashMap<String, String> headers);
6262
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void setAuthtoken(String authtoken) {
3636
@NotNull
3737
@Override
3838
public Response intercept(Chain chain) throws IOException {
39-
final String xUserAgent = Util.SDK_NAME + "/" + Util.SDK_VERSION;
39+
final String xUserAgent = Util.SDK_NAME + "/v" + Util.SDK_VERSION;
4040
Request.Builder request = chain.request().newBuilder()
4141
.header(Util.X_USER_AGENT, xUserAgent)
4242
.header(Util.USER_AGENT, Util.defaultUserAgent())

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public class Util {
4242
public static final String MULTIPART = "multipart/form-data";
4343
public static final String CONTENT_TYPE_VALUE = "application/json";
4444

45+
// Error Messages
46+
public static final String MISSING_INSTALLATION_ID = "installation uid is required";
47+
public static final String ERROR_INSTALLATION = "installation uid is required";
48+
public static final String MISSING_ORG_ID = "organization uid is required";
49+
4550
Util() throws IllegalAccessException {
4651
throw new IllegalAccessException("private=modifier");
4752
}

src/main/java/com/contentstack/cms/marketplace/Marketplace.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
import com.contentstack.cms.marketplace.request.AppRequest;
77
import org.jetbrains.annotations.NotNull;
88
import retrofit2.Retrofit;
9+
import retrofit2.converter.gson.GsonConverterFactory;
910

1011
/**
1112
* The type Marketplace.
1213
*/
1314
public class Marketplace {
1415

15-
private final Retrofit client;
16+
private Retrofit client;
1617
private final String orgId;
17-
private final String ERR_MESSAGE = "To access the marketplace, the organization_uid parameter is required. " +
18+
private final static String ERR_MESSAGE = "To access marketplace instance, the organization_uid parameter is required. " +
1819
"Please ensure that you provide a valid organization_uid value when calling the marketplace() method";
1920

2021
/**
@@ -24,16 +25,36 @@ public class Marketplace {
2425
* the client
2526
* @param orgId
2627
* the org id
28+
* @param baseUrl
29+
* the base url
2730
*/
28-
public Marketplace(@NotNull Retrofit client, @NotNull String orgId) {
31+
public Marketplace(@NotNull Retrofit client, @NotNull String orgId, String baseUrl) {
2932
this.client = client;
3033
this.orgId = orgId;
34+
if (baseUrl == null) {
35+
String parentEndpoint = String.valueOf(this.client.baseUrl());
36+
if (parentEndpoint.contains("v3/")) {
37+
parentEndpoint = parentEndpoint.replaceFirst("v3/", "");
38+
}
39+
this.client = updateClient(this.client, parentEndpoint);
40+
} else {
41+
this.client = updateClient(this.client, baseUrl);
42+
}
43+
3144
if (this.orgId.isEmpty()) {
3245
throw new NullPointerException(ERR_MESSAGE);
3346
}
3447
}
3548

3649

50+
private Retrofit updateClient(Retrofit client, String baseUrl) {
51+
if (!baseUrl.startsWith("http")) {
52+
baseUrl = "https://" + baseUrl;
53+
}
54+
return client.newBuilder()
55+
.baseUrl(baseUrl).addConverterFactory(GsonConverterFactory.create()).build();
56+
}
57+
3758
/**
3859
* App app.
3960
*
@@ -64,14 +85,26 @@ public Auth authorizations() {
6485
}
6586

6687
/**
67-
* Installation installation.
88+
* returns instance of Installation.
6889
*
69-
* @return the instance of installation
90+
* @return the instance of {@link Installation}
7091
*/
7192
public Installation installation() {
7293
return new Installation(this.client, this.orgId);
7394
}
7495

96+
97+
/**
98+
* returns instance of Installation.
99+
*
100+
* @param installationId
101+
* the installation uid
102+
* @return instance of {@link Installation}
103+
*/
104+
public Installation installation(String installationId) {
105+
return new Installation(this.client, this.orgId, installationId);
106+
}
107+
75108
/**
76109
* Request app request.
77110
*

0 commit comments

Comments
 (0)