Skip to content

Commit

Permalink
ListByUser and CountByUser in OccurrenceDownloadResource using LocalD…
Browse files Browse the repository at this point in the history
…ateTime instead of Date
  • Loading branch information
marcos-lg committed Aug 1, 2023
1 parent bf7f34b commit 490e5c1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.gbif.ws.security.KeyStore;

import java.security.AccessControlException;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Collections;
Expand Down Expand Up @@ -419,6 +420,8 @@ public void testListBySourceAndStatus(ServiceType serviceType) {
@ParameterizedTest
@EnumSource(ServiceType.class)
public void testListByUserAndStatus(ServiceType serviceType) {
LocalDateTime.now().atOffset(ZoneOffset.UTC).toString();

OccurrenceDownloadService service =
getService(serviceType, occurrenceDownloadResource, occurrenceDownloadClient);
for (int i = 1; i <= 5; i++) {
Expand All @@ -430,7 +433,7 @@ public void testListByUserAndStatus(ServiceType serviceType) {
TestConstants.TEST_ADMIN,
new PagingRequest(0, 5),
Download.Status.EXECUTING_STATUSES,
null,
LocalDateTime.now().minusMinutes(30),
true);

assertTrue(
Expand All @@ -441,8 +444,25 @@ public void testListByUserAndStatus(ServiceType serviceType) {
service.countByUser(
TestConstants.TEST_ADMIN,
Download.Status.EXECUTING_STATUSES,
null);
LocalDateTime.now().minusMinutes(30));
assertEquals(downloads.getResults().size(), count);

assertEquals(
0,
service
.listByUser(
TestConstants.TEST_ADMIN,
new PagingRequest(0, 5),
Download.Status.EXECUTING_STATUSES,
LocalDateTime.now(),
true)
.getResults()
.size());

assertEquals(
0,
service.countByUser(
TestConstants.TEST_ADMIN, Download.Status.EXECUTING_STATUSES, LocalDateTime.now()));
}

/** Tests the status update of {@link Download}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.gbif.api.model.occurrence.DownloadStatistics;
import org.gbif.api.model.occurrence.DownloadType;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -65,20 +66,20 @@ List<Download> listByUserLightweight(
@Nullable @Param("page") Pageable page,
@Param("status") Set<Download.Status> status,
@Nullable @Param("type") DownloadType type,
@Nullable @Param("from") Date from);
@Nullable @Param("from") LocalDateTime from);

List<Download> listByUser(
@Param("creator") String creator,
@Nullable @Param("page") Pageable page,
@Param("status") Set<Download.Status> status,
@Nullable @Param("type") DownloadType type,
@Nullable @Param("from") Date from);
@Nullable @Param("from") LocalDateTime from);

int countByUser(
@Param("creator") String creator,
@Param("status") Set<Download.Status> status,
@Nullable @Param("type") DownloadType type,
@Nullable @Param("from") Date from);
@Nullable @Param("from") LocalDateTime from);

List<Download> listByEraseAfter(
@Nullable @Param("page") Pageable page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import org.gbif.api.vocabulary.OrganizationUsageSortField;
import org.gbif.api.vocabulary.SortOrder;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -83,7 +85,9 @@ PagingResponse<Download> listByUser(
@PathVariable("user") String user,
@SpringQueryMap Pageable pageable,
@RequestParam(value = "status", required = false) Set<Download.Status> status,
@RequestParam(value = "from", required = false) Date from,
@RequestParam(value = "from", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
LocalDateTime from,
@RequestParam(
value = "statistics",
required = false,
Expand All @@ -99,7 +103,9 @@ PagingResponse<Download> listByUser(
long countByUser(
@PathVariable("user") String user,
@RequestParam(value = "status", required = false) Set<Download.Status> status,
@RequestParam(value = "from", required = false) Date from);
@RequestParam(value = "from", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
LocalDateTime from);

@RequestMapping(
method = RequestMethod.GET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.EnumSet;
import java.util.List;
Expand All @@ -81,6 +82,7 @@
import org.slf4j.MarkerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -372,7 +374,9 @@ public PagingResponse<Download> listByUser(
@PathVariable String user,
Pageable page,
@RequestParam(value = "status", required = false) Set<Download.Status> status,
@RequestParam(value = "from", required = false) Date from,
@RequestParam(value = "from", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
LocalDateTime from,
@RequestParam(
value = "statistics",
required = false,
Expand Down Expand Up @@ -424,7 +428,9 @@ public PagingResponse<Download> listByUser(
public long countByUser(
@PathVariable String user,
@RequestParam(value = "status", required = false) Set<Download.Status> status,
@RequestParam(value = "from", required = false) Date from) {
@RequestParam(value = "from", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
LocalDateTime from) {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
checkUserIsInSecurityContext(user, authentication);
return occurrenceDownloadMapper.countByUser(user, status, downloadType, from);
Expand Down

0 comments on commit 490e5c1

Please sign in to comment.