Skip to content

Commit

Permalink
1680 - updated ape/terms api. Added updated_at field and start/end da…
Browse files Browse the repository at this point in the history
…te query params (#1685)
  • Loading branch information
Vladysl authored Jun 5, 2024
1 parent 6d49481 commit 83e9479
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -50,8 +51,10 @@ public class TermController implements TermApi {
@Override
public Mono<ResponseEntity<TermRefList>> 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,7 +15,9 @@

public interface ReactiveTermRepository extends ReactiveCRUDRepository<TermPojo> {

Mono<Page<TermRefDto>> listTermRefDtos(final int page, final int size, final String query);
Mono<Page<TermRefDto>> listTermRefDtos(final int page, final int size, final String query,
final OffsetDateTime updatedAtRangeStartDateTime,
final OffsetDateTime updatedAtRangeEndDateTime);

Mono<Boolean> existsByNamespace(final Long namespaceId);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -102,9 +106,12 @@ public ReactiveTermRepositoryImpl(final JooqReactiveOperations jooqReactiveOpera
}

@Override
public Mono<Page<TermRefDto>> listTermRefDtos(final int page, final int size, final String nameQuery) {
public Mono<Page<TermRefDto>> listTermRefDtos(final int page, final int size, final String nameQuery,
final OffsetDateTime updatedAtRangeStartDateTime,
final OffsetDateTime updatedAtRangeEndDateTime) {
final Select<TermRecord> homogeneousQuery = DSL.selectFrom(TERM)
.where(listCondition(nameQuery));
.where(ListUtils.union(listCondition(nameQuery),
dateConditions(updatedAtRangeStartDateTime, updatedAtRangeEndDateTime)));

final Select<? extends Record> termSelect =
paginate(homogeneousQuery, List.of(new OrderByField(TERM.ID, SortOrder.ASC)), (page - 1) * size, size);
Expand Down Expand Up @@ -627,4 +634,23 @@ private List<LinkedTermDto> extractTerms(final Record record) {
})
.toList();
}

private List<Condition> dateConditions(final OffsetDateTime updatedAtRangeStartDateTime,
final OffsetDateTime updatedAtRangeEndDateTime) {
if (updatedAtRangeStartDateTime == null && updatedAtRangeEndDateTime == null) {
return Collections.emptyList();
}

final List<Condition> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,7 +15,9 @@
import reactor.core.publisher.Mono;

public interface TermService {
Mono<TermRefList> getTerms(final Integer page, final Integer size, final String query);
Mono<TermRefList> getTerms(final Integer page, final Integer size, final String query,
final OffsetDateTime updatedAtRangeStartDateTime,
final OffsetDateTime updatedAtRangeEndDateTime);

Mono<TermRef> getTermByNamespaceAndName(final String namespaceName, final String name);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -80,8 +81,10 @@ public class TermServiceImpl implements TermService {
private final TagMapper tagMapper;

@Override
public Mono<TermRefList> getTerms(final Integer page, final Integer size, final String query) {
return termRepository.listTermRefDtos(page, size, query)
public Mono<TermRefList> 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);
}

Expand Down
3 changes: 3 additions & 0 deletions odd-platform-specification/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,9 @@ components:
type: string
definition:
type: string
updated_at:
type: string
format: date-time
namespace:
$ref: '#/components/schemas/Namespace'
required:
Expand Down
12 changes: 12 additions & 0 deletions odd-platform-specification/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 83e9479

Please sign in to comment.