forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(graphql): Adding resolvers for adding multiple tags, terms, and …
…owners (datahub-project#4917)
- Loading branch information
1 parent
8dbf135
commit 2a9d01e
Showing
14 changed files
with
1,128 additions
and
25 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
63 changes: 63 additions & 0 deletions
63
...l-core/src/main/java/com/linkedin/datahub/graphql/resolvers/mutate/AddOwnersResolver.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,63 @@ | ||
package com.linkedin.datahub.graphql.resolvers.mutate; | ||
|
||
import com.linkedin.common.urn.CorpuserUrn; | ||
|
||
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.AddOwnersInput; | ||
import com.linkedin.datahub.graphql.generated.OwnerInput; | ||
import com.linkedin.datahub.graphql.resolvers.mutate.util.OwnerUtils; | ||
import com.linkedin.metadata.entity.EntityService; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class AddOwnersResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
|
||
private final EntityService _entityService; | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throws Exception { | ||
final AddOwnersInput input = bindArgument(environment.getArgument("input"), AddOwnersInput.class); | ||
List<OwnerInput> owners = input.getOwners(); | ||
Urn targetUrn = Urn.createFromString(input.getResourceUrn()); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
|
||
if (!OwnerUtils.isAuthorizedToUpdateOwners(environment.getContext(), targetUrn)) { | ||
throw new AuthorizationException("Unauthorized to perform this action. Please contact your DataHub administrator."); | ||
} | ||
|
||
OwnerUtils.validateAddInput( | ||
owners, | ||
targetUrn, | ||
_entityService | ||
); | ||
try { | ||
|
||
log.debug("Adding Owners. input: {}", input.toString()); | ||
|
||
Urn actor = CorpuserUrn.createFromString(((QueryContext) environment.getContext()).getActorUrn()); | ||
OwnerUtils.addOwners( | ||
owners, | ||
targetUrn, | ||
actor, | ||
_entityService | ||
); | ||
return true; | ||
} catch (Exception e) { | ||
log.error("Failed to add owners to resource with input {}, {}", input.toString(), e.getMessage()); | ||
throw new RuntimeException(String.format("Failed to add owners to resource with input %s", input.toString()), e); | ||
} | ||
}); | ||
} | ||
} |
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
69 changes: 69 additions & 0 deletions
69
...hql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/mutate/AddTagsResolver.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,69 @@ | ||
package com.linkedin.datahub.graphql.resolvers.mutate; | ||
|
||
import com.linkedin.common.urn.CorpuserUrn; | ||
|
||
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.AddTagsInput; | ||
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils; | ||
import com.linkedin.metadata.entity.EntityService; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class AddTagsResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
|
||
private final EntityService _entityService; | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throws Exception { | ||
final AddTagsInput input = bindArgument(environment.getArgument("input"), AddTagsInput.class); | ||
List<Urn> tagUrns = input.getTagUrns().stream() | ||
.map(UrnUtils::getUrn) | ||
.collect(Collectors.toList()); | ||
Urn targetUrn = Urn.createFromString(input.getResourceUrn()); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
|
||
if (!LabelUtils.isAuthorizedToUpdateTags(environment.getContext(), targetUrn, input.getSubResource())) { | ||
throw new AuthorizationException("Unauthorized to perform this action. Please contact your DataHub administrator."); | ||
} | ||
|
||
LabelUtils.validateInput( | ||
tagUrns, | ||
targetUrn, | ||
input.getSubResource(), | ||
input.getSubResourceType(), | ||
"tag", | ||
_entityService, | ||
false | ||
); | ||
try { | ||
log.info("Adding Tags. input: {}", input.toString()); | ||
Urn actor = CorpuserUrn.createFromString(((QueryContext) environment.getContext()).getActorUrn()); | ||
LabelUtils.addTagsToTarget( | ||
tagUrns, | ||
targetUrn, | ||
input.getSubResource(), | ||
actor, | ||
_entityService | ||
); | ||
return true; | ||
} catch (Exception e) { | ||
log.error("Failed to perform update against input {}, {}", input.toString(), e.getMessage()); | ||
throw new RuntimeException(String.format("Failed to perform update against input %s", input.toString()), e); | ||
} | ||
}); | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
...ql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/mutate/AddTermsResolver.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,67 @@ | ||
package com.linkedin.datahub.graphql.resolvers.mutate; | ||
|
||
import com.linkedin.common.urn.CorpuserUrn; | ||
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.AddTermsInput; | ||
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils; | ||
import com.linkedin.metadata.entity.EntityService; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class AddTermsResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
private final EntityService _entityService; | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throws Exception { | ||
final AddTermsInput input = bindArgument(environment.getArgument("input"), AddTermsInput.class); | ||
List<Urn> termUrns = input.getTermUrns().stream() | ||
.map(UrnUtils::getUrn) | ||
.collect(Collectors.toList()); | ||
Urn targetUrn = Urn.createFromString(input.getResourceUrn()); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
|
||
if (!LabelUtils.isAuthorizedToUpdateTerms(environment.getContext(), targetUrn, input.getSubResource())) { | ||
throw new AuthorizationException("Unauthorized to perform this action. Please contact your DataHub administrator."); | ||
} | ||
|
||
LabelUtils.validateInput( | ||
termUrns, | ||
targetUrn, | ||
input.getSubResource(), | ||
input.getSubResourceType(), | ||
"glossaryTerm", | ||
_entityService, | ||
false | ||
); | ||
|
||
try { | ||
log.info("Adding Term. input: {}", input); | ||
Urn actor = CorpuserUrn.createFromString(((QueryContext) environment.getContext()).getActorUrn()); | ||
LabelUtils.addTermsToTarget( | ||
termUrns, | ||
targetUrn, | ||
input.getSubResource(), | ||
actor, | ||
_entityService | ||
); | ||
return true; | ||
} catch (Exception e) { | ||
log.error("Failed to perform update against input {}, {}", input.toString(), e.getMessage()); | ||
throw new RuntimeException(String.format("Failed to perform update against input %s", input.toString()), e); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.