Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1680 - updated ape/terms api. Added updated_at field and start/end date query params #1685

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opendatadiscovery.oddplatform.controller;

import java.time.LocalDate;
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 LocalDate updatedAtRangeStartDateTime,
final LocalDate 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.LocalDate;
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 LocalDate updatedAtRangeStartDateTime,
final LocalDate 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.LocalDate;
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 @@ -102,9 +105,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 LocalDate updatedAtRangeStartDateTime,
final LocalDate 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 +633,23 @@ private List<LinkedTermDto> extractTerms(final Record record) {
})
.toList();
}

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

final List<Condition> conditions = new ArrayList<>();

if (updatedAtRangeStartDateTime != null) {
conditions.add(TERM.UPDATED_AT.greaterOrEqual(updatedAtRangeStartDateTime.atStartOfDay()));
}

if (updatedAtRangeEndDateTime != null) {
conditions.add(TERM.UPDATED_AT.lessThan(updatedAtRangeEndDateTime.atStartOfDay()));
}

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.LocalDate;
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,8 @@
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 LocalDate updatedAtRangeStartDateTime, final LocalDate 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.LocalDate;
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 LocalDate updatedAtRangeStartDateTime,
final LocalDate 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
- name: updated_at_range_end_date_time
in: query
required: false
schema:
type: string
format: date
responses:
'200':
description: OK
Expand Down
Loading