updated datamodel, introduced UUID as primary key

This commit is contained in:
jomu
2016-04-08 13:42:44 +00:00
parent fdef4d4e25
commit 5cf92b57aa
14 changed files with 496 additions and 396 deletions

View File

@ -55,6 +55,11 @@
<artifactId>javaee-api</artifactId> <artifactId>javaee-api</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -66,9 +71,11 @@
<version>2.5.1</version> <version>2.5.1</version>
<configuration> <configuration>
<ejbVersion>3.1</ejbVersion> <ejbVersion>3.1</ejbVersion>
<excludes>
<exclude>**/persistence.xml</exclude>
</excludes>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -12,12 +12,15 @@ DROP TABLE application_permission;
CREATE TABLE application_role ( CREATE TABLE application_role (
id UUID NOT NULL,
role_name varchar(80) NOT NULL, role_name varchar(80) NOT NULL,
role_description varchar(200) NOT NULL, role_description varchar(200) NOT NULL,
CONSTRAINT pk_application_role_pk PRIMARY KEY (role_name) CONSTRAINT pk_application_role_pk PRIMARY KEY (id),
CONSTRAINT uidx_application_id UNIQUE (id)
); );
CREATE TABLE account ( CREATE TABLE account (
id UUID NOT NULL,
username varchar(32) NOT NULL, username varchar(32) NOT NULL,
emailaddress varchar(200) NOT NULL, emailaddress varchar(200) NOT NULL,
firstname varchar(100) NOT NULL, firstname varchar(100) NOT NULL,
@ -34,50 +37,55 @@ CREATE TABLE account (
created_by varchar(32) NOT NULL, created_by varchar(32) NOT NULL,
last_updated_on timestamp with time zone NOT NULL DEFAULT (now() at time zone 'utc'), last_updated_on timestamp with time zone NOT NULL DEFAULT (now() at time zone 'utc'),
last_updated_by varchar(32) NOT NULL, last_updated_by varchar(32) NOT NULL,
CONSTRAINT pk_account PRIMARY KEY (username) CONSTRAINT pk_account PRIMARY KEY (id),
CONSTRAINT uidx_username UNIQUE (username)
); );
CREATE TABLE account_history ( CREATE TABLE account_history (
id SERIAL NOT NULL, id UUID NOT NULL,
username varchar(32) NOT NULL, account_id UUID NOT NULL,
message varchar(200), message varchar(200),
failure_count int NOT NULL DEFAULT 0, failure_count int NOT NULL DEFAULT 0,
status varchar(20) NOT NULL, -- constants needed, after action - new, init, active, blocked, inactive, marked for deletion status varchar(20) NOT NULL, -- constants needed, after action - new, init, active, blocked, inactive, marked for deletion
last_updated_on timestamp with time zone NOT NULL DEFAULT (now() at time zone 'utc'), last_updated_on timestamp with time zone NOT NULL DEFAULT (now() at time zone 'utc'),
last_updated_by varchar(32) NOT NULL, last_updated_by varchar(32) NOT NULL,
CONSTRAINT pk_account_history PRIMARY KEY (id), CONSTRAINT pk_account_history PRIMARY KEY (id),
CONSTRAINT fk_account_history_username_fk FOREIGN KEY (username) REFERENCES account (username) CONSTRAINT fk_account_history_username_fk FOREIGN KEY (account_id) REFERENCES account (id)
); );
CREATE TABLE account_role ( CREATE TABLE account_role (
username varchar(32) NOT NULL, account UUID NOT NULL,
role_name varchar(80) NOT NULL, account_role UUID NOT NULL,
CONSTRAINT pk_account_role PRIMARY KEY (username, role_name), CONSTRAINT pk_account_role PRIMARY KEY (account, account_role),
CONSTRAINT fk_account_role_account FOREIGN KEY (username) REFERENCES account(username), CONSTRAINT fk_account_role_account FOREIGN KEY (account) REFERENCES account(id),
CONSTRAINT fk_account_role_role_name FOREIGN KEY (role_name) REFERENCES application_role(role_name) CONSTRAINT fk_account_role_role_name FOREIGN KEY (account_role) REFERENCES application_role(id)
); );
CREATE TABLE application_permission ( CREATE TABLE application_permission (
id UUID NOT NULL,
permission_name varchar(80) NOT NULL, permission_name varchar(80) NOT NULL,
permission_description varchar(200) NOT NULL, permission_description varchar(200) NOT NULL,
CONSTRAINT application_permission_pk PRIMARY KEY (permission_name) CONSTRAINT pk_application_permission PRIMARY KEY (id),
CONSTRAINT uidx_application_permission_name UNIQUE (permission_name)
); );
CREATE TABLE role_permission ( CREATE TABLE role_permission (
role_name varchar(80) NOT NULL, application_role UUID NOT NULL,
permission_name varchar(80) NOT NULL, role_permission UUID NOT NULL,
CONSTRAINT pk_role_permission_role_permission_name PRIMARY KEY (role_name, permission_name), CONSTRAINT pk_role_permission_role_permission_name PRIMARY KEY (application_role, role_permission),
CONSTRAINT fk_role_permission_role_name FOREIGN KEY (role_name) REFERENCES application_role(role_name), CONSTRAINT fk_role_permission_application_role FOREIGN KEY (application_role) REFERENCES application_role(id),
CONSTRAINT fk_role_permission_permission_name FOREIGN KEY (permission_name) REFERENCES application_permission(permission_name) CONSTRAINT fk_role_permission_role_permission FOREIGN KEY (role_permission) REFERENCES application_permission(id)
); );
INSERT INTO application_permission (permission_name, permission_description) values ('test:view', 'Display test view'); INSERT INTO application_permission (id, permission_name, permission_description) values ('dfd0f8f1-4a51-4fdc-9a1c-a942bee9b649', 'test:view', 'Display test view');
INSERT INTO application_role (role_name, role_description) values ('Admin', 'Admin role'); INSERT INTO application_role (id, role_name, role_description) values ('5cd0aca0-5466-483d-8f3e-c369f8061131','Admin', 'Admin role');
INSERT INTO application_role (role_name, role_description) values ('User', 'Standard user role'); INSERT INTO application_role (id, role_name, role_description) values ('da30060e-fd23-4016-a506-4e12e9322148', 'User', 'Standard user role');
-- INSERT INTO role_permission (role_name, permission_name) values ('Admin','test:view'); -- INSERT INTO role_permission (role_name, permission_name) values ('Admin','test:view');
INSERT INTO account (username, emailaddress, firstname, lastname, account_password, created_by, last_updated_by) values('admin', 'joern@muehlencord.de', 'Joern', 'Muehlencord','$shiro1$SHA-256$500000$4bHPNH9k539UjdFLgm/HOA==$T/n8skgoGSOtNw/c9ScDlXCiGrx2cZF0Esrvf6WPq6g=', 'admin','admin'); --admin/secret INSERT INTO account (id, username, emailaddress, firstname, lastname, account_password, created_by, last_updated_by) values('ab5c8337-6872-4aea-a9b9-78ea63706b8f','admin', 'joern@muehlencord.de', 'Joern', 'Muehlencord','$shiro1$SHA-256$500000$4bHPNH9k539UjdFLgm/HOA==$T/n8skgoGSOtNw/c9ScDlXCiGrx2cZF0Esrvf6WPq6g=', 'admin','admin'); --admin/secret
INSERT INTO account_role (username, role_name) values ('admin', 'Admin'); INSERT INTO account_role (account, account_role) values ('ab5c8337-6872-4aea-a9b9-78ea63706b8f', '5cd0aca0-5466-483d-8f3e-c369f8061131');
--select uuid_generate_v4();

View File

@ -4,7 +4,7 @@ import de.muehlencord.shared.account.business.ConfigService;
import de.muehlencord.shared.account.business.mail.MailException; import de.muehlencord.shared.account.business.mail.MailException;
import de.muehlencord.shared.account.business.mail.MailService; import de.muehlencord.shared.account.business.mail.MailService;
import de.muehlencord.shared.account.entity.AccountEntity; import de.muehlencord.shared.account.entity.AccountEntity;
import de.muehlencord.shared.account.entity.RoleEntity; import de.muehlencord.shared.account.entity.ApplicationRoleEntity;
import de.muehlencord.shared.account.util.SecurityUtil; import de.muehlencord.shared.account.util.SecurityUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -50,7 +50,7 @@ public class AccountControl {
StringBuilder queryBuilder = new StringBuilder(); StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("SELECT a FROM AccountEntity a "); queryBuilder.append("SELECT a FROM AccountEntity a ");
if (loadRoles) { if (loadRoles) {
queryBuilder.append("JOIN FETCH a.roleEntityList "); queryBuilder.append("JOIN FETCH a.applicationRoleList ");
} }
queryBuilder.append("WHERE a.username = :username"); queryBuilder.append("WHERE a.username = :username");
Query query = em.createQuery(queryBuilder.toString()); Query query = em.createQuery(queryBuilder.toString());
@ -93,21 +93,21 @@ public class AccountControl {
// load Admin or User role from database // load Admin or User role from database
String roleName = (isAdmin ? "Admin" : "User"); String roleName = (isAdmin ? "Admin" : "User");
Query roleQuery = em.createNamedQuery("RoleEntity.findByRoleName"); Query roleQuery = em.createNamedQuery("ApplicationRole.findByRoleName");
roleQuery.setParameter("roleName", roleName); roleQuery.setParameter("roleName", roleName);
RoleEntity role = (RoleEntity) roleQuery.getSingleResult(); ApplicationRoleEntity role = (ApplicationRoleEntity) roleQuery.getSingleResult();
if (role != null) { if (role != null) {
// add new user add required role // add new user add required role
// do not request based on newUser variable; this way existing users with missing role (for whatever reason) // do not request based on newUser variable; this way existing users with missing role (for whatever reason)
// will be fixed automatically // will be fixed automatically
if (account.getRoleEntityList() == null || account.getRoleEntityList().isEmpty()) { if (account.getApplicationRoleList() == null || account.getApplicationRoleList().isEmpty()) {
account.setRoleEntityList(new ArrayList<>()); account.setApplicationRoleList(new ArrayList<>());
account.getRoleEntityList().add(role); account.getApplicationRoleList().add(role);
em.merge(account); em.merge(account);
LOGGER.info("Added role " + roleName + " to user " + account.getUsername()); LOGGER.info("Added role " + roleName + " to user " + account.getUsername());
} else if (!account.getRoleEntityList().get(0).equals(role)) { } else if (!account.getApplicationRoleList().get(0).equals(role)) {
// change role from User to Admin and vice versa // change role from User to Admin and vice versa
// user already exists, has existing role // user already exists, has existing role
// check if existing role is different from current role and change it // check if existing role is different from current role and change it
@ -115,8 +115,8 @@ public class AccountControl {
// he is either User or Admin // he is either User or Admin
// TODO add "UserRole" to every user, make this default Role configurable // TODO add "UserRole" to every user, make this default Role configurable
// TODO add AdminRole in addtion if needed // TODO add AdminRole in addtion if needed
account.getRoleEntityList().remove(0); account.getApplicationRoleList().remove(0);
account.getRoleEntityList().add(role); account.getApplicationRoleList().add(role);
em.merge(account); em.merge(account);
LOGGER.info("Switched role of user " + account.getUsername() + " to " + roleName); LOGGER.info("Switched role of user " + account.getUsername() + " to " + roleName);

View File

@ -4,6 +4,7 @@ import de.muehlencord.shared.account.entity.AccountEntity;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Date; import java.util.Date;
import java.util.UUID;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
@ -38,8 +39,8 @@ public class MailService {
} }
public void sendTestHtmlEmail(String recipient) throws MailException { public void sendTestHtmlEmail(String recipient) throws MailException {
Date now = new Date(); Date now = new Date();
AccountEntity account = new AccountEntity("joern.muehlencord", "joern@muehlencord.de", "Jörn", "Mühlencord", "secret", 0, "NEW", now, "admin", now, "admin"); AccountEntity account = new AccountEntity(UUID.randomUUID(), "joern.muehlencord", "joern@muehlencord.de", "Jörn", "Mühlencord", "secret", 0, "NEW", false, now, "admin", now, "admin");
MailDatamodel dataModel = new MailDatamodel(account); MailDatamodel dataModel = new MailDatamodel(account);
dataModel.addParameter("url", "http://url.de"); dataModel.addParameter("url", "http://url.de");
dataModel.addParameter("resetUrl", "http://reseturl.de"); dataModel.addParameter("resetUrl", "http://reseturl.de");

View File

@ -3,10 +3,12 @@ package de.muehlencord.shared.account.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID;
import javax.persistence.Basic; import javax.persistence.Basic;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
@ -21,6 +23,8 @@ import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
/** /**
* *
@ -40,6 +44,9 @@ import javax.xml.bind.annotation.XmlTransient;
@NamedQuery(name = "AccountEntity.findByLastFailedLogin", query = "SELECT a FROM AccountEntity a WHERE a.lastFailedLogin = :lastFailedLogin"), @NamedQuery(name = "AccountEntity.findByLastFailedLogin", query = "SELECT a FROM AccountEntity a WHERE a.lastFailedLogin = :lastFailedLogin"),
@NamedQuery(name = "AccountEntity.findByFailureCount", query = "SELECT a FROM AccountEntity a WHERE a.failureCount = :failureCount"), @NamedQuery(name = "AccountEntity.findByFailureCount", query = "SELECT a FROM AccountEntity a WHERE a.failureCount = :failureCount"),
@NamedQuery(name = "AccountEntity.findByStatus", query = "SELECT a FROM AccountEntity a WHERE a.status = :status"), @NamedQuery(name = "AccountEntity.findByStatus", query = "SELECT a FROM AccountEntity a WHERE a.status = :status"),
@NamedQuery(name = "AccountEntity.findByPasswordResetOngoing", query = "SELECT a FROM AccountEntity a WHERE a.passwordResetOngoing = :passwordResetOngoing"),
@NamedQuery(name = "AccountEntity.findByPasswordResetValidTo", query = "SELECT a FROM AccountEntity a WHERE a.passwordResetValidTo = :passwordResetValidTo"),
@NamedQuery(name = "AccountEntity.findByPasswordResetHash", query = "SELECT a FROM AccountEntity a WHERE a.passwordResetHash = :passwordResetHash"),
@NamedQuery(name = "AccountEntity.findByCreatedOn", query = "SELECT a FROM AccountEntity a WHERE a.createdOn = :createdOn"), @NamedQuery(name = "AccountEntity.findByCreatedOn", query = "SELECT a FROM AccountEntity a WHERE a.createdOn = :createdOn"),
@NamedQuery(name = "AccountEntity.findByCreatedBy", query = "SELECT a FROM AccountEntity a WHERE a.createdBy = :createdBy"), @NamedQuery(name = "AccountEntity.findByCreatedBy", query = "SELECT a FROM AccountEntity a WHERE a.createdBy = :createdBy"),
@NamedQuery(name = "AccountEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"), @NamedQuery(name = "AccountEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"),
@ -50,6 +57,13 @@ public class AccountEntity implements Serializable {
@Id @Id
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull
@Column(name = "id")
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Type(type = "pg-uuid")
private UUID id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 32) @Size(min = 1, max = 32)
@Column(name = "username") @Column(name = "username")
private String username; private String username;
@ -119,22 +133,22 @@ public class AccountEntity implements Serializable {
@Column(name = "last_updated_by") @Column(name = "last_updated_by")
private String lastUpdatedBy; private String lastUpdatedBy;
@JoinTable(name = "account_role", joinColumns = { @JoinTable(name = "account_role", joinColumns = {
@JoinColumn(name = "username", referencedColumnName = "username")}, inverseJoinColumns = { @JoinColumn(name = "account", referencedColumnName = "id")}, inverseJoinColumns = {
@JoinColumn(name = "role_name", referencedColumnName = "role_name")}) @JoinColumn(name = "account_role", referencedColumnName = "id")})
@ManyToMany @ManyToMany
private List<RoleEntity> roleEntityList; private List<ApplicationRoleEntity> applicationRoleList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "username") @OneToMany(cascade = CascadeType.ALL, mappedBy = "accountId")
private List<AccountHistoryEntity> accountHistoryEntityList; private List<AccountHistoryEntity> accountHistoryList;
public AccountEntity() { public AccountEntity() {
// empty constructor needed for JPA handling, do not remove
} }
public AccountEntity(String username) { public AccountEntity(UUID id) {
this.username = username; this.id = id;
} }
public AccountEntity(String username, String emailaddress, String firstname, String lastname, String accountPassword, int failureCount, String status, Date createdOn, String createdBy, Date lastUpdatedOn, String lastUpdatedBy) { public AccountEntity(UUID id, String username, String emailaddress, String firstname, String lastname, String accountPassword, int failureCount, String status, boolean passwordResetOngoing, Date createdOn, String createdBy, Date lastUpdatedOn, String lastUpdatedBy) {
this.id = id;
this.username = username; this.username = username;
this.emailaddress = emailaddress; this.emailaddress = emailaddress;
this.firstname = firstname; this.firstname = firstname;
@ -142,12 +156,21 @@ public class AccountEntity implements Serializable {
this.accountPassword = accountPassword; this.accountPassword = accountPassword;
this.failureCount = failureCount; this.failureCount = failureCount;
this.status = status; this.status = status;
this.passwordResetOngoing = passwordResetOngoing;
this.createdOn = createdOn; this.createdOn = createdOn;
this.createdBy = createdBy; this.createdBy = createdBy;
this.lastUpdatedOn = lastUpdatedOn; this.lastUpdatedOn = lastUpdatedOn;
this.lastUpdatedBy = lastUpdatedBy; this.lastUpdatedBy = lastUpdatedBy;
} }
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getUsername() { public String getUsername() {
return username; return username;
} }
@ -277,27 +300,27 @@ public class AccountEntity implements Serializable {
} }
@XmlTransient @XmlTransient
public List<RoleEntity> getRoleEntityList() { public List<ApplicationRoleEntity> getApplicationRoleList() {
return roleEntityList; return applicationRoleList;
} }
public void setRoleEntityList(List<RoleEntity> roleEntityList) { public void setApplicationRoleList(List<ApplicationRoleEntity> applicationRoleList) {
this.roleEntityList = roleEntityList; this.applicationRoleList = applicationRoleList;
} }
@XmlTransient @XmlTransient
public List<AccountHistoryEntity> getAccountHistoryEntityList() { public List<AccountHistoryEntity> getAccountHistoryList() {
return accountHistoryEntityList; return accountHistoryList;
} }
public void setAccountHistoryEntityList(List<AccountHistoryEntity> accountHistoryEntityList) { public void setAccountHistoryList(List<AccountHistoryEntity> accountHistoryList) {
this.accountHistoryEntityList = accountHistoryEntityList; this.accountHistoryList = accountHistoryList;
} }
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 0; int hash = 0;
hash += (username != null ? username.hashCode() : 0); hash += (id != null ? id.hashCode() : 0);
return hash; return hash;
} }
@ -308,7 +331,7 @@ public class AccountEntity implements Serializable {
return false; return false;
} }
AccountEntity other = (AccountEntity) object; AccountEntity other = (AccountEntity) object;
if ((this.username == null && other.username != null) || (this.username != null && !this.username.equals(other.username))) { if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false; return false;
} }
return true; return true;
@ -316,7 +339,7 @@ public class AccountEntity implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "de.muehlencord.ssg.entity.AccountEntity[ username=" + username + " ]"; return "de.muehlencord.shared.account.entity.Account[ id=" + id + " ]";
} }
} }

View File

@ -2,6 +2,7 @@ package de.muehlencord.shared.account.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.UUID;
import javax.persistence.Basic; import javax.persistence.Basic;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -18,6 +19,8 @@ import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
/** /**
* *
@ -38,10 +41,13 @@ public class AccountHistoryEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false) @Basic(optional = false)
@NotNull
@Column(name = "id") @Column(name = "id")
private Integer id; @GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Type(type = "pg-uuid")
private UUID id;
@Size(max = 200) @Size(max = 200)
@Column(name = "message") @Column(name = "message")
private String message; private String message;
@ -64,18 +70,18 @@ public class AccountHistoryEntity implements Serializable {
@Size(min = 1, max = 32) @Size(min = 1, max = 32)
@Column(name = "last_updated_by") @Column(name = "last_updated_by")
private String lastUpdatedBy; private String lastUpdatedBy;
@JoinColumn(name = "username", referencedColumnName = "username") @JoinColumn(name = "account_id", referencedColumnName = "id")
@ManyToOne(optional = false) @ManyToOne(optional = false)
private AccountEntity username; private AccountEntity accountId;
public AccountHistoryEntity() { public AccountHistoryEntity() {
} }
public AccountHistoryEntity(Integer id) { public AccountHistoryEntity(UUID id) {
this.id = id; this.id = id;
} }
public AccountHistoryEntity(Integer id, int failureCount, String status, Date lastUpdatedOn, String lastUpdatedBy) { public AccountHistoryEntity(UUID id, int failureCount, String status, Date lastUpdatedOn, String lastUpdatedBy) {
this.id = id; this.id = id;
this.failureCount = failureCount; this.failureCount = failureCount;
this.status = status; this.status = status;
@ -83,11 +89,11 @@ public class AccountHistoryEntity implements Serializable {
this.lastUpdatedBy = lastUpdatedBy; this.lastUpdatedBy = lastUpdatedBy;
} }
public Integer getId() { public UUID getId() {
return id; return id;
} }
public void setId(Integer id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
@ -131,12 +137,12 @@ public class AccountHistoryEntity implements Serializable {
this.lastUpdatedBy = lastUpdatedBy; this.lastUpdatedBy = lastUpdatedBy;
} }
public AccountEntity getUsername() { public AccountEntity getAccountId() {
return username; return accountId;
} }
public void setUsername(AccountEntity username) { public void setAccountId(AccountEntity accountId) {
this.username = username; this.accountId = accountId;
} }
@Override @Override
@ -161,7 +167,7 @@ public class AccountHistoryEntity implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "de.muehlencord.ssg.entity.AccountHistoryEntity[ id=" + id + " ]"; return "de.muehlencord.shared.account.entity.AccountHistory[ id=" + id + " ]";
} }
} }

View File

@ -0,0 +1,130 @@
package de.muehlencord.shared.account.entity;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
/**
*
* @author joern.muehlencord
*/
@Entity
@Table(name = "application_permission")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "ApplicationPermissionEntity.findAll", query = "SELECT a FROM ApplicationPermissionEntity a"),
@NamedQuery(name = "ApplicationPermissionEntity.findByPermissionName", query = "SELECT a FROM ApplicationPermissionEntity a WHERE a.permissionName = :permissionName"),
@NamedQuery(name = "ApplicationPermissionEntity.findByPermissionDescription", query = "SELECT a FROM ApplicationPermissionEntity a WHERE a.permissionDescription = :permissionDescription")})
public class ApplicationPermissionEntity implements Serializable {
private static final long serialVersionUID = -8985982754544829534L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "id")
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Type(type = "pg-uuid")
private UUID id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 80)
@Column(name = "permission_name")
private String permissionName;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 200)
@Column(name = "permission_description")
private String permissionDescription;
@ManyToMany(mappedBy = "applicationPermissionList")
private List<ApplicationRoleEntity> applicationRoleList;
public ApplicationPermissionEntity() {
}
public ApplicationPermissionEntity(UUID id) {
this.id = id;
}
public ApplicationPermissionEntity(UUID id, String permissionName, String permissionDescription) {
this.id = id;
this.permissionName = permissionName;
this.permissionDescription = permissionDescription;
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getPermissionName() {
return permissionName;
}
public void setPermissionName(String permissionName) {
this.permissionName = permissionName;
}
public String getPermissionDescription() {
return permissionDescription;
}
public void setPermissionDescription(String permissionDescription) {
this.permissionDescription = permissionDescription;
}
@XmlTransient
public List<ApplicationRoleEntity> getApplicationRoleList() {
return applicationRoleList;
}
public void setApplicationRoleList(List<ApplicationRoleEntity> applicationRoleList) {
this.applicationRoleList = applicationRoleList;
}
@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 ApplicationPermissionEntity)) {
return false;
}
ApplicationPermissionEntity other = (ApplicationPermissionEntity) 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 "de.muehlencord.shared.account.entity.ApplicationPermission[ id=" + id + " ]";
}
}

View File

@ -0,0 +1,147 @@
package de.muehlencord.shared.account.entity;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
/**
*
* @author joern.muehlencord
*/
@Entity
@Table(name = "application_role")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "ApplicationRoleEntity.findAll", query = "SELECT a FROM ApplicationRoleEntity a"),
@NamedQuery(name = "ApplicationRoleEntity.findByRoleName", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.roleName = :roleName"),
@NamedQuery(name = "ApplicationRoleEntity.findByRoleDescription", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.roleDescription = :roleDescription")})
public class ApplicationRoleEntity implements Serializable {
private static final long serialVersionUID = -8324054525780893823L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "id")
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Type(type = "pg-uuid")
private UUID id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 80)
@Column(name = "role_name")
private String roleName;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 200)
@Column(name = "role_description")
private String roleDescription;
@ManyToMany(mappedBy = "applicationRoleList")
private List<AccountEntity> accountList;
@JoinTable(name = "role_permission", joinColumns = {
@JoinColumn(name = "application_role", referencedColumnName = "id")}, inverseJoinColumns = {
@JoinColumn(name = "role_permission", referencedColumnName = "id")})
@ManyToMany
private List<ApplicationPermissionEntity> applicationPermissionList;
public ApplicationRoleEntity() {
}
public ApplicationRoleEntity(UUID id) {
this.id = id;
}
public ApplicationRoleEntity(UUID id, String roleName, String roleDescription) {
this.id = id;
this.roleName = roleName;
this.roleDescription = roleDescription;
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public String getRoleDescription() {
return roleDescription;
}
public void setRoleDescription(String roleDescription) {
this.roleDescription = roleDescription;
}
@XmlTransient
public List<AccountEntity> getAccountList() {
return accountList;
}
public void setAccountList(List<AccountEntity> accountList) {
this.accountList = accountList;
}
@XmlTransient
public List<ApplicationPermissionEntity> getApplicationPermissionList() {
return applicationPermissionList;
}
public void setApplicationPermissionList(List<ApplicationPermissionEntity> applicationPermissionList) {
this.applicationPermissionList = applicationPermissionList;
}
@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 ApplicationRoleEntity)) {
return false;
}
ApplicationRoleEntity other = (ApplicationRoleEntity) 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 "de.muehlencord.shared.account.entity.ApplicationRole[ id=" + id + " ]";
}
}

