From 83e94792e4cc9846db088473aa2e828b85ea48bb Mon Sep 17 00:00:00 2001 From: Vladysl <45620393+Vladysl@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:20:35 +0300 Subject: [PATCH] 1680 - updated ape/terms api. Added updated_at field and start/end date query params (#1685) --- .../controller/TermController.java | 5 +++- .../reactive/ReactiveTermRepository.java | 5 +++- .../reactive/ReactiveTermRepositoryImpl.java | 30 +++++++++++++++++-- .../oddplatform/service/term/TermService.java | 5 +++- .../service/term/TermServiceImpl.java | 7 +++-- odd-platform-specification/components.yaml | 3 ++ odd-platform-specification/openapi.yaml | 12 ++++++++ 7 files changed, 60 insertions(+), 7 deletions(-) diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/TermController.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/TermController.java index 5d7e6fc9f..25841a116 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/TermController.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/TermController.java @@ -1,5 +1,6 @@ package org.opendatadiscovery.oddplatform.controller; +import java.time.OffsetDateTime; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.opendatadiscovery.oddplatform.api.contract.api.TermApi; @@ -50,8 +51,10 @@ public class TermController implements TermApi { @Override public Mono> getTermsList(final Integer page, final Integer size, final String query, + final OffsetDateTime updatedAtRangeStartDateTime, + final OffsetDateTime updatedAtRangeEndDateTime, final ServerWebExchange exchange) { - return termService.getTerms(page, size, query) + return termService.getTerms(page, size, query, updatedAtRangeStartDateTime, updatedAtRangeEndDateTime) .map(ResponseEntity::ok); } diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTermRepository.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTermRepository.java index 81b5d2f18..426788358 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTermRepository.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTermRepository.java @@ -1,5 +1,6 @@ package org.opendatadiscovery.oddplatform.repository.reactive; +import java.time.OffsetDateTime; import java.util.List; import org.opendatadiscovery.oddplatform.dto.FacetStateDto; import org.opendatadiscovery.oddplatform.dto.term.LinkedTermDto; @@ -14,7 +15,9 @@ public interface ReactiveTermRepository extends ReactiveCRUDRepository { - Mono> listTermRefDtos(final int page, final int size, final String query); + Mono> listTermRefDtos(final int page, final int size, final String query, + final OffsetDateTime updatedAtRangeStartDateTime, + final OffsetDateTime updatedAtRangeEndDateTime); Mono existsByNamespace(final Long namespaceId); diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTermRepositoryImpl.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTermRepositoryImpl.java index 023069a7b..37a5ace83 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTermRepositoryImpl.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTermRepositoryImpl.java @@ -1,13 +1,16 @@ package org.opendatadiscovery.oddplatform.repository.reactive; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.StringUtils; import org.jooq.Condition; import org.jooq.Field; @@ -42,6 +45,7 @@ import org.opendatadiscovery.oddplatform.repository.util.JooqReactiveOperations; import org.opendatadiscovery.oddplatform.repository.util.JooqRecordHelper; import org.opendatadiscovery.oddplatform.repository.util.OrderByField; +import org.opendatadiscovery.oddplatform.service.ingestion.util.DateTimeUtil; import org.opendatadiscovery.oddplatform.utils.Page; import org.springframework.stereotype.Repository; import reactor.core.publisher.Flux; @@ -102,9 +106,12 @@ public ReactiveTermRepositoryImpl(final JooqReactiveOperations jooqReactiveOpera } @Override - public Mono> listTermRefDtos(final int page, final int size, final String nameQuery) { + public Mono> listTermRefDtos(final int page, final int size, final String nameQuery, + final OffsetDateTime updatedAtRangeStartDateTime, + final OffsetDateTime updatedAtRangeEndDateTime) { final Select homogeneousQuery = DSL.selectFrom(TERM) - .where(listCondition(nameQuery)); + .where(ListUtils.union(listCondition(nameQuery), + dateConditions(updatedAtRangeStartDateTime, updatedAtRangeEndDateTime))); final Select termSelect = paginate(homogeneousQuery, List.of(new OrderByField(TERM.ID, SortOrder.ASC)), (page - 1) * size, size); @@ -627,4 +634,23 @@ private List extractTerms(final Record record) { }) .toList(); } + + private List dateConditions(final OffsetDateTime updatedAtRangeStartDateTime, + final OffsetDateTime updatedAtRangeEndDateTime) { + if (updatedAtRangeStartDateTime == null && updatedAtRangeEndDateTime == null) { + return Collections.emptyList(); + } + + final List conditions = new ArrayList<>(); + + if (updatedAtRangeStartDateTime != null) { + conditions.add(TERM.UPDATED_AT.greaterOrEqual(DateTimeUtil.mapUTCDateTime(updatedAtRangeStartDateTime))); + } + + if (updatedAtRangeEndDateTime != null) { + conditions.add(TERM.UPDATED_AT.lessThan(DateTimeUtil.mapUTCDateTime(updatedAtRangeEndDateTime))); + } + + return conditions; + } } diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/term/TermService.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/term/TermService.java index b44243caa..d50398f24 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/term/TermService.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/term/TermService.java @@ -1,5 +1,6 @@ package org.opendatadiscovery.oddplatform.service.term; +import java.time.OffsetDateTime; import java.util.List; import org.opendatadiscovery.oddplatform.api.contract.model.LinkedTerm; import org.opendatadiscovery.oddplatform.api.contract.model.LinkedTermList; @@ -14,7 +15,9 @@ import reactor.core.publisher.Mono; public interface TermService { - Mono getTerms(final Integer page, final Integer size, final String query); + Mono getTerms(final Integer page, final Integer size, final String query, + final OffsetDateTime updatedAtRangeStartDateTime, + final OffsetDateTime updatedAtRangeEndDateTime); Mono getTermByNamespaceAndName(final String namespaceName, final String name); diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/term/TermServiceImpl.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/term/TermServiceImpl.java index c89d188fa..5ff15fb2d 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/term/TermServiceImpl.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/term/TermServiceImpl.java @@ -1,5 +1,6 @@ package org.opendatadiscovery.oddplatform.service.term; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -80,8 +81,10 @@ public class TermServiceImpl implements TermService { private final TagMapper tagMapper; @Override - public Mono getTerms(final Integer page, final Integer size, final String query) { - return termRepository.listTermRefDtos(page, size, query) + public Mono getTerms(final Integer page, final Integer size, final String query, + final OffsetDateTime updatedAtRangeStartDateTime, + final OffsetDateTime updatedAtRangeEndDateTime) { + return termRepository.listTermRefDtos(page, size, query, updatedAtRangeStartDateTime, updatedAtRangeEndDateTime) .map(termMapper::mapToRefPage); } diff --git a/odd-platform-specification/components.yaml b/odd-platform-specification/components.yaml index decd7940b..a45e1d260 100644 --- a/odd-platform-specification/components.yaml +++ b/odd-platform-specification/components.yaml @@ -2558,6 +2558,9 @@ components: type: string definition: type: string + updated_at: + type: string + format: date-time namespace: $ref: '#/components/schemas/Namespace' required: diff --git a/odd-platform-specification/openapi.yaml b/odd-platform-specification/openapi.yaml index 60e90c010..2a94ace24 100644 --- a/odd-platform-specification/openapi.yaml +++ b/odd-platform-specification/openapi.yaml @@ -2725,6 +2725,18 @@ paths: - $ref: './components.yaml/#/components/parameters/PageParam' - $ref: './components.yaml/#/components/parameters/SizeParam' - $ref: './components.yaml/#/components/parameters/SearchParam' + - name: updated_at_range_start_date_time + in: query + required: false + schema: + type: string + format: date-time + - name: updated_at_range_end_date_time + in: query + required: false + schema: + type: string + format: date-time responses: '200': description: OK