diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/ActivityController.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/ActivityController.java index d69762b31..95c6053c9 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/ActivityController.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/ActivityController.java @@ -8,6 +8,7 @@ import org.opendatadiscovery.oddplatform.api.contract.model.ActivityCountInfo; import org.opendatadiscovery.oddplatform.api.contract.model.ActivityEventType; import org.opendatadiscovery.oddplatform.api.contract.model.ActivityType; +import org.opendatadiscovery.oddplatform.api.contract.model.ActivityUserList; import org.opendatadiscovery.oddplatform.service.activity.ActivityService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -28,7 +29,7 @@ public Mono>> getActivity(final OffsetDateTime beg final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityType type, final ActivityEventType eventType, final Long lasEventId, @@ -36,7 +37,7 @@ public Mono>> getActivity(final OffsetDateTime beg final ServerWebExchange exchange) { return Mono.just( activityService.getActivityList(beginDate, endDate, size, datasourceId, namespaceId, tagIds, ownerIds, - userIds, type, eventType, lasEventId, lastEventDateTime)) + usernames, type, eventType, lasEventId, lastEventDateTime)) .map(ResponseEntity::ok); } @@ -47,11 +48,20 @@ public Mono> getActivityCounts(final OffsetDat final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityEventType eventType, final ServerWebExchange exchange) { return activityService.getActivityCounts(beginDate, endDate, datasourceId, namespaceId, - tagIds, ownerIds, userIds, eventType) + tagIds, ownerIds, usernames, eventType) + .map(ResponseEntity::ok); + } + + @Override + public Mono> getUsersList(final Integer page, + final Integer size, + final String query, + final ServerWebExchange exchange) { + return activityService.getUsersList(page, size, query) .map(ResponseEntity::ok); } } diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/DataEntityController.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/DataEntityController.java index 6342f562c..058e3cd47 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/DataEntityController.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/controller/DataEntityController.java @@ -353,13 +353,13 @@ public Mono>> getDataEntityActivity(final Long dat final OffsetDateTime beginDate, final OffsetDateTime endDate, final Integer size, - final List userIds, + final List usernames, final ActivityEventType eventType, final Long lastEventId, final OffsetDateTime lastEventDateTime, final ServerWebExchange exchange) { return Mono.just( - activityService.getDataEntityActivityList(beginDate, endDate, size, dataEntityId, userIds, eventType, + activityService.getDataEntityActivityList(beginDate, endDate, size, dataEntityId, usernames, eventType, lastEventId, lastEventDateTime) ).map(ResponseEntity::ok); } diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/dto/activity/UsernameDto.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/dto/activity/UsernameDto.java new file mode 100644 index 000000000..74c71f747 --- /dev/null +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/dto/activity/UsernameDto.java @@ -0,0 +1,6 @@ +package org.opendatadiscovery.oddplatform.dto.activity; + +import org.opendatadiscovery.oddplatform.model.tables.pojos.OwnerPojo; + +public record UsernameDto(String username, OwnerPojo ownerPojo) { +} \ No newline at end of file diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/mapper/ActivityMapper.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/mapper/ActivityMapper.java index 6333cbd8b..c5388317f 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/mapper/ActivityMapper.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/mapper/ActivityMapper.java @@ -4,6 +4,7 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.collections4.CollectionUtils; import org.jooq.JSONB; import org.mapstruct.Mapper; @@ -12,6 +13,8 @@ import org.mapstruct.NullValueCheckStrategy; import org.opendatadiscovery.oddplatform.api.contract.model.Activity; import org.opendatadiscovery.oddplatform.api.contract.model.ActivityState; +import org.opendatadiscovery.oddplatform.api.contract.model.ActivityUser; +import org.opendatadiscovery.oddplatform.api.contract.model.ActivityUserList; import org.opendatadiscovery.oddplatform.api.contract.model.AlertHaltConfigActivityState; import org.opendatadiscovery.oddplatform.api.contract.model.AlertReceivedActivityState; import org.opendatadiscovery.oddplatform.api.contract.model.AlertStatusUpdatedActivityState; @@ -31,6 +34,7 @@ import org.opendatadiscovery.oddplatform.api.contract.model.DatasetFieldValuesActivityState; import org.opendatadiscovery.oddplatform.api.contract.model.DescriptionActivityState; import org.opendatadiscovery.oddplatform.api.contract.model.OwnershipActivityState; +import org.opendatadiscovery.oddplatform.api.contract.model.PageInfo; import org.opendatadiscovery.oddplatform.api.contract.model.TagActivityState; import org.opendatadiscovery.oddplatform.api.contract.model.TermActivityState; import org.opendatadiscovery.oddplatform.dto.AssociatedOwnerDto; @@ -53,10 +57,12 @@ import org.opendatadiscovery.oddplatform.dto.activity.OwnershipActivityStateDto; import org.opendatadiscovery.oddplatform.dto.activity.TagActivityStateDto; import org.opendatadiscovery.oddplatform.dto.activity.TermActivityStateDto; +import org.opendatadiscovery.oddplatform.dto.activity.UsernameDto; import org.opendatadiscovery.oddplatform.model.tables.pojos.ActivityPojo; import org.opendatadiscovery.oddplatform.model.tables.pojos.DataEntityPojo; import org.opendatadiscovery.oddplatform.service.ingestion.util.DateTimeUtil; import org.opendatadiscovery.oddplatform.utils.JSONSerDeUtils; +import org.opendatadiscovery.oddplatform.utils.Page; import org.springframework.beans.factory.annotation.Autowired; @Mapper(config = MapperConfig.class, uses = {DateTimeMapper.class}) @@ -309,4 +315,17 @@ AssociatedOwner mapUser(final ActivityDto activityDto) { return associatedOwnerMapper.mapAssociatedOwner( new AssociatedOwnerDto(activityDto.activity().getCreatedBy(), activityDto.user(), null)); } + + public ActivityUserList mapToActivityUserList(final Page usernameDtos) { + return new ActivityUserList() + .items(mapActivityUsers(usernameDtos.getData())) + .pageInfo(new PageInfo().total(usernameDtos.getTotal())); + } + + private List mapActivityUsers(final List dtos) { + return dtos.stream().map(this::mapToActivityUser).collect(Collectors.toList()); + } + + @Mapping(source = "ownerPojo.id", target = "ownerId") + abstract ActivityUser mapToActivityUser(final UsernameDto dto); } diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveActivityRepository.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveActivityRepository.java index 878a1b9ae..fc6d39190 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveActivityRepository.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveActivityRepository.java @@ -4,7 +4,9 @@ import java.util.List; import org.opendatadiscovery.oddplatform.dto.activity.ActivityDto; import org.opendatadiscovery.oddplatform.dto.activity.ActivityEventTypeDto; +import org.opendatadiscovery.oddplatform.dto.activity.UsernameDto; import org.opendatadiscovery.oddplatform.model.tables.pojos.ActivityPojo; +import org.opendatadiscovery.oddplatform.utils.Page; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -20,7 +22,7 @@ Flux findAllActivities(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long lastEventId, final OffsetDateTime lastEventDateTime); @@ -31,7 +33,7 @@ Flux findMyActivities(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long currentOwnerId, final Long lastEventId, @@ -43,7 +45,7 @@ Flux findDependentActivities(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final List oddrns, final Long lastEventId, @@ -53,7 +55,7 @@ Flux findDataEntityActivities(final OffsetDateTime beginDate, final OffsetDateTime endDate, final Integer size, final Long dataEntityId, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long lastEventId, final OffsetDateTime lastEventDateTime); @@ -64,7 +66,7 @@ Mono getTotalActivitiesCount(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType); Mono getMyObjectsActivitiesCount(final OffsetDateTime beginDate, @@ -72,7 +74,7 @@ Mono getMyObjectsActivitiesCount(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long currentOwnerId); @@ -81,7 +83,9 @@ Mono getDependentActivitiesCount(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final List oddrns); + + Mono> getUsersList(final Integer page, final Integer size, final String query); } diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveActivityRepositoryImpl.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveActivityRepositoryImpl.java index 798c3bd59..b3cb9095b 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveActivityRepositoryImpl.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveActivityRepositoryImpl.java @@ -9,22 +9,32 @@ import java.util.stream.Stream; import lombok.RequiredArgsConstructor; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.Condition; import org.jooq.DatePart; import org.jooq.Field; import org.jooq.InsertSetStep; import org.jooq.Record; +import org.jooq.Record1; +import org.jooq.Select; +import org.jooq.SelectConditionStep; import org.jooq.SelectJoinStep; +import org.jooq.SortOrder; +import org.jooq.Table; import org.jooq.impl.DSL; import org.opendatadiscovery.oddplatform.dto.activity.ActivityDto; import org.opendatadiscovery.oddplatform.dto.activity.ActivityEventTypeDto; +import org.opendatadiscovery.oddplatform.dto.activity.UsernameDto; import org.opendatadiscovery.oddplatform.model.tables.pojos.ActivityPojo; import org.opendatadiscovery.oddplatform.model.tables.pojos.DataEntityPojo; import org.opendatadiscovery.oddplatform.model.tables.pojos.OwnerPojo; import org.opendatadiscovery.oddplatform.model.tables.records.ActivityRecord; +import org.opendatadiscovery.oddplatform.repository.util.JooqQueryHelper; 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; import reactor.core.publisher.Mono; @@ -45,6 +55,7 @@ public class ReactiveActivityRepositoryImpl implements ReactiveActivityRepository { private final JooqReactiveOperations jooqReactiveOperations; private final JooqRecordHelper jooqRecordHelper; + private final JooqQueryHelper jooqQueryHelper; @Override public Mono saveReturning(final ActivityPojo pojo) { @@ -78,13 +89,13 @@ public Flux findAllActivities(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long lastEventId, final OffsetDateTime lastEventDateTime) { final var baseQuery = buildBaseQuery(datasourceId, namespaceId, tagIds, ownerIds); final List conditions = getCommonConditions(beginDate, endDate, datasourceId, namespaceId, tagIds, - ownerIds, userIds, eventType); + ownerIds, usernames, eventType); return findActivities(baseQuery, conditions, lastEventId, lastEventDateTime, size); } @@ -95,14 +106,14 @@ public Flux findMyActivities(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long currentOwnerId, final Long lastEventId, final OffsetDateTime lastEventDateTime) { final var baseQuery = buildBaseQuery(datasourceId, namespaceId, tagIds, List.of(currentOwnerId)); final List conditions = getCommonConditions(beginDate, endDate, datasourceId, namespaceId, tagIds, - List.of(currentOwnerId), userIds, eventType); + List.of(currentOwnerId), usernames, eventType); return findActivities(baseQuery, conditions, lastEventId, lastEventDateTime, size); } @@ -113,14 +124,14 @@ public Flux findDependentActivities(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final List oddrns, final Long lastEventId, final OffsetDateTime lastEventDateTime) { final var baseQuery = buildBaseQuery(datasourceId, namespaceId, tagIds, List.of()); final List conditions = getCommonConditions(beginDate, endDate, datasourceId, namespaceId, tagIds, - List.of(), userIds, eventType); + List.of(), usernames, eventType); conditions.add(DATA_ENTITY.ODDRN.in(oddrns)); return findActivities(baseQuery, conditions, lastEventId, lastEventDateTime, size); } @@ -130,13 +141,13 @@ public Flux findDataEntityActivities(final OffsetDateTime beginDate final OffsetDateTime endDate, final Integer size, final Long dataEntityId, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long lastEventId, final OffsetDateTime lastEventDateTime) { final var baseQuery = buildBaseQuery(null, null, List.of(), List.of()); final List conditions = getCommonConditions(beginDate, endDate, null, null, List.of(), - List.of(), userIds, eventType); + List.of(), usernames, eventType); conditions.add(DATA_ENTITY.ID.eq(dataEntityId)); return findActivities(baseQuery, conditions, lastEventId, lastEventDateTime, size); } @@ -148,7 +159,7 @@ public Mono getTotalActivitiesCount(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType) { final var countQuery = DSL.selectCount() .from(ACTIVITY) @@ -158,7 +169,7 @@ public Mono getTotalActivitiesCount(final OffsetDateTime beginDate, .and(USER_OWNER_MAPPING.DELETED_AT.isNull())); addJoins(countQuery, datasourceId, namespaceId, tagIds, ownerIds); final List conditions = - getCommonConditions(beginDate, endDate, datasourceId, namespaceId, tagIds, ownerIds, userIds, eventType); + getCommonConditions(beginDate, endDate, datasourceId, namespaceId, tagIds, ownerIds, usernames, eventType); return getActivityCount(countQuery, conditions); } @@ -168,7 +179,7 @@ public Mono getMyObjectsActivitiesCount(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long currentOwnerId) { final var countQuery = DSL.selectCount() @@ -179,7 +190,7 @@ public Mono getMyObjectsActivitiesCount(final OffsetDateTime beginDate, .and(USER_OWNER_MAPPING.DELETED_AT.isNull())); addJoins(countQuery, datasourceId, namespaceId, tagIds, List.of(currentOwnerId)); final List conditions = getCommonConditions(beginDate, endDate, datasourceId, namespaceId, tagIds, - List.of(currentOwnerId), userIds, eventType); + List.of(currentOwnerId), usernames, eventType); return getActivityCount(countQuery, conditions); } @@ -189,7 +200,7 @@ public Mono getDependentActivitiesCount(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final List oddrns) { final var countQuery = DSL.selectCount() @@ -200,11 +211,45 @@ public Mono getDependentActivitiesCount(final OffsetDateTime beginDate, .and(USER_OWNER_MAPPING.DELETED_AT.isNull())); addJoins(countQuery, datasourceId, namespaceId, tagIds, List.of()); final List conditions = getCommonConditions(beginDate, endDate, datasourceId, namespaceId, tagIds, - List.of(), userIds, eventType); + List.of(), usernames, eventType); conditions.add(DATA_ENTITY.ODDRN.in(oddrns)); return getActivityCount(countQuery, conditions); } + @Override + public Mono> getUsersList(final Integer page, final Integer size, final String query) { + final var select = + DSL.selectDistinct(ACTIVITY.CREATED_BY).from(ACTIVITY) + .where(ACTIVITY.CREATED_BY.isNotNull()) + .and(StringUtils.isBlank(query) + ? DSL.noCondition() + : ACTIVITY.CREATED_BY.containsIgnoreCase(query)); + + final Select userSelect = + jooqQueryHelper.paginate(select, List.of(new OrderByField(ACTIVITY.CREATED_BY, SortOrder.ASC)), + (page - 1) * size, + size); + + final Table userCTE = userSelect.asTable("user_cte"); + + final var resultQuery = DSL.with(userCTE.getName()) + .as(userSelect) + .select(userCTE.fields()) + .select(OWNER.fields()) + .from(userCTE) + .leftJoin(USER_OWNER_MAPPING).on(USER_OWNER_MAPPING.OIDC_USERNAME.eq(userCTE.field(ACTIVITY.CREATED_BY)) + .and(USER_OWNER_MAPPING.DELETED_AT.isNull())) + .leftJoin(OWNER).on(OWNER.ID.eq(USER_OWNER_MAPPING.OWNER_ID)); + + return jooqReactiveOperations.flux(resultQuery) + .collectList() + .flatMap(records -> jooqQueryHelper.pageifyResult( + records, + this::mapRecordToUsernameDto, + fetchCount(query) + )); + } + private SelectJoinStep buildBaseQuery(final Long datasourceId, final Long namespaceId, final List tagIds, final List ownerIds) { final List> selectFields = Stream @@ -249,7 +294,7 @@ private List getCommonConditions(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType) { final List conditions = new ArrayList<>(); conditions.add(ACTIVITY.CREATED_AT.greaterOrEqual(DateTimeUtil.mapUTCDateTime(beginDate))); @@ -269,10 +314,10 @@ private List getCommonConditions(final OffsetDateTime beginDate, if (CollectionUtils.isNotEmpty(ownerIds)) { conditions.add(OWNERSHIP.OWNER_ID.in(ownerIds)); } - if (CollectionUtils.isNotEmpty(userIds)) { - conditions.add(USER_OWNER_MAPPING.OWNER_ID.in(userIds)); - conditions.add(USER_OWNER_MAPPING.DELETED_AT.isNull()); + if (CollectionUtils.isNotEmpty(usernames)) { + conditions.add(ACTIVITY.CREATED_BY.in(usernames)); } + return conditions; } @@ -307,4 +352,24 @@ private ActivityDto mapDto(final Record r) { final OwnerPojo user = jooqRecordHelper.extractRelation(r, OWNER, OwnerPojo.class); return new ActivityDto(activity, user, dataEntity); } + + private UsernameDto mapRecordToUsernameDto(final Record r) { + return new UsernameDto( + r.get(ACTIVITY.CREATED_BY, String.class), + jooqRecordHelper.extractRelation(r, OWNER, OwnerPojo.class) + ); + } + + private Mono fetchCount(final String query) { + final SelectConditionStep> select = + DSL.select(DSL.countDistinct(ACTIVITY.CREATED_BY)).from(ACTIVITY) + .where(ACTIVITY.CREATED_BY.isNotNull()) + .and(StringUtils.isBlank(query) + ? DSL.noCondition() + : ACTIVITY.CREATED_BY.containsIgnoreCase(query)); + + return jooqReactiveOperations + .mono(select) + .map(r -> r.component1().longValue()); + } } \ No newline at end of file diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/activity/ActivityService.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/activity/ActivityService.java index 20ea6bf52..c446ffe3e 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/activity/ActivityService.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/activity/ActivityService.java @@ -7,6 +7,7 @@ import org.opendatadiscovery.oddplatform.api.contract.model.ActivityCountInfo; import org.opendatadiscovery.oddplatform.api.contract.model.ActivityEventType; import org.opendatadiscovery.oddplatform.api.contract.model.ActivityType; +import org.opendatadiscovery.oddplatform.api.contract.model.ActivityUserList; import org.opendatadiscovery.oddplatform.dto.activity.ActivityContextInfo; import org.opendatadiscovery.oddplatform.dto.activity.ActivityCreateEvent; import org.opendatadiscovery.oddplatform.dto.activity.ActivityEventTypeDto; @@ -36,7 +37,7 @@ Flux getActivityList(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityType type, final ActivityEventType eventType, final Long lastEventId, @@ -46,7 +47,7 @@ Flux getDataEntityActivityList(final OffsetDateTime beginDate, final OffsetDateTime endDate, final Integer size, final Long dataEntityId, - final List userIds, + final List usernames, final ActivityEventType eventType, final Long lastEventId, final OffsetDateTime lastEventDateTime); @@ -57,6 +58,8 @@ Mono getActivityCounts(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityEventType eventType); + + Mono getUsersList(final Integer page, final Integer size, final String query); } diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/activity/ActivityServiceImpl.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/activity/ActivityServiceImpl.java index 93257de8c..514f2fbb2 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/activity/ActivityServiceImpl.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/service/activity/ActivityServiceImpl.java @@ -11,6 +11,7 @@ import org.opendatadiscovery.oddplatform.api.contract.model.ActivityCountInfo; import org.opendatadiscovery.oddplatform.api.contract.model.ActivityEventType; import org.opendatadiscovery.oddplatform.api.contract.model.ActivityType; +import org.opendatadiscovery.oddplatform.api.contract.model.ActivityUserList; import org.opendatadiscovery.oddplatform.auth.AuthIdentityProvider; import org.opendatadiscovery.oddplatform.dto.activity.ActivityContextInfo; import org.opendatadiscovery.oddplatform.dto.activity.ActivityCreateEvent; @@ -90,7 +91,7 @@ public Flux getActivityList(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityType type, final ActivityEventType eventType, final Long lastEventId, @@ -102,17 +103,17 @@ public Flux getActivityList(final OffsetDateTime beginDate, eventType != null ? ActivityEventTypeDto.valueOf(eventType.name()) : null; if (type == null) { return fetchAllActivities(beginDate, endDate, size, datasourceId, namespaceId, tagIds, ownerIds, - userIds, eventTypeDto, lastEventId, lastEventDateTime); + usernames, eventTypeDto, lastEventId, lastEventDateTime); } return switch (type) { - case MY_OBJECTS -> fetchMyActivities(beginDate, endDate, size, datasourceId, namespaceId, tagIds, userIds, + case MY_OBJECTS -> fetchMyActivities(beginDate, endDate, size, datasourceId, namespaceId, tagIds, usernames, eventTypeDto, lastEventId, lastEventDateTime); case DOWNSTREAM -> fetchDependentActivities(beginDate, endDate, size, datasourceId, namespaceId, tagIds, - userIds, eventTypeDto, lastEventId, lastEventDateTime, LineageStreamKind.DOWNSTREAM); + usernames, eventTypeDto, lastEventId, lastEventDateTime, LineageStreamKind.DOWNSTREAM); case UPSTREAM -> fetchDependentActivities(beginDate, endDate, size, datasourceId, namespaceId, tagIds, - userIds, eventTypeDto, lastEventId, lastEventDateTime, LineageStreamKind.UPSTREAM); + usernames, eventTypeDto, lastEventId, lastEventDateTime, LineageStreamKind.UPSTREAM); case ALL -> fetchAllActivities(beginDate, endDate, size, datasourceId, namespaceId, tagIds, ownerIds, - userIds, eventTypeDto, lastEventId, lastEventDateTime); + usernames, eventTypeDto, lastEventId, lastEventDateTime); }; } @@ -121,7 +122,7 @@ public Flux getDataEntityActivityList(final OffsetDateTime beginDate, final OffsetDateTime endDate, final Integer size, final Long dataEntityId, - final List userIds, + final List usernames, final ActivityEventType eventType, final Long lastEventId, final OffsetDateTime lastEventDateTime) { @@ -130,7 +131,7 @@ public Flux getDataEntityActivityList(final OffsetDateTime beginDate, } final ActivityEventTypeDto eventTypeDto = eventType != null ? ActivityEventTypeDto.valueOf(eventType.name()) : null; - return activityRepository.findDataEntityActivities(beginDate, endDate, size, dataEntityId, userIds, + return activityRepository.findDataEntityActivities(beginDate, endDate, size, dataEntityId, usernames, eventTypeDto, lastEventId, lastEventDateTime) .map(activityMapper::mapToActivity); } @@ -142,19 +143,19 @@ public Mono getActivityCounts(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityEventType eventType) { final ActivityEventTypeDto eventTypeDto = eventType != null ? ActivityEventTypeDto.valueOf(eventType.name()) : null; final Mono totalCount = - getTotalCount(beginDate, endDate, datasourceId, namespaceId, tagIds, ownerIds, userIds, eventTypeDto); + getTotalCount(beginDate, endDate, datasourceId, namespaceId, tagIds, ownerIds, usernames, eventTypeDto); final Mono myObjectActivitiesCount = getMyObjectActivitiesCount(beginDate, endDate, datasourceId, namespaceId, - tagIds, userIds, eventTypeDto); + tagIds, usernames, eventTypeDto); final Mono downstreamActivitiesCount = getDependentActivitiesCount(beginDate, endDate, datasourceId, - namespaceId, tagIds, userIds, eventTypeDto, LineageStreamKind.DOWNSTREAM); + namespaceId, tagIds, usernames, eventTypeDto, LineageStreamKind.DOWNSTREAM); final Mono upstreamActivitiesCount = getDependentActivitiesCount(beginDate, endDate, datasourceId, - namespaceId, tagIds, userIds, eventTypeDto, LineageStreamKind.UPSTREAM); + namespaceId, tagIds, usernames, eventTypeDto, LineageStreamKind.UPSTREAM); return Mono.zip(totalCount, myObjectActivitiesCount, downstreamActivitiesCount, upstreamActivitiesCount) .map(function( (total, myObjectsCount, downstreamCount, upstreamCount) -> new ActivityCountInfo() @@ -165,6 +166,12 @@ public Mono getActivityCounts(final OffsetDateTime beginDate, )); } + @Override + public Mono getUsersList(final Integer page, final Integer size, final String query) { + return activityRepository.getUsersList(page, size, query) + .map(activityMapper::mapToActivityUserList); + } + private Flux fetchAllActivities(final OffsetDateTime beginDate, final OffsetDateTime endDate, final Integer size, @@ -172,12 +179,12 @@ private Flux fetchAllActivities(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long lastEventId, final OffsetDateTime lastEventDateTime) { return activityRepository.findAllActivities(beginDate, endDate, size, datasourceId, namespaceId, tagIds, - ownerIds, userIds, eventType, lastEventId, lastEventDateTime) + ownerIds, usernames, eventType, lastEventId, lastEventDateTime) .map(activityMapper::mapToActivity); } @@ -187,13 +194,13 @@ private Flux fetchMyActivities(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long lastEventId, final OffsetDateTime lastEventDateTime) { return authIdentityProvider.fetchAssociatedOwner() .flatMapMany(owner -> activityRepository.findMyActivities(beginDate, endDate, size, datasourceId, - namespaceId, tagIds, userIds, eventType, owner.getId(), lastEventId, lastEventDateTime)) + namespaceId, tagIds, usernames, eventType, owner.getId(), lastEventId, lastEventDateTime)) .map(activityMapper::mapToActivity) .switchIfEmpty(Flux.empty()); } @@ -204,14 +211,14 @@ private Flux fetchDependentActivities(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final Long lastEventId, final OffsetDateTime lastEventDateTime, final LineageStreamKind lineageStreamKind) { return dataEntityRelationsService.getDependentDataEntityOddrns(lineageStreamKind) .flatMapMany(oddrns -> activityRepository.findDependentActivities(beginDate, endDate, size, datasourceId, - namespaceId, tagIds, userIds, eventType, oddrns, lastEventId, lastEventDateTime)) + namespaceId, tagIds, usernames, eventType, oddrns, lastEventId, lastEventDateTime)) .map(activityMapper::mapToActivity) .switchIfEmpty(Flux.empty()); } @@ -222,10 +229,10 @@ private Mono getTotalCount(final OffsetDateTime beginDate, final Long namespaceId, final List tagIds, final List ownerIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType) { return activityRepository.getTotalActivitiesCount(beginDate, endDate, datasourceId, namespaceId, tagIds, - ownerIds, userIds, eventType) + ownerIds, usernames, eventType) .defaultIfEmpty(0L); } @@ -234,12 +241,12 @@ private Mono getMyObjectActivitiesCount(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType) { return authIdentityProvider.fetchAssociatedOwner() .flatMap( owner -> activityRepository.getMyObjectsActivitiesCount(beginDate, endDate, datasourceId, namespaceId, - tagIds, userIds, eventType, owner.getId())) + tagIds, usernames, eventType, owner.getId())) .defaultIfEmpty(0L); } @@ -248,12 +255,12 @@ private Mono getDependentActivitiesCount(final OffsetDateTime beginDate, final Long datasourceId, final Long namespaceId, final List tagIds, - final List userIds, + final List usernames, final ActivityEventTypeDto eventType, final LineageStreamKind lineageStreamKind) { return dataEntityRelationsService.getDependentDataEntityOddrns(lineageStreamKind) .flatMap(oddrns -> activityRepository.getDependentActivitiesCount(beginDate, endDate, datasourceId, - namespaceId, tagIds, userIds, eventType, oddrns)) + namespaceId, tagIds, usernames, eventType, oddrns)) .defaultIfEmpty(0L); } diff --git a/odd-platform-specification/components.yaml b/odd-platform-specification/components.yaml index 3e6ad5b7b..bc51de316 100644 --- a/odd-platform-specification/components.yaml +++ b/odd-platform-specification/components.yaml @@ -4159,6 +4159,30 @@ components: body: type: string + ActivityUserList: + type: object + properties: + items: + type: array + items: + $ref: '#/components/schemas/ActivityUser' + page_info: + $ref: '#/components/schemas/PageInfo' + required: + - items + - page_info + + ActivityUser: + type: object + properties: + owner_id: + type: integer + format: int64 + username: + type: string + required: + - name + parameters: PageParam: name: page diff --git a/odd-platform-specification/openapi.yaml b/odd-platform-specification/openapi.yaml index ed08d377a..62b276e0f 100644 --- a/odd-platform-specification/openapi.yaml +++ b/odd-platform-specification/openapi.yaml @@ -1403,13 +1403,12 @@ paths: schema: type: string format: date-time - - name: user_ids + - name: usernames in: query schema: type: array items: - type: integer - format: int64 + type: string - name: event_type in: query schema: @@ -3121,13 +3120,12 @@ paths: items: type: integer format: int64 - - name: user_ids + - name: usernames in: query schema: type: array items: - type: integer - format: int64 + type: string - name: type in: query schema: @@ -3159,6 +3157,27 @@ paths: tags: - activity + /api/activity/users: + get: + summary: List of users + description: Gets the list of existing users + operationId: getUsersList + parameters: + - $ref: './components.yaml/#/components/parameters/SearchParam' + - $ref: './components.yaml/#/components/parameters/PageParam' + - $ref: './components.yaml/#/components/parameters/SizeParam' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: './components.yaml/#/components/schemas/ActivityUserList' + '500': + $ref: './components.yaml/#/components/responses/InternalError' + tags: + - activity + /api/activity/counts: get: summary: Get activity counts @@ -3201,13 +3220,12 @@ paths: items: type: integer format: int64 - - name: user_ids + - name: usernames in: query schema: type: array items: - type: integer - format: int64 + type: string - name: event_type in: query schema: