Skip to content

Commit

Permalink
Add relationships to datasets (#1654)
Browse files Browse the repository at this point in the history
Co-authored-by: ayemets-corcentric <[email protected]>
Co-authored-by: vburlachenko <[email protected]>
  • Loading branch information
3 people authored Apr 5, 2024
1 parent 90efc54 commit 883b47d
Show file tree
Hide file tree
Showing 34 changed files with 905 additions and 508 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.opendatadiscovery.oddplatform.api.contract.api.DataSetApi;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityRelationshipList;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityRelationshipDetailsList;
import org.opendatadiscovery.oddplatform.api.contract.model.DataSetStructure;
import org.opendatadiscovery.oddplatform.api.contract.model.DataSetVersionDiffList;
import org.opendatadiscovery.oddplatform.api.contract.model.RelationshipsType;
Expand Down Expand Up @@ -50,9 +50,10 @@ public Mono<ResponseEntity<DataSetVersionDiffList>> getDataSetStructureDiff(fina
}

@Override
public Mono<ResponseEntity<DataEntityRelationshipList>> getDataSetRelationships(final Long dataEntityId,
final RelationshipsType type,
final ServerWebExchange exchange) {
public Mono<ResponseEntity<DataEntityRelationshipDetailsList>>
getDataSetRelationships(final Long dataEntityId,
final RelationshipsType type,
final ServerWebExchange exchange) {
return relationshipsService.getRelationsByDatasetId(dataEntityId, type)
.map(ResponseEntity::ok);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.opendatadiscovery.oddplatform.api.contract.api.RelationshipApi;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityERDRelationshipDetails;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityGraphRelationshipDetails;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityRelationshipDetails;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityRelationshipList;
import org.opendatadiscovery.oddplatform.api.contract.model.RelationshipsType;
import org.opendatadiscovery.oddplatform.service.RelationshipsService;
Expand All @@ -28,15 +27,15 @@ public Mono<ResponseEntity<DataEntityRelationshipList>> getRelationships(final I
}

@Override
public Mono<ResponseEntity<DataEntityERDRelationshipDetails>>
public Mono<ResponseEntity<DataEntityRelationshipDetails>>
getERDRelationshipById(final Long relationshipId,
final ServerWebExchange exchange) {
return relationshipsService.getERDRelationshipById(relationshipId)
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<DataEntityGraphRelationshipDetails>>
public Mono<ResponseEntity<DataEntityRelationshipDetails>>
getGraphRelationshipById(final Long relationshipId,
final ServerWebExchange exchange) {
return relationshipsService.getGraphRelationshipById(relationshipId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.opendatadiscovery.oddplatform.dto;

import java.util.List;
import lombok.Builder;
import org.apache.commons.lang3.tuple.Pair;
import org.opendatadiscovery.oddplatform.model.tables.pojos.DatasetFieldPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.ErdRelationshipDetailsPojo;

@Builder
public record ErdRelationshipDetailsDto(ErdRelationshipDetailsPojo pojo,
List<Pair<
Pair<String, DatasetFieldPojo>,
Pair<String, DatasetFieldPojo>>> fieldPairList) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

import lombok.Builder;
import org.opendatadiscovery.oddplatform.model.tables.pojos.DataEntityPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.ErdRelationshipDetailsPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.DataSourcePojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.GraphRelationshipPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.NamespacePojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.RelationshipsPojo;

@Builder
public record RelationshipDetailsDto(DataEntityPojo dataEntityRelationship,
RelationshipsPojo relationshipPojo,
DataEntityPojo sourceDataEntity,
DataEntityPojo targetDataEntity,
ErdRelationshipDetailsPojo erdRelationshipDetailsPojo,
DataSourcePojo dataSourcePojo,
NamespacePojo dataSourceNamespacePojo,
ErdRelationshipDetailsDto erdRelationshipDetailsDto,
GraphRelationshipPojo graphRelationshipPojo) {
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
package org.opendatadiscovery.oddplatform.mapper;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.commons.lang3.tuple.Pair;
import org.opendatadiscovery.oddplatform.api.contract.model.ERDRelationshipDetails;
import org.opendatadiscovery.oddplatform.api.contract.model.ERDRelationshipPairs;
import org.opendatadiscovery.oddplatform.model.tables.pojos.ErdRelationshipDetailsPojo;
import org.opendatadiscovery.oddplatform.dto.ErdRelationshipDetailsDto;
import org.opendatadiscovery.oddplatform.model.tables.pojos.DatasetFieldPojo;
import org.springframework.stereotype.Component;
import org.thymeleaf.util.ArrayUtils;

@Component
public class ErdRelationshipMapper {
public ERDRelationshipDetails mapPojoToDetails(final ErdRelationshipDetailsPojo erd) {
public ERDRelationshipDetails mapPojoToDetails(final ErdRelationshipDetailsDto erd) {
if (erd == null) {
return null;
}

return new ERDRelationshipDetails()
.erdRelationshipId(erd.getId())
.fieldsPairs(mapPairs(erd.getSourceDatasetFieldOddrn(), erd.getTargetDatasetFieldOddrn()))
.isIdentifying(erd.getIsIdentifying())
.cardinality(erd.getCardinality());
.erdRelationshipId(erd.pojo().getId())
.fieldsPairs(mapPairs(erd.fieldPairList()))
.isIdentifying(erd.pojo().getIsIdentifying())
.cardinality(erd.pojo().getCardinality());
}

private List<ERDRelationshipPairs> mapPairs(final String[] source, final String[] target) {
if (ArrayUtils.isEmpty(source)) {
return null;
private List<ERDRelationshipPairs> mapPairs(final List<Pair<Pair<String, DatasetFieldPojo>,
Pair<String, DatasetFieldPojo>>> fieldPairsList) {
if (fieldPairsList.isEmpty()) {
return Collections.emptyList();
}

return IntStream.range(0, source.length).mapToObj(i -> new ERDRelationshipPairs()
.sourceDatasetFieldOddrn(source[i])
.targetDatasetFieldOddrn(target[i])).collect(Collectors.toList());
return fieldPairsList.stream().map(fieldPairs -> new ERDRelationshipPairs()
.sourceDatasetFieldOddrn(fieldPairs.getLeft().getKey())
.sourceDatasetFieldId(
fieldPairs.getLeft().getValue() != null ? fieldPairs.getLeft().getValue().getId() : null)
.targetDatasetFieldOddrn(fieldPairs.getRight().getKey())
.targetDatasetFieldId(
fieldPairs.getRight().getValue() != null ? fieldPairs.getRight().getValue().getId() : null))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Component
public class GraphRelationshipMapper {
public GraphRelationshipDetails mapPojoToDetails(final GraphRelationshipPojo pojo) {
if (pojo == null) {
if (pojo == null || pojo.getId() == null) {
return null;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityRelationship;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityRelationshipDetails;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityRelationshipDetailsList;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityRelationshipList;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityRelationshipType;
import org.opendatadiscovery.oddplatform.api.contract.model.PageInfo;
import org.opendatadiscovery.oddplatform.dto.DataSourceDto;
import org.opendatadiscovery.oddplatform.dto.RelationshipDetailsDto;
import org.opendatadiscovery.oddplatform.dto.RelationshipDto;
import org.opendatadiscovery.oddplatform.dto.RelationshipTypeDto;
import org.opendatadiscovery.oddplatform.utils.Page;
Expand All @@ -17,12 +20,20 @@
@Component
public class RelationshipMapper {
private final DataSourceSafeMapper dataSourceSafeMapper;
private final NamespaceMapper namespaceMapper;
private final DataEntityMapper dataEntityMapper;
private final ErdRelationshipMapper erdRelationshipMapper;
private final GraphRelationshipMapper graphRelationshipMapper;

public DataEntityRelationshipList mapListToRelationshipList(final List<RelationshipDto> relationshipDtos) {
return new DataEntityRelationshipList()
.items(mapToRelationshipList(relationshipDtos))
.pageInfo(new PageInfo().total((long) relationshipDtos.size()).hasNext(false));
public DataEntityRelationshipDetailsList mapListToRelationshipList(final List<RelationshipDetailsDto> dtos) {
return new DataEntityRelationshipDetailsList()
.items(mapToRelationshipDetailsList(dtos))
.pageInfo(new PageInfo().total((long) dtos.size()).hasNext(false));
}

private List<DataEntityRelationshipDetails> mapToRelationshipDetailsList(final List<RelationshipDetailsDto> dtos) {
return dtos.stream()
.map(this::mapToDatasetRelationshipDetails)
.collect(Collectors.toList());
}

private List<DataEntityRelationship> mapToRelationshipList(final List<RelationshipDto> relationshipDtos) {
Expand All @@ -31,26 +42,41 @@ private List<DataEntityRelationship> mapToRelationshipList(final List<Relationsh
.collect(Collectors.toList());
}

public DataEntityRelationshipList mapListToRelationshipPage(final Page<RelationshipDto> relationshipDtoPage) {
return new DataEntityRelationshipList()
.items(mapToRelationshipList(relationshipDtoPage.getData()))
.pageInfo(new PageInfo().total((relationshipDtoPage.getTotal())).hasNext(relationshipDtoPage.isHasNext()));
}

public DataEntityRelationship mapToDatasetRelationship(final RelationshipDto item) {
return new DataEntityRelationship()
.id(item.dataEntityRelationship().getId())
.name(item.dataEntityRelationship().getExternalName())
.oddrn(item.dataEntityRelationship().getOddrn())
.sourceDatasetOddrn(item.relationshipPojo().getSourceDatasetOddrn())
.targetDatasetOddrn(item.relationshipPojo().getTargetDatasetOddrn())
.sourceDataEntityId(item.sourceDataEntity() != null ? item.sourceDataEntity().getId() : null)
.targetDataEntityId(item.targetDataEntity() != null ? item.targetDataEntity().getId() : null)
.sourceDataEntity(dataEntityMapper.mapRef(item.sourceDataEntity()))
.targetDataEntity(dataEntityMapper.mapRef(item.targetDataEntity()))
.dataSource(dataSourceSafeMapper.mapDto(new DataSourceDto(item.dataSourcePojo(),
item.dataSourceNamespacePojo(), null)))
.namespace(namespaceMapper.mapPojo(item.relationshipNamespacePojo()))
.type(RelationshipTypeDto.ERD.name().equals(item.relationshipPojo().getRelationshipType())
? DataEntityRelationshipType.ENTITY_RELATIONSHIP
: DataEntityRelationshipType.GRAPH_RELATIONSHIP);
}

public DataEntityRelationshipList mapListToRelationshipPage(final Page<RelationshipDto> relationshipDtoPage) {
return new DataEntityRelationshipList()
.items(mapToRelationshipList(relationshipDtoPage.getData()))
.pageInfo(new PageInfo().total((relationshipDtoPage.getTotal())).hasNext(relationshipDtoPage.isHasNext()));
public DataEntityRelationshipDetails mapToDatasetRelationshipDetails(final RelationshipDetailsDto item) {
return new DataEntityRelationshipDetails()
.id(item.dataEntityRelationship().getId())
.name(item.dataEntityRelationship().getExternalName())
.oddrn(item.dataEntityRelationship().getOddrn())
.sourceDataEntity(dataEntityMapper.mapRef(item.sourceDataEntity()))
.targetDataEntity(dataEntityMapper.mapRef(item.targetDataEntity()))
.dataSource(dataSourceSafeMapper.mapDto(new DataSourceDto(item.dataSourcePojo(),
item.dataSourceNamespacePojo(), null)))
.type(RelationshipTypeDto.ERD.name().equals(item.relationshipPojo().getRelationshipType())
? DataEntityRelationshipType.ENTITY_RELATIONSHIP
: DataEntityRelationshipType.GRAPH_RELATIONSHIP)
.erdRelationship(
erdRelationshipMapper.mapPojoToDetails(item.erdRelationshipDetailsDto()))
.graphRelationship(
graphRelationshipMapper.mapPojoToDetails(item.graphRelationshipPojo()));
}
}

This file was deleted.

Loading

0 comments on commit 883b47d

Please sign in to comment.