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..05fe7b4 100644 --- a/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataLoad.java +++ b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataLoad.java @@ -1,12 +1,10 @@ package org.orph2020.pst.common.json; // data type for the loading of the optional telescope data. -public class OpticalTelescopeDataLoad { - // the proposal id. - public String proposalID; +public class OpticalTelescopeDataLoad extends OpticalTelescopeDataProposal { // 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 @@ -15,7 +13,24 @@ public class OpticalTelescopeDataLoad { * @param observationID: the observation id. */ public OpticalTelescopeDataLoad(String proposalID, String observationID) { - this.proposalID = proposalID; + super(proposalID); + this.observationID = observationID; + } + + /** + * the default constructor for the data saved within the database for a given + * observation. + */ + public OpticalTelescopeDataLoad() { + super(null); + this.observationID = null; + } + + public String getObservationID() { + return observationID; + } + + public void setObservationID(String observationID) { this.observationID = observationID; } } diff --git a/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataProposal.java b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataProposal.java new file mode 100644 index 0000000..520c5e6 --- /dev/null +++ b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataProposal.java @@ -0,0 +1,30 @@ +package org.orph2020.pst.common.json; + +/** + * creates a holder for the proposal id only. + */ +public class OpticalTelescopeDataProposal { + // the proposal id + private String proposalID; + + // default constructor. + public OpticalTelescopeDataProposal() { + } + + /** + * constructor. + * + * @param proposalID the proposal id. + */ + public OpticalTelescopeDataProposal(String proposalID) { + this.proposalID = proposalID; + } + + public String getProposalID() { + return proposalID; + } + + public void setProposalID(String proposalID) { + this.proposalID = proposalID; + } +} 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..8429e58 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,47 @@ 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", + foreignKey = @ForeignKey( + foreignKeyDefinition = "ON DELETE CASCADE")), + @JoinColumn(name = "observation_id", + referencedColumnName = "observationID", + foreignKey = @ForeignKey( + foreignKeyDefinition = "ON DELETE CASCADE")) + }) -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; + + // the time value + @Column(name = "telescope_time_value") + private String telescopeTimeValue; + + @Column(name = "telescope_time_unit") + private String telescopeTimeUnit; + + @Column(name = "user_type") + private String userType; /** * constructor for the telescope data for saving. @@ -15,13 +49,83 @@ 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 telescopeTimeValue: the telescope time value. + * @param telescopeTimeUnit: the telescope time unit. + * @param userType: the user type. * @param choices: the choices made. */ public OpticalTelescopeDataSave( String proposalID, String observationID, String telescopeName, + String instrumentName, String telescopeTimeValue, + String telescopeTimeUnit, String userType, HashMap choices) { - super(proposalID, observationID); + this.primaryKey = new OpticalTelescopeDataId(proposalID, observationID); this.telescopeName = telescopeName; + this.instrumentName = instrumentName; + this.telescopeTimeUnit = telescopeTimeUnit; + this.telescopeTimeValue = telescopeTimeValue; + this.userType = userType; + 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; + } + + public String getTelescopeTimeValue() { + return telescopeTimeValue; + } + + public void setTelescopeTimeValue(String telescopeTimeValue) { + this.telescopeTimeValue = telescopeTimeValue; + } + + public String getTelescopeTimeUnit() { + return telescopeTimeUnit; + } + + public void setTelescopeTimeUnit(String telescopeTimeUnit) { + this.telescopeTimeUnit = telescopeTimeUnit; + } + + public String getUserType() { + return userType; + } + + public void setUserType(String userType) { + this.userType = userType; + } } diff --git a/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataTableReturn.java b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataTableReturn.java new file mode 100644 index 0000000..a2cc1fe --- /dev/null +++ b/src/main/java/org/orph2020/pst/common/json/OpticalTelescopeDataTableReturn.java @@ -0,0 +1,42 @@ +package org.orph2020.pst.common.json; + +public class OpticalTelescopeDataTableReturn { + // the telescope name. + private String telescopeName; + + // the instrument name. + private String instrumentName; + + /** + * constructor for the telescope data for saving. + * + * @param telescopeName: the telescope name. + * @param instrumentName: the instrument name chosen for the choices. + */ + public OpticalTelescopeDataTableReturn( + String telescopeName, String instrumentName) { + this.telescopeName = telescopeName; + this.instrumentName = instrumentName; + } + + public OpticalTelescopeDataTableReturn() { + // No-argument constructor for Hibernate ORM + } + + + 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; + } +}