00001 package cedar.hepdata.model;
00002
00003 import java.util.*;
00004 import javax.persistence.*;
00005
00011 @Entity
00012 @Table(name="Papers")
00013 public class Paper extends Storeable {
00014 @Id @GeneratedValue
00015 @Column(name="PAPER_ID")
00017 private Long _id;
00018
00019
00020 @Column(name="SpiresId", unique=true, nullable=true)
00022 private Long _spiresId = null;
00023
00024
00025 @Column(name="RedId", unique=true, nullable=true)
00027 private Long _redId = null;
00028
00029
00030 @Column(name="Title", unique=false, nullable=true)
00032 private String _title = "";
00033
00034
00035 @org.hibernate.annotations.CollectionOfElements
00036 @JoinTable(name="PaperExpts", joinColumns=@JoinColumn(name="PAPER_ID"))
00037 @org.hibernate.annotations.CollectionId(columns=@Column(name="PaperExptId"), type=@org.hibernate.annotations.Type(type="long"), generator="sequence")
00038 @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00040 private SortedSet<Experiment> _experiments = new TreeSet<Experiment>();
00041
00042
00043 @org.hibernate.annotations.CollectionOfElements
00044 @JoinTable(name="PaperAuthors", joinColumns=@JoinColumn(name="PAPER_ID"))
00045 @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00046 @org.hibernate.annotations.BatchSize(size=2)
00048 private SortedSet<String> _authors = new TreeSet<String>();
00049
00050
00051 @org.hibernate.annotations.CollectionOfElements
00052 @JoinTable(name="PaperRefs", joinColumns=@JoinColumn(name="PAPER_ID"))
00053 @org.hibernate.annotations.CollectionId(columns=@Column(name="PaperRefId"), type=@org.hibernate.annotations.Type(type="long"), generator="sequence")
00054 @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00056 private SortedSet<Reference> _references = new TreeSet<Reference>();
00057
00058
00059 @org.hibernate.annotations.CollectionOfElements
00060 @JoinTable(name="PaperComments", joinColumns=@JoinColumn(name="PAPER_ID"))
00061 @org.hibernate.annotations.IndexColumn(name="Posn")
00062 @Column(length=10000)
00064 private List<String> _comments = new Vector<String>();
00065
00066
00067 @org.hibernate.annotations.CollectionOfElements
00068 @JoinTable(name="PaperMods", joinColumns=@JoinColumn(name="PAPER_ID"))
00069 @org.hibernate.annotations.CollectionId(columns=@Column(name="PaperModId"), type=@org.hibernate.annotations.Type(type="long"), generator="sequence")
00070 @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00071 @org.hibernate.annotations.BatchSize(size=2)
00073 private SortedSet<Modification> _modifications = new TreeSet<Modification>();
00074
00075
00076 @OneToMany(mappedBy="_paper")
00077 @org.hibernate.annotations.Fetch(value=org.hibernate.annotations.FetchMode.SUBSELECT)
00078 @org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
00079 @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00080 @org.hibernate.annotations.BatchSize(size=5)
00082 private SortedSet<Dataset> _datasets = new TreeSet<Dataset>();
00083
00084
00086
00087
00089 public Paper() {}
00090
00092 public Paper(String title) {
00093 setTitle(title);
00094 }
00095
00097 public Paper(String title, Long spiresId) {
00098 this(title);
00099 setSpiresId(spiresId);
00100 }
00101
00103 public Paper(String title, Integer spiresId) {
00104 this(title, new Long(spiresId));
00105 }
00106
00107
00109
00110
00112 public Long getSpiresId() {
00113 return _spiresId;
00114 }
00116 public Paper setSpiresId(Long spiresId) {
00117 _spiresId = spiresId;
00118 return this;
00119 }
00121 public Paper setSpiresId(Integer spiresId) {
00122 _spiresId = new Long(spiresId);
00123 return this;
00124 }
00125
00126
00128 public Long getRedId() {
00129 return _redId;
00130 }
00132 public Paper setRedId(Long redId) {
00133 _redId = redId;
00134 return this;
00135 }
00137 public Paper setRedId(Integer redId) {
00138 _redId = new Long(redId);
00139 return this;
00140 }
00141
00142
00143
00145 public String getTitle() {
00146 return _title;
00147 }
00149 public Paper setTitle(String title) {
00150 _title = title;
00151 return this;
00152 }
00153
00154
00155
00157 public SortedSet<Experiment> getExperiments() {
00158 return _experiments;
00159 }
00160
00162 public Paper setExperiments(SortedSet<Experiment> experiments) {
00163 _experiments = experiments;
00164 return this;
00165 }
00166
00168 public Paper addExperiment(Experiment experiment) {
00169 if (experiment != null) {
00170 _experiments.add(experiment);
00171 } else {
00172 log().warn("Tried to add a null experiment to a paper");
00173 }
00174 return this;
00175 }
00176
00178 public Paper removeExperiment(Experiment experiment) {
00179 if (experiment != null) {
00180 _experiments.remove(experiment);
00181 } else {
00182 log().warn("Tried to remove a null experiment from a paper");
00183 }
00184 return this;
00185 }
00186
00187
00188
00190 public SortedSet<String> getAuthors() {
00191 return _authors;
00192 }
00194 public Paper setAuthors(SortedSet<String> authors) {
00195 _authors = authors;
00196 return this;
00197 }
00199 public Paper addAuthor(String author) {
00200 if (author != null) {
00201 _authors.add(author);
00202 } else {
00203 log().warn("Tried to add a null author to a paper");
00204 }
00205 return this;
00206 }
00208 public Paper removeAuthor(String author) {
00209 if (author != null) {
00210 _authors.remove(author);
00211 } else {
00212 log().warn("Tried to remove a null author from a paper");
00213 }
00214 return this;
00215 }
00216
00217
00219 public List<String> getComments() {
00220 return _comments;
00221 }
00223 public Paper setComments(List<String> comments) {
00224 _comments = comments;
00225 return this;
00226 }
00228 public Paper addComment(String comment) {
00229 _comments.add(comment);
00230 return this;
00231 }
00232
00233
00234
00236 public SortedSet<Dataset> getDatasets() {
00237 return _datasets;
00238 }
00239
00241 public Dataset getDataset(Integer datasetId) {
00242 Dataset theDataset = null;
00243 for (Dataset d : getDatasets()) {
00244 if (d.getId().equals(datasetId)) {
00245 theDataset = d;
00246 break;
00247 }
00248 }
00249 return theDataset;
00250 }
00251
00253 public Paper setDatasets(SortedSet<Dataset> datasets) {
00254 getDatasets().clear();
00255 for (Dataset d : datasets) addDataset(d);
00256 return this;
00257 }
00258
00260 public Paper setDatasets(Collection<Dataset> datasets) {
00261 setDatasets(new TreeSet(datasets));
00262 return this;
00263 }
00264
00266 public Paper setDatasets(Dataset[] datasets) {
00267 setDatasets(Arrays.asList(datasets));
00268 return this;
00269 }
00270
00272 public Paper addDataset(Dataset dataset) {
00273 if (dataset != null) {
00274 dataset.setPaper(this);
00275 } else {
00276 log().warn("Tried to add null dataset to a paper");
00277 }
00278 return this;
00279 }
00280
00282 public Paper removeDataset(Dataset dataset) {
00283 if (dataset != null) {
00284 _datasets.remove(dataset);
00285 } else {
00286 log().warn("Tried to remove a null dataset from a paper");
00287 }
00288 return this;
00289 }
00290
00291
00293 public SortedSet<Modification> getModifications() {
00294 return _modifications;
00295 }
00296
00298 public Paper setModifications(SortedSet<Modification> modifications) {
00299 _modifications = modifications;
00300 return this;
00301 }
00302
00304 public Paper addModification(Modification modification) {
00305 _modifications.add(modification);
00306 return this;
00307 }
00308
00310 public Paper removeModification(Modification modification) {
00311 _modifications.remove(modification);
00312 return this;
00313 }
00314
00315
00316
00318 public SortedSet<Reference> getReferences() {
00319 return _references;
00320 }
00321
00323 public Paper setReferences(SortedSet<Reference> references) {
00324 _references = references;
00325 return this;
00326 }
00327
00329 public Paper addReference(Reference reference) {
00330 _references.add(reference);
00331 return this;
00332 }
00333
00335 public Paper removeReference(Reference reference) {
00336 _references.remove(reference);
00337 return this;
00338 }
00339
00340
00342
00343
00345 public String toString() {
00346 return toString(0);
00347 }
00348
00349
00351 public String toString(Integer indentBy) {
00352 StringBuffer s = new StringBuffer();
00353 String indent = "";
00354 for (int i = 0; i < indentBy; ++i) indent += " ";
00355
00356
00357 s.append(indent + "Title: ");
00358 if (getTitle() != null) {
00359 s.append(getTitle());
00360 } else {
00361 s.append("N/A");
00362 }
00363
00364
00365 s.append("\n" + indent + "Spires ID: " + getSpiresId());
00366 if (getRedId() != null) {
00367 s.append("\n" + indent + "Reaction database ID: " + getRedId());
00368 }
00369
00370
00371 s.append("\n" + indent + "Modifications: ");
00372 if (getModifications().size() == 0) {
00373 s.append("none");
00374 } else {
00375 for (Modification mod : getModifications()) {
00376 s.append("\n" + indent + mod.getTimestamp());
00377 s.append(" by " + mod.getModifier());
00378 if (mod.getComment() != null && mod.getComment().length() != 0)
00379 s.append(": " + mod.getComment());
00380 }
00381 }
00382
00383
00384 s.append("\n" + indent + "Comments: ");
00385 if (getComments().size() == 0) {
00386 s.append("none");
00387 } else {
00388 for (String c : getComments()) s.append("\n" + c);
00389 }
00390
00391
00392 if (!getDatasets().isEmpty()) {
00393 s.append("\n" + indent + getDatasets().size() + " Datasets");
00394 for (Dataset ds : getDatasets()) {
00395 s.append("\n" + ds.toString(indentBy + 2));
00396 }
00397 }
00398
00399 return s.toString();
00400 }
00401
00402
00404
00405
00407 public boolean equals(Object other) {
00408 if (this == other) return true;
00409 if (! (other instanceof Paper)) return false;
00410 return hashCode() == other.hashCode();
00411 }
00412
00414 public int hashCode() {
00415 int code = 37;
00416 if (getSpiresId() != null) code ^= getSpiresId().hashCode();
00417 if (getRedId() != null) code ^= getRedId().hashCode();
00418 if (getTitle() != null) code ^= getTitle().hashCode();
00419 for (Experiment e : getExperiments()) code ^= e.hashCode();
00420 for (String a : getAuthors()) code ^= a.hashCode();
00421 for (String c : getComments()) code ^= c.hashCode();
00422 for (Modification m : getModifications()) code ^= m.hashCode();
00423 for (Reference r : getReferences()) code ^= r.hashCode();
00424 return code;
00425 }
00426
00427 }