Skip to content

Commit

Permalink
#726 - lastModifiedDateTime is optional in location external api feed
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels authored and himeshr committed May 15, 2024
1 parent 38a36c1 commit 4425236
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.avni.server.dao.sync.SyncEntityName;
import org.avni.server.domain.*;
import org.avni.server.framework.security.UserContextHolder;
import org.avni.server.web.request.EntitySyncStatusContract;
import org.joda.time.DateTime;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -36,7 +37,7 @@ Page<EntityApprovalStatus> findByLastModifiedDateTimeIsBetweenOrderByLastModifie
default Page<EntityApprovalStatus> findEntityApprovalStatuses(EntityApprovalStatusSearchParams searchParams, Pageable pageable) {

Specification specification = lastModifiedBetween(
CHSEntity.toDate(searchParams.getLastModifiedDateTime() != null ? searchParams.getLastModifiedDateTime() : new DateTime("1900-01-01T00:00:00.000Z")),
CHSEntity.toDate(searchParams.getLastModifiedDateTime() != null ? searchParams.getLastModifiedDateTime() : EntitySyncStatusContract.REALLY_OLD_DATE),
CHSEntity.toDate(searchParams.getNow() != null ? searchParams.getNow() : new DateTime()));

if (searchParams.getEntityType() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.avni.server.dao.LocationRepository;
import org.avni.server.domain.AddressLevel;
import org.avni.server.service.ConceptService;
import org.avni.server.util.DateTimeUtil;
import org.avni.server.web.request.EntitySyncStatusContract;
import org.avni.server.web.response.LocationApiResponse;
import org.avni.server.web.response.ResponsePage;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -32,9 +34,12 @@ public LocationApiController(LocationRepository locationRepository, ConceptRepos

@RequestMapping(value = "/api/locations", method = RequestMethod.GET)
@PreAuthorize(value = "hasAnyAuthority('user')")
public ResponsePage getLocations(@RequestParam(value = "lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime,
public ResponsePage getLocations(@RequestParam(value = "lastModifiedDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime,
@RequestParam(value = "now", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now,
Pageable pageable) {
if (lastModifiedDateTime == null) {
lastModifiedDateTime = EntitySyncStatusContract.REALLY_OLD_DATE;
}
Page<AddressLevel> addresses = locationRepository.findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(lastModifiedDateTime, now, pageable);
ArrayList<LocationApiResponse> locationApiResponses = new ArrayList<>();
addresses.forEach(addressLevel -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.UUID;

public class EntitySyncStatusContract {
private static final DateTime REALLY_OLD_DATE = new DateTime("1900-01-01T00:00:00.000Z");
public static final DateTime REALLY_OLD_DATE = new DateTime("1900-01-01T00:00:00.000Z");
private String uuid;
private String entityName;
private DateTime loadedSince;
Expand Down

0 comments on commit 4425236

Please sign in to comment.