Skip to content
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

Adapted to latest API changes: #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/example/MongoConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ ObjectMapper objectMapper() {
return Jackson2ObjectMapperBuilder.json().build();
}


@Override
public MongoClient mongoClient() {
public MongoClient reactiveMongoClient() {
return MongoClients.create();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public CommandLineRunner initDatabase(ReactorPersonRepository repository) {
);

return args -> {
repository.deleteAll().thenMany(repository.save(people)).blockLast();
repository.deleteAll().thenMany(repository.saveAll(people)).blockLast();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Flux<ReactorIssue> findReactorIssues() {
.getUsersInRoom(this.properties.getReactor().getGitterRoomId(), 300)
.collectList();

return users.flatMap(gitterUserList -> {
return users.flatMapMany(gitterUserList -> {
return issues.map(issue -> {
String userLogin = issue.getUser().getLogin();
Optional<GitterUser> gitterUser = gitterUserList.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ public class GithubClient {

public GithubClient(DashboardProperties properties) {
this.webClient = WebClient
.create("https://api.github.com")
.builder()
.baseUrl("https://api.github.com")
.filter(ExchangeFilterFunctions
.basicAuthentication(properties.getGithub().getUsername(),
properties.getGithub().getToken()))
.filter(userAgent());
.filter(userAgent())
.build();
}

public Flux<GithubIssue> findOpenIssues(String owner, String repo) {
return this.webClient
.get()
.uri("/repos/{owner}/{repo}/issues?state=open", owner, repo)
.accept(VND_GITHUB_V3)
.exchange().flatMap(response -> response.bodyToFlux(GithubIssue.class));
.exchange().flatMapMany(response -> response.bodyToFlux(GithubIssue.class));
}


Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/example/integration/gitter/GitterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public class GitterClient {
private final WebClient webClient;

public GitterClient(DashboardProperties properties) {
this.webClient = WebClient.create()
.filter(oAuthToken(properties.getGitter().getToken()));
this.webClient = WebClient.builder()
.filter(oAuthToken(properties.getGitter().getToken())).build();
}

public Flux<GitterUser> getUsersInRoom(String roomId, int limit) {
return this.webClient
.get().uri("https://api.gitter.im/v1/rooms/{roomId}/users?limit={limit}", roomId, limit)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.flatMap(response -> response.bodyToFlux(GitterUser.class));
.flatMapMany(response -> response.bodyToFlux(GitterUser.class));
}

public Mono<GitterUser> findUserInRoom(String userName, String roomId) {
Expand All @@ -38,7 +38,7 @@ public Mono<GitterUser> findUserInRoom(String userName, String roomId) {
.uri("https://api.gitter.im/v1/rooms/{roomId}/users?q={userName}", roomId, userName)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.then(response -> response.bodyToMono(GitterUser.class));
.flatMap(response -> response.bodyToMono(GitterUser.class));
}

public Flux<GitterMessage> latestChatMessages(String roomId, int limit) {
Expand All @@ -47,7 +47,7 @@ public Flux<GitterMessage> latestChatMessages(String roomId, int limit) {
.uri("https://api.gitter.im/v1/rooms/{roomId}/chatMessages?limit={limit}", roomId, limit)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.flatMap(response -> response.bodyToFlux(GitterMessage.class));
.flatMapMany(response -> response.bodyToFlux(GitterMessage.class));
}

public Flux<GitterMessage> streamChatMessages(String roomId) {
Expand All @@ -56,7 +56,7 @@ public Flux<GitterMessage> streamChatMessages(String roomId) {
.uri("https://stream.gitter.im/v1/rooms/{roomId}/chatMessages", roomId)
.accept(MediaType.TEXT_EVENT_STREAM)
.exchange()
.flatMap(response -> response.bodyToFlux(GitterMessage.class));
.flatMapMany(response -> response.bodyToFlux(GitterMessage.class));
}

private ExchangeFilterFunction oAuthToken(String token) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/example/web/DashboardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public Flux<ReactorPerson> findReactorPeople() {
@GetMapping("/reactor/people/{id}")
@ResponseBody
public Mono<ReactorPerson> findReactorPerson(@PathVariable String id) {
return this.repository.findOne(id)
.otherwiseIfEmpty(Mono.error(new ReactorPersonNotFoundException(id)));
return this.repository.findById(id)
.switchIfEmpty(Mono.error(new ReactorPersonNotFoundException(id)));
}

@ExceptionHandler
Expand Down