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

IQSS/7177 enhance metrics api #7178

Merged
Merged
Show file tree
Hide file tree
Changes from 137 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
4abcb14
add filetype metric api endpoint
qqmyers Jul 30, 2020
40571ee
missing query ending
qqmyers Jul 30, 2020
71bf163
add parens around in
qqmyers Jul 30, 2020
2ce60ea
typo
qqmyers Jul 30, 2020
34d1865
add count, fix names (case sensitive)
qqmyers Jul 30, 2020
470c135
use native query
qqmyers Jul 30, 2020
246f368
count is BigDecimal
qqmyers Jul 30, 2020
96492f7
determine types
qqmyers Jul 30, 2020
3e722a0
remove debug
qqmyers Jul 30, 2020
9f08bf1
Enable per dataverse reporting of all metrics
qqmyers Jul 31, 2020
0764c20
Allow an ok(JsonObject) for convenience
qqmyers Jul 31, 2020
a5f3f68
simplify ok response type
qqmyers Jul 31, 2020
4525c3d
sanitize incoming yyyymm info as in Metrics API
qqmyers Jul 31, 2020
ff6cd96
refactor response logic, add fileTypes by Date, add MDC per Dataverse
qqmyers Jul 31, 2020
d6aa0e8
fix test to match MetricsUtil changes
qqmyers Jul 31, 2020
6b09238
allow parentAlias param
qqmyers Jul 31, 2020
b98b076
fix getMetric query
qqmyers Jul 31, 2020
37af77f
try entity as param
qqmyers Jul 31, 2020
7bec8be
allow null and fix query
qqmyers Jul 31, 2020
b7aab41
update join info
qqmyers Jul 31, 2020
2917413
add unique download query
qqmyers Jul 31, 2020
913205f
adjust query
qqmyers Jul 31, 2020
91d1619
try param name change
qqmyers Jul 31, 2020
1389107
debug logging
qqmyers Jul 31, 2020
5f3c792
typo
qqmyers Jul 31, 2020
bb9b21d
return null for null input and more debug
qqmyers Jul 31, 2020
c2550a0
fix ? statement
qqmyers Jul 31, 2020
034c938
merge with dvobject when needed
qqmyers Jul 31, 2020
8fb61d9
fix MDC query
qqmyers Jul 31, 2020
8214d02
alphabetic compare against string monthyear column
qqmyers Aug 5, 2020
cf61002
typo
qqmyers Aug 5, 2020
9df23ac
more typos
qqmyers Aug 5, 2020
264a324
handle country correctly
qqmyers Aug 6, 2020
804aca6
add debug logging
qqmyers Aug 6, 2020
770cc6b
Validate country code to ISO 1366 and cache per country
qqmyers Aug 6, 2020
861a43e
make country codes transient
qqmyers Aug 6, 2020
a2cf4d3
move country code validation out of Entity
qqmyers Aug 6, 2020
d8bc901
handle null country case
qqmyers Aug 6, 2020
84ca24f
handle null result representing 0 counts
qqmyers Aug 6, 2020
e07f461
default to current month instead of null
qqmyers Aug 6, 2020
b4ff22f
unique downloads endpoint
qqmyers Aug 6, 2020
6d55bba
typo
qqmyers Aug 6, 2020
85413ce
try coalesce to avoid null
qqmyers Aug 7, 2020
662f44e
add json tree of dataverses endpoint
qqmyers Aug 7, 2020
cd59b71
Simplify error handling
qqmyers Aug 7, 2020
eb1dec0
reformatting only
qqmyers Aug 7, 2020
6dcd0a4
fix type cast and check for no parent dataverse
qqmyers Aug 7, 2020
83b2f81
fix logging statement
qqmyers Aug 7, 2020
836f36a
fix root case
qqmyers Aug 7, 2020
995f6b2
handle null case
qqmyers Aug 9, 2020
ec2c75e
use constants
qqmyers Aug 13, 2020
b05fb49
dataverse time series
qqmyers Aug 13, 2020
ab3e41b
typo
qqmyers Aug 13, 2020
8024709
document params
qqmyers Aug 14, 2020
86553d1
datasets time series
qqmyers Aug 14, 2020
80aa9dc
logic issues, typos
qqmyers Aug 14, 2020
695b66e
logic, include parent in list
qqmyers Aug 14, 2020
33224e8
method name change
qqmyers Aug 14, 2020
c922d21
add params comment
qqmyers Aug 14, 2020
2a5b6ea
fix add parent dataverse logic
qqmyers Aug 14, 2020
7879656
reversed logic
qqmyers Aug 14, 2020
aaf43ea
add mimetype
qqmyers Aug 19, 2020
5f907dd
add csv endpoint
qqmyers Aug 19, 2020
54723d7
typo
qqmyers Aug 19, 2020
9b3d3c3
convert int to string
qqmyers Aug 19, 2020
786e99b
use JsonValue
qqmyers Aug 19, 2020
1b23f57
make CSV the default
qqmyers Aug 19, 2020
094db71
calculate full time series
qqmyers Aug 19, 2020
d931e82
fix date parse issue
qqmyers Aug 19, 2020
ddef69e
stop at last result
qqmyers Aug 19, 2020
43da440
correct date
qqmyers Aug 19, 2020
19684f6
allow CORS requests to send accept header
qqmyers Aug 19, 2020
29fb537
datasets timeseries and csv export
qqmyers Aug 20, 2020
17788ce
cleanup
qqmyers Aug 20, 2020
c23b070
csv for dataverse by subject and category
qqmyers Aug 20, 2020
4d4a5ce
datasets by subject csv
qqmyers Aug 20, 2020
8427d3f
add files time series, timeseries util, restore /datasets
qqmyers Aug 20, 2020
e08fe4a
files by type time series with csv
qqmyers Aug 20, 2020
8981eb2
downloads time series
qqmyers Aug 20, 2020
7ed9d6a
MDC timeseries with csv
qqmyers Aug 20, 2020
2f70fa7
unique downloads timeseries and csv
qqmyers Aug 20, 2020
3976fb5
update name of query select column
qqmyers Aug 20, 2020
0eed6d0
stop while when out of results
qqmyers Aug 20, 2020
edd6058
fix timeseriesbyX logic
qqmyers Aug 20, 2020
f46e6c5
use yyyy in pattern
qqmyers Aug 21, 2020
50d4d1b
use YearMonth
qqmyers Aug 21, 2020
d18b196
fix date parsing
qqmyers Aug 21, 2020
58f6c32
update files/ByType, caching, naming cleanup
qqmyers Aug 21, 2020
13d3159
Constraining calls to require released parent dataverse
qqmyers Aug 21, 2020
5d2804e
null check
qqmyers Aug 21, 2020
17411da
fix queries
qqmyers Aug 21, 2020
b0c9867
typo in query
qqmyers Aug 21, 2020
6ccb88a
typo cut/paste
qqmyers Aug 21, 2020
1ca4c4d
typo - err in download counts
qqmyers Aug 24, 2020
c112dca
typo - autoescaped quotes
qqmyers Aug 24, 2020
5a8cbbc
use array for unique downloads
qqmyers Aug 24, 2020
e3308cf
fix where /and clauses for various cases
qqmyers Aug 24, 2020
f94a85e
support downloads total and views total queries
qqmyers Aug 24, 2020
cc85f34
all four aggregate metrics
qqmyers Aug 24, 2020
caa205a
order by popularity
qqmyers Aug 25, 2020
dbb8a01
try retrieving selected contenttype
qqmyers Aug 26, 2020
5e9a0b7
handle return type selection better and add csv filenames
qqmyers Aug 26, 2020
b13e70a
formatting only
qqmyers Aug 26, 2020
28760d4
update rsync call to use new ok() method
qqmyers Aug 26, 2020
f87fd53
fix return contentype logic
qqmyers Aug 26, 2020
c6402ca
prefer csv when client doesn't care
qqmyers Aug 26, 2020
e578fec
reverse order in variant request
qqmyers Aug 26, 2020
282c77e
add db update script
qqmyers Aug 27, 2020
781e105
update db update script name
qqmyers Aug 27, 2020
944dcd0
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers Aug 31, 2020
454b2b6
missed updates
qqmyers Aug 31, 2020
38cd064
make update idempotent
qqmyers Sep 1, 2020
97bbfc5
filedownloads api endpoint
qqmyers Sep 9, 2020
1335ea4
id is Integer
qqmyers Sep 9, 2020
f592b2f
fix csv download
qqmyers Sep 9, 2020
44ab11c
add unique and toMonth file download options
qqmyers Sep 9, 2020
9c22bd0
most counts first
qqmyers Sep 9, 2020
4e708fa
add missing csv downloads
qqmyers Sep 9, 2020
620c422
another csv add
qqmyers Sep 9, 2020
e4965d1
don't show 0 total count dates in timeseries
qqmyers Sep 10, 2020
435a6d2
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers Oct 6, 2020
b249c87
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers Oct 8, 2020
88dc295
debug log causes failure with no dataverse sent
qqmyers Oct 12, 2020
d3d401b
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers Oct 20, 2020
4caed91
per @pdurbin's review, including additional documentation
qqmyers Oct 28, 2020
c373ddb
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers Oct 30, 2020
a49785d
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers Nov 3, 2020
ff092f8
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers Jan 8, 2021
14c0e58
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers Jan 29, 2021
708b1e8
Merge remote-tracking branch 'IQSS/develop' into
qqmyers Feb 23, 2021
3d505bb
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers Apr 7, 2021
c881053
update flyway script number
qqmyers Apr 7, 2021
e642ff8
fix github link
qqmyers Apr 7, 2021
0419166
release notes
qqmyers Apr 8, 2021
cc1c067
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers Apr 13, 2021
e495cf7
Merge remote-tracking branch 'IQSS/develop' into IQSS/7177-enhance_me…
qqmyers May 5, 2021
1e4a4cf
prevent text from being large #7177
pdurbin May 10, 2021
2b87262
rename flyway
qqmyers May 12, 2021
61e926d
Merge remote-tracking branch 'origin/IQSS/7177-enhance_metrics_api' i…
qqmyers May 12, 2021
35461b7
Report missing file sizes and return 0 instead of null
qqmyers May 12, 2021
bbbfcd1
don't fire a log message if metricscachetimeoutminutes isn't set
qqmyers May 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/release-notes/7178-new_metrics.md
@@ -0,0 +1,3 @@
## Major Use Cases

