Mercurial > hg > LGDataverses
comparison src/main/java/edu/harvard/iq/dataverse/DatasetFieldValue.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 | |
| 7 package edu.harvard.iq.dataverse; | |
| 8 | |
| 9 import java.io.Serializable; | |
| 10 import java.util.Comparator; | |
| 11 import javax.persistence.Column; | |
| 12 import javax.persistence.Entity; | |
| 13 import javax.persistence.GeneratedValue; | |
| 14 import javax.persistence.GenerationType; | |
| 15 import javax.persistence.Id; | |
| 16 import javax.persistence.Index; | |
| 17 import javax.persistence.JoinColumn; | |
| 18 import javax.persistence.ManyToOne; | |
| 19 import javax.persistence.Table; | |
| 20 import javax.persistence.Transient; | |
| 21 | |
| 22 /** | |
| 23 * | |
| 24 * @author gdurand | |
| 25 */ | |
| 26 @Entity | |
| 27 @ValidateDatasetFieldType | |
| 28 @Table(indexes = {@Index(columnList="datasetfield_id")}) | |
| 29 public class DatasetFieldValue implements Serializable { | |
| 30 private static final long serialVersionUID = 1L; | |
| 31 | |
| 32 public static final Comparator<DatasetFieldValue> DisplayOrder = new Comparator<DatasetFieldValue>() { | |
| 33 @Override | |
| 34 public int compare(DatasetFieldValue o1, DatasetFieldValue o2) { | |
| 35 return Integer.compare( o1.getDisplayOrder(), | |
| 36 o2.getDisplayOrder() ); | |
| 37 }}; | |
| 38 | |
| 39 public DatasetFieldValue() { | |
| 40 } | |
| 41 | |
| 42 public DatasetFieldValue(DatasetField aField) { | |
| 43 setDatasetField(aField); | |
| 44 } | |
| 45 | |
| 46 public DatasetFieldValue(DatasetField aField, String aValue) { | |
| 47 setDatasetField(aField); | |
| 48 value = aValue; | |
| 49 } | |
| 50 | |
| 51 @Id | |
| 52 @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| 53 private Long id; | |
| 54 | |
| 55 @Column(name = "value", columnDefinition = "TEXT", nullable = false) | |
| 56 private String value; | |
| 57 private int displayOrder; | |
| 58 | |
| 59 @ManyToOne | |
| 60 @JoinColumn(nullable=false) | |
| 61 private DatasetField datasetField; | |
| 62 | |
| 63 public Long getId() { | |
| 64 return id; | |
| 65 } | |
| 66 | |
| 67 public void setId(Long id) { | |
| 68 this.id = id; | |
| 69 } | |
| 70 | |
| 71 public String getValue() { | |
| 72 return value; | |
| 73 } | |
| 74 | |
| 75 public void setValue(String value) { | |
| 76 this.value = value; | |
| 77 } | |
| 78 | |
| 79 // these methods wrap around value but do not display the N/A value | |
| 80 // (forcing validation) | |
| 81 public String getValueForEdit() { | |
| 82 return DatasetField.NA_VALUE.equals(value) ? "" : value; | |
| 83 } | |
| 84 | |
| 85 public void setValueForEdit(String value) { | |
| 86 this.value = value; | |
| 87 } | |
| 88 | |
| 89 public int getDisplayOrder() { | |
| 90 return displayOrder; | |
| 91 } | |
| 92 | |
| 93 public void setDisplayOrder(int displayOrder) { | |
| 94 this.displayOrder = displayOrder; | |
| 95 } | |
| 96 | |
| 97 public DatasetField getDatasetField() { | |
| 98 return datasetField; | |
| 99 } | |
| 100 | |
| 101 public void setDatasetField(DatasetField datasetField) { | |
| 102 this.datasetField = datasetField; | |
| 103 } | |
| 104 | |
| 105 @Transient private String validationMessage; | |
| 106 | |
| 107 public String getValidationMessage() { | |
| 108 return validationMessage; | |
| 109 } | |
| 110 | |
| 111 public void setValidationMessage(String validationMessage) { | |
| 112 this.validationMessage = validationMessage; | |
| 113 } | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 @Override | |
| 119 public int hashCode() { | |
| 120 int hash = 0; | |
| 121 hash += (id != null ? id.hashCode() : 0); | |
| 122 return hash; | |
| 123 } | |
| 124 | |
| 125 @Override | |
| 126 public boolean equals(Object object) { | |
| 127 // TODO: Warning - this method won't work in the case the id fields are not set | |
| 128 if (!(object instanceof DatasetFieldValue)) { | |
| 129 return false; | |
| 130 } | |
| 131 DatasetFieldValue other = (DatasetFieldValue) object; | |
| 132 if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { | |
| 133 return false; | |
| 134 } | |
| 135 return true; | |
| 136 } | |
| 137 | |
| 138 @Override | |
| 139 public String toString() { | |
| 140 return "edu.harvard.iq.dataverse.DatasetFieldValueValue[ id=" + id + " ]"; | |
| 141 } | |
| 142 | |
| 143 public DatasetFieldValue copy(DatasetField dsf) { | |
| 144 DatasetFieldValue dsfv = new DatasetFieldValue(); | |
| 145 dsfv.setDatasetField(dsf); | |
| 146 dsfv.setDisplayOrder(displayOrder); | |
| 147 dsfv.setValue(value); | |
| 148 | |
| 149 return dsfv; | |
| 150 } | |
| 151 | |
| 152 } |
