Skip to content

Commit

Permalink
Remove dataLocation from bySubject/toMonth #5445
Browse files Browse the repository at this point in the history
We will try to add this again later. Is it not actually required.
  • Loading branch information
matthew-a-dunlap committed Feb 7, 2019
1 parent cdfffcc commit d5d5230
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 47 deletions.
16 changes: 8 additions & 8 deletions src/main/java/edu/harvard/iq/dataverse/api/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,16 @@ public Response getDatasetsPastDays(@Context UriInfo uriInfo, @PathParam("days")

@GET
@Path("datasets/bySubject")
public Response getDatasetsBySubject(@Context UriInfo uriInfo, @QueryParam("dataLocation") String dataLocation) {
return getDatasetsBySubjectToMonth(uriInfo, MetricsUtil.getCurrentMonth(), dataLocation);
public Response getDatasetsBySubject(@Context UriInfo uriInfo) {
return getDatasetsBySubjectToMonth(uriInfo, MetricsUtil.getCurrentMonth());
}

//TODO: This endpoint should be updated to take dataLocation
@GET
@Path("datasets/bySubject/toMonth/{yyyymm}")
public Response getDatasetsBySubjectToMonth(@Context UriInfo uriInfo, @PathParam("yyyymm") String yyyymm, @QueryParam("dataLocation") String dataLocation) {
public Response getDatasetsBySubjectToMonth(@Context UriInfo uriInfo, @PathParam("yyyymm") String yyyymm) {
try {
errorIfUnrecongizedQueryParamPassed(uriInfo, new String[]{"dataLocation"});
errorIfUnrecongizedQueryParamPassed(uriInfo, new String[]{""});
} catch (IllegalArgumentException ia) {
return allowCors(error(BAD_REQUEST, ia.getLocalizedMessage()));
}
Expand All @@ -252,13 +253,12 @@ public Response getDatasetsBySubjectToMonth(@Context UriInfo uriInfo, @PathParam

try {
String sanitizedyyyymm = MetricsUtil.sanitizeYearMonthUserInput(yyyymm);
String validDataLocation = MetricsUtil.validateDataLocationStringType(dataLocation);
String jsonArrayString = metricsSvc.returnUnexpiredCacheMonthly(metricName, sanitizedyyyymm, validDataLocation);
String jsonArrayString = metricsSvc.returnUnexpiredCacheMonthly(metricName, sanitizedyyyymm, null);

if (null == jsonArrayString) { //run query and save
JsonArrayBuilder jsonArrayBuilder = MetricsUtil.datasetsBySubjectToJson(metricsSvc.datasetsBySubjectToMonth(sanitizedyyyymm, validDataLocation));
JsonArrayBuilder jsonArrayBuilder = MetricsUtil.datasetsBySubjectToJson(metricsSvc.datasetsBySubjectToMonth(sanitizedyyyymm));
jsonArrayString = jsonArrayBuilder.build().toString();
metricsSvc.save(new Metric(metricName, sanitizedyyyymm, validDataLocation, jsonArrayString));
metricsSvc.save(new Metric(metricName, sanitizedyyyymm, null, jsonArrayString));
}

return allowCors(ok(MetricsUtil.stringToJsonArrayBuilder(jsonArrayString)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,43 +131,8 @@ public long datasetsToMonth(String yyyymm, String dataLocation) throws Exception
return (long) query.getSingleResult();
}

public List<Object[]> datasetsBySubjectToMonth(String yyyymm, String dataLocation) {
String dataLocationLine = "(date_trunc('month', releasetime) <= to_date('" + yyyymm +"','YYYY-MM') and dataset.harvestingclient_id IS NULL)\n";

if(!DATA_LOCATION_LOCAL.equals(dataLocation)) { //Default api state is DATA_LOCATION_LOCAL
//we have to use createtime for harvest as post dvn3 harvests do not have releasetime populated
String harvestBaseLine = "(date_trunc('month', createtime) <= to_date('" + yyyymm +"','YYYY-MM') and dataset.harvestingclient_id IS NOT NULL)\n";
if (DATA_LOCATION_REMOTE.equals(dataLocation)) {
dataLocationLine = harvestBaseLine; //replace
} else if(DATA_LOCATION_ALL.equals(dataLocation)) {
dataLocationLine += " or " +harvestBaseLine; //append
}
}

public List<Object[]> datasetsBySubjectToMonth(String yyyymm) {
Query query = em.createNativeQuery(""
+ "SELECT strvalue, count(dataset.id)\n"
+ "FROM datasetfield_controlledvocabularyvalue \n"
+ "(\n"
+ "select datasetversion.dataset_id || ':' || max(datasetversion.versionnumber + (.1 * datasetversion.minorversionnumber)) as max \n"
+ "from datasetversion\n"
+ "join dataset on dataset.id = datasetversion.dataset_id\n"
+ "JOIN controlledvocabularyvalue ON controlledvocabularyvalue.id = datasetfield_controlledvocabularyvalue.controlledvocabularyvalues_id\n"
+ "JOIN datasetfield ON datasetfield.id = datasetfield_controlledvocabularyvalue.datasetfield_id\n"
+ "JOIN datasetfieldtype ON datasetfieldtype.id = controlledvocabularyvalue.datasetfieldtype_id\n"
+ "JOIN datasetversion ON datasetversion.id = datasetfield.datasetversion_id\n"
+ "JOIN dvobject ON dvobject.id = datasetversion.dataset_id\n"
+ "JOIN dataset ON dataset.id = datasetversion.dataset_id\n"
+ "where versionstate='RELEASED'\n"
+ "and"
+ dataLocationLine
+ "group by dataset_id \n"
+ ")\n"
+ "AND datasetfieldtype.name = 'subject'\n"
+ "GROUP BY strvalue\n"
+ "ORDER BY count(dataset.id) desc;"
);

Query queryOldDelete = em.createNativeQuery(""
+ "SELECT strvalue, count(dataset.id)\n"
+ "FROM datasetfield_controlledvocabularyvalue \n"
+ "JOIN controlledvocabularyvalue ON controlledvocabularyvalue.id = datasetfield_controlledvocabularyvalue.controlledvocabularyvalues_id\n"
Expand All @@ -183,7 +148,7 @@ public List<Object[]> datasetsBySubjectToMonth(String yyyymm, String dataLocatio
+ "from datasetversion\n"
+ "join dataset on dataset.id = datasetversion.dataset_id\n"
+ "where versionstate='RELEASED'\n"
+ dataLocationLine
+ "and dataset.harvestingclient_id is null\n"
+ "and date_trunc('month', releasetime) <= to_date('" + yyyymm + "','YYYY-MM')\n"
+ "group by dataset_id \n"
+ ")\n"
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/edu/harvard/iq/dataverse/api/MetricsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ public void testGetDatasetsBySubjectToMonth() {

assertEquals(precache, postcache);

//Test ok when passing extra query params
//Test error passing extra query params
response = UtilIT.metricsDatasetsBySubjectToMonth(thismonth, "dataLocation=local");
response.then().assertThat()
.statusCode(OK.getStatusCode());
.statusCode(BAD_REQUEST.getStatusCode());
}
}

0 comments on commit d5d5230

Please sign in to comment.