Skip to content

Commit

Permalink
fix: Add @value annotation in the constructor (#396)
Browse files Browse the repository at this point in the history
* fix: Add @value annotation in the constructor complying with Rule_2.7 of the plugin's architecture rule

* Add SuppressWarnings annotation in adapter operations

* fix: Update localstack endpoint for S3 in local environment
  • Loading branch information
luisgomez29 authored Oct 27, 2023
1 parent 29d9ce8 commit a88edd9
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
.appendToProperties("adapter.aws.s3")
.put("bucketName", "test")
.put("region", "us-east-1")
.put("endpoint", "http://localhost:49153");
.put("endpoint", "https://s3.localhost.localstack.cloud:4566");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":s3-repository");
builder.appendDependencyToModule(APP_SERVICE, dependency);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package {{package}}.consumer;

{{#lombok}}
import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
{{/lombok}}
public class ObjectRequest {
private String val1;
private String val2;
private String val1;
private String val2;
{{^lombok}}
public ObjectRequest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package {{package}}.consumer;

{{#lombok}}
import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
{{/lombok}}
public class ObjectResponse {
private String state;
private String state;
{{^lombok}}
public ObjectResponse() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
@Configuration
public class RestConsumerConfig {
@Value("${adapter.restconsumer.url}")
private String url;
@Value("${adapter.restconsumer.timeout}")
private int timeout;
private final String url;
private final int timeout;
public RestConsumerConfig(@Value("${adapter.restconsumer.url}") String url,
@Value("${adapter.restconsumer.timeout}") int timeout) {
this.url = url;
this.timeout = timeout;
}

@Bean
public WebClient getWebClient(WebClient.Builder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class AdapterOperations<E, D, I, R extends CrudRepository<D, I>
protected ObjectMapper mapper;
private Function<D, E> toEntityFn;
@SuppressWarnings("unchecked")
protected AdapterOperations(R repository, ObjectMapper mapper, Function<D, E> toEntityFn) {
this.repository = repository;
this.mapper = mapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package {{package}}.kms;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
Expand All @@ -15,20 +14,16 @@ import software.amazon.awssdk.services.kms.model.EncryptionAlgorithmSpec;
import java.util.Base64;

@Component
{{#lombok}}
@RequiredArgsConstructor
{{/lombok}}
public class KmsAdapter // implements ModelRepository from domain
{
@Value("${adapters.aws.kms.keyId}")
private String keyId;
private final String keyId;
private final KmsAsyncClient kmsAsyncClient;
{{^lombok}}
public KmsAdapter(KmsAsyncClient kmsAsyncClient ) {
this.kmsAsyncClient = kmsAsyncClient;
public KmsAdapter(@Value("${adapters.aws.kms.keyId}") String keyId, KmsAsyncClient kmsAsyncClient) {
this.keyId = keyId;
this.kmsAsyncClient = kmsAsyncClient;
}
{{/lombok}}

public Mono<byte[]> decrypt(String secretKey) {
return Mono.fromFuture(kmsAsyncClient.decrypt(getDecryptRequest(secretKey, keyId)))
.map(DecryptResponse::plaintext)
Expand Down
17 changes: 5 additions & 12 deletions src/main/resources/driven-adapter/kms/kms-adapter.java.mustache
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package {{package}}.kms;

{{#lombok}}
import lombok.RequiredArgsConstructor;
{{/lombok}}
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import software.amazon.awssdk.core.SdkBytes;
Expand All @@ -15,20 +12,16 @@ import java.util.Base64;
import java.util.concurrent.ExecutionException;

@Component
{{#lombok}}
@RequiredArgsConstructor
{{/lombok}}
public class KmsAdapter // implements ModelRepository from domain
{
@Value("${adapters.aws.kms.keyId}")
private String keyId;
private final String keyId;
private final KmsAsyncClient kmsAsyncClient;
{{^lombok}}
public KmsAdapter(KmsAsyncClient kmsAsyncClient ) {
this.kmsAsyncClient = kmsAsyncClient;
public KmsAdapter(@Value("${adapters.aws.kms.keyId}") String keyId, KmsAsyncClient kmsAsyncClient) {
this.keyId = keyId;
this.kmsAsyncClient = kmsAsyncClient;
}
{{/lombok}}

public byte[] decrypt(String secretKey) throws ExecutionException, InterruptedException {
return kmsAsyncClient.decrypt(getDecryptRequest(secretKey, keyId))
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class AdapterOperations<E, D, I, R extends MongoRepository<D, I>
protected ObjectMapper mapper;
private Function<D, E> toEntityFn;
@SuppressWarnings("unchecked")
protected AdapterOperations(R repository, ObjectMapper mapper, Function<D, E> toEntityFn) {
this.repository = repository;
this.mapper = mapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public abstract class ReactiveAdapterOperations<E, D, I, R extends ReactiveCrudR
private final Class<D> dataClass;
private final Function<D, E> toEntityFn;
@SuppressWarnings("unchecked")
protected ReactiveAdapterOperations(R repository, ObjectMapper mapper, Function<D, E> toEntityFn) {
this.repository = repository;
this.mapper = mapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package {{package}}.sqs.sender;

import {{package}}.sqs.sender.config.SQSSenderProperties;
{{#lombok}}
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
{{/lombok}}
import org.springframework.stereotype.Service;
Expand All @@ -14,7 +14,7 @@ import software.amazon.awssdk.services.sqs.model.SendMessageResponse;
@Service
{{#lombok}}
@Log4j2
@AllArgsConstructor
@RequiredArgsConstructor
{{/lombok}}
public class SQSSender /*implements SomeGateway*/ {
{{^lombok}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package {{package}}.sqs.sender;

import {{package}}.sqs.sender.config.SQSSenderProperties;
{{#lombok}}
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
{{/lombok}}
Expand All @@ -14,7 +14,7 @@ import software.amazon.awssdk.services.sqs.model.SendMessageResponse;
@Service
{{#lombok}}
@Log4j2
@AllArgsConstructor
@RequiredArgsConstructor
{{/lombok}}
public class SQSSender /*implements SomeGateway*/ {
{{^lombok}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class SQSListener {
{{/metrics}}
ExecutorService service = Executors.newFixedThreadPool(properties.getNumberOfThreads());
Flux<Void> flow = listenRetryRepeat().publishOn(Schedulers.fromExecutorService(service));
for (int i = 0; i < properties.getNumberOfThreads(); i++) {
for (var i = 0; i < properties.getNumberOfThreads(); i++) {
flow.subscribe();
}
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package {{package}}.sqs.listener;

{{#lombok}}
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
{{/lombok}}
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
Expand All @@ -11,7 +11,7 @@ import java.util.function.Function;

@Service
{{#lombok}}
@AllArgsConstructor
@RequiredArgsConstructor
{{/lombok}}
public class SQSProcessor implements Function<Message, Mono<Void>> {
// private final MyUseCase myUseCase;
Expand Down

0 comments on commit a88edd9

Please sign in to comment.