Skip to content

Applied design & implementation level refactoring techniques to improve code readability & maintainability #2517

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

Closed
wants to merge 3 commits into from

Conversation

Taran05
Copy link

@Taran05 Taran05 commented Apr 4, 2023

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our [issue tracker](https://github.
    com/spring-projects/spring-data-elasticsearch/issues)
    . Add the issue number to the Closes #issue-number line below
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

Closes #issue-number

@pivotal-cla
Copy link

@Taran05 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-cla
Copy link

@Taran05 Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 4, 2023
Copy link
Collaborator

@sothawo sothawo left a comment

Choose a reason for hiding this comment

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

This PR does not fix anything or add value to the code. It rather removes some compiler safety and reverts previous changes.

Don't commit formatting changes that are not aligned with the linked code style rules.

When running the tests, InetSocketAddressParserUnitTests fails.

And, before submitting a pull request, create an issue explaining the problem that you want to address and how you plan to solve it.

* @return the function for configuring a WebClient.
*/
Function<WebClient, WebClient> getWebClientConfigurer();

Copy link
Collaborator

Choose a reason for hiding this comment

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

This reverts the change from #2513 reintroducing the since 4.3 unused method for configuring the WebClient. Why?

@@ -329,7 +335,7 @@ default TerminalClientConfigurationBuilder withSocketTimeout(long millis) {
* @param proxy a proxy formatted as String {@literal host:port}.
* @return the {@link TerminalClientConfigurationBuilder}.
*/
TerminalClientConfigurationBuilder withProxy(String proxy);
TerminalClientConfigurationBuilder setProxy(String proxy);
Copy link
Collaborator

Choose a reason for hiding this comment

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

all the methods on this builder class (and probably almost all builders in this project) use the with...() naming. Why should this be changed?

@@ -71,7 +73,6 @@
public MaybeSecureClientConfigurationBuilder connectedTo(String... hostAndPorts) {

Assert.notEmpty(hostAndPorts, "At least one host is required");

Copy link
Collaborator

Choose a reason for hiding this comment

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

We separate the Assert.* blocks with a newline from the rest of the code. One leading and one trailing. There might be places where such a newline is missing, but here the formatting is alright.

@@ -59,6 +60,7 @@
private @Nullable String password;
private @Nullable String pathPrefix;
private @Nullable String proxy;
private final Function<WebClient, WebClient> webClientConfigurer = Function.identity();
Copy link
Collaborator

Choose a reason for hiding this comment

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

reintroducing removed code

@@ -91,7 +92,7 @@ public MaybeSecureClientConfigurationBuilder connectedTo(InetSocketAddress... en
}

@Override
public MaybeSecureClientConfigurationBuilder withProxy(String proxy) {
public MaybeSecureClientConfigurationBuilder setProxy(String proxy) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

see my other comment in ClientConfiguration


TransportOptions.Builder transportOptionsBuilder = transportOptions != null ? transportOptions.toBuilder()
: new RestClientOptions(RequestOptions.DEFAULT).toBuilder();

ContentType jsonContentType = Version.VERSION == null ? ContentType.APPLICATION_JSON
: ContentType.create("application/vnd.elasticsearch+json",
new BasicNameValuePair("compatible-with", String.valueOf(Version.VERSION.major())));
new BasicNameValuePair("compatible-with", String.valueOf(Version.VERSION.major())));
Copy link
Collaborator

Choose a reason for hiding this comment

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

formatting change not compatible with code formatting guidelines

Comment on lines +408 to +426

/**
* Provides the {@link ElasticsearchClient} to be used.
*
* @param restClient the low level RestClient to use
* @return ElasticsearchClient instance
*/
@Bean
public static ElasticsearchClient elasticsearchClient(RestClient restClient) {

Assert.notNull(restClient, "restClient must not be null");

return ElasticsearchClients.createImperative(restClient, transportOptions());
}

public static TransportOptions transportOptions() {
return new RestClientOptions(RequestOptions.DEFAULT);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

putting a @Bean method here makes no sense, as this is a final utility class containing static methods and not a Spring configuration class that could provide beans. Bean setup of all relevant beans is done in the org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration derived classes.

Assert.notNull(restClient, "restClient must not be null");

return ElasticsearchClients.createImperative(restClient, transportOptions());
return ElasticsearchClients.elasticsearchClient(restClient);
Copy link
Collaborator

Choose a reason for hiding this comment

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

see my comment in ElasticsearchClients about creation of beans. In addition to that, we cannot remove the transportOptions() method from this abstract class, as it might be overridden by the user in a derived implementation.

@@ -81,7 +79,7 @@ public ElasticsearchClient elasticsearchClient(RestClient restClient) {
*/
@Bean(name = { "elasticsearchOperations", "elasticsearchTemplate" })
public ElasticsearchOperations elasticsearchOperations(ElasticsearchConverter elasticsearchConverter,
ElasticsearchClient elasticsearchClient) {
ElasticsearchClient elasticsearchClient) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

formatting change not compatible with code formatting guidelines

@@ -159,7 +160,6 @@ public <T> List<MultiGetItem<T>> multiGet(Query query, Class<T> clazz, IndexCoor
.collect(Collectors.toList());
}

@Override
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why should we remove the @Override annotations on these methods? This would remove the ability of the compiler to check if we are really implementing or overloading a method instead of overloading it.

Otherwise only irrelevant formatting changes

@sothawo sothawo closed this Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants