Skip to content

Commit

Permalink
MDC expanded dataset api logging #4821
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-a-dunlap committed Mar 1, 2019
1 parent 278568d commit 6375598
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ path_types:
investigations:
- ^.*/dataset.xhtml\S*$
- ^.*/file.xhtml\S*$
- ^.*/api/datasets/export\S*$
- ^.*/api/v1/datasets/export\S*$
- ^.*/api/datasets\S*$
- ^.*/api/v1/datasets\S*$
## Below historic regex for testing
#- ^/api/datasets/[^\/]+$
#- ^/api/versions/\d+$
Expand Down
37 changes: 20 additions & 17 deletions scripts/vagrant/counter-processor-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ log_name_pattern: sample_logs/counter_(yyyy-mm-dd).log
# Dataverse Note: the url matches on this does not include the query params, so dataset.xhtml\S+ will not match
path_types:
investigations:
- ^/dataset.xhtml\S*$
- ^/file.xhtml\S*$
# Below historic regex for testing
- ^/api/datasets/[^\/]+$
- ^/api/versions/\d+$
- ^/stash/dataset/\S+$
- ^/stash/data_paper/\S+$
- ^.*/dataset.xhtml\S*$
- ^.*/file.xhtml\S*$
- ^.*/api/datasets\S*$
- ^.*/api/v1/datasets\S*$
## Below historic regex for testing
#- ^/api/datasets/[^\/]+$
#- ^/api/versions/\d+$
#- ^/stash/dataset/\S+$
#- ^/stash/data_paper/\S+$
requests:
- ^/api/access/datafile\S+$
# Below historic regex for testing
- ^/api/datasets/[^\/]+/download$
- ^/api/versions/\d+/download$
- ^/api/downloads/\d+$
- ^/stash/downloads/download_resource/\d+$
- ^/stash/downloads/file_download/\d+$
- ^/stash/downloads/file_stream/\d+$
- ^/stash/downloads/async_request/\d+$
- ^/stash/share/\S+$
- ^.*/api/access/datafile\S+$
- ^.*/api/v1/access/datafile\S+$
## Below historic regex for testing
#- ^/api/datasets/[^\/]+/download$
#- ^/api/versions/\d+/download$
#- ^/api/downloads/\d+$
#- ^/stash/downloads/download_resource/\d+$
#- ^/stash/downloads/file_download/\d+$
#- ^/stash/downloads/file_stream/\d+$
#- ^/stash/downloads/async_request/\d+$
#- ^/stash/share/\S+$

# Robots and machines urls are urls where the script can download a list of regular expressions to determine
# if something is a robot or machine user-agent. The text file has one regular expression per line
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,38 +323,40 @@ public Response listVersions( @PathParam("id") String id ) {

@GET
@Path("{id}/versions/{versionId}")
public Response getVersion( @PathParam("id") String datasetId, @PathParam("versionId") String versionId) {
public Response getVersion( @PathParam("id") String datasetId, @PathParam("versionId") String versionId, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
return allowCors(response( req -> {
DatasetVersion dsv = getDatasetVersionOrDie(req, versionId, findDatasetOrDie(datasetId));
DatasetVersion dsv = getDatasetVersionOrDie(req, versionId, findDatasetOrDie(datasetId), uriInfo, headers);
return (dsv == null || dsv.getId() == null) ? notFound("Dataset version not found")
: ok(json(dsv));
}));
}

@GET
@Path("{id}/versions/{versionId}/files")
public Response getVersionFiles( @PathParam("id") String datasetId, @PathParam("versionId") String versionId) {
public Response getVersionFiles( @PathParam("id") String datasetId, @PathParam("versionId") String versionId, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
return allowCors(response( req -> ok( jsonFileMetadatas(
getDatasetVersionOrDie(req, versionId, findDatasetOrDie(datasetId)).getFileMetadatas()))));
getDatasetVersionOrDie(req, versionId, findDatasetOrDie(datasetId), uriInfo, headers).getFileMetadatas()))));
}

@GET
@Path("{id}/versions/{versionId}/metadata")
public Response getVersionMetadata( @PathParam("id") String datasetId, @PathParam("versionId") String versionId) {
public Response getVersionMetadata( @PathParam("id") String datasetId, @PathParam("versionId") String versionId, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
return allowCors(response( req -> ok(
jsonByBlocks(
getDatasetVersionOrDie(req, versionId, findDatasetOrDie(datasetId) )
getDatasetVersionOrDie(req, versionId, findDatasetOrDie(datasetId), uriInfo, headers )
.getDatasetFields()))));
}

@GET
@Path("{id}/versions/{versionNumber}/metadata/{block}")
public Response getVersionMetadataBlock( @PathParam("id") String datasetId,
@PathParam("versionNumber") String versionNumber,
@PathParam("block") String blockName ) {
@PathParam("block") String blockName,
@Context UriInfo uriInfo,
@Context HttpHeaders headers ) {

return allowCors(response( req -> {
DatasetVersion dsv = getDatasetVersionOrDie(req, versionNumber, findDatasetOrDie(datasetId) );
DatasetVersion dsv = getDatasetVersionOrDie(req, versionNumber, findDatasetOrDie(datasetId), uriInfo, headers );

Map<MetadataBlock, List<DatasetField>> fieldsByBlock = DatasetField.groupByBlock(dsv.getDatasetFields());
for ( Map.Entry<MetadataBlock, List<DatasetField>> p : fieldsByBlock.entrySet() ) {
Expand Down Expand Up @@ -1418,7 +1420,7 @@ private <T> T handleVersion( String versionId, DsVersionHandler<T> hdl )
}
}

private DatasetVersion getDatasetVersionOrDie( final DataverseRequest req, String versionNumber, final Dataset ds ) throws WrappedResponse {
private DatasetVersion getDatasetVersionOrDie( final DataverseRequest req, String versionNumber, final Dataset ds, UriInfo uriInfo, HttpHeaders headers) throws WrappedResponse {
DatasetVersion dsv = execCommand( handleVersion(versionNumber, new DsVersionHandler<Command<DatasetVersion>>(){

@Override
Expand All @@ -1444,6 +1446,10 @@ public Command<DatasetVersion> handleLatestPublished() {
if ( dsv == null || dsv.getId() == null ) {
throw new WrappedResponse( notFound("Dataset version " + versionNumber + " of dataset " + ds.getId() + " not found") );
}

MakeDataCountLoggingServiceBean.MakeDataCountEntry entry = new MakeDataCountEntry(uriInfo, headers, dvRequestService, ds);
mdcLogService.logEntry(entry);

return dsv;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,16 @@ public MakeDataCountEntry(FacesContext fc, DataverseRequestServiceBean dvRequest
setPublisherId("tbd"); //"tbd" is a special case in counter processor that gives values that pass MDC.
setTitle(publishedVersion.getTitle());
setVersion(String.valueOf(publishedVersion.getVersionNumber()));
setPublicationYear(new SimpleDateFormat("yyyy").format(publishedVersion.getReleaseTime()));

Date releaseTime = publishedVersion.getReleaseTime();
if(null == releaseTime) { //Seems to be null when called from Datasets api
releaseTime = publishedVersion.getLastUpdateTime();
}
setPublicationYear(new SimpleDateFormat("yyyy").format(releaseTime));

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
setPublicationDate(format.format(publishedVersion.getReleaseTime()));
setPublicationDate(format.format(releaseTime));
}

if(dvRequestService != null) {
Expand Down

0 comments on commit 6375598

Please sign in to comment.