Skip to content

Commit

Permalink
Madroño statistics improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
juancorr committed Dec 4, 2023
1 parent c51d765 commit 5ac979d
Show file tree
Hide file tree
Showing 20 changed files with 633,765 additions and 22 deletions.
69 changes: 69 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/CountriesMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package edu.harvard.iq.dataverse;

import java.io.Serializable;
import javax.persistence.*;

/**
*
* @author juancorr
*
* CONSORCIO MADROÑO. New class to read the country codes for the statistics
* visualization
*
*/
@Entity
@Table (name = "countriesmap" , indexes = {@Index(columnList="id")})
@NamedQueries({
@NamedQuery(name = "CountriesMap.findAll", query= "SELECT f FROM CountriesMap f")
})
public class CountriesMap implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id", columnDefinition = "TEXT", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;

@Column(name = "name", columnDefinition = "TEXT", nullable = false)
private String name;

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@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 code fields are not set
if (!(object instanceof CountriesMap)) {
return false;
}
CountriesMap other = (CountriesMap) 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.dvn.core.vdc.CountriesMap[ id=" + id + " ]";
}
}
13 changes: 12 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
import javax.persistence.TemporalType;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.StringUtil;
import es.consorciomadrono.DatasetMetricsByMonth;
import es.consorciomadrono.StatisticsByDataset;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
Expand Down Expand Up @@ -667,7 +672,7 @@ public Timestamp getCitationDate() {

public String getCitationDateFormattedYYYYMMDD() {
if (getCitationDate() != null){
return new SimpleDateFormat("yyyy-MM-dd").format(getCitationDate());
return new SimpleDateFormat("yyyy-MM-dd").format(getCitationDate());
}
return null;
}
Expand All @@ -692,6 +697,12 @@ public List<DatasetMetrics> getDatasetMetrics() {
return datasetMetrics;
}

// MADROÑO BEGIN
public DatasetMetricsByMonth getDatasetMetricsByMonth() {
return StatisticsByDataset.getDatasetMetricsByMonth(this);
}
// MADROÑO END

public void setDatasetMetrics(List<DatasetMetrics> datasetMetrics) {
this.datasetMetrics = datasetMetrics;
}
Expand Down
48 changes: 47 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
import org.apache.commons.httpclient.HttpClient;
//import org.primefaces.context.RequestContext;
import java.util.Arrays;
import java.util.HashSet;
import java.util.HashSet;
import javax.faces.model.SelectItem;
import javax.faces.validator.ValidatorException;

Expand Down Expand Up @@ -137,7 +137,14 @@
import edu.harvard.iq.dataverse.search.SearchServiceBean;
import edu.harvard.iq.dataverse.search.SearchUtil;
import edu.harvard.iq.dataverse.search.SolrClientService;
import es.consorciomadrono.DatasetMetricsByMonth;
import java.util.Comparator;
import java.util.Vector;
import java.util.stream.Collectors;
import javax.ejb.TransactionAttribute;
import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.FacetField;
Expand Down Expand Up @@ -168,6 +175,13 @@ public enum DisplayMode {
INIT, SAVE
};

// MADROÑO BEGIN
@PersistenceContext(unitName = "VDCNet-ejbPU")
protected EntityManager em;
private static HashMap <String, String> countriesMap;
private static ArrayList <String> countriesList;
// MADROÑO END


@EJB
DatasetServiceBean datasetService;
Expand Down Expand Up @@ -1786,6 +1800,11 @@ public boolean rsyncUploadSupported() {
}

private String init(boolean initFull) {
// MADROÑO BEGIN
if (countriesMap == null) {
initCountriesMapList ();
}
// MADROÑO END

//System.out.println("_YE_OLDE_QUERY_COUNTER_"); // for debug purposes
setDataverseSiteUrl(systemConfig.getDataverseSiteUrl());
Expand Down Expand Up @@ -5879,4 +5898,31 @@ public boolean downloadingRestrictedFiles() {
}
return false;
}

// MADROÑO BEGIN
@TransactionAttribute(REQUIRES_NEW)
private void initCountriesMapList () {
if (countriesMap== null) {
if (em== null)
Logger.getLogger(DatasetMetricsByMonth.class.getName()).log(Level.SEVERE, "*************#####*****######********* createDatasetMetricsByMonth: em is NULL");

Vector <CountriesMap> countriesMapList = (Vector) em.createNamedQuery("CountriesMap.findAll", CountriesMap.class).getResultList();
countriesMap= (HashMap) countriesMapList.stream().collect(Collectors.toMap(CountriesMap::getId, CountriesMap::getName));
countriesList= new ArrayList<>();
}
}


public static ArrayList <String> getCountriesList () {
for (String id: countriesMap.keySet()) {
String country= countriesMap.get(id);
String bundle="country." + id;
String translatedCountry= BundleUtil.getStringFromBundle(bundle);
//Logger.getLogger(DatasetPage.class.getName()).log(Level.SEVERE, "#####*****###### createDatasetMetricsByMonth country: {0}; bundle: {1} ; translatedCountry {2}", new Object[]{country, bundle, translatedCountry});
countriesList.add("\"" + id+";"+ translatedCountry + "\"");
}
return countriesList;
}
// MADROÑO END

}
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,5 @@ public DatasetMetrics save(DatasetMetrics datasetMetrics) {
DatasetMetrics savedDatasetMetrics = em.merge(datasetMetrics);
return savedDatasetMetrics;
}

}
Loading

0 comments on commit 5ac979d

Please sign in to comment.