From 79c8075c40c63deac9e1b73e4a0456e8935acc2a Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Tue, 16 Jan 2024 11:46:53 +0530 Subject: [PATCH 1/3] CS-42937 : Support for Early Access Header CS-42936 : Taxonomy document and Test --- LICENSE | 2 +- README.md | 2 +- changelog.md | 26 ++++++++++++++++++- pom.xml | 2 +- .../java/com/contentstack/cms/core/Util.java | 6 ++--- .../com/contentstack/cms/stack/Entry.java | 23 +++++++++++++--- .../contentstack/cms/stack/EntryService.java | 7 +++++ .../com/contentstack/cms/stack/Taxonomy.java | 12 +++++++++ .../cms/stack/TaxonomyService.java | 7 +++++ .../cms/ContentstackUnitTest.java | 2 +- .../cms/stack/EntryFieldUnitTests.java | 20 ++++++++++++++ .../contentstack/cms/stack/TaxonomyTest.java | 23 ++++++++++++++++ 12 files changed, 121 insertions(+), 11 deletions(-) diff --git a/LICENSE b/LICENSE index 981ba261..d77c7f4e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2012 - 2023 Contentstack +Copyright (c) 2012 - 2024 Contentstack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2e119302..0ef4f52a 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ if(response.isSuccessful()){ ### The MIT License (MIT) -Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved +Copyright © 2012-2024 [Contentstack](https://www.contentstack.com/). All Rights Reserved 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 diff --git a/changelog.md b/changelog.md index 55ed9d34..5b25c619 100644 --- a/changelog.md +++ b/changelog.md @@ -1,11 +1,34 @@ # Changelog +## v1.2.0 + +### Dec 18, 2023 + +- New Features: + - Early access header support + + + +## v1.1.0 + +### Oct 31, 2023 + +- New Features: + - Taxonomy + - Teams + +Bug Fixes: + - KeepAliveDuration + - SNYK issues fixed + + ## v1.0.0 ### Aug 01, 2023 + - Bug Fixed For un-localize An Entry - Fixed Timeout Issue -- #32 Fixed +- #32 Fixed - Code coverage improvements - NRP support added - General improvements with minor breaking changes @@ -15,4 +38,5 @@ ### Initial Release ### Oct 20, 2022 + Initial release for Contentstack CMA base Java management SDK diff --git a/pom.xml b/pom.xml index 82180728..53c033d6 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ cms jar contentstack-management-java - 1.1.0 + 1.3.0 Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an API-first approach diff --git a/src/main/java/com/contentstack/cms/core/Util.java b/src/main/java/com/contentstack/cms/core/Util.java index 48a0fa29..8ce1a9f1 100644 --- a/src/main/java/com/contentstack/cms/core/Util.java +++ b/src/main/java/com/contentstack/cms/core/Util.java @@ -15,10 +15,10 @@ */ public class Util { - // The line `public static final String SDK_VERSION = "1.0.0";` + // The line `public static final String SDK_VERSION = "1.2.0";` // named `SDK_VERSION` of type `String`. The value of this constant is set to - // "1.0.0". - public static final String SDK_VERSION = "1.0.0"; + // "1.2.0". + public static final String SDK_VERSION = "1.2.0"; static final String PRIVATE_CONSTRUCTOR = "private constructor can't be accessed outside the class"; public static final Boolean RETRY_ON_FAILURE = true; diff --git a/src/main/java/com/contentstack/cms/stack/Entry.java b/src/main/java/com/contentstack/cms/stack/Entry.java index 41de44a8..10351804 100644 --- a/src/main/java/com/contentstack/cms/stack/Entry.java +++ b/src/main/java/com/contentstack/cms/stack/Entry.java @@ -744,12 +744,12 @@ public Call publishWithReference(@NotNull JSONObject requestBody) } /** - * To Unpublish an entry call will unpublish an entry at once, and also, gives - * you the provision to unpublish an + * To Un-publish an entry call will un-publish an entry at once, and also, gives + * you the provision to un-publish an * entry automatically at a later date/time. *

* In the 'Body' section, you can specify the locales and environments from - * which you want to unpublish the entry. + * which you want to un-publish the entry. * These details should be specified in the *

* entry parameter. However, if @@ -778,4 +778,21 @@ public Call unpublish(@NotNull JSONObject requestBody) { return this.service.unpublish(this.headers, this.contentTypeUid, this.entryUid, requestBody); } + + /** + * Get instance of taxonomy search filter class instance through which we can query on taxonomy based on content type + *

Examples

+ *

+ *

+     *           JSONObject query = new JSONObject();
+     *         query.put("taxonomies.taxonomy_uid", "{ \"$in\" : [\"term_uid1\" , \"term_uid2\" ] }");
+     *         Response response = entry.query(query).execute();
+     *     
+ * instance of {@link Terms} + */ + public Call query(@NotNull JSONObject query) { + validateCT(); + return this.service.filterTaxonomy(this.headers, this.contentTypeUid, query); + } + } diff --git a/src/main/java/com/contentstack/cms/stack/EntryService.java b/src/main/java/com/contentstack/cms/stack/EntryService.java index d5ef1e23..3fe6d220 100644 --- a/src/main/java/com/contentstack/cms/stack/EntryService.java +++ b/src/main/java/com/contentstack/cms/stack/EntryService.java @@ -146,4 +146,11 @@ Call unpublish( @Path("content_type_uid") String contentTypeUid, @Path("entry_uid") String entryUid, @Body JSONObject requestBody); + + @GET("content_types/{content_type_uid}/entries") + Call filterTaxonomy( + @HeaderMap Map headers, + @Path("content_type_uid") String contentTypeUid, + @Query("query") JSONObject queryObject); + } diff --git a/src/main/java/com/contentstack/cms/stack/Taxonomy.java b/src/main/java/com/contentstack/cms/stack/Taxonomy.java index 020270e8..fce2db5a 100644 --- a/src/main/java/com/contentstack/cms/stack/Taxonomy.java +++ b/src/main/java/com/contentstack/cms/stack/Taxonomy.java @@ -251,4 +251,16 @@ public Terms terms() { return new Terms(this.taxonomyService, this.headers, this.taxonomyId); } + + /** + * Get instance of taxonomy search filter class instance through which we can query on taxonomy based on Entry + *

Example usage:

+ *
JSONObject object = new JSonObject();
+ *
object.put("taxonomies.color", Object)
+ *
Taxonomy taxonomy = stack("authtoken").taxonomy("taxonomyId").filterTaxonomy(object);
+ */ + public Call query(JSONObject query) { + return this.taxonomyService.filterTaxonomy(this.headers, query); + } + } diff --git a/src/main/java/com/contentstack/cms/stack/TaxonomyService.java b/src/main/java/com/contentstack/cms/stack/TaxonomyService.java index f104c368..571a9bcb 100644 --- a/src/main/java/com/contentstack/cms/stack/TaxonomyService.java +++ b/src/main/java/com/contentstack/cms/stack/TaxonomyService.java @@ -91,4 +91,11 @@ Call reorder( Call searchTerm( @HeaderMap HashMap headers, @Query("typeahead") String termString); + + + @GET("taxonomies/entries") + Call filterTaxonomy( + @HeaderMap HashMap headers, + @Query("query") JSONObject queryObject + ); } diff --git a/src/test/java/com/contentstack/cms/ContentstackUnitTest.java b/src/test/java/com/contentstack/cms/ContentstackUnitTest.java index ea4e09f6..eaca866e 100644 --- a/src/test/java/com/contentstack/cms/ContentstackUnitTest.java +++ b/src/test/java/com/contentstack/cms/ContentstackUnitTest.java @@ -250,7 +250,7 @@ public void testValidOrganization() { @Test public void testNullOrganizationUid() { Contentstack client = new Contentstack.Builder().setAuthtoken("fake@authtoken").build(); - Assertions.assertThrows(IllegalArgumentException.class, () -> client.organization(null)); + Assertions.assertThrows(NullPointerException.class, () -> client.organization(null)); } @Test diff --git a/src/test/java/com/contentstack/cms/stack/EntryFieldUnitTests.java b/src/test/java/com/contentstack/cms/stack/EntryFieldUnitTests.java index f43cbc0a..f9701a5a 100644 --- a/src/test/java/com/contentstack/cms/stack/EntryFieldUnitTests.java +++ b/src/test/java/com/contentstack/cms/stack/EntryFieldUnitTests.java @@ -3,6 +3,7 @@ import com.contentstack.cms.Contentstack; import com.contentstack.cms.TestClient; import okhttp3.Request; +import okhttp3.ResponseBody; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.junit.jupiter.api.*; @@ -768,4 +769,23 @@ void testHeader() { Assertions.assertEquals(3, resp.headers().size()); } + @Test + void queryFiltersOnTaxonomy() { + JSONObject query = new JSONObject(); + query.put("taxonomies.taxonomy_uid", "{ \"$in\" : [\"term_uid1\" , \"term_uid2\" ] }"); + Request request = entryInstance.query(query).request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(4, request.url().pathSegments().size()); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertEquals("content_types", request.url().pathSegments().get(1)); + Assertions.assertEquals("product", request.url().pathSegments().get(2)); + Assertions.assertEquals("entries", request.url().pathSegments().get(3)); + Assertions.assertNull(request.body()); + Assertions.assertEquals("query={\"taxonomies.taxonomy_uid\":\"{ \\\"$in\\\" : [\\\"term_uid1\\\" , \\\"term_uid2\\\" ] }\"}", request.url().query()); + + } + } diff --git a/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java b/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java index d65d7c3b..23d9fca7 100644 --- a/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java +++ b/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java @@ -365,4 +365,27 @@ void findTestAPI() throws IOException { System.out.println(response); } + @Test + void queryFiltersOnTaxonomy() { + Taxonomy taxonomy = new Contentstack.Builder() + .setAuthtoken(TestClient.AUTHTOKEN) + .setHost("api.contentstack.io") + .build() + .stack("blt12c1ba95c1b11e88") + .taxonomy(); + JSONObject query = new JSONObject(); + query.put("taxonomies.taxonomy_uid", "{ \"$in\" : [\"term_uid1\" , \"term_uid2\" ] }"); + Request request = taxonomy.query(query).request(); + Assertions.assertEquals(1, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(3, request.url().pathSegments().size()); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertEquals("entries", request.url().pathSegments().get(2)); + Assertions.assertNull(request.body()); + Assertions.assertEquals("query={\"taxonomies.taxonomy_uid\":\"{ \\\"$in\\\" : [\\\"term_uid1\\\" , \\\"term_uid2\\\" ] }\"}", request.url().query()); + } + } From 873efb1385eb6d47c1a757ff21b1bb19f31d9d3f Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Tue, 16 Jan 2024 12:00:52 +0530 Subject: [PATCH 2/3] CS-42937 : Support for Early Access Header CS-42936 : Taxonomy document and Test --- src/main/java/com/contentstack/cms/stack/Entry.java | 7 ++++--- src/main/java/com/contentstack/cms/stack/Locale.java | 2 -- .../java/com/contentstack/cms/stack/ManagementToken.java | 1 - src/main/java/com/contentstack/cms/stack/Taxonomy.java | 3 +++ src/main/java/com/contentstack/cms/stack/Tokens.java | 2 -- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/contentstack/cms/stack/Entry.java b/src/main/java/com/contentstack/cms/stack/Entry.java index 10351804..6fb633af 100644 --- a/src/main/java/com/contentstack/cms/stack/Entry.java +++ b/src/main/java/com/contentstack/cms/stack/Entry.java @@ -782,13 +782,14 @@ public Call unpublish(@NotNull JSONObject requestBody) { /** * Get instance of taxonomy search filter class instance through which we can query on taxonomy based on content type *

Examples

- *

*

      *           JSONObject query = new JSONObject();
      *         query.put("taxonomies.taxonomy_uid", "{ \"$in\" : [\"term_uid1\" , \"term_uid2\" ] }");
-     *         Response response = entry.query(query).execute();
+     *         Call response = entry.query(query).execute();
      *     
- * instance of {@link Terms} + * + * @param query the request body of type {@link JSONObject} + * @return instance of {@link Terms} */ public Call query(@NotNull JSONObject query) { validateCT(); diff --git a/src/main/java/com/contentstack/cms/stack/Locale.java b/src/main/java/com/contentstack/cms/stack/Locale.java index 24662b86..fb7a1f49 100644 --- a/src/main/java/com/contentstack/cms/stack/Locale.java +++ b/src/main/java/com/contentstack/cms/stack/Locale.java @@ -11,8 +11,6 @@ import java.util.Map; /** - * Languages - *
* Contentstack has a sophisticated multilingual capability. It allows you to * create and publish entries in any * language. This feature allows you to set up multilingual websites and cater diff --git a/src/main/java/com/contentstack/cms/stack/ManagementToken.java b/src/main/java/com/contentstack/cms/stack/ManagementToken.java index 95d3334d..cd7a8923 100644 --- a/src/main/java/com/contentstack/cms/stack/ManagementToken.java +++ b/src/main/java/com/contentstack/cms/stack/ManagementToken.java @@ -9,7 +9,6 @@ import java.util.HashMap; /** - * Management tokens:
* To authenticate Content Management API (CMA) requests over your stack * content, you can use Management Tokens *
diff --git a/src/main/java/com/contentstack/cms/stack/Taxonomy.java b/src/main/java/com/contentstack/cms/stack/Taxonomy.java index fce2db5a..ea7ee77a 100644 --- a/src/main/java/com/contentstack/cms/stack/Taxonomy.java +++ b/src/main/java/com/contentstack/cms/stack/Taxonomy.java @@ -258,6 +258,9 @@ public Terms terms() { *
JSONObject object = new JSonObject();
*
object.put("taxonomies.color", Object)
*
Taxonomy taxonomy = stack("authtoken").taxonomy("taxonomyId").filterTaxonomy(object);
+ * + * @param query the query of type @{@link JSONObject} + * @return instance of {@link Call} */ public Call query(JSONObject query) { return this.taxonomyService.filterTaxonomy(this.headers, query); diff --git a/src/main/java/com/contentstack/cms/stack/Tokens.java b/src/main/java/com/contentstack/cms/stack/Tokens.java index 91d0f453..11f23a50 100644 --- a/src/main/java/com/contentstack/cms/stack/Tokens.java +++ b/src/main/java/com/contentstack/cms/stack/Tokens.java @@ -4,8 +4,6 @@ import retrofit2.Retrofit; /** - * Tokens - *
* Contentstack provides different types of tokens to authorize API requests * * @author ***REMOVED*** From 587e34478c9ccbed7feaf1351b6d59d1f0724896 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Tue, 16 Jan 2024 12:18:24 +0530 Subject: [PATCH 3/3] CS-42937 : Support for Early Access Header CS-42936 : Taxonomy document and Test --- changelog.md | 19 +++++++++++++------ .../java/com/contentstack/cms/core/Util.java | 4 ++-- .../contentstack/cms/stack/TaxonomyTest.java | 4 +--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/changelog.md b/changelog.md index 5b25c619..1f71bc61 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # Changelog +## v1.3.0 + +### Jan 18, 2024 + +- New Features: + - Query filter support in Taxonomy + - query filter support in Entry + - query filter support in Taxonomy + ## v1.2.0 ### Dec 18, 2023 @@ -7,20 +16,18 @@ - New Features: - Early access header support - - ## v1.1.0 ### Oct 31, 2023 - New Features: - - Taxonomy - - Teams + - Taxonomy + - Teams Bug Fixes: - - KeepAliveDuration - - SNYK issues fixed +- KeepAliveDuration +- SNYK issues fixed ## v1.0.0 diff --git a/src/main/java/com/contentstack/cms/core/Util.java b/src/main/java/com/contentstack/cms/core/Util.java index 8ce1a9f1..6f969dbe 100644 --- a/src/main/java/com/contentstack/cms/core/Util.java +++ b/src/main/java/com/contentstack/cms/core/Util.java @@ -15,10 +15,10 @@ */ public class Util { - // The line `public static final String SDK_VERSION = "1.2.0";` + // The line `public static final String SDK_VERSION = "1.3.0";` // named `SDK_VERSION` of type `String`. The value of this constant is set to // "1.2.0". - public static final String SDK_VERSION = "1.2.0"; + public static final String SDK_VERSION = "1.3.0"; static final String PRIVATE_CONSTRUCTOR = "private constructor can't be accessed outside the class"; public static final Boolean RETRY_ON_FAILURE = true; diff --git a/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java b/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java index 23d9fca7..13d10a10 100644 --- a/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java +++ b/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java @@ -25,8 +25,6 @@ class TaxonomyTest { protected static Terms terms; protected static JSONObject body; - // Create a JSONObject, JSONObject could be created in multiple ways. - // We choose JSONParser that converts string to JSONObject static String theBody = "{\n" + " \"taxonomy\": {\n" + " \"name\": \"Taxonomy 1\",\n" + @@ -371,7 +369,7 @@ void queryFiltersOnTaxonomy() { .setAuthtoken(TestClient.AUTHTOKEN) .setHost("api.contentstack.io") .build() - .stack("blt12c1ba95c1b11e88") + .stack("fakestackkey") .taxonomy(); JSONObject query = new JSONObject(); query.put("taxonomies.taxonomy_uid", "{ \"$in\" : [\"term_uid1\" , \"term_uid2\" ] }");