From cf8333cdfc9a597bf0ac36ce4108267ecdfd395b Mon Sep 17 00:00:00 2001 From: Victoria Lubitch Date: Fri, 15 Feb 2019 12:18:54 -0500 Subject: [PATCH 1/2] Added wfreq - weighted frequency --- .../iq/dataverse/datavariable/VariableMetadata.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/edu/harvard/iq/dataverse/datavariable/VariableMetadata.java b/src/main/java/edu/harvard/iq/dataverse/datavariable/VariableMetadata.java index aef4a68cb4a..78d6960a9a8 100644 --- a/src/main/java/edu/harvard/iq/dataverse/datavariable/VariableMetadata.java +++ b/src/main/java/edu/harvard/iq/dataverse/datavariable/VariableMetadata.java @@ -78,6 +78,11 @@ public class VariableMetadata implements Serializable { */ private boolean weighted = false; + /** + * wfreq: Weighted frequency for weigted variable + */ + private Double wfreq; + /** * dataVariable: DataVariable with which this variable is weighted. */ @@ -175,6 +180,14 @@ public boolean isWeighted() { return weighted; } + public Double getWfreq() { + return wfreq; + } + + public void setWfreq(Double wfreq) { + this.wfreq = wfreq; + } + @Override public int hashCode() { int hash = 0; From 7d62a2c03270b70b506b2fa003f5fb2c49704daa Mon Sep 17 00:00:00 2001 From: Victoria Lubitch Date: Tue, 19 Feb 2019 14:12:50 -0500 Subject: [PATCH 2/2] Add CategoryMetadata instead wfreq --- .../datavariable/CategoryMetadata.java | 88 +++++++++++++++++++ .../datavariable/VariableMetadata.java | 18 ++-- 2 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 src/main/java/edu/harvard/iq/dataverse/datavariable/CategoryMetadata.java diff --git a/src/main/java/edu/harvard/iq/dataverse/datavariable/CategoryMetadata.java b/src/main/java/edu/harvard/iq/dataverse/datavariable/CategoryMetadata.java new file mode 100644 index 00000000000..0729aaabed9 --- /dev/null +++ b/src/main/java/edu/harvard/iq/dataverse/datavariable/CategoryMetadata.java @@ -0,0 +1,88 @@ +package edu.harvard.iq.dataverse.datavariable; + +import javax.persistence.Index; +import javax.persistence.Entity; +import javax.persistence.Table; +import javax.persistence.GenerationType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.JoinColumn; + +@Entity +@Table(indexes = {@Index(columnList="category_id"), @Index(columnList="variablemetadata_id")}) +public class CategoryMetadata { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + Long id; + + @ManyToOne + @JoinColumn(nullable=false) + VariableCategory category; + + @ManyToOne + @JoinColumn(nullable=false) + private VariableMetadata variableMetadata; + + Double wfreq; + + public CategoryMetadata() {} + + public CategoryMetadata(VariableMetadata variableMetadata) { + this.variableMetadata = variableMetadata; + } + + public Double getWfreq() { + return wfreq; + } + + public void setWfreq(Double wfreq) { + this.wfreq = wfreq; + } + + public VariableCategory getCategory() { + return category; + } + + public void setCategory(VariableCategory category) { + this.category = category; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public void setVariableMetadata(VariableMetadata variableMetadata) { + this.variableMetadata = variableMetadata; + } + + public VariableMetadata getVariableMetadata() { + return variableMetadata; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (this.id != null ? this.id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof CategoryMetadata)) { + return false; + } + + CategoryMetadata other = (CategoryMetadata) object; + if (this.id != other.id ) { + if (this.id == null || !this.id.equals(other.id)) { + return false; + } + } + return true; + } +} diff --git a/src/main/java/edu/harvard/iq/dataverse/datavariable/VariableMetadata.java b/src/main/java/edu/harvard/iq/dataverse/datavariable/VariableMetadata.java index 78d6960a9a8..6a5bab39109 100644 --- a/src/main/java/edu/harvard/iq/dataverse/datavariable/VariableMetadata.java +++ b/src/main/java/edu/harvard/iq/dataverse/datavariable/VariableMetadata.java @@ -12,6 +12,11 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Column; +import javax.persistence.OneToMany; +import javax.persistence.CascadeType; + +import java.util.Collection; +import java.util.Set; import edu.harvard.iq.dataverse.FileMetadata; @@ -79,9 +84,10 @@ public class VariableMetadata implements Serializable { private boolean weighted = false; /** - * wfreq: Weighted frequency for weigted variable + * categoriesMetadata: variable metadata for categories that includes weighted frequencies */ - private Double wfreq; + @OneToMany (mappedBy="VariableMetadata", cascade={ CascadeType.REMOVE, CascadeType.MERGE,CascadeType.PERSIST}) + private Collection categoriesMetadata; /** * dataVariable: DataVariable with which this variable is weighted. @@ -180,12 +186,12 @@ public boolean isWeighted() { return weighted; } - public Double getWfreq() { - return wfreq; + public Collection getWfreq() { + return categoriesMetadata; } - public void setWfreq(Double wfreq) { - this.wfreq = wfreq; + public void setWfreq(Set categoriesMetadata) { + this.categoriesMetadata = categoriesMetadata; } @Override