Skip to content

Commit

Permalink
1622 - added deleted_at to user_owner_mapping table and created creat…
Browse files Browse the repository at this point in the history
…eUserOwnerMapping and deleteUserOwnerMapping API's (#1638)

Co-authored-by: ayemets-corcentric <[email protected]>
  • Loading branch information
Vladysl and anatolii-yemets authored Apr 17, 2024
1 parent 883b47d commit 9c13c99
Show file tree
Hide file tree
Showing 64 changed files with 1,943 additions and 576 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import static org.opendatadiscovery.oddplatform.dto.policy.PolicyPermissionDto.OWNER_ASSOCIATION_MANAGE;
import static org.opendatadiscovery.oddplatform.dto.policy.PolicyPermissionDto.OWNER_CREATE;
import static org.opendatadiscovery.oddplatform.dto.policy.PolicyPermissionDto.OWNER_DELETE;
import static org.opendatadiscovery.oddplatform.dto.policy.PolicyPermissionDto.OWNER_RELATION_MANAGE;
import static org.opendatadiscovery.oddplatform.dto.policy.PolicyPermissionDto.OWNER_UPDATE;
import static org.opendatadiscovery.oddplatform.dto.policy.PolicyPermissionDto.POLICY_CREATE;
import static org.opendatadiscovery.oddplatform.dto.policy.PolicyPermissionDto.POLICY_DELETE;
Expand Down Expand Up @@ -149,6 +150,14 @@ NO_CONTEXT, new PathPatternParserServerWebExchangeMatcher("/api/owner_associatio
NO_CONTEXT, new PathPatternParserServerWebExchangeMatcher(
"/api/owner_association_request/{owner_association_request_id}", PUT),
OWNER_ASSOCIATION_MANAGE),
new SecurityRule(
NO_CONTEXT, new PathPatternParserServerWebExchangeMatcher(
"/api/owners/mapping", POST),
OWNER_RELATION_MANAGE),
new SecurityRule(
NO_CONTEXT, new PathPatternParserServerWebExchangeMatcher(
"/api/owners/mapping/{owner_id}", DELETE),
OWNER_RELATION_MANAGE),
new SecurityRule(NO_CONTEXT, new PathPatternParserServerWebExchangeMatcher("/api/policies", POST),
POLICY_CREATE),
new SecurityRule(NO_CONTEXT, new PathPatternParserServerWebExchangeMatcher("/api/policies/{policy_id}", PUT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import lombok.RequiredArgsConstructor;
import org.opendatadiscovery.oddplatform.api.contract.api.OwnerAssociationRequestApi;
import org.opendatadiscovery.oddplatform.api.contract.model.Owner;
import org.opendatadiscovery.oddplatform.api.contract.model.OwnerAssociationRequest;
import org.opendatadiscovery.oddplatform.api.contract.model.OwnerAssociationRequestActivityList;
import org.opendatadiscovery.oddplatform.api.contract.model.OwnerAssociationRequestList;
import org.opendatadiscovery.oddplatform.api.contract.model.OwnerAssociationRequestStatusFormData;
import org.opendatadiscovery.oddplatform.api.contract.model.OwnerAssociationRequestStatusParam;
import org.opendatadiscovery.oddplatform.api.contract.model.OwnerFormData;
import org.opendatadiscovery.oddplatform.api.contract.model.ProviderList;
import org.opendatadiscovery.oddplatform.api.contract.model.UserOwnerMappingFormData;
import org.opendatadiscovery.oddplatform.service.OwnerAssociationRequestActivityService;
import org.opendatadiscovery.oddplatform.service.OwnerAssociationRequestService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -16,6 +22,7 @@
@RequiredArgsConstructor
public class OwnerAssociationRequestController implements OwnerAssociationRequestApi {
private final OwnerAssociationRequestService ownerAssociationRequestService;
private final OwnerAssociationRequestActivityService activityService;

@Override
public Mono<ResponseEntity<OwnerAssociationRequest>> createOwnerAssociationRequest(
Expand All @@ -27,12 +34,21 @@ public Mono<ResponseEntity<OwnerAssociationRequest>> createOwnerAssociationReque
}

@Override
public Mono<ResponseEntity<OwnerAssociationRequestList>> getOwnerAssociationRequestList(final Integer page,
final Integer size,
final Boolean active,
final String query,
final ServerWebExchange e) {
return ownerAssociationRequestService.getOwnerAssociationRequestList(page, size, query, active)
public Mono<ResponseEntity<OwnerAssociationRequestList>>
getOwnerAssociationRequestList(final Integer page,
final Integer size,
final OwnerAssociationRequestStatusParam status,
final String query,
final ServerWebExchange e) {
return ownerAssociationRequestService.getOwnerAssociationRequestList(page, size, query, status)
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<OwnerAssociationRequestActivityList>> getOwnerAssociationRequestActivityList(
final Integer page, final Integer size, final OwnerAssociationRequestStatusParam status, final String query,
final ServerWebExchange exchange) {
return activityService.getOwnerAssociationRequestList(page, size, query, status)
.map(ResponseEntity::ok);
}

Expand All @@ -45,4 +61,26 @@ public Mono<ResponseEntity<OwnerAssociationRequest>> updateOwnerAssociationReque
.flatMap(fd -> ownerAssociationRequestService.updateOwnerAssociationRequest(id, fd.getStatus()))
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<Owner>>
createUserOwnerMapping(final Mono<UserOwnerMappingFormData> userOwnerMappingFormData,
final ServerWebExchange exchange) {
return userOwnerMappingFormData
.flatMap(ownerAssociationRequestService::createUserOwnerMapping)
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<Void>> deleteActiveUserOwnerMapping(final Long ownerId,
final ServerWebExchange exchange) {
return ownerAssociationRequestService.deleteActiveUserOwnerMapping(ownerId)
.thenReturn(ResponseEntity.noContent().build());
}

@Override
public Mono<ResponseEntity<ProviderList>> getAuthProviders(final ServerWebExchange exchange) {
return ownerAssociationRequestService.getAuthProviders()
.map(ResponseEntity::ok);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.opendatadiscovery.oddplatform.dto;

import org.opendatadiscovery.oddplatform.model.tables.pojos.OwnerAssociationRequestActivityPojo;

public record OwnerAssociationRequestActivityDto(OwnerAssociationRequestActivityPojo activityPojo,
OwnerAssociationRequestDto associationRequestDto) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.opendatadiscovery.oddplatform.dto;

public enum OwnerAssociationRequestActivityType {
REQUEST_CREATED,
REQUEST_DECLINED,
REQUEST_APPROVED,
REQUEST_MANUALLY_APPROVED,
REQUEST_MANUALLY_DECLINED
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.opendatadiscovery.oddplatform.dto;

import java.util.Collection;
import org.opendatadiscovery.oddplatform.model.tables.pojos.OwnerAssociationRequestPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.RolePojo;

public record OwnerAssociationRequestDto(OwnerAssociationRequestPojo pojo,
String ownerName,
Long ownerId,
Collection<RolePojo> roles,
AssociatedOwnerDto statusUpdatedUser) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.Collection;
import org.opendatadiscovery.oddplatform.model.tables.pojos.OwnerPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.RolePojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.UserOwnerMappingPojo;

public record OwnerDto(OwnerPojo ownerPojo, Collection<RolePojo> roles) {
public record OwnerDto(OwnerPojo ownerPojo,
Collection<RolePojo> roles,
UserOwnerMappingPojo associatedUser) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public enum PolicyPermissionDto {
OWNER_UPDATE(MANAGEMENT),
OWNER_DELETE(MANAGEMENT),
OWNER_ASSOCIATION_MANAGE(MANAGEMENT),
OWNER_RELATION_MANAGE(MANAGEMENT),
DIRECT_OWNER_SYNC(MANAGEMENT),
POLICY_CREATE(MANAGEMENT),
POLICY_UPDATE(MANAGEMENT),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package org.opendatadiscovery.oddplatform.mapper;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.opendatadiscovery.oddplatform.api.contract.model.AssociatedOwner;
import org.opendatadiscovery.oddplatform.api.contract.model.Identity;
import org.opendatadiscovery.oddplatform.api.contract.model.OwnerAssociationRequest;
import org.opendatadiscovery.oddplatform.api.contract.model.OwnerAssociationRequestStatus;
import org.opendatadiscovery.oddplatform.api.contract.model.Permission;
import org.opendatadiscovery.oddplatform.api.contract.model.Role;
import org.opendatadiscovery.oddplatform.dto.AssociatedOwnerDto;
import org.opendatadiscovery.oddplatform.dto.OwnerAssociationRequestDto;
import org.opendatadiscovery.oddplatform.model.tables.pojos.RolePojo;
import org.springframework.stereotype.Component;

@Component
Expand Down Expand Up @@ -46,6 +51,17 @@ private OwnerAssociationRequest mapAssociationRequest(final OwnerAssociationRequ
return new OwnerAssociationRequest()
.username(dto.pojo().getUsername())
.ownerName(dto.ownerName())
.ownerId(dto.ownerId())
.roles(rolePojoCollectionToRoleList(dto.roles()))
.status(OwnerAssociationRequestStatus.valueOf(dto.pojo().getStatus()));
}

private List<Role> rolePojoCollectionToRoleList(final Collection<RolePojo> collection) {
if (collection == null || collection.isEmpty()) {
return null;
}

return collection.stream().map(rolePojo -> new Role().id(rolePojo.getId()).name(rolePojo.getName()))
.collect(Collectors.toCollection(() -> new ArrayList<>(collection.size())));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.opendatadiscovery.oddplatform.mapper;

import java.util.Collection;
import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.opendatadiscovery.oddplatform.api.contract.model.OwnerAssociationRequestActivity;
import org.opendatadiscovery.oddplatform.api.contract.model.OwnerAssociationRequestActivityList;
import org.opendatadiscovery.oddplatform.api.contract.model.PageInfo;
import org.opendatadiscovery.oddplatform.dto.OwnerAssociationRequestActivityDto;
import org.opendatadiscovery.oddplatform.model.tables.pojos.OwnerAssociationRequestActivityPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.OwnerAssociationRequestPojo;
import org.opendatadiscovery.oddplatform.utils.Page;

@Mapper(config = MapperConfig.class, uses = {DateTimeMapper.class, AssociatedOwnerMapper.class})
public interface OwnerAssociationRequestActivityMapper {

@Mapping(target = "activityId", source = "dto.activityPojo.id")
@Mapping(target = ".", source = "dto.associationRequestDto.pojo")
@Mapping(target = "statusUpdatedBy", source = "dto.associationRequestDto.statusUpdatedUser")
@Mapping(target = "status", source = "dto.activityPojo.status")
@Mapping(target = "roles", source = "dto.associationRequestDto.roles")
@Mapping(target = "ownerName", source = "dto.associationRequestDto.ownerName")
@Mapping(target = "eventType", source = "dto.activityPojo.eventType")
@Mapping(target = "statusUpdatedAt", source = "dto.activityPojo.createdAt")
OwnerAssociationRequestActivity mapToOwnerAssociationRequestActivity(final OwnerAssociationRequestActivityDto dto);

List<OwnerAssociationRequestActivity> mapList(final Collection<OwnerAssociationRequestActivityDto> dtos);

default OwnerAssociationRequestActivityList mapPage(final Page<OwnerAssociationRequestActivityDto> page) {
final List<OwnerAssociationRequestActivity> items = mapList(page.getData());
final PageInfo pageInfo = new PageInfo(page.getTotal(), page.isHasNext());
return new OwnerAssociationRequestActivityList(items, pageInfo);
}

@Mapping(target = "ownerAssociationRequestId", source = "pojo.id")
@Mapping(target = "status", source = "pojo.status")
@Mapping(target = "statusUpdatedBy", source = "statusUpdatedBy")
@Mapping(target = "id", ignore = true)
@Mapping(target = "createdAt", ignore = true)
OwnerAssociationRequestActivityPojo mapToPojo(final OwnerAssociationRequestPojo pojo,
final String statusUpdatedBy,
final String eventType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ public Mono<Long> getTotalActivitiesCount(final OffsetDateTime beginDate,
final var countQuery = DSL.selectCount()
.from(ACTIVITY)
.join(DATA_ENTITY).on(DATA_ENTITY.ID.eq(ACTIVITY.DATA_ENTITY_ID))
.leftJoin(USER_OWNER_MAPPING).on(USER_OWNER_MAPPING.OIDC_USERNAME.eq(ACTIVITY.CREATED_BY));
.leftJoin(USER_OWNER_MAPPING)
.on(USER_OWNER_MAPPING.OIDC_USERNAME.eq(ACTIVITY.CREATED_BY)
.and(USER_OWNER_MAPPING.DELETED_AT.isNull()));
addJoins(countQuery, datasourceId, namespaceId, tagIds, ownerIds);
final List<Condition> conditions =
getCommonConditions(beginDate, endDate, datasourceId, namespaceId, tagIds, ownerIds, userIds, eventType);
Expand All @@ -172,7 +174,9 @@ public Mono<Long> getMyObjectsActivitiesCount(final OffsetDateTime beginDate,
final var countQuery = DSL.selectCount()
.from(ACTIVITY)
.join(DATA_ENTITY).on(DATA_ENTITY.ID.eq(ACTIVITY.DATA_ENTITY_ID))
.leftJoin(USER_OWNER_MAPPING).on(USER_OWNER_MAPPING.OIDC_USERNAME.eq(ACTIVITY.CREATED_BY));
.leftJoin(USER_OWNER_MAPPING)
.on(USER_OWNER_MAPPING.OIDC_USERNAME.eq(ACTIVITY.CREATED_BY)
.and(USER_OWNER_MAPPING.DELETED_AT.isNull()));
addJoins(countQuery, datasourceId, namespaceId, tagIds, List.of(currentOwnerId));
final List<Condition> conditions = getCommonConditions(beginDate, endDate, datasourceId, namespaceId, tagIds,
List.of(currentOwnerId), userIds, eventType);
Expand All @@ -191,7 +195,9 @@ public Mono<Long> getDependentActivitiesCount(final OffsetDateTime beginDate,
final var countQuery = DSL.selectCount()
.from(ACTIVITY)
.join(DATA_ENTITY).on(DATA_ENTITY.ID.eq(ACTIVITY.DATA_ENTITY_ID))
.leftJoin(USER_OWNER_MAPPING).on(USER_OWNER_MAPPING.OIDC_USERNAME.eq(ACTIVITY.CREATED_BY));
.leftJoin(USER_OWNER_MAPPING)
.on(USER_OWNER_MAPPING.OIDC_USERNAME.eq(ACTIVITY.CREATED_BY)
.and(USER_OWNER_MAPPING.DELETED_AT.isNull()));
addJoins(countQuery, datasourceId, namespaceId, tagIds, List.of());
final List<Condition> conditions = getCommonConditions(beginDate, endDate, datasourceId, namespaceId, tagIds,
List.of(), userIds, eventType);
Expand All @@ -211,7 +217,9 @@ private SelectJoinStep<?> buildBaseQuery(final Long datasourceId, final Long nam
final var query = DSL.select(selectFields)
.from(ACTIVITY)
.join(DATA_ENTITY).on(DATA_ENTITY.ID.eq(ACTIVITY.DATA_ENTITY_ID))
.leftJoin(USER_OWNER_MAPPING).on(USER_OWNER_MAPPING.OIDC_USERNAME.eq(ACTIVITY.CREATED_BY))
.leftJoin(USER_OWNER_MAPPING)
.on(USER_OWNER_MAPPING.OIDC_USERNAME.eq(ACTIVITY.CREATED_BY)
.and(USER_OWNER_MAPPING.DELETED_AT.isNull()))
.leftJoin(OWNER).on(OWNER.ID.eq(USER_OWNER_MAPPING.OWNER_ID));
return addJoins(query, datasourceId, namespaceId, tagIds, ownerIds);
}
Expand Down Expand Up @@ -263,6 +271,7 @@ private List<Condition> getCommonConditions(final OffsetDateTime beginDate,
}
if (CollectionUtils.isNotEmpty(userIds)) {
conditions.add(USER_OWNER_MAPPING.OWNER_ID.in(userIds));
conditions.add(USER_OWNER_MAPPING.DELETED_AT.isNull());
}
return conditions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public Mono<AlertDto> get(final long id) {
.select(jsonArrayAgg(field(ALERT_CHUNK.asterisk().toString())).as(ALERT_CHUNK_FIELD))
.from(ALERT)
.join(DATA_ENTITY).on(DATA_ENTITY.ODDRN.eq(ALERT.DATA_ENTITY_ODDRN))
.leftJoin(USER_OWNER_MAPPING).on(ALERT.STATUS_UPDATED_BY.eq(USER_OWNER_MAPPING.OIDC_USERNAME))
.leftJoin(USER_OWNER_MAPPING)
.on(ALERT.STATUS_UPDATED_BY.eq(USER_OWNER_MAPPING.OIDC_USERNAME)
.and(USER_OWNER_MAPPING.DELETED_AT.isNull()))
.leftJoin(OWNER).on(USER_OWNER_MAPPING.OWNER_ID.eq(OWNER.ID))
.join(ALERT_CHUNK).on(ALERT_CHUNK.ALERT_ID.eq(ALERT.ID))
.where(ALERT.ID.eq(id))
Expand All @@ -100,7 +102,9 @@ public Mono<List<AlertDto>> get(final List<Long> ids) {
.select(jsonArrayAgg(field(ALERT_CHUNK.asterisk().toString())).as(ALERT_CHUNK_FIELD))
.from(ALERT)
.join(DATA_ENTITY).on(DATA_ENTITY.ODDRN.eq(ALERT.DATA_ENTITY_ODDRN))
.leftJoin(USER_OWNER_MAPPING).on(ALERT.STATUS_UPDATED_BY.eq(USER_OWNER_MAPPING.OIDC_USERNAME))
.leftJoin(USER_OWNER_MAPPING)
.on(ALERT.STATUS_UPDATED_BY.eq(USER_OWNER_MAPPING.OIDC_USERNAME)
.and(USER_OWNER_MAPPING.DELETED_AT.isNull()))
.leftJoin(OWNER).on(USER_OWNER_MAPPING.OWNER_ID.eq(OWNER.ID))
.join(ALERT_CHUNK).on(ALERT_CHUNK.ALERT_ID.eq(ALERT.ID))
.where(ALERT.ID.in(ids))
Expand Down Expand Up @@ -493,7 +497,8 @@ private SelectSeekStepN<Record> createAlertOuterSelect(final Select<? extends Re
.join(DATA_ENTITY)
.on(DATA_ENTITY.ODDRN.eq(alertCte.field(ALERT.DATA_ENTITY_ODDRN)))
.leftJoin(USER_OWNER_MAPPING)
.on(alertCte.field(ALERT.STATUS_UPDATED_BY).eq(USER_OWNER_MAPPING.OIDC_USERNAME))
.on(alertCte.field(ALERT.STATUS_UPDATED_BY).eq(USER_OWNER_MAPPING.OIDC_USERNAME)
.and(USER_OWNER_MAPPING.DELETED_AT.isNull()))
.leftJoin(OWNER).on(USER_OWNER_MAPPING.OWNER_ID.eq(OWNER.ID))
.join(ALERT_CHUNK).on(ALERT_CHUNK.ALERT_ID.eq(alertCte.field(ALERT.ID)))
.groupBy(groupByFields)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.opendatadiscovery.oddplatform.repository.reactive;

import org.opendatadiscovery.oddplatform.api.contract.model.OwnerAssociationRequestStatusParam;
import org.opendatadiscovery.oddplatform.dto.OwnerAssociationRequestActivityDto;
import org.opendatadiscovery.oddplatform.model.tables.pojos.OwnerAssociationRequestActivityPojo;
import org.opendatadiscovery.oddplatform.utils.Page;
import reactor.core.publisher.Mono;

public interface ReactiveOwnerAssociationRequestActivityRepository
extends ReactiveCRUDRepository<OwnerAssociationRequestActivityPojo> {
Mono<Page<OwnerAssociationRequestActivityDto>> getDtoList(final Integer page, final Integer size,
final String query,
final OwnerAssociationRequestStatusParam status);
}
Loading

0 comments on commit 9c13c99

Please sign in to comment.