diff --git a/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataId.java b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataId.java new file mode 100644 index 0000000..ba2b0ca --- /dev/null +++ b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataId.java @@ -0,0 +1,51 @@ +package org.orph2020.pst.common.json; + +import jakarta.persistence.Embeddable; +import java.io.Serializable; +import java.util.Objects; + + +@Embeddable +public class OpticalTelescopeDataId implements Serializable { + + private String proposalID; + private String observationID; + + public OpticalTelescopeDataId() { + } + + public OpticalTelescopeDataId(String proposalID, String observationID) { + this.proposalID = proposalID; + this.observationID = observationID; + } + + public String getProposalID() { + return proposalID; + } + + public void setProposalID(String proposalID) { + this.proposalID = proposalID; + } + + public String getObservationID() { + return observationID; + } + + public void setObservationID(String observationID) { + this.observationID = observationID; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + OpticalTelescopeDataId that = (OpticalTelescopeDataId) o; + return Objects.equals(proposalID, that.proposalID) && + Objects.equals(observationID, that.observationID); + } + + @Override + public int hashCode() { + return Objects.hash(proposalID, observationID); + } +} \ No newline at end of file diff --git a/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataLoad.java b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataLoad.java index 546de14..15cf279 100644 --- a/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataLoad.java +++ b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataLoad.java @@ -3,10 +3,10 @@ // data type for the loading of the optional telescope data. public class OpticalTelescopeDataLoad { // the proposal id. - public String proposalID; + private String proposalID; // the observation id for the telescope data. - public String observationID; + private String observationID; /** * the constructor for the data saved within the database for a given @@ -18,4 +18,29 @@ public OpticalTelescopeDataLoad(String proposalID, String observationID) { this.proposalID = proposalID; this.observationID = observationID; } + + /** + * the default constructor for the data saved within the database for a given + * observation. + */ + public OpticalTelescopeDataLoad() { + this.proposalID = null; + this.observationID = null; + } + + public String getProposalID() { + return proposalID; + } + + public void setProposalID(String proposalID) { + this.proposalID = proposalID; + } + + public String getObservationID() { + return observationID; + } + + public void setObservationID(String observationID) { + this.observationID = observationID; + } } diff --git a/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataSave.java b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataSave.java index 4d1563d..0c82288 100644 --- a/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataSave.java +++ b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataSave.java @@ -1,13 +1,32 @@ package org.orph2020.pst.common.json; - +import jakarta.persistence.*; import java.util.HashMap; +import java.util.Map; + +@Entity +@Table(name = "optical_telescope_data") +public class OpticalTelescopeDataSave { + @EmbeddedId + private OpticalTelescopeDataId primaryKey; + + @ElementCollection + @CollectionTable(name = "telescope_choices", joinColumns = { + @JoinColumn(name = "proposal_id", referencedColumnName = "proposalID"), + @JoinColumn(name = "observation_id", referencedColumnName = "observationID") + }) -public class OpticalTelescopeDataSave extends OpticalTelescopeDataLoad{ // the new states of the choices. - HashMap choices; + @MapKeyColumn(name = "choice_key") + @Column(name = "choice_value") + private Map choices; // the telescope name. - public String telescopeName; + @Column(name = "telescope_name") + private String telescopeName; + + // the instrument name. + @Column(name = "instrument_name") + private String instrumentName; /** * constructor for the telescope data for saving. @@ -15,13 +34,51 @@ public class OpticalTelescopeDataSave extends OpticalTelescopeDataLoad{ * @param proposalID: the proposal id. * @param observationID: the observation id. * @param telescopeName: the telescope name. + * @param instrumentName: the instrument name chosen for the choices. * @param choices: the choices made. */ public OpticalTelescopeDataSave( String proposalID, String observationID, String telescopeName, - HashMap choices) { - super(proposalID, observationID); + String instrumentName, HashMap choices) { + this.primaryKey = new OpticalTelescopeDataId(proposalID, observationID); this.telescopeName = telescopeName; + this.instrumentName = instrumentName; + this.choices = choices; + } + + public OpticalTelescopeDataSave() { + // No-argument constructor for Hibernate ORM + } + + public Map getChoices() { + return choices; + } + + public void setChoices(Map choices) { this.choices = choices; } + + public void setTelescopeName(String telescopeName) { + this.telescopeName = telescopeName; + } + + public void setInstrumentName(String instrumentName) { + this.instrumentName = instrumentName; + } + + public String getTelescopeName() { + return telescopeName; + } + + public String getInstrumentName() { + return instrumentName; + } + + public OpticalTelescopeDataId getPrimaryKey() { + return primaryKey; + } + + public void setPrimaryKey(OpticalTelescopeDataId primaryKey) { + this.primaryKey = primaryKey; + } }