Ignore:
Timestamp:
01/16/22 20:22:55 (3 years ago)
Author:
Test <matonikolov77@…>
Branches:
main
Children:
3ded84d
Parents:
2d57cad (diff), 7bc8942 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Resolving models

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/wediscussmovies/project/model/Movie.java

    r2d57cad r7fafead  
    11package com.wediscussmovies.project.model;
     2
     3import lombok.Data;
    24
    35import javax.persistence.*;
    46import java.sql.Date;
    57import java.util.Collection;
     8import java.util.Comparator;
     9import java.util.List;
    610import java.util.Objects;
     11
    712
    813@Entity
    914@Table(name = "movies", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies")
     15@Data
    1016public class Movie {
     17
    1118    @GeneratedValue(strategy = GenerationType.IDENTITY)
    1219    @Id
    1320    @Column(name = "movie_id")
    14     private int movieId;
    15     @Basic
    16     @Column(name = "title")
     21    private Long id;
     22
    1723    private String title;
    18     @Basic
    19     @Column(name = "description")
     24
    2025    private String description;
    21     @Basic
     26
    2227    @Column(name = "image_url")
    2328    private String imageUrl;
    24     @Basic
     29
     30
    2531    @Column(name = "airing_date")
    26     private Date airingDate;
    27     @Basic
     32    private Date aringDate;
     33
    2834    @Column(name = "imdb_rating")
    29     private Double imdbRating;
    30     @Basic
    31     @Column(name = "director_id")
    32     private Integer directorId;
    33     @OneToMany(mappedBy = "moviesByMovieId")
    34     private Collection<Discussion> discussionsByMovieId;
    35     @OneToMany(mappedBy = "moviesByMovieId")
    36     private Collection<MovieActorsEntity> movieActorsByMovieId;
    37     @OneToMany(mappedBy = "moviesByMovieId")
    38     private Collection<MovieGenresEntity> movieGenresByMovieId;
    39     @OneToMany(mappedBy = "moviesByMovieId")
    40     private Collection<MovieLikesEntity> movieLikesByMovieId;
    41     @OneToMany(mappedBy = "moviesByMovieId")
    42     private Collection<MovieRatesEntity> movieRatesByMovieId;
     35    private Double imbdRating;
     36
     37    @ManyToMany
     38    private List<Genre> genres;
     39
     40    @ManyToMany
     41    private List<Person> likes;
     42
     43    @ManyToMany
     44    private List<Person> actors;
     45
     46
     47
     48
    4349    @ManyToOne
    44     @JoinColumn(name = "director_id", referencedColumnName = "person_id",insertable = false, updatable = false)
    45     private Person personsByDirectorId;
     50    @JoinColumn(name = "director_id")
     51    private Person director;
    4652
    47     public int getMovieId() {
    48         return movieId;
     53
     54
     55
     56
     57
     58    public boolean isFromGenre(Genre genre){
     59
     60     return    genres
     61                .stream()
     62                .anyMatch(g -> Objects.equals(g.getId(), genre.getId()));
     63
     64    }
     65    public boolean hasActor(Person p){
     66        return
     67                actors
     68                        .stream()
     69                        .anyMatch(a -> Objects.equals(a.getPersonId(), p.getPersonId()));
     70
     71
    4972    }
    5073
    51     public void setMovieId(int movieId) {
    52         this.movieId = movieId;
     74    public boolean isDirectedBy(Person p){
     75        return Objects.equals(director.getPersonId(), p.getPersonId());
    5376    }
    5477
    55     public String getTitle() {
    56         return title;
    57     }
     78    public static Comparator<Movie> comparatorTitle = Comparator.comparing(Movie::getTitle);
    5879
    59     public void setTitle(String title) {
    60         this.title = title;
    61     }
    6280
    63     public String getDescription() {
    64         return description;
    65     }
     81    public Movie( String title, String description, String imageUrl, Date aringDate, Double imbdRating,Person director, List<Person> actors, List<Genre> genres) {
    6682
    67     public void setDescription(String description) {
    68         this.description = description;
    69     }
    70 
    71     public String getImageUrl() {
    72         return imageUrl;
    73     }
    74 
    75     public void setImageUrl(String imageUrl) {
    76         this.imageUrl = imageUrl;
    77     }
    78 
    79     public Date getAiringDate() {
    80         return airingDate;
    81     }
    82 
    83     public void setAiringDate(Date airingDate) {
    84         this.airingDate = airingDate;
    85     }
    86 
    87     public Double getImdbRating() {
    88         return imdbRating;
    89     }
    90 
    91     public void setImdbRating(Double imdbRating) {
    92         this.imdbRating = imdbRating;
    93     }
    94 
    95     public Integer getDirectorId() {
    96         return directorId;
    97     }
    98 
    99     public void setDirectorId(Integer directorId) {
    100         this.directorId = directorId;
    101     }
    102 
    103     @Override
    104     public boolean equals(Object o) {
    105         if (this == o) return true;
    106         if (o == null || getClass() != o.getClass()) return false;
    107 
    108         Movie that = (Movie) o;
    109 
    110         if (movieId != that.movieId) return false;
    111         if (!Objects.equals(title, that.title)) return false;
    112         if (!Objects.equals(description, that.description)) return false;
    113         if (!Objects.equals(imageUrl, that.imageUrl)) return false;
    114         if (!Objects.equals(airingDate, that.airingDate)) return false;
    115         if (!Objects.equals(imdbRating, that.imdbRating)) return false;
    116         if (!Objects.equals(directorId, that.directorId)) return false;
    117 
    118         return true;
    119     }
    120 
    121     public Movie(String title, String description, String imageUrl, Date airingDate, Double imdbRating, Integer directorId) {
    12283        this.title = title;
    12384        this.description = description;
    12485        this.imageUrl = imageUrl;
    125         this.airingDate = airingDate;
    126         this.imdbRating = imdbRating;
    127         this.directorId = directorId;
     86        this.aringDate = aringDate;
     87        this.imbdRating = imbdRating;
     88        this.genres = genres;
     89        this.likes = likes;
     90        this.actors = actors;
     91        this.director = director;
    12892    }
    12993
     
    13195    }
    13296
    133     @Override
    134     public int hashCode() {
    135         int result = movieId;
    136         result = 31 * result + (title != null ? title.hashCode() : 0);
    137         result = 31 * result + (description != null ? description.hashCode() : 0);
    138         result = 31 * result + (imageUrl != null ? imageUrl.hashCode() : 0);
    139         result = 31 * result + (airingDate != null ? airingDate.hashCode() : 0);
    140         result = 31 * result + (imdbRating != null ? imdbRating.hashCode() : 0);
    141         result = 31 * result + (directorId != null ? directorId.hashCode() : 0);
    142         return result;
    143     }
    14497
    145     public Collection<Discussion> getDiscussionsByMovieId() {
    146         return discussionsByMovieId;
    147     }
    148 
    149     public void setDiscussionsByMovieId(Collection<Discussion> discussionsByMovieId) {
    150         this.discussionsByMovieId = discussionsByMovieId;
    151     }
    152 
    153     public Collection<MovieActorsEntity> getMovieActorsByMovieId() {
    154         return movieActorsByMovieId;
    155     }
    156 
    157     public void setMovieActorsByMovieId(Collection<MovieActorsEntity> movieActorsByMovieId) {
    158         this.movieActorsByMovieId = movieActorsByMovieId;
    159     }
    160 
    161     public Collection<MovieGenresEntity> getMovieGenresByMovieId() {
    162         return movieGenresByMovieId;
    163     }
    164 
    165     public void setMovieGenresByMovieId(Collection<MovieGenresEntity> movieGenresByMovieId) {
    166         this.movieGenresByMovieId = movieGenresByMovieId;
    167     }
    168 
    169     public Collection<MovieLikesEntity> getMovieLikesByMovieId() {
    170         return movieLikesByMovieId;
    171     }
    172 
    173     public void setMovieLikesByMovieId(Collection<MovieLikesEntity> movieLikesByMovieId) {
    174         this.movieLikesByMovieId = movieLikesByMovieId;
    175     }
    176 
    177     public Collection<MovieRatesEntity> getMovieRatesByMovieId() {
    178         return movieRatesByMovieId;
    179     }
    180 
    181     public void setMovieRatesByMovieId(Collection<MovieRatesEntity> movieRatesByMovieId) {
    182         this.movieRatesByMovieId = movieRatesByMovieId;
    183     }
    184 
    185     public Person getPersonsByDirectorId() {
    186         return personsByDirectorId;
    187     }
    188 
    189     public void setPersonsByDirectorId(Person personsByDirectorId) {
    190         this.personsByDirectorId = personsByDirectorId;
    191     }
    19298}
Note: See TracChangeset for help on using the changeset viewer.