From e50e042b6978d1c6d2465f0af56cc033af4c433b Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 09:42:10 +0100
Subject: [PATCH 01/12] Add empty album creation

---
 src/main/java/NTNU/IDATT1002/App.java         |  3 +-
 .../java/NTNU/IDATT1002/ApplicationState.java |  4 ++
 .../IDATT1002/controllers/CreateAlbum.java    | 41 +++++++++++++++++++
 .../IDATT1002/service/ImageAlbumService.java  | 15 ++++++-
 .../NTNU/IDATT1002/create_album.fxml          |  2 +-
 5 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/src/main/java/NTNU/IDATT1002/App.java b/src/main/java/NTNU/IDATT1002/App.java
index bb4ba2a5..b0981f7e 100644
--- a/src/main/java/NTNU/IDATT1002/App.java
+++ b/src/main/java/NTNU/IDATT1002/App.java
@@ -18,7 +18,8 @@ public class App extends Application {
     @Override
     public void start(Stage stage) throws IOException {
         ex = new DataExchange();
-        scene = new Scene(loadFXML("login"));
+//        scene = new Scene(loadFXML("login"));
+        scene = new Scene(loadFXML("create_album"));
         stage.setScene(scene);
         stage.show();
     }
diff --git a/src/main/java/NTNU/IDATT1002/ApplicationState.java b/src/main/java/NTNU/IDATT1002/ApplicationState.java
index 89bd9027..73f4d145 100644
--- a/src/main/java/NTNU/IDATT1002/ApplicationState.java
+++ b/src/main/java/NTNU/IDATT1002/ApplicationState.java
@@ -16,4 +16,8 @@ public final class ApplicationState {
     public static void setCurrentUser(User currentUser) {
         ApplicationState.currentUser = currentUser;
     }
+
+    public static User getCurrentUser() {
+        return currentUser;
+    }
 }
diff --git a/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java b/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
index cd4784b0..36638370 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
@@ -1,6 +1,11 @@
 package NTNU.IDATT1002.controllers;
 
 import NTNU.IDATT1002.App;
+import NTNU.IDATT1002.ApplicationState;
+import NTNU.IDATT1002.models.ImageAlbum;
+import NTNU.IDATT1002.models.Tag;
+import NTNU.IDATT1002.models.User;
+import NTNU.IDATT1002.service.ImageAlbumService;
 import javafx.event.ActionEvent;
 import javafx.scene.control.Button;
 import javafx.scene.control.TextArea;
@@ -11,6 +16,10 @@ import javafx.scene.layout.GridPane;
 import javafx.scene.layout.Pane;
 
 import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * Controls the buttons and changeable elements on create_album.fxml,
@@ -33,6 +42,12 @@ public class CreateAlbum {
     public Button tbar_albums;
     public Button tbar_searchBtn;
 
+    private ImageAlbumService imageAlbumService;
+
+    public CreateAlbum() {
+        imageAlbumService = new ImageAlbumService();
+    }
+
     /**
      * Method that changes stage to Main page
      * @param mouseEvent
@@ -90,4 +105,30 @@ public class CreateAlbum {
     public void switchToUpload(ActionEvent actionEvent) throws IOException {
         App.setRoot("upload");
     }
+
+    public void createEmptyImageAlbum(ActionEvent actionEvent) {
+        User newUser = new User();
+        newUser.setUsername("Fillip");
+        ApplicationState.setCurrentUser(newUser);
+
+        String title =  album_title_field.getText();
+        String description = album_desc_field.getText();
+        List<Tag> tags = getTags();
+        User user = ApplicationState.getCurrentUser();
+
+        Optional<ImageAlbum> imageAlbum = imageAlbumService.createImageAlbum(title, description, user, tags);
+
+        System.out.println(imageAlbum.isPresent());
+    }
+
+    private List<Tag> getTags() {
+        String[] tagsAsStrings = album_tag_field.getText()
+                .trim()
+                .split("[, ?.@]+");
+
+        return Stream.of(tagsAsStrings)
+                .map(Tag::new)
+                .collect(Collectors.toList());
+    }
+
 }
diff --git a/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java b/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java
index afdbd702..07c7debb 100644
--- a/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java
+++ b/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java
@@ -11,6 +11,7 @@ import NTNU.IDATT1002.service.filters.ImageAlbumFilter;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -42,7 +43,7 @@ public class ImageAlbumService {
     }
 
     /**
-     * Saves a new image album with the given input.
+     * Create a new image album with all fields populated.
      *
      * @param title the title of the image album
      * @param description the description of the image album
@@ -66,6 +67,18 @@ public class ImageAlbumService {
         return imageAlbumRepository.save(imageAlbum);
     }
 
+    /**
+     * Create and empty image album.
+     *
+     * @param title the title of the image album
+     * @param description the description of the image album
+     * @param user the user of the image album
+     * @param tags the tags of the image album
+     */
+    public Optional<ImageAlbum> createImageAlbum(String title, String description, User user, List<Tag> tags) {
+        return createImageAlbum(title, description, user, tags, new ArrayList<>());
+    }
+
     /**
      * Retrieves all image albums created by the given user by username.
      *
diff --git a/src/main/resources/NTNU/IDATT1002/create_album.fxml b/src/main/resources/NTNU/IDATT1002/create_album.fxml
index faae6ab4..a47a0ef6 100644
--- a/src/main/resources/NTNU/IDATT1002/create_album.fxml
+++ b/src/main/resources/NTNU/IDATT1002/create_album.fxml
@@ -83,7 +83,7 @@
                         <Font name="System Bold" size="18.0" />
                      </font>
                   </Button>
-                  <Button fx:id="create_album_button" layoutX="641.0" layoutY="867.0" mnemonicParsing="false" text="CREATE ALBUM">
+                  <Button fx:id="create_album_button" layoutX="641.0" layoutY="867.0" mnemonicParsing="false" onAction="#createEmptyImageAlbum" text="CREATE ALBUM">
                      <font>
                         <Font name="System Bold" size="18.0" />
                      </font>
-- 
GitLab


From d683b04251b1a72834d4265da818a2ab1e2229b9 Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 10:08:12 +0100
Subject: [PATCH 02/12] Add anonmymous user and userRepository to
 ApplicationState

---
 .../java/NTNU/IDATT1002/ApplicationState.java | 32 ++++++++++++-
 .../IDATT1002/controllers/CreateAlbum.java    | 10 +---
 src/main/java/NTNU/IDATT1002/models/User.java | 30 ++++++++++--
 .../IDATT1002/repository/UserRepository.java  |  2 +-
 .../repository/LoginRepositoryTest.java       | 46 +++++++++----------
 5 files changed, 81 insertions(+), 39 deletions(-)

diff --git a/src/main/java/NTNU/IDATT1002/ApplicationState.java b/src/main/java/NTNU/IDATT1002/ApplicationState.java
index 73f4d145..b53dc857 100644
--- a/src/main/java/NTNU/IDATT1002/ApplicationState.java
+++ b/src/main/java/NTNU/IDATT1002/ApplicationState.java
@@ -2,6 +2,11 @@ package NTNU.IDATT1002;
 
 
 import NTNU.IDATT1002.models.User;
+import NTNU.IDATT1002.repository.UserRepository;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
 
 /**
  * Class Application State. Keeps a record of the global application state, such as the current logged in user.
@@ -13,11 +18,36 @@ public final class ApplicationState {
      */
     private static User currentUser;
 
+    /**
+     * Anonymous user for developing purposes.
+     */
+    private static User anonymousUser;
+
+    private static UserRepository userRepository;
+
+    /**
+     * Initiate properties and save an anonymous user once.
+     */
+    static {
+        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("ImageApplication");
+        EntityManager entityManager = entityManagerFactory.createEntityManager();
+
+        userRepository = new UserRepository(entityManager);
+    }
+
     public static void setCurrentUser(User currentUser) {
         ApplicationState.currentUser = currentUser;
     }
 
+    /**
+     * Retrieve the current logged in user if present, or retrieve an anonymous user.
+     *
+     * @return the current user.
+     * @throws IllegalArgumentException if neither the current user nor the anonymous user are present.
+     */
     public static User getCurrentUser() {
-        return currentUser;
+        return userRepository.findById(currentUser.getUsername())
+                .orElseGet(() -> userRepository.findById(anonymousUser.getUsername())
+                        .orElseThrow(IllegalArgumentException::new));
     }
 }
diff --git a/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java b/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
index 36638370..253374f8 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
@@ -2,7 +2,6 @@ package NTNU.IDATT1002.controllers;
 
 import NTNU.IDATT1002.App;
 import NTNU.IDATT1002.ApplicationState;
-import NTNU.IDATT1002.models.ImageAlbum;
 import NTNU.IDATT1002.models.Tag;
 import NTNU.IDATT1002.models.User;
 import NTNU.IDATT1002.service.ImageAlbumService;
@@ -17,7 +16,6 @@ import javafx.scene.layout.Pane;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.Optional;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -107,18 +105,12 @@ public class CreateAlbum {
     }
 
     public void createEmptyImageAlbum(ActionEvent actionEvent) {
-        User newUser = new User();
-        newUser.setUsername("Fillip");
-        ApplicationState.setCurrentUser(newUser);
-
         String title =  album_title_field.getText();
         String description = album_desc_field.getText();
         List<Tag> tags = getTags();
         User user = ApplicationState.getCurrentUser();
 
-        Optional<ImageAlbum> imageAlbum = imageAlbumService.createImageAlbum(title, description, user, tags);
-
-        System.out.println(imageAlbum.isPresent());
+        imageAlbumService.createImageAlbum(title, description, user, tags);
     }
 
     private List<Tag> getTags() {
diff --git a/src/main/java/NTNU/IDATT1002/models/User.java b/src/main/java/NTNU/IDATT1002/models/User.java
index 91de223a..256ad9b1 100644
--- a/src/main/java/NTNU/IDATT1002/models/User.java
+++ b/src/main/java/NTNU/IDATT1002/models/User.java
@@ -12,7 +12,7 @@ import java.util.List;
 @Table(name = "user")
 public class User {
 
-    @Id @NotBlank(message = "Username may not be blank")
+    @Id
     private String username;
 
     @Email
@@ -55,9 +55,9 @@ public class User {
     public User() {
     }
 
-    public User(String email, String username, String firstName, String lastName, String callingCode, String phoneNumber, Date birthDate) {
-        this.email = email;
+    public User(String username, String email, String firstName, String lastName, String callingCode, String phoneNumber, Date birthDate) {
         this.username = username;
+        this.email = email;
         this.firstName = firstName;
         this.lastName = lastName;
         this.callingCode = callingCode;
@@ -65,7 +65,6 @@ public class User {
         this.birthDate = birthDate;
         this.isAdmin = false;
         this.isActive = true;
-        this.imageAlbums = imageAlbums;
     }
 
     public String getEmail() {
@@ -108,6 +107,29 @@ public class User {
         this.username = username;
     }
 
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public void setCallingCode(String callingCode) {
+        this.callingCode = callingCode;
+    }
+
+    public void setPhoneNumber(String phoneNumber) {
+        this.phoneNumber = phoneNumber;
+    }
+
+    public void setBirthDate(Date birthDate) {
+        this.birthDate = birthDate;
+    }
     /**
      * Add given image album.
      *
diff --git a/src/main/java/NTNU/IDATT1002/repository/UserRepository.java b/src/main/java/NTNU/IDATT1002/repository/UserRepository.java
index 1ca6b3d8..df6fec47 100644
--- a/src/main/java/NTNU/IDATT1002/repository/UserRepository.java
+++ b/src/main/java/NTNU/IDATT1002/repository/UserRepository.java
@@ -10,7 +10,7 @@ import javax.persistence.EntityManager;
  *
  * @version 1.0 22.03.20
  */
-public class UserRepository extends GenericRepository<User, Long> {
+public class UserRepository extends GenericRepository<User, String> {
 
     /**
      * Constructor to inject {@link EntityManager} dependency and sets the class type to {@link User}
diff --git a/src/test/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java b/src/test/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java
index 72bab67e..e510f0d6 100644
--- a/src/test/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java
+++ b/src/test/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java
@@ -9,8 +9,6 @@ import org.junit.jupiter.api.Test;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
-
-import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -30,8 +28,8 @@ class LoginRepositoryTest {
 
     private LoginRepository loginRepository;
 
-    private String id1;
-    private String id2;
+    private String username1;
+    private String username2;
     private String password;
     private String newPassword;
     private Date date;
@@ -49,17 +47,17 @@ class LoginRepositoryTest {
     public void setUp() {
         EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("ImageApplicationTest");
         EntityManager entityManager = entityManagerFactory.createEntityManager();
+        loginRepository = new LoginRepository(entityManager);
 
-        id1 = "test1";
-        id2 = "test2";
+        username1 = "test1";
+        username2 = "test2";
         password = "Test123";
         newPassword = "Test321";
         date = new Date(System.currentTimeMillis());
-        user1 = new User("epost", id1, "fornavn", "etternavn", "test" , "test", date);
-        user2 = new User("epost2" , id2, "fornavn2", "etternavn2", "test2", "test2", date);
+        user1 = new User(username1,"epost","fornavn", "etternavn", "test" , "test", date);
+        user2 = new User(username2, "epost2" , "fornavn2", "etternavn2", "test2", "test2", date);
         login1 = new Login(user1, "test", "test");
         login2 = new Login(user2, "test2", "test2");
-        loginRepository = new LoginRepository(entityManager);
     }
 
     /**
@@ -101,10 +99,10 @@ class LoginRepositoryTest {
     void testFindByIdReturnsOptionalWithEntityWithId() {
 
         loginRepository.save(login1);
-        Optional<Login> foundLogins = loginRepository.findById(id1);
+        Optional<Login> foundLogins = loginRepository.findById(username1);
 
         assertTrue(foundLogins.isPresent());
-        assertEquals(id1, foundLogins.get().getUser().getUsername());
+        assertEquals(username1, foundLogins.get().getUser().getUsername());
     }
 
     /**
@@ -113,10 +111,10 @@ class LoginRepositoryTest {
     @Test
     void testDeleteById() {
         loginRepository.save(login1);
-        Optional<Login> foundLogins = loginRepository.findById(id1);
+        Optional<Login> foundLogins = loginRepository.findById(username1);
 
-        foundLogins.ifPresent(Login -> loginRepository.deleteById(id1));
-        Optional<Login> deletedLogin = loginRepository.findById(id1);
+        foundLogins.ifPresent(Login -> loginRepository.deleteById(username1));
+        Optional<Login> deletedLogin = loginRepository.findById(username1);
 
         assertTrue(deletedLogin.isEmpty());
     }
@@ -145,7 +143,7 @@ class LoginRepositoryTest {
         Login login3 = new Login(user1, salt, hash);
         loginRepository.save(login3);
 
-        assertTrue(loginRepository.logIn(id1, password));
+        assertTrue(loginRepository.logIn(username1, password));
     }
 
     /**
@@ -159,7 +157,7 @@ class LoginRepositoryTest {
         Login login3 = new Login(user1, salt, hash);
         loginRepository.save(login3);
 
-        assertTrue(loginRepository.changePassword(id1, password, newPassword));
+        assertTrue(loginRepository.changePassword(username1, password, newPassword));
     }
 
     /**
@@ -173,9 +171,9 @@ class LoginRepositoryTest {
         Login login3 = new Login(user1, salt, hash);
         loginRepository.save(login3);
 
-        assertTrue(loginRepository.logIn(id1, password));
-        assertTrue(loginRepository.changePassword(id1, password, newPassword));
-        assertTrue(loginRepository.logIn(id1, newPassword));
+        assertTrue(loginRepository.logIn(username1, password));
+        assertTrue(loginRepository.changePassword(username1, password, newPassword));
+        assertTrue(loginRepository.logIn(username1, newPassword));
     }
 
     /**
@@ -188,7 +186,7 @@ class LoginRepositoryTest {
         String hash = credentials.get(1);
         Login login3 = new Login(user1, salt, hash);
         loginRepository.save(login3);
-        assertFalse(loginRepository.logIn(id1, newPassword));
+        assertFalse(loginRepository.logIn(username1, newPassword));
     }
 
     /**
@@ -201,8 +199,8 @@ class LoginRepositoryTest {
         String hash = credentials.get(1);
         Login login3 = new Login(user1, salt, hash);
         loginRepository.save(login3);
-        assertFalse(loginRepository.changePassword(id1, newPassword, password));
-        assertTrue(loginRepository.logIn(id1, password));
+        assertFalse(loginRepository.changePassword(username1, newPassword, password));
+        assertTrue(loginRepository.logIn(username1, password));
     }
 
     /**
@@ -215,7 +213,7 @@ class LoginRepositoryTest {
         String hash = credentials.get(1);
         Login login3 = new Login(user1, salt, hash);
         loginRepository.save(login3);
-        assertFalse(loginRepository.logIn(id1, null));
+        assertFalse(loginRepository.logIn(username1, null));
     }
 
     /**
@@ -228,6 +226,6 @@ class LoginRepositoryTest {
         String hash = credentials.get(1);
         Login login3 = new Login(user1, salt, hash);
         loginRepository.save(login3);
-        assertFalse(loginRepository.changePassword(id1, null, newPassword));
+        assertFalse(loginRepository.changePassword(username1, null, newPassword));
     }
 }
\ No newline at end of file
-- 
GitLab


From a329aec21b6aeb4b300f2378216d89c82025ea9b Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 10:12:14 +0100
Subject: [PATCH 03/12] Add javadoc to CreateAlbumController

---
 .../NTNU/IDATT1002/controllers/CreateAlbum.java    | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java b/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
index 253374f8..a6ff748f 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
@@ -104,16 +104,26 @@ public class CreateAlbum {
         App.setRoot("upload");
     }
 
+    /**
+     * Create an empty image album. The user will default to the currently logged in user.
+     *
+     * @param actionEvent
+     */
     public void createEmptyImageAlbum(ActionEvent actionEvent) {
         String title =  album_title_field.getText();
         String description = album_desc_field.getText();
-        List<Tag> tags = getTags();
+        List<Tag> tags = getTagsFromTextField();
         User user = ApplicationState.getCurrentUser();
 
         imageAlbumService.createImageAlbum(title, description, user, tags);
     }
 
-    private List<Tag> getTags() {
+    /**
+     * Retrieves tags from text field and converts them to a list of tag objects.
+     *
+     * @return the list of tag objects
+     */
+    private List<Tag> getTagsFromTextField() {
         String[] tagsAsStrings = album_tag_field.getText()
                 .trim()
                 .split("[, ?.@]+");
-- 
GitLab


From 81ec9f8f52a2c174a75905226a5fcce99ba60ec6 Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 10:21:51 +0100
Subject: [PATCH 04/12] Change App.main back to normal

---
 pom.xml                                       |  6 +++++
 src/main/java/NTNU/IDATT1002/App.java         |  3 +--
 .../controllers/CreateAlbumTest.java          | 25 +++++++++++++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 src/test/java/NTNU/IDATT1002/controllers/CreateAlbumTest.java

diff --git a/pom.xml b/pom.xml
index da7e76c3..629802db 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,6 +127,12 @@
             <artifactId>bcprov-jdk15on</artifactId>
             <version>1.56</version>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-junit-jupiter</artifactId>
+            <version>3.3.0</version>
+            <scope>test</scope>
+        </dependency>
 
     </dependencies>
     <build>
diff --git a/src/main/java/NTNU/IDATT1002/App.java b/src/main/java/NTNU/IDATT1002/App.java
index b0981f7e..bb4ba2a5 100644
--- a/src/main/java/NTNU/IDATT1002/App.java
+++ b/src/main/java/NTNU/IDATT1002/App.java
@@ -18,8 +18,7 @@ public class App extends Application {
     @Override
     public void start(Stage stage) throws IOException {
         ex = new DataExchange();
-//        scene = new Scene(loadFXML("login"));
-        scene = new Scene(loadFXML("create_album"));
+        scene = new Scene(loadFXML("login"));
         stage.setScene(scene);
         stage.show();
     }
diff --git a/src/test/java/NTNU/IDATT1002/controllers/CreateAlbumTest.java b/src/test/java/NTNU/IDATT1002/controllers/CreateAlbumTest.java
new file mode 100644
index 00000000..75d5c2ff
--- /dev/null
+++ b/src/test/java/NTNU/IDATT1002/controllers/CreateAlbumTest.java
@@ -0,0 +1,25 @@
+package NTNU.IDATT1002.controllers;
+
+import NTNU.IDATT1002.repository.ImageAlbumRepository;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+class CreateAlbumTest {
+
+    @Mock
+    private ImageAlbumRepository imageAlbumRepository;
+
+
+
+    @BeforeEach
+    void setUp() {
+    }
+
+    @Test
+    void createEmptyImageAlbum() {
+    }
+}
\ No newline at end of file
-- 
GitLab


From 2a76af2b5ffcc7f7b1e31f721db0133725d268b3 Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 10:35:41 +0100
Subject: [PATCH 05/12] Move getTagsFromString to imageAlbumService

---
 .../IDATT1002/controllers/CreateAlbum.java    | 22 +------------------
 .../IDATT1002/service/ImageAlbumService.java  | 21 ++++++++++++++++--
 2 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java b/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
index a6ff748f..09681920 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/CreateAlbum.java
@@ -2,7 +2,6 @@ package NTNU.IDATT1002.controllers;
 
 import NTNU.IDATT1002.App;
 import NTNU.IDATT1002.ApplicationState;
-import NTNU.IDATT1002.models.Tag;
 import NTNU.IDATT1002.models.User;
 import NTNU.IDATT1002.service.ImageAlbumService;
 import javafx.event.ActionEvent;
@@ -15,9 +14,6 @@ import javafx.scene.layout.GridPane;
 import javafx.scene.layout.Pane;
 
 import java.io.IOException;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * Controls the buttons and changeable elements on create_album.fxml,
@@ -112,25 +108,9 @@ public class CreateAlbum {
     public void createEmptyImageAlbum(ActionEvent actionEvent) {
         String title =  album_title_field.getText();
         String description = album_desc_field.getText();
-        List<Tag> tags = getTagsFromTextField();
+        String tags = album_tag_field.getText();
         User user = ApplicationState.getCurrentUser();
 
         imageAlbumService.createImageAlbum(title, description, user, tags);
     }
-
-    /**
-     * Retrieves tags from text field and converts them to a list of tag objects.
-     *
-     * @return the list of tag objects
-     */
-    private List<Tag> getTagsFromTextField() {
-        String[] tagsAsStrings = album_tag_field.getText()
-                .trim()
-                .split("[, ?.@]+");
-
-        return Stream.of(tagsAsStrings)
-                .map(Tag::new)
-                .collect(Collectors.toList());
-    }
-
 }
diff --git a/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java b/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java
index 07c7debb..41fa883f 100644
--- a/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java
+++ b/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java
@@ -15,6 +15,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 
 /**
@@ -73,12 +74,28 @@ public class ImageAlbumService {
      * @param title the title of the image album
      * @param description the description of the image album
      * @param user the user of the image album
-     * @param tags the tags of the image album
+     * @param tagsAsString the tags of the image album as strings
      */
-    public Optional<ImageAlbum> createImageAlbum(String title, String description, User user, List<Tag> tags) {
+    public Optional<ImageAlbum> createImageAlbum(String title, String description, User user, String tagsAsString) {
+        List<Tag> tags = getTagsFromString(tagsAsString);
         return createImageAlbum(title, description, user, tags, new ArrayList<>());
     }
 
+    /**
+     * Retrieves tags from text field and converts them to a list of tag objects.
+     *
+     * @return the list of tag objects
+     */
+    private List<Tag> getTagsFromString(String tagsAsString) {
+        String[] tags = tagsAsString
+                .trim()
+                .split("[, ?.@]+");
+
+        return Stream.of(tags)
+                .map(Tag::new)
+                .collect(Collectors.toList());
+    }
+
     /**
      * Retrieves all image albums created by the given user by username.
      *
-- 
GitLab


From 901d072215ee291c3b35559059d2f6ba1dc7f662 Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 10:40:50 +0100
Subject: [PATCH 06/12] Remove mockito junit dependency

---
 pom.xml | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/pom.xml b/pom.xml
index 629802db..da7e76c3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,12 +127,6 @@
             <artifactId>bcprov-jdk15on</artifactId>
             <version>1.56</version>
         </dependency>
-        <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-junit-jupiter</artifactId>
-            <version>3.3.0</version>
-            <scope>test</scope>
-        </dependency>
 
     </dependencies>
     <build>
-- 
GitLab


From 1125943d91756239521b5577e0e1d432fd702d82 Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 11:33:47 +0100
Subject: [PATCH 07/12] what even

---
 src/main/java/NTNU/IDATT1002/App.java          |  2 +-
 .../IDATT1002/controllers/ExploreAlbums.java   | 14 ++++++++++++++
 .../IDATT1002/service/ImageAlbumService.java   | 18 +++++++++---------
 .../NTNU/IDATT1002/explore_albums.fxml         |  2 +-
 4 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/main/java/NTNU/IDATT1002/App.java b/src/main/java/NTNU/IDATT1002/App.java
index bb4ba2a5..ebc756de 100644
--- a/src/main/java/NTNU/IDATT1002/App.java
+++ b/src/main/java/NTNU/IDATT1002/App.java
@@ -18,7 +18,7 @@ public class App extends Application {
     @Override
     public void start(Stage stage) throws IOException {
         ex = new DataExchange();
-        scene = new Scene(loadFXML("login"));
+        scene = new Scene(loadFXML("explore_albums"));
         stage.setScene(scene);
         stage.show();
     }
diff --git a/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java b/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
index 7fefe1dc..40f35989 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
@@ -1,6 +1,7 @@
 package NTNU.IDATT1002.controllers;
 
 import NTNU.IDATT1002.App;
+import NTNU.IDATT1002.service.ImageAlbumService;
 import javafx.event.ActionEvent;
 import javafx.scene.control.Button;
 import javafx.scene.control.ChoiceBox;
@@ -62,6 +63,18 @@ public class ExploreAlbums {
     public Button open_album1;
     public Button open_album;
 
+    private ImageAlbumService imageAlbumService;
+
+    public ExploreAlbums() {
+        imageAlbumService = new ImageAlbumService();
+
+        populateImageAlbumPanes();
+    }
+
+    private void populatePanes() {
+        pulateImageAlbumPane1();
+    }
+
     /**
      * Method that changes stage to Main page
      * @param mouseEvent
@@ -156,4 +169,5 @@ public class ExploreAlbums {
         //TODO: write method to open the specific album chosen
         App.setRoot("view_album");
     }
+
 }
diff --git a/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java b/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java
index 41fa883f..f5655614 100644
--- a/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java
+++ b/src/main/java/NTNU/IDATT1002/service/ImageAlbumService.java
@@ -43,6 +43,15 @@ public class ImageAlbumService {
         this.tagRepository = new TagRepository(entityManager);
     }
 
+    /**
+     * Retrieves all image albums.
+     *
+     * @return list of all image albums.
+     */
+    public List<ImageAlbum> getAllImageAlbums() {
+        return imageAlbumRepository.findAll();
+    }
+
     /**
      * Create a new image album with all fields populated.
      *
@@ -106,15 +115,6 @@ public class ImageAlbumService {
         return imageAlbumRepository.findAllByUsername(user.getUsername());
     }
 
-    /**
-     * Retrieves all image albums.
-     *
-     * @return list of all image albums.
-     */
-    public List<ImageAlbum> getAllImageAlbums() {
-        return imageAlbumRepository.findAll();
-    }
-
 
     /**
      *  Adds the given tag to the given image album.
diff --git a/src/main/resources/NTNU/IDATT1002/explore_albums.fxml b/src/main/resources/NTNU/IDATT1002/explore_albums.fxml
index ddb7cfc6..2220bd28 100644
--- a/src/main/resources/NTNU/IDATT1002/explore_albums.fxml
+++ b/src/main/resources/NTNU/IDATT1002/explore_albums.fxml
@@ -83,7 +83,7 @@
                                 <Pane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #6d6d6d;" BorderPane.alignment="CENTER" />
                             </right>
                             <center>
-                                <GridPane alignment="CENTER" BorderPane.alignment="CENTER">
+                                <GridPane fx:id="albums" alignment="CENTER" BorderPane.alignment="CENTER">
                                     <columnConstraints>
                                         <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                                     </columnConstraints>
-- 
GitLab


From 57cd1f624e00b7410d944847720925f1f4658efe Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 13:22:32 +0100
Subject: [PATCH 08/12] Made explore albums page dynamic

---
 .../IDATT1002/controllers/ExploreAlbums.java  | 228 ++++++++++++--
 .../NTNU/IDATT1002/explore_albums.fxml        | 284 +-----------------
 2 files changed, 206 insertions(+), 306 deletions(-)

diff --git a/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java b/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
index 40f35989..6acf0469 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
@@ -3,78 +3,241 @@ package NTNU.IDATT1002.controllers;
 import NTNU.IDATT1002.App;
 import NTNU.IDATT1002.service.ImageAlbumService;
 import javafx.event.ActionEvent;
-import javafx.scene.control.Button;
-import javafx.scene.control.ChoiceBox;
-import javafx.scene.control.ScrollPane;
-import javafx.scene.control.TextField;
+import javafx.fxml.FXML;
+import javafx.fxml.Initializable;
+import javafx.scene.control.*;
+import javafx.scene.image.Image;
 import javafx.scene.image.ImageView;
 import javafx.scene.input.MouseEvent;
+import javafx.scene.layout.GridPane;
+import javafx.scene.layout.Pane;
+import javafx.scene.shape.StrokeType;
+import javafx.scene.text.Font;
 import javafx.scene.text.Text;
 
 import java.io.IOException;
+import java.net.URL;
+import java.util.ResourceBundle;
 
 /**
  * Controls the buttons and changeable elements on explore_albums.fxml,
  * a page where you explore albums
  * @version 1.0 22.03.2020
  */
-public class ExploreAlbums {
+public class ExploreAlbums implements Initializable {
     public ImageView tbar_logo;
     public TextField tbar_search;
     public Button tbar_map;
     public Button tbar_upload;
+    public Button tbar_albums;
+    public Button tbar_searchBtn;
+    public Button tbar_explore;
+
     public ScrollPane scrollpane;
     public Button footer_previous_page;
     public Button footer_next_page;
-    public Button tbar_searchBtn;
-    public Button tbar_explore;
+
     public Text album_amount;
     public ChoiceBox sorted_by_choicebox;
     public Button create_album_button;
+
     public ImageView album_image;
     public Text album_author;
     public Text album_title;
     public Text album_desc;
     public Text album_tags;
-    public Text album_author2;
+    public Button open_album;
+
+    public ImageView album_image2;
     public Text album_title2;
+    public Text album_author2;
     public Text album_desc2;
     public Text album_tags2;
-    public ImageView album_image2;
-    public ImageView album_image3;
-    public Text album_author3;
-    public Text album_title3;
-    public Text album_desc3;
-    public Text album_tags3;
-    public ImageView album_image4;
-    public Text album_author4;
-    public Text album_title4;
-    public Text album_desc4;
-    public Text album_tags4;
-    public ImageView album_image5;
-    public Text album_author5;
-    public Text album_title5;
-    public Text album_desc5;
-    public Text album_tags5;
-    public Button tbar_albums;
-    public Button open_album4;
-    public Button open_album3;
     public Button open_album2;
-    public Button open_album1;
-    public Button open_album;
+
+    @FXML
+    private GridPane albums_grid_pane;
+    private Pane paneContainer;
+    private Label paneLabel;
 
     private ImageAlbumService imageAlbumService;
 
     public ExploreAlbums() {
         imageAlbumService = new ImageAlbumService();
+    }
+
+    @Override
+    public void initialize(URL url, ResourceBundle resourceBundle) {
+        for(int i = 0; i<4; i++) {
+            paneContainer = new Pane();
+            paneContainer.setStyle("prefHeight:200.0; prefWidth:200.0; ");
+            paneContainer.setPrefWidth(200);
+            paneContainer.setPrefHeight(100);
+
+            addSingleAlbumContentToPane(paneContainer);
+
+            albums_grid_pane.add(paneContainer, 0, i);
+        }
+    }
+
+    private void addSingleAlbumContentToPane(Pane pane) {
+        insertImageViewToPane(pane);
+        insertAlbumTitleLabelToPane(pane);
+        insertAlbumAuthorLabelToPane(pane);
+        insertAlbumDescriptionLabelToPane(pane);
+        insertAlbumAuthorToPane(pane);
+        insertAlbumTitleToPane(pane);
+        insertAlbumDescriptionToPane(pane);
+        insertAlbumTagsLabelToPane(pane);
+        insertAlbumTagsToPane(pane);
+        insertOpenAlbumButtonToPane(pane);
+    }
+
+    private void insertAlbumAuthorLabelToPane(Pane pane) {
+        // set and format author label
+        Text authorLabel = new Text();
+        authorLabel.setText("AUTHOR: ");
+        authorLabel.setFont(Font.font(24));
+        authorLabel.setLayoutX(551.0);
+        authorLabel.setLayoutY(97.0);
+        authorLabel.setStrokeType(StrokeType.OUTSIDE);
+        authorLabel.setStrokeWidth(0.0);
+        authorLabel.setWrappingWidth(150.0);
+
+        pane.getChildren().add(authorLabel);
+    }
+
+    private void insertAlbumDescriptionLabelToPane(Pane pane) {
+        // set and format description label
+        Text descriptionLabel = new Text();
+        descriptionLabel.setText("DESCRIPTION: ");
+        descriptionLabel.setFont(Font.font(18.0));
+        descriptionLabel.setLayoutX(551.0);
+        descriptionLabel.setLayoutY(157.0);
+        descriptionLabel.setStrokeType(StrokeType.OUTSIDE);
+        descriptionLabel.setStrokeWidth(0.0);
+        descriptionLabel.setWrappingWidth(129.0);
+
+        pane.getChildren().add(descriptionLabel);
+    }
+
+    private void insertAlbumAuthorToPane(Pane pane) {
+        // set and format author
+        album_author2 = new Text();
+        album_author2.setId("album_author");
+        album_author2.setText("INSERT AUTHOR HERE");
+        album_author2.setFont(Font.font(24.0));
+        album_author2.setLayoutX(707.0);
+        album_author2.setLayoutY(97.0);
+        album_author2.setStrokeType(StrokeType.OUTSIDE);
+        album_author2.setStrokeWidth(0.0);
+        album_author2.setWrappingWidth(270.0);
+
+        pane.getChildren().add(album_author2);
+    }
 
-        populateImageAlbumPanes();
+    private void insertAlbumTitleToPane(Pane pane) {
+        // set and format title
+        album_title2 = new Text();
+        album_title2.setId("album_title");
+        album_title2.setText("INSERT TITLE HERE");
+        album_title2.setFont(Font.font(48.0));
+        album_title2.setLayoutX(751.0);
+        album_title2.setLayoutY(65.0);
+        album_title2.setStrokeType(StrokeType.OUTSIDE);
+        album_title2.setStrokeWidth(0.0);
+        album_title2.setWrappingWidth(653.0);
+
+        pane.getChildren().add(album_title2);
     }
 
-    private void populatePanes() {
-        pulateImageAlbumPane1();
+    private void insertAlbumDescriptionToPane(Pane pane) {
+        // set and format description
+        album_desc2 = new Text();
+        album_desc2.setId("album_desc");
+        album_desc2.setText("INSERT DESC HERE");
+        album_desc2.setFont(Font.font(18.0));
+        album_desc2.setLayoutX(707.0);
+        album_desc2.setLayoutY(157.0);
+        album_desc2.setStrokeType(StrokeType.OUTSIDE);
+        album_desc2.setStrokeWidth(0.0);
+        album_desc2.setWrappingWidth(229.0);
+
+        pane.getChildren().add(album_desc2);
     }
 
+    private void insertAlbumTagsLabelToPane(Pane paneContainer) {
+        // set and format tags label
+        Text tagsLabel = new Text();
+        tagsLabel.setText("TAGS: ");
+        tagsLabel.setFont(Font.font(24));
+        tagsLabel.setLayoutX(551.0);
+        tagsLabel.setLayoutY(129.0);
+        tagsLabel.setStrokeType(StrokeType.OUTSIDE);
+        tagsLabel.setStrokeWidth(0.0);
+        tagsLabel.setWrappingWidth(150.0);
+
+        paneContainer.getChildren().add(tagsLabel);
+    }
+
+    private void insertAlbumTagsToPane(Pane pane) {
+        // set and format tags
+        Text tags = new Text();
+        tags.setText("INSERT TAGS HERE");
+        tags.setFont(Font.font(24.0));
+        tags.setLayoutX(707.0);
+        tags.setLayoutY(129.0);
+        tags.setStrokeType(StrokeType.OUTSIDE);
+        tags.setStrokeWidth(0.0);
+        tags.setWrappingWidth(270.0);
+
+        pane.getChildren().add(tags);
+    }
+
+    private void insertOpenAlbumButtonToPane(Pane pane) {
+        // set and format open album button
+        open_album2 = new Button();
+        open_album2.setId("open_album");
+        open_album2.setText("Open Album");
+        open_album2.setFont(Font.font(18.0));
+        open_album2.setLayoutX(551.0);
+        open_album2.setLayoutY(250.0);
+
+        pane.getChildren().add(open_album2);
+    }
+
+    private void insertImageViewToPane(Pane pane) {
+        // Set and format image
+        album_image2 = new ImageView();
+        album_image2.setFitHeight(307.0);
+        album_image2.setFitWidth(516.0);
+        album_image2.setLayoutX(-2.0);
+        album_image2.setLayoutY(-1.0);
+        album_image2.setPickOnBounds(true);
+        album_image2.setPreserveRatio(true);
+        album_image2.setId("put_image_album_id_here");
+
+        Image image = new Image("@../../Images/placeholder-1920x1080.png");
+        album_image2.setImage(image);
+
+        pane.getChildren().add(album_image2);
+    }
+
+    private void insertAlbumTitleLabelToPane(Pane pane) {
+        // set and format title label
+        Text text = new Text();
+        text.setText("ALBUM: ");
+        text.setFont(Font.font(48.0));
+        text.setLayoutX(551.0);
+        text.setLayoutY(63.0);
+        text.setStrokeType(StrokeType.OUTSIDE);
+        text.setStrokeWidth(0.0);
+        text.setWrappingWidth(200);
+
+        pane.getChildren().add(text);
+    }
+
+
     /**
      * Method that changes stage to Main page
      * @param mouseEvent
@@ -170,4 +333,5 @@ public class ExploreAlbums {
         App.setRoot("view_album");
     }
 
+
 }
diff --git a/src/main/resources/NTNU/IDATT1002/explore_albums.fxml b/src/main/resources/NTNU/IDATT1002/explore_albums.fxml
index 2220bd28..49f92493 100644
--- a/src/main/resources/NTNU/IDATT1002/explore_albums.fxml
+++ b/src/main/resources/NTNU/IDATT1002/explore_albums.fxml
@@ -83,7 +83,7 @@
                                 <Pane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #6d6d6d;" BorderPane.alignment="CENTER" />
                             </right>
                             <center>
-                                <GridPane fx:id="albums" alignment="CENTER" BorderPane.alignment="CENTER">
+                                <GridPane fx:id="albums_grid_pane" alignment="CENTER" BorderPane.alignment="CENTER">
                                     <columnConstraints>
                                         <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                                     </columnConstraints>
@@ -95,281 +95,15 @@
                                         <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                     </rowConstraints>
                                     <children>
+
                                         <Pane prefHeight="200.0" prefWidth="200.0">
-                                            <children>
-                                                <ImageView fx:id="album_image" fitHeight="307.0" fitWidth="516.0" layoutX="-2.0" layoutY="-1.0" pickOnBounds="true" preserveRatio="true">
-                                                    <image>
-                                                        <Image url="@../../Images/placeholder-1920x1080.png" />
-                                                    </image>
-                                                </ImageView>
-                                                <Text layoutX="551.0" layoutY="63.0" strokeType="OUTSIDE" strokeWidth="0.0" text="ALBUM:" wrappingWidth="200.0">
-                                                    <font>
-                                                        <Font name="System Bold" size="48.0" />
-                                                    </font>
-                                                </Text>
-                                                <Text layoutX="551.0" layoutY="97.0" strokeType="OUTSIDE" strokeWidth="0.0" text="AUTHOR:" wrappingWidth="150.0">
-                                                    <font>
-                                                        <Font name="System Bold" size="24.0" />
-                                                    </font>
-                                                </Text>
-                                                <Text layoutX="551.0" layoutY="157.0" strokeType="OUTSIDE" strokeWidth="0.0" text="DESCRIPTION:" wrappingWidth="129.0">
-                                                    <font>
-                                                        <Font name="System Bold" size="18.0" />
-                                                    </font>
-                                                </Text>
-                                                <Text fx:id="album_author" layoutX="707.0" layoutY="97.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="70.0">
-                                                    <font>
-                                                        <Font name="System Bold" size="24.0" />
-                                                    </font>
-                                                </Text>
-                                                <Text fx:id="album_title" layoutX="751.0" layoutY="65.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="153.0">
-                                                    <font>
-                                                        <Font name="System Bold" size="48.0" />
-                                                    </font>
-                                                </Text>
-                                                <Text fx:id="album_desc" layoutX="707.0" layoutY="157.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="129.0">
-                                                    <font>
-                                                        <Font name="System Bold" size="18.0" />
-                                                    </font>
-                                                </Text>
-                                    <Text layoutX="551.0" layoutY="129.0" strokeType="OUTSIDE" strokeWidth="0.0" text="TAGS:" wrappingWidth="150.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_tags" layoutX="707.0" layoutY="129.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="70.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Button fx:id="open_album" layoutX="551.0" layoutY="250.0" mnemonicParsing="false" onAction="#switchToViewAlbum" text="Open Album">
-                                       <font>
-                                          <Font size="18.0" />
-                                       </font>
-                                    </Button>
-                                            </children>
-                                        </Pane>
-                                        <Pane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
-                                            <children>
-                                                <ImageView fx:id="album_image2" fitHeight="307.0" fitWidth="516.0" layoutX="-2.0" layoutY="-1.0" pickOnBounds="true" preserveRatio="true">
-                                                    <image>
-                                                        <Image url="@../../Images/placeholder-1920x1080.png" />
-                                                    </image>
-                                                </ImageView>
-                                    <Text layoutX="552.0" layoutY="67.0" strokeType="OUTSIDE" strokeWidth="0.0" text="ALBUM:" wrappingWidth="200.0">
-                                       <font>
-                                          <Font name="System Bold" size="48.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="552.0" layoutY="101.0" strokeType="OUTSIDE" strokeWidth="0.0" text="AUTHOR:" wrappingWidth="150.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="552.0" layoutY="161.0" strokeType="OUTSIDE" strokeWidth="0.0" text="DESCRIPTION:" wrappingWidth="129.0">
-                                       <font>
-                                          <Font name="System Bold" size="18.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_author2" layoutX="708.0" layoutY="101.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="70.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_title2" layoutX="752.0" layoutY="69.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="153.0">
-                                       <font>
-                                          <Font name="System Bold" size="48.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_desc2" layoutX="708.0" layoutY="161.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="129.0">
-                                       <font>
-                                          <Font name="System Bold" size="18.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="552.0" layoutY="133.0" strokeType="OUTSIDE" strokeWidth="0.0" text="TAGS:" wrappingWidth="150.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_tags2" layoutX="708.0" layoutY="133.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="70.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Button fx:id="open_album1" layoutX="551.0" layoutY="250.0" mnemonicParsing="false" onAction="#switchToViewAlbum" text="Open Album">
-                                       <font>
-                                          <Font size="18.0" />
-                                       </font>
-                                    </Button>
-                                            </children>
-                                        </Pane>
-                                        <Pane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2">
-                                            <children>
-                                                <ImageView fx:id="album_image3" fitHeight="307.0" fitWidth="516.0" layoutX="-2.0" layoutY="-1.0" pickOnBounds="true" preserveRatio="true">
-                                                    <image>
-                                                        <Image url="@../../Images/placeholder-1920x1080.png" />
-                                                    </image>
-                                                </ImageView>
-                                    <Text layoutX="545.0" layoutY="66.0" strokeType="OUTSIDE" strokeWidth="0.0" text="ALBUM:" wrappingWidth="200.0">
-                                       <font>
-                                          <Font name="System Bold" size="48.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="545.0" layoutY="100.0" strokeType="OUTSIDE" strokeWidth="0.0" text="AUTHOR:" wrappingWidth="150.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="545.0" layoutY="160.0" strokeType="OUTSIDE" strokeWidth="0.0" text="DESCRIPTION:" wrappingWidth="129.0">
-                                       <font>
-                                          <Font name="System Bold" size="18.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_author3" layoutX="701.0" layoutY="100.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="70.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_title3" layoutX="745.0" layoutY="68.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="153.0">
-                                       <font>
-                                          <Font name="System Bold" size="48.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_desc3" layoutX="701.0" layoutY="160.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="129.0">
-                                       <font>
-                                          <Font name="System Bold" size="18.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="545.0" layoutY="132.0" strokeType="OUTSIDE" strokeWidth="0.0" text="TAGS:" wrappingWidth="150.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_tags3" layoutX="701.0" layoutY="132.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="70.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Button fx:id="open_album2" layoutX="551.0" layoutY="250.0" mnemonicParsing="false" onAction="#switchToViewAlbum" text="Open Album">
-                                       <font>
-                                          <Font size="18.0" />
-                                       </font>
-                                    </Button>
-                                            </children>
-                                        </Pane>
-                                        <Pane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="3">
-                                            <children>
-                                                <ImageView fx:id="album_image4" fitHeight="307.0" fitWidth="516.0" layoutX="-2.0" layoutY="-1.0" pickOnBounds="true" preserveRatio="true">
-                                                    <image>
-                                                        <Image url="@../../Images/placeholder-1920x1080.png" />
-                                                    </image>
-                                                </ImageView>
-                                    <Text layoutX="545.0" layoutY="66.0" strokeType="OUTSIDE" strokeWidth="0.0" text="ALBUM:" wrappingWidth="200.0">
-                                       <font>
-                                          <Font name="System Bold" size="48.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="545.0" layoutY="100.0" strokeType="OUTSIDE" strokeWidth="0.0" text="AUTHOR:" wrappingWidth="150.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="545.0" layoutY="160.0" strokeType="OUTSIDE" strokeWidth="0.0" text="DESCRIPTION:" wrappingWidth="129.0">
-                                       <font>
-                                          <Font name="System Bold" size="18.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_author4" layoutX="701.0" layoutY="100.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="70.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_title4" layoutX="745.0" layoutY="68.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="153.0">
-                                       <font>
-                                          <Font name="System Bold" size="48.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_desc4" layoutX="701.0" layoutY="160.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="129.0">
-                                       <font>
-                                          <Font name="System Bold" size="18.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="545.0" layoutY="132.0" strokeType="OUTSIDE" strokeWidth="0.0" text="TAGS:" wrappingWidth="150.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_tags4" layoutX="701.0" layoutY="132.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="70.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Button fx:id="open_album3" layoutX="551.0" layoutY="250.0" mnemonicParsing="false" onAction="#switchToViewAlbum" text="Open Album">
-                                       <font>
-                                          <Font size="18.0" />
-                                       </font>
-                                    </Button>
-                                            </children>
-                                        </Pane>
-                                        <Pane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="4">
-                                            <children>
-                                                <ImageView fx:id="album_image5" fitHeight="307.0" fitWidth="516.0" layoutX="-2.0" layoutY="-1.0" pickOnBounds="true" preserveRatio="true">
-                                                    <image>
-                                                        <Image url="@../../Images/placeholder-1920x1080.png" />
-                                                    </image>
-                                                </ImageView>
-                                    <Text layoutX="545.0" layoutY="65.0" strokeType="OUTSIDE" strokeWidth="0.0" text="ALBUM:" wrappingWidth="200.0">
-                                       <font>
-                                          <Font name="System Bold" size="48.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="545.0" layoutY="99.0" strokeType="OUTSIDE" strokeWidth="0.0" text="AUTHOR:" wrappingWidth="150.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="545.0" layoutY="159.0" strokeType="OUTSIDE" strokeWidth="0.0" text="DESCRIPTION:" wrappingWidth="129.0">
-                                       <font>
-                                          <Font name="System Bold" size="18.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_author5" layoutX="701.0" layoutY="99.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="70.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_title5" layoutX="745.0" layoutY="67.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="153.0">
-                                       <font>
-                                          <Font name="System Bold" size="48.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_desc5" layoutX="701.0" layoutY="159.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="129.0">
-                                       <font>
-                                          <Font name="System Bold" size="18.0" />
-                                       </font>
-                                    </Text>
-                                    <Text layoutX="545.0" layoutY="131.0" strokeType="OUTSIDE" strokeWidth="0.0" text="TAGS:" wrappingWidth="150.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Text fx:id="album_tags5" layoutX="701.0" layoutY="131.0" strokeType="OUTSIDE" strokeWidth="0.0" text="&quot;&quot;" wrappingWidth="70.0">
-                                       <font>
-                                          <Font name="System Bold" size="24.0" />
-                                       </font>
-                                    </Text>
-                                    <Button fx:id="open_album4" layoutX="551.0" layoutY="250.0" mnemonicParsing="false" onAction="#switchToViewAlbum" text="Open Album">
-                                       <font>
-                                          <Font size="18.0" />
-                                       </font>
-                                    </Button>
-                                            </children>
                                         </Pane>
+
                                     </children>
                                 </GridPane>
-                            </center>
-                            <bottom>
-                                <Pane prefHeight="150.0" prefWidth="1920.0" style="-fx-background-color: #6d6d6d;" BorderPane.alignment="CENTER">
+                                        </center>
+                                        <bottom>
+                                    <Pane prefHeight="150.0" prefWidth="1920.0" style="-fx-background-color: #6d6d6d;" BorderPane.alignment="CENTER">
                                     <children>
                                         <HBox alignment="CENTER" layoutY="-2.0" prefHeight="84.0" prefWidth="1920.0" spacing="20.0">
                                             <children>
@@ -377,10 +111,12 @@
                                                 <Button fx:id="footer_next_page" layoutX="944.0" layoutY="48.0" mnemonicParsing="false" onAction="#switchToNext" text="NEXT" />
                                             </children>
                                         </HBox>
-                                    </children></Pane>
+                                    </children>
+                                </Pane>
                             </bottom>
                         </BorderPane>
-                    </children></AnchorPane>
+                    </children>
+                </AnchorPane>
             </content>
         </ScrollPane>
     </children>
-- 
GitLab


From f460bff1c8ac5fb658594afef641e5e8f75dcab3 Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 13:56:32 +0100
Subject: [PATCH 09/12] Gridpane album population

---
 .../IDATT1002/controllers/ExploreAlbums.java  | 117 ++++++++++--------
 1 file changed, 62 insertions(+), 55 deletions(-)

diff --git a/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java b/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
index 6acf0469..4a412697 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
@@ -1,6 +1,7 @@
 package NTNU.IDATT1002.controllers;
 
 import NTNU.IDATT1002.App;
+import NTNU.IDATT1002.models.ImageAlbum;
 import NTNU.IDATT1002.service.ImageAlbumService;
 import javafx.event.ActionEvent;
 import javafx.fxml.FXML;
@@ -17,6 +18,7 @@ import javafx.scene.text.Text;
 
 import java.io.IOException;
 import java.net.URL;
+import java.util.List;
 import java.util.ResourceBundle;
 
 /**
@@ -68,32 +70,67 @@ public class ExploreAlbums implements Initializable {
 
     @Override
     public void initialize(URL url, ResourceBundle resourceBundle) {
-        for(int i = 0; i<4; i++) {
+        List<ImageAlbum> albums = imageAlbumService.getAllImageAlbums();
+
+        for(int i = 0; i<albums.size(); i++) {
             paneContainer = new Pane();
             paneContainer.setStyle("prefHeight:200.0; prefWidth:200.0; ");
             paneContainer.setPrefWidth(200);
             paneContainer.setPrefHeight(100);
 
-            addSingleAlbumContentToPane(paneContainer);
+            addSingleAlbumContentToPane(album, paneContainer);
 
             albums_grid_pane.add(paneContainer, 0, i);
         }
     }
 
-    private void addSingleAlbumContentToPane(Pane pane) {
-        insertImageViewToPane(pane);
-        insertAlbumTitleLabelToPane(pane);
-        insertAlbumAuthorLabelToPane(pane);
-        insertAlbumDescriptionLabelToPane(pane);
-        insertAlbumAuthorToPane(pane);
-        insertAlbumTitleToPane(pane);
-        insertAlbumDescriptionToPane(pane);
-        insertAlbumTagsLabelToPane(pane);
-        insertAlbumTagsToPane(pane);
-        insertOpenAlbumButtonToPane(pane);
+    private void addSingleAlbumContentToPane(ImageAlbum album, Pane pane) {
+        insertImageViewToPane(album, pane);
+        insertAlbumTitleLabelToPane(album, pane);
+        insertAlbumAuthorLabelToPane(album, pane);
+        insertAlbumDescriptionLabelToPane(album, pane);
+        insertAlbumAuthorToPane(album, pane);
+        insertAlbumTitleToPane(album, pane);
+        insertAlbumDescriptionToPane(album, pane);
+        insertAlbumTagsLabelToPane(album, pane);
+        insertAlbumTagsToPane(album, pane);
+        insertOpenAlbumButtonToPane(album, pane);
+    }
+
+    private void insertImageViewToPane(ImageAlbum album, Pane pane) {
+        // Set and format image
+        album_image2 = new ImageView();
+        album_image2.setFitHeight(307.0);
+        album_image2.setFitWidth(516.0);
+        album_image2.setLayoutX(-2.0);
+        album_image2.setLayoutY(-1.0);
+        album_image2.setPickOnBounds(true);
+        album_image2.setPreserveRatio(true);
+
+        NTNU.IDATT1002.models.Image titleImage = album.getImages().get(0);
+        album_image2.setId(titleImage.getId().toString());
+
+        Image image = new Image("@../../Images/placeholder-1920x1080.png"); // TODO: display image here
+        album_image2.setImage(image);
+
+        pane.getChildren().add(album_image2);
     }
 
-    private void insertAlbumAuthorLabelToPane(Pane pane) {
+    private void insertAlbumTitleLabelToPane(ImageAlbum album, Pane pane) {
+        // set and format title label
+        Text text = new Text();
+        text.setText("ALBUM: ");
+        text.setFont(Font.font(48.0));
+        text.setLayoutX(551.0);
+        text.setLayoutY(63.0);
+        text.setStrokeType(StrokeType.OUTSIDE);
+        text.setStrokeWidth(0.0);
+        text.setWrappingWidth(200);
+
+        pane.getChildren().add(text);
+    }
+
+    private void insertAlbumAuthorLabelToPane(ImageAlbum album, Pane pane) {
         // set and format author label
         Text authorLabel = new Text();
         authorLabel.setText("AUTHOR: ");
@@ -107,7 +144,7 @@ public class ExploreAlbums implements Initializable {
         pane.getChildren().add(authorLabel);
     }
 
-    private void insertAlbumDescriptionLabelToPane(Pane pane) {
+    private void insertAlbumDescriptionLabelToPane(ImageAlbum album, Pane pane) {
         // set and format description label
         Text descriptionLabel = new Text();
         descriptionLabel.setText("DESCRIPTION: ");
@@ -121,11 +158,11 @@ public class ExploreAlbums implements Initializable {
         pane.getChildren().add(descriptionLabel);
     }
 
-    private void insertAlbumAuthorToPane(Pane pane) {
+    private void insertAlbumAuthorToPane(ImageAlbum album, Pane pane) {
         // set and format author
         album_author2 = new Text();
         album_author2.setId("album_author");
-        album_author2.setText("INSERT AUTHOR HERE");
+        album_author2.setText(album.getUser().getUsername());
         album_author2.setFont(Font.font(24.0));
         album_author2.setLayoutX(707.0);
         album_author2.setLayoutY(97.0);
@@ -136,11 +173,11 @@ public class ExploreAlbums implements Initializable {
         pane.getChildren().add(album_author2);
     }
 
-    private void insertAlbumTitleToPane(Pane pane) {
+    private void insertAlbumTitleToPane(ImageAlbum album, Pane pane) {
         // set and format title
         album_title2 = new Text();
         album_title2.setId("album_title");
-        album_title2.setText("INSERT TITLE HERE");
+        album_title2.setText(album.getTitle());
         album_title2.setFont(Font.font(48.0));
         album_title2.setLayoutX(751.0);
         album_title2.setLayoutY(65.0);
@@ -151,11 +188,11 @@ public class ExploreAlbums implements Initializable {
         pane.getChildren().add(album_title2);
     }
 
-    private void insertAlbumDescriptionToPane(Pane pane) {
+    private void insertAlbumDescriptionToPane(ImageAlbum album, Pane pane) {
         // set and format description
         album_desc2 = new Text();
         album_desc2.setId("album_desc");
-        album_desc2.setText("INSERT DESC HERE");
+        album_desc2.setText(album.getDescription());
         album_desc2.setFont(Font.font(18.0));
         album_desc2.setLayoutX(707.0);
         album_desc2.setLayoutY(157.0);
@@ -166,7 +203,7 @@ public class ExploreAlbums implements Initializable {
         pane.getChildren().add(album_desc2);
     }
 
-    private void insertAlbumTagsLabelToPane(Pane paneContainer) {
+    private void insertAlbumTagsLabelToPane(ImageAlbum album, Pane paneContainer) {
         // set and format tags label
         Text tagsLabel = new Text();
         tagsLabel.setText("TAGS: ");
@@ -180,10 +217,10 @@ public class ExploreAlbums implements Initializable {
         paneContainer.getChildren().add(tagsLabel);
     }
 
-    private void insertAlbumTagsToPane(Pane pane) {
+    private void insertAlbumTagsToPane(ImageAlbum album, Pane pane) {
         // set and format tags
         Text tags = new Text();
-        tags.setText("INSERT TAGS HERE");
+        tags.setText(String.join(", ", (CharSequence) album.getTags()));
         tags.setFont(Font.font(24.0));
         tags.setLayoutX(707.0);
         tags.setLayoutY(129.0);
@@ -194,7 +231,7 @@ public class ExploreAlbums implements Initializable {
         pane.getChildren().add(tags);
     }
 
-    private void insertOpenAlbumButtonToPane(Pane pane) {
+    private void insertOpenAlbumButtonToPane(ImageAlbum album, Pane pane) {
         // set and format open album button
         open_album2 = new Button();
         open_album2.setId("open_album");
@@ -206,36 +243,6 @@ public class ExploreAlbums implements Initializable {
         pane.getChildren().add(open_album2);
     }
 
-    private void insertImageViewToPane(Pane pane) {
-        // Set and format image
-        album_image2 = new ImageView();
-        album_image2.setFitHeight(307.0);
-        album_image2.setFitWidth(516.0);
-        album_image2.setLayoutX(-2.0);
-        album_image2.setLayoutY(-1.0);
-        album_image2.setPickOnBounds(true);
-        album_image2.setPreserveRatio(true);
-        album_image2.setId("put_image_album_id_here");
-
-        Image image = new Image("@../../Images/placeholder-1920x1080.png");
-        album_image2.setImage(image);
-
-        pane.getChildren().add(album_image2);
-    }
-
-    private void insertAlbumTitleLabelToPane(Pane pane) {
-        // set and format title label
-        Text text = new Text();
-        text.setText("ALBUM: ");
-        text.setFont(Font.font(48.0));
-        text.setLayoutX(551.0);
-        text.setLayoutY(63.0);
-        text.setStrokeType(StrokeType.OUTSIDE);
-        text.setStrokeWidth(0.0);
-        text.setWrappingWidth(200);
-
-        pane.getChildren().add(text);
-    }
 
 
     /**
-- 
GitLab


From 463a14574be857dc898c6c13445a02d9897221cc Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 15:02:50 +0100
Subject: [PATCH 10/12] Cleaned up Explorecontroller and add javadoc

---
 .../IDATT1002/controllers/ExploreAlbums.java  | 247 +++++++++++-------
 1 file changed, 157 insertions(+), 90 deletions(-)

diff --git a/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java b/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
index 4a412697..7320cf56 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
@@ -2,11 +2,15 @@ package NTNU.IDATT1002.controllers;
 
 import NTNU.IDATT1002.App;
 import NTNU.IDATT1002.models.ImageAlbum;
+import NTNU.IDATT1002.models.Tag;
 import NTNU.IDATT1002.service.ImageAlbumService;
 import javafx.event.ActionEvent;
 import javafx.fxml.FXML;
 import javafx.fxml.Initializable;
-import javafx.scene.control.*;
+import javafx.scene.control.Button;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.ScrollPane;
+import javafx.scene.control.TextField;
 import javafx.scene.image.Image;
 import javafx.scene.image.ImageView;
 import javafx.scene.input.MouseEvent;
@@ -20,6 +24,7 @@ import java.io.IOException;
 import java.net.URL;
 import java.util.List;
 import java.util.ResourceBundle;
+import java.util.stream.Collectors;
 
 /**
  * Controls the buttons and changeable elements on explore_albums.fxml,
@@ -43,24 +48,17 @@ public class ExploreAlbums implements Initializable {
     public ChoiceBox sorted_by_choicebox;
     public Button create_album_button;
 
+
     public ImageView album_image;
-    public Text album_author;
     public Text album_title;
+    public Text album_author;
     public Text album_desc;
     public Text album_tags;
     public Button open_album;
 
-    public ImageView album_image2;
-    public Text album_title2;
-    public Text album_author2;
-    public Text album_desc2;
-    public Text album_tags2;
-    public Button open_album2;
-
     @FXML
     private GridPane albums_grid_pane;
     private Pane paneContainer;
-    private Label paneLabel;
 
     private ImageAlbumService imageAlbumService;
 
@@ -68,55 +66,80 @@ public class ExploreAlbums implements Initializable {
         imageAlbumService = new ImageAlbumService();
     }
 
+
+    /**
+     * Initialize page with all albums. Max 5 per page.
+     *
+     * @param url
+     * @param resourceBundle
+     */
     @Override
     public void initialize(URL url, ResourceBundle resourceBundle) {
         List<ImageAlbum> albums = imageAlbumService.getAllImageAlbums();
 
-        for(int i = 0; i<albums.size(); i++) {
+        int maxPerPage = Math.min(albums.size(), 5);
+
+        for(int i = 0; i<maxPerPage; i++) {
             paneContainer = new Pane();
-            paneContainer.setStyle("prefHeight:200.0; prefWidth:200.0; ");
             paneContainer.setPrefWidth(200);
             paneContainer.setPrefHeight(100);
 
-            addSingleAlbumContentToPane(album, paneContainer);
+            addSingleAlbumContentToPane(albums.get(i), paneContainer);
 
             albums_grid_pane.add(paneContainer, 0, i);
         }
     }
 
+    /**
+     * Add all components needed to display an album.
+     *
+     * @param album the album to display
+     * @param pane the pane to add the album to
+     */
     private void addSingleAlbumContentToPane(ImageAlbum album, Pane pane) {
         insertImageViewToPane(album, pane);
-        insertAlbumTitleLabelToPane(album, pane);
-        insertAlbumAuthorLabelToPane(album, pane);
-        insertAlbumDescriptionLabelToPane(album, pane);
+        insertAlbumTitleLabelToPane(pane);
+        insertAlbumAuthorLabelToPane(pane);
+        insertAlbumDescriptionLabelToPane(pane);
         insertAlbumAuthorToPane(album, pane);
         insertAlbumTitleToPane(album, pane);
         insertAlbumDescriptionToPane(album, pane);
-        insertAlbumTagsLabelToPane(album, pane);
+        insertAlbumTagsLabelToPane(pane);
         insertAlbumTagsToPane(album, pane);
         insertOpenAlbumButtonToPane(album, pane);
     }
 
+    /**
+     * Format and insert the first image in the given album to the given pane.
+     *
+     * @param album the album to display image from
+     * @param pane the pane to add the image to
+     */
     private void insertImageViewToPane(ImageAlbum album, Pane pane) {
         // Set and format image
-        album_image2 = new ImageView();
-        album_image2.setFitHeight(307.0);
-        album_image2.setFitWidth(516.0);
-        album_image2.setLayoutX(-2.0);
-        album_image2.setLayoutY(-1.0);
-        album_image2.setPickOnBounds(true);
-        album_image2.setPreserveRatio(true);
+        album_image = new ImageView();
+        album_image.setFitHeight(307.0);
+        album_image.setFitWidth(516.0);
+        album_image.setLayoutX(-2.0);
+        album_image.setLayoutY(-1.0);
+        album_image.setPickOnBounds(true);
+        album_image.setPreserveRatio(true);
 
         NTNU.IDATT1002.models.Image titleImage = album.getImages().get(0);
-        album_image2.setId(titleImage.getId().toString());
+        album_image.setId(titleImage.getId().toString());
 
         Image image = new Image("@../../Images/placeholder-1920x1080.png"); // TODO: display image here
-        album_image2.setImage(image);
+        album_image.setImage(image);
 
-        pane.getChildren().add(album_image2);
+        pane.getChildren().add(album_image);
     }
 
-    private void insertAlbumTitleLabelToPane(ImageAlbum album, Pane pane) {
+    /**
+     * Insert album title label to given pane.
+     *
+     * @param pane the pane to add the title to
+     */
+    private void insertAlbumTitleLabelToPane(Pane pane) {
         // set and format title label
         Text text = new Text();
         text.setText("ALBUM: ");
@@ -130,7 +153,12 @@ public class ExploreAlbums implements Initializable {
         pane.getChildren().add(text);
     }
 
-    private void insertAlbumAuthorLabelToPane(ImageAlbum album, Pane pane) {
+    /**
+     * Insert author label of the given album to the given pane
+     *
+     * @param pane the pane to add the author label to
+     */
+    private void insertAlbumAuthorLabelToPane(Pane pane) {
         // set and format author label
         Text authorLabel = new Text();
         authorLabel.setText("AUTHOR: ");
@@ -144,7 +172,12 @@ public class ExploreAlbums implements Initializable {
         pane.getChildren().add(authorLabel);
     }
 
-    private void insertAlbumDescriptionLabelToPane(ImageAlbum album, Pane pane) {
+    /**
+     * Insert description label of the given album to the given pane
+     *
+     * @param pane the pane to add the description label to
+     */
+    private void insertAlbumDescriptionLabelToPane(Pane pane) {
         // set and format description label
         Text descriptionLabel = new Text();
         descriptionLabel.setText("DESCRIPTION: ");
@@ -158,53 +191,73 @@ public class ExploreAlbums implements Initializable {
         pane.getChildren().add(descriptionLabel);
     }
 
+    /**
+     * Insert author of the given album to the given pane
+     *
+     * @param album the album which author to display
+     * @param pane the pane to add the author to
+     */
     private void insertAlbumAuthorToPane(ImageAlbum album, Pane pane) {
         // set and format author
-        album_author2 = new Text();
-        album_author2.setId("album_author");
-        album_author2.setText(album.getUser().getUsername());
-        album_author2.setFont(Font.font(24.0));
-        album_author2.setLayoutX(707.0);
-        album_author2.setLayoutY(97.0);
-        album_author2.setStrokeType(StrokeType.OUTSIDE);
-        album_author2.setStrokeWidth(0.0);
-        album_author2.setWrappingWidth(270.0);
-
-        pane.getChildren().add(album_author2);
+        album_author = new Text();
+        album_author.setId("album_author");
+        album_author.setText(album.getUser().getUsername());
+        album_author.setFont(Font.font(24.0));
+        album_author.setLayoutX(707.0);
+        album_author.setLayoutY(97.0);
+        album_author.setStrokeType(StrokeType.OUTSIDE);
+        album_author.setStrokeWidth(0.0);
+        album_author.setWrappingWidth(270.0);
+
+        pane.getChildren().add(album_author);
     }
 
+    /**
+     * Insert title of the given album to the given pane
+     *
+     * @param album the album which title to display
+     * @param pane the pane to add the title to
+     */
     private void insertAlbumTitleToPane(ImageAlbum album, Pane pane) {
-        // set and format title
-        album_title2 = new Text();
-        album_title2.setId("album_title");
-        album_title2.setText(album.getTitle());
-        album_title2.setFont(Font.font(48.0));
-        album_title2.setLayoutX(751.0);
-        album_title2.setLayoutY(65.0);
-        album_title2.setStrokeType(StrokeType.OUTSIDE);
-        album_title2.setStrokeWidth(0.0);
-        album_title2.setWrappingWidth(653.0);
-
-        pane.getChildren().add(album_title2);
+        album_title = new Text();
+        album_title.setId("album_title");
+        album_title.setText(album.getTitle());
+        album_title.setFont(Font.font(48.0));
+        album_title.setLayoutX(751.0);
+        album_title.setLayoutY(65.0);
+        album_title.setStrokeType(StrokeType.OUTSIDE);
+        album_title.setStrokeWidth(0.0);
+        album_title.setWrappingWidth(653.0);
+
+        pane.getChildren().add(album_title);
     }
 
+    /**
+     * Insert description of the given album to the given pane
+     *
+     * @param album the album which description to display
+     * @param pane the pane to add the description to
+     */
     private void insertAlbumDescriptionToPane(ImageAlbum album, Pane pane) {
-        // set and format description
-        album_desc2 = new Text();
-        album_desc2.setId("album_desc");
-        album_desc2.setText(album.getDescription());
-        album_desc2.setFont(Font.font(18.0));
-        album_desc2.setLayoutX(707.0);
-        album_desc2.setLayoutY(157.0);
-        album_desc2.setStrokeType(StrokeType.OUTSIDE);
-        album_desc2.setStrokeWidth(0.0);
-        album_desc2.setWrappingWidth(229.0);
-
-        pane.getChildren().add(album_desc2);
+        album_desc = new Text();
+        album_desc.setId("album_desc");
+        album_desc.setText(album.getDescription());
+        album_desc.setFont(Font.font(18.0));
+        album_desc.setLayoutX(707.0);
+        album_desc.setLayoutY(157.0);
+        album_desc.setStrokeType(StrokeType.OUTSIDE);
+        album_desc.setStrokeWidth(0.0);
+        album_desc.setWrappingWidth(229.0);
+
+        pane.getChildren().add(album_desc);
     }
 
-    private void insertAlbumTagsLabelToPane(ImageAlbum album, Pane paneContainer) {
-        // set and format tags label
+    /**
+     * Insert tags label of the given album to the given pane
+     *
+     * @param pane the pane to add the tags label to
+     */
+    private void insertAlbumTagsLabelToPane(Pane pane) {
         Text tagsLabel = new Text();
         tagsLabel.setText("TAGS: ");
         tagsLabel.setFont(Font.font(24));
@@ -214,37 +267,52 @@ public class ExploreAlbums implements Initializable {
         tagsLabel.setStrokeWidth(0.0);
         tagsLabel.setWrappingWidth(150.0);
 
-        paneContainer.getChildren().add(tagsLabel);
+        pane.getChildren().add(tagsLabel);
     }
 
+    /**
+     * Insert tags of the given album to the given pane
+     *
+     * @param album the album which tags to display
+     * @param pane the pane to add the tags to
+     */
     private void insertAlbumTagsToPane(ImageAlbum album, Pane pane) {
-        // set and format tags
-        Text tags = new Text();
-        tags.setText(String.join(", ", (CharSequence) album.getTags()));
-        tags.setFont(Font.font(24.0));
-        tags.setLayoutX(707.0);
-        tags.setLayoutY(129.0);
-        tags.setStrokeType(StrokeType.OUTSIDE);
-        tags.setStrokeWidth(0.0);
-        tags.setWrappingWidth(270.0);
-
-        pane.getChildren().add(tags);
+        String tagsAsString = album.getTags().stream()
+                .map(Tag::getName)
+                .collect(Collectors.joining(", "));
+
+        System.out.println(tagsAsString);
+
+        album_tags = new Text();
+        album_tags.setText("tag1, tag2");
+        album_tags.setFont(Font.font(24.0));
+        album_tags.setLayoutX(707.0);
+        album_tags.setLayoutY(129.0);
+        album_tags.setStrokeType(StrokeType.OUTSIDE);
+        album_tags.setStrokeWidth(0.0);
+        album_tags.setWrappingWidth(270.0);
+
+        pane.getChildren().add(album_tags);
     }
 
+    /**
+     * Insert an 'open album' button to the given album to the given pane
+     *
+     * @param album the album which the button should take the user to
+     * @param pane the pane to add the button to
+     */
     private void insertOpenAlbumButtonToPane(ImageAlbum album, Pane pane) {
         // set and format open album button
-        open_album2 = new Button();
-        open_album2.setId("open_album");
-        open_album2.setText("Open Album");
-        open_album2.setFont(Font.font(18.0));
-        open_album2.setLayoutX(551.0);
-        open_album2.setLayoutY(250.0);
-
-        pane.getChildren().add(open_album2);
+        open_album = new Button();
+        open_album.setId(album.getId().toString());
+        open_album.setText("Open Album");
+        open_album.setFont(Font.font(18.0));
+        open_album.setLayoutX(551.0);
+        open_album.setLayoutY(250.0);
+
+        pane.getChildren().add(open_album);
     }
 
-
-
     /**
      * Method that changes stage to Main page
      * @param mouseEvent
@@ -340,5 +408,4 @@ public class ExploreAlbums implements Initializable {
         App.setRoot("view_album");
     }
 
-
 }
-- 
GitLab


From e6eb464ea5ceedb2e532690ad21965aefbeab66c Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 15:16:33 +0100
Subject: [PATCH 11/12] Implemented method to take user to the appropriate
 album

---
 .../NTNU/IDATT1002/controllers/DataExchange.java  |  9 +++++++++
 .../NTNU/IDATT1002/controllers/ExploreAlbums.java | 15 +++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/main/java/NTNU/IDATT1002/controllers/DataExchange.java b/src/main/java/NTNU/IDATT1002/controllers/DataExchange.java
index e3ad7ae7..359b68ab 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/DataExchange.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/DataExchange.java
@@ -11,6 +11,7 @@ import java.util.List;
 public class DataExchange {
     private String searchField;
     private List<File> uploadedFiles;
+    private Long albumId;
 
     public DataExchange(){
         searchField = "";
@@ -23,6 +24,10 @@ public class DataExchange {
         return searchField;
     }
 
+    public Long getAlbumId() {
+        return albumId;
+    }
+
     public void setUploadedFiles(List<File> uploadedFiles) {
         this.uploadedFiles = uploadedFiles;
     }
@@ -30,4 +35,8 @@ public class DataExchange {
     public void setSearchField(String searchField) {
         this.searchField = searchField;
     }
+
+    public void setAlbumId(Long albumId) {
+        this.albumId = albumId;
+    }
 }
diff --git a/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java b/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
index 7320cf56..86bb22c3 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/ExploreAlbums.java
@@ -296,7 +296,8 @@ public class ExploreAlbums implements Initializable {
     }
 
     /**
-     * Insert an 'open album' button to the given album to the given pane
+     * Insert an 'open album' button to the given album to the given pane.
+     * If pushed it will take the user to the appropriate album.
      *
      * @param album the album which the button should take the user to
      * @param pane the pane to add the button to
@@ -309,6 +310,13 @@ public class ExploreAlbums implements Initializable {
         open_album.setFont(Font.font(18.0));
         open_album.setLayoutX(551.0);
         open_album.setLayoutY(250.0);
+        open_album.setOnAction(event -> {
+            try {
+                switchToViewAlbum(event);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        });
 
         pane.getChildren().add(open_album);
     }
@@ -404,7 +412,10 @@ public class ExploreAlbums implements Initializable {
      * @throws IOException
      */
     public void switchToViewAlbum(ActionEvent actionEvent) throws IOException {
-        //TODO: write method to open the specific album chosen
+        Button source = (Button) actionEvent.getSource();
+        Long albumId = Long.parseLong(source.getId());
+        App.ex.setAlbumId(albumId);
+
         App.setRoot("view_album");
     }
 
-- 
GitLab


From a572cec57d510998d26dfd7c49d01021b8fe1dd1 Mon Sep 17 00:00:00 2001
From: Eirik Steira <eirsteir@stud.ntnu.no>
Date: Mon, 23 Mar 2020 17:42:42 +0100
Subject: [PATCH 12/12] Change user arguments to english in LoginRepositoryTest

---
 .../controllers/CreateAlbumTest.java          | 25 -------------------
 .../repository/LoginRepositoryTest.java       |  4 +--
 2 files changed, 2 insertions(+), 27 deletions(-)
 delete mode 100644 src/test/java/NTNU/IDATT1002/controllers/CreateAlbumTest.java

diff --git a/src/test/java/NTNU/IDATT1002/controllers/CreateAlbumTest.java b/src/test/java/NTNU/IDATT1002/controllers/CreateAlbumTest.java
deleted file mode 100644
index 75d5c2ff..00000000
--- a/src/test/java/NTNU/IDATT1002/controllers/CreateAlbumTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package NTNU.IDATT1002.controllers;
-
-import NTNU.IDATT1002.repository.ImageAlbumRepository;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-@RunWith(MockitoJUnitRunner.class)
-class CreateAlbumTest {
-
-    @Mock
-    private ImageAlbumRepository imageAlbumRepository;
-
-
-
-    @BeforeEach
-    void setUp() {
-    }
-
-    @Test
-    void createEmptyImageAlbum() {
-    }
-}
\ No newline at end of file
diff --git a/src/test/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java b/src/test/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java
index e510f0d6..ab6bf487 100644
--- a/src/test/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java
+++ b/src/test/java/NTNU/IDATT1002/repository/LoginRepositoryTest.java
@@ -54,8 +54,8 @@ class LoginRepositoryTest {
         password = "Test123";
         newPassword = "Test321";
         date = new Date(System.currentTimeMillis());
-        user1 = new User(username1,"epost","fornavn", "etternavn", "test" , "test", date);
-        user2 = new User(username2, "epost2" , "fornavn2", "etternavn2", "test2", "test2", date);
+        user1 = new User(username1,"email","firstName", "lastName", "test" , "test", date);
+        user2 = new User(username2, "email2" , "firstName2", "lastName2", "test2", "test2", date);
         login1 = new Login(user1, "test", "test");
         login2 = new Login(user2, "test2", "test2");
     }
-- 
GitLab