Mercurial > hg > LGDataverses
comparison src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java @ 10:a50cf11e5178
Rewrite LGDataverse completely upgrading to dataverse4.0
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Tue, 08 Sep 2015 17:00:21 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 9:5926d6419569 | 10:a50cf11e5178 |
|---|---|
| 1 /* | |
| 2 * To change this license header, choose License Headers in Project Properties. | |
| 3 * To change this template file, choose Tools | Templates | |
| 4 * and open the template in the editor. | |
| 5 */ | |
| 6 package edu.harvard.iq.dataverse; | |
| 7 | |
| 8 import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; | |
| 9 import java.io.Serializable; | |
| 10 import java.sql.Timestamp; | |
| 11 import java.text.SimpleDateFormat; | |
| 12 import java.util.ArrayList; | |
| 13 import java.util.Date; | |
| 14 import java.util.List; | |
| 15 import javax.persistence.*; | |
| 16 | |
| 17 /** | |
| 18 * | |
| 19 * @author skraffmiller | |
| 20 */ | |
| 21 @Entity | |
| 22 @Table(indexes = { | |
| 23 @Index(columnList = "guestbook_id"), | |
| 24 @Index(columnList = "datafile_id"), | |
| 25 @Index(columnList = "dataset_id") | |
| 26 }) | |
| 27 public class GuestbookResponse implements Serializable { | |
| 28 private static final long serialVersionUID = 1L; | |
| 29 @Id | |
| 30 @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| 31 private Long id; | |
| 32 | |
| 33 @ManyToOne | |
| 34 @JoinColumn(nullable=false) | |
| 35 private Guestbook guestbook; | |
| 36 | |
| 37 @ManyToOne | |
| 38 @JoinColumn(nullable=false) | |
| 39 private DataFile dataFile; | |
| 40 | |
| 41 @ManyToOne | |
| 42 @JoinColumn(nullable=false) | |
| 43 private Dataset dataset; | |
| 44 | |
| 45 @ManyToOne | |
| 46 @JoinColumn(nullable=true) | |
| 47 private DatasetVersion datasetVersion; | |
| 48 | |
| 49 @ManyToOne | |
| 50 @JoinColumn(nullable=true) | |
| 51 private AuthenticatedUser authenticatedUser; | |
| 52 | |
| 53 @OneToMany(mappedBy="guestbookResponse",cascade={CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST},orphanRemoval=true) | |
| 54 @OrderBy ("id") | |
| 55 private List<CustomQuestionResponse> customQuestionResponses; | |
| 56 | |
| 57 | |
| 58 private String name; | |
| 59 private String email; | |
| 60 private String institution; | |
| 61 private String position; | |
| 62 private String downloadtype; | |
| 63 private String sessionId; | |
| 64 | |
| 65 @Temporal(value = TemporalType.TIMESTAMP) | |
| 66 private Date responseTime; | |
| 67 | |
| 68 public GuestbookResponse(){ | |
| 69 | |
| 70 } | |
| 71 | |
| 72 public GuestbookResponse(GuestbookResponse source){ | |
| 73 //makes a clone of a response for adding of studyfiles in case of multiple downloads | |
| 74 this.setName(source.getName()); | |
| 75 this.setEmail(source.getEmail()); | |
| 76 this.setInstitution(source.getInstitution()); | |
| 77 this.setPosition(source.getPosition()); | |
| 78 this.setResponseTime(source.getResponseTime()); | |
| 79 this.setDataset(source.getDataset()); | |
| 80 this.setDatasetVersion(source.getDatasetVersion()); | |
| 81 this.setAuthenticatedUser(source.getAuthenticatedUser()); | |
| 82 this.setSessionId(source.getSessionId()); | |
| 83 List <CustomQuestionResponse> customQuestionResponses = new ArrayList(); | |
| 84 if (!source.getCustomQuestionResponses().isEmpty()){ | |
| 85 for (CustomQuestionResponse customQuestionResponse : source.getCustomQuestionResponses() ){ | |
| 86 CustomQuestionResponse customQuestionResponseAdd = new CustomQuestionResponse(); | |
| 87 customQuestionResponseAdd.setResponse(customQuestionResponse.getResponse()); | |
| 88 customQuestionResponseAdd.setCustomQuestion(customQuestionResponse.getCustomQuestion()); | |
| 89 customQuestionResponseAdd.setGuestbookResponse(this); | |
| 90 customQuestionResponses.add(customQuestionResponseAdd); | |
| 91 } | |
| 92 } | |
| 93 this.setCustomQuestionResponses(customQuestionResponses); | |
| 94 this.setGuestbook(source.getGuestbook()); | |
| 95 } | |
| 96 | |
| 97 | |
| 98 public String getEmail() { | |
| 99 return email; | |
| 100 } | |
| 101 | |
| 102 public void setEmail(String email) { | |
| 103 this.email = email; | |
| 104 } | |
| 105 | |
| 106 public Guestbook getGuestbook() { | |
| 107 return guestbook; | |
| 108 } | |
| 109 | |
| 110 public void setGuestbook(Guestbook guestbook) { | |
| 111 this.guestbook = guestbook; | |
| 112 } | |
| 113 | |
| 114 public String getInstitution() { | |
| 115 return institution; | |
| 116 } | |
| 117 | |
| 118 public void setInstitution(String institution) { | |
| 119 this.institution = institution; | |
| 120 } | |
| 121 | |
| 122 public String getName() { | |
| 123 return name; | |
| 124 } | |
| 125 | |
| 126 public void setName(String name) { | |
| 127 this.name = name; | |
| 128 } | |
| 129 | |
| 130 public String getPosition() { | |
| 131 return position; | |
| 132 } | |
| 133 | |
| 134 public void setPosition(String position) { | |
| 135 this.position = position; | |
| 136 } | |
| 137 | |
| 138 public Long getId() { | |
| 139 return id; | |
| 140 } | |
| 141 | |
| 142 public void setId(Long id) { | |
| 143 this.id = id; | |
| 144 } | |
| 145 | |
| 146 public Date getResponseTime() { | |
| 147 return responseTime; | |
| 148 } | |
| 149 | |
| 150 public void setResponseTime(Date responseTime) { | |
| 151 this.responseTime = responseTime; | |
| 152 } | |
| 153 | |
| 154 public String getResponseDateForDisplay(){ | |
| 155 return null; // SimpleDateFormat("yyyy").format(new Timestamp(new Date().getTime())); | |
| 156 } | |
| 157 | |
| 158 | |
| 159 public List<CustomQuestionResponse> getCustomQuestionResponses() { | |
| 160 return customQuestionResponses; | |
| 161 } | |
| 162 | |
| 163 public void setCustomQuestionResponses(List<CustomQuestionResponse> customQuestionResponses) { | |
| 164 this.customQuestionResponses = customQuestionResponses; | |
| 165 } | |
| 166 | |
| 167 public Dataset getDataset() { | |
| 168 return dataset; | |
| 169 } | |
| 170 | |
| 171 public void setDataset(Dataset dataset) { | |
| 172 this.dataset = dataset; | |
| 173 } | |
| 174 | |
| 175 public DataFile getDataFile() { | |
| 176 return dataFile; | |
| 177 } | |
| 178 | |
| 179 public void setDataFile(DataFile dataFile) { | |
| 180 this.dataFile = dataFile; | |
| 181 } | |
| 182 | |
| 183 public DatasetVersion getDatasetVersion() { | |
| 184 return datasetVersion; | |
| 185 } | |
| 186 | |
| 187 public void setDatasetVersion(DatasetVersion datasetVersion) { | |
| 188 this.datasetVersion = datasetVersion; | |
| 189 } | |
| 190 | |
| 191 public AuthenticatedUser getAuthenticatedUser() { | |
| 192 return authenticatedUser; | |
| 193 } | |
| 194 | |
| 195 public void setAuthenticatedUser(AuthenticatedUser authenticatedUser) { | |
| 196 this.authenticatedUser = authenticatedUser; | |
| 197 } | |
| 198 | |
| 199 public String getDownloadtype() { | |
| 200 return downloadtype; | |
| 201 } | |
| 202 | |
| 203 public void setDownloadtype(String downloadtype) { | |
| 204 this.downloadtype = downloadtype; | |
| 205 } | |
| 206 | |
| 207 public String getSessionId() { | |
| 208 return sessionId; | |
| 209 } | |
| 210 | |
| 211 public void setSessionId(String sessionId) { | |
| 212 this.sessionId = sessionId; | |
| 213 } | |
| 214 | |
| 215 @Override | |
| 216 public int hashCode() { | |
| 217 int hash = 0; | |
| 218 hash += (id != null ? id.hashCode() : 0); | |
| 219 return hash; | |
| 220 } | |
| 221 | |
| 222 @Override | |
| 223 public boolean equals(Object object) { | |
| 224 // TODO: Warning - this method won't work in the case the id fields are not set | |
| 225 if (!(object instanceof GuestbookResponse)) { | |
| 226 return false; | |
| 227 } | |
| 228 GuestbookResponse other = (GuestbookResponse) object; | |
| 229 if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { | |
| 230 return false; | |
| 231 } | |
| 232 return true; | |
| 233 } | |
| 234 | |
| 235 @Override | |
| 236 public String toString() { | |
| 237 return "edu.harvard.iq.dvn.core.vdc.GuestBookResponse[ id=" + id + " ]"; | |
| 238 } | |
| 239 | |
| 240 } | |
| 241 |
