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 {
00015 @Id @GeneratedValue
00016 @Column(name="PAPER_ID")
00017 private Long _id;
00018
00019
00021 @Column(name="SpiresId", unique=true, nullable=true)
00022 private Long _spiresId = null;
00023
00024
00026 @Column(name="RedId", unique=true, nullable=true)
00027 private Long _redId = null;
00028
00029
00031 @Column(name="Title", unique=false, nullable=true)
00032 private String _title = "";
00033
00034
00036 @org.hibernate.annotations.CollectionOfElements
00037 @JoinTable(name="PaperExpts", joinColumns=@JoinColumn(name="PAPER_ID"))
00038 @org.hibernate.annotations.CollectionId(columns=@Column(name="PaperExptId"), type=@org.hibernate.annotations.Type(type="long"), generator="sequence")
00039 @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00040 private SortedSet<Experiment> _experiments = new TreeSet<Experiment>();
00041
00042
00044 @org.hibernate.annotations.CollectionOfElements
00045 @JoinTable(name="PaperAuthors", joinColumns=@JoinColumn(name="PAPER_ID"))
00046 @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00047 @org.hibernate.annotations.BatchSize(size=2)
00048 private SortedSet<String> _authors = new TreeSet<String>();
00049
00050
00052 @org.hibernate.annotations.CollectionOfElements
00053 @JoinTable(name="PaperRefs", joinColumns=@JoinColumn(name="PAPER_ID"))
00054 @org.hibernate.annotations.CollectionId(columns=@Column(name="PaperRefId"), type=@org.hibernate.annotations.Type(type="long"), generator="sequence")
00055 @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00056 private SortedSet<Reference> _references = new TreeSet<Reference>();
00057
00058
00060 @org.hibernate.annotations.CollectionOfElements
00061 @JoinTable(name="PaperComments", joinColumns=@JoinColumn(name="PAPER_ID"))
00062 @org.hibernate.annotations.IndexColumn(name="Posn")
00063 @Column(length=10000)
00064 private List<String> _comments = new Vector<String>();
00065
00066
00068 @org.hibernate.annotations.CollectionOfElements
00069 @JoinTable(name="PaperMods", joinColumns=@JoinColumn(name="PAPER_ID"))
00070 @org.hibernate.annotations.CollectionId(columns=@Column(name="PaperModId"), type=@org.hibernate.annotations.Type(type="long"), generator="sequence")
00071 @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00072 @org.hibernate.annotations.BatchSize(size=2)
00073 private SortedSet<Modification> _modifications = new TreeSet<Modification>();
00074
00075
00077 @OneToMany(mappedBy="_paper")
00078 @org.hibernate.annotations.Fetch(value=org.hibernate.annotations.FetchMode.SUBSELECT)
00079 @org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
00080 @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00081 @org.hibernate.annotations.BatchSize(size=5)
00082 private SortedSet<Dataset> _datasets = new TreeSet<Dataset>();
00083
00084
00086
00087
00089 public Paper() {}
00090
00091 public Paper(String title) {
00092 setTitle(title);
00093 }
00094
00095 public Paper(String title, Long spiresId) {
00096 this(title);
00097 setSpiresId(spiresId);
00098 }
00099
00100 public Paper(String title, Integer spiresId) {
00101 this(title, new Long(spiresId));
00102 }
00103
00104
00106
00107
00109 public Long getSpiresId() {
00110 return _spiresId;
00111 }
00113 public Paper setSpiresId(Long spiresId) {
00114 _spiresId = spiresId;
00115 return this;
00116 }
00118 public Paper setSpiresId(Integer spiresId) {
00119 _spiresId = new Long(spiresId);
00120 return this;
00121 }
00122
00123
00125 public Long getRedId() {
00126 return _redId;
00127 }
00129 public Paper setRedId(Long redId) {
00130 _redId = redId;
00131 return this;
00132 }
00134 public Paper setRedId(Integer redId) {
00135 _redId = new Long(redId);
00136 return this;
00137 }
00138
00139
00140
00142 public String getTitle() {
00143 return _title;
00144 }
00146 public Paper setTitle(String title) {
00147 _title = title;
00148 return this;
00149 }
00150
00151
00152
00154 public SortedSet<Experiment> getExperiments() {
00155 return _experiments;
00156 }
00157
00159 public Paper setExperiments(SortedSet<Experiment> experiments) {
00160 _experiments = experiments;
00161 return this;
00162 }
00163
00165 public Paper addExperiment(Experiment experiment) {
00166 if (experiment != null) {
00167 _experiments.add(experiment);
00168 } else {
00169 log().warn("Tried to add a null experiment to a paper");
00170 }
00171 return this;
00172 }
00173
00175 public Paper removeExperiment(Experiment experiment) {
00176 if (experiment != null) {
00177 _experiments.remove(experiment);
00178 } else {
00179 log().warn("Tried to remove a null experiment from a paper");
00180 }
00181 return this;
00182 }
00183
00184
00185
00186
00187 public SortedSet<String> getAuthors() {
00188 return _authors;
00189 }
00190 public Paper setAuthors(SortedSet<String> authors) {
00191 _authors = authors;
00192 return this;
00193 }
00194 public Paper addAuthor(String author) {
00195 if (author != null) {
00196 _authors.add(author);
00197 } else {
00198 log().warn("Tried to add a null author to a paper");
00199 }
00200 return this;
00201 }
00202 public Paper removeAuthor(String author) {
00203 if (author != null) {
00204 _authors.remove(author);
00205 } else {
00206 log().warn("Tried to remove a null author from a paper");
00207 }
00208 return this;
00209 }
00210
00211
00213 public List<String> getComments() {
00214 return _comments;
00215 }
00217 public Paper setComments(List<String> comments) {
00218 _comments = comments;
00219 return this;
00220 }
00222 public Paper addComment(String comment) {
00223 _comments.add(comment);
00224 return this;
00225 }
00226
00227
00228
00230 public SortedSet<Dataset> getDatasets() {
00231 return _datasets;
00232 }
00233
00235 public Dataset getDataset(Integer datasetId) {
00236 Dataset theDataset = null;
00237 for (Dataset d : getDatasets()) {
00238 if (d.getId().equals(datasetId)) {
00239 theDataset = d;
00240 break;
00241 }
00242 }
00243 return theDataset;
00244 }
00245
00247 public Paper setDatasets(SortedSet<Dataset> datasets) {
00249 _datasets = datasets;
00250 return this;
00251 }
00252
00254 public Paper setDatasets(Collection<Dataset> datasets) {
00255 setDatasets(new TreeSet(datasets));
00256 return this;
00257 }
00258
00260 public Paper setDatasets(Dataset[] datasets) {
00261 setDatasets(Arrays.asList(datasets));
00262 return this;
00263 }
00264
00266 public Paper addDataset(Dataset dataset) {
00267 if (dataset != null) {
00268 if (dataset.getId() == null) {
00269 int highestId = 0;
00270 if (getDatasets().size() > 0) {
00271 highestId = getDatasets().last().getId();
00272 }
00273 log().debug("Incrementing dataset ID: " + (highestId + 1));
00274 dataset.setId(highestId + 1);
00275 }
00276 log().debug("Adding dataset: ID = " + dataset.getId());
00277 dataset.setPaper(this);
00278 _datasets.add(dataset);
00279 } else {
00280 log().warn("Tried to add null dataset to a paper");
00281 }
00282 return this;
00283 }
00284
00286 public Paper removeDataset(Dataset dataset) {
00287 if (dataset != null) {
00288 dataset.setPaper(null);
00289 _datasets.remove(dataset);
00290 } else {
00291 log().warn("Tried to remove a null dataset from a paper");
00292 }
00293 return this;
00294 }
00295
00296
00298 public SortedSet<Modification> getModifications() {
00299 return _modifications;
00300 }
00301
00303 public Paper setModifications(SortedSet<Modification> modifications) {
00304 _modifications = modifications;
00305 return this;
00306 }
00307
00309 public Paper addModification(Modification modification) {
00310 _modifications.add(modification);
00311 return this;
00312 }
00313
00315 public Paper removeModification(Modification modification) {
00316 _modifications.remove(modification);
00317 return this;
00318 }
00319
00320
00321
00323 public SortedSet<Reference> getReferences() {
00324 return _references;
00325 }
00326
00328 public Paper setReferences(SortedSet<Reference> references) {
00329 _references = references;
00330 return this;
00331 }
00332
00334 public Paper addReference(Reference reference) {
00335 _references.add(reference);
00336 return this;
00337 }
00338
00340 public Paper removeReference(Reference reference) {
00341 _references.remove(reference);
00342 return this;
00343 }
00344
00345
00347
00348
00350 public String toString() {
00351 return toString(0);
00352 }
00353
00354
00356 public String toString(Integer indentBy) {
00357 StringBuffer s = new StringBuffer();
00358 String indent = "";
00359 for (int i = 0; i < indentBy; ++i) indent += " ";
00360
00361
00362 s.append(indent + "Title: ");
00363 if (getTitle() != null) {
00364 s.append(getTitle());
00365 } else {
00366 s.append("N/A");
00367 }
00368
00369
00370 s.append("\n" + indent + "Spires ID: " + getSpiresId());
00371 if (getRedId() != null) {
00372 s.append("\n" + indent + "Reaction database ID: " + getRedId());
00373 }
00374
00375
00376 s.append("\n" + indent + "Modifications: ");
00377 if (getModifications().size() == 0) {
00378 s.append("none");
00379 } else {
00380 for (Modification mod : getModifications()) {
00381 s.append("\n" + indent + mod.getTimestamp());
00382 s.append(" by " + mod.getModifier());
00383 if (mod.getComment() != null && mod.getComment().length() != 0)
00384 s.append(": " + mod.getComment());
00385 }
00386 }
00387
00388
00389 s.append("\n" + indent + "Comments: ");
00390 if (getComments().size() == 0) {
00391 s.append("none");
00392 } else {
00393 for (String c : getComments()) s.append("\n" + c);
00394 }
00395
00396
00397 if (!getDatasets().isEmpty()) {
00398 s.append("\n" + indent + getDatasets().size() + " Datasets");
00399 for (Dataset ds : getDatasets()) {
00400 s.append("\n" + ds.toString(indentBy + 2));
00401 }
00402 }
00403
00404 return s.toString();
00405 }
00406 }