View File

@ -1,92 +1,87 @@
/* package de.muehlencord.shared.account.entity;
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates import java.io.Serializable;
* and open the template in the editor. import javax.persistence.Basic;
*/ import javax.persistence.Column;
package de.muehlencord.shared.account.entity; import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.Serializable; import javax.persistence.NamedQueries;
import javax.persistence.Basic; import javax.persistence.NamedQuery;
import javax.persistence.Column; import javax.persistence.Table;
import javax.persistence.Entity; import javax.validation.constraints.NotNull;
import javax.persistence.Id; import javax.validation.constraints.Size;
import javax.persistence.NamedQueries; import javax.xml.bind.annotation.XmlRootElement;
import javax.persistence.NamedQuery;
import javax.persistence.Table; /**
import javax.validation.constraints.NotNull; *
import javax.validation.constraints.Size; * @author joern.muehlencord
import javax.xml.bind.annotation.XmlRootElement; */
@Entity
/** @Table(name = "config")
* @XmlRootElement
* @author jomu @NamedQueries({
*/ @NamedQuery(name = "ConfigEntity.findAll", query = "SELECT c FROM ConfigEntity c"),
@Entity @NamedQuery(name = "ConfigEntity.findByConfigKey", query = "SELECT c FROM ConfigEntity c WHERE c.configKey = :configKey"),
@Table(name = "config") @NamedQuery(name = "ConfigEntity.findByConfigValue", query = "SELECT c FROM ConfigEntity c WHERE c.configValue = :configValue")})
@XmlRootElement public class ConfigEntity implements Serializable {
@NamedQueries({
@NamedQuery(name = "ConfigEntity.findAll", query = "SELECT c FROM ConfigEntity c"), private static final long serialVersionUID = 1L;
@NamedQuery(name = "ConfigEntity.findByConfigKey", query = "SELECT c FROM ConfigEntity c WHERE c.configKey = :configKey"), @Id
@NamedQuery(name = "ConfigEntity.findByConfigValue", query = "SELECT c FROM ConfigEntity c WHERE c.configValue = :configValue")}) @Basic(optional = false)
public class ConfigEntity implements Serializable { @NotNull
@Size(min = 1, max = 100)
private static final long serialVersionUID = 1L; @Column(name = "config_key")
@Id private String configKey;
@Basic(optional = false) @Size(max = 200)
@NotNull @Column(name = "config_value")
@Size(min = 1, max = 100) private String configValue;
@Column(name = "config_key")
private String configKey; public ConfigEntity() {
@Size(max = 200) }
@Column(name = "config_value")
private String configValue; public ConfigEntity(String configKey) {
this.configKey = configKey;
public ConfigEntity() { }
}
public String getConfigKey() {
public ConfigEntity(String configKey) { return configKey;
this.configKey = configKey; }
}
public void setConfigKey(String configKey) {
public String getConfigKey() { this.configKey = configKey;
return configKey; }
}
public String getConfigValue() {
public void setConfigKey(String configKey) { return configValue;
this.configKey = configKey; }
}
public void setConfigValue(String configValue) {
public String getConfigValue() { this.configValue = configValue;
return configValue; }
}
@Override
public void setConfigValue(String configValue) { public int hashCode() {
this.configValue = configValue; int hash = 0;
} hash += (configKey != null ? configKey.hashCode() : 0);
return hash;
@Override }
public int hashCode() {
int hash = 0; @Override
hash += (configKey != null ? configKey.hashCode() : 0); public boolean equals(Object object) {
return hash; // TODO: Warning - this method won't work in the case the id fields are not set
} if (!(object instanceof ConfigEntity)) {
return false;
@Override }
public boolean equals(Object object) { ConfigEntity other = (ConfigEntity) object;
// TODO: Warning - this method won't work in the case the id fields are not set if ((this.configKey == null && other.configKey != null) || (this.configKey != null && !this.configKey.equals(other.configKey))) {
if (!(object instanceof ConfigEntity)) { return false;
return false; }
} return true;
ConfigEntity other = (ConfigEntity) object; }
if ((this.configKey == null && other.configKey != null) || (this.configKey != null && !this.configKey.equals(other.configKey))) {
return false; @Override
} public String toString() {
return true; return "de.muehlencord.shared.account.entity.Config[ configKey=" + configKey + " ]";
} }
@Override }
public String toString() {
return "de.muehlencord.ssg.entity.ConfigEntity[ configKey=" + configKey + " ]";
}
}

View File

@ -14,7 +14,7 @@ import javax.xml.bind.annotation.XmlRootElement;
/** /**
* *
* @author jomu * @author joern.muehlencord
*/ */
@Entity @Entity
@Table(name = "mail_template") @Table(name = "mail_template")
@ -88,7 +88,7 @@ public class MailTemplateEntity implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "de.muehlencord.ssg.entity.MailTemplateEntity[ templateName=" + templateName + " ]"; return "de.muehlencord.shared.account.entity.MailTemplate[ templateName=" + templateName + " ]";
} }
} }

View File

@ -1,113 +0,0 @@
package de.muehlencord.shared.account.entity;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author joern.muehlencord
*/
@Entity
@Table(name = "application_permission")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "PermissionEntity.findAll", query = "SELECT p FROM PermissionEntity p"),
@NamedQuery(name = "PermissionEntity.findByPermissionName", query = "SELECT p FROM PermissionEntity p WHERE p.permissionName = :permissionName"),
@NamedQuery(name = "PermissionEntity.findByPermissionDescription", query = "SELECT p FROM PermissionEntity p WHERE p.permissionDescription = :permissionDescription")})
public class PermissionEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 80)
@Column(name = "permission_name")
private String permissionName;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 200)
@Column(name = "permission_description")
private String permissionDescription;
@JoinTable(name = "role_permission", joinColumns = {
@JoinColumn(name = "permission_name", referencedColumnName = "permission_name")}, inverseJoinColumns = {
@JoinColumn(name = "role_name", referencedColumnName = "role_name")})
@ManyToMany
private List<RoleEntity> roleEntityList;
public PermissionEntity() {
}
public PermissionEntity(String permissionName) {
this.permissionName = permissionName;
}
public PermissionEntity(String permissionName, String permissionDescription) {
this.permissionName = permissionName;
this.permissionDescription = permissionDescription;
}
public String getPermissionName() {
return permissionName;
}
public void setPermissionName(String permissionName) {
this.permissionName = permissionName;
}
public String getPermissionDescription() {
return permissionDescription;
}
public void setPermissionDescription(String permissionDescription) {
this.permissionDescription = permissionDescription;
}
@XmlTransient
public List<RoleEntity> getRoleEntityList() {
return roleEntityList;
}
public void setRoleEntityList(List<RoleEntity> roleEntityList) {
this.roleEntityList = roleEntityList;
}
@Override
public int hashCode() {
int hash = 0;
hash += (permissionName != null ? permissionName.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 PermissionEntity)) {
return false;
}
PermissionEntity other = (PermissionEntity) object;
if ((this.permissionName == null && other.permissionName != null) || (this.permissionName != null && !this.permissionName.equals(other.permissionName))) {
return false;
}
return true;
}
@Override
public String toString() {
return "de.muehlencord.ssg.entity.PermissionEntity[ permissionName=" + permissionName + " ]";
}
}

View File

@ -1,119 +0,0 @@
package de.muehlencord.shared.account.entity;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author joern.muehlencord
*/
@Entity
@Table(name = "application_role")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "RoleEntity.findAll", query = "SELECT r FROM RoleEntity r"),
@NamedQuery(name = "RoleEntity.findByRoleName", query = "SELECT r FROM RoleEntity r WHERE r.roleName = :roleName"),
@NamedQuery(name = "RoleEntity.findByRoleDescription", query = "SELECT r FROM RoleEntity r WHERE r.roleDescription = :roleDescription")})
public class RoleEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 80)
@Column(name = "role_name")
private String roleName;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 200)
@Column(name = "role_description")
private String roleDescription;
@ManyToMany(mappedBy = "roleEntityList")
private List<AccountEntity> accountEntityList;
@ManyToMany(mappedBy = "roleEntityList")
private List<PermissionEntity> permissionEntityList;
public RoleEntity() {
}
public RoleEntity(String roleName) {
this.roleName = roleName;
}
public RoleEntity(String roleName, String roleDescription) {
this.roleName = roleName;
this.roleDescription = roleDescription;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public String getRoleDescription() {
return roleDescription;
}
public void setRoleDescription(String roleDescription) {
this.roleDescription = roleDescription;
}
@XmlTransient
public List<AccountEntity> getAccountEntityList() {
return accountEntityList;
}
public void setAccountEntityList(List<AccountEntity> accountEntityList) {
this.accountEntityList = accountEntityList;
}
@XmlTransient
public List<PermissionEntity> getPermissionEntityList() {
return permissionEntityList;
}
public void setPermissionEntityList(List<PermissionEntity> permissionEntityList) {
this.permissionEntityList = permissionEntityList;
}
@Override
public int hashCode() {
int hash = 0;
hash += (roleName != null ? roleName.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 RoleEntity)) {
return false;
}
RoleEntity other = (RoleEntity) object;
if ((this.roleName == null && other.roleName != null) || (this.roleName != null && !this.roleName.equals(other.roleName))) {
return false;
}
return true;
}
@Override
public String toString() {
return "de.muehlencord.ssg.entity.RoleEntity[ roleName=" + roleName + " ]";
}
}

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<jboss/>

View File

@ -0,0 +1,13 @@
<?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="de.muehlencord.shared_shared-account_ejb_1.0-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/radius"/>
<property name="javax.persistence.jdbc.user" value="jomu"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.password" value="jomu"/>
</properties>
</persistence-unit>
</persistence>