Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDC handle legacy counts #6543

Merged
merged 11 commits into from
Jun 13, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
Expand Down Expand Up @@ -910,8 +911,17 @@ public Long getCountGuestbookResponsesByDataFileId(Long dataFileId) {
}

public Long getCountGuestbookResponsesByDatasetId(Long datasetId) {
return getCountGuestbookResponsesByDatasetId(datasetId, null);
}

public Long getCountGuestbookResponsesByDatasetId(Long datasetId, LocalDate date) {
// dataset id is null, will return 0
Query query = em.createNativeQuery("select count(o.id) from GuestbookResponse o where o.dataset_id = " + datasetId);
Query query;
if(date != null) {
query = em.createNativeQuery("select count(o.id) from GuestbookResponse o where o.dataset_id = " + datasetId + " and responsetime < '" + date.toString() + "'");
}else {
query = em.createNativeQuery("select count(o.id) from GuestbookResponse o where o.dataset_id = " + datasetId);
}
return (Long) query.getSingleResult();
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,16 @@ public boolean isDataCiteInstallation() {
public boolean isMakeDataCountDisplayEnabled() {
boolean safeDefaultIfKeyNotFound = (getValueForKey(SettingsServiceBean.Key.MDCLogPath)!=null); //Backward compatible
return isTrueForKey(SettingsServiceBean.Key.DisplayMDCMetrics, safeDefaultIfKeyNotFound);
}

public LocalDate getMDCStartDate() {
String date = getValueForKey(SettingsServiceBean.Key.MDCStartDate);
LocalDate ld=null;
if(date!=null) {
ld = LocalDate.parse(date);
}
return ld;

}

public boolean displayChronologicalDateFacets() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,10 @@ Whether Harvesting (OAI) service is enabled
*/
InheritParentRoleAssignments,

/** Make Data Count Logging and Display */
/** Make Data Count Logging, Display, and Start Date */
MDCLogPath,
DisplayMDCMetrics,
MDCStartDate,
Copy link
Member

@pdurbin pdurbin Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can :MDCStartDate be changed from a database setting to MPCONFIG?

And can we please have a release note about the new setting?


/**
* Allow CORS flag (true or false). It is true by default
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1401,17 +1401,22 @@ metrics.title=Metrics
metrics.title.tip=View more metrics information
metrics.dataset.title=Dataset Metrics
metrics.dataset.tip.default=Aggregated metrics for this dataset.
metrics.dataset.makedatacount.title=Make Data Count (MDC) Metrics
metrics.dataset.makedatacount.since=since
metrics.dataset.tip.makedatacount=Metrics collected using <a href="https://makedatacount.org/counter-code-of-practice-for-research-data/" target="_blank" rel="noopener"/>Make Data Count</a> standards.
metrics.dataset.views.tip=Dataset views are combined with both aggregated file views and file downloads.
metrics.dataset.views.tip=Aggregate of views of the dataset landing page, file views, and file downloads.
metrics.dataset.downloads.default.tip=Total aggregated downloads of files in this dataset.
metrics.dataset.downloads.makedatacount.tip=Each file downloaded is counted as 1, and added to the total download count.
metrics.dataset.downloads.premakedatacount.tip=Downloads prior to enabling MDC. Counts do not have the same filtering and detail as MDC metrics.
metrics.dataset.citations.tip=Click for a list of citation URLs.
metrics.file.title=File Metrics
metrics.file.tip.default=Metrics for this individual file.
metrics.file.tip.makedatacount=Individual file downloads are tracked in Dataverse but are not reported as part of the Make Data Count standard.
metrics.file.downloads.tip=Total downloads of this file.
metrics.file.downloads.nonmdc.tip=Total downloads. Due to differences between MDC and Dataverse's internal tracking, the sum of these for all files in a dataset may be larger than total downloads reported for a dataset.
metrics.views={0, choice, 0#Views|1#View|2#Views}
metrics.downloads={0, choice, 0#Downloads|1#Download|2#Downloads}
metrics.downloads.nonMDC={0, choice, 0#|1# (+ 1 pre-MDC |2< (+ {0} pre-MDC }
metrics.citations={0, choice, 0#Citations|1#Citation|2#Citations}
metrics.citations.dialog.header=Dataset Citations
metrics.citations.dialog.help=Citations for this dataset are retrieved from Crossref via DataCite using Make Data Count standards. For more information about dataset metrics, please refer to the <a href="{0}/{1}/user/dataset-management.html#dataset-metrics-and-make-data-count" title="Dataset Metrics and Make Data Count - Dataverse User Guide" target="_blank">User Guide</a>.
Expand Down
11 changes: 10 additions & 1 deletion src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,17 @@
<!-- Metrics -->
<div id="metrics-block">
<div id="metrics-heading">
#{bundle['metrics.dataset.title']}
#{settingsWrapper.makeDataCountDisplayEnabled ? bundle['metrics.dataset.makedatacount.title'] : bundle['metrics.dataset.title']}
<ui:fragment rendered="#{!settingsWrapper.makeDataCountDisplayEnabled}">
<span class="glyphicon glyphicon-question-sign tooltip-icon" data-toggle="tooltip" data-placement="auto top"
data-trigger="hover" data-original-title="#{bundle['metrics.dataset.tip.default']}"></span>
</ui:fragment>
<ui:fragment rendered="#{settingsWrapper.makeDataCountDisplayEnabled}">
<a tabindex="0" role="button" class="glyphicon glyphicon-question-sign tooltip-icon" data-toggle="popover" data-placement="auto top"
data-trigger="focus" data-html="true" data-content="#{bundle['metrics.dataset.tip.makedatacount']}"></a>
<div id="metrics-heading-subtitle">#{bundle['metrics.dataset.makedatacount.since']} #{settingsWrapper.getMDCStartDate().toString()}</div>
</ui:fragment>

</div>
<div id="metrics-body">
<!-- Classic downloads -->
Expand All @@ -552,6 +554,13 @@
</h:outputFormat>
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.dataset.downloads.makedatacount.tip']}"></span>
<span jsf:rendered="#{settingsWrapper.getMDCStartDate()!=null}">
<h:outputFormat value="#{bundle['metrics.downloads.nonMDC']}">
<f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDatasetId(DatasetPage.dataset.id, settingsWrapper.getMDCStartDate())}"/>
</h:outputFormat>
<span jsf:rendered="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDatasetId(DatasetPage.dataset.id, settingsWrapper.getMDCStartDate()) > 0}" class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.dataset.downloads.premakedatacount.tip']}"></span>)
</span>
</div>
<!-- Make Data Count citations (DOIs only, not Handles) -->
<div class="metrics-count-block" jsf:rendered="#{settingsWrapper.makeDataCountDisplayEnabled and settingsWrapper.doiInstallation}">
Expand Down
49 changes: 33 additions & 16 deletions src/main/webapp/file.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,39 @@
data-trigger="focus" data-html="true" data-content="#{bundle['metrics.file.tip.makedatacount']}"></a>
</ui:fragment>
</div>
<div id="metrics-body">
<!-- Classic downloads -->
<div class="metrics-count-block" jsf:rendered="#{!settingsWrapper.makeDataCountDisplayEnabled}">
<h:outputFormat value="{0} #{bundle['metrics.downloads']}">
<f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDataFileId(FilePage.fileId)}"/>
</h:outputFormat>
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.file.downloads.tip']}"></span>
</div>
<!-- Make Data Count downloads -->
<div class="metrics-count-block" jsf:rendered="#{settingsWrapper.makeDataCountDisplayEnabled}">
<h:outputFormat value="{0} #{bundle['metrics.downloads']}">
<f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDataFileId(FilePage.fileId)}"/>
</h:outputFormat>
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.file.downloads.tip']}"></span>
<!-- END DATASET CITATION -->
<!-- Metrics -->
<div class="col-sm-3">
<div id="metrics-block" jsf:rendered="#{!(widgetWrapper.widgetView or FilePage.fileMetadata.dataFile.filePackage or FilePage.fileMetadata.datasetVersion.deaccessioned)}">
<div id="metrics-heading">
#{bundle['metrics.file.title']}
<ui:fragment rendered="#{!settingsWrapper.makeDataCountDisplayEnabled}">
<span class="glyphicon glyphicon-question-sign tooltip-icon" data-toggle="tooltip" data-placement="auto top"
data-trigger="hover" data-original-title="#{bundle['metrics.dataset.tip.default']}"></span>
</ui:fragment>
<ui:fragment rendered="#{settingsWrapper.makeDataCountDisplayEnabled}">
<a tabindex="0" role="button" class="glyphicon glyphicon-question-sign tooltip-icon" data-toggle="popover" data-placement="auto top"
data-trigger="focus" data-html="true" data-content="#{bundle['metrics.dataset.tip.makedatacount']}"></a>
</ui:fragment>
</div>
<div id="metrics-body">
<!-- Classic downloads -->
<div class="metrics-count-block" jsf:rendered="#{!settingsWrapper.makeDataCountDisplayEnabled}">
<h:outputFormat value="{0} #{bundle['metrics.downloads']}">
<f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDataFileId(FilePage.fileId)}"/>
</h:outputFormat>
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.file.downloads.tip']}"></span>
</div>
<!-- Make Data Count downloads -->
<div class="metrics-count-block" jsf:rendered="#{settingsWrapper.makeDataCountDisplayEnabled}">
<h:outputFormat value="{0} #{bundle['metrics.downloads']}">
<f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDataFileId(FilePage.fileId)}"/>
</h:outputFormat>
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.file.downloads.nonmdc.tip']}"></span>
</div>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/resources/css/structure.css
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@ div[id$='roleDisplay'] span.label, div[id$='roleDetails'] span.label {display:in
#metrics-content {color:#333;background:#fff;padding:8px 10px;}
/* -- NEW LAYOUT, DATASET + FILE -- */
#metrics-block {border:0; margin-top:6px;}
#metrics-body {border:1px solid #EEE;border-width:1px 0 0 0;padding:8px 0;}
#metrics-heading-subtitle {font-weight:normal;font-size:smaller;}
#metrics-body {border:1px solid #EEE;border-top-width:0;padding:8px 10px;}
#metrics-block .metrics-count-block:not(:last-child) {margin-bottom:.5em;padding-bottom:.5em;border-bottom:1px solid #EEE}

/* -------- SHARRRE -------- */
Expand Down