Skip to content

Commit

Permalink
Merge pull request #47 from contentstack/CS-43305-query-taxonomy
Browse files Browse the repository at this point in the history
CS-43305-Taxonomy-Filter-Query
  • Loading branch information
ishaileshmishra authored Jan 16, 2024
2 parents c5e5d90 + 55f0ea2 commit 948daea
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 18 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 32 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
# 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

- 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
Expand All @@ -15,4 +45,5 @@
### Initial Release

### Oct 20, 2022

Initial release for Contentstack CMA base Java management SDK
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>cms</artifactId>
<packaging>jar</packaging>
<name>contentstack-management-java</name>
<version>1.1.0</version>
<version>1.3.0</version>
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
API-first approach
</description>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/contentstack/cms/core/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.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.3.0";

static final String PRIVATE_CONSTRUCTOR = "private constructor can't be accessed outside the class";
public static final Boolean RETRY_ON_FAILURE = true;
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/com/contentstack/cms/stack/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,12 @@ public Call<ResponseBody> 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.
* <p>
* 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
* <p>
* <b>entry</b> parameter. However, if
Expand Down Expand Up @@ -778,4 +778,22 @@ public Call<ResponseBody> 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
* <p><b>Examples</b></p>
* <pre>
* JSONObject query = new JSONObject();
* query.put("taxonomies.taxonomy_uid", "{ \"$in\" : [\"term_uid1\" , \"term_uid2\" ] }");
* Call response = entry.query(query).execute();
* </pre>
*
* @param query the request body of type {@link JSONObject}
* @return instance of {@link Terms}
*/
public Call<ResponseBody> query(@NotNull JSONObject query) {
validateCT();
return this.service.filterTaxonomy(this.headers, this.contentTypeUid, query);
}

}
7 changes: 7 additions & 0 deletions src/main/java/com/contentstack/cms/stack/EntryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,11 @@ Call<ResponseBody> unpublish(
@Path("content_type_uid") String contentTypeUid,
@Path("entry_uid") String entryUid,
@Body JSONObject requestBody);

@GET("content_types/{content_type_uid}/entries")
Call<ResponseBody> filterTaxonomy(
@HeaderMap Map<String, Object> headers,
@Path("content_type_uid") String contentTypeUid,
@Query("query") JSONObject queryObject);

}
2 changes: 0 additions & 2 deletions src/main/java/com/contentstack/cms/stack/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import java.util.Map;

/**
* <b>Languages</b>
* <br>
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.HashMap;

/**
* <b>Management tokens: </b> <br>
* To authenticate Content Management API (CMA) requests over your stack
* content, you can use Management Tokens
* <br>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/contentstack/cms/stack/Taxonomy.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,19 @@ 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
* <p>Example usage:</p>
* <pre>JSONObject object = new JSonObject();</pre>
* <pre>object.put("taxonomies.color", Object)</pre>
* <pre>Taxonomy taxonomy = stack("authtoken").taxonomy("taxonomyId").filterTaxonomy(object);</pre>
*
* @param query the query of type @{@link JSONObject}
* @return instance of {@link Call}
*/
public Call<ResponseBody> query(JSONObject query) {
return this.taxonomyService.filterTaxonomy(this.headers, query);
}

}
7 changes: 7 additions & 0 deletions src/main/java/com/contentstack/cms/stack/TaxonomyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,11 @@ Call<ResponseBody> reorder(
Call<ResponseBody> searchTerm(
@HeaderMap HashMap<String, Object> headers,
@Query("typeahead") String termString);


@GET("taxonomies/entries")
Call<ResponseBody> filterTaxonomy(
@HeaderMap HashMap<String, Object> headers,
@Query("query") JSONObject queryObject
);
}
2 changes: 0 additions & 2 deletions src/main/java/com/contentstack/cms/stack/Tokens.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import retrofit2.Retrofit;

/**
* <b>Tokens</b>
* <br>
* Contentstack provides different types of tokens to authorize API requests
*
* @author ishaileshmishra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/contentstack/cms/stack/EntryFieldUnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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());

}

}
25 changes: 23 additions & 2 deletions src/test/java/com/contentstack/cms/stack/TaxonomyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down Expand Up @@ -365,4 +363,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("fakestackkey")
.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());
}

}

0 comments on commit 948daea

Please sign in to comment.