Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.20 KB | None | 0 0
  1. import com.fasterxml.jackson.annotation.JsonBackReference;
  2.  
  3. import javax.persistence.*;
  4. import javax.validation.constraints.NotNull;
  5. import java.math.BigDecimal;
  6. import java.util.*;
  7. import java.util.stream.Collectors;
  8.  
  9. @Entity
  10. @Table(name = "user")
  11. public class User {
  12. @Id
  13. @GeneratedValue(strategy= GenerationType.AUTO)
  14. @Column(name="id")
  15. private Integer id;
  16.  
  17. @Column(name="email")
  18. private String email;
  19.  
  20. @Column(name="username")
  21. private String username;
  22.  
  23. @Column(name="password_hash")
  24. private String password;
  25.  
  26. @Column(name = "activation_token")
  27. private String activationToken;
  28.  
  29. @Column(name = "change_password_date")
  30. private Date changePasswordDate;
  31.  
  32. @Column(name = "change_password_token")
  33. private String changePasswordToken;
  34.  
  35. @Column(name = "enabled")
  36. private boolean enabled;
  37.  
  38. @Column(name = "last_password_reset_date")
  39. @Temporal(TemporalType.TIMESTAMP)
  40. @NotNull
  41. private Date lastPasswordResetDate;
  42.  
  43. @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE)
  44. @JoinTable(
  45. name = "USER_AUTHORITY",
  46. joinColumns = {@JoinColumn(name = "USER_ID", referencedColumnName = "ID")},
  47. inverseJoinColumns = {@JoinColumn(name = "AUTHORITY_ID", referencedColumnName = "ID")})
  48. private List<Authority> authorities;
  49.  
  50. @Column(name="village_name")
  51. private String villageName;
  52.  
  53. @Column(name="coordinate_x")
  54. private Integer coordinateX;
  55.  
  56. @Column(name="coordinate_y")
  57. private Integer coordinateY;
  58.  
  59. @ManyToOne(cascade = CascadeType.REMOVE)
  60. @JoinColumn(name="mine_id")
  61. private Mine mine;
  62.  
  63. @ManyToOne(cascade = CascadeType.REMOVE)
  64. @JoinColumn(name="sawmill_id")
  65. private Sawmill sawmill;
  66.  
  67. @ManyToOne(cascade = CascadeType.REMOVE)
  68. @JoinColumn(name="farm_id")
  69. private Farm farm;
  70.  
  71. @ManyToOne(cascade = CascadeType.REMOVE)
  72. @JoinColumn(name="barrack_id")
  73. private Barrack barrack;
  74.  
  75. @OneToMany(fetch = FetchType.LAZY, mappedBy = "attacker", cascade = CascadeType.REMOVE)
  76. private Set<Report> attackReports;
  77.  
  78. @OneToMany(fetch = FetchType.LAZY, mappedBy = "defender", cascade = CascadeType.REMOVE)
  79. private Set<Report> defenceReports;
  80.  
  81. @OneToMany(fetch = FetchType.LAZY, mappedBy = "user", cascade = CascadeType.REMOVE)
  82. private Set<ExplorationReport> explorationReports;
  83.  
  84. @OneToMany(fetch = FetchType.EAGER, mappedBy = "user", cascade = CascadeType.REMOVE)
  85. private Set<UsersUnits> usersUnits;
  86.  
  87. @OneToMany(fetch = FetchType.EAGER, mappedBy = "user", cascade = CascadeType.REMOVE)
  88. private Set<Field> fields;
  89.  
  90. @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
  91. @JoinColumn(name="resources_id")
  92. private Resources resources;
  93.  
  94. @Version
  95. @Column(name="version")
  96. private Integer version;
  97.  
  98. public Set<Field> getFields() {
  99. return fields.stream().sorted((f1, f2) -> f1.getId()
  100. .compareTo(f2.getId())).collect(Collectors.toSet());
  101. }
  102.  
  103. public void setFields(Set<Field> fields) {
  104. this.fields = fields;
  105. }
  106.  
  107. public Integer getId() {
  108. return id;
  109. }
  110.  
  111. public String getUsername() {
  112. return username;
  113. }
  114.  
  115. public void setUsername(String username) {
  116. this.username = username;
  117. }
  118.  
  119. public void setId(Integer id) {
  120. this.id = id;
  121. }
  122.  
  123. public Integer getVersion() {
  124. return version;
  125. }
  126.  
  127. public void setVersion(Integer version) {
  128. this.version = version;
  129. }
  130.  
  131. public String getEmail() {
  132. return email;
  133. }
  134.  
  135. public void setEmail(String email) {
  136. this.email = email;
  137. }
  138.  
  139. public String getPassword() {
  140. return password;
  141. }
  142.  
  143. public void setPassword(String password) {
  144. this.password = password;
  145. }
  146.  
  147. public boolean isEnabled() {
  148. return enabled;
  149. }
  150.  
  151. public void setEnabled(boolean enabled) {
  152. this.enabled = enabled;
  153. }
  154.  
  155. public Date getChangePasswordDate() {
  156. return changePasswordDate;
  157. }
  158.  
  159. public void setChangePasswordDate(Date changePasswordDate) {
  160. this.changePasswordDate = changePasswordDate;
  161. }
  162.  
  163. public String getChangePasswordToken() {
  164. return changePasswordToken;
  165. }
  166.  
  167. public void setChangePasswordToken(String changePasswordToken) {
  168. this.changePasswordToken = changePasswordToken;
  169. }
  170.  
  171. public String getActivationToken() {
  172. return activationToken;
  173. }
  174.  
  175. public void setActivationToken(String activationToken) {
  176. this.activationToken = activationToken;
  177. }
  178.  
  179. public List<Report> getAttackReports() {
  180. return attackReports.stream().sorted((f1, f2) -> f2.getAttackDate()
  181. .compareTo(f1.getAttackDate())).collect(Collectors.toList());
  182. }
  183.  
  184. public List<Report> getDefenceReports() {
  185. return defenceReports.stream().sorted((f1, f2) -> f2.getAttackDate()
  186. .compareTo(f1.getAttackDate())).collect(Collectors.toList());
  187. }
  188.  
  189. public Date getLastPasswordResetDate() {
  190. return lastPasswordResetDate;
  191. }
  192.  
  193. public void setLastPasswordResetDate(Date lastPasswordResetDate) {
  194. this.lastPasswordResetDate = lastPasswordResetDate;
  195. }
  196.  
  197. public List<Authority> getAuthorities() {
  198. return authorities;
  199. }
  200.  
  201. public void setAuthorities(List<Authority> authorities) {
  202. this.authorities = authorities;
  203. }
  204.  
  205. public String getVillageName() {
  206. return villageName;
  207. }
  208.  
  209. public void setVillageName(String villageName) {
  210. this.villageName = villageName;
  211. }
  212.  
  213. public Integer getCoordinateX() {
  214. return coordinateX;
  215. }
  216.  
  217. public void setCoordinateX(Integer coordinateX) {
  218. this.coordinateX = coordinateX;
  219. }
  220.  
  221. public Integer getCoordinateY() {
  222. return coordinateY;
  223. }
  224.  
  225. public void setCoordinateY(Integer coordinateY) {
  226. this.coordinateY = coordinateY;
  227. }
  228.  
  229. public void setAttackReports(Set<Report> attackReports) {
  230. this.attackReports = attackReports;
  231. }
  232.  
  233. public void setDefenceReports(Set<Report> defenceReports) {
  234. this.defenceReports = defenceReports;
  235. }
  236.  
  237. public Set<UsersUnits> getUsersUnits() {
  238. return usersUnits;
  239. }
  240.  
  241. public void setUsersUnits(Set<UsersUnits> usersUnits) {
  242. this.usersUnits = usersUnits;
  243. }
  244.  
  245. public Mine getMine() {
  246. return mine;
  247. }
  248.  
  249. public void setMine(Mine mine) {
  250. this.mine = mine;
  251. }
  252.  
  253. public Sawmill getSawmill() {
  254. return sawmill;
  255. }
  256.  
  257. public void setSawmill(Sawmill sawmill) {
  258. this.sawmill = sawmill;
  259. }
  260.  
  261. public Farm getFarm() {
  262. return farm;
  263. }
  264.  
  265. public void setFarm(Farm farm) {
  266. this.farm = farm;
  267. }
  268.  
  269. public Barrack getBarrack() {
  270. return barrack;
  271. }
  272.  
  273. public void setBarrack(Barrack barrack) {
  274. this.barrack = barrack;
  275. }
  276.  
  277. public Resources getResources() {
  278. return resources;
  279. }
  280.  
  281. public void setResources(Resources resources) {
  282. this.resources = resources;
  283. }
  284.  
  285. public List<ExplorationReport> getExplorationReports() {
  286. return explorationReports.stream().sorted((f1, f2) -> f2.getExplorationDate()
  287. .compareTo(f1.getExplorationDate())).collect(Collectors.toList());
  288. }
  289.  
  290. public void setExplorationReports(Set<ExplorationReport> explorationReports) {
  291. this.explorationReports = explorationReports;
  292. }
  293.  
  294. public User() {
  295. }
  296.  
  297. public User(String email, String username, String password, String activationToken, Authority authority) {
  298. this.email = email;
  299. this.username = username;
  300. this.password = password;
  301. this.activationToken = activationToken;
  302. this.enabled = false;
  303. this.lastPasswordResetDate = new Date();
  304. this.authorities = new ArrayList<>();
  305. this.attackReports = new HashSet<>();
  306. this.defenceReports = new HashSet<>();
  307. this.explorationReports = new HashSet<>();
  308. this.authorities.add(authority);
  309. this.version = 0;
  310. }
  311.  
  312.  
  313. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement