noter un film en neo4j
This commit is contained in:
parent
e9627fa59a
commit
c393a86f23
@ -13,23 +13,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
|
|
||||||
import com.camillepradel.movierecommender.model.Genre;
|
import com.camillepradel.movierecommender.model.Genre;
|
||||||
import com.camillepradel.movierecommender.model.Movie;
|
import com.camillepradel.movierecommender.model.Movie;
|
||||||
import com.mongodb.BasicDBList;
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.DBCursor;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.client.FindIterable;
|
|
||||||
import com.mongodb.client.MongoCollection;
|
|
||||||
import com.mongodb.client.MongoCursor;
|
|
||||||
import com.mongodb.client.MongoDatabase;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import org.bson.Document;
|
|
||||||
import java.net.ConnectException;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import org.neo4j.driver.v1.Record;
|
|
||||||
import org.neo4j.driver.v1.Session;
|
|
||||||
import org.neo4j.driver.v1.StatementResult;
|
|
||||||
import com.camillepradel.movierecommender.model.Rating;
|
import com.camillepradel.movierecommender.model.Rating;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@ -51,8 +34,8 @@ public class MainController {
|
|||||||
public ModelAndView showMovies(
|
public ModelAndView showMovies(
|
||||||
@RequestParam(value = "user_id", required = false) Integer userId) {
|
@RequestParam(value = "user_id", required = false) Integer userId) {
|
||||||
|
|
||||||
//List<Movie> movies = Neo4JController.getMoviesNeo4JByUser(userId);
|
List<Movie> movies = Neo4JController.getMoviesNeo4JByUser(userId);
|
||||||
List<Movie> movies = MongoDBController.getMoviesMongoDBByUser(userId);
|
//List<Movie> movies = MongoDBController.getMoviesMongoDBByUser(userId);
|
||||||
|
|
||||||
ModelAndView mv = new ModelAndView("movies");
|
ModelAndView mv = new ModelAndView("movies");
|
||||||
mv.addObject("userId", userId);
|
mv.addObject("userId", userId);
|
||||||
@ -67,13 +50,13 @@ public class MainController {
|
|||||||
System.out.println("GET /movieratings for user " + userId);
|
System.out.println("GET /movieratings for user " + userId);
|
||||||
|
|
||||||
// write query to retrieve all movies from DB
|
// write query to retrieve all movies from DB
|
||||||
List<Movie> allMovies = MongoDBController.getMoviesMongoDBByUser(userId);
|
//List<Movie> allMovies = MongoDBController.getMoviesMongoDBByUser(null);
|
||||||
//List<Movie> allMovies =Neo4JController.getMoviesNeo4JByUser(userId);
|
List<Movie> allMovies =Neo4JController.getMoviesNeo4JByUser(null);
|
||||||
|
|
||||||
// write query to retrieve all ratings from the specified user
|
// write query to retrieve all ratings from the specified user
|
||||||
List<Rating> ratings = MongoDBController.getRatingMongoDBByUser(userId);
|
//List<Rating> ratings = MongoDBController.getRatingMongoDBByUser(userId);
|
||||||
|
|
||||||
//List<Rating> ratings=Neo4JController.GetMoviesRatingNeo4JByUser(userId);
|
List<Rating> ratings=Neo4JController.GetMoviesRatingNeo4JByUser(userId);
|
||||||
ModelAndView mv = new ModelAndView("movieratings");
|
ModelAndView mv = new ModelAndView("movieratings");
|
||||||
mv.addObject("userId", userId);
|
mv.addObject("userId", userId);
|
||||||
mv.addObject("allMovies", allMovies);
|
mv.addObject("allMovies", allMovies);
|
||||||
@ -85,13 +68,9 @@ public class MainController {
|
|||||||
@RequestMapping(value = "/movieratings", method = RequestMethod.POST)
|
@RequestMapping(value = "/movieratings", method = RequestMethod.POST)
|
||||||
public String saveOrUpdateRating(@ModelAttribute("rating") Rating rating) {
|
public String saveOrUpdateRating(@ModelAttribute("rating") Rating rating) {
|
||||||
System.out.println("POST /movieratings for user " + rating.getUserId()
|
System.out.println("POST /movieratings for user " + rating.getUserId()
|
||||||
+ ", movie " + rating.getMovie().getId()
|
+ ", movie " + rating.getMovie().getTitle()
|
||||||
+ ", score " + rating.getScore());
|
+ ", score " + rating.getScore());
|
||||||
|
Neo4JController.updateMovieRatingNeo4J(rating);
|
||||||
// TODO: add query which
|
|
||||||
// - add rating between specified user and movie if it doesn't exist
|
|
||||||
// - update it if it does exist
|
|
||||||
|
|
||||||
return "redirect:/movieratings?user_id=" + rating.getUserId();
|
return "redirect:/movieratings?user_id=" + rating.getUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,4 +97,37 @@ public class Neo4JController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void updateMovieRatingNeo4J(Rating note){
|
||||||
|
|
||||||
|
Integer user_id = note.getUserId();
|
||||||
|
try {
|
||||||
|
if (user_id != null && user_id >=0 ){
|
||||||
|
|
||||||
|
Neo4jConnector.getInstance().getConnection().run( "MATCH (u:User{id:"+user_id+"})-[r:RATED]->(m:Movie)\n" +
|
||||||
|
"where m.id ="+note.getMovie().getId()+"\n" +
|
||||||
|
"delete r" );
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (ConnectException ex) {
|
||||||
|
System.out.println(ex);
|
||||||
|
}
|
||||||
|
finally{
|
||||||
|
Neo4jConnector.getInstance().close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
Neo4jConnector.getInstance().getConnection().run( "MATCH (u:User{id:"+user_id+"}),(m:Movie)\n" +
|
||||||
|
"where m.id = "+note.getMovie().getId()+"\n" +
|
||||||
|
"CREATE (u)-[r:RATED{note:"+note.getScore()+", timestamp: "+System.currentTimeMillis()+"}]->(m) \n" +
|
||||||
|
"RETURN *" );
|
||||||
|
|
||||||
|
} catch (ConnectException ex) {
|
||||||
|
System.out.println(ex);
|
||||||
|
}
|
||||||
|
finally{
|
||||||
|
Neo4jConnector.getInstance().close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
package com.camillepradel.movierecommender.controller;
|
package com.camillepradel.movierecommender.controller;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import org.neo4j.driver.v1.*;
|
import org.neo4j.driver.v1.*;
|
||||||
import org.neo4j.driver.v1.exceptions.Neo4jException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user