Skip to content

Commit cac7e07

Browse files
committed
Include mongodb-driver-sync for MongoOperations.
Resolves #3.
1 parent bb5f2e0 commit cac7e07

File tree

18 files changed

+68
-33
lines changed

18 files changed

+68
-33
lines changed

2-reactive/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<groupId>org.springframework.boot</groupId>
3737
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
3838
</dependency>
39+
<dependency>
40+
<groupId>org.mongodb</groupId>
41+
<artifactId>mongodb-driver-sync</artifactId>
42+
</dependency>
3943
<dependency>
4044
<groupId>de.flapdoodle.embed</groupId>
4145
<artifactId>de.flapdoodle.embed.mongo</artifactId>

3-reactive/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<groupId>org.springframework.boot</groupId>
2424
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
2525
</dependency>
26+
<dependency>
27+
<groupId>org.mongodb</groupId>
28+
<artifactId>mongodb-driver-sync</artifactId>
29+
</dependency>
2630
<dependency>
2731
<groupId>org.springframework.boot</groupId>
2832
<artifactId>spring-boot-starter-thymeleaf</artifactId>

4-reactive/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<groupId>org.springframework.boot</groupId>
2424
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
2525
</dependency>
26+
<dependency>
27+
<groupId>org.mongodb</groupId>
28+
<artifactId>mongodb-driver-sync</artifactId>
29+
</dependency>
2630
<dependency>
2731
<groupId>org.springframework.boot</groupId>
2832
<artifactId>spring-boot-starter-thymeleaf</artifactId>

5-reactive/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<groupId>org.springframework.boot</groupId>
2828
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
2929
</dependency>
30+
<dependency>
31+
<groupId>org.mongodb</groupId>
32+
<artifactId>mongodb-driver-sync</artifactId>
33+
</dependency>
3034
<dependency>
3135
<groupId>org.springframework.boot</groupId>
3236
<artifactId>spring-boot-starter-thymeleaf</artifactId>

6-reactive/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<groupId>org.springframework.boot</groupId>
2828
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
2929
</dependency>
30+
<dependency>
31+
<groupId>org.mongodb</groupId>
32+
<artifactId>mongodb-driver-sync</artifactId>
33+
</dependency>
3034
<dependency>
3135
<groupId>org.springframework.boot</groupId>
3236
<artifactId>spring-boot-starter-thymeleaf</artifactId>

8-reactive-server/src/main/java/com/greglturnquist/hackingspringboot/reactive/server/RSocketService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ public Mono<Item> processNewItemsViaRSocketRequestResponse(Item item) { // <2>
6161
// end::request-response[]
6262

6363
// tag::fire-and-forget[]
64-
@MessageMapping("newItems.fire-and-forget") // <1>
65-
public Mono<Void> processNewItemsViaRSocketFireAndForget(Item item) { // <2>
66-
return this.repository.save(item) // <3>
64+
@MessageMapping("newItems.fire-and-forget")
65+
public Mono<Void> processNewItemsViaRSocketFireAndForget(Item item) {
66+
return this.repository.save(item) //
6767
.map(savedItem -> {
6868
if (this.itemSink != null) {
6969
this.itemSink.next(savedItem);
7070
}
7171
return savedItem;
7272
}) //
73-
.then(); // <4>
73+
.then();
7474
}
7575
// end::fire-and-forget[]
7676

9-reactive-custom-config/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
<groupId>org.springframework.boot</groupId>
2727
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
2828
</dependency>
29+
<dependency>
30+
<groupId>org.mongodb</groupId>
31+
<artifactId>mongodb-driver-sync</artifactId>
32+
</dependency>
33+
2934
<dependency>
3035
<groupId>org.springframework.boot</groupId>
3136
<artifactId>spring-boot-starter-thymeleaf</artifactId>

9-reactive-custom-config/src/main/java/com/greglturnquist/hackingspringboot/reactive/HomeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public HomeController(InventoryService inventoryService) {
4040

4141
// tag::user-cart[]
4242
@GetMapping
43-
Mono<Rendering> index(Authentication auth) { // <1>
43+
Mono<Rendering> home(Authentication auth) { // <1>
4444
return Mono.just(Rendering.view("home.html") //
4545
.modelAttribute("items", this.inventoryService.getInventory()) //
4646
.modelAttribute("cart", this.inventoryService.getCart(cartName(auth)) // <2>

9-reactive-custom-config/src/test/java/com/greglturnquist/hackingspringboot/reactive/HomeControllerTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20-
import reactor.test.StepVerifier;
21-
2220
import org.junit.jupiter.api.Test;
21+
import reactor.test.StepVerifier;
2322
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
2524
import org.springframework.boot.test.context.SpringBootTest;
@@ -71,14 +70,14 @@ void addingInventoryWithProperRoleSucceeds() {
7170
.post().uri("/") //
7271
.contentType(MediaType.APPLICATION_JSON) // <2>
7372
.bodyValue("{" + // <3>
74-
"\"name\": \"iPhone X\", " + //
73+
"\"name\": \"iPhone 11\", " + //
7574
"\"description\": \"upgrade\", " + //
7675
"\"price\": 999.99" + //
7776
"}") //
7877
.exchange() //
7978
.expectStatus().isOk(); // <4>
8079

81-
this.repository.findByName("iPhone X") // <5>
80+
this.repository.findByName("iPhone 11") // <5>
8281
.as(StepVerifier::create) // <6>
8382
.expectNextMatches(item -> { // <7>
8483
assertThat(item.getDescription()).isEqualTo("upgrade");

9-reactive-method-security/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<groupId>org.springframework.boot</groupId>
2727
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
2828
</dependency>
29+
<dependency>
30+
<groupId>org.mongodb</groupId>
31+
<artifactId>mongodb-driver-sync</artifactId>
32+
</dependency>
2933
<dependency>
3034
<groupId>org.springframework.boot</groupId>
3135
<artifactId>spring-boot-starter-thymeleaf</artifactId>

9-reactive-method-security/src/main/java/com/greglturnquist/hackingspringboot/reactive/ApiItemController.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ Mono<RepresentationModel<?>> root() {
8484

8585
// tag::find-all[]
8686
@GetMapping("/api/items")
87-
Mono<CollectionModel<EntityModel<Item>>> findAll(Authentication authentication) {
87+
Mono<CollectionModel<EntityModel<Item>>> findAll(Authentication auth) {
8888
ApiItemController controller = methodOn(ApiItemController.class);
8989

90-
Mono<Link> selfLink = linkTo(controller.findAll(authentication)).withSelfRel().toMono();
90+
Mono<Link> selfLink = linkTo(controller.findAll(auth)).withSelfRel().toMono();
9191

9292
Mono<Links> allLinks;
9393

94-
if (authentication.getAuthorities().contains(ROLE_INVENTORY)) {
95-
Mono<Link> addNewLink = linkTo(controller.addNewItem(null, authentication)).withRel("add").toMono();
94+
if (auth.getAuthorities().contains(ROLE_INVENTORY)) {
95+
Mono<Link> addNewLink = linkTo(controller.addNewItem(null, auth)).withRel("add").toMono();
9696

9797
allLinks = Mono.zip(selfLink, addNewLink) //
9898
.map(links -> Links.of(links.getT1(), links.getT2()));
@@ -103,29 +103,28 @@ Mono<CollectionModel<EntityModel<Item>>> findAll(Authentication authentication)
103103

104104
return allLinks //
105105
.flatMap(links -> this.repository.findAll() //
106-
.flatMap(item -> findOne(item.getId(), authentication)) //
106+
.flatMap(item -> findOne(item.getId(), auth)) //
107107
.collectList() //
108108
.map(entityModels -> new CollectionModel<>(entityModels, links)));
109109
}
110110
// end::find-all[]
111111

112112
// tag::find-one[]
113113
@GetMapping("/api/items/{id}")
114-
Mono<EntityModel<Item>> findOne(@PathVariable String id, Authentication authentication) {
114+
Mono<EntityModel<Item>> findOne(@PathVariable String id, Authentication auth) {
115115
ApiItemController controller = methodOn(ApiItemController.class);
116116

117-
Mono<Link> selfLink = linkTo(controller.findOne(id, authentication)).withSelfRel() //
117+
Mono<Link> selfLink = linkTo(controller.findOne(id, auth)).withSelfRel() //
118118
.toMono();
119119

120-
Mono<Link> aggregateLink = linkTo(controller.findAll(authentication)).withRel(IanaLinkRelations.ITEM) //
120+
Mono<Link> aggregateLink = linkTo(controller.findAll(auth)).withRel(IanaLinkRelations.ITEM) //
121121
.toMono();
122122

123123
Mono<Links> allLinks; // <1>
124124

125-
if (authentication.getAuthorities().contains(ROLE_INVENTORY)) { // <2>
126-
Mono<Link> deleteLink = linkTo(controller.deleteItem(id)).withRel("delete").toMono();
127-
128-
allLinks = Mono.zip(selfLink, aggregateLink, deleteLink) //
125+
if (auth.getAuthorities().contains(ROLE_INVENTORY)) { // <2>
126+
allLinks = Mono.zip(selfLink, aggregateLink, //
127+
linkTo(controller.deleteItem(id)).withRel("delete").toMono()) //
129128
.map(links -> Links.of(links.getT1(), links.getT2(), links.getT3()));
130129
} else { // <3>
131130
allLinks = Mono.zip(selfLink, aggregateLink) //
@@ -136,15 +135,16 @@ Mono<EntityModel<Item>> findOne(@PathVariable String id, Authentication authenti
136135
.flatMap(links -> this.repository.findById(id) //
137136
.map(item -> new EntityModel<>(item, links)));
138137
}
138+
139139
// end::find-one[]
140140

141141
// tag::add-new-item[]
142142
@PreAuthorize("hasRole('" + INVENTORY + "')") // <1>
143143
@PostMapping("/api/items/add") // <2>
144-
Mono<ResponseEntity<?>> addNewItem(@RequestBody Item item, Authentication authentication) { // <3>
144+
Mono<ResponseEntity<?>> addNewItem(@RequestBody Item item, Authentication auth) { // <3>
145145
return this.repository.save(item) //
146146
.map(Item::getId) //
147-
.flatMap(id -> findOne(id, authentication)) //
147+
.flatMap(id -> findOne(id, auth)) //
148148
.map(newModel -> ResponseEntity.created(newModel //
149149
.getRequiredLink(IanaLinkRelations.SELF) //
150150
.toUri()).build());
@@ -153,7 +153,7 @@ Mono<ResponseEntity<?>> addNewItem(@RequestBody Item item, Authentication authen
153153

154154
// tag::delete-item[]
155155
@PreAuthorize("hasRole('" + INVENTORY + "')")
156-
@DeleteMapping("api/items/delete/{id}")
156+
@DeleteMapping("/api/items/delete/{id}")
157157
Mono<ResponseEntity<?>> deleteItem(@PathVariable String id) {
158158
return this.repository.deleteById(id) //
159159
.then(Mono.just(ResponseEntity.noContent().build()));
@@ -163,13 +163,13 @@ Mono<ResponseEntity<?>> deleteItem(@PathVariable String id) {
163163
// tag::update-item[]
164164
@PutMapping("/api/items/{id}") // <1>
165165
public Mono<ResponseEntity<?>> updateItem(@RequestBody Mono<EntityModel<Item>> item, // <2>
166-
@PathVariable String id, Authentication authentication) {
166+
@PathVariable String id, Authentication auth) {
167167
return item //
168168
.map(EntityModel::getContent) //
169169
.map(content -> new Item(id, content.getName(), // <3>
170170
content.getDescription(), content.getPrice())) //
171171
.flatMap(this.repository::save) // <4>
172-
.then(findOne(id, authentication)) // <5>
172+
.then(findOne(id, auth)) // <5>
173173
.map(model -> ResponseEntity.noContent() // <6>
174174
.location(model.getRequiredLink(IanaLinkRelations.SELF).toUri()).build());
175175
}

9-reactive-method-security/src/main/java/com/greglturnquist/hackingspringboot/reactive/HomeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public HomeController(InventoryService inventoryService) {
3636

3737
// tag::user-cart[]
3838
@GetMapping
39-
Mono<Rendering> index(Authentication auth) { // <1>
39+
Mono<Rendering> home(Authentication auth) { // <1>
4040
return Mono.just(Rendering.view("home.html") //
4141
.modelAttribute("items", this.inventoryService.getInventory()) //
4242
.modelAttribute("cart", this.inventoryService.getCart(cartName(auth)) // <2>

9-reactive-method-security/src/test/java/com/greglturnquist/hackingspringboot/reactive/ApiItemControllerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ void navigateToItemWithoutInventoryAuthority() {
178178
@Test
179179
@WithMockUser(username = "alice", roles = { "INVENTORY" })
180180
void navigateToItemWithInventoryAuthority() {
181+
181182
// Navigate to the root URI of the API.
182183
RepresentationModel<?> root = this.webTestClient.get().uri("/api") //
183184
.exchange() //

9-reactive-oauth/src/main/java/com/greglturnquist/hackingspringboot/reactive/HomeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public HomeController(InventoryService inventoryService) {
4444

4545
// tag::user-cart[]
4646
@GetMapping
47-
Mono<Rendering> index( //
47+
Mono<Rendering> home( //
4848
@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authorizedClient,
4949
@AuthenticationPrincipal OAuth2User oauth2User) { // <1>
5050
return Mono.just(Rendering.view("home.html") //

9-reactive-quick/pom.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<groupId>org.springframework.boot</groupId>
2727
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
2828
</dependency>
29+
<dependency>
30+
<groupId>org.mongodb</groupId>
31+
<artifactId>mongodb-driver-sync</artifactId>
32+
</dependency>
2933
<dependency>
3034
<groupId>org.springframework.boot</groupId>
3135
<artifactId>spring-boot-starter-thymeleaf</artifactId>
@@ -40,15 +44,13 @@
4044
<groupId>org.springframework.boot</groupId>
4145
<artifactId>spring-boot-starter-security</artifactId>
4246
</dependency>
43-
<!-- end::spring-security[] -->
4447

45-
<!-- tag::spring-security-test[] -->
4648
<dependency>
4749
<groupId>org.springframework.security</groupId>
4850
<artifactId>spring-security-test</artifactId>
4951
<scope>test</scope>
5052
</dependency>
51-
<!-- end::spring-security-test[] -->
53+
<!-- end::spring-security[] -->
5254

5355
<dependency>
5456
<groupId>org.springframework.boot</groupId>

9-reactive-quick/src/main/java/com/greglturnquist/hackingspringboot/reactive/HomeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public HomeController(InventoryService inventoryService) {
3636
}
3737

3838
@GetMapping
39-
Mono<Rendering> index() {
39+
Mono<Rendering> home() {
4040
return Mono.just(Rendering.view("home.html") // <2>
4141
.modelAttribute("items", this.inventoryService.getInventory()) // <3>
4242
.modelAttribute("cart", this.inventoryService.getCart("My Cart") // <4>

9-reactive-repository/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<groupId>org.springframework.boot</groupId>
2727
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
2828
</dependency>
29+
<dependency>
30+
<groupId>org.mongodb</groupId>
31+
<artifactId>mongodb-driver-sync</artifactId>
32+
</dependency>
2933
<dependency>
3034
<groupId>org.springframework.boot</groupId>
3135
<artifactId>spring-boot-starter-thymeleaf</artifactId>

9-reactive-repository/src/main/java/com/greglturnquist/hackingspringboot/reactive/HomeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public HomeController(InventoryService inventoryService) {
3636
}
3737

3838
@GetMapping
39-
Mono<Rendering> index() {
39+
Mono<Rendering> home() {
4040
return Mono.just(Rendering.view("home.html") // <2>
4141
.modelAttribute("items", this.inventoryService.getInventory()) // <3>
4242
.modelAttribute("cart", this.inventoryService.getCart("My Cart") // <4>

0 commit comments

Comments
 (0)