<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.harvard.iq.dataverse;

/**
 *
 * @author skraffmiller
 */
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;


@Entity
public class DatasetFieldValue implements Serializable,   Comparable<DatasetFieldValue> {

    public DatasetFieldValue () {
    }
    
    public DatasetFieldValue(DatasetField sf, DatasetVersion dsv, String val) {
        setDatasetField(sf);
        setDatasetVersion(dsv);
        setStrValue(val);    
    }    
    
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    
    @ManyToOne
    @JoinColumn(nullable=false)
    private DatasetField datasetField;
    public DatasetField getDatasetField() {
        return datasetField;
    }
    public void setDatasetField(DatasetField datasetField) {
        this.datasetField = datasetField;
    }
    
    @ManyToOne
    @JoinColumn(nullable=false)
    private DatasetVersion datasetVersion;
    public DatasetVersion getDatasetVersion() {
        return datasetVersion;
    }
    public void setDatasetVersion(DatasetVersion datasetVersion) {
        this.datasetVersion = datasetVersion;
    }
    

    @OneToMany(mappedBy = "parentDatasetFieldValue", cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST})
    @OrderBy("displayOrder ASC")
    private List<DatasetFieldValue> childDatasetFieldValues= new ArrayList();

    public List<DatasetFieldValue> getChildDatasetFieldValues() {
        if (this.childDatasetFieldValues != null) {
            Collections.sort(this.childDatasetFieldValues, new Comparator<DatasetFieldValue>() {
                public int compare(DatasetFieldValue d1, DatasetFieldValue d2) {
                    int a = d1.getDatasetField().getDisplayOrder();
                    int b = d2.getDatasetField().getDisplayOrder();
                    return Integer.valueOf(a).compareTo(Integer.valueOf(b));
                }
            });
        }
        return this.childDatasetFieldValues;
    }
    public void setChildDatasetFieldValues(List<DatasetFieldValue> childDatasetFieldValues) {
        this.childDatasetFieldValues = childDatasetFieldValues;
    }
    
    public boolean isChildEmpty(){
        //check all child values for empty...        
        for (DatasetFieldValue dsfvc: this.childDatasetFieldValues){
            if(dsfvc.getStrValue()!= null && !dsfvc.getStrValue().isEmpty()){
                return false;
            }
        }
        return true;
    }
    
    @ManyToOne(cascade = CascadeType.MERGE)
    private DatasetFieldValue parentDatasetFieldValue;
    public DatasetFieldValue getParentDatasetFieldValue() {
        return parentDatasetFieldValue;
    }
    public void setParentDatasetFieldValue(DatasetFieldValue parentDatasetFieldValue) {
        this.parentDatasetFieldValue = parentDatasetFieldValue;
    }
    
    @Column(columnDefinition="TEXT") 
    private String strValue;

    public String getStrValue() {
        return strValue;
    }

    public void setStrValue(String strValue) {
        this.strValue = strValue;
        
    }    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DatasetFieldValue)) {
            return false;
        }
        DatasetFieldValue other = (DatasetFieldValue) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.harvard.iq.dataverse.DatasetFieldValue[ id=" + id + " ]";
    }
    
     public boolean isEmpty() {
        return ((strValue==null || strValue.trim().equals("")));
    }
    
    private int displayOrder;
    public int getDisplayOrder() { return this.displayOrder;}
    public void setDisplayOrder(int displayOrder) {this.displayOrder = displayOrder;} 

    @Override
    public int compareTo(DatasetFieldValue o) {
        return Integer.compare(this.getDatasetField().getDisplayOrder(),(o.getDatasetField().getDisplayOrder())); 
    }
    
}<commit_msg>added join to ControlledVocabularyValue entity / table<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.harvard.iq.dataverse;

/**
 *
 * @author skraffmiller
 */
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;


@Entity
public class DatasetFieldValue implements Serializable,   Comparable<DatasetFieldValue> {

    public DatasetFieldValue () {
    }
    
    public DatasetFieldValue(DatasetField sf, DatasetVersion dsv, String val) {
        setDatasetField(sf);
        setDatasetVersion(dsv);
        setStrValue(val);    
    }    
    
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    
    @ManyToOne
    @JoinColumn(nullable=false)
    private DatasetField datasetField;
    public DatasetField getDatasetField() {
        return datasetField;
    }
    public void setDatasetField(DatasetField datasetField) {
        this.datasetField = datasetField;
    }
    
    @ManyToOne
    @JoinColumn(nullable=false)
    private DatasetVersion datasetVersion;
    public DatasetVersion getDatasetVersion() {
        return datasetVersion;
    }
    public void setDatasetVersion(DatasetVersion datasetVersion) {
        this.datasetVersion = datasetVersion;
    }
    

    @OneToMany(mappedBy = "parentDatasetFieldValue", cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST})
    @OrderBy("displayOrder ASC")
    private List<DatasetFieldValue> childDatasetFieldValues= new ArrayList();

    public List<DatasetFieldValue> getChildDatasetFieldValues() {
        if (this.childDatasetFieldValues != null) {
            Collections.sort(this.childDatasetFieldValues, new Comparator<DatasetFieldValue>() {
                public int compare(DatasetFieldValue d1, DatasetFieldValue d2) {
                    int a = d1.getDatasetField().getDisplayOrder();
                    int b = d2.getDatasetField().getDisplayOrder();
                    return Integer.valueOf(a).compareTo(Integer.valueOf(b));
                }
            });
        }
        return this.childDatasetFieldValues;
    }
    public void setChildDatasetFieldValues(List<DatasetFieldValue> childDatasetFieldValues) {
        this.childDatasetFieldValues = childDatasetFieldValues;
    }
    
    public boolean isChildEmpty(){
        //check all child values for empty...        
        for (DatasetFieldValue dsfvc: this.childDatasetFieldValues){
            if(dsfvc.getStrValue()!= null && !dsfvc.getStrValue().isEmpty()){
                return false;
            }
        }
        return true;
    }
    
    @ManyToOne(cascade = CascadeType.MERGE)
    private DatasetFieldValue parentDatasetFieldValue;
    public DatasetFieldValue getParentDatasetFieldValue() {
        return parentDatasetFieldValue;
    }
    public void setParentDatasetFieldValue(DatasetFieldValue parentDatasetFieldValue) {
        this.parentDatasetFieldValue = parentDatasetFieldValue;
    }
    
    @Column(columnDefinition="TEXT") 
    private String strValue;

    public String getStrValue() {
        return strValue;
    }

    public void setStrValue(String strValue) {
        this.strValue = strValue;
        
    }    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DatasetFieldValue)) {
            return false;
        }
        DatasetFieldValue other = (DatasetFieldValue) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.harvard.iq.dataverse.DatasetFieldValue[ id=" + id + " ]";
    }
    
     public boolean isEmpty() {
        return ((strValue==null || strValue.trim().equals("")));
    }
    
    private int displayOrder;
    public int getDisplayOrder() { return this.displayOrder;}
    public void setDisplayOrder(int displayOrder) {this.displayOrder = displayOrder;} 

    @Override
    public int compareTo(DatasetFieldValue o) {
        return Integer.compare(this.getDatasetField().getDisplayOrder(),(o.getDatasetField().getDisplayOrder())); 
    }
    
    @OneToMany(cascade = {CascadeType.MERGE})    
    private List<ControlledVocabularyValue> controlledVocabularyValues;

    public List<ControlledVocabularyValue> getControlledVocabularyValues() {
        return controlledVocabularyValues;
    }

    public void setControlledVocabularyValues(List<ControlledVocabularyValue> controlledVocabularyValues) {
        this.controlledVocabularyValues = controlledVocabularyValues;
    }    
}
{'fraction_non_alphanumeric': 0.09109711384788945, 'fraction_numerical': 0.0011281376327912005, 'mean_word_length': 2.885317750182615, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5394678', 'n_tokens_mistral': 2898, 'n_tokens_neox': 2950, 'n_words': 655}