Skip to content
Snippets Groups Projects
Commit d9816b66 authored by Eirik Steira's avatar Eirik Steira Committed by Mads Lundegaard
Browse files

Add ImageAlbum model and add relevant fields to User and Image

Add ImageAlbum model and add relevant fields to User and Image
parent de26b4af
No related branches found
No related tags found
1 merge request!30Weekly merge to master
......@@ -8,8 +8,8 @@
<java.version>11</java.version>
<hibernate.version>5.3.6.Final</hibernate.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
......@@ -29,17 +29,17 @@
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.0.Final</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.glassfish.jaxb</groupId>-->
<!-- <artifactId>jaxb-runtime</artifactId>-->
<!-- <version>2.3.0.1</version>-->
<!-- </dependency>-->
<!-- Logging -->
<dependency>
......@@ -94,7 +94,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>${java.version}</release>
<release>11</release>
</configuration>
</plugin>
<plugin>
......
package NTNU.IDATT1002.models;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Table(name = "image")
public class Image {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToMany
private List<ImageAlbum> imageAlbums = new ArrayList<>();;
}
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;
@Entity
@Table(name = "image_album")
public class ImageAlbum {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotBlank(message = "Title may not be blank")
private String title;
@ManyToOne
private User author;
@ManyToMany
private List<Image> images = new ArrayList<>();;
private String description;
@CreationTimestamp
private Date createdAt;
@UpdateTimestamp
private Date updatedAt;
public ImageAlbum() {
}
public ImageAlbum(@NotBlank(message = "Title may not be blank") String title, User author, List<Image> images, String description, Date createdAt, Date updatedAt) {
this.title = title;
this.author = author;
this.images = images;
this.description = description;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public User getAuthor() {
return author;
}
public void setAuthor(User author) {
this.author = author;
}
public List<Image> getImages() {
return images;
}
public void setImages(List<Image> images) {
this.images = images;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
@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) &&
author.equals(that.author) &&
Objects.equals(images, that.images) &&
Objects.equals(description, that.description) &&
createdAt.equals(that.createdAt) &&
updatedAt.equals(that.updatedAt);
}
}
package NTNU.IDATT1002.models;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Table(name = "user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private String username;
@OneToMany(
mappedBy = "user",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private List<ImageAlbum> imageAlbums = new ArrayList<>();
public void addImageAlbum(ImageAlbum imageAlbum) {
imageAlbums.add(imageAlbum);
imageAlbum.setAuthor(this);
}
public void removeImageAlbum(ImageAlbum imageAlbum) {
imageAlbums.remove(imageAlbum);
imageAlbum.setAuthor(null);
}
}
......@@ -8,6 +8,7 @@
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- Entity classes -->
<class>NTNU.IDATT1002.models.ImageAlbum</class>
<properties>
<!-- Configuring JDBC properties -->
......
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