/app/models/Review.java
Java | 229 lines | 208 code | 21 blank | 0 comment | 23 complexity | 4f8ae47a3728625deb679790ecd52807 MD5 | raw file
- package models;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import javax.imageio.ImageIO;
- import com.google.gson.Gson;
- import com.google.gson.JsonObject;
- import org.bson.types.ObjectId;
- import com.fasterxml.jackson.databind.JsonNode;
- import play.Logger;
- import play.mvc.Http.MultipartFormData.FilePart;
- import Utils.ImageUtils;
- import com.mongodb.BasicDBObject;
- import com.mongodb.DBObject;
- public class Review {
- public ObjectId dishId;
- public ObjectId userId;
- public float points=0.f;
- public String user="";
- public String description="";
- public String tags[] = new String[] { "" };
- public String photoURL="http://toptasting.s3.amazonaws.com/sinImagenDish.png";
- public String userPhotoURL;
- public boolean firstTimeInVenue=false;
- public boolean firstReviewInVenue=false;
- public boolean firstReviewInDish=false;
- public boolean repeated=false;
- final int firstTIVpoints=1;
- final int firstRIVpoints=1;
- final int firstRIDpoints=1;
- final int hasPicturePoints=1;
- final int hasDescriptionPoints=1;
- public String getUserPhotoURL() {
- return userPhotoURL;
- }
- public void setUserPhotoURL(String userPhotoURL) {
- this.userPhotoURL = userPhotoURL;
- }
- public String getPhotoURL() {
- return photoURL;
- }
- public void setPhotoURL(String photoURL) {
- this.photoURL = photoURL;
- }
- public String date="";
- public String venueName;
-
- public Review() {
- }
- @SuppressWarnings("unchecked")
- public Review(DBObject object) {
- Object o;
- if (object.containsField("userId")) {
- this.userId = (ObjectId) object.get("userId");
- ;
- }
- if (object.containsField("user")) {
- this.user = object.get("user").toString();
- ;
- }
- o=object.get("date");
- if (o!=null) {
- this.date = o.toString();
- ;
- }
- if (object.containsField("points")) {
- this.points = Float.parseFloat(object.get("points").toString());
- }
- if (object.containsField("photoURL")) {
- this.photoURL = object.get("photoURL").toString();
- }
- if (object.containsField("description")) {
- this.description = object.get("description").toString();
- }
- if (object.get("firstIV")!=null) {
- this.firstTimeInVenue = (Boolean) object.get("firstIV");
- }if (object.get("firstRIV")!=null) {
- this.firstReviewInVenue = (Boolean) object.get("firstRIV");
- }if (object.get("firstRID")!=null) {
- this.firstReviewInDish= (Boolean) object.get("firstRID");
- }
- if (object.get("firstRID")!=null) {
- this.repeated= (Boolean) object.get("repeated");
- }
- ArrayList<Object> al = (ArrayList<Object>) object.get("tags");
- if (al != null) {
- this.tags = new String[al.size()];
- int i = 0;
- for (Object ob : al) {
- this.tags[i] = ob.toString();
- i++;
- }
- }
- }
- public Review(JsonNode json) {
- userId = new ObjectId(json.findPath("userId").textValue());
- Logger.info("USER ID (review): "+userId);
- points = json.findPath("points").intValue();
- user = json.findPath("user").asText();
- description = json.findPath("description").asText();
- photoURL = json.findPath("photoURL").asText();
- date=json.findPath("date").asText();
- dishId=new ObjectId(json.findPath("dishId").textValue());
- firstTimeInVenue=json.findPath("firstTIV").booleanValue();
- firstReviewInVenue=json.findPath("firstRIV").booleanValue();
- firstReviewInDish=json.findPath("firstRID").booleanValue();
- repeated=json.findPath("repeated").booleanValue();
- }
- public Review(JsonNode json, FilePart picture) {
- userId = new ObjectId(json.findPath("userId").asText());
- points = json.findPath("points").intValue();
- user = json.findPath("user").asText();
- date= json.findPath("date").asText();
- description = json.findPath("description").asText();
- firstTimeInVenue=json.findPath("firstTIV").booleanValue();
- firstReviewInVenue=json.findPath("firstRIV").booleanValue();
- firstReviewInDish=json.findPath("firstRID").booleanValue();
- repeated=json.findPath("repeated").booleanValue();
- photoURL = Utils.AWSuploader.insertImage(picture, "reviews");
- }
- public BasicDBObject toDBO() {
- BasicDBObject doc = new BasicDBObject();
- doc.append("description", description);
- doc.append("points", points);
- doc.append("photoURL", photoURL);
- doc.append("tags", tags);
- doc.append("user", user);
- doc.append("userId", userId);
- doc.append("date", date);
- doc.append("firstTIV", firstTimeInVenue);
- doc.append("firstRIV", firstReviewInVenue);
- doc.append("firstRID", firstReviewInDish);
- doc.append("repeated", repeated);
- return doc;
- }
- public String toJson(){
- JsonObject jsObject = new JsonObject();
- jsObject.addProperty("userId", userId.toString());
- jsObject.addProperty("dishId",dishId.toString());
- jsObject.addProperty("date",date);
- jsObject.addProperty("userName",user);
- jsObject.addProperty("venueName",venueName);
- jsObject.addProperty("points",points);
- jsObject.addProperty("firstTIV",firstTimeInVenue);
- jsObject.addProperty("firstRIV",firstReviewInVenue);
- jsObject.addProperty("firstRID",firstReviewInDish);
- jsObject.addProperty("photoURL", photoURL);
- jsObject.addProperty("repeated", repeated);
- return jsObject.toString();
- }
- public String getJsonPoints(){
- JsonObject jsObject = new JsonObject();
- if(!repeated){
- if(firstTimeInVenue){
- jsObject.addProperty("firstTIV",firstTIVpoints);
- }else{
- jsObject.addProperty("firstTIV",0);
- }
- if(firstReviewInVenue){
- jsObject.addProperty("firstRIV", firstRIVpoints);
- }else{
- jsObject.addProperty("firstRIV", 0);
- }
- if(firstReviewInDish){
- jsObject.addProperty("firstRID", firstRIDpoints);
- }else{
- jsObject.addProperty("firstRID", 0);
- }
- if(!photoURL.equalsIgnoreCase("http://toptasting.s3.amazonaws.com/sinImagenDish.png")){
- jsObject.addProperty("hasPicture", hasPicturePoints);
- }else{
- jsObject.addProperty("hasPicture", 0);
- }
- if(description!=null&&description.length()>10){
- jsObject.addProperty("hasDescription", hasDescriptionPoints);
- }else{
- jsObject.addProperty("hasDescription", 0);
- }
- }
- else{
- jsObject.addProperty("repeated", 1);
- }
- return jsObject.toString();
- }
- public int getUserPoints(){
- int points=1;
- if(repeated){
- return points;
- }
- if(firstTimeInVenue){
- points+=firstTIVpoints;
- }
- if(firstReviewInVenue){
- points+=firstRIVpoints;
- }
- if(firstReviewInDish){
- points+=firstRIDpoints;
- }
- if(!photoURL.equalsIgnoreCase("http://toptasting.s3.amazonaws.com/sinImagenDish.png")){
- points+=hasPicturePoints;
- }
- if(description!=null&&description.length()>10){
- points+= hasDescriptionPoints;
- }
- return points;
- }
- }