Skip to content

Commit

Permalink
#526 added showDownloadDetails to DatasetDownloadUsageResource
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed Sep 26, 2023
1 parent 513e3b0 commit 7192bff
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<spring-cloud-sleuth.version>2.2.8.RELEASE</spring-cloud-sleuth.version>

<!-- GBIF -->
<gbif-api.version>1.12.5</gbif-api.version>
<gbif-api.version>1.12.6-SNAPSHOT</gbif-api.version>
<gbif-common.version>0.59</gbif-common.version>
<gbif-common-mybatis.version>1.3</gbif-common-mybatis.version>
<gbif-common-ws.version>1.25</gbif-common-ws.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testAddAndGetOccurrenceDatasetOne(ServiceType serviceType) {
assertEquals(
1,
datasetOccurrenceDownloadUsageService
.listByDataset(testDataset.getKey(), new PagingRequest(0, 3))
.listByDataset(testDataset.getKey(), true, new PagingRequest(0, 3))
.getResults()
.size(),
"List operation should return 1 record");
Expand All @@ -153,7 +153,7 @@ public void testAddAndGetOccurrenceDatasetOne(ServiceType serviceType) {
occurrenceDownloadService.createUsages(occurrenceDownload.getKey(), datasetCitation);
List<DatasetOccurrenceDownloadUsage> usages =
datasetOccurrenceDownloadUsageService
.listByDataset(testDataset.getKey(), new PagingRequest(0, 3))
.listByDataset(testDataset.getKey(), true, new PagingRequest(0, 3))
.getResults();
assertEquals(1, usages.size(), "List operation should return 1 record");
assertEquals(2000L, usages.get(0).getNumberRecords());
Expand Down Expand Up @@ -191,21 +191,21 @@ public void testAddAndGetOccurrenceDatasetMany(ServiceType serviceType) {
assertEquals(
1,
datasetOccurrenceDownloadUsageService
.listByDataset(testDataset1.getKey(), new PagingRequest(0, 3))
.listByDataset(testDataset1.getKey(), true, new PagingRequest(0, 3))
.getResults()
.size(),
"List operation should return 1 record");
assertEquals(
1,
datasetOccurrenceDownloadUsageService
.listByDataset(testDataset2.getKey(), new PagingRequest(0, 3))
.listByDataset(testDataset2.getKey(), true, new PagingRequest(0, 3))
.getResults()
.size(),
"List operation should return 1 record");
assertEquals(
1,
datasetOccurrenceDownloadUsageService
.listByDataset(testDataset3.getKey(), new PagingRequest(0, 3))
.listByDataset(testDataset3.getKey(), true, new PagingRequest(0, 3))
.getResults()
.size(),
"List operation should return 1 record");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ List<DatasetOccurrenceDownloadUsage> listByDataset(
@Param("type") DownloadType type,
@Nullable @Param("page") Pageable page);

List<DatasetOccurrenceDownloadUsage> listByDatasetWithoutDownload(
@Param("datasetKey") UUID datasetKey,
@Param("type") DownloadType type,
@Nullable @Param("page") Pageable page);

int countByDataset(@Param("datasetKey") UUID datasetKey, @Param("type") DownloadType type);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@
</if>
</select>

<select id="listByDatasetWithoutDownload" resultMap="DATASET_OCCURRENCE_OMIT_DOWNLOAD_MAP" parameterType="map">
SELECT <include refid="DATASET_OCCURRENCE_DOWNLOAD_FIELDS"/>
FROM dataset_occurrence_download dod
JOIN occurrence_download od ON dod.download_key = od.key
WHERE dod.dataset_key = #{datasetKey,jdbcType=OTHER}
<if test="type != null">
AND od.type = #{type,jdbcType=OTHER}
</if>
ORDER BY od.created DESC, od.key
<if test="page != null" >
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>

<select id="listByDownload" resultMap="DATASET_OCCURRENCE_OMIT_DOWNLOAD_MAP" parameterType="org.gbif.api.model.common.paging.Pageable">
SELECT <include refid="DATASET_OCCURRENCE_DOWNLOAD_FIELDS"/>,o.country
FROM dataset_occurrence_download dod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

public interface BaseDatasetDownloadUsageClient extends DatasetOccurrenceDownloadUsageService {
Expand All @@ -36,5 +37,8 @@ public interface BaseDatasetDownloadUsageClient extends DatasetOccurrenceDownloa
@ResponseBody
@Override
PagingResponse<DatasetOccurrenceDownloadUsage> listByDataset(
@PathVariable("datasetKey") UUID datasetKey, @SpringQueryMap Pageable pageable);
@PathVariable("datasetKey") UUID datasetKey,
@RequestParam(value = "showDownloadDetails", required = false, defaultValue = "true")
Boolean showDownloadDetails,
@SpringQueryMap Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.gbif.registry.ws.resources;

import org.gbif.api.model.common.paging.Pageable;
import org.gbif.api.model.common.paging.PagingRequest;
import org.gbif.api.model.common.paging.PagingResponse;
import org.gbif.api.model.occurrence.DownloadType;
import org.gbif.api.model.registry.DatasetOccurrenceDownloadUsage;
Expand All @@ -27,6 +28,7 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -50,25 +52,40 @@ public DatasetDownloadUsageResourceBase(
}

@Operation(
operationId = "getDatasetDownloadActivity",
summary = "List the downloads activity of a dataset.",
description = "Lists the downloads in which data from a dataset has been included.")
operationId = "getDatasetDownloadActivity",
summary = "List the downloads activity of a dataset.",
description = "Lists the downloads in which data from a dataset has been included.")
@Parameter(name = "datasetKey", description = "The key of the dataset.", in = ParameterIn.PATH)
@Parameter(
name = "datasetKey",
description = "The key of the dataset.",
in = ParameterIn.PATH)
name = "showDownloadDetails",
description = "Flag to indicate if we want the download details in the response.",
in = ParameterIn.QUERY)
@Pageable.OffsetLimitParameters
@ApiResponse(
responseCode = "200",
description = "Dataset found and download information returned")
responseCode = "200",
description = "Dataset found and download information returned")
@Docs.DefaultUnsuccessfulReadResponses
@GetMapping("{datasetKey}")
@Override
public PagingResponse<DatasetOccurrenceDownloadUsage> listByDataset(
@PathVariable UUID datasetKey, Pageable page) {
@PathVariable UUID datasetKey,
@RequestParam(value = "showDownloadDetails", required = false, defaultValue = "true")
Boolean showDownloadDetails,
Pageable page) {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
List<DatasetOccurrenceDownloadUsage> usages =
datasetOccurrenceDownloadMapper.listByDataset(datasetKey, downloadType, page);

if (Boolean.TRUE.equals(showDownloadDetails) && page.getLimit() > 100) {
page = new PagingRequest(page.getOffset(), 100);
}

List<DatasetOccurrenceDownloadUsage> usages = null;
if (Boolean.FALSE.equals(showDownloadDetails)) {
usages =
datasetOccurrenceDownloadMapper.listByDatasetWithoutDownload(
datasetKey, downloadType, page);
} else {
usages = datasetOccurrenceDownloadMapper.listByDataset(datasetKey, downloadType, page);
}
clearSensitiveData(authentication, usages);
return new PagingResponse<>(
page,
Expand Down

0 comments on commit 7192bff

Please sign in to comment.