Skip to content

Commit

Permalink
Polish (#1269)
Browse files Browse the repository at this point in the history
* polish code

* polish code

* format code

* fix : build issue

* Update README.md
  • Loading branch information
rajadilipkolli authored Jun 14, 2024
1 parent c77726f commit d351ec5
Show file tree
Hide file tree
Showing 55 changed files with 135 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public static ArchCondition<JavaField> haveGetterAndSetter(Map<String, String> e

private static ArchCondition<JavaField> buildFieldHaveGetterAndSetterCondition(
boolean forceSetters, Map<String, String> exclusions) {
return new ArchCondition<JavaField>(
forceSetters ? HAVE_GETTER_AND_SETTER_DESCRIPTION : HAVE_GETTER_DESCRIPTION) {
return new ArchCondition<>(forceSetters ? HAVE_GETTER_AND_SETTER_DESCRIPTION : HAVE_GETTER_DESCRIPTION) {

@Override
public void check(JavaField field, ConditionEvents events) {
Expand Down Expand Up @@ -84,7 +83,7 @@ public void check(JavaField field, ConditionEvents events) {
}

private static ArchCondition<JavaClass> buildClassHaveEqualsAndHashCodeCondition() {
return new ArchCondition<JavaClass>(EQUALS_AND_HASH_CODE_DESCRIPTION) {
return new ArchCondition<>(EQUALS_AND_HASH_CODE_DESCRIPTION) {

@Override
public void check(JavaClass javaClass, ConditionEvents events) {
Expand All @@ -109,7 +108,7 @@ public void check(JavaClass javaClass, ConditionEvents events) {
}

private static ArchCondition<JavaClass> buildStaticMethodsAreNotAllowedCondition() {
return new ArchCondition<JavaClass>(EQUALS_AND_HASH_CODE_DESCRIPTION) {
return new ArchCondition<>(EQUALS_AND_HASH_CODE_DESCRIPTION) {

@Override
public void check(JavaClass javaClass, ConditionEvents events) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@

public class CustomerRequestSimulation extends Simulation {

HttpProtocolBuilder httpProtocol =
final HttpProtocolBuilder httpProtocol =
http.baseUrl("http://localhost:8080")
.acceptHeader("application/json")
.userAgentHeader("Gatling/Performance Test");

Iterator<Map<String, Object>> feeder =
final Iterator<Map<String, Object>> feeder =
Stream.generate(
(Supplier<Map<String, Object>>)
() ->
Collections.singletonMap(
"text", UUID.randomUUID().toString()))
.iterator();

ScenarioBuilder scn =
final ScenarioBuilder scn =
CoreDsl.scenario("Load Test Creating Customers")
.feed(feeder)
.exec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ deleteDatasources:
- name: Prometheus
orgId: 1

# list of datasources to insert/update depending
# whats available in the database
# list of datasources to insert/update depending on what's available in the database
datasources:
# <string, required> name of the datasource. Required
- name: Prometheus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public Mono<AggregationSearchResponse> aggregateSearch(
});
}

Function<Map<String, ElasticsearchAggregation>, Map<String, Map<String, Long>>>
final Function<Map<String, ElasticsearchAggregation>, Map<String, Map<String, Long>>>
aggregationFunction =
aggregationMap -> {
Map<String, Map<String, Long>> resultMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ void findByBoroughOrCuisineOrName() {
assertThat(searchPage.isEmpty()).isFalse();
assertThat(searchPage.hasContent()).isTrue();
assertThat(searchPage.stream().count()).isEqualTo(2);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand Down Expand Up @@ -208,7 +209,8 @@ void termQueryForBorough() {
assertThat(searchPage.isEmpty()).isFalse();
assertThat(searchPage.hasContent()).isTrue();
assertThat(searchPage.stream().count()).isEqualTo(2);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand All @@ -235,7 +237,8 @@ void termsQueryForBorough() {
assertThat(searchPage.isEmpty()).isFalse();
assertThat(searchPage.hasContent()).isTrue();
assertThat(searchPage.stream().count()).isEqualTo(2);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand Down Expand Up @@ -264,7 +267,8 @@ void queryBoolWithShould() {
assertThat(searchPage.isEmpty()).isFalse();
assertThat(searchPage.hasContent()).isTrue();
assertThat(searchPage.stream().count()).isEqualTo(2);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand Down Expand Up @@ -304,7 +308,8 @@ void wildcardSearch() {
assertThat(searchPage.isEmpty()).isFalse();
assertThat(searchPage.hasContent()).isTrue();
assertThat(searchPage.stream().count()).isEqualTo(1);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(40363920L);
assertThat(restaurant1.getName()).isEqualTo("Yono gardens");
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand All @@ -331,7 +336,8 @@ void regExpSearch() {
assertThat(searchPage.isEmpty()).isFalse();
assertThat(searchPage.hasContent()).isTrue();
assertThat(searchPage.stream().count()).isEqualTo(2);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand All @@ -358,7 +364,8 @@ void searchSimpleQueryForBoroughAndCuisine() {
assertThat(searchPage.isEmpty()).isFalse();
assertThat(searchPage.hasContent()).isTrue();
assertThat(searchPage.stream().count()).isEqualTo(2);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand All @@ -383,7 +390,8 @@ void searchRestaurantIdRange() {
assertThat(searchPage.isEmpty()).isFalse();
assertThat(searchPage.hasContent()).isTrue();
assertThat(searchPage.stream().count()).isEqualTo(1);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand Down Expand Up @@ -411,7 +419,8 @@ void searchDateRange() {
assertThat(searchPage.isEmpty()).isFalse();
assertThat(searchPage.hasContent()).isTrue();
assertThat(searchPage.stream().count()).isEqualTo(2);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand All @@ -437,7 +446,8 @@ void findAll() {
assertThat(searchPage.isEmpty()).isFalse();
assertThat(searchPage.hasContent()).isTrue();
assertThat(searchPage.stream().count()).isEqualTo(2);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand Down Expand Up @@ -471,7 +481,8 @@ void aggregation() {
.isNotNull()
.isExactlyInstanceOf(ElasticsearchAggregations.class);
assertThat(searchPage.stream().count()).isEqualTo(1);
Restaurant restaurant1 = searchPage.getContent().get(0).getContent();
Restaurant restaurant1 =
searchPage.getContent().getFirst().getContent();
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public Initializer(ApplicationProperties properties) {

@Override
public void run(String... args) {
log.info("Running Initializer.....");
log.info("Running Initializer..... {}", properties.getCors());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public PagedResult<Restaurant> aggregateSearch(
return new PagedResult<>(searchPage, map);
}

Function<Map<String, Aggregation>, Map<String, Map<String, Long>>> aggregationFunction =
final Function<Map<String, Aggregation>, Map<String, Map<String, Long>>> aggregationFunction =
aggregationMap -> {
Map<String, Map<String, Long>> resultMap = new HashMap<>();
aggregationMap.forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class ContainersConfig {

@Container
public static OpensearchContainer<?> openSearchContainer =
public static final OpensearchContainer<?> openSearchContainer =
new OpensearchContainer<>(DockerImageName.parse("opensearchproject/opensearch:2.14.0"))
.withEnv("OPENSEARCH_INITIAL_ADMIN_PASSWORD", "admin");

Expand All @@ -19,7 +19,6 @@ public class ContainersConfig {

@DynamicPropertySource
static void setApplicationProperties(DynamicPropertyRegistry dynamicPropertyRegistry) {
dynamicPropertyRegistry.add(
"opensearch.uris", () -> openSearchContainer.getHttpHostAddress());
dynamicPropertyRegistry.add("opensearch.uris", openSearchContainer::getHttpHostAddress);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ void shouldFindUserById() throws Exception {
parameterWithName("id")
.description("The id of the user to retrieve")),
responseFields(getUserFieldDescriptor())));
;
}

@Test
Expand Down Expand Up @@ -165,7 +164,6 @@ void shouldCreateNewUser() throws Exception {
preprocessResponse(prettyPrint()),
requestFields(getUserRequestFieldDescriptor()),
responseFields(getUserFieldDescriptor())));
;
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion boot-strategy-plugin/docker-compose-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
image: ghcr.io/rajadilipkolli/my-spring-boot-experiments/boot-strategy-plugin:latest
container_name: strategy-plugin-service
ports:
- 8080:8080
- "8080:8080"
depends_on:
grafana:
condition: service_healthy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ deleteDatasources:
- name: Prometheus
orgId: 1

# list of datasources to insert/update depending
# whats available in the database
# list of datasources to insert/update depending on what's available in the database
datasources:
# <string, required> name of the datasource. Required
- name: Prometheus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ RedisCacheConfiguration defaultCacheConfig() {
@Bean
LettuceConnectionFactory redisConnectionFactory(CacheConfigurationProperties properties) {
log.info(
"Redis (/Lettuce) configuration enabled. With cache timeout "
+ properties.getTimeoutSeconds()
+ " seconds.");
"Redis (/Lettuce) configuration enabled. With cache timeout {} seconds.",
properties.getTimeoutSeconds());

RedisStandaloneConfiguration redisStandaloneConfiguration =
new RedisStandaloneConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Post {
private List<PostComment> comments = new ArrayList<>();

@JoinColumn(name = "details_Id")
@OneToOne(cascade = CascadeType.ALL, mappedBy = "post", orphanRemoval = true, fetch = FetchType.LAZY)
@OneToOne(cascade = CascadeType.ALL, mappedBy = "post", orphanRemoval = true)
private PostDetails details;

@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.example.graphql.exception;

import java.util.Map;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.WebProperties;
import org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler;
import org.springframework.boot.web.reactive.error.ErrorAttributes;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.http.MediaType;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.server.*;
import reactor.core.publisher.Mono;

@Component
@Order(-2)
Expand All @@ -32,13 +28,4 @@ public GlobalErrorWebExceptionHandler(
protected RouterFunction<ServerResponse> getRoutingFunction(ErrorAttributes errorAttributes) {
return RouterFunctions.route(RequestPredicates.all(), this::renderErrorResponse);
}

@Override
protected Mono<ServerResponse> renderErrorResponse(ServerRequest request) {
Map<String, Object> error =
this.getErrorAttributes(request, this.getErrorAttributeOptions(request, MediaType.ALL));
return ServerResponse.status(this.getHttpStatus(error))
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(error));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ deleteDatasources:
- name: Prometheus
orgId: 1

# list of datasources to insert/update depending
# whats available in the database
# list of datasources to insert/update depending on what's available in the database
datasources:
- name: Prometheus
type: prometheus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@ public LocalDateTime parseValue(
// Will be String if the value is specified via external variables object,
// and a StringValue
// if provided direct in the query.
if (input instanceof StringValue stringValue) {
return parseString(stringValue.getValue());
}
if (input instanceof String inputString) {
return parseString(inputString);
}
if (input instanceof LocalDateTime localDateTime) {
return localDateTime;
}
throw new CoercingParseValueException(
"Expected a 'String' but was '" + typeName(input) + "'.");
return switch (input) {
case StringValue stringValue -> parseString(stringValue.getValue());
case String inputString -> parseString(inputString);
case LocalDateTime localDateTime -> localDateTime;
default ->
throw new CoercingParseValueException(
"Expected a 'String' but was '"
+ typeName(input)
+ "'.");
};
}

private LocalDateTime parseString(String input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.example.graphql.model.response.AuthorResponse;
import com.example.graphql.repositories.AuthorRepository;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.ConversionService;
Expand Down Expand Up @@ -45,7 +46,7 @@ public AuthorResponse saveAuthor(AuthorRequest authorRequest) {
AuthorEntity authorEntity =
this.appConversionService.convert(authorRequest, AuthorEntity.class);
return this.appConversionService.convert(
authorRepository.save(authorEntity), AuthorResponse.class);
authorRepository.save(Objects.requireNonNull(authorEntity)), AuthorResponse.class);
}

public Optional<AuthorResponse> updateAuthor(AuthorRequest authorRequest, Long id) {
Expand Down
Loading

0 comments on commit d351ec5

Please sign in to comment.