I'm trying to execute a custom cypher query in Spring boot reactive app but always getting an empty output. I have tried executing the query in neo4j browser and I'm able to get an anticipated result. I have found similar kind of example here but it is with Neo4JClient not with Neo4jReactiveClient
When I tried debugging the code in MyDbClient -> getTeamWithPlayers the pointer is not entering into query.mappedBy function.
API
GetMapping("/teamAndPlayes/{teamId}")
public Mono<TeamWithPlayers> updateEventStatus(@RequestHeader("uid") String uid, @PathVariable Long teamId) {
return myDbClient.getTeamWithPlayers(teamId);
}
ReactiveNeo4jClient Implementation
@Component
@RequiredArgsConstructor
public class MyDbClient {
private final ReactiveNeo4jClient client;
public Mono<TeamWithPlayers> getTeamWithPlayers(Long teamId) {
String query = "Match (team:Team) where id(team) =$teamId match (team)-[:REL{is:'TEAM'}]->(u:User) "
+ "optional Match (u) -[role:ROLE]->(team) "
+ "with team, COLLECT(u) as users, collect({uid: u.uid, role : role.is}) as roles "
+ "return team {id:id(team), .name, .description, .location, .emailAddress, .profileImgURL, .createdOn, users: users, roles: roles}";
return client.query(query).bind(teamId).to("teamId").fetchAs(TeamWithPlayers.class)
.mappedBy((TypeSystem ts, Record r) -> {
Value team = r.get("team");
List<User> users = team.get("users").asList(u -> User.builder()
.firstName(u.get("firstName").asString()).lastName(u.get("lastName").asString()).build());
List<PlayerRole> roles = team.get("roles").asList(pr -> PlayerRole.builder()
.uid(pr.get("uid").asString()).role(pr.get("role").asString()).build());
return TeamWithPlayers.builder().id(team.get("id").asLong()).name(team.get("name").asString())
.description(team.get("description").asString()).location(team.get("location").asString())
.emailAddress(team.get("emailAddress").asString())
.createdOn(team.get("createdOn").asLocalDateTime()).users(users).roles(roles).build();
}).one();
}
}
Mapping classes
@Data
@Builder
@ToString
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class TeamWithPlayers {
private Long id;
private String name;
private String description;
private String location;
private String emailAddress;
private String profileImgURL;
private LocalDateTime createdOn;
List<User> users;
List<PlayerRole> roles;
}
@Node
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class User implements Entity {
@Id
@GeneratedValue
private Long id;
private String uid;
private String firstName;
private String lastName;
private String emailAddress;
private String profileImgURL;
private LocalDateTime updatedAt;
private LocalDateTime createdAt;
private LocalDateTime lastLoggedInAt;
}
@Data
@ToString
@Builder
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class PlayerRole {
String uid;
String role;
}
POM dependencies **2.4.2**
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
Not sure what wrong in my approach