diff --git a/src/main/java/NTNU/IDATT1002/models/Album.java b/src/main/java/NTNU/IDATT1002/models/Album.java index aee5740349a298f837687951e85a2c7e143a922c..6f428e945edaec30f3c2da22a8d76bf9feecfa63 100644 --- a/src/main/java/NTNU/IDATT1002/models/Album.java +++ b/src/main/java/NTNU/IDATT1002/models/Album.java @@ -22,7 +22,13 @@ import java.util.stream.Collectors; @Table(name = "album") @NamedQueries({ @NamedQuery(name="Album.findAllByUsername", - query = "SELECT ia from Album ia WHERE ia.user.username = :username") + query = "SELECT ia from Album ia WHERE ia.user.username = :username"), + @NamedQuery(name="Album.findByTags", + query = "SELECT ia from Album ia " + + "join ia.tags tg " + + "where tg.name = :name"), + @NamedQuery(name="Image.findByTitle", + query = "SELECT ia from Album ia WHERE ia.title = :title") }) public class Album { diff --git a/src/main/java/NTNU/IDATT1002/models/ImageAlbum.java b/src/main/java/NTNU/IDATT1002/models/ImageAlbum.java deleted file mode 100644 index d2f6da100f9cba0c12f43e35a13c4cf4c1fb5a68..0000000000000000000000000000000000000000 --- a/src/main/java/NTNU/IDATT1002/models/ImageAlbum.java +++ /dev/null @@ -1,180 +0,0 @@ -package NTNU.IDATT1002.models; - -import org.hibernate.annotations.CreationTimestamp; -import org.hibernate.annotations.UpdateTimestamp; - -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; - - -/** - * Class ImageAlbum representing an image album. Contains {@link Image}s and the creator ({@link User}) - * - * @author Eirik Steira - * @version 1.1 19.03.20 - * */ -@Entity -@Table(name = "image_album") -@NamedQueries({ - @NamedQuery(name="ImageAlbum.findAllByUsername", - query = "SELECT ia from ImageAlbum ia WHERE ia.user.username = :username"), - @NamedQuery(name="ImageAlbum.findByTags", - query = "SELECT ia from ImageAlbum ia " - + "join ia.tags tg " - + "where tg.name = :name"), - @NamedQuery(name="Image.findByTitle", - query = "SELECT ia from ImageAlbum ia WHERE ia.title = :title") -}) -public class ImageAlbum { - - @Id - @GeneratedValue - private Long id; - - @NotBlank(message = "Title may not be blank") - private String title; - - @ManyToOne(fetch = FetchType.LAZY) - private User user; - - @ManyToMany(fetch = FetchType.LAZY) - private List<Image> images = new ArrayList<>();; - - @ManyToMany(fetch = FetchType.LAZY) - private List<Tag> tags = new ArrayList<>();; - - private String description; - - @CreationTimestamp - private Date createdAt; - - @UpdateTimestamp - private Date updatedAt; - - public ImageAlbum() { - } - - public void setId(Long id) { - this.id = id; - } - - public Long getId() { - return id; - } - - public String getTitle() { - return title; - } - - public User getUser() { - return user; - } - - public List<Image> getImages() { - return images; - } - - public String getDescription() { - return description; - } - - public Date getCreatedAt() { - return createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public List<Tag> getTags() { - return tags; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setDescription(String description) { - this.description = description; - } - - public void setUser(User user) { - this.user = user; - } - - public void setTags(List<Tag> tags) { - this.tags = tags; - } - - public void setImages(List<Image> images) { - this.images = images; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - /** - * Add given image to this album. - * - * @param image the image to add - */ - public void addImage(Image image) { - image.addImageAlbum(this); - images.add(image); - } - - /** - * Remove given image from the album. - * - * @param image the image to add - */ - public void removeImage(Image image) { - image.removeImageAlbum(this); - images.remove(image); - } - - /** - * Add given tag to this album - * - * @param tag the tag to add - */ - public void addTag(Tag tag) { - tags.add(tag); - } - - /** - * Remove given tag to this album - * - * @param tag the tag to add - */ - public void removeTag(Tag tag) { - tags.remove(tag); - } - - /** - * Check if this and given entity are equal. - * The two are defined as equal if all individual fields are equal. - * - * @param o object to check for equality against - * @return true if this is equal to given object, else false - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ImageAlbum that = (ImageAlbum) o; - return id.equals(that.id) && - title.equals(that.title) && - user.equals(that.user) && - Objects.equals(images, that.images) && - Objects.equals(description, that.description) && - createdAt.equals(that.createdAt) && - updatedAt.equals(that.updatedAt); - } - -}