forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'datahub-project:master' into master
- Loading branch information
Showing
241 changed files
with
12,657 additions
and
3,357 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
54 changes: 54 additions & 0 deletions
54
...re/src/main/java/com/linkedin/datahub/graphql/resolvers/form/BatchRemoveFormResolver.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,54 @@ | ||
package com.linkedin.datahub.graphql.resolvers.form; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument; | ||
|
||
import com.datahub.authentication.Authentication; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.common.urn.UrnUtils; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.generated.BatchAssignFormInput; | ||
import com.linkedin.metadata.service.FormService; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nonnull; | ||
|
||
public class BatchRemoveFormResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
|
||
private final FormService _formService; | ||
|
||
public BatchRemoveFormResolver(@Nonnull final FormService formService) { | ||
_formService = Objects.requireNonNull(formService, "formService must not be null"); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(final DataFetchingEnvironment environment) | ||
throws Exception { | ||
final QueryContext context = environment.getContext(); | ||
|
||
final BatchAssignFormInput input = | ||
bindArgument(environment.getArgument("input"), BatchAssignFormInput.class); | ||
final Urn formUrn = UrnUtils.getUrn(input.getFormUrn()); | ||
final List<String> entityUrns = input.getEntityUrns(); | ||
final Authentication authentication = context.getAuthentication(); | ||
|
||
// TODO: (PRD-1062) Add permission check once permission exists | ||
|
||
return CompletableFuture.supplyAsync( | ||
() -> { | ||
try { | ||
_formService.batchUnassignFormForEntities( | ||
entityUrns.stream().map(UrnUtils::getUrn).collect(Collectors.toList()), | ||
formUrn, | ||
authentication); | ||
return true; | ||
} catch (Exception e) { | ||
throw new RuntimeException( | ||
String.format("Failed to perform update against input %s", input), 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
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
83 changes: 83 additions & 0 deletions
83
...rc/test/java/com/linkedin/datahub/graphql/resolvers/form/BatchRemoveFormResolverTest.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,83 @@ | ||
package com.linkedin.datahub.graphql.resolvers.form; | ||
|
||
import static com.linkedin.datahub.graphql.TestUtils.getMockAllowContext; | ||
import static org.testng.Assert.assertThrows; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import com.datahub.authentication.Authentication; | ||
import com.linkedin.common.urn.UrnUtils; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.generated.BatchAssignFormInput; | ||
import com.linkedin.metadata.service.FormService; | ||
import graphql.com.google.common.collect.ImmutableList; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.concurrent.CompletionException; | ||
import org.mockito.Mockito; | ||
import org.testng.annotations.Test; | ||
|
||
public class BatchRemoveFormResolverTest { | ||
|
||
private static final String TEST_DATASET_URN = | ||
"urn:li:dataset:(urn:li:dataPlatform:hive,name,PROD)"; | ||
private static final String TEST_FORM_URN = "urn:li:form:1"; | ||
|
||
private static final BatchAssignFormInput TEST_INPUT = | ||
new BatchAssignFormInput(TEST_FORM_URN, ImmutableList.of(TEST_DATASET_URN)); | ||
|
||
@Test | ||
public void testGetSuccess() throws Exception { | ||
FormService mockFormService = initMockFormService(true); | ||
BatchRemoveFormResolver resolver = new BatchRemoveFormResolver(mockFormService); | ||
|
||
// Execute resolver | ||
QueryContext mockContext = getMockAllowContext(); | ||
DataFetchingEnvironment mockEnv = Mockito.mock(DataFetchingEnvironment.class); | ||
Mockito.when(mockEnv.getArgument(Mockito.eq("input"))).thenReturn(TEST_INPUT); | ||
Mockito.when(mockEnv.getContext()).thenReturn(mockContext); | ||
|
||
boolean success = resolver.get(mockEnv).get(); | ||
|
||
assertTrue(success); | ||
|
||
// Validate that we called unassign on the service | ||
Mockito.verify(mockFormService, Mockito.times(1)) | ||
.batchUnassignFormForEntities( | ||
Mockito.eq(ImmutableList.of(UrnUtils.getUrn(TEST_DATASET_URN))), | ||
Mockito.eq(UrnUtils.getUrn(TEST_FORM_URN)), | ||
Mockito.any(Authentication.class)); | ||
} | ||
|
||
@Test | ||
public void testThrowsError() throws Exception { | ||
FormService mockFormService = initMockFormService(false); | ||
BatchRemoveFormResolver resolver = new BatchRemoveFormResolver(mockFormService); | ||
|
||
// Execute resolver | ||
QueryContext mockContext = getMockAllowContext(); | ||
DataFetchingEnvironment mockEnv = Mockito.mock(DataFetchingEnvironment.class); | ||
Mockito.when(mockEnv.getArgument(Mockito.eq("input"))).thenReturn(TEST_INPUT); | ||
Mockito.when(mockEnv.getContext()).thenReturn(mockContext); | ||
|
||
assertThrows(CompletionException.class, () -> resolver.get(mockEnv).join()); | ||
|
||
// Validate that we called unassign on the service - but it throws an error | ||
Mockito.verify(mockFormService, Mockito.times(1)) | ||
.batchUnassignFormForEntities( | ||
Mockito.eq(ImmutableList.of(UrnUtils.getUrn(TEST_DATASET_URN))), | ||
Mockito.eq(UrnUtils.getUrn(TEST_FORM_URN)), | ||
Mockito.any(Authentication.class)); | ||
} | ||
|
||
private FormService initMockFormService(final boolean shouldSucceed) throws Exception { | ||
FormService service = Mockito.mock(FormService.class); | ||
|
||
if (!shouldSucceed) { | ||
Mockito.doThrow(new RuntimeException()) | ||
.when(service) | ||
.batchUnassignFormForEntities( | ||
Mockito.any(), Mockito.any(), Mockito.any(Authentication.class)); | ||
} | ||
|
||
return service; | ||
} | ||
} |
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
Oops, something went wrong.