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(ui/backend/openapi/docs) : Add support for Business Attributes #9863

Merged
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
d443b07
business-attribute: graphql crud resolvers and metadata models
deepgarg-visa Dec 17, 2023
830294d
business-attribute: add businessAttributeService
deepgarg-visa Dec 18, 2023
a3d81d1
business-attribute: add resolvers to add/remove businessattribute to …
deepgarg-visa Dec 21, 2023
0e84213
business-attribute: Created initial version of Business Attribute Scr…
PrithviVISA Jan 3, 2024
f02ffee
Merge pull request #3 from PrithviVISA/business-attributes-v1
PrithviVISA Jan 5, 2024
5606c91
Added lastModified and Created for business Attribute
PrithviVISA Jan 10, 2024
f988a10
Merge branch 'business-attributes-v1' of https://github.com/deepgarg-…
deepgarg-visa Jan 10, 2024
583d647
business-attribute: refactoring and added lastmodified
deepgarg-visa Jan 10, 2024
41b6731
business-attribute: junits for business attribute resolvers
deepgarg-visa Jan 11, 2024
730bb5a
Business Attribute Association
aditigup-visa Jan 16, 2024
618e691
Merge pull request #5 from aditigup-visa/business-attributes-v1
deepgarg-visa Jan 17, 2024
c1f7680
Business Attribute related entities and css
aditigup-visa Jan 19, 2024
fed0202
Merge pull request #6 from aditigup-visa/business-attributes-v1
deepgarg-visa Jan 21, 2024
58d364e
businessattribute: openApi support
deepgarg-visa Jan 22, 2024
b127d4f
businessattribute: businessattribute custom properties fetching
deepgarg-visa Jan 22, 2024
1ab94f2
Business Attribute Minor Issues
aditigup-visa Jan 23, 2024
fcbc9c1
Business Attribute Minor Issues
aditigup-visa Jan 24, 2024
b7aea86
Merge pull request #7 from aditigup-visa/business-attributes-v1
deepgarg-visa Jan 24, 2024
fa23494
businessattribute: generate platform events for business attributes
deepgarg-visa Jan 27, 2024
aaf5182
businessattribute: metadata access management for Business Attribute
deepgarg-visa Feb 1, 2024
24baf28
businessattribute: modifify policies.json
deepgarg-visa Feb 2, 2024
8bc9669
businessattribute: generate lifecycle platform events
deepgarg-visa Feb 2, 2024
249adec
Cypress Test Cases, Preview Test Case, updating delete BA api, Removi…
aditigup-visa Feb 5, 2024
70054ea
Enabling editing data type
aditigup-visa Feb 5, 2024
e0ff89d
Merge pull request #10 from aditigup-visa/business-attributes-v1
deepgarg-visa Feb 5, 2024
3aee567
Merge branch 'master' into business-attributes
deepgarg-visa Feb 7, 2024
0ba227c
businessattribute: resolve merge conflicts with master
deepgarg-visa Feb 7, 2024
8f5ea63
business-attribute: businessattributes change propagation platform ev…
aabharti-visa Feb 2, 2024
7877912
Business attribute UI changes merged with master
aditigup-visa Feb 12, 2024
5e78afd
Merge remote-tracking branch 'datahub/business-attributes' into busin…
aditigup-visa Feb 12, 2024
e6b9d24
Merge remote-tracking branch 'datahub/business-attributes' into busin…
aditigup-visa Feb 12, 2024
dbc0a40
Merge branch 'business-attributes' of https://github.com/deepgarg-vis…
deepgarg-visa Feb 12, 2024
950f40b
business-attribute: documentation
deepgarg-visa Feb 13, 2024
6b25744
Business Attribute : SearchableRef Annotation Elastic Insert and Search
hisingh-visa Feb 13, 2024
07b9494
business-attribute: update documentation
deepgarg-visa Feb 15, 2024
f5420e9
Merge branch 'master' into business-attributes
deepgarg-visa Feb 19, 2024
9b65c79
Merge branch 'master' into business-attributes
deepgarg-visa Feb 28, 2024
6c05227
business-attributes-propagation-tests
aabharti-visa Mar 1, 2024
3cec180
Merge pull request #23 from deepgarg-visa/business-attributes-propaga…
deepgarg-visa Mar 1, 2024
3b2c34c
business attributes: fixing dependency issue
deepgarg-visa Mar 4, 2024
c68bcbc
Merge branch 'master' into business-attributes
deepgarg-visa Mar 4, 2024
3669141
business-attribute: fix issues due to merge conflicts
deepgarg-visa Mar 6, 2024
13e5aee
Business Attribute : SearchableRef Unit Test
hisingh-visa Dec 20, 2023
6b242a0
fix(ui): business-attribute: Dulicate Gloassary term rendering
amit-visa Mar 6, 2024
77ba88f
Merge pull request #24 from hisingh-visa/business-attributes-ref-unit…
deepgarg-visa Mar 7, 2024
1c7c6e5
Bug Fix : SearchableRef Search Reference Field
hisingh-visa Mar 4, 2024
f394657
fix(ui): business-attribute: institutional memory support
deepgarg-visa Mar 7, 2024
7026939
Merge pull request #27 from hisingh-visa/business-attributes-searchab…
deepgarg-visa Mar 8, 2024
4562978
Fix : Business Attribute SearchableRef Search Depth
hisingh-visa Mar 19, 2024
a1294bf
business-attributes: review comments - business attributes lives in s…
deepgarg-visa Mar 19, 2024
7365b43
Merge branch 'master' into business-attributes
deepgarg-visa Mar 20, 2024
0bb7aa4
business-attributes: review comments - refactor businessAttribute pro…
deepgarg-visa Mar 20, 2024
0cc49c0
feature flag for business attribute GENAI=YES
aabharti-visa Mar 21, 2024
b7d827f
Merge branch 'business-attributes' of https://github.com/deepgarg-vis…
aabharti-visa Mar 21, 2024
ba03044
rebase
aabharti-visa Mar 21, 2024
b497277
Merge pull request #29 from deepgarg-visa/feature-flag-for-business-a…
deepgarg-visa Mar 21, 2024
8cb0811
Merge pull request #28 from hisingh-visa/business-attributes-depth_fix
deepgarg-visa Mar 21, 2024
e2651a8
business-attributes: support for custom urn with graphql
deepgarg-visa Mar 22, 2024
cb54236
Merge branch 'master' into business-attributes
deepgarg-visa Mar 26, 2024
8411393
business-attributes: Update Business Attribute changes as per current…
deepgarg-visa Mar 27, 2024
89d9e93
Merge branch 'master' into business-attributes
deepgarg-visa Mar 28, 2024
baa052b
Business Attributes: UI Schema Field Entity Changes
kartikey-visa Mar 28, 2024
56b3066
Merge pull request #30 from kartikey-visa/feature/business-attributes…
deepgarg-visa Apr 1, 2024
ee865dd
feat(search): Add SchemaFieldEntity to search functionality
amit-visa Apr 2, 2024
7997a12
Business Attributes: UI Show|Hide Feature Flag Implementation | Modif…
kartikey-visa Mar 28, 2024
d05f792
Merge pull request #31 from kartikey-visa/feature/ui-business-attribu…
deepgarg-visa Apr 3, 2024
c277123
Merge pull request #32 from amit-visa/schema-field-search
deepgarg-visa Apr 3, 2024
982f7d5
Business Attributes: Customized URNs Support for Business Attributes
kartikey-visa Apr 3, 2024
998aeb2
Merge pull request #33 from kartikey-visa/feature/added-support-for-c…
deepgarg-visa Apr 3, 2024
8195acf
Business Attributes: Fixed Schema Field Cypress Test Cases
kartikey-visa Apr 3, 2024
d43a0bc
Merge pull request #34 from kartikey-visa/test/fixed-cypress-test-cas…
deepgarg-visa Apr 3, 2024
799759e
business-attributes: introduce fieldNamealias for schemafieldentity
deepgarg-visa Apr 4, 2024
dafa1c7
feat(search/schema_field): Update schema field card in search results
amit-visa Apr 4, 2024
4e0b9e4
Merge pull request #38 from amit-visa/feature/schema-field-attr
deepgarg-visa Apr 4, 2024
ec2d7ea
Business Attributes: Feature Flag Cypress Test Cases Fix
kartikey-visa Apr 3, 2024
0e39770
Merge pull request #36 from kartikey-visa/test/feature-flag-cypress-t…
deepgarg-visa Apr 4, 2024
cd15208
business-attribute-flag-for-openapi
aabharti-visa Apr 4, 2024
b2854bd
Merge pull request #37 from aabharti-visa/feature-flag-for-business-a…
deepgarg-visa Apr 4, 2024
1c2ba53
Merge branch 'master' into business-attributes
deepgarg-visa Apr 14, 2024
3267fdf
business-attributes: changes due to merge resolve conflicts
deepgarg-visa Apr 14, 2024
6640d2b
business-attributes: fix failing frontend test
deepgarg-visa Apr 15, 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 @@ -60,6 +60,7 @@ public class OpenApiEntities {
.add("dataProductProperties")
.add("institutionalMemory")
.add("forms").add("formInfo").add("dynamicFormAssignment")
.add("businessAttributeInfo")
.build();

private final static ImmutableSet<String> ENTITY_EXCLUSIONS = ImmutableSet.<String>builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.linkedin.datahub.graphql.generated.BrowsePathEntry;
import com.linkedin.datahub.graphql.generated.BrowseResultGroupV2;
import com.linkedin.datahub.graphql.generated.BrowseResults;
import com.linkedin.datahub.graphql.generated.BusinessAttribute;
import com.linkedin.datahub.graphql.generated.BusinessAttributeAssociation;
import com.linkedin.datahub.graphql.generated.Chart;
import com.linkedin.datahub.graphql.generated.ChartInfo;
import com.linkedin.datahub.graphql.generated.Container;
Expand Down Expand Up @@ -68,6 +70,7 @@
import com.linkedin.datahub.graphql.generated.InstitutionalMemoryMetadata;
import com.linkedin.datahub.graphql.generated.LineageRelationship;
import com.linkedin.datahub.graphql.generated.ListAccessTokenResult;
import com.linkedin.datahub.graphql.generated.ListBusinessAttributesResult;
import com.linkedin.datahub.graphql.generated.ListDomainsResult;
import com.linkedin.datahub.graphql.generated.ListGroupsResult;
import com.linkedin.datahub.graphql.generated.ListOwnershipTypesResult;
Expand Down Expand Up @@ -115,6 +118,12 @@
import com.linkedin.datahub.graphql.resolvers.browse.BrowsePathsResolver;
import com.linkedin.datahub.graphql.resolvers.browse.BrowseResolver;
import com.linkedin.datahub.graphql.resolvers.browse.EntityBrowsePathsResolver;
import com.linkedin.datahub.graphql.resolvers.businessattribute.AddBusinessAttributeResolver;
import com.linkedin.datahub.graphql.resolvers.businessattribute.CreateBusinessAttributeResolver;
import com.linkedin.datahub.graphql.resolvers.businessattribute.DeleteBusinessAttributeResolver;
import com.linkedin.datahub.graphql.resolvers.businessattribute.ListBusinessAttributesResolver;
import com.linkedin.datahub.graphql.resolvers.businessattribute.RemoveBusinessAttributeResolver;
import com.linkedin.datahub.graphql.resolvers.businessattribute.UpdateBusinessAttributeResolver;
import com.linkedin.datahub.graphql.resolvers.chart.BrowseV2Resolver;
import com.linkedin.datahub.graphql.resolvers.chart.ChartStatsSummaryResolver;
import com.linkedin.datahub.graphql.resolvers.config.AppConfigResolver;
Expand Down Expand Up @@ -289,6 +298,7 @@
import com.linkedin.datahub.graphql.types.aspect.AspectType;
import com.linkedin.datahub.graphql.types.assertion.AssertionType;
import com.linkedin.datahub.graphql.types.auth.AccessTokenMetadataType;
import com.linkedin.datahub.graphql.types.businessattribute.BusinessAttributeType;
import com.linkedin.datahub.graphql.types.chart.ChartType;
import com.linkedin.datahub.graphql.types.common.mappers.OperationMapper;
import com.linkedin.datahub.graphql.types.common.mappers.UrnToEntityMapper;
Expand Down Expand Up @@ -345,6 +355,7 @@
import com.linkedin.metadata.query.filter.SortOrder;
import com.linkedin.metadata.recommendation.RecommendationsService;
import com.linkedin.metadata.secret.SecretService;
import com.linkedin.metadata.service.BusinessAttributeService;
import com.linkedin.metadata.service.DataProductService;
import com.linkedin.metadata.service.FormService;
import com.linkedin.metadata.service.LineageService;
Expand Down Expand Up @@ -420,6 +431,7 @@ public class GmsGraphQLEngine {
private final FormService formService;
private final RestrictedService restrictedService;

private final BusinessAttributeService businessAttributeService;
private final FeatureFlags featureFlags;

private final IngestionConfiguration ingestionConfiguration;
Expand Down Expand Up @@ -476,6 +488,8 @@ public class GmsGraphQLEngine {
private final int graphQLQueryComplexityLimit;
private final int graphQLQueryDepthLimit;

private final BusinessAttributeType businessAttributeType;

/** A list of GraphQL Plugins that extend the core engine */
private final List<GmsGraphQLPlugin> graphQLPlugins;

Expand Down Expand Up @@ -533,6 +547,7 @@ public GmsGraphQLEngine(final GmsGraphQLEngineArgs args) {
this.formService = args.formService;
this.restrictedService = args.restrictedService;

this.businessAttributeService = args.businessAttributeService;
this.ingestionConfiguration = Objects.requireNonNull(args.ingestionConfiguration);
this.authenticationConfiguration = Objects.requireNonNull(args.authenticationConfiguration);
this.authorizationConfiguration = Objects.requireNonNull(args.authorizationConfiguration);
Expand Down Expand Up @@ -586,6 +601,7 @@ public GmsGraphQLEngine(final GmsGraphQLEngineArgs args) {
this.graphQLQueryComplexityLimit = args.graphQLQueryComplexityLimit;
this.graphQLQueryDepthLimit = args.graphQLQueryDepthLimit;

this.businessAttributeType = new BusinessAttributeType(entityClient);
// Init Lists
this.entityTypes =
ImmutableList.of(
Expand Down Expand Up @@ -626,7 +642,8 @@ public GmsGraphQLEngine(final GmsGraphQLEngineArgs args) {
entityTypeType,
formType,
incidentType,
restrictedType);
restrictedType,
businessAttributeType);
this.loadableTypes = new ArrayList<>(entityTypes);
// Extend loadable types with types from the plugins
// This allows us to offer search and browse capabilities out of the box for those types
Expand Down Expand Up @@ -717,6 +734,8 @@ public void configureRuntimeWiring(final RuntimeWiring.Builder builder) {
configureFormResolvers(builder);
configureIncidentResolvers(builder);
configureRestrictedResolvers(builder);
configureBusinessAttributeResolver(builder);
configureBusinessAttributeAssociationResolver(builder);
}

private void configureOrganisationRoleResolvers(RuntimeWiring.Builder builder) {
Expand Down Expand Up @@ -1002,7 +1021,11 @@ private void configureQueryResolvers(final RuntimeWiring.Builder builder) {
"listOwnershipTypes", new ListOwnershipTypesResolver(this.entityClient))
.dataFetcher(
"browseV2",
new BrowseV2Resolver(this.entityClient, this.viewService, this.formService)));
new BrowseV2Resolver(this.entityClient, this.viewService, this.formService))
.dataFetcher("businessAttribute", getResolver(businessAttributeType))
.dataFetcher(
"listBusinessAttributes",
new ListBusinessAttributesResolver(this.entityClient)));
}

private DataFetcher getEntitiesResolver() {
Expand Down Expand Up @@ -1227,7 +1250,24 @@ private void configureMutationResolvers(final RuntimeWiring.Builder builder) {
.dataFetcher("raiseIncident", new RaiseIncidentResolver(this.entityClient))
.dataFetcher(
"updateIncidentStatus",
new UpdateIncidentStatusResolver(this.entityClient, this.entityService)));
new UpdateIncidentStatusResolver(this.entityClient, this.entityService))
.dataFetcher(
"createBusinessAttribute",
new CreateBusinessAttributeResolver(
this.entityClient, this.entityService, this.businessAttributeService))
.dataFetcher(
"updateBusinessAttribute",
new UpdateBusinessAttributeResolver(
this.entityClient, this.businessAttributeService))
.dataFetcher(
"deleteBusinessAttribute",
new DeleteBusinessAttributeResolver(this.entityClient))
.dataFetcher(
"addBusinessAttribute",
new AddBusinessAttributeResolver(this.entityClient, this.entityService))
.dataFetcher(
"removeBusinessAttribute",
new RemoveBusinessAttributeResolver(this.entityClient, this.entityService)));
}

private void configureGenericEntityResolvers(final RuntimeWiring.Builder builder) {
Expand Down Expand Up @@ -2826,4 +2866,40 @@ private void configureRestrictedResolvers(final RuntimeWiring.Builder builder) {
siblingGraphService, restrictedService, this.authorizationConfiguration))
.dataFetcher("relationships", new EntityRelationshipsResultResolver(graphClient)));
}

private void configureBusinessAttributeResolver(final RuntimeWiring.Builder builder) {
builder
.type(
"BusinessAttribute",
typeWiring ->
typeWiring
.dataFetcher("exists", new EntityExistsResolver(entityService))
.dataFetcher("privileges", new EntityPrivilegesResolver(entityClient)))
.type(
"ListBusinessAttributesResult",
typeWiring ->
typeWiring.dataFetcher(
"businessAttributes",
new LoadableTypeBatchResolver<>(
businessAttributeType,
(env) ->
((ListBusinessAttributesResult) env.getSource())
.getBusinessAttributes().stream()
.map(BusinessAttribute::getUrn)
.collect(Collectors.toList()))));
}

private void configureBusinessAttributeAssociationResolver(final RuntimeWiring.Builder builder) {
builder.type(
"BusinessAttributeAssociation",
typeWiring ->
typeWiring.dataFetcher(
"businessAttribute",
new LoadableTypeResolver<>(
businessAttributeType,
(env) ->
((BusinessAttributeAssociation) env.getSource())
.getBusinessAttribute()
.getUrn())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.linkedin.metadata.models.registry.EntityRegistry;
import com.linkedin.metadata.recommendation.RecommendationsService;
import com.linkedin.metadata.secret.SecretService;
import com.linkedin.metadata.service.BusinessAttributeService;
import com.linkedin.metadata.service.DataProductService;
import com.linkedin.metadata.service.FormService;
import com.linkedin.metadata.service.LineageService;
Expand Down Expand Up @@ -79,6 +80,7 @@ public class GmsGraphQLEngineArgs {
RestrictedService restrictedService;
int graphQLQueryComplexityLimit;
int graphQLQueryDepthLimit;
BusinessAttributeService businessAttributeService;

// any fork specific args should go below this line
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.linkedin.datahub.graphql.generated.AuthenticatedUser;
import com.linkedin.datahub.graphql.generated.CorpUser;
import com.linkedin.datahub.graphql.generated.PlatformPrivileges;
import com.linkedin.datahub.graphql.resolvers.businessattribute.BusinessAttributeAuthorizationUtils;
import com.linkedin.datahub.graphql.types.corpuser.mappers.CorpUserMapper;
import com.linkedin.entity.EntityResponse;
import com.linkedin.entity.client.EntityClient;
Expand Down Expand Up @@ -84,7 +85,10 @@ public CompletableFuture<AuthenticatedUser> get(DataFetchingEnvironment environm
AuthorizationUtils.canManageOwnershipTypes(context));
platformPrivileges.setManageGlobalAnnouncements(
AuthorizationUtils.canManageGlobalAnnouncements(context));

platformPrivileges.setCreateBusinessAttributes(
BusinessAttributeAuthorizationUtils.canCreateBusinessAttribute(context));
platformPrivileges.setManageBusinessAttributes(
BusinessAttributeAuthorizationUtils.canManageBusinessAttribute(context));
// Construct and return authenticated user object.
final AuthenticatedUser authUser = new AuthenticatedUser();
authUser.setCorpUser(corpUser);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.linkedin.datahub.graphql.resolvers.businessattribute;

import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument;
import static com.linkedin.datahub.graphql.resolvers.businessattribute.BusinessAttributeAuthorizationUtils.isAuthorizeToUpdateDataset;
import static com.linkedin.datahub.graphql.resolvers.mutate.MutationUtils.buildMetadataChangeProposalWithUrn;
import static com.linkedin.datahub.graphql.resolvers.mutate.MutationUtils.getFieldInfoFromSchema;

import com.linkedin.businessattribute.BusinessAttributeAssociation;
import com.linkedin.common.AuditStamp;
import com.linkedin.common.urn.Urn;
import com.linkedin.common.urn.UrnUtils;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.exception.AuthorizationException;
import com.linkedin.datahub.graphql.generated.AddBusinessAttributeInput;
import com.linkedin.datahub.graphql.generated.ResourceRefInput;
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.entity.EntityService;
import com.linkedin.metadata.entity.EntityUtils;
import com.linkedin.mxe.MetadataChangeProposal;
import com.linkedin.r2.RemoteInvocationException;
import com.linkedin.schema.EditableSchemaFieldInfo;
import com.linkedin.schema.EditableSchemaMetadata;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.concurrent.CompletableFuture;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
public class AddBusinessAttributeResolver implements DataFetcher<CompletableFuture<Boolean>> {
private final EntityClient _entityClient;
private final EntityService _entityService;

@Override
public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throws Exception {
final QueryContext context = environment.getContext();
AddBusinessAttributeInput input =
bindArgument(environment.getArgument("input"), AddBusinessAttributeInput.class);
Urn businessAttributeUrn = UrnUtils.getUrn(input.getBusinessAttributeUrn());
ResourceRefInput resourceRefInput = input.getResourceUrn();
if (!isAuthorizeToUpdateDataset(
context, Urn.createFromString(resourceRefInput.getResourceUrn()))) {
throw new AuthorizationException(
"Unauthorized to perform this action. Please contact your DataHub administrator.");
}
if (!_entityClient.exists(businessAttributeUrn, context.getAuthentication())) {
throw new RuntimeException(
String.format("This urn does not exist: %s", businessAttributeUrn));
}
return CompletableFuture.supplyAsync(
() -> {
try {
validateInputResource(resourceRefInput);
addBusinessAttribute(businessAttributeUrn, resourceRefInput, context);
return true;
} catch (Exception e) {
throw new RuntimeException(
String.format(
"Failed to add Business Attribute with urn %s to dataset with urn %s",
businessAttributeUrn, resourceRefInput.getResourceUrn()),
e);
}
});
}

private void validateInputResource(ResourceRefInput resource) {
final Urn resourceUrn = UrnUtils.getUrn(resource.getResourceUrn());
LabelUtils.validateResource(
resourceUrn, resource.getSubResource(), resource.getSubResourceType(), _entityService);
}

private void addBusinessAttribute(
Urn businessAttributeUrn, ResourceRefInput resourceRefInput, QueryContext context)
throws RemoteInvocationException {
_entityClient.ingestProposal(
buildAddBusinessAttributeToSubresourceProposal(
businessAttributeUrn, resourceRefInput, context),
context.getAuthentication());
}

private MetadataChangeProposal buildAddBusinessAttributeToSubresourceProposal(
Urn businessAttributeUrn, ResourceRefInput resource, QueryContext context) {
com.linkedin.schema.EditableSchemaMetadata editableSchemaMetadata =
(com.linkedin.schema.EditableSchemaMetadata)
EntityUtils.getAspectFromEntity(
resource.getResourceUrn(),
Constants.EDITABLE_SCHEMA_METADATA_ASPECT_NAME,
_entityService,
new EditableSchemaMetadata());

EditableSchemaFieldInfo editableFieldInfo =
getFieldInfoFromSchema(editableSchemaMetadata, resource.getSubResource());

if (editableFieldInfo == null) {
throw new IllegalArgumentException(
String.format(
"Subresource %s does not exist in dataset %s",
resource.getSubResource(), resource.getResourceUrn()));
}

if (editableFieldInfo.hasBusinessAttribute()) {
throw new RuntimeException(
String.format("Schema field has already attached with business attribute"));
}
editableFieldInfo.setBusinessAttribute(new BusinessAttributeAssociation());
addBusinessAttribute(
editableFieldInfo.getBusinessAttribute(),
businessAttributeUrn,
UrnUtils.getUrn(context.getActorUrn()));
return buildMetadataChangeProposalWithUrn(
UrnUtils.getUrn(resource.getResourceUrn()),
Constants.EDITABLE_SCHEMA_METADATA_ASPECT_NAME,
editableSchemaMetadata);
}

private void addBusinessAttribute(
BusinessAttributeAssociation businessAttributeAssociation,
Urn businessAttributeUrn,
Urn actorUrn) {
businessAttributeAssociation.setDestinationUrn(businessAttributeUrn);
AuditStamp nowAuditStamp =
new AuditStamp().setTime(System.currentTimeMillis()).setActor(actorUrn);
businessAttributeAssociation.setCreated(nowAuditStamp);
businessAttributeAssociation.setLastModified(nowAuditStamp);
}
}
Loading
Loading