forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
190 changed files
with
13,177 additions
and
5,977 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...hql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/chart/BrowseV2Resolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.linkedin.datahub.graphql.resolvers.chart; | ||
|
||
import com.linkedin.common.urn.UrnUtils; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.generated.BrowseResultGroupV2; | ||
import com.linkedin.datahub.graphql.generated.BrowseResultMetadata; | ||
import com.linkedin.datahub.graphql.generated.BrowseResultsV2; | ||
import com.linkedin.datahub.graphql.generated.BrowseV2Input; | ||
import com.linkedin.datahub.graphql.resolvers.EntityTypeMapper; | ||
import com.linkedin.datahub.graphql.resolvers.ResolverUtils; | ||
import com.linkedin.datahub.graphql.resolvers.search.SearchUtils; | ||
import com.linkedin.datahub.graphql.types.common.mappers.UrnToEntityMapper; | ||
import com.linkedin.entity.client.EntityClient; | ||
import com.linkedin.metadata.browse.BrowseResultV2; | ||
import com.linkedin.metadata.query.filter.Filter; | ||
import com.linkedin.metadata.service.ViewService; | ||
import com.linkedin.view.DataHubViewInfo; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.linkedin.datahub.graphql.Constants.BROWSE_PATH_V2_DELIMITER; | ||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument; | ||
import static com.linkedin.datahub.graphql.resolvers.search.SearchUtils.resolveView; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class BrowseV2Resolver implements DataFetcher<CompletableFuture<BrowseResultsV2>> { | ||
|
||
private final EntityClient _entityClient; | ||
private final ViewService _viewService; | ||
|
||
private static final int DEFAULT_START = 0; | ||
private static final int DEFAULT_COUNT = 10; | ||
|
||
@Override | ||
public CompletableFuture<BrowseResultsV2> get(DataFetchingEnvironment environment) { | ||
final QueryContext context = environment.getContext(); | ||
final BrowseV2Input input = bindArgument(environment.getArgument("input"), BrowseV2Input.class); | ||
final String entityName = EntityTypeMapper.getName(input.getType()); | ||
|
||
final int start = input.getStart() != null ? input.getStart() : DEFAULT_START; | ||
final int count = input.getCount() != null ? input.getCount() : DEFAULT_COUNT; | ||
final String query = input.getQuery() != null ? input.getQuery() : "*"; | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
try { | ||
final DataHubViewInfo maybeResolvedView = (input.getViewUrn() != null) | ||
? resolveView(_viewService, UrnUtils.getUrn(input.getViewUrn()), context.getAuthentication()) | ||
: null; | ||
final String pathStr = input.getPath().size() > 0 ? BROWSE_PATH_V2_DELIMITER + String.join(BROWSE_PATH_V2_DELIMITER, input.getPath()) : ""; | ||
final Filter filter = ResolverUtils.buildFilter(null, input.getOrFilters()); | ||
|
||
BrowseResultV2 browseResults = _entityClient.browseV2( | ||
entityName, | ||
pathStr, | ||
maybeResolvedView != null | ||
? SearchUtils.combineFilters(filter, maybeResolvedView.getDefinition().getFilter()) | ||
: filter, | ||
query, | ||
start, | ||
count, | ||
context.getAuthentication() | ||
); | ||
return mapBrowseResults(browseResults); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to execute browse V2", e); | ||
} | ||
}); | ||
} | ||
|
||
private BrowseResultsV2 mapBrowseResults(BrowseResultV2 browseResults) { | ||
BrowseResultsV2 results = new BrowseResultsV2(); | ||
results.setTotal(browseResults.getNumGroups()); | ||
results.setStart(browseResults.getFrom()); | ||
results.setCount(browseResults.getPageSize()); | ||
|
||
List<BrowseResultGroupV2> groups = new ArrayList<>(); | ||
browseResults.getGroups().forEach(group -> { | ||
BrowseResultGroupV2 browseGroup = new BrowseResultGroupV2(); | ||
browseGroup.setName(group.getName()); | ||
browseGroup.setCount(group.getCount()); | ||
browseGroup.setHasSubGroups(group.isHasSubGroups()); | ||
if (group.hasUrn() && group.getUrn() != null) { | ||
browseGroup.setEntity(UrnToEntityMapper.map(group.getUrn())); | ||
} | ||
groups.add(browseGroup); | ||
}); | ||
results.setGroups(groups); | ||
|
||
BrowseResultMetadata resultMetadata = new BrowseResultMetadata(); | ||
resultMetadata.setPath(Arrays.stream(browseResults.getMetadata().getPath() | ||
.split(BROWSE_PATH_V2_DELIMITER)) | ||
.filter(pathComponent -> !"".equals(pathComponent)) | ||
.collect(Collectors.toList()) | ||
); | ||
resultMetadata.setTotalNumEntities(browseResults.getMetadata().getTotalNumEntities()); | ||
results.setMetadata(resultMetadata); | ||
|
||
return results; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../src/main/java/com/linkedin/datahub/graphql/types/common/mappers/BrowsePathsV2Mapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.linkedin.datahub.graphql.types.common.mappers; | ||
|
||
import com.linkedin.common.BrowsePathsV2; | ||
import com.linkedin.datahub.graphql.generated.BrowsePathEntry; | ||
import com.linkedin.datahub.graphql.generated.BrowsePathV2; | ||
import com.linkedin.datahub.graphql.types.mappers.ModelMapper; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class BrowsePathsV2Mapper implements ModelMapper<BrowsePathsV2, BrowsePathV2> { | ||
|
||
public static final BrowsePathsV2Mapper INSTANCE = new BrowsePathsV2Mapper(); | ||
|
||
public static BrowsePathV2 map(@Nonnull final BrowsePathsV2 metadata) { | ||
return INSTANCE.apply(metadata); | ||
} | ||
|
||
@Override | ||
public BrowsePathV2 apply(@Nonnull final BrowsePathsV2 input) { | ||
final BrowsePathV2 result = new BrowsePathV2(); | ||
final List<BrowsePathEntry> path = input.getPath().stream().map(this::mapBrowsePathEntry).collect(Collectors.toList()); | ||
result.setPath(path); | ||
return result; | ||
} | ||
|
||
private BrowsePathEntry mapBrowsePathEntry(com.linkedin.common.BrowsePathEntry pathEntry) { | ||
final BrowsePathEntry entry = new BrowsePathEntry(); | ||
entry.setName(pathEntry.getId()); | ||
if (pathEntry.hasUrn() && pathEntry.getUrn() != null) { | ||
entry.setEntity(UrnToEntityMapper.map(pathEntry.getUrn())); | ||
} | ||
return entry; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.