diff --git a/src/main/java/info/bukova/isspst/data/BaseSimpleData.java b/src/main/java/info/bukova/isspst/data/BaseSimpleData.java new file mode 100644 index 00000000..d25c9fce --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/BaseSimpleData.java @@ -0,0 +1,65 @@ +package info.bukova.isspst.data; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.Transient; + +@MappedSuperclass +public abstract class BaseSimpleData implements DataModel { + + @Id + @Column(name="ID") + @GeneratedValue + private int id; + @Column(name="CREATED") + private Date created; + @Column(name="MODIFIED") + private Date modified; + @Transient + private boolean valid; + + @Override + public int getId() { + return id; + } + + @Override + public void setId(int id) { + this.id = id; + } + + @Override + public Date getCreated() { + return created; + } + + @Override + public void setCreated(Date created) { + this.created = created; + } + + @Override + public Date getModified() { + return modified; + } + + @Override + public void setModified(Date modified) { + this.modified = modified; + } + + @Override + public boolean isValid() { + return valid; + } + + @Override + public void setValid(boolean valid) { + this.valid = valid; + } + +} diff --git a/src/main/java/info/bukova/isspst/data/Role.java b/src/main/java/info/bukova/isspst/data/Role.java index b957606f..4c7bbc2f 100644 --- a/src/main/java/info/bukova/isspst/data/Role.java +++ b/src/main/java/info/bukova/isspst/data/Role.java @@ -1,40 +1,25 @@ package info.bukova.isspst.data; -import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; import javax.persistence.Table; -import javax.persistence.Transient; import org.springframework.security.core.GrantedAuthority; @Entity @Table(name="ROLE") -public class Role implements GrantedAuthority, DataModel { +public class Role extends BaseSimpleData implements GrantedAuthority, DataModel { /** * */ private static final long serialVersionUID = 5677876140880991163L; - @Id - @Column(name="ID") - @GeneratedValue - private int id; @Column(name="AUTHORITY", unique=true) private String authority; @Column(name="DESCRIPTION") private String description; - @Column(name="CREATED") - private Date created; - @Column(name="MODIFIED") - private Date modified; - @Transient - private boolean valid; - + public Role(String authority, String description) { this.authority = authority; this.description = description; @@ -49,14 +34,6 @@ public class Role implements GrantedAuthority, DataModel { return authority; } - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - public String getDescription() { return description; } @@ -69,33 +46,9 @@ public class Role implements GrantedAuthority, DataModel { this.authority = authority; } - public Date getCreated() { - return created; - } - - public void setCreated(Date created) { - this.created = created; - } - - public Date getModified() { - return modified; - } - - public void setModified(Date modified) { - this.modified = modified; - } - - public boolean isValid() { - return valid; - } - - public void setValid(boolean valid) { - this.valid = valid; - } - @Override public boolean equals(Object o) { - if ((o instanceof Role) && ((Role)o).getId() == this.id) { + if ((o instanceof Role) && ((Role)o).getId() == this.getId()) { return true; } else { return false; diff --git a/src/main/java/info/bukova/isspst/data/User.java b/src/main/java/info/bukova/isspst/data/User.java index fc3c20d7..34790a9e 100644 --- a/src/main/java/info/bukova/isspst/data/User.java +++ b/src/main/java/info/bukova/isspst/data/User.java @@ -1,35 +1,27 @@ package info.bukova.isspst.data; import java.util.ArrayList; -import java.util.Date; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.Table; -import javax.persistence.Transient; import org.springframework.security.core.userdetails.UserDetails; @Entity @Table(name="USER") -public class User implements UserDetails, DataModel { +public class User extends BaseSimpleData implements UserDetails, DataModel { /** * */ private static final long serialVersionUID = 5421234421833765433L; - @Id - @Column(name="ID") - @GeneratedValue - private int id; @Column(name="USERNAME", unique=true) private String username; @Column(name="PASSWORD") @@ -49,13 +41,7 @@ public class User implements UserDetails, DataModel { @ManyToMany(fetch=FetchType.EAGER) @JoinTable(name="USER_ROLE", joinColumns={@JoinColumn(name="USER_ID")}, inverseJoinColumns={@JoinColumn(name="ROLE_ID")}) private List authorities; - @Column(name="CREATED") - private Date created; - @Column(name="MODIFIED") - private Date modified; - @Transient - private boolean valid; - + public User() { authorities = new ArrayList(); } @@ -95,14 +81,6 @@ public class User implements UserDetails, DataModel { return enabled; } - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - public void setPassword(String password) { this.password = password; } @@ -123,30 +101,6 @@ public class User implements UserDetails, DataModel { this.authorities.add(role); } - public Date getCreated() { - return created; - } - - public void setCreated(Date created) { - this.created = created; - } - - public Date getModified() { - return modified; - } - - public void setModified(Date modified) { - this.modified = modified; - } - - public boolean isValid() { - return valid; - } - - public void setValid(boolean valid) { - this.valid = valid; - } - public String getFullName() { String ret = ""; if (firstName != null && !firstName.isEmpty()) {