- Users can retrieve new types of metrics and per-collection metrics. The new capabilities are described in the guides. A new version of the [Dataverse Metrics web app](https://github.com/IQSS/dataverse-metrics) adds interactive graphs to display these metrics. Anyone running the existing Dataverse Metrics app will need to upgrade or apply [a small patch](https://github.com/IQSS/dataverse-metrics/pull/60) to continue retrieving metrics from Dataverse instances upgrading to this release. Issue #7177/PR #7178
153 changes: 106 additions & 47 deletions doc/sphinx-guides/source/api/metrics.rst

Large diffs are not rendered by default.

29 changes: 24 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/Metric.java
Expand Up @@ -15,6 +15,8 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
Expand Down Expand Up @@ -46,6 +48,10 @@ public class Metric implements Serializable {
@Column(columnDefinition = "TEXT", nullable = true)
private String dayString;

@ManyToOne(optional=true)
@JoinColumn(name="dataverse_id", nullable=true)
private Dataverse dataverse;

@Temporal(value = TemporalType.TIMESTAMP)
@Column(nullable = false)
private Date lastCalledDate;
Expand All @@ -55,16 +61,21 @@ public Metric() {
}

//For monthly and day metrics

public Metric(String name, String dayString, String dataLocation, String value) throws IOException {
if(null == name || null == value) {
throw new IOException("A created metric must have a metricName and metricValue");
}
/**
*
* @param name - metric name
* @param dayString - how many days (day metric only)
* @param dataLocation - local, remote, all
* @param d - the parent dataverse
* @param value - the value to cache
*/
public Metric(String name, String dayString, String dataLocation, Dataverse d, String value) {
this.name = name;
this.valueJson = value;
this.dataLocation = dataLocation;
this.dayString = dayString;
this.lastCalledDate = new Timestamp(new Date().getTime());
this.dataverse = d;
}

/**
Expand Down Expand Up @@ -121,4 +132,12 @@ public void setLastCalledDate(Date calledDate) {
this.lastCalledDate = calledDate;
}

public Dataverse getDataverse() {
return dataverse;
}

public void setDataverse(Dataverse dataverse) {
this.dataverse = dataverse;
}

}
29 changes: 26 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/api/AbstractApiBean.java
Expand Up @@ -63,6 +63,7 @@
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
Expand All @@ -76,6 +77,7 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import static org.apache.commons.lang.StringUtils.isNumeric;

Expand Down Expand Up @@ -706,7 +708,15 @@ protected Response response( DataverseRequestHandler hdl ) {
protected Response ok( JsonArrayBuilder bld ) {
return Response.ok(Json.createObjectBuilder()
.add("status", STATUS_OK)
.add("data", bld).build()).build();
.add("data", bld).build())
.type(MediaType.APPLICATION_JSON).build();
}

protected Response ok( JsonArray ja ) {
return Response.ok(Json.createObjectBuilder()
.add("status", STATUS_OK)
.add("data", ja).build())
.type(MediaType.APPLICATION_JSON).build();
}

protected Response ok( JsonObjectBuilder bld ) {
Expand All @@ -716,6 +726,14 @@ protected Response ok( JsonObjectBuilder bld ) {
.type(MediaType.APPLICATION_JSON)
.build();
}

protected Response ok( JsonObject jo ) {
return Response.ok( Json.createObjectBuilder()
.add("status", STATUS_OK)
.add("data", jo).build() )
.type(MediaType.APPLICATION_JSON)
.build();
}

protected Response ok( String msg ) {
return Response.ok().entity(Json.createObjectBuilder()
Expand Down Expand Up @@ -743,10 +761,15 @@ protected Response ok( boolean value ) {
/**
* @param data Payload to return.
* @param mediaType Non-JSON media type.
* @param downloadFilename - add Content-Disposition header to suggest filename if not null
* @return Non-JSON response, such as a shell script.
*/
protected Response ok(String data, MediaType mediaType) {
return Response.ok().entity(data).type(mediaType).build();
protected Response ok(String data, MediaType mediaType, String downloadFilename) {
ResponseBuilder res =Response.ok().entity(data).type(mediaType);
if(downloadFilename != null) {
res = res.header("Content-Disposition", "attachment; filename=" + downloadFilename);
}
return res.build();
}

protected Response created( String uri, JsonObjectBuilder bld ) {
Expand Down
Expand Up @@ -163,7 +163,7 @@ public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) thr
if (settingsSvc.isTrueForKey(SettingsServiceBean.Key.AllowCors, true )) {
((HttpServletResponse) sr1).addHeader("Access-Control-Allow-Origin", "*");
((HttpServletResponse) sr1).addHeader("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
((HttpServletResponse) sr1).addHeader("Access-Control-Allow-Headers", "Content-Type, X-Dataverse-Key");
((HttpServletResponse) sr1).addHeader("Access-Control-Allow-Headers", "Accept, Content-Type, X-Dataverse-Key");
}
fc.doFilter(sr, sr1);
} catch ( ServletException se ) {
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Expand Up @@ -95,6 +95,7 @@
import edu.harvard.iq.dataverse.makedatacount.DatasetMetricsServiceBean;
import edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean;
import edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean.MakeDataCountEntry;
import edu.harvard.iq.dataverse.metrics.MetricsUtil;
import edu.harvard.iq.dataverse.makedatacount.MakeDataCountUtil;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.ArchiverUtil;
Expand Down Expand Up @@ -1380,7 +1381,7 @@ public Response getRsync(@PathParam("identifier") String id) {
logger.log(Level.WARNING, "Failed to lock the dataset (dataset id={0})", dataset.getId());
return error(Response.Status.FORBIDDEN, "Failed to lock the dataset (dataset id="+dataset.getId()+")");
}
return ok(scriptRequestResponse.getScript(), MediaType.valueOf(MediaType.TEXT_PLAIN));
return ok(scriptRequestResponse.getScript(), MediaType.valueOf(MediaType.TEXT_PLAIN), null);
} catch (WrappedResponse wr) {
return wr.getResponse();
} catch (EJBException ex) {
Expand Down Expand Up @@ -2192,7 +2193,13 @@ public Response getMakeDataCountMetric(@PathParam("id") String idSupplied, @Path
if (yyyymm != null) {
// We add "-01" because we store "2018-05-01" rather than "2018-05" in the "monthyear" column.
// Dates come to us as "2018-05-01" in the SUSHI JSON ("begin-date") and we decided to store them as-is.
monthYear = yyyymm + "-01";
monthYear = MetricsUtil.sanitizeYearMonthUserInput(yyyymm) + "-01";
}
if (country != null) {
country = country.toLowerCase();
if (!MakeDataCountUtil.isValidCountryCode(country)) {
return error(Response.Status.BAD_REQUEST, "Country must be one of the ISO 1366 Country Codes");
}
}
DatasetMetrics datasetMetrics = datasetMetricsSvc.getDatasetMetricsByDatasetForDisplay(dataset, monthYear, country);
if (datasetMetrics == null) {
Expand Down Expand Up @@ -2273,6 +2280,9 @@ public Response getMakeDataCountMetric(@PathParam("id") String idSupplied, @Path
return ok(jsonObjectBuilder);
} catch (WrappedResponse wr) {
return wr.getResponse();
} catch (Exception e) {
//bad date - caught in sanitize call
return error(BAD_REQUEST, e.getMessage());
}
}

Expand Down