Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing: Java client v3 #540

Merged
merged 172 commits into from
Jun 10, 2019
Merged

Introducing: Java client v3 #540

merged 172 commits into from
Jun 10, 2019

Conversation

Ant-hem
Copy link
Member

@Ant-hem Ant-hem commented Feb 27, 2019

Introducing Java Client v3 ☕️

ChangeLog/ New features

Maven

To get the beta version add this to your pom.xml

<dependency>
         <groupId>com.algolia</groupId>
        <artifactId>algoliasearch-core</artifactId>
        <version>3.0.0-beta-2</version>
 </dependency>

<dependency>
        <groupId>com.algolia</groupId>
         <artifactId>algoliasearch-apache</artifactId>
         <version>3.0.0-beta-2</version>
</dependency>

Less dependencies!

  • org.apache.httpcomponents.httpasyncclient
  • com.fasterxml.jackson.core / jackson-core / jackson-databind /jackson-datatype-jsr310
  • And that's it...

Injectable HttpCient

The default HttpClient is httpasyncclient from Apache. If you want another one, just implement the IHttpRequester interface with your favorite HttpClient and inject it!

New test suite!

  • Powered by JUnit5
  • Running in less than 30 seconds locally! ⚡️

Asynchronous and synchronous methods in the same class!

Before, asynchronous and synchronous methods were split in two different classes. Now, they are reunited in the same class!

All asynchronous methods are suffixed with the async keyword and return a CompletableFuture.

SearchClient searchClient = DefaultSearchClient.create(ALGOLIA_APPLICATION_ID_1, ALGOLIA_API_KEY_1);
SearchIndex<Employee> index = searchClient.initIndex("employees", Employee.class);
    
// Async Code
CompletableFuture<SearchResult<Employee>> searchFuture = index.searchAsync(new Query("algolia"));

// Sync code
SearchResult<Employee> search = index.search(new Query("algolia"))

Useful helper: waiTask()

All Algolia's asynchronous operations can now be awaited like this:

index.setSettings(indexSettings).waitTask();

Static factories

We added static factories to Algolia's POJOs such as Synonyms, Rules to help you build valid Algolia's objects.

    Synonym wiiToWiiu =
        Synonym.createOneWaySynonym("wii_to_wii_u", "wii", Collections.singletonList("wii u"));

Getting started locally:

  • Clone the repo and checkout on the develop branch.

  • Build the project

mvn clean install
  • Run the tests
mvn clean test

algoliasearch/pom.xml Outdated Show resolved Hide resolved
Copy link

@ElPicador ElPicador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice improvements 👍

@Ant-hem
Copy link
Member Author

Ant-hem commented Apr 4, 2019

ping @BenoitPerrot ! :) Integrated some of the improvements we discussed yesterday.

Copy link
Member

@PLNech PLNech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superficial review considering the changeset's size, but still a few (hopefully useful) comments 🙃

@@ -4,10 +4,10 @@ set -e

if [[ "${JAVA_VERSION}" = "8" ]]; then
if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [[ ! "$TRAVIS_PULL_REQUEST_SLUG" =~ ^algolia\/ ]]; then
eval $(./algolia-keys export) && mvn clean test jacoco:report jacoco:report-aggregate -B && mvn -pl algoliasearch-tests coveralls:report -B;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you choose to stop reporting Code coverage?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still jacoco in pom.xml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nop I don't want to drop it! I removed it temporarily at the begining of the project. I'll add it back in a few days :)

pom.xml Outdated Show resolved Hide resolved
src/main/java/com/algolia/search/SearchClient.java Outdated Show resolved Hide resolved
src/main/java/com/algolia/search/util/AlgoliaUtils.java Outdated Show resolved Hide resolved
import java.util.HashMap;
import java.util.Map;

public class HttpRequest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could benefit Nullability annotations (same for HttpResponse) :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for any model which would be manipulated by our users, when its fields are not covered by methods with Nullability annotations

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate? 🤔 Do you mean to add annotations on the constructors parameters?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean adding annotations wherever our users might benefit it:

  • Constructor parameters of classes they could instantiate (not convinced it would be relevant here, as I don't think they have to create a new HTTPRequest() anytime)
  • Annotations on public fields / public {g,s}etters that the users would manipulate to avoid unnecessary null-checks (e.g. if headers is never null, would mark getHeaders() as @NonNull)

I think this can be applied more consistently in some classes, e.g. :

  • new Variant(...) takes a @NonNull String index in constructor
    -> Variant.getIndex() could be annotated as @NonNull
    -> Variant.setIndex() should have its param annotated as @NonNull

You might want to use Intellij's Infer Nullity to quickly generate consistent annotations based on your current codebase 🙃

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification! Neat idea. I'll look at it.

@PLNech PLNech self-requested a review April 17, 2019 15:24
Copy link
Member

@PLNech PLNech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided you resolve the last unsolved discussions, LGTM 👌

@Ant-hem
Copy link
Member Author

Ant-hem commented Apr 17, 2019

Provided you resolve the last unsolved discussions, LGTM 👌

Thanks! Still need to have a look at the Nullability annotations for some POJOs :)

aseure and others added 24 commits May 24, 2019 13:27
…nd ensure all steps are run in separate order
- Added QueryBase with CRTP to handle Query inheritance and to prevent
down-casting for the children
Removing slf4j allow to remove on more dependency of the library and
to simplify the shading process.

 - Added: JUL in HttpTransport with Log.FINEST level
 - Removed: SLF4J and Logback from pom.xml
 - Updated: logging.properties

 To activate JUL please set in logging.properties
 .level=FINEST
 com.algolia.search.HttpTransport=FINEST
 java.util.logging.ConsoleHandler.level=FINEST

 and set:
 -Djava.util.logging.config.file="logging.properties-path"

 More information about JUL:
 http://java.ociweb.com/mark/programming/JavaLogging.html
- Removed org.apache.http.level=WARNING from algoliasearch-core
- Added org.apache.http.level=WARNING in algoliasearch-apache file
The query parameter aroundPrecision can now handle a JSON format;
{ "aroundPrecision":
[ {"from":0, "value":10}, {"from":100, "value":1000}, ... ]
}
In order to respect fluent API design used by other setters.
Reported in #571.
In order to respect fluent API design used by other setters.
Reported in #571.
@Ant-hem Ant-hem merged commit a0210a3 into master Jun 10, 2019
@aseure aseure deleted the develop branch July 10, 2019 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants