diff --git a/pom.xml b/pom.xml index b8463d3..6cb3ac9 100644 --- a/pom.xml +++ b/pom.xml @@ -8,6 +8,23 @@ musicplayer DEVELOPMENT + + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + + + + @@ -30,6 +47,11 @@ gstreamer-java 1.5 + + junit + junit + 4.12 + diff --git a/src/main/java/musicplayer/db/Gateway.java b/src/main/java/musicplayer/db/Gateway.java index 10f3cfb..7a54952 100644 --- a/src/main/java/musicplayer/db/Gateway.java +++ b/src/main/java/musicplayer/db/Gateway.java @@ -81,7 +81,8 @@ public class Gateway { Artist artist = new Artist(metadata.artist); artistObj = Optional.of(artist); } - session.save(new Song(metadata.trackNumber, metadata.title, artistObj.get(), albumObj.get(), metadata.genre, metadata.songFile)); + session.save(new Song(metadata.trackNumber, metadata.discNumber, metadata.title, artistObj.get(), + albumObj.get(), metadata.genre, metadata.songFile)); session.getTransaction().commit(); } } diff --git a/src/main/java/musicplayer/model/Song.java b/src/main/java/musicplayer/model/Song.java index b6b4344..7bf88d5 100644 --- a/src/main/java/musicplayer/model/Song.java +++ b/src/main/java/musicplayer/model/Song.java @@ -31,14 +31,22 @@ public class Song implements Comparable { private String songFile; @Column(name = "trackNumber") private int trackNumber; + @Column(name = "discNumber") + private int discNumber; + + @Transient + private static int discNumberComparator = 1000; protected Song() { } - public Song(String trackNumber, String title, Artist artist, Album album, String genre, String songFile) { + public Song(String trackNumber, String discNumber, String title, Artist artist, Album album, String genre, String songFile) { try { this.trackNumber = Integer.parseInt(trackNumber); } catch (NumberFormatException e){ this.trackNumber = 0; } + try { + this.discNumber = Integer.parseInt(discNumber); + } catch (NumberFormatException e){ this.discNumber = 0; } this.title = title; this.artist = artist; this.genre = genre; @@ -118,8 +126,10 @@ public class Song implements Comparable { return trackNumber; } + public Integer getDiscNumber() { return discNumber; } + @Override public int compareTo(Song o) { - return trackNumber - o.getTrackNumber(); + return (trackNumber - o.getTrackNumber()) + ((discNumber - o.getDiscNumber()) * discNumberComparator); } } diff --git a/src/test/java/musicplayer/db/GatewayTest.java b/src/test/java/musicplayer/db/GatewayTest.java index 8bd8d0f..f402fd3 100644 --- a/src/test/java/musicplayer/db/GatewayTest.java +++ b/src/test/java/musicplayer/db/GatewayTest.java @@ -7,7 +7,7 @@ import musicplayer.model.Song; import org.hibernate.Session; import org.jaudiotagger.tag.FieldKey; import org.jaudiotagger.tag.Tag; -import org.jaudiotagger.tag.id3.ID3v11Tag; +import org.jaudiotagger.tag.id3.ID3v23Tag; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -70,9 +70,9 @@ public class GatewayTest { @Test public void testListAllSongs() throws Exception { - Song song1 = new Song("1", "s1", new Artist("a"), new Album("a"), "", ""); - Song song2 = new Song("2", "s2", new Artist("b"), new Album("a"), "", ""); - Song song3 = new Song("1", "t1", new Artist("c"), new Album("b"), "", ""); + Song song1 = new Song("1", "1", "s1", new Artist("a"), new Album("a"), "", ""); + Song song2 = new Song("2", "1","s2", new Artist("b"), new Album("a"), "", ""); + Song song3 = new Song("1", "1","t1", new Artist("c"), new Album("b"), "", ""); session.beginTransaction(); session.save(song1); session.save(song2); @@ -95,9 +95,9 @@ public class GatewayTest { public void testListAllSongsGroupedByAlbum() throws Exception { Album album1 = new Album("Test 1"); Album album2 = new Album("Test 2"); - Song song1 = new Song("1", "s1", new Artist("a"), album1, "", ""); - Song song2 = new Song("2", "s2", new Artist("b"), album1, "", ""); - Song song3 = new Song("1", "t1", new Artist("c"), album2, "", ""); + Song song1 = new Song("1", "1", "s1", new Artist("a"), album1, "", ""); + Song song2 = new Song("2", "1", "s2", new Artist("b"), album1, "", ""); + Song song3 = new Song("1", "1", "t1", new Artist("c"), album2, "", ""); session.beginTransaction(); session.save(song1); session.save(song2); @@ -120,12 +120,13 @@ public class GatewayTest { @Test public void testAddSong() throws Exception { - Tag tags = new ID3v11Tag(); + Tag tags = new ID3v23Tag(); tags.addField(FieldKey.ALBUM, "Test Album"); tags.addField(FieldKey.ARTIST, "Test Artist"); tags.addField(FieldKey.TRACK, "1"); tags.addField(FieldKey.TITLE, "Test Song"); tags.addField(FieldKey.GENRE, "Test Genre"); + tags.addField(FieldKey.DISC_NO, "100"); ExtractedMetadata metadata = new ExtractedMetadata(tags, new File("")); Gateway.addSong(metadata); Song song = (Song)session.createCriteria(Song.class).uniqueResult(); @@ -134,5 +135,6 @@ public class GatewayTest { assertEquals(song.getTrackNumber(), Integer.valueOf(1)); assertEquals(song.getTitle(), metadata.title); assertEquals(song.getGenre(), metadata.genre); + assertEquals(song.getDiscNumber(), Integer.valueOf(100)); } } \ No newline at end of file