-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ingest): datamodel to ingest organisation role metadata for a da…
…taset
- Loading branch information
Showing
21 changed files
with
606 additions
and
3 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
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
120 changes: 120 additions & 0 deletions
120
...ava/com/linkedin/datahub/graphql/types/externalrolemetadata/ExternalRoleMetadataType.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,120 @@ | ||
package com.linkedin.datahub.graphql.types.externalrolemetadata; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.common.urn.UrnUtils; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.generated.AutoCompleteResults; | ||
import com.linkedin.datahub.graphql.generated.Entity; | ||
import com.linkedin.datahub.graphql.generated.EntityType; | ||
import com.linkedin.datahub.graphql.generated.ExternalRoleMetadata; | ||
import com.linkedin.datahub.graphql.generated.FacetFilterInput; | ||
import com.linkedin.datahub.graphql.generated.SearchResults; | ||
import com.linkedin.datahub.graphql.types.SearchableEntityType; | ||
import com.linkedin.datahub.graphql.types.externalrolemetadata.mappers.ExternalRoleMetadataMapper; | ||
import com.linkedin.datahub.graphql.types.mappers.AutoCompleteResultsMapper; | ||
import com.linkedin.datahub.graphql.types.mappers.UrnSearchResultsMapper; | ||
import com.linkedin.entity.EntityResponse; | ||
import com.linkedin.entity.client.EntityClient; | ||
import com.linkedin.metadata.Constants; | ||
import com.linkedin.metadata.query.AutoCompleteResult; | ||
import com.linkedin.metadata.query.SearchFlags; | ||
import com.linkedin.metadata.query.filter.Filter; | ||
import com.linkedin.metadata.search.SearchResult; | ||
import graphql.execution.DataFetcherResult; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
public class ExternalRoleMetadataType implements SearchableEntityType<ExternalRoleMetadata, String>, | ||
com.linkedin.datahub.graphql.types.EntityType<ExternalRoleMetadata, String> { | ||
|
||
static final Set<String> ASPECTS_TO_FETCH = ImmutableSet.of( | ||
Constants.EXTERNAL_ROLE_METADATA_KEY_ASPECT_NAME, | ||
Constants.EXTERNAL_ROLE_PROPERTIES_ASPECT_NAME, | ||
Constants.EXTERNAL_ROLE_PROVISIONEDUSERS_ASPECT_NAME | ||
); | ||
|
||
private final EntityClient _entityClient; | ||
|
||
public ExternalRoleMetadataType(final EntityClient entityClient) { | ||
_entityClient = entityClient; | ||
} | ||
|
||
@Override | ||
public EntityType type() { | ||
return EntityType.EXTERNAL_ROLE_METADATA; | ||
} | ||
|
||
@Override | ||
public Function<Entity, String> getKeyProvider() { | ||
return Entity::getUrn; | ||
} | ||
|
||
@Override | ||
public Class<ExternalRoleMetadata> objectClass() { | ||
return ExternalRoleMetadata.class; | ||
} | ||
|
||
@Override | ||
public List<DataFetcherResult<ExternalRoleMetadata>> batchLoad(@Nonnull List<String> urns, | ||
@Nonnull QueryContext context) throws Exception { | ||
final List<Urn> externalRolesUrns = urns.stream() | ||
.map(UrnUtils::getUrn) | ||
.collect(Collectors.toList()); | ||
|
||
try { | ||
final Map<Urn, EntityResponse> entities = _entityClient.batchGetV2( | ||
Constants.EXTERNAL_ROLE_METADATA_ENTITY_NAME, | ||
new HashSet<>(externalRolesUrns), | ||
ASPECTS_TO_FETCH, | ||
context.getAuthentication()); | ||
|
||
final List<EntityResponse> gmsResults = new ArrayList<>(); | ||
for (Urn urn : externalRolesUrns) { | ||
gmsResults.add(entities.getOrDefault(urn, null)); | ||
} | ||
return gmsResults.stream() | ||
.map(gmsResult -> | ||
gmsResult == null ? null : DataFetcherResult.<ExternalRoleMetadata>newResult() | ||
.data(ExternalRoleMetadataMapper.map(gmsResult)) | ||
.build() | ||
) | ||
.collect(Collectors.toList()); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to batch load ExternalRoleMetadata", e); | ||
} | ||
} | ||
|
||
@Override | ||
public SearchResults search(@Nonnull String query, | ||
@Nullable List<FacetFilterInput> filters, | ||
int start, | ||
int count, | ||
@Nonnull final QueryContext context) throws Exception { | ||
final SearchResult searchResult = _entityClient.search(Constants.EXTERNAL_ROLE_METADATA_ENTITY_NAME, | ||
query, Collections.emptyMap(), start, count, | ||
context.getAuthentication(), new SearchFlags().setFulltext(true)); | ||
return UrnSearchResultsMapper.map(searchResult); | ||
} | ||
|
||
@Override | ||
public AutoCompleteResults autoComplete(@Nonnull String query, | ||
@Nullable String field, | ||
@Nullable Filter filters, | ||
int limit, | ||
@Nonnull final QueryContext context) throws Exception { | ||
final AutoCompleteResult result = _entityClient.autoComplete(Constants.EXTERNAL_ROLE_METADATA_ENTITY_NAME, | ||
query, filters, limit, context.getAuthentication()); | ||
return AutoCompleteResultsMapper.map(result); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...nkedin/datahub/graphql/types/externalrolemetadata/mappers/ExternalRoleMetadataMapper.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,78 @@ | ||
package com.linkedin.datahub.graphql.types.externalrolemetadata.mappers; | ||
|
||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.datahub.graphql.generated.CorpUser; | ||
import com.linkedin.datahub.graphql.generated.EntityType; | ||
import com.linkedin.datahub.graphql.generated.ExternalRoleMetadata; | ||
import com.linkedin.datahub.graphql.generated.ExternalRoleProperties; | ||
import com.linkedin.datahub.graphql.generated.PrivilegeType; | ||
import com.linkedin.datahub.graphql.types.mappers.ModelMapper; | ||
import com.linkedin.entity.EntityResponse; | ||
import com.linkedin.entity.EnvelopedAspect; | ||
import com.linkedin.entity.EnvelopedAspectMap; | ||
import com.linkedin.metadata.Constants; | ||
import com.linkedin.metadata.key.ExternalRoleMetadataKey; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.stream.Collectors; | ||
|
||
public class ExternalRoleMetadataMapper implements ModelMapper<EntityResponse, ExternalRoleMetadata> { | ||
|
||
public static final ExternalRoleMetadataMapper INSTANCE = new ExternalRoleMetadataMapper(); | ||
|
||
public static ExternalRoleMetadata map(@Nonnull final EntityResponse entityResponse) { | ||
return INSTANCE.apply(entityResponse); | ||
} | ||
|
||
private static ExternalRoleProperties mapExtRoleProperties(final com.linkedin.externalrolemetadata.ExternalRoleProperties e) { | ||
final ExternalRoleProperties propertiesResult = new ExternalRoleProperties(); | ||
propertiesResult.setName(e.getName()); | ||
propertiesResult.setDescription(e.getDescription()); | ||
propertiesResult.setType(PrivilegeType.valueOf(e.getType().toString())); | ||
propertiesResult.setRequestUrl(e.getRequesturl()); | ||
|
||
return propertiesResult; | ||
} | ||
|
||
private static CorpUser mapExtRoleProvisionedUsers(final com.linkedin.externalrolemetadata.ExternalRoleProvisionedUser provisionedUser) { | ||
CorpUser result = new CorpUser(); | ||
result.setUrn(provisionedUser.getProvisionedUser().toString()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public ExternalRoleMetadata apply(EntityResponse input) { | ||
|
||
|
||
final ExternalRoleMetadata result = new ExternalRoleMetadata(); | ||
final Urn entityUrn = input.getUrn(); | ||
|
||
result.setUrn(entityUrn.toString()); | ||
result.setType(EntityType.EXTERNAL_ROLE_METADATA); | ||
|
||
final EnvelopedAspectMap aspects = input.getAspects(); | ||
|
||
final EnvelopedAspect externalRoleMetadataKeyAspect = aspects.get(Constants.EXTERNAL_ROLE_METADATA_KEY_ASPECT_NAME); | ||
if (externalRoleMetadataKeyAspect != null) { | ||
result.setId(new ExternalRoleMetadataKey(externalRoleMetadataKeyAspect.getValue().data()).getId()); | ||
} | ||
final EnvelopedAspect envelopedPropertiesAspect = aspects.get(Constants.EXTERNAL_ROLE_PROPERTIES_ASPECT_NAME); | ||
if (envelopedPropertiesAspect != null) { | ||
result.setProperties(mapExtRoleProperties( | ||
new com.linkedin.externalrolemetadata.ExternalRoleProperties( | ||
envelopedPropertiesAspect.getValue().data())) | ||
); | ||
} | ||
|
||
final EnvelopedAspect envelopedProvisionedUsers = aspects.get(Constants.EXTERNAL_ROLE_PROVISIONEDUSERS_ASPECT_NAME); | ||
if (envelopedProvisionedUsers != null) { | ||
result.setProvisionedUsers( | ||
new com.linkedin.externalrolemetadata.ExternalRoleProvisionedUsers(envelopedProvisionedUsers.getValue().data()) | ||
.getProvisionedUsers() | ||
.stream().map(x -> mapExtRoleProvisionedUsers(x)) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
return result; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...kedin/datahub/graphql/types/externalrolemetadata/mappers/ExternalRolesMetadataMapper.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,40 @@ | ||
package com.linkedin.datahub.graphql.types.externalrolemetadata.mappers; | ||
|
||
|
||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.datahub.graphql.generated.EntityType; | ||
import com.linkedin.datahub.graphql.generated.ExternalRoleAssociation; | ||
import com.linkedin.datahub.graphql.generated.ExternalRoleMetadata; | ||
import javax.annotation.Nonnull; | ||
import java.util.stream.Collectors; | ||
|
||
public class ExternalRolesMetadataMapper { | ||
public static final ExternalRolesMetadataMapper INSTANCE = new ExternalRolesMetadataMapper(); | ||
|
||
public static com.linkedin.datahub.graphql.generated.ExternalRolesMetadata map( | ||
@Nonnull final com.linkedin.common.ExternalRolesMetadata externalRolesMetadata, | ||
@Nonnull final Urn entityUrn) { | ||
return INSTANCE.apply(externalRolesMetadata, entityUrn); | ||
} | ||
|
||
public com.linkedin.datahub.graphql.generated.ExternalRolesMetadata apply( | ||
@Nonnull final com.linkedin.common.ExternalRolesMetadata externalRolesMetadata, | ||
@Nonnull final Urn entityUrn) { | ||
com.linkedin.datahub.graphql.generated.ExternalRolesMetadata result = new com.linkedin.datahub.graphql.generated.ExternalRolesMetadata(); | ||
result.setRoles(externalRolesMetadata.getRoles().stream().map( | ||
association -> this.mapExtRoleAssociation(association, entityUrn) | ||
).collect(Collectors.toList())); | ||
return result; | ||
} | ||
|
||
private ExternalRoleAssociation mapExtRoleAssociation(com.linkedin.common.ExternalRoleAssociation association, Urn entityUrn) { | ||
ExternalRoleAssociation extRoleAssociation = new ExternalRoleAssociation(); | ||
ExternalRoleMetadata resultExtRole = new ExternalRoleMetadata(); | ||
resultExtRole.setType(EntityType.EXTERNAL_ROLE_METADATA); | ||
resultExtRole.setUrn(association.getUrn().toString()); | ||
extRoleAssociation.setExternalRoleMetadata(resultExtRole); | ||
extRoleAssociation.setAssociatedUrn(entityUrn.toString()); | ||
return extRoleAssociation; | ||
} | ||
|
||
} |
Oops, something went wrong.