source: Git/Sources/src/main/java/com/wediscussmovies/project/model/Movie.java@ 980eeda

main
Last change on this file since 980eeda was 980eeda, checked in by Test <matonikolov77@…>, 22 months ago

Restructuring project

  • Property mode set to 100644
File size: 2.9 KB
Line 
1package com.wediscussmovies.project.model;
2
3import com.wediscussmovies.project.model.relation.MovieLikes;
4import com.wediscussmovies.project.model.relation.MovieActors;
5import com.wediscussmovies.project.model.relation.MovieGenres;
6import com.wediscussmovies.project.model.relation.MovieRates;
7import lombok.Data;
8import org.hibernate.annotations.Fetch;
9
10import javax.persistence.*;
11import java.io.Serializable;
12import java.sql.Date;
13import java.util.Collection;
14import java.util.Comparator;
15import java.util.Objects;
16
17@Entity
18@Table(name = "movies", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies")
19@Data
20public class Movie {
21 @GeneratedValue(strategy = GenerationType.IDENTITY)
22 @Id
23 @Column(name = "movie_id")
24 private int movieId;
25 @Basic
26 @Column(name = "title")
27 private String title;
28 @Basic
29 @Column(name = "description")
30 private String description;
31 @Basic
32 @Column(name = "image_url")
33 private String imageUrl;
34 @Basic
35 @Column(name = "airing_date")
36 private Date airingDate;
37 @Basic
38 @Column(name = "imdb_rating")
39 private Double imdbRating;
40
41 @OneToMany(mappedBy = "movie", fetch = FetchType.LAZY)
42 private Collection<MovieActors> actors;
43 @OneToMany(mappedBy = "movie", fetch = FetchType.LAZY)
44 private Collection<MovieGenres> genres;
45 @OneToMany(mappedBy = "movie")
46 private Collection<MovieLikes> likes;
47 @OneToMany(mappedBy = "movie")
48 private Collection<MovieRates> rates;
49
50 @ManyToOne
51 @JoinColumn(name = "director_id")
52 private Person director;
53
54 public Movie() {
55
56 }
57
58 public Movie(String title, String description, String imageUrl, Date airingDate,
59 Double imdbRating, Person director) {
60 this.title = title;
61 this.description = description;
62 this.imageUrl = imageUrl;
63 this.airingDate = airingDate;
64 this.imdbRating = imdbRating;
65 this.director = director;
66
67 }
68
69 public Movie(int movieId, String title, Double imdbRating, String imageUrl) {
70 this.movieId = movieId;
71 this.title = title;
72 this.imdbRating = imdbRating;
73 this.imageUrl = imageUrl;
74 }
75
76 public String getDateFormatted(){
77 String dob = airingDate.toString();
78 String [] parts = dob.split("-");
79 return parts[2]+"/"+parts[1]+"/"+parts[0];
80 }
81
82 @Override
83 public boolean equals(Object o) {
84 if (this == o) return true;
85 if (o == null || getClass() != o.getClass()) return false;
86 Movie movie = (Movie) o;
87 return movieId == movie.movieId;
88 }
89
90 @Override
91 public int hashCode() {
92 return Objects.hash(movieId);
93 }
94
95 public static Comparator<Movie> comparatorTitle = Comparator.comparing(Movie::getTitle);
96
97
98 public String getShortTitle(){
99 int to = 20;
100 if (title.length() < to)
101 to = title.length();
102 if(to<20)
103 return title;
104 return title.substring(0, to) + "...";
105 }
106
107
108
109
110}
Note: See TracBrowser for help on using the repository browser.