diff --git a/samples/choreography-saga-quickstart/src/main/java/user/registry/api/UserEndpoint.java b/samples/choreography-saga-quickstart/src/main/java/user/registry/api/UserEndpoint.java index ac0cde654..ffb3b8a29 100644 --- a/samples/choreography-saga-quickstart/src/main/java/user/registry/api/UserEndpoint.java +++ b/samples/choreography-saga-quickstart/src/main/java/user/registry/api/UserEndpoint.java @@ -173,7 +173,7 @@ public CompletionStage getUserInfo(String userId) { @Get("/by-country/{country}") - public CompletionStage getUsersByCountry(String country) { + public CompletionStage getUsersByCountry(String country) { return client.forView() .method(UsersByCountryView::getUserByCountry) diff --git a/samples/choreography-saga-quickstart/src/main/java/user/registry/application/UsersByCountryView.java b/samples/choreography-saga-quickstart/src/main/java/user/registry/application/UsersByCountryView.java index d5517f9e5..748856086 100644 --- a/samples/choreography-saga-quickstart/src/main/java/user/registry/application/UsersByCountryView.java +++ b/samples/choreography-saga-quickstart/src/main/java/user/registry/application/UsersByCountryView.java @@ -16,19 +16,19 @@ /** * A View to query users by country. */ -@ComponentId("view-users-by-newCountry") +@ComponentId("users-by-country") public class UsersByCountryView extends View { private static Logger logger = LoggerFactory.getLogger(UsersByCountryView.class); @Consume.FromEventSourcedEntity(value = UserEntity.class) - public static class UsersByCountry extends TableUpdater { - public Effect onEvent(UserEvent evt) { + public static class UsersByCountryUpdater extends TableUpdater { + public Effect onEvent(UserEvent evt) { return switch (evt) { case UserWasCreated created -> { logger.info("User was created: {}", created); var currentId = updateContext().eventSubject().orElseThrow(); - yield effects().updateRow(new UserView(currentId, created.name(), created.country(), created.email())); + yield effects().updateRow(new UserEntry(currentId, created.name(), created.country(), created.email())); } case EmailAssigned emailAssigned -> { logger.info("User address changed: {}", emailAssigned); @@ -41,16 +41,16 @@ public Effect onEvent(UserEvent evt) { } } - public record UserView(String id, String name, String country, String email) { - public UserView withEmail(String email) { - return new UserView(id, name, country, email); + public record UserEntry(String id, String name, String country, String email) { + public UserEntry withEmail(String email) { + return new UserEntry(id, name, country, email); } } - public record UserList(List users) { } + public record UserEntries(List users) { } @Query("SELECT * AS users FROM users_by_country WHERE country = :country") - public QueryEffect getUserByCountry(String country) { + public QueryEffect getUserByCountry(String country) { return queryResult(); } diff --git a/samples/event-sourced-counter-brokers/src/main/java/counter/application/CounterByValueViewEnrichment.java b/samples/event-sourced-counter-brokers/src/main/java/counter/application/CounterByValueViewEnrichment.java index 883adb45d..42f703c9f 100644 --- a/samples/event-sourced-counter-brokers/src/main/java/counter/application/CounterByValueViewEnrichment.java +++ b/samples/event-sourced-counter-brokers/src/main/java/counter/application/CounterByValueViewEnrichment.java @@ -14,35 +14,35 @@ @ComponentId("counter-by-value-enrichment") public class CounterByValueViewEnrichment extends View { - public record CounterByValue(String name, int value) { + public record CounterByValueEntry(String name, int value) { } - public record CounterByValueList(List counters) { + public record CounterByValueEntries(List counters) { } // tag::events-enrichment[] @Consume.FromEventSourcedEntity(CounterEntity.class) - public static class CounterByValueUpdater extends TableUpdater { - public Effect onEvent(CounterEvent counterEvent) { + public static class CounterByValueUpdater extends TableUpdater { + public Effect onEvent(CounterEvent counterEvent) { var name = updateContext().eventSubject().get(); return switch (counterEvent) { case ValueIncreased increased -> effects().updateRow( - new CounterByValue(name, increased.updatedValue())); // <1> + new CounterByValueEntry(name, increased.updatedValue())); // <1> case ValueMultiplied multiplied -> effects().updateRow( - new CounterByValue(name, multiplied.updatedValue())); // <1> + new CounterByValueEntry(name, multiplied.updatedValue())); // <1> }; } } // end::events-enrichment[] @Query("SELECT * AS counters FROM counter_by_value WHERE value > :value") - public QueryEffect findByCountersByValueGreaterThan(int value) { + public QueryEffect findByCountersByValueGreaterThan(int value) { return queryResult(); } @Query("SELECT * AS counters FROM counter_by_value") - public QueryEffect findAll() { + public QueryEffect findAll() { return queryResult(); } // tag::events-enrichment[] diff --git a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/api/CustomerRegistryEndpoint.java b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/api/CustomerRegistryEndpoint.java index 5fb10a6ce..a1a24bb1b 100644 --- a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/api/CustomerRegistryEndpoint.java +++ b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/api/CustomerRegistryEndpoint.java @@ -12,7 +12,7 @@ import akka.javasdk.http.HttpException; import akka.javasdk.http.HttpResponses; import customer.application.CustomersByNameView; -import customer.domain.CustomersList; +import customer.domain.CustomerEntries; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,7 +62,7 @@ public CompletionStage create(String id, CreateCustomerRequest cre // end::cross-service-call[] @Get("/by_name/{name}") - public CompletionStage findByName(String name) { + public CompletionStage findByName(String name) { return componentClient.forView().method(CustomersByNameView::findByName).invokeAsync(name); } } diff --git a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/application/CustomersByEmailView.java b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/application/CustomersByEmailView.java index 45ee62c21..4421230df 100644 --- a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/application/CustomersByEmailView.java +++ b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/application/CustomersByEmailView.java @@ -1,19 +1,18 @@ package customer.application; -import akka.javasdk.annotations.Acl; import akka.javasdk.annotations.ComponentId; import akka.javasdk.annotations.Consume; import akka.javasdk.annotations.Query; import akka.javasdk.view.TableUpdater; import akka.javasdk.view.View; -import customer.domain.Customer; -import customer.domain.CustomersList; +import customer.domain.CustomerEntry; +import customer.domain.CustomerEntries; import org.slf4j.Logger; import org.slf4j.LoggerFactory; // tag::view[] -@ComponentId("customers_by_email_view") +@ComponentId("customers-by-email") public class CustomersByEmailView extends View { // end::view[] private static final Logger logger = LoggerFactory.getLogger(CustomersByEmailView.class); @@ -24,17 +23,17 @@ public class CustomersByEmailView extends View { id = "customer_events", // <3> consumerGroup = "customer-by-email-view" // <4> ) - public static class CustomersByEmail extends TableUpdater { - public Effect onEvent(CustomerPublicEvent.Created created) { + public static class CustomersByEmailUpdater extends TableUpdater { + public Effect onEvent(CustomerPublicEvent.Created created) { // end::view[] logger.info("Received: {}", created); // tag::view[] var id = updateContext().eventSubject().get(); return effects().updateRow( - new Customer(id, created.email(), created.name())); + new CustomerEntry(id, created.email(), created.name())); } - public Effect onEvent(CustomerPublicEvent.NameChanged nameChanged) { + public Effect onEvent(CustomerPublicEvent.NameChanged nameChanged) { // end::view[] logger.info("Received: {}", nameChanged); // tag::view[] @@ -44,7 +43,7 @@ public Effect onEvent(CustomerPublicEvent.NameChanged nameChanged) { } @Query("SELECT * AS customers FROM customers_by_email WHERE email = :email") - public QueryEffect findByEmail(String email) { + public QueryEffect findByEmail(String email) { return queryResult(); } diff --git a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/application/CustomersByNameView.java b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/application/CustomersByNameView.java index 5a36f6c15..660227917 100644 --- a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/application/CustomersByNameView.java +++ b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/application/CustomersByNameView.java @@ -1,18 +1,17 @@ package customer.application; -import akka.javasdk.annotations.Acl; import akka.javasdk.annotations.Query; import akka.javasdk.annotations.Consume; import akka.javasdk.annotations.ComponentId; import akka.javasdk.view.View; import akka.javasdk.view.TableUpdater; -import customer.domain.Customer; -import customer.domain.CustomersList; +import customer.domain.CustomerEntry; +import customer.domain.CustomerEntries; import org.slf4j.Logger; import org.slf4j.LoggerFactory; // tag::view[] -@ComponentId("customers_by_name") +@ComponentId("customers-by-name") public class CustomersByNameView extends View { // end::view[] private static final Logger logger = LoggerFactory.getLogger(CustomersByNameView.class); @@ -23,19 +22,19 @@ public class CustomersByNameView extends View { id = "customer_events", // <3> consumerGroup = "customer-by-name-view" // <4> ) - public static class CustomersByName extends TableUpdater { + public static class CustomersByNameUpdater extends TableUpdater { - public Effect onEvent( // <5> - CustomerPublicEvent.Created created) { + public Effect onEvent( // <5> + CustomerPublicEvent.Created created) { // end::view[] logger.info("Received: {}", created); // tag::view[] var id = updateContext().eventSubject().get(); return effects().updateRow( - new Customer(id, created.email(), created.name())); + new CustomerEntry(id, created.email(), created.name())); } - public Effect onEvent( + public Effect onEvent( CustomerPublicEvent.NameChanged nameChanged) { // end::view[] logger.info("Received: {}", nameChanged); @@ -46,7 +45,7 @@ public Effect onEvent( } @Query("SELECT * as customers FROM customers_by_name WHERE name = :name") - public QueryEffect findByName(String name) { + public QueryEffect findByName(String name) { return queryResult(); } diff --git a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/Customer.java b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/Customer.java deleted file mode 100644 index 4be853009..000000000 --- a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/Customer.java +++ /dev/null @@ -1,7 +0,0 @@ -package customer.domain; - -public record Customer(String id, String email, String name) { - public Customer withName(String newName) { - return new Customer(id, email, newName); - } -} diff --git a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/CustomerEntries.java b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/CustomerEntries.java new file mode 100644 index 000000000..14028b9ec --- /dev/null +++ b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/CustomerEntries.java @@ -0,0 +1,6 @@ +package customer.domain; + +import java.util.Collection; + +public record CustomerEntries(Collection customers) { +} diff --git a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/CustomerEntry.java b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/CustomerEntry.java new file mode 100644 index 000000000..d1fe8d334 --- /dev/null +++ b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/CustomerEntry.java @@ -0,0 +1,7 @@ +package customer.domain; + +public record CustomerEntry(String id, String email, String name) { + public CustomerEntry withName(String newName) { + return new CustomerEntry(id, email, newName); + } +} diff --git a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/CustomersList.java b/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/CustomersList.java deleted file mode 100644 index 7f36044d5..000000000 --- a/samples/event-sourced-customer-registry-subscriber/src/main/java/customer/domain/CustomersList.java +++ /dev/null @@ -1,6 +0,0 @@ -package customer.domain; - -import java.util.Collection; - -public record CustomersList(Collection customers) { -} diff --git a/samples/event-sourced-customer-registry-subscriber/src/test/java/customer/api/CustomerIntegrationTest.java b/samples/event-sourced-customer-registry-subscriber/src/test/java/customer/api/CustomerIntegrationTest.java index d44288b79..b418deff5 100644 --- a/samples/event-sourced-customer-registry-subscriber/src/test/java/customer/api/CustomerIntegrationTest.java +++ b/samples/event-sourced-customer-registry-subscriber/src/test/java/customer/api/CustomerIntegrationTest.java @@ -2,12 +2,11 @@ import akka.http.javadsl.model.StatusCodes; -import akka.javasdk.http.HttpClient; import akka.javasdk.http.StrictResponse; import akka.util.ByteString; import customer.api.CustomerRegistryEndpoint.CreateCustomerRequest; import customer.application.CustomersByNameView; -import customer.domain.Customer; +import customer.domain.CustomerEntry; import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; @@ -62,7 +61,7 @@ public void create() { componentClient.forView() .method(CustomersByNameView::findByName) .invokeAsync(createRequest.name()) - ).customers().stream().map(Customer::name); + ).customers().stream().map(CustomerEntry::name); assertThat(foundCustomers).containsExactly(createRequest.name()); }); diff --git a/samples/event-sourced-customer-registry-subscriber/src/test/java/customer/api/CustomersByNameViewIntegrationTest.java b/samples/event-sourced-customer-registry-subscriber/src/test/java/customer/api/CustomersByNameViewIntegrationTest.java index 8b3dd8995..b31cefabe 100644 --- a/samples/event-sourced-customer-registry-subscriber/src/test/java/customer/api/CustomersByNameViewIntegrationTest.java +++ b/samples/event-sourced-customer-registry-subscriber/src/test/java/customer/api/CustomersByNameViewIntegrationTest.java @@ -1,6 +1,6 @@ package customer.api; -import customer.domain.Customer; +import customer.domain.CustomerEntry; import customer.application.CustomerPublicEvent.Created; import customer.application.CustomersByEmailView; import customer.application.CustomersByNameView; @@ -38,23 +38,23 @@ public void shouldReturnCustomersFromViews() { .pollInterval(1, TimeUnit.SECONDS) .untilAsserted(() -> { - Customer customer = + CustomerEntry customer = await( componentClient.forView() .method(CustomersByNameView::findByName) .invokeAsync(created1.name()) ).customers().stream().findFirst().get(); - assertThat(customer).isEqualTo(new Customer("b", created1.email(), created1.name())); + assertThat(customer).isEqualTo(new CustomerEntry("b", created1.email(), created1.name())); - Customer customer2 = + CustomerEntry customer2 = await( componentClient.forView() .method(CustomersByEmailView::findByEmail) .invokeAsync(created2.email()) ).customers().stream().findFirst().get(); - assertThat(customer2).isEqualTo(new Customer("a", created2.email(), created2.name())); + assertThat(customer2).isEqualTo(new CustomerEntry("a", created2.email(), created2.name())); } ); diff --git a/samples/event-sourced-customer-registry/src/main/java/customer/api/CustomerEndpoint.java b/samples/event-sourced-customer-registry/src/main/java/customer/api/CustomerEndpoint.java index 2d037297a..d33835125 100644 --- a/samples/event-sourced-customer-registry/src/main/java/customer/api/CustomerEndpoint.java +++ b/samples/event-sourced-customer-registry/src/main/java/customer/api/CustomerEndpoint.java @@ -9,12 +9,12 @@ import akka.javasdk.client.ComponentClient; import akka.javasdk.http.HttpException; import akka.javasdk.http.HttpResponses; -import customer.application.CustomerByEmailView; -import customer.application.CustomerByNameView; +import customer.application.CustomersByEmailView; +import customer.application.CustomersByNameView; import customer.application.CustomerEntity; import customer.domain.Address; import customer.domain.Customer; -import customer.domain.CustomersList; +import customer.domain.CustomerEntries; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,16 +76,16 @@ public CompletionStage changeAddress(String customerId, Address ne } @Get("/by-name/{name}") - public CompletionStage customerByName(String name) { + public CompletionStage customerByName(String name) { return componentClient.forView() - .method(CustomerByNameView::getCustomers) + .method(CustomersByNameView::getCustomers) .invokeAsync(name); } @Get("/by-email/{email}") - public CompletionStage customerByEmail(String email) { + public CompletionStage customerByEmail(String email) { return componentClient.forView() - .method(CustomerByEmailView::getCustomers) + .method(CustomersByEmailView::getCustomers) .invokeAsync(email); } } diff --git a/samples/event-sourced-customer-registry/src/main/java/customer/api/CustomerGrpcEndpointImpl.java b/samples/event-sourced-customer-registry/src/main/java/customer/api/CustomerGrpcEndpointImpl.java index 22afe9e85..524a92fd4 100644 --- a/samples/event-sourced-customer-registry/src/main/java/customer/api/CustomerGrpcEndpointImpl.java +++ b/samples/event-sourced-customer-registry/src/main/java/customer/api/CustomerGrpcEndpointImpl.java @@ -7,14 +7,14 @@ import akka.javasdk.client.ComponentClient; import akka.stream.javadsl.Source; import customer.api.proto.*; -import customer.application.CustomerByEmailView; -import customer.application.CustomerByNameView; +import customer.application.CustomersByEmailView; +import customer.application.CustomersByNameView; import customer.application.CustomerEntity; +import customer.domain.CustomerEntry; import io.grpc.Status; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; @Acl(allow = @Acl.Matcher(principal = Acl.Principal.ALL)) @@ -91,7 +91,7 @@ public CompletionStage changeAddress(ChangeAddressRequest @Override public CompletionStage customerByName(CustomerByNameRequest in) { return componentClient.forView() - .method(CustomerByNameView::getCustomers) + .method(CustomersByNameView::getCustomers) .invokeAsync(in.getName()) .thenApply(viewCustomerList -> { var apiCustomers = viewCustomerList.customers().stream().map(this::domainToApi).toList(); @@ -103,7 +103,7 @@ public CompletionStage customerByName(CustomerByNameRequest in) { @Override public CompletionStage customerByEmail(CustomerByEmailRequest in) { return componentClient.forView() - .method(CustomerByEmailView::getCustomers) + .method(CustomersByEmailView::getCustomers) .invokeAsync(in.getEmail()) .thenApply(viewCustomerList -> { var apiCustomers = viewCustomerList.customers().stream().map(this::domainToApi).toList(); @@ -118,7 +118,7 @@ public Source customerByEmailStream(CustomerByEmailReq // Shows of streaming consumption of a view, transforming // each element and passing along to a streamed response var customerSummarySource = componentClient.forView() - .stream(CustomerByEmailView::getCustomersStream) + .stream(CustomersByEmailView::getCustomersStream) .source(in.getEmail()); return customerSummarySource.map(c -> @@ -170,7 +170,7 @@ private Address domainToApi(customer.domain.Address domainAddress) { } // end::endpoint-component-interaction[] - private Customer domainToApi(customer.domain.CustomerRow domainRow) { + private Customer domainToApi(CustomerEntry domainRow) { return Customer.newBuilder() .setName(domainRow.name()) .setEmail(domainRow.email()) diff --git a/samples/event-sourced-customer-registry/src/main/java/customer/application/CustomerByEmailView.java b/samples/event-sourced-customer-registry/src/main/java/customer/application/CustomersByEmailView.java similarity index 67% rename from samples/event-sourced-customer-registry/src/main/java/customer/application/CustomerByEmailView.java rename to samples/event-sourced-customer-registry/src/main/java/customer/application/CustomersByEmailView.java index e07ea251c..10794e706 100644 --- a/samples/event-sourced-customer-registry/src/main/java/customer/application/CustomerByEmailView.java +++ b/samples/event-sourced-customer-registry/src/main/java/customer/application/CustomersByEmailView.java @@ -6,29 +6,29 @@ import akka.javasdk.view.TableUpdater; import akka.javasdk.view.View; import customer.domain.CustomerEvent; -import customer.domain.CustomerRow; -import customer.domain.CustomersList; +import customer.domain.CustomerEntry; +import customer.domain.CustomerEntries; -@ComponentId("view_customers_by_email") -public class CustomerByEmailView extends View { +@ComponentId("customers-by-email") +public class CustomersByEmailView extends View { @Query("SELECT * as customers FROM customers_by_email WHERE email = :email") - public QueryEffect getCustomers(String email) { + public QueryEffect getCustomers(String email) { return queryResult(); } @Query(value = "SELECT * FROM customers_by_email WHERE email = :email", streamUpdates = true) - public QueryStreamEffect getCustomersStream(String email) { + public QueryStreamEffect getCustomersStream(String email) { return queryStreamResult(); } @Consume.FromEventSourcedEntity(CustomerEntity.class) - public static class CustomersByEmail extends TableUpdater { + public static class CustomersByEmail extends TableUpdater { - public Effect onEvent(CustomerEvent event) { // <1> + public Effect onEvent(CustomerEvent event) { // <1> return switch (event) { case CustomerEvent.CustomerCreated created -> - effects().updateRow(new CustomerRow(created.email(), created.name(), created.address())); + effects().updateRow(new CustomerEntry(created.email(), created.name(), created.address())); case CustomerEvent.NameChanged nameChanged -> effects().updateRow(rowState().withName(nameChanged.newName())); diff --git a/samples/event-sourced-customer-registry/src/main/java/customer/application/CustomerByNameView.java b/samples/event-sourced-customer-registry/src/main/java/customer/application/CustomersByNameView.java similarity index 62% rename from samples/event-sourced-customer-registry/src/main/java/customer/application/CustomerByNameView.java rename to samples/event-sourced-customer-registry/src/main/java/customer/application/CustomersByNameView.java index fd5685436..865036c09 100644 --- a/samples/event-sourced-customer-registry/src/main/java/customer/application/CustomerByNameView.java +++ b/samples/event-sourced-customer-registry/src/main/java/customer/application/CustomersByNameView.java @@ -8,19 +8,19 @@ import akka.javasdk.view.TableUpdater; import akka.javasdk.view.View; import customer.domain.CustomerEvent; -import customer.domain.CustomerRow; -import customer.domain.CustomersList; +import customer.domain.CustomerEntry; +import customer.domain.CustomerEntries; -@ComponentId("view_customers_by_name") // <1> -public class CustomerByNameView extends View { +@ComponentId("customers-by-name") // <1> +public class CustomersByNameView extends View { @Consume.FromEventSourcedEntity(CustomerEntity.class) - public static class CustomersByName extends TableUpdater { // <2> + public static class CustomersByNameUpdater extends TableUpdater { // <2> - public Effect onEvent(CustomerEvent event) { // <3> + public Effect onEvent(CustomerEvent event) { // <3> return switch (event) { case CustomerEvent.CustomerCreated created -> - effects().updateRow(new CustomerRow(created.email(), created.name(), created.address())); + effects().updateRow(new CustomerEntry(created.email(), created.name(), created.address())); case CustomerEvent.NameChanged nameChanged -> effects().updateRow(rowState().withName(nameChanged.newName())); @@ -32,7 +32,7 @@ public Effect onEvent(CustomerEvent event) { // <3> } @Query("SELECT * as customers FROM customers_by_name WHERE name = :name") - public QueryEffect getCustomers(String name) { + public QueryEffect getCustomers(String name) { return queryResult(); } diff --git a/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomerEntries.java b/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomerEntries.java new file mode 100644 index 000000000..14028b9ec --- /dev/null +++ b/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomerEntries.java @@ -0,0 +1,6 @@ +package customer.domain; + +import java.util.Collection; + +public record CustomerEntries(Collection customers) { +} diff --git a/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomerEntry.java b/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomerEntry.java new file mode 100644 index 000000000..0aab9c332 --- /dev/null +++ b/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomerEntry.java @@ -0,0 +1,12 @@ +package customer.domain; + +public record CustomerEntry(String email, String name, Address address) { + + public CustomerEntry withName(String newName) { + return new CustomerEntry(email, newName, address); + } + + public CustomerEntry withAddress(Address newAddress) { + return new CustomerEntry(email, name, newAddress); + } +} diff --git a/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomerRow.java b/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomerRow.java deleted file mode 100644 index 52cd8b4f3..000000000 --- a/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomerRow.java +++ /dev/null @@ -1,14 +0,0 @@ -package customer.domain; - -import customer.domain.Address; - -public record CustomerRow(String email, String name, Address address) { - - public CustomerRow withName(String newName) { - return new CustomerRow(email, newName, address); - } - - public CustomerRow withAddress(Address newAddress) { - return new CustomerRow(email, name, newAddress); - } -} diff --git a/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomersList.java b/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomersList.java deleted file mode 100644 index 3af66b8ce..000000000 --- a/samples/event-sourced-customer-registry/src/main/java/customer/domain/CustomersList.java +++ /dev/null @@ -1,6 +0,0 @@ -package customer.domain; - -import java.util.Collection; - -public record CustomersList(Collection customers) { -} diff --git a/samples/event-sourced-customer-registry/src/test/java/customer/api/CustomerIntegrationTest.java b/samples/event-sourced-customer-registry/src/test/java/customer/api/CustomerIntegrationTest.java index ab1066384..07c2a76a9 100644 --- a/samples/event-sourced-customer-registry/src/test/java/customer/api/CustomerIntegrationTest.java +++ b/samples/event-sourced-customer-registry/src/test/java/customer/api/CustomerIntegrationTest.java @@ -5,8 +5,8 @@ import customer.application.CustomerEntity; import customer.domain.Address; import customer.domain.Customer; -import customer.application.CustomerByEmailView; -import customer.application.CustomerByNameView; +import customer.application.CustomersByEmailView; +import customer.application.CustomersByNameView; import akka.javasdk.testkit.TestKitSupport; import org.awaitility.Awaitility; import org.hamcrest.core.IsEqual; @@ -94,7 +94,7 @@ public void findByName() { .until(() -> await( componentClient.forView() - .method(CustomerByNameView::getCustomers) + .method(CustomersByNameView::getCustomers) .invokeAsync("Foo") ).customers().stream().findFirst().get().name(), new IsEqual("Foo") @@ -119,7 +119,7 @@ public void findByEmail() { .until(() -> await( componentClient.forView() - .method(CustomerByEmailView::getCustomers) + .method(CustomersByEmailView::getCustomers) .invokeAsync("bar@example.com") ).customers().stream().findFirst().get().name(), new IsEqual("Bar") diff --git a/samples/key-value-customer-registry/src/main/java/customer/application/CustomerSummaryByName.java b/samples/key-value-customer-registry/src/main/java/customer/application/CustomerSummaryByName.java index 16b38d1c4..d6dfe032c 100644 --- a/samples/key-value-customer-registry/src/main/java/customer/application/CustomerSummaryByName.java +++ b/samples/key-value-customer-registry/src/main/java/customer/application/CustomerSummaryByName.java @@ -8,14 +8,14 @@ import akka.javasdk.annotations.ComponentId; import akka.javasdk.view.View; -@ComponentId("summary_customer_by_name") +@ComponentId("customers-by-name") public class CustomerSummaryByName extends View { public record CustomerSummary(String id, String name) { } // tag::delete[] @Consume.FromKeyValueEntity(value = CustomerEntity.class) - public static class Customers extends TableUpdater { // <1> + public static class CustomersUpdater extends TableUpdater { // <1> public Effect onUpdate(Customer customer) { return effects() .updateRow(new CustomerSummary(updateContext().eventSubject().get(), customer.name())); diff --git a/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByCity.java b/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByCity.java index 9e756a67e..456532a73 100644 --- a/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByCity.java +++ b/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByCity.java @@ -9,12 +9,12 @@ import java.util.List; -@ComponentId("customers_by_city") +@ComponentId("customers-by-city") // tag::view-test[] public class CustomersByCity extends View { @Consume.FromKeyValueEntity(CustomerEntity.class) - public static class Customers extends TableUpdater {} + public static class CustomerUpdater extends TableUpdater {} @Query(""" SELECT * AS customers diff --git a/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByEmail.java b/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByEmail.java index 84fb073aa..820841566 100644 --- a/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByEmail.java +++ b/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByEmail.java @@ -11,13 +11,13 @@ import java.util.List; -@ComponentId("customers_by_email") // <1> +@ComponentId("customers-by-email") // <1> public class CustomersByEmail extends View { // <2> public record Customers(List customers) { } @Consume.FromKeyValueEntity(CustomerEntity.class) // <3> - public static class CustomerByEmail extends TableUpdater { } // <4> + public static class CustomersByEmailUpdater extends TableUpdater { } // <4> @Query("SELECT * AS customers FROM customers_by_email WHERE email = :email") // <5> public QueryEffect getCustomer(String email) { diff --git a/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByName.java b/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByName.java index 1275739ab..7dd2afbd4 100644 --- a/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByName.java +++ b/samples/key-value-customer-registry/src/main/java/customer/application/CustomersByName.java @@ -11,7 +11,7 @@ import java.util.Collection; -@ComponentId("customers_by_name") +@ComponentId("customers-by-name") public class CustomersByName extends View { // tag::row[] @@ -19,7 +19,7 @@ public record CustomerSummary(String customerId, String name, String email) { } // end::row[] @Consume.FromKeyValueEntity(CustomerEntity.class) - public static class CustomerByNameUpdater extends TableUpdater { // <1> + public static class CustomersByNameUpdater extends TableUpdater { // <1> public Effect onUpdate(Customer customer) { // <2> return effects() .updateRow(new CustomerSummary(updateContext().eventSubject().get(), customer.name(), customer.email())); // <3> @@ -32,10 +32,10 @@ public QueryEffect getFirstCustomerSummary(String name) { // <5 } // end::class[] - public record Customers(Collection customers) { } // <6> + public record CustomerSummaries(Collection customers) { } // <6> @Query("SELECT * AS customers FROM customers_by_name WHERE name = :name") // <7> - public QueryEffect getCustomers(String name) { + public QueryEffect getCustomers(String name) { return queryResult(); // <8> } diff --git a/samples/key-value-customer-registry/src/main/java/customer/application/CustomersResponseByName.java b/samples/key-value-customer-registry/src/main/java/customer/application/CustomersResponseByName.java index daef96d2a..a0c2a3960 100644 --- a/samples/key-value-customer-registry/src/main/java/customer/application/CustomersResponseByName.java +++ b/samples/key-value-customer-registry/src/main/java/customer/application/CustomersResponseByName.java @@ -7,12 +7,12 @@ import akka.javasdk.annotations.ComponentId; import akka.javasdk.view.View; -@ComponentId("customers_by_name_2") +@ComponentId("customers-by-name") // tag::class[] public class CustomersResponseByName extends View { @Consume.FromKeyValueEntity(CustomerEntity.class) - public static class Customers extends TableUpdater { } // <1> + public static class CustomersByNameUpdater extends TableUpdater { } // <1> @Query(""" SELECT * AS customers diff --git a/samples/transfer-workflow/src/main/java/com/example/transfer/api/TransferEndpoint.java b/samples/transfer-workflow/src/main/java/com/example/transfer/api/TransferEndpoint.java index a57f57aa9..db41bdd3a 100644 --- a/samples/transfer-workflow/src/main/java/com/example/transfer/api/TransferEndpoint.java +++ b/samples/transfer-workflow/src/main/java/com/example/transfer/api/TransferEndpoint.java @@ -7,8 +7,8 @@ import akka.javasdk.annotations.http.Post; import akka.javasdk.client.ComponentClient; import akka.javasdk.http.HttpResponses; -import com.example.transfer.application.TransferView; -import com.example.transfer.application.TransferView.TransferEntries; +import com.example.transfer.application.TransfersView; +import com.example.transfer.application.TransfersView.TransferEntries; import com.example.transfer.application.TransferWorkflow; import com.example.transfer.domain.TransferState.Transfer; import org.slf4j.Logger; @@ -41,7 +41,7 @@ public CompletionStage get(String id) { @Get("/transfers/completed") public CompletionStage getCompleted() { return componentClient.forView() - .method(TransferView::getAllCompleted).invokeAsync(); + .method(TransfersView::getAllCompleted).invokeAsync(); } @Post("/transfer/{id}") diff --git a/samples/transfer-workflow/src/main/java/com/example/transfer/application/TransferView.java b/samples/transfer-workflow/src/main/java/com/example/transfer/application/TransfersView.java similarity index 89% rename from samples/transfer-workflow/src/main/java/com/example/transfer/application/TransferView.java rename to samples/transfer-workflow/src/main/java/com/example/transfer/application/TransfersView.java index 2a2ae614a..146f0bd45 100644 --- a/samples/transfer-workflow/src/main/java/com/example/transfer/application/TransferView.java +++ b/samples/transfer-workflow/src/main/java/com/example/transfer/application/TransfersView.java @@ -11,7 +11,7 @@ // tag::view-from-workflow[] @ComponentId("transfer-view") -public class TransferView extends View { +public class TransfersView extends View { public record TransferEntry(String id, String status) {} @@ -23,7 +23,7 @@ public QueryEffect getAllCompleted() { } @Consume.FromWorkflow(TransferWorkflow.class) // <1> - public static class TransferUpdater extends TableUpdater { + public static class TransfersUpdater extends TableUpdater { public Effect onUpdate(TransferState transferState) { // <2> var id = updateContext().eventSubject().orElse(""); diff --git a/samples/transfer-workflow/src/test/java/com/example/transfer/application/TransferWorkflowIntegrationTest.java b/samples/transfer-workflow/src/test/java/com/example/transfer/application/TransferWorkflowIntegrationTest.java index fec16b368..3783504e7 100644 --- a/samples/transfer-workflow/src/test/java/com/example/transfer/application/TransferWorkflowIntegrationTest.java +++ b/samples/transfer-workflow/src/test/java/com/example/transfer/application/TransferWorkflowIntegrationTest.java @@ -1,7 +1,7 @@ package com.example.transfer.application; import akka.javasdk.testkit.TestKitSupport; -import com.example.transfer.application.TransferView.TransferEntries; +import com.example.transfer.application.TransfersView.TransferEntries; import com.example.transfer.domain.TransferState.Transfer; import com.example.wallet.application.WalletEntity; import org.awaitility.Awaitility; @@ -46,8 +46,8 @@ public void shouldTransferMoney() { assertThat(balance1).isEqualTo(90); assertThat(balance2).isEqualTo(110); - TransferEntries result = await(componentClient.forView().method(TransferView::getAllCompleted).invokeAsync()); - assertThat(result.entries()).contains(new TransferView.TransferEntry(transferId, "COMPLETED")); + TransferEntries result = await(componentClient.forView().method(TransfersView::getAllCompleted).invokeAsync()); + assertThat(result.entries()).contains(new TransfersView.TransferEntry(transferId, "COMPLETED")); }); } diff --git a/samples/transfer-workflow/src/test/java/com/example/transfer/application/TransferViewIntegrationTest.java b/samples/transfer-workflow/src/test/java/com/example/transfer/application/TransfersViewIntegrationTest.java similarity index 83% rename from samples/transfer-workflow/src/test/java/com/example/transfer/application/TransferViewIntegrationTest.java rename to samples/transfer-workflow/src/test/java/com/example/transfer/application/TransfersViewIntegrationTest.java index 9b80479af..de9d1fee5 100644 --- a/samples/transfer-workflow/src/test/java/com/example/transfer/application/TransferViewIntegrationTest.java +++ b/samples/transfer-workflow/src/test/java/com/example/transfer/application/TransfersViewIntegrationTest.java @@ -13,7 +13,7 @@ import static java.time.temporal.ChronoUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; -class TransferViewIntegrationTest extends TestKitSupport { +class TransfersViewIntegrationTest extends TestKitSupport { private EventingTestKit.IncomingMessages transferStates; @@ -46,8 +46,8 @@ public void shouldTestTransferViewWithPredefinedStateChanges() { .atMost(10, TimeUnit.of(SECONDS)) .untilAsserted(() -> { - TransferView.TransferEntries result = await(componentClient.forView().method(TransferView::getAllCompleted).invokeAsync()); - assertThat(result.entries()).contains(new TransferView.TransferEntry("t2", "COMPLETED")); + TransfersView.TransferEntries result = await(componentClient.forView().method(TransfersView::getAllCompleted).invokeAsync()); + assertThat(result.entries()).contains(new TransfersView.TransferEntry("t2", "COMPLETED")); }); } diff --git a/samples/view-store/src/main/java/store/order/view/joined/JoinedCustomerOrdersView.java b/samples/view-store/src/main/java/store/order/view/joined/JoinedCustomerOrdersView.java index 5146ea14f..6d6a01e8b 100644 --- a/samples/view-store/src/main/java/store/order/view/joined/JoinedCustomerOrdersView.java +++ b/samples/view-store/src/main/java/store/order/view/joined/JoinedCustomerOrdersView.java @@ -23,7 +23,7 @@ public class JoinedCustomerOrdersView extends View { @Table("customers") // <2> @Consume.FromEventSourcedEntity(CustomerEntity.class) - public static class Customers extends TableUpdater { + public static class CustomersUpdater extends TableUpdater { public Effect onEvent(CustomerEvent event) { return switch (event) { case CustomerEvent.CustomerCreated created -> { @@ -43,7 +43,7 @@ yield effects() @Table("products") // <2> @Consume.FromEventSourcedEntity(ProductEntity.class) - public static class Products extends TableUpdater { + public static class ProductsUpdater extends TableUpdater { public Effect onEvent(ProductEvent event) { return switch (event) { case ProductEvent.ProductCreated created -> { @@ -62,7 +62,7 @@ public Effect onEvent(ProductEvent event) { @Table("orders") // <2> @Consume.FromKeyValueEntity(OrderEntity.class) - public static class Orders extends TableUpdater { + public static class OrdersUpdater extends TableUpdater { } public record JoinedCustomerOrders(List orders) { } diff --git a/samples/view-store/src/main/java/store/order/view/nested/NestedCustomerOrdersView.java b/samples/view-store/src/main/java/store/order/view/nested/NestedCustomerOrdersView.java index c0472e1f5..30b5a98b1 100644 --- a/samples/view-store/src/main/java/store/order/view/nested/NestedCustomerOrdersView.java +++ b/samples/view-store/src/main/java/store/order/view/nested/NestedCustomerOrdersView.java @@ -35,7 +35,7 @@ public QueryEffect get(String customerId) { // <2> @Table("customers") @Consume.FromEventSourcedEntity(CustomerEntity.class) - public static class Customers extends TableUpdater { + public static class CustomersUpdater extends TableUpdater { public Effect onEvent(CustomerEvent event) { return switch (event) { case CustomerEvent.CustomerCreated created -> { @@ -55,7 +55,7 @@ yield effects() @Table("products") @Consume.FromEventSourcedEntity(ProductEntity.class) - public static class Products extends TableUpdater { + public static class ProductsUpdater extends TableUpdater { public Effect onEvent(ProductEvent event) { return switch (event) { case ProductEvent.ProductCreated created -> { @@ -74,5 +74,5 @@ public Effect onEvent(ProductEvent event) { @Table("orders") @Consume.FromKeyValueEntity(OrderEntity.class) - public static class Orders extends TableUpdater { } + public static class OrdersUpdater extends TableUpdater { } } diff --git a/samples/view-store/src/main/java/store/order/view/structured/StructuredCustomerOrdersView.java b/samples/view-store/src/main/java/store/order/view/structured/StructuredCustomerOrdersView.java index 142fbbdc6..4590ce239 100644 --- a/samples/view-store/src/main/java/store/order/view/structured/StructuredCustomerOrdersView.java +++ b/samples/view-store/src/main/java/store/order/view/structured/StructuredCustomerOrdersView.java @@ -46,7 +46,7 @@ public QueryEffect get(String customerId) { @Table("customers") @Consume.FromEventSourcedEntity(CustomerEntity.class) - public static class Customers extends TableUpdater { + public static class CustomersUpdater extends TableUpdater { public Effect onEvent(CustomerEvent event) { return switch (event) { case CustomerEvent.CustomerCreated created -> { @@ -66,7 +66,7 @@ yield effects() @Table("products") @Consume.FromEventSourcedEntity(ProductEntity.class) - public static class Products extends TableUpdater { + public static class ProductsUpdater extends TableUpdater { public Effect onEvent(ProductEvent event) { return switch (event) { case ProductEvent.ProductCreated created -> { @@ -85,6 +85,6 @@ public Effect onEvent(ProductEvent event) { @Table("orders") @Consume.FromKeyValueEntity(OrderEntity.class) - public static class Orders extends TableUpdater { + public static class OrdersUpdater extends TableUpdater { } }