Refactored to use database
#5 Switched to use maria database to store song information #7 Added spring and hibernate support #8 Added song upload functionality
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
|
||||
Project: ${project.name}, File: ${file.name}
|
||||
|
||||
Copyright ${license.git.copyrightLastYear} Locusworks LLC.
|
||||
Copyright 2019-${license.git.copyrightLastYear} Locusworks LLC.
|
||||
All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
12
pom.xml
12
pom.xml
@ -332,7 +332,17 @@
|
||||
<artifactId>activation</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>eclipselink</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
|
||||
<version>2.5.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: EightTrackBeanConfiguration.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: EightTrackDataSource.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: DiscordGuild.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
@ -34,7 +34,9 @@ package net.locusworks.discord.eighttrack.database.entities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
@ -42,6 +44,7 @@ import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
@ -71,6 +74,10 @@ public class DiscordGuild implements Serializable {
|
||||
@Column(name = "date_joined")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date dateJoined;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "guild")
|
||||
private List<GuildSong> guildSongList;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "guild")
|
||||
private List<GuildPlaylist> guildPlaylistList;
|
||||
|
||||
public DiscordGuild() {
|
||||
}
|
||||
@ -117,6 +124,22 @@ public class DiscordGuild implements Serializable {
|
||||
this.dateJoined = dateJoined;
|
||||
}
|
||||
|
||||
public List<GuildSong> getGuildSongList() {
|
||||
return guildSongList;
|
||||
}
|
||||
|
||||
public void setGuildSongList(List<GuildSong> guildSongList) {
|
||||
this.guildSongList = guildSongList;
|
||||
}
|
||||
|
||||
public List<GuildPlaylist> getGuildPlaylistList() {
|
||||
return guildPlaylistList;
|
||||
}
|
||||
|
||||
public void setGuildPlaylistList(List<GuildPlaylist> guildPlaylistList) {
|
||||
this.guildPlaylistList = guildPlaylistList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
@ -139,7 +162,7 @@ public class DiscordGuild implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "net.locusworks.discord.pseudobot.database.entities.DiscordGuild[ id=" + id + " ]";
|
||||
return "net.locusworks.discord.eighttrack.database.entities.DiscordGuild[ id=" + id + " ]";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,171 @@
|
||||
/**
|
||||
*
|
||||
* Project: Eight Track, File: GuildPlaylist.java
|
||||
*
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
* modified, duplicated, adapted or translated into another program language in any
|
||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||
* affirms that Eight-Track(R) software and data is subject to United States
|
||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||
*
|
||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.database.entities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author isaac
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "guild_playlist", catalog = "eighttrack", schema = "")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "GuildPlaylist.findAll", query = "SELECT g FROM GuildPlaylist g")})
|
||||
public class GuildPlaylist implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Basic(optional = false)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
@Basic(optional = false)
|
||||
@Column(name = "userId")
|
||||
private long userId;
|
||||
@Basic(optional = false)
|
||||
@Column(name = "playlist")
|
||||
private String playlist;
|
||||
@Column(name = "date_added")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date dateAdded;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "guildPlaylist")
|
||||
private List<GuildPlaylistSong> guildPlaylistSongList;
|
||||
@JoinColumn(name = "guild", referencedColumnName = "id")
|
||||
@ManyToOne(optional = false)
|
||||
private DiscordGuild guild;
|
||||
|
||||
public GuildPlaylist() {
|
||||
}
|
||||
|
||||
public GuildPlaylist(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public GuildPlaylist(Long id, long userId, String playlist) {
|
||||
this.id = id;
|
||||
this.userId = userId;
|
||||
this.playlist = playlist;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getPlaylist() {
|
||||
return playlist;
|
||||
}
|
||||
|
||||
public void setPlaylist(String playlist) {
|
||||
this.playlist = playlist;
|
||||
}
|
||||
|
||||
public Date getDateAdded() {
|
||||
return dateAdded;
|
||||
}
|
||||
|
||||
public void setDateAdded(Date dateAdded) {
|
||||
this.dateAdded = dateAdded;
|
||||
}
|
||||
|
||||
public List<GuildPlaylistSong> getGuildPlaylistSongList() {
|
||||
return guildPlaylistSongList;
|
||||
}
|
||||
|
||||
public void setGuildPlaylistSongList(List<GuildPlaylistSong> guildPlaylistSongList) {
|
||||
this.guildPlaylistSongList = guildPlaylistSongList;
|
||||
}
|
||||
|
||||
public DiscordGuild getGuild() {
|
||||
return guild;
|
||||
}
|
||||
|
||||
public void setGuild(DiscordGuild guild) {
|
||||
this.guild = guild;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof GuildPlaylist)) {
|
||||
return false;
|
||||
}
|
||||
GuildPlaylist other = (GuildPlaylist) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "net.locusworks.discord.eighttrack.database.entities.GuildPlaylist[ id=" + id + " ]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
/**
|
||||
*
|
||||
* Project: Eight Track, File: GuildPlaylistSong.java
|
||||
*
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
* modified, duplicated, adapted or translated into another program language in any
|
||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||
* affirms that Eight-Track(R) software and data is subject to United States
|
||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||
*
|
||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.database.entities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author isaac
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "guild_playlist_song", catalog = "eighttrack", schema = "")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "GuildPlaylistSong.findAll", query = "SELECT g FROM GuildPlaylistSong g")})
|
||||
public class GuildPlaylistSong implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Basic(optional = false)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
@Column(name = "date_added")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date dateAdded;
|
||||
@JoinColumn(name = "guild_playlist", referencedColumnName = "id")
|
||||
@ManyToOne(optional = false)
|
||||
private GuildPlaylist guildPlaylist;
|
||||
@JoinColumn(name = "guild_song", referencedColumnName = "id")
|
||||
@ManyToOne(optional = false)
|
||||
private GuildSong guildSong;
|
||||
|
||||
public GuildPlaylistSong() {
|
||||
}
|
||||
|
||||
public GuildPlaylistSong(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getDateAdded() {
|
||||
return dateAdded;
|
||||
}
|
||||
|
||||
public void setDateAdded(Date dateAdded) {
|
||||
this.dateAdded = dateAdded;
|
||||
}
|
||||
|
||||
public GuildPlaylist getGuildPlaylist() {
|
||||
return guildPlaylist;
|
||||
}
|
||||
|
||||
public void setGuildPlaylist(GuildPlaylist guildPlaylist) {
|
||||
this.guildPlaylist = guildPlaylist;
|
||||
}
|
||||
|
||||
public GuildSong getGuildSong() {
|
||||
return guildSong;
|
||||
}
|
||||
|
||||
public void setGuildSong(GuildSong guildSong) {
|
||||
this.guildSong = guildSong;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof GuildPlaylistSong)) {
|
||||
return false;
|
||||
}
|
||||
GuildPlaylistSong other = (GuildPlaylistSong) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong[ id=" + id + " ]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
/**
|
||||
*
|
||||
* Project: Eight Track, File: GuildSong.java
|
||||
*
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
* modified, duplicated, adapted or translated into another program language in any
|
||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||
* affirms that Eight-Track(R) software and data is subject to United States
|
||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||
*
|
||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.database.entities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author isaac
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "guild_song", catalog = "eighttrack", schema = "")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "GuildSong.findAll", query = "SELECT g FROM GuildSong g")})
|
||||
public class GuildSong implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Basic(optional = false)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
@Column(name = "date_added")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date dateAdded;
|
||||
@JoinColumn(name = "guild", referencedColumnName = "id")
|
||||
@ManyToOne(optional = false)
|
||||
private DiscordGuild guild;
|
||||
@JoinColumn(name = "song", referencedColumnName = "id")
|
||||
@ManyToOne(optional = false)
|
||||
private Song song;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "guildSong")
|
||||
private List<GuildPlaylistSong> guildPlaylistSongList;
|
||||
|
||||
public GuildSong() {
|
||||
}
|
||||
|
||||
public GuildSong(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getDateAdded() {
|
||||
return dateAdded;
|
||||
}
|
||||
|
||||
public void setDateAdded(Date dateAdded) {
|
||||
this.dateAdded = dateAdded;
|
||||
}
|
||||
|
||||
public DiscordGuild getGuild() {
|
||||
return guild;
|
||||
}
|
||||
|
||||
public void setGuild(DiscordGuild guild) {
|
||||
this.guild = guild;
|
||||
}
|
||||
|
||||
public Song getSong() {
|
||||
return song;
|
||||
}
|
||||
|
||||
public void setSong(Song song) {
|
||||
this.song = song;
|
||||
}
|
||||
|
||||
public List<GuildPlaylistSong> getGuildPlaylistSongList() {
|
||||
return guildPlaylistSongList;
|
||||
}
|
||||
|
||||
public void setGuildPlaylistSongList(List<GuildPlaylistSong> guildPlaylistSongList) {
|
||||
this.guildPlaylistSongList = guildPlaylistSongList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof GuildSong)) {
|
||||
return false;
|
||||
}
|
||||
GuildSong other = (GuildSong) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "net.locusworks.discord.eighttrack.database.entities.GuildSong[ id=" + id + " ]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,253 @@
|
||||
/**
|
||||
*
|
||||
* Project: Eight Track, File: Song.java
|
||||
*
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
* modified, duplicated, adapted or translated into another program language in any
|
||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||
* affirms that Eight-Track(R) software and data is subject to United States
|
||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||
*
|
||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.database.entities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author isaac
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "song", catalog = "eighttrack", schema = "")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "Song.findAll", query = "SELECT s FROM Song s")})
|
||||
public class Song implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Basic(optional = false)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
@Basic(optional = false)
|
||||
@Column(name = "uuid")
|
||||
private String uuid;
|
||||
@Basic(optional = false)
|
||||
@Column(name = "title")
|
||||
private String title;
|
||||
@Column(name = "artist")
|
||||
private String artist;
|
||||
@Column(name = "album")
|
||||
private String album;
|
||||
@Column(name = "genre")
|
||||
private String genre;
|
||||
@Column(name = "track_number")
|
||||
private String trackNumber;
|
||||
@Column(name = "disc_number")
|
||||
private String discNumber;
|
||||
@Column(name = "release_year")
|
||||
private String releaseYear;
|
||||
@Column(name = "duration")
|
||||
private BigInteger duration;
|
||||
@Basic(optional = false)
|
||||
@Column(name = "file_path")
|
||||
private String filePath;
|
||||
@Basic(optional = false)
|
||||
@Column(name = "file_hash")
|
||||
private String fileHash;
|
||||
@Column(name = "date_added")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date dateAdded;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "song")
|
||||
private List<GuildSong> guildSongList;
|
||||
|
||||
public Song() {
|
||||
}
|
||||
|
||||
public Song(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Song(Long id, String uuid, String title, String filePath, String fileHash) {
|
||||
this.id = id;
|
||||
this.uuid = uuid;
|
||||
this.title = title;
|
||||
this.filePath = filePath;
|
||||
this.fileHash = fileHash;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
public void setArtist(String artist) {
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public String getAlbum() {
|
||||
return album;
|
||||
}
|
||||
|
||||
public void setAlbum(String album) {
|
||||
this.album = album;
|
||||
}
|
||||
|
||||
public String getGenre() {
|
||||
return genre;
|
||||
}
|
||||
|
||||
public void setGenre(String genre) {
|
||||
this.genre = genre;
|
||||
}
|
||||
|
||||
public String getTrackNumber() {
|
||||
return trackNumber;
|
||||
}
|
||||
|
||||
public void setTrackNumber(String trackNumber) {
|
||||
this.trackNumber = trackNumber;
|
||||
}
|
||||
|
||||
public String getDiscNumber() {
|
||||
return discNumber;
|
||||
}
|
||||
|
||||
public void setDiscNumber(String discNumber) {
|
||||
this.discNumber = discNumber;
|
||||
}
|
||||
|
||||
public String getReleaseYear() {
|
||||
return releaseYear;
|
||||
}
|
||||
|
||||
public void setReleaseYear(String releaseYear) {
|
||||
this.releaseYear = releaseYear;
|
||||
}
|
||||
|
||||
public BigInteger getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(BigInteger duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getFileHash() {
|
||||
return fileHash;
|
||||
}
|
||||
|
||||
public void setFileHash(String fileHash) {
|
||||
this.fileHash = fileHash;
|
||||
}
|
||||
|
||||
public Date getDateAdded() {
|
||||
return dateAdded;
|
||||
}
|
||||
|
||||
public void setDateAdded(Date dateAdded) {
|
||||
this.dateAdded = dateAdded;
|
||||
}
|
||||
|
||||
public List<GuildSong> getGuildSongList() {
|
||||
return guildSongList;
|
||||
}
|
||||
|
||||
public void setGuildSongList(List<GuildSong> guildSongList) {
|
||||
this.guildSongList = guildSongList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof Song)) {
|
||||
return false;
|
||||
}
|
||||
Song other = (Song) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "net.locusworks.discord.eighttrack.database.entities.Song[ id=" + id + " ]";
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: GuildRepository.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -0,0 +1,51 @@
|
||||
/**
|
||||
*
|
||||
* Project: Eight Track, File: GuildSongRepository.java
|
||||
*
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
* modified, duplicated, adapted or translated into another program language in any
|
||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||
* affirms that Eight-Track(R) software and data is subject to United States
|
||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||
*
|
||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.database.repos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||
import net.locusworks.discord.eighttrack.database.entities.Song;
|
||||
|
||||
public interface GuildSongRepository extends CrudRepository<GuildSong, Long> {
|
||||
|
||||
GuildSong findByGuildAndSong(DiscordGuild guild, Song song);
|
||||
|
||||
@Query("SELECT gs FROM GuildSong gs WHERE gs.guild.guildId = ?1 AND gs.song.fileHash = ?2")
|
||||
GuildSong findByGuildAndSongHash(Long guildId, String songHash);
|
||||
|
||||
List<GuildSong> findByGuild(DiscordGuild guild);
|
||||
|
||||
@Query("SELECT gs FROM GuildSong gs WHERE gs.guild.guildId = ?1")
|
||||
List<GuildSong> findByGuild(Long guildId);
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/**
|
||||
*
|
||||
* Project: Eight Track, File: SongRepository.java
|
||||
*
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
* modified, duplicated, adapted or translated into another program language in any
|
||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||
* affirms that Eight-Track(R) software and data is subject to United States
|
||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||
*
|
||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.database.repos;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import net.locusworks.discord.eighttrack.database.entities.Song;
|
||||
|
||||
public interface SongRepository extends CrudRepository<Song, Long> {
|
||||
|
||||
Song findByUuid(String uuid);
|
||||
|
||||
Song findByFileHash(String fileHash);
|
||||
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: Configuration.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: DiscordEventHandler.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
@ -43,6 +43,7 @@ import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||
import net.locusworks.discord.eighttrack.database.repos.GuildRepository;
|
||||
import net.locusworks.discord.eighttrack.services.ConfigurationService;
|
||||
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||
import net.locusworks.discord.eighttrack.services.GuildSongRepoService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
|
||||
@ -65,6 +66,9 @@ public class DiscordEventHandler extends ListenerAdapter {
|
||||
@Autowired
|
||||
private Mp3UploadHandler uploadHandler;
|
||||
|
||||
@Autowired
|
||||
private GuildSongRepoService guildSongRepoService;
|
||||
|
||||
@PostConstruct
|
||||
private void init() throws IOException {
|
||||
this.musicDir = confService.getMusicDirectory();
|
||||
@ -106,7 +110,7 @@ public class DiscordEventHandler extends ListenerAdapter {
|
||||
private void onGuildMessageReceivedHelper(GuildMessageReceivedEvent event) throws IOException {
|
||||
|
||||
if (!musicService.containsKey(event.getGuild().getIdLong())) {
|
||||
musicService.put(event.getGuild().getIdLong(), new GuildMusicHandler(musicDir, uploadHandler));
|
||||
musicService.put(event.getGuild().getIdLong(), new GuildMusicHandler(musicDir, uploadHandler, guildSongRepoService));
|
||||
}
|
||||
GuildMusicHandler gmh = musicService.get(event.getGuild().getIdLong());
|
||||
gmh.accept((id) -> musicService.remove(id));
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: EightTrackAudioSendHandler.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: GuildMusicHandler.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
@ -29,10 +29,13 @@ package net.locusworks.discord.eighttrack.handlers;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
@ -51,7 +54,12 @@ import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
import net.locusworks.crypto.utils.HashUtils;
|
||||
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||
import net.locusworks.discord.eighttrack.database.entities.Song;
|
||||
import net.locusworks.discord.eighttrack.scheduler.TrackScheduler;
|
||||
import net.locusworks.discord.eighttrack.services.GuildSongRepoService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
|
||||
@ -69,13 +77,15 @@ public class GuildMusicHandler {
|
||||
|
||||
private Consumer<Long> callback;
|
||||
private Mp3UploadHandler uploadHandler;
|
||||
private GuildSongRepoService guildSongRepoService;
|
||||
|
||||
public GuildMusicHandler(Path musicDir, Mp3UploadHandler uploadHandler) throws IOException {
|
||||
public GuildMusicHandler(Path musicDir, Mp3UploadHandler uploadHandler, GuildSongRepoService guildSongRepoService) throws IOException {
|
||||
this.logger = ApplicationLoggerFactory.getLogger(GuildMusicHandler.class);
|
||||
this.playing = new AtomicBoolean(false);
|
||||
this.musicDir = musicDir;
|
||||
this.lastPlayed = OffsetDateTime.now();
|
||||
this.uploadHandler = uploadHandler;
|
||||
this.guildSongRepoService = guildSongRepoService;
|
||||
this.apm = new DefaultAudioPlayerManager();
|
||||
|
||||
AudioSourceManagers.registerLocalSource(apm);
|
||||
@ -211,16 +221,13 @@ public class GuildMusicHandler {
|
||||
|
||||
for(Attachment attachment : event.getMessage().getAttachments()) {
|
||||
attachment.retrieveInputStream().thenAccept((in) -> {
|
||||
Mp3UploadResults res = null;
|
||||
try {
|
||||
Mp3UploadResults res = uploadHandler.parse(in);
|
||||
|
||||
MessageEmbed embed = new EmbedBuilder()
|
||||
.setColor(Color.GREEN)
|
||||
.setTitle("Upload Results")
|
||||
.setDescription(res.toString())
|
||||
.setTimestamp(OffsetDateTime.now())
|
||||
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||
.build();
|
||||
MessageEmbed embed = null;
|
||||
res = uploadHandler.parse(in);
|
||||
if (res.validFile()) {
|
||||
embed =persistSong(res, event, attachment.getFileName());
|
||||
}
|
||||
|
||||
event.getChannel().sendMessage(embed).queue();
|
||||
} catch (Exception ex) {
|
||||
@ -228,12 +235,72 @@ public class GuildMusicHandler {
|
||||
logger.error(ex);
|
||||
} finally {
|
||||
event.getMessage().delete().queue();
|
||||
if (res != null) res.clear();
|
||||
}
|
||||
|
||||
}).exceptionally((err) ->{
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private MessageEmbed persistSong(Mp3UploadResults result, GuildMessageReceivedEvent event, String fileName) throws Exception {
|
||||
|
||||
DiscordGuild guild = guildSongRepoService.getGuildRepo().findByGuildId(event.getGuild().getIdLong());
|
||||
if(guild == null) {
|
||||
throw new IOException("Unable to find guild in database. Please contact administrator");
|
||||
}
|
||||
|
||||
Path output = musicDir;
|
||||
if (result.getArtist() != null) {
|
||||
output = output.resolve(result.getArtist());
|
||||
if (result.getAlbum() != null) {
|
||||
output = output.resolve(result.getAlbum());
|
||||
}
|
||||
}
|
||||
output = output.resolve(fileName);
|
||||
|
||||
if (!Files.exists(output.toAbsolutePath().getParent())) {
|
||||
Files.createDirectories(output.toAbsolutePath().getParent());
|
||||
}
|
||||
|
||||
Files.write(output, result.getData());
|
||||
|
||||
Song song = new Song();
|
||||
song.setAlbum(result.getAlbum());
|
||||
song.setArtist(result.getArtist());
|
||||
song.setDateAdded(new Date());
|
||||
song.setDiscNumber(result.getDiscNumber());
|
||||
if (result.getDuration() != null)
|
||||
song.setDuration(BigInteger.valueOf(result.getDuration()));
|
||||
song.setFileHash(HashUtils.hash("SHA-1", result.getData()));
|
||||
song.setFilePath(output.toAbsolutePath().toString());
|
||||
song.setGenre(result.getGenre());
|
||||
song.setReleaseYear(result.getReleaseDate());
|
||||
song.setTitle(result.getTitle());
|
||||
song.setTrackNumber(result.getTrackNumber());
|
||||
song.setUuid(UUID.nameUUIDFromBytes(result.getData()).toString());
|
||||
|
||||
guildSongRepoService.getSongRepo().save(song);
|
||||
|
||||
GuildSong gs = new GuildSong();
|
||||
gs.setDateAdded(new Date());
|
||||
gs.setGuild(guild);
|
||||
gs.setSong(song);
|
||||
|
||||
guildSongRepoService.getGuildSongRepo().save(gs);
|
||||
|
||||
String out = String.format("```%s%n%-10s: %s```", result, "UUID", song.getUuid());
|
||||
|
||||
MessageEmbed embed = new EmbedBuilder()
|
||||
.setColor(Color.GREEN)
|
||||
.setTitle("Upload Results for " + fileName)
|
||||
.setDescription(out)
|
||||
.setTimestamp(OffsetDateTime.now())
|
||||
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||
.build();
|
||||
|
||||
return embed;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: Mp3UploadHandler.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
@ -27,6 +27,8 @@
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.handlers;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
@ -50,16 +52,26 @@ public class Mp3UploadHandler {
|
||||
}
|
||||
|
||||
public Mp3UploadResults parse(InputStream is) throws IOException {
|
||||
try {
|
||||
byte[] data;
|
||||
try(InputStream in = is; ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
int read = 0;
|
||||
byte[] buffer = new byte[1024 * 1024];
|
||||
while((read = in.read(buffer)) > 0) {
|
||||
baos.write(buffer, 0, read);
|
||||
}
|
||||
data = baos.toByteArray();
|
||||
}
|
||||
|
||||
try (InputStream in = new ByteArrayInputStream(data)) {
|
||||
BodyContentHandler handler = new BodyContentHandler();
|
||||
Metadata metadata = new Metadata();
|
||||
ParseContext context = new ParseContext();
|
||||
|
||||
Mp3Parser parser = new Mp3Parser();
|
||||
|
||||
parser.parse(is, handler, metadata, context);
|
||||
parser.parse(in, handler, metadata, context);
|
||||
|
||||
return new Mp3UploadResults(metadata);
|
||||
return new Mp3UploadResults(metadata, data);
|
||||
} catch (Exception ex) {
|
||||
throw new IOException(ex);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: Mp3UploadResults.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
@ -63,9 +63,11 @@ public class Mp3UploadResults {
|
||||
private String releaseDate;
|
||||
private Long duration;
|
||||
|
||||
private byte[] rawData;
|
||||
|
||||
public Mp3UploadResults( Metadata metadata) {
|
||||
public Mp3UploadResults( Metadata metadata, byte[] data) {
|
||||
parseResults(metadata);
|
||||
this.rawData = data;
|
||||
}
|
||||
|
||||
private void parseResults(Metadata metadata) {
|
||||
@ -84,6 +86,10 @@ public class Mp3UploadResults {
|
||||
}
|
||||
}
|
||||
|
||||
public final byte[] getData() {
|
||||
return this.rawData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the genre
|
||||
*/
|
||||
@ -153,7 +159,7 @@ public class Mp3UploadResults {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("```");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (getTitle() != null)
|
||||
sb.append(String.format("%-10s: %s%n", "Title", getTitle()));
|
||||
|
||||
@ -178,10 +184,13 @@ public class Mp3UploadResults {
|
||||
if (duration != null)
|
||||
sb.append(String.format("%-10s: %s%n", "Duration", dateFormat(getDuration())));
|
||||
|
||||
sb.append("```");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
rawData = new byte[0];
|
||||
}
|
||||
|
||||
private String dateFormat(long timeInMilliSeconds) {
|
||||
long seconds = timeInMilliSeconds / 1000;
|
||||
long minutes = seconds / 60;
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: EightTrackLauncher.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: TrackScheduler.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: AESService.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: ConfigurationService.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: DatabaseCleanupService.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: EightTrackService.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: GuildMusicService.java
|
||||
*
|
||||
* Copyright 2019 Locusworks LLC.
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
|
@ -0,0 +1,70 @@
|
||||
/**
|
||||
*
|
||||
* Project: Eight Track, File: GuildSongRepoService.java
|
||||
*
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
* modified, duplicated, adapted or translated into another program language in any
|
||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
||||
* affirms that Eight-Track(R) software and data is subject to United States
|
||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
||||
*
|
||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import net.locusworks.discord.eighttrack.database.repos.GuildRepository;
|
||||
import net.locusworks.discord.eighttrack.database.repos.GuildSongRepository;
|
||||
import net.locusworks.discord.eighttrack.database.repos.SongRepository;
|
||||
|
||||
@Service
|
||||
public class GuildSongRepoService {
|
||||
|
||||
@Autowired
|
||||
private GuildRepository guildRepo;
|
||||
|
||||
@Autowired
|
||||
private GuildSongRepository guildSongRepo;
|
||||
|
||||
@Autowired
|
||||
private SongRepository songRepo;
|
||||
|
||||
/**
|
||||
* @return the guildRepo
|
||||
*/
|
||||
public final GuildRepository getGuildRepo() {
|
||||
return guildRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the guildSongRepo
|
||||
*/
|
||||
public final GuildSongRepository getGuildSongRepo() {
|
||||
return guildSongRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the songRepo
|
||||
*/
|
||||
public final SongRepository getSongRepo() {
|
||||
return songRepo;
|
||||
}
|
||||
|
||||
}
|
17
src/main/resources/META-INF/persistence.xml
Normal file
17
src/main/resources/META-INF/persistence.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
|
||||
<persistence-unit name="net.locusworks.discord_eight-track_jar_0.0.1-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
|
||||
<class>net.locusworks.discord.eighttrack.database.entities.GuildSong</class>
|
||||
<class>net.locusworks.discord.eighttrack.database.entities.GuildPlaylist</class>
|
||||
<class>net.locusworks.discord.eighttrack.database.entities.DiscordGuild</class>
|
||||
<class>net.locusworks.discord.eighttrack.database.entities.Song</class>
|
||||
<class>net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong</class>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:mariadb://devops.locusworks.net:3306/eighttrack"/>
|
||||
<property name="javax.persistence.jdbc.user" value="root"/>
|
||||
<property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver"/>
|
||||
<property name="javax.persistence.jdbc.password" value="0a0wNt6aX4e66LNhA5uKLdnnN"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
@ -6,3 +6,58 @@ CREATE TABLE eighttrack.discord_guild (
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY guild_UN (guild_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Information about discord guild';
|
||||
|
||||
CREATE TABLE eighttrack.song (
|
||||
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
|
||||
uuid varchar(100) NOT NULL COMMENT 'Unique Identifier',
|
||||
title varchar(500) NOT NULL COMMENT 'title of song',
|
||||
artist varchar(500) DEFAULT NULL COMMENT 'songs artist',
|
||||
album varchar(500) DEFAULT NULL COMMENT 'songs album',
|
||||
genre varchar(500) DEFAULT NULL COMMENT 'songs genre',
|
||||
track_number varchar(100) DEFAULT NULL COMMENT 'track number',
|
||||
disc_number varchar(100) DEFAULT NULL COMMENT 'disc number',
|
||||
release_year varchar(100) DEFAULT NULL COMMENT 'release year',
|
||||
duration bigint(20) DEFAULT NULL COMMENT 'songs duration',
|
||||
file_path varchar(5000) NOT NULL COMMENT 'file location on local file system',
|
||||
file_hash varchar(40) NOT NULL COMMENT 'sha1 hash of file',
|
||||
date_added timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY song_uuid_UN (uuid),
|
||||
UNIQUE KEY song_file_hash_UN (file_hash)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE eighttrack.guild_song (
|
||||
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
||||
guild bigint(20) NOT NULL COMMENT 'guild the song belongs to',
|
||||
song bigint(20) NOT NULL COMMENT 'the song',
|
||||
date_added timestamp NULL DEFAULT NULL COMMENT 'date added',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY guild_song_UN (guild,song),
|
||||
KEY guild_song_FK_1 (song),
|
||||
CONSTRAINT guild_song_FK FOREIGN KEY (guild) REFERENCES eighttrack.discord_guild (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT guild_song_FK_1 FOREIGN KEY (song) REFERENCES eighttrack.song (id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE eighttrack.guild_playlist (
|
||||
id bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
guild bigint(20) NOT NULL,
|
||||
userId bigint(20) NOT NULL,
|
||||
playlist varchar(500) NOT NULL,
|
||||
date_added timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY guild_playlist_UN (guild,userId,playlist),
|
||||
CONSTRAINT guild_playlist_FK FOREIGN KEY (guild) REFERENCES eighttrack.discord_guild (id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
CREATE TABLE eighttrack.guild_playlist_song (
|
||||
id bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
guild_playlist bigint(20) NOT NULL,
|
||||
guild_song bigint(20) NOT NULL,
|
||||
date_added timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY guild_playlist_song_UN (guild_playlist,guild_song),
|
||||
KEY guild_playlist_song_FK_1 (guild_song),
|
||||
CONSTRAINT guild_playlist_song_FK FOREIGN KEY (guild_playlist) REFERENCES eighttrack.guild_playlist (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT guild_playlist_song_FK_1 FOREIGN KEY (guild_song) REFERENCES eighttrack.guild_song (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
Reference in New Issue
Block a user