Skip to content
Snippets Groups Projects
Commit ef37d75c authored by Stian Fjæran Mogen's avatar Stian Fjæran Mogen
Browse files

updated album removed imagealbum

added the changes in previous imagealbum to album, now up to date with dev
parent fa0864df
No related branches found
No related tags found
1 merge request!92Namedquery search
Pipeline #78527 passed
......@@ -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 {
......
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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment