2021-01-06 13:40:04 +01:00
|
|
|
package com.plannaplan.entities;
|
|
|
|
|
2021-01-13 12:23:00 +01:00
|
|
|
import java.sql.Timestamp;
|
|
|
|
|
2021-01-06 13:40:04 +01:00
|
|
|
import javax.persistence.Entity;
|
|
|
|
import javax.persistence.GeneratedValue;
|
|
|
|
import javax.persistence.GenerationType;
|
|
|
|
import javax.persistence.Id;
|
2021-01-06 14:34:25 +01:00
|
|
|
import javax.persistence.JoinColumn;
|
|
|
|
import javax.persistence.OneToOne;
|
2021-01-06 13:40:04 +01:00
|
|
|
|
2021-01-06 16:23:18 +01:00
|
|
|
/**
|
2021-01-07 16:51:35 +01:00
|
|
|
* Entity that keeps user exchange offer.
|
2021-01-06 16:23:18 +01:00
|
|
|
*/
|
2021-01-06 13:40:04 +01:00
|
|
|
@Entity
|
|
|
|
public class Exchange {
|
|
|
|
|
|
|
|
@Id
|
|
|
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
|
|
private Long id;
|
|
|
|
|
2021-01-06 14:34:25 +01:00
|
|
|
@OneToOne
|
2021-01-13 12:23:00 +01:00
|
|
|
@JoinColumn(name = "owned_id")
|
2021-01-06 13:40:04 +01:00
|
|
|
private Assignment ownedAssignment;
|
2021-01-07 16:51:35 +01:00
|
|
|
|
2021-01-06 14:34:25 +01:00
|
|
|
@OneToOne
|
|
|
|
@JoinColumn(name = "desired_id")
|
2021-01-06 13:40:04 +01:00
|
|
|
private Groups desiredAssignment;
|
|
|
|
|
2021-01-07 16:51:35 +01:00
|
|
|
private Long ownerId;
|
|
|
|
|
2021-01-13 12:23:00 +01:00
|
|
|
private Timestamp dateExchange;
|
|
|
|
|
2021-01-07 16:51:35 +01:00
|
|
|
public Exchange(){
|
2021-01-13 12:23:00 +01:00
|
|
|
|
2021-01-06 13:40:04 +01:00
|
|
|
}
|
|
|
|
|
2021-01-13 12:23:00 +01:00
|
|
|
/**
|
2021-01-07 16:51:35 +01:00
|
|
|
* @return Long ID of exchange trader
|
|
|
|
*/
|
|
|
|
public Long getOwnerId() {
|
|
|
|
return ownerId;
|
|
|
|
}
|
2021-01-13 12:23:00 +01:00
|
|
|
|
|
|
|
/**
|
2021-01-07 16:51:35 +01:00
|
|
|
* @param ownerId ID of exchange trader
|
|
|
|
*/
|
|
|
|
public void setOwnerId(Long ownerId) {
|
|
|
|
this.ownerId = ownerId;
|
|
|
|
}
|
|
|
|
|
2021-01-13 12:23:00 +01:00
|
|
|
public Timestamp getDataExchange() {
|
|
|
|
return this.dateExchange;
|
|
|
|
}
|
|
|
|
|
2021-01-07 16:51:35 +01:00
|
|
|
/**
|
2021-01-13 12:23:00 +01:00
|
|
|
*
|
2021-01-07 16:51:35 +01:00
|
|
|
* @param ownedAssignment Assignment which owner would like to trade
|
|
|
|
* @param desiredAssignment Groups instance that trader wants
|
|
|
|
*/
|
|
|
|
public Exchange(Assignment ownedAssignment, Groups desiredAssignment) {
|
2021-01-06 13:40:04 +01:00
|
|
|
this.ownedAssignment = ownedAssignment;
|
|
|
|
this.desiredAssignment = desiredAssignment;
|
2021-01-13 12:23:00 +01:00
|
|
|
this.ownerId = this.ownedAssignment != null ? this.ownedAssignment.getCommision().getCommisionOwner().getId() : null;
|
|
|
|
this.dateExchange = new Timestamp(System.currentTimeMillis());
|
2021-01-06 13:40:04 +01:00
|
|
|
}
|
|
|
|
|
2021-01-13 12:23:00 +01:00
|
|
|
/**
|
2021-01-06 16:23:18 +01:00
|
|
|
* @return Long ID in database
|
|
|
|
*/
|
2021-01-06 13:40:04 +01:00
|
|
|
public Long getId(){
|
|
|
|
return this.id;
|
|
|
|
}
|
2021-01-13 12:23:00 +01:00
|
|
|
|
|
|
|
/**
|
2021-01-06 16:23:18 +01:00
|
|
|
* @return Groups Target group
|
|
|
|
*/
|
2021-01-06 13:40:04 +01:00
|
|
|
public Groups getDesiredAssignment() {
|
|
|
|
return desiredAssignment;
|
|
|
|
}
|
|
|
|
|
2021-01-13 12:23:00 +01:00
|
|
|
/**
|
2021-01-06 16:23:18 +01:00
|
|
|
* @param desiredAssignment Target group
|
|
|
|
*/
|
2021-01-06 13:40:04 +01:00
|
|
|
public void setDesiredAssignment(Groups desiredAssignment) {
|
|
|
|
this.desiredAssignment = desiredAssignment;
|
|
|
|
}
|
|
|
|
|
2021-01-13 12:23:00 +01:00
|
|
|
/**
|
2021-01-06 16:23:18 +01:00
|
|
|
* @return Assignment Owned assignment
|
|
|
|
*/
|
2021-01-06 13:40:04 +01:00
|
|
|
public Assignment getOwnedAssignment() {
|
|
|
|
return ownedAssignment;
|
|
|
|
}
|
|
|
|
|
2021-01-13 12:23:00 +01:00
|
|
|
/**
|
2021-01-06 16:23:18 +01:00
|
|
|
* @param ownedAssignment Owned assignment
|
|
|
|
*/
|
2021-01-06 13:40:04 +01:00
|
|
|
public void setOwnedAssignment(Assignment ownedAssignment) {
|
|
|
|
this.ownedAssignment = ownedAssignment;
|
|
|
|
}
|
2021-01-13 12:23:00 +01:00
|
|
|
}
|