Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(models) : Joins (Datasets) schema, resolvers and UI #8325

Merged
merged 118 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
da18715
Initial version - Joins Schema
rtekal May 4, 2023
bdf2bc6
Joins slight model changes
rtekal May 9, 2023
eeba4cb
Added resolvers
rtekal May 31, 2023
89e8782
Graphql change and extraneous code removed
rtekal May 31, 2023
0c22848
Merge branch 'master' into master
rtekal May 31, 2023
35ea6ca
Remove Snapshot and Aspect
rtekal Jun 15, 2023
5ff65c5
Merge branch 'master' into master
rtekal Jun 16, 2023
03319c1
Merge - Sync with master
rtekal Jun 21, 2023
a819bfa
Join resolver updates
rtekal Jun 23, 2023
0cd6323
Additional changes to graphql files
rtekal Jun 25, 2023
f84a576
join ui changes
poorvi767 Jun 27, 2023
badcb44
minor correction
poorvi767 Jun 27, 2023
996bcce
more updates to join ui
poorvi767 Jun 28, 2023
0b9246a
Merge branch 'master' into pl-join-ui
poorvi767 Jun 28, 2023
6d123c1
review comments incorporate for UI
poorvi767 Jul 14, 2023
2550337
Review changes 1
rtekal Jul 17, 2023
7d3680b
Merge branch 'pl-join-ui-review' into vt-pl-join-ui-codeReview
rtekal Jul 17, 2023
1a4967b
Merge pull request #1 from rtekal/vt-pl-join-ui-codeReview
poorvi767 Jul 17, 2023
6173ce4
placed new entries at the end
poorvi767 Jul 17, 2023
2c7e901
graphql fragments update
poorvi767 Jul 17, 2023
a3c8f0c
WIP- create and update join resolvers separate implementation
poorvi767 Jul 18, 2023
60ee9e8
fetched unr from envt for update join
poorvi767 Jul 18, 2023
fca944c
CreatedBy is an entity
rtekal Jul 19, 2023
8c1d018
create and update resolver refactoring done
poorvi767 Jul 19, 2023
3f0d55e
Merge with pl-join-ui-review
rtekal Jul 20, 2023
2d87628
updated return type for join mutations
poorvi767 Jul 20, 2023
d0f3b45
Merge branch 'pl-join-ui-review' into vt-pl-join-ui-codeReview
rtekal Jul 20, 2023
c99b654
Merged with pl-join-ui-review
rtekal Jul 20, 2023
e08fa36
join policy configuration
poorvi767 Jul 21, 2023
73f5993
Merge branch 'pl-join-ui-review' into vt-pl-join-ui-codeReview
rtekal Jul 21, 2023
fdff95f
CreatedActor as Entity
rtekal Jul 24, 2023
3fc0ba2
Merge pull request #2 from rtekal/vt-pl-join-ui-codeReview
poorvi767 Jul 25, 2023
cd8d480
timestamp to auditstamp changes
poorvi767 Jul 25, 2023
6ca1bb4
Merge branch 'pl-join-ui-review' of https://github.com/poorvi767/data…
poorvi767 Jul 25, 2023
b317a90
CreatedActor when not present
rtekal Jul 25, 2023
0d29228
policy and authorization for join
poorvi767 Jul 26, 2023
1442f3a
conflict resolution
poorvi767 Jul 26, 2023
084ca29
Merge pl-join-ui-review for Policy AuditStamp, FieldMapping
rtekal Jul 27, 2023
f0af033
Create_Join_Privilege should be part of COMMON_ENTITY_PRIVILEGES
rtekal Jul 27, 2023
3d8991e
Merge pull request #4 from rtekal/vt-pl-join-ui-codeReview
poorvi767 Jul 27, 2023
7a00ade
update create join authorization
poorvi767 Jul 27, 2023
6a6ebf8
removed commented code
poorvi767 Jul 28, 2023
c7cf14c
Merge pull request #5 from poorvi767/pl-join-ui-review
poorvi767 Jul 28, 2023
3139b8b
Merge branch 'master' into pl-join-ui
poorvi767 Jul 28, 2023
80484c3
create join modal refactored
poorvi767 Aug 1, 2023
795f663
removed console log
poorvi767 Aug 3, 2023
c0a64f3
skipped using apollo client direct for check duplicate join name
poorvi767 Aug 3, 2023
d784cad
Merge branch 'master' into pl-join-ui
poorvi767 Sep 6, 2023
9368a21
Join UUID non-random generation
rtekal Sep 13, 2023
d2fa626
Join GUID generation
rtekal Sep 15, 2023
7299279
Join Feature with Feature Flag
rtekal Sep 18, 2023
7cd52b2
Use About Join for description
rtekal Sep 20, 2023
b4c74fb
Removed details from JoinFieldMapping
rtekal Sep 21, 2023
34df52b
Message modification when empty join fields
rtekal Sep 22, 2023
e4deef1
review comments incorporate
poorvi767 Sep 29, 2023
ba32a4e
Merge authorization changes
rtekal Sep 29, 2023
96c5d6d
Merge authorization conflict resolution
rtekal Sep 29, 2023
3675766
Correction for style check
rtekal Oct 2, 2023
f25663a
Merge pull request #8 from rtekal/rtekal-reviews-pl-join-ui
poorvi767 Oct 3, 2023
e7916f2
css fixes
poorvi767 Oct 3, 2023
9ce4607
Merge pull request #10 from poorvi767/pl-join-ui-pr
poorvi767 Oct 3, 2023
6847170
Merge/conflict fixes with master
rtekal Oct 3, 2023
4715295
Merge pull request #11 from rtekal/rtekal-reviews-pl-join-ui
poorvi767 Oct 4, 2023
75499a7
fixed loading join under relationships tab
poorvi767 Oct 4, 2023
b53de1c
Merge pull request #12 from poorvi767/pl-join-ui-pr
poorvi767 Oct 4, 2023
e337e32
Merge branch 'master' into pl-join-ui
poorvi767 Oct 4, 2023
3da6cdb
Merge branch 'master' into pl-join-ui
poorvi767 Oct 4, 2023
ac87425
minor fix- reset join form after submit
poorvi767 Oct 4, 2023
085e472
Merge branch 'master' into pl-join-ui
poorvi767 Oct 4, 2023
5a03193
Merge with v0.12.1rc2
rtekal Dec 19, 2023
6325729
Changed Join to ERModelRelation - build compiles
rtekal Jan 3, 2024
d122996
Datahub comes up. Needs more UI testing
rtekal Jan 19, 2024
8e727c3
Typo in entity name
rtekal Jan 22, 2024
07c6a18
Merge pull request #13 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Jan 22, 2024
7c0d45f
Merged with master
rtekal Jan 23, 2024
91ac7d9
Indent correction
rtekal Jan 23, 2024
226fa40
Merging with main
rtekal Jan 30, 2024
43bc95c
spotless java changes
rtekal Feb 1, 2024
2369e07
Register for UI ERModelRelationEntity
rtekal Feb 2, 2024
dd09115
Merge pull request #14 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Feb 2, 2024
2831bf6
Master merge and resolve conflicts
rtekal Feb 2, 2024
aab5d0a
Merge pull request #16 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Feb 2, 2024
d9e0e5f
UI display: ER-Model-Relation
rtekal Feb 2, 2024
6952bab
Merge pull request #17 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Feb 2, 2024
a0a7264
Merge with master due to conflict
rtekal Feb 9, 2024
f2f8023
Merge pull request #18 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Feb 9, 2024
80bdd98
Merge branch 'master' into pl-join-ui
poorvi767 Feb 16, 2024
724145e
Feature flag name change
rtekal Feb 23, 2024
7422b4b
DatasetA -> source, DatasetB -> destination
rtekal Feb 27, 2024
3da6c48
Use generic Urn instead of DatasetUrn
rtekal Feb 28, 2024
0fd67ce
Mutation name changes Relation -> Relationship
rtekal Mar 4, 2024
39623ac
afield, bfield -> sourceField, destinationField
rtekal Mar 4, 2024
faf98b6
Merge with master
rtekal Mar 5, 2024
693b37c
Correct after merge
rtekal Mar 5, 2024
71cc165
Merge pull request #19 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Mar 5, 2024
c984965
Merge branch 'master' into rtekal-pl-join-ui-ERModelRelation
rtekal Mar 5, 2024
15cf41c
Merge pull request #20 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Mar 5, 2024
8c46b16
Changed to array of RelatipnshipFieldMapping
rtekal Mar 12, 2024
860006d
Entity name change: ermodelrelation -> erModelRelationship
rtekal Mar 13, 2024
1dc9631
Changed ermodelrelation to ermodelrelationship for entity name and ma…
rtekal Mar 14, 2024
97817f3
Rename ermodelrelationId -> id
rtekal Mar 14, 2024
5ce698f
ERModel relation -> relationship; code compiles
rtekal Mar 14, 2024
36ace22
Few more name changes
rtekal Mar 18, 2024
0690c2d
Add Cardinality based on relations
rtekal Mar 18, 2024
4e569d2
More Web files names changed to relationship
rtekal Mar 18, 2024
eda02f7
One more rename to relathipship
rtekal Mar 18, 2024
94220c5
Some more renames to relationship
rtekal Mar 18, 2024
15b7334
Merge branch 'master' into rtekal-pl-join-ui-ERModelRelation
rtekal Mar 18, 2024
6f4d1b1
Merge pull request #21 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Mar 18, 2024
ce7d553
Merge branch 'master' into rtekal-pl-join-ui-ERModelRelation
rtekal Mar 18, 2024
40da935
Merge pull request #22 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Mar 18, 2024
004eac0
Merge branch 'master' into pl-join-ui
chriscollins3456 Mar 19, 2024
9ebb047
Merge with main and some renames
rtekal Mar 19, 2024
5b54652
few more renames
rtekal Mar 19, 2024
49d9e55
Some more name changes
rtekal Mar 19, 2024
4d50ae2
Merge pull request #23 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Mar 19, 2024
79694d7
Merge branch 'master' into rtekal-pl-join-ui-ERModelRelation
rtekal Mar 19, 2024
99ded17
Merge pull request #24 from rtekal/rtekal-pl-join-ui-ERModelRelation
rtekal Mar 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.linkedin.datahub.graphql.generated.Dataset;
import com.linkedin.datahub.graphql.generated.DatasetStatsSummary;
import com.linkedin.datahub.graphql.generated.Domain;
import com.linkedin.datahub.graphql.generated.ERModelRelationshipProperties;
import com.linkedin.datahub.graphql.generated.EntityPath;
import com.linkedin.datahub.graphql.generated.EntityRelationship;
import com.linkedin.datahub.graphql.generated.EntityRelationshipLegacy;
Expand Down Expand Up @@ -308,6 +309,9 @@
import com.linkedin.datahub.graphql.types.datatype.DataTypeType;
import com.linkedin.datahub.graphql.types.domain.DomainType;
import com.linkedin.datahub.graphql.types.entitytype.EntityTypeType;
import com.linkedin.datahub.graphql.types.ermodelrelationship.CreateERModelRelationshipResolver;
import com.linkedin.datahub.graphql.types.ermodelrelationship.ERModelRelationshipType;
import com.linkedin.datahub.graphql.types.ermodelrelationship.UpdateERModelRelationshipResolver;
import com.linkedin.datahub.graphql.types.form.FormType;
import com.linkedin.datahub.graphql.types.glossary.GlossaryNodeType;
import com.linkedin.datahub.graphql.types.glossary.GlossaryTermType;
Expand Down Expand Up @@ -346,6 +350,7 @@
import com.linkedin.metadata.recommendation.RecommendationsService;
import com.linkedin.metadata.secret.SecretService;
import com.linkedin.metadata.service.DataProductService;
import com.linkedin.metadata.service.ERModelRelationshipService;
import com.linkedin.metadata.service.FormService;
import com.linkedin.metadata.service.LineageService;
import com.linkedin.metadata.service.OwnershipTypeService;
Expand Down Expand Up @@ -417,6 +422,7 @@ public class GmsGraphQLEngine {
private final LineageService lineageService;
private final QueryService queryService;
private final DataProductService dataProductService;
private final ERModelRelationshipService erModelRelationshipService;
private final FormService formService;
private final RestrictedService restrictedService;

Expand Down Expand Up @@ -462,6 +468,7 @@ public class GmsGraphQLEngine {
private final DataHubPolicyType dataHubPolicyType;
private final DataHubRoleType dataHubRoleType;
private final SchemaFieldType schemaFieldType;
private final ERModelRelationshipType erModelRelationshipType;
private final DataHubViewType dataHubViewType;
private final QueryType queryType;
private final DataProductType dataProductType;
Expand Down Expand Up @@ -529,6 +536,7 @@ public GmsGraphQLEngine(final GmsGraphQLEngineArgs args) {
this.settingsService = args.settingsService;
this.lineageService = args.lineageService;
this.queryService = args.queryService;
this.erModelRelationshipService = args.erModelRelationshipService;
this.dataProductService = args.dataProductService;
this.formService = args.formService;
this.restrictedService = args.restrictedService;
Expand Down Expand Up @@ -572,6 +580,7 @@ public GmsGraphQLEngine(final GmsGraphQLEngineArgs args) {
this.dataHubPolicyType = new DataHubPolicyType(entityClient);
this.dataHubRoleType = new DataHubRoleType(entityClient);
this.schemaFieldType = new SchemaFieldType(entityClient, featureFlags);
this.erModelRelationshipType = new ERModelRelationshipType(entityClient, featureFlags);
this.dataHubViewType = new DataHubViewType(entityClient);
this.queryType = new QueryType(entityClient);
this.dataProductType = new DataProductType(entityClient);
Expand Down Expand Up @@ -617,6 +626,7 @@ public GmsGraphQLEngine(final GmsGraphQLEngineArgs args) {
dataHubPolicyType,
dataHubRoleType,
schemaFieldType,
erModelRelationshipType,
dataHubViewType,
queryType,
dataProductType,
Expand Down Expand Up @@ -707,6 +717,7 @@ public void configureRuntimeWiring(final RuntimeWiring.Builder builder) {
configureTestResultResolvers(builder);
configureRoleResolvers(builder);
configureSchemaFieldResolvers(builder);
configureERModelRelationshipResolvers(builder);
configureEntityPathResolvers(builder);
configureResolvedAuditStampResolvers(builder);
configureViewResolvers(builder);
Expand Down Expand Up @@ -939,6 +950,7 @@ private void configureQueryResolvers(final RuntimeWiring.Builder builder) {
.dataFetcher("glossaryTerm", getResolver(glossaryTermType))
.dataFetcher("glossaryNode", getResolver(glossaryNodeType))
.dataFetcher("domain", getResolver((domainType)))
.dataFetcher("erModelRelationship", getResolver(erModelRelationshipType))
.dataFetcher("dataPlatform", getResolver(dataPlatformType))
.dataFetcher("dataPlatformInstance", getResolver(dataPlatformInstanceType))
.dataFetcher("mlFeatureTable", getResolver(mlFeatureTableType))
Expand Down Expand Up @@ -1069,6 +1081,13 @@ private void configureMutationResolvers(final RuntimeWiring.Builder builder) {
.dataFetcher("updateDataFlow", new MutableTypeResolver<>(dataFlowType))
.dataFetcher("updateCorpUserProperties", new MutableTypeResolver<>(corpUserType))
.dataFetcher("updateCorpGroupProperties", new MutableTypeResolver<>(corpGroupType))
.dataFetcher(
"updateERModelRelationship",
new UpdateERModelRelationshipResolver(this.entityClient))
.dataFetcher(
"createERModelRelationship",
new CreateERModelRelationshipResolver(
this.entityClient, this.erModelRelationshipService))
.dataFetcher("addTag", new AddTagResolver(entityService))
.dataFetcher("addTags", new AddTagsResolver(entityService))
.dataFetcher("batchAddTags", new BatchAddTagsResolver(entityService))
Expand Down Expand Up @@ -2078,6 +2097,60 @@ private void configureTypeExtensions(final RuntimeWiring.Builder builder) {
builder.scalar(GraphQLLong);
}

/** Configures resolvers responsible for resolving the {@link ERModelRelationship} type. */
private void configureERModelRelationshipResolvers(final RuntimeWiring.Builder builder) {
builder
.type(
"ERModelRelationship",
typeWiring ->
typeWiring
.dataFetcher("privileges", new EntityPrivilegesResolver(entityClient))
.dataFetcher(
"relationships", new EntityRelationshipsResultResolver(graphClient)))
.type(
"ERModelRelationshipProperties",
typeWiring ->
typeWiring
.dataFetcher(
"source",
new LoadableTypeResolver<>(
datasetType,
(env) -> {
final ERModelRelationshipProperties erModelRelationshipProperties =
env.getSource();
return erModelRelationshipProperties.getSource() != null
? erModelRelationshipProperties.getSource().getUrn()
: null;
}))
.dataFetcher(
"destination",
new LoadableTypeResolver<>(
datasetType,
(env) -> {
final ERModelRelationshipProperties erModelRelationshipProperties =
env.getSource();
return erModelRelationshipProperties.getDestination() != null
? erModelRelationshipProperties.getDestination().getUrn()
: null;
})))
.type(
"Owner",
typeWiring ->
typeWiring.dataFetcher(
"owner",
new OwnerTypeResolver<>(
ownerTypes, (env) -> ((Owner) env.getSource()).getOwner())))
.type(
"InstitutionalMemoryMetadata",
typeWiring ->
typeWiring.dataFetcher(
"author",
new LoadableTypeResolver<>(
corpUserType,
(env) ->
((InstitutionalMemoryMetadata) env.getSource()).getAuthor().getUrn())));
}

/**
* Configures resolvers responsible for resolving the {@link
* com.linkedin.datahub.graphql.generated.DataJob} type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.linkedin.metadata.recommendation.RecommendationsService;
import com.linkedin.metadata.secret.SecretService;
import com.linkedin.metadata.service.DataProductService;
import com.linkedin.metadata.service.ERModelRelationshipService;
import com.linkedin.metadata.service.FormService;
import com.linkedin.metadata.service.LineageService;
import com.linkedin.metadata.service.OwnershipTypeService;
Expand Down Expand Up @@ -75,6 +76,7 @@ public class GmsGraphQLEngineArgs {
QueryService queryService;
FeatureFlags featureFlags;
DataProductService dataProductService;
ERModelRelationshipService erModelRelationshipService;
FormService formService;
RestrictedService restrictedService;
int graphQLQueryComplexityLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class FeatureFlags {
private boolean platformBrowseV2 = false;
private PreProcessHooks preProcessHooks;
private boolean showAcrylInfo = false;
private boolean erModelRelationshipFeatureEnabled = false;
private boolean showAccessManagement = false;
private boolean nestedDomainsEnabled = false;
private boolean schemaFieldEntityFetchEnabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public CompletableFuture<AppConfig> get(final DataFetchingEnvironment environmen
.setReadOnlyModeEnabled(_featureFlags.isReadOnlyModeEnabled())
.setShowBrowseV2(_featureFlags.isShowBrowseV2())
.setShowAcrylInfo(_featureFlags.isShowAcrylInfo())
.setErModelRelationshipFeatureEnabled(
_featureFlags.isErModelRelationshipFeatureEnabled())
.setShowAccessManagement(_featureFlags.isShowAccessManagement())
.setNestedDomainsEnabled(_featureFlags.isNestedDomainsEnabled())
.setPlatformBrowseV2(_featureFlags.isPlatformBrowseV2())
Expand Down Expand Up @@ -262,6 +264,10 @@ private EntityType mapResourceTypeToEntityType(final String resourceType) {
.getResourceType()
.equals(resourceType)) {
return EntityType.CORP_USER;
} else if (com.linkedin.metadata.authorization.PoliciesConfig.ER_MODEL_RELATIONSHIP_PRIVILEGES
.getResourceType()
.equals(resourceType)) {
return EntityType.ER_MODEL_RELATIONSHIP;
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.linkedin.datahub.graphql.generated.DataProduct;
import com.linkedin.datahub.graphql.generated.Dataset;
import com.linkedin.datahub.graphql.generated.Domain;
import com.linkedin.datahub.graphql.generated.ERModelRelationship;
import com.linkedin.datahub.graphql.generated.Entity;
import com.linkedin.datahub.graphql.generated.EntityType;
import com.linkedin.datahub.graphql.generated.GlossaryNode;
Expand Down Expand Up @@ -155,6 +156,11 @@ public Entity apply(Urn input) {
((Domain) partialEntity).setUrn(input.toString());
((Domain) partialEntity).setType(EntityType.DOMAIN);
}
if (input.getEntityType().equals("erModelRelationship")) {
partialEntity = new ERModelRelationship();
((ERModelRelationship) partialEntity).setUrn(input.toString());
((ERModelRelationship) partialEntity).setType(EntityType.ER_MODEL_RELATIONSHIP);
}
if (input.getEntityType().equals("assertion")) {
partialEntity = new Assertion();
((Assertion) partialEntity).setUrn(input.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class EntityTypeMapper {
.put(EntityType.NOTEBOOK, "notebook")
.put(EntityType.DATA_PLATFORM_INSTANCE, "dataPlatformInstance")
.put(EntityType.TEST, "test")
.put(EntityType.ER_MODEL_RELATIONSHIP, Constants.ER_MODEL_RELATIONSHIP_ENTITY_NAME)
.put(EntityType.DATAHUB_VIEW, Constants.DATAHUB_VIEW_ENTITY_NAME)
.put(EntityType.DATA_PRODUCT, Constants.DATA_PRODUCT_ENTITY_NAME)
.put(EntityType.SCHEMA_FIELD, "schemaField")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.linkedin.datahub.graphql.types.ermodelrelationship;

import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument;

import com.datahub.authentication.Authentication;
import com.linkedin.common.urn.CorpuserUrn;
import com.linkedin.common.urn.ERModelRelationshipUrn;
import com.linkedin.common.urn.Urn;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.exception.AuthorizationException;
import com.linkedin.datahub.graphql.generated.ERModelRelationship;
import com.linkedin.datahub.graphql.generated.ERModelRelationshipPropertiesInput;
import com.linkedin.datahub.graphql.generated.ERModelRelationshipUpdateInput;
import com.linkedin.datahub.graphql.types.ermodelrelationship.mappers.ERModelRelationMapper;
import com.linkedin.datahub.graphql.types.ermodelrelationship.mappers.ERModelRelationshipUpdateInputMapper;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.metadata.service.ERModelRelationshipService;
import com.linkedin.mxe.MetadataChangeProposal;
import com.linkedin.r2.RemoteInvocationException;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;

@Slf4j
@RequiredArgsConstructor
public class CreateERModelRelationshipResolver
implements DataFetcher<CompletableFuture<ERModelRelationship>> {

private final EntityClient _entityClient;
private final ERModelRelationshipService _erModelRelationshipService;

@Override
public CompletableFuture<ERModelRelationship> get(DataFetchingEnvironment environment)
throws Exception {
final ERModelRelationshipUpdateInput input =
bindArgument(environment.getArgument("input"), ERModelRelationshipUpdateInput.class);

final ERModelRelationshipPropertiesInput erModelRelationshipPropertiesInput =
input.getProperties();
String ermodelrelationName = erModelRelationshipPropertiesInput.getName();
String source = erModelRelationshipPropertiesInput.getSource();
String destination = erModelRelationshipPropertiesInput.getDestination();

String lowDataset = source;
String highDataset = destination;
if (source.compareTo(destination) > 0) {
lowDataset = destination;
highDataset = source;
}
// The following sequence mimics datahub.emitter.mce_builder.datahub_guid

String ermodelrelationKey =
"{\"Source\":\""
+ lowDataset
+ "\",\"Destination\":\""
+ highDataset
+ "\",\"ERModelRelationName\":\""
+ ermodelrelationName
+ "\"}";

byte[] mybytes = ermodelrelationKey.getBytes(StandardCharsets.UTF_8);

String ermodelrelationKeyEncoded = new String(mybytes, StandardCharsets.UTF_8);
String ermodelrelationGuid = DigestUtils.md5Hex(ermodelrelationKeyEncoded);
log.info(
"ermodelrelationkey {}, ermodelrelationGuid {}",
ermodelrelationKeyEncoded,
ermodelrelationGuid);

ERModelRelationshipUrn inputUrn = new ERModelRelationshipUrn(ermodelrelationGuid);
QueryContext context = environment.getContext();
final Authentication authentication = context.getAuthentication();
final CorpuserUrn actor = CorpuserUrn.createFromString(context.getActorUrn());
if (!ERModelRelationshipType.canCreateERModelRelation(
context,
Urn.createFromString(input.getProperties().getSource()),
Urn.createFromString(input.getProperties().getDestination()))) {
throw new AuthorizationException(
"Unauthorized to create erModelRelationship. Please contact your DataHub administrator.");
}
return CompletableFuture.supplyAsync(
() -> {
try {
log.debug("Create ERModelRelation input: {}", input);
final Collection<MetadataChangeProposal> proposals =
ERModelRelationshipUpdateInputMapper.map(input, actor);
proposals.forEach(proposal -> proposal.setEntityUrn(inputUrn));
try {
_entityClient.batchIngestProposals(proposals, context.getAuthentication(), false);
} catch (RemoteInvocationException e) {
throw new RuntimeException("Failed to create erModelRelationship entity", e);
}
return ERModelRelationMapper.map(
_erModelRelationshipService.getERModelRelationshipResponse(
Urn.createFromString(inputUrn.toString()), authentication));
} catch (Exception e) {
log.error(
"Failed to create ERModelRelation to resource with input {}, {}",
input,
e.getMessage());
throw new RuntimeException(
String.format(
"Failed to create erModelRelationship to resource with input %s", input),
e);
}
});
}
}
Loading
Loading