Skip to content

Commit 6a28bff

Browse files
Merge pull request for v0.1.0
v0.1.0
2 parents 82f36dd + d27e227 commit 6a28bff

Some content is hidden

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

47 files changed

+2713
-1804
lines changed

.github/workflows/publish.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Publish to Docker
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
publish:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
# Add your test steps here if needed...
12+
- name: Set up Java for publishing to Maven Central Repository
13+
uses: docker/build-push-action@v1
14+
with:
15+
java-version: 1.8
16+
server-id: ossrh
17+
server-username: MAVEN_USERNAME
18+
server-password: MAVEN_PASSWORD
19+
gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
20+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
21+
- name: build artifact
22+
# run: mvn clean package
23+
# - name: Create release
24+
uses: ncipollo/release-action@v1
25+
with:
26+
allowUpdates: true
27+
artifacts: "${{ github.workspace }}/target/*.jar"
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Publish to the Maven Central Repository
30+
run: |
31+
mvn \
32+
--no-transfer-progress \
33+
--batch-mode \
34+
deploy
35+
env:
36+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
37+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
38+
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
39+
40+

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "automatic"
3+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2012 - 2022 Contentstack
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+4-14
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ Stack stack = contentstack.stack("API_KEY", "MANAGEMENT_TOKEN");
7575
To use the Java CMA SDK, you need to first initialize it. To do this, use the following code:
7676

7777
```java
78-
package com.contentstack.cms;
79-
8078
Contentstack contentstack = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
8179
```
8280

@@ -94,18 +92,12 @@ Response<ResponseBody> response = stack.fetch().execute();
9492
To create an entry in a specific content type of a stack, use the following lines of code:
9593

9694
```java
95+
Contentstack contentstack = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
9796
Stack stack = contentstack.stack("API_KEY");
98-
// Create JSONObject to upload
99-
JSONObject jsonBody = new JSONObject()
100-
jsonBody.put("key", "value");
101-
102-
// Add Query parameters to the entry
103-
entry.addParam("locale", "en-us");
104-
Response<ResponseBody> response = entry.create(jsonBody).execute();
97+
JSONObject body = ....
98+
Response<ResponseBody> response = entry.create(body).execute();
10599
if (response.isSuccessful()){
106100
System.out.println(response.body());
107-
}else {
108-
System.out.println(response.errorBody());
109101
}
110102
```
111103

@@ -114,11 +106,9 @@ if (response.isSuccessful()){
114106
The following lines of code can be used to upload assets to your stack:
115107

116108
```java
109+
Contentstack contentstack = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
117110
Stack stack = contentstack.stack("API_KEY");
118111
Asset asset = stack.asset();
119-
120-
// Add Query parameters to the entry
121-
asset.addParam("title'","headeline")
122112
Response<ResponseBody> response = asset.uploadAsset("filePath", "description").execute();
123113
if (response.isSuccessful()){
124114
System.out.println(response.body());

SECURITY.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Security
2+
3+
Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
4+
5+
If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.
6+
7+
## Reporting Security Issues
8+
9+
**Please do not report security vulnerabilities through public GitHub issues.**
10+
11+
Send email to [[email protected]](mailto:[email protected]).
12+
13+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
14+
15+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
16+
17+
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
18+
- Full paths of source file(s) related to the manifestation of the issue
19+
- The location of the affected source code (tag/branch/commit or direct URL)
20+
- Any special configuration required to reproduce the issue
21+
- Step-by-step instructions to reproduce the issue
22+
- Proof-of-concept or exploit code (if possible)
23+
- Impact of the issue, including how an attacker might exploit the issue
24+
25+
This information will help us triage your report more quickly.
26+
27+
[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/)

changelog.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# Changelog
2+
3+
## v0.1.0
4+
5+
### 20-OCT-2022
16

2-
## v1.0.0
3-
#### 03-SEP-2021
47
Initial release for Contentstack CMA base Java management SDK

cms.iml

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</content>
1212
<orderEntry type="inheritedJdk" />
1313
<orderEntry type="sourceFolder" forTests="false" />
14-
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.9.0" level="project" />
14+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.10" level="project" />
1515
<orderEntry type="library" name="Maven: io.reactivex.rxjava3:rxjava:3.1.5" level="project" />
1616
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.4" level="project" />
1717
<orderEntry type="library" name="Maven: com.squareup.retrofit2:retrofit:2.9.0" level="project" />
@@ -26,14 +26,14 @@
2626
<orderEntry type="library" scope="TEST" name="Maven: io.github.cdimascio:java-dotenv:5.2.2" level="project" />
2727
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.4.0" level="project" />
2828
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.4.0" level="project" />
29-
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.8.2" level="project" />
30-
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.2" level="project" />
29+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.9.0" level="project" />
30+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.9.0" level="project" />
3131
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
32-
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.2" level="project" />
33-
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.8.2" level="project" />
34-
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.8.2" level="project" />
35-
<orderEntry type="library" scope="TEST" name="Maven: org.junit.vintage:junit-vintage-engine:5.8.2" level="project" />
36-
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.8.2" level="project" />
32+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.9.0" level="project" />
33+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.9.0" level="project" />
34+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.9.0" level="project" />
35+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.vintage:junit-vintage-engine:5.9.0" level="project" />
36+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.9.0" level="project" />
3737
<orderEntry type="library" name="Maven: junit:junit:4.13.2" level="project" />
3838
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
3939
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />

pom.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<artifactId>cms</artifactId>
77
<packaging>jar</packaging>
88
<name>contentstack-management-java</name>
9-
<version>0.1.0-alpha-SNAPSHOT</version>
9+
<version>0.1.0</version>
1010
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
1111
API-first approach
1212
</description>
@@ -67,12 +67,12 @@
6767
</snapshotRepository>
6868
<repository>
6969
<id>ossrh</id>
70-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
70+
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
7171
</repository>
7272
</distributionManagement>
7373

7474
<properties>
75-
<sdk.version>1.0.0-SNAPSHOT</sdk.version>
75+
<sdk.version>0.1.0-SNAPSHOT</sdk.version>
7676
<sdk.version.snapshot>${sdk.version}-SNAPSHOT</sdk.version.snapshot>
7777
<maven.compiler.target>1.8</maven.compiler.target>
7878
<maven.compiler.source>1.8</maven.compiler.source>
@@ -87,14 +87,14 @@
8787
<logging.version>4.10.0</logging.version>
8888
<jococo-plugin.version>0.8.5</jococo-plugin.version>
8989
<lombok-source.version>1.18.24</lombok-source.version>
90-
<junit-jupiter.version>5.8.2</junit-jupiter.version>
90+
<junit-jupiter.version>5.9.0</junit-jupiter.version>
9191
<junit-jupiter-engine.version>5.8.0-M1</junit-jupiter-engine.version>
92-
<junit-vintage-engine.version>5.8.2</junit-vintage-engine.version>
93-
<gson.version>2.9.0</gson.version>
92+
<junit-vintage-engine.version>5.9.0</junit-vintage-engine.version>
93+
<gson.version>2.10</gson.version>
9494
<maven-site-plugin.version>3.3</maven-site-plugin.version>
9595
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
9696
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
97-
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
97+
<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>
100100
<dependencies>

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

+32-7
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
/**
2828
* <b>Contentstack Java Management SDK</b>
2929
* <br>
30-
* <b>Contentstack Java Management SDK</b> interact with the Content Management APIs and allow you to create, update,
31-
* delete, and fetch content from your Contentstack account. They are read-write in nature.
30+
* <b>Java Management SDK</b> Interact with the Content Management APIs and allow you to create, update,
31+
* delete, and fetch content from your Contentstack account. (They are read-write in nature.)
3232
* <br>
3333
* You can use them to build your own apps and manage your content from Contentstack.
3434
*/
@@ -330,7 +330,7 @@ public Stack stack() {
330330
* @return the stack instance
331331
*/
332332
public Stack stack(@NotNull Map<String, Object> header) {
333-
if (this.authtoken == null && header.size() == 0)
333+
if (this.authtoken == null && !header.containsKey(AUTHORIZATION) && header.get(AUTHORIZATION) == null)
334334
throw new IllegalStateException(PLEASE_LOGIN);
335335
return new Stack(this.instance, header);
336336
}
@@ -355,14 +355,41 @@ public Stack stack(@NotNull Map<String, Object> header) {
355355
* @return the stack instance
356356
*/
357357
public Stack stack(@NotNull String apiKey, @NotNull String managementToken) {
358-
if (this.authtoken == null)
359-
throw new IllegalStateException(PLEASE_LOGIN);
360358
HashMap<String, Object> headers = new HashMap<>();
361359
headers.put(API_KEY, apiKey);
362360
headers.put(AUTHORIZATION, managementToken);
363361
return new Stack(this.instance, headers);
364362
}
365363

364+
365+
/**
366+
* <a href= "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a> A stack is
367+
* a space that stores the content of a project (a web or mobile property). Within a stack, you can create content
368+
* structures, content entries, users, etc. related to the project
369+
* <p>
370+
* <b> Example </b>
371+
*
372+
* <pre>
373+
* Contentstack client = new Contentstack.Builder().build();
374+
* Stack org = client.stack();
375+
* </pre>
376+
*
377+
* @param key
378+
* You can provide apiKey of the stack or branchKey
379+
* @return the stack instance
380+
*/
381+
public Stack stack(@NotNull String key) {
382+
HashMap<String, Object> headers = new HashMap<>();
383+
if (key.startsWith("blt")) {
384+
// In the case of API_Key provided
385+
headers.put(API_KEY, key);
386+
} else {
387+
// In case of branch provided
388+
headers.put(BRANCH, key);
389+
}
390+
return new Stack(this.instance, headers);
391+
}
392+
366393
/**
367394
* <a href= "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a> A stack is
368395
* a space that stores the content of a project (a web or mobile property). Within a stack, you can create content
@@ -384,8 +411,6 @@ public Stack stack(@NotNull String apiKey, @NotNull String managementToken) {
384411
* @return the stack instance
385412
*/
386413
public Stack stack(@NotNull String apiKey, @NotNull String managementToken, @NotNull String branch) {
387-
if (this.authtoken == null)
388-
throw new IllegalStateException(PLEASE_LOGIN);
389414
HashMap<String, Object> headers = new HashMap<>();
390415
headers.put(API_KEY, apiKey);
391416
headers.put(AUTHORIZATION, managementToken);

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
/**
1111
* <b>The type Header interceptor that extends Interceptor</b>
1212
* <p>
13-
* Interceptors are a powerful way to customize requests with Retrofit. A common use-case where you want to intercept
14-
* the actual request is to observe, modifies, and potentially short-circuits requests going out and the corresponding
15-
* responses coming back in. Typically, interceptors add, remove, or transform headers on the request. Depending on the
16-
* API implementation, you'll want to pass the auth token as the value for the Authorization header.
13+
* Interceptors are a powerful way to customize requests with Retrofit. A common
14+
* use-case where you want to intercept
15+
* the actual request is to observe, modifies, and potentially short-circuits
16+
* requests going out and the corresponding
17+
* responses coming back in. Typically, interceptors add, remove, or transform
18+
* headers on the request. Depending on the
19+
* API implementation, you'll want to pass the auth token as the value for the
20+
* Authorization header.
1721
*
1822
* @author ***REMOVED***
19-
* @version 1.0.0
20-
* @since 2022-05-19
23+
* @since v0.1.0
2124
*/
2225
public class AuthInterceptor implements Interceptor {
2326

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* The Contentstack Logger
99
*
1010
* @author ***REMOVED***
11-
* @version 1.0.0
12-
* @since 2022-05-19
11+
* @version v0.1.0
12+
* @since 2022-10-20
1313
*/
1414
public class CMALogger {
1515

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* Contentstack Response:
1414
*
1515
* @author ***REMOVED***
16-
* @version 1.0.0
17-
* @since 2022-05-19
16+
* @version v0.1.0
17+
* @since 2022-10-20
1818
*/
1919

2020
public class CMAResponseConvertor {

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
* CMARuntimeException that extends Exception class
55
*
66
* @author ***REMOVED***
7-
* @version 1.0.0
8-
* @since 2022-05-19
7+
* @version v0.1.0
8+
* @since 2022-10-20
99
*/
10-
public class CMARuntimeException extends Exception { public CMARuntimeException(String message) {
10+
public class CMARuntimeException extends Exception {
11+
public CMARuntimeException(String message) {
1112
super(message);
12-
}}
13+
}
14+
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
import java.io.IOException;
88

9-
109
/**
11-
* The ContentstackResponse is the response when we execute the API Response, ContentstackResponse contains different
10+
* The ContentstackResponse is the response when we execute the API Response,
11+
* ContentstackResponse contains different
1212
* response type
1313
*
1414
* @author ***REMOVED***
15-
* @version 1.0.0
16-
* @since 2022-05-19
15+
* @version v0.1.0
16+
* @since 2022-10-20
1717
*/
1818
class ContentstackResponse<T> {
1919

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.contentstack.cms.core;
2+
3+
public class NullKeyException extends Exception {
4+
5+
public NullKeyException() {
6+
super();
7+
}
8+
9+
/**
10+
* Constructs a new exception with the specified detail message. The
11+
* cause is not initialized, and may subsequently be initialized by
12+
* a call to {@link #initCause}.
13+
*
14+
* @param message the detail message. The detail message is saved for
15+
* later retrieval by the {@link #getMessage()} method.
16+
*/
17+
public NullKeyException(String message) {
18+
super(message);
19+
}
20+
21+
}

0 commit comments

Comments
 (0)