-
Notifications
You must be signed in to change notification settings - Fork 3k
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(users): adding user graphql mutation #4033
Merged
shirshanka
merged 7 commits into
datahub-project:master
from
gabe-lyons:gabe--addingUserMutations
Feb 3, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2d2c2e2
adding user mutations endpoint
gabe-lyons 4d6242f
Merge branch 'master' into gabe--addingUserMutations
gabe-lyons c828f88
adding reads + email
gabe-lyons 4baab06
Merge branch 'gabe--addingUserMutations' of github.com:gabe-lyons/dat…
gabe-lyons 02003b8
moving editable properties mapper to main snapshot mapper
gabe-lyons cbedf7e
Fix lint
gabe-lyons 6f817a1
Merge remote-tracking branch 'private/gabe--addingUserMutations' into…
gabe-lyons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package com.linkedin.datahub.graphql.types.corpuser; | ||
|
||
import com.linkedin.common.url.Url; | ||
import com.linkedin.common.urn.CorpuserUrn; | ||
|
||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.data.template.RecordTemplate; | ||
import com.linkedin.data.template.StringArray; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.generated.CorpUserUpdateInput; | ||
import com.linkedin.datahub.graphql.generated.EntityType; | ||
import com.linkedin.datahub.graphql.types.MutableType; | ||
import com.linkedin.datahub.graphql.types.SearchableEntityType; | ||
import com.linkedin.datahub.graphql.generated.AutoCompleteResults; | ||
import com.linkedin.datahub.graphql.generated.CorpUser; | ||
|
@@ -15,10 +20,16 @@ | |
import com.linkedin.datahub.graphql.types.mappers.UrnSearchResultsMapper; | ||
import com.linkedin.entity.Entity; | ||
import com.linkedin.entity.client.EntityClient; | ||
import com.linkedin.events.metadata.ChangeType; | ||
import com.linkedin.identity.CorpUserEditableInfo; | ||
import com.linkedin.metadata.Constants; | ||
import com.linkedin.metadata.query.AutoCompleteResult; | ||
import com.linkedin.metadata.search.SearchResult; | ||
|
||
import com.linkedin.metadata.utils.GenericAspectUtils; | ||
import com.linkedin.mxe.MetadataChangeProposal; | ||
import graphql.execution.DataFetcherResult; | ||
import java.util.Optional; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.net.URISyntaxException; | ||
|
@@ -29,7 +40,7 @@ | |
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class CorpUserType implements SearchableEntityType<CorpUser> { | ||
public class CorpUserType implements SearchableEntityType<CorpUser>, MutableType<CorpUserUpdateInput> { | ||
|
||
private final EntityClient _entityClient; | ||
|
||
|
@@ -99,4 +110,59 @@ private CorpuserUrn getCorpUserUrn(final String urnStr) { | |
throw new RuntimeException(String.format("Failed to retrieve user with urn %s, invalid urn", urnStr)); | ||
} | ||
} | ||
|
||
public Class<CorpUserUpdateInput> inputClass() { | ||
return CorpUserUpdateInput.class; | ||
} | ||
|
||
@Override | ||
public CorpUser update(@Nonnull String urn, @Nonnull CorpUserUpdateInput input, @Nonnull QueryContext context) throws Exception { | ||
final CorpuserUrn actor = CorpuserUrn.createFromString(context.getAuthentication().getActor().toUrnStr()); | ||
|
||
// Get existing editable info to merge with | ||
Optional<CorpUserEditableInfo> existingCorpUserEditableInfo = | ||
_entityClient.getVersionedAspect(urn, Constants.CORP_USER_EDITABLE_INFO_NAME, 0L, CorpUserEditableInfo.class, | ||
context.getAuthentication()); | ||
|
||
// Create the MCP | ||
final MetadataChangeProposal proposal = new MetadataChangeProposal(); | ||
proposal.setEntityUrn(Urn.createFromString(urn)); | ||
proposal.setEntityType(Constants.CORP_USER_ENTITY_NAME); | ||
proposal.setAspectName(Constants.CORP_USER_EDITABLE_INFO_NAME); | ||
proposal.setAspect(GenericAspectUtils.serializeAspect(mapCorpUserEditableInfo(input, existingCorpUserEditableInfo))); | ||
proposal.setChangeType(ChangeType.UPSERT); | ||
_entityClient.ingestProposal(proposal, context.getAuthentication()); | ||
|
||
return load(urn, context).getData(); | ||
} | ||
|
||
private RecordTemplate mapCorpUserEditableInfo(CorpUserUpdateInput input, Optional<CorpUserEditableInfo> existing) { | ||
CorpUserEditableInfo result = existing.orElseGet(() -> new CorpUserEditableInfo()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow this is awesome - I love how this is basically a patch! |
||
if (input.getAboutMe() != null) { | ||
result.setAboutMe(input.getAboutMe()); | ||
} | ||
if (input.getPictureLink() != null) { | ||
result.setPictureLink(new Url(input.getPictureLink())); | ||
} | ||
if (input.getAboutMe() != null) { | ||
result.setAboutMe(input.getAboutMe()); | ||
} | ||
if (input.getSkills() != null) { | ||
result.setSkills(new StringArray(input.getSkills())); | ||
} | ||
if (input.getTeams() != null) { | ||
result.setTeams(new StringArray(input.getTeams())); | ||
} | ||
if (input.getPhone() != null) { | ||
result.setPhone(input.getPhone()); | ||
} | ||
if (input.getSlack() != null) { | ||
result.setSlack(input.getSlack()); | ||
} | ||
if (input.getEmail() != null) { | ||
result.setEmail(input.getEmail()); | ||
} | ||
|
||
return result; | ||
} | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason we went specific here? Instead of saying "updateCorpUser" like the others?