Mercurial > hg > LGDataverses
comparison src/main/java/edu/harvard/iq/dataverse/ControlledVocabularyValue.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.ArrayList; | |
| 11 import java.util.Collection; | |
| 12 import java.util.Comparator; | |
| 13 import java.util.Objects; | |
| 14 import javax.persistence.CascadeType; | |
| 15 import javax.persistence.Column; | |
| 16 import javax.persistence.Entity; | |
| 17 import javax.persistence.GeneratedValue; | |
| 18 import javax.persistence.GenerationType; | |
| 19 import javax.persistence.Id; | |
| 20 import javax.persistence.JoinColumn; | |
| 21 import javax.persistence.ManyToOne; | |
| 22 import javax.persistence.OneToMany; | |
| 23 | |
| 24 /** | |
| 25 * | |
| 26 * @author skraffmiller | |
| 27 */ | |
| 28 @Entity | |
| 29 public class ControlledVocabularyValue implements Serializable { | |
| 30 | |
| 31 public static final Comparator<ControlledVocabularyValue> DisplayOrder = new Comparator<ControlledVocabularyValue>() { | |
| 32 @Override | |
| 33 public int compare(ControlledVocabularyValue o1, ControlledVocabularyValue o2) { | |
| 34 return Integer.compare( o1.getDisplayOrder(), o2.getDisplayOrder() ); | |
| 35 }}; | |
| 36 | |
| 37 public ControlledVocabularyValue() { | |
| 38 } | |
| 39 | |
| 40 public ControlledVocabularyValue(Long id, String strValue, DatasetFieldType datasetFieldType) { | |
| 41 this.id = id; | |
| 42 this.strValue = strValue; | |
| 43 this.datasetFieldType = datasetFieldType; | |
| 44 } | |
| 45 | |
| 46 @Id | |
| 47 @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| 48 private Long id; | |
| 49 | |
| 50 public Long getId() { | |
| 51 return this.id; | |
| 52 } | |
| 53 | |
| 54 public void setId(Long id) { | |
| 55 this.id = id; | |
| 56 } | |
| 57 | |
| 58 @Column(columnDefinition="TEXT", nullable=false) | |
| 59 private String strValue; | |
| 60 | |
| 61 public String getStrValue() { | |
| 62 return strValue; | |
| 63 } | |
| 64 public void setStrValue(String strValue) { | |
| 65 this.strValue = strValue; | |
| 66 | |
| 67 } | |
| 68 | |
| 69 private String identifier; | |
| 70 | |
| 71 public String getIdentifier() { | |
| 72 return identifier; | |
| 73 } | |
| 74 | |
| 75 public void setIdentifier(String identifier) { | |
| 76 this.identifier = identifier; | |
| 77 } | |
| 78 | |
| 79 | |
| 80 | |
| 81 private int displayOrder; | |
| 82 public int getDisplayOrder() { return this.displayOrder;} | |
| 83 public void setDisplayOrder(int displayOrder) {this.displayOrder = displayOrder;} | |
| 84 | |
| 85 | |
| 86 @ManyToOne | |
| 87 // @JoinColumn( nullable = false ) TODO this breaks for the N/A value. need to create an N/A type for that value. | |
| 88 private DatasetFieldType datasetFieldType; | |
| 89 public DatasetFieldType getDatasetFieldType() { | |
| 90 return datasetFieldType; | |
| 91 } | |
| 92 public void setDatasetFieldType(DatasetFieldType datasetFieldType) { | |
| 93 this.datasetFieldType = datasetFieldType; | |
| 94 } | |
| 95 | |
| 96 @OneToMany(mappedBy = "controlledVocabularyValue", cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST}) | |
| 97 private Collection<ControlledVocabAlternate> controlledVocabAlternates = new ArrayList<>(); | |
| 98 | |
| 99 public Collection<ControlledVocabAlternate> getControlledVocabAlternates() { | |
| 100 return controlledVocabAlternates; | |
| 101 } | |
| 102 | |
| 103 public void setControlledVocabAlternates(Collection<ControlledVocabAlternate> controlledVocabAlternates) { | |
| 104 this.controlledVocabAlternates = controlledVocabAlternates; | |
| 105 } | |
| 106 | |
| 107 | |
| 108 @Override | |
| 109 public int hashCode() { | |
| 110 int hash = 0; | |
| 111 hash += (this.id != null ? this.id.hashCode() : 0); | |
| 112 return hash; | |
| 113 } | |
| 114 | |
| 115 @Override | |
| 116 public boolean equals(Object object) { | |
| 117 if (!(object instanceof ControlledVocabularyValue)) { | |
| 118 return false; | |
| 119 } | |
| 120 ControlledVocabularyValue other = (ControlledVocabularyValue) object; | |
| 121 return Objects.equals(getId(), other.getId()); | |
| 122 } | |
| 123 | |
| 124 @Override | |
| 125 public String toString() { | |
| 126 return "edu.harvard.iq.dataverse.ControlledVocabularyValue[ id=" + id + " ]"; | |
| 127 } | |
| 128 | |
| 129 } |
