From 8ef664d872c5df15b7fd357e2567cb3b86287a1e Mon Sep 17 00:00:00 2001 From: mohitdeuex Date: Mon, 16 Dec 2024 14:12:18 +0530 Subject: [PATCH 1/9] Update Create Team to use entityName for create requests --- .../service/resources/teams/TeamResource.java | 11 ++++++----- .../org/openmetadata/service/util/EntityUtil.java | 11 +++++++++++ .../resources/json/schema/api/teams/createTeam.json | 10 +++++----- .../ui/src/generated/api/teams/createTeam.ts | 4 +--- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/TeamResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/TeamResource.java index 6f0070dff28a..f268d76953d8 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/TeamResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/TeamResource.java @@ -764,12 +764,13 @@ private Team getTeam(CreateTeam ct, String user) { .copy(new Team(), ct, user) .withProfile(ct.getProfile()) .withIsJoinable(ct.getIsJoinable()) - .withUsers(EntityUtil.toEntityReferences(ct.getUsers(), Entity.USER)) - .withDefaultRoles(EntityUtil.toEntityReferences(ct.getDefaultRoles(), Entity.ROLE)) + .withUsers(EntityUtil.populateEntityReferenceFromFqn(ct.getUsers(), Entity.USER)) + .withDefaultRoles( + EntityUtil.populateEntityReferenceFromFqn(ct.getDefaultRoles(), Entity.ROLE)) .withTeamType(ct.getTeamType()) - .withParents(EntityUtil.toEntityReferences(ct.getParents(), Entity.TEAM)) - .withChildren(EntityUtil.toEntityReferences(ct.getChildren(), Entity.TEAM)) - .withPolicies(EntityUtil.toEntityReferences(ct.getPolicies(), Entity.POLICY)) + .withParents(EntityUtil.populateEntityReferenceFromFqn(ct.getParents(), Entity.TEAM)) + .withChildren(EntityUtil.populateEntityReferenceFromFqn(ct.getChildren(), Entity.TEAM)) + .withPolicies(EntityUtil.populateEntityReferenceFromFqn(ct.getPolicies(), Entity.POLICY)) .withEmail(ct.getEmail()) .withDomains(EntityUtil.getEntityReferences(Entity.DOMAIN, ct.getDomains())); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java index 234366057b27..845611140711 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java @@ -267,6 +267,17 @@ public static List toEntityReferences(List ids, String en .collect(Collectors.toList()); } + public static List populateEntityReferenceFromFqn( + List fqns, String entityType) { + if (fqns == null) { + return null; + } + return populateEntityReferences( + fqns.stream() + .map(fqn -> new EntityReference().withFullyQualifiedName(fqn).withType(entityType)) + .collect(Collectors.toList())); + } + public static List refToIds(List refs) { if (refs == null) { return null; diff --git a/openmetadata-spec/src/main/resources/json/schema/api/teams/createTeam.json b/openmetadata-spec/src/main/resources/json/schema/api/teams/createTeam.json index 2ee198f369fb..705fad42e6f1 100644 --- a/openmetadata-spec/src/main/resources/json/schema/api/teams/createTeam.json +++ b/openmetadata-spec/src/main/resources/json/schema/api/teams/createTeam.json @@ -35,7 +35,7 @@ "description": "Parent teams. For an `Organization` the `parent` is always null. A `BusinessUnit` always has only one parent of type `BusinessUnit` or an `Organization`. A `Division` can have multiple parents of type `BusinessUnit` or `Division`. A `Department` can have multiple parents of type `Division` or `Department`.", "type": "array", "items": { - "$ref": "../../type/basic.json#/definitions/uuid" + "$ref": "../../type/basic.json#/definitions/entityName" }, "default": null }, @@ -43,7 +43,7 @@ "description": "Children teams. An `Organization` can have `BusinessUnit`, `Division` or `Department` as children. A `BusinessUnit` can have `BusinessUnit`, `Division`, or `Department` as children. A `Division` can have `Division` or `Department` as children. A `Department` can have `Department` as children.", "type": "array", "items": { - "$ref": "../../type/basic.json#/definitions/uuid" + "$ref": "../../type/basic.json#/definitions/entityName" }, "default": null }, @@ -51,7 +51,7 @@ "description": "Optional IDs of users that are part of the team.", "type": "array", "items": { - "$ref": "../../type/basic.json#/definitions/uuid" + "$ref": "../../type/basic.json#/definitions/entityName" }, "default": null }, @@ -59,7 +59,7 @@ "description": "Roles to be assigned to all users that are part of this team.", "type": "array", "items": { - "$ref": "../../type/basic.json#/definitions/uuid" + "$ref": "../../type/basic.json#/definitions/entityName" }, "default": null }, @@ -77,7 +77,7 @@ "description": "Policies that is attached to this team.", "type": "array", "items": { - "$ref": "../../type/basic.json#/definitions/uuid" + "$ref": "../../type/basic.json#/definitions/entityName" }, "default": null }, diff --git a/openmetadata-ui/src/main/resources/ui/src/generated/api/teams/createTeam.ts b/openmetadata-ui/src/main/resources/ui/src/generated/api/teams/createTeam.ts index 9b60d31c1410..97c2ce6423ba 100644 --- a/openmetadata-ui/src/main/resources/ui/src/generated/api/teams/createTeam.ts +++ b/openmetadata-ui/src/main/resources/ui/src/generated/api/teams/createTeam.ts @@ -10,9 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - - /** +/** * Team entity */ export interface CreateTeam { From a4ec8b0548fd805ea4919d385369e1c8de408ea9 Mon Sep 17 00:00:00 2001 From: mohitdeuex Date: Mon, 16 Dec 2024 14:39:09 +0530 Subject: [PATCH 2/9] Test Fixes --- .../bundles/searchIndex/SearchIndexApp.java | 35 +++++++++++++++++++ .../service/jdbi3/EntityRepository.java | 11 ++++++ .../openmetadata/service/util/EntityUtil.java | 7 ++++ .../resources/feeds/FeedResourceTest.java | 2 +- .../feeds/SuggestionsResourceTest.java | 2 +- .../policies/PolicyResourceTest.java | 26 ++++++++++---- .../resources/teams/RoleResourceTest.java | 4 +-- .../openmetadata/service/util/TestUtils.java | 21 +++++++++++ 8 files changed, 98 insertions(+), 10 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/searchIndex/SearchIndexApp.java b/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/searchIndex/SearchIndexApp.java index fd34c2027f5c..fe34b8a53bc1 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/searchIndex/SearchIndexApp.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/searchIndex/SearchIndexApp.java @@ -49,11 +49,17 @@ import static org.openmetadata.service.workflows.searchIndex.ReindexingUtil.ENTITY_TYPE_KEY; import static org.openmetadata.service.workflows.searchIndex.ReindexingUtil.isDataInsightIndex; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Queue; import java.util.Set; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -168,6 +174,7 @@ public class SearchIndexApp extends AbstractNativeApplication { private final AtomicReference batchSize = new AtomicReference<>(5); private JobExecutionContext jobExecutionContext; private volatile boolean stopped = false; + Queue> entityRecords = new ConcurrentLinkedQueue<>(); public SearchIndexApp(CollectionDAO collectionDAO, SearchRepository searchRepository) { super(collectionDAO, searchRepository); @@ -309,6 +316,20 @@ private void performReindex(JobExecutionContext jobExecutionContext) throws Inte } finally { shutdownExecutor(jobExecutor, "JobExecutor", 20, TimeUnit.SECONDS); shutdownExecutor(producerExecutor, "ReaderExecutor", 1, TimeUnit.MINUTES); + + for (Map rec : entityRecords) { + try (BufferedWriter writer = + new BufferedWriter( + new FileWriter( + String.format( + "/Users/mohityadav/IdeaProjects/OMTesting/sample_data/%s.json", + rec.get(ENTITY_TYPE_KEY)), + true))) { + writer.write(JsonUtils.pojoToJson(rec, true)); + } catch (IOException e) { + e.printStackTrace(); + } + } } } @@ -657,6 +678,20 @@ private void processReadTask( LOG.debug("Read Entities with entityType: {}, CurrentOffset: {}", entityType, offset); if (resultList != null) { ResultList entities = extractEntities(entityType, resultList); + Map contextData = new HashMap<>(); + List> resultData = new ArrayList<>(); + for (Object ob : entities.getData()) { + Map result = JsonUtils.getMap(ob); + Map ansert = new HashMap<>(); + ansert.put("teamType", result.get("teamType")); + ansert.put("name", result.get("name")); + ansert.put("parents", result.get("parents")); + ansert.put("isJoinable", result.get("isJoinable")); + resultData.add(ansert); + } + contextData.put(ENTITY_TYPE_KEY, entityType); + contextData.put("records", resultData); + entityRecords.add(contextData); if (!nullOrEmpty(entities.getData())) { IndexingTask task = new IndexingTask<>(entityType, entities, offset); processTask(task, jobExecutionContext); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java index e86f736d444c..30555ca8cd85 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java @@ -961,6 +961,17 @@ public final PutResponse createOrUpdate(UriInfo uriInfo, T updated) { return update(uriInfo, original, updated); } + @Transaction + public final PutResponse createOrUpdate(UriInfo uriInfo, String updatedJson) { + T updated = JsonUtils.readValue(updatedJson, entityClass); + T original = findByNameOrNull(updated.getFullyQualifiedName(), ALL); + if (original == null) { // If an original entity does not exist then create it, else update + return new PutResponse<>( + Status.CREATED, withHref(uriInfo, createNewEntity(updated)), ENTITY_CREATED); + } + return update(uriInfo, original, updated); + } + @SuppressWarnings("unused") protected void postCreate(T entity) { if (supportsSearch) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java index 845611140711..097e60d52d4b 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java @@ -285,6 +285,13 @@ public static List refToIds(List refs) { return refs.stream().map(EntityReference::getId).collect(Collectors.toList()); } + public static List refToFqns(List refs) { + if (refs == null) { + return null; + } + return refs.stream().map(EntityReference::getFullyQualifiedName).collect(Collectors.toList()); + } + public static boolean isDescriptionRequired(Class clz) { // Returns true if description field in entity is required try { diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/FeedResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/FeedResourceTest.java index 3f8c92ca05d8..0bbda4caf4fc 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/FeedResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/FeedResourceTest.java @@ -177,7 +177,7 @@ public void setup(TestInfo test) throws IOException, URISyntaxException { .createRequest(test, 4) .withDisplayName("Team2") .withDescription("Team2 description") - .withUsers(List.of(USER2.getId())); + .withUsers(List.of(USER2.getFullyQualifiedName())); TEAM2 = teamResourceTest.createAndCheckEntity(createTeam, ADMIN_AUTH_HEADERS); EntityReference TEAM2_REF = TEAM2.getEntityReference(); diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/SuggestionsResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/SuggestionsResourceTest.java index a3375627643d..f87f7bbd633c 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/SuggestionsResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/SuggestionsResourceTest.java @@ -104,7 +104,7 @@ public void setup(TestInfo test) throws IOException, URISyntaxException { .createRequest(test, 4) .withDisplayName("Team2") .withDescription("Team2 description") - .withUsers(List.of(USER2.getId())); + .withUsers(List.of(USER2.getFullyQualifiedName())); TEAM2 = teamResourceTest.createAndCheckEntity(createTeam, ADMIN_AUTH_HEADERS); EntityReference TEAM2_REF = TEAM2.getEntityReference(); diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/policies/PolicyResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/policies/PolicyResourceTest.java index 1b3b30bb6f76..a75d307c0847 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/policies/PolicyResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/policies/PolicyResourceTest.java @@ -429,7 +429,9 @@ void get_policyTeamsAndRoles(TestInfo test) throws IOException { for (int i = 0; i < 3; i++) { // Team X has Policy X CreateTeam createTeam = - TEAM_TEST.createRequest(test, i).withPolicies(List.of(policies.get(i).getId())); + TEAM_TEST + .createRequest(test, i) + .withPolicies(List.of(policies.get(i).getFullyQualifiedName())); teams.add(TEAM_TEST.createEntity(createTeam, ADMIN_AUTH_HEADERS)); } @@ -542,15 +544,27 @@ void test_roles_policies_scenarios() throws HttpResponseException { TEAM_TEST .createRequest("rolesPoliciesTeam2") .withTeamType(DEPARTMENT) - .withDefaultRoles(listOf(DATA_STEWARD_ROLE.getId())); + .withDefaultRoles(listOf(DATA_STEWARD_ROLE.getFullyQualifiedName())); Team team2 = TEAM_TEST.createEntity(createTeam, ADMIN_AUTH_HEADERS); - createTeam = TEAM_TEST.createRequest("rolesPoliciesTeam11").withParents(listOf(team1.getId())); + createTeam = + TEAM_TEST + .createRequest("rolesPoliciesTeam11") + .withParents(listOf(team1.getFullyQualifiedName())); Team team11 = TEAM_TEST.createEntity(createTeam, ADMIN_AUTH_HEADERS); - createTeam = TEAM_TEST.createRequest("rolesPoliciesTeam12").withParents(listOf(team1.getId())); + createTeam = + TEAM_TEST + .createRequest("rolesPoliciesTeam12") + .withParents(listOf(team1.getFullyQualifiedName())); Team team12 = TEAM_TEST.createEntity(createTeam, ADMIN_AUTH_HEADERS); - createTeam = TEAM_TEST.createRequest("rolesPoliciesTeam21").withParents(listOf(team2.getId())); + createTeam = + TEAM_TEST + .createRequest("rolesPoliciesTeam21") + .withParents(listOf(team2.getFullyQualifiedName())); Team team21 = TEAM_TEST.createEntity(createTeam, ADMIN_AUTH_HEADERS); - createTeam = TEAM_TEST.createRequest("rolesPoliciesTeam22").withParents(listOf(team2.getId())); + createTeam = + TEAM_TEST + .createRequest("rolesPoliciesTeam22") + .withParents(listOf(team2.getFullyQualifiedName())); Team team22 = TEAM_TEST.createEntity(createTeam, ADMIN_AUTH_HEADERS); // Create users - Team2 has default role DataSteward diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/RoleResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/RoleResourceTest.java index a367e397e6cc..37eeff1a5407 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/RoleResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/RoleResourceTest.java @@ -194,12 +194,12 @@ public Role validateGetWithDifferentFields(Role role, boolean byName) teamResourceTest.createEntity( teamResourceTest .createRequest("roleTeam1", "", "", null) - .withDefaultRoles(List.of(role.getId())), + .withDefaultRoles(List.of(role.getFullyQualifiedName())), ADMIN_AUTH_HEADERS); teamResourceTest.createEntity( teamResourceTest .createRequest("roleTeam2", "", "", null) - .withDefaultRoles(List.of(role.getId())), + .withDefaultRoles(List.of(role.getFullyQualifiedName())), ADMIN_AUTH_HEADERS); } diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java b/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java index e39f2d05a6e5..2892e10a2c40 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java @@ -529,6 +529,27 @@ public static void assertEntityReferenceIds(List expected, List expected, List actual) { + if (expected == null && actual == null) { + return; + } + expected = listOrEmpty(expected); + actual = listOrEmpty(actual); + if (expected.isEmpty()) { + return; + } + assertEquals(expected.size(), actual.size()); + for (String fqn : expected) { + assertNotNull( + actual.stream() + .filter(entity -> entity.getFullyQualifiedName().equals(fqn)) + .findAny() + .orElse(null)); + } + validateEntityReferences(actual); + } + public static void assertEntityReferences( List expected, List actual) { if (expected == actual) { // Take care of both being null From 221bca819fe718a9ac95b1f4464feb3104e9cfab Mon Sep 17 00:00:00 2001 From: mohitdeuex Date: Mon, 16 Dec 2024 14:41:39 +0530 Subject: [PATCH 3/9] Fix Tests --- .../resources/teams/TeamResourceTest.java | 53 +++++++++++-------- .../openmetadata/service/util/TestUtils.java | 3 +- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/TeamResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/TeamResourceTest.java index 5ce46845715f..22f0b5f30b87 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/TeamResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/TeamResourceTest.java @@ -131,18 +131,18 @@ public void setupTeams(TestInfo test) throws HttpResponseException { CreateTeam createTeam = createRequest(test, 1).withTeamType(DEPARTMENT); TEAM1 = createEntity(createTeam, ADMIN_AUTH_HEADERS); - createTeam = createRequest(test, 11).withParents(List.of(TEAM1.getId())); + createTeam = createRequest(test, 11).withParents(List.of(TEAM1.getFullyQualifiedName())); TEAM11 = createEntity(createTeam, ADMIN_AUTH_HEADERS); // TEAM2 has Team only policy - users from other teams can't access its assets createTeam = createRequest(test, 2) .withTeamType(DEPARTMENT) - .withPolicies(List.of(TEAM_ONLY_POLICY.getId())) - .withDefaultRoles(List.of(DATA_STEWARD_ROLE.getId())); + .withPolicies(List.of(TEAM_ONLY_POLICY.getFullyQualifiedName())) + .withDefaultRoles(List.of(DATA_STEWARD_ROLE.getFullyQualifiedName())); TEAM2 = createEntity(createTeam, ADMIN_AUTH_HEADERS); - createTeam = createRequest(test, 21).withParents(List.of(TEAM2.getId())); + createTeam = createRequest(test, 21).withParents(List.of(TEAM2.getFullyQualifiedName())); TEAM21 = createEntity(createTeam, ADMIN_AUTH_HEADERS); TEAM11_REF = TEAM11.getEntityReference(); @@ -203,14 +203,16 @@ void post_teamWithUsersAndDefaultRoles_200_OK(TestInfo test) throws IOException User user2 = userResourceTest.createEntity( userResourceTest.createRequest(test, 2), USER_WITH_CREATE_HEADERS); - List users = Arrays.asList(user1.getId(), user2.getId()); + List users = + Arrays.asList(user1.getFullyQualifiedName(), user2.getFullyQualifiedName()); RoleResourceTest roleResourceTest = new RoleResourceTest(); Role role1 = roleResourceTest.createEntity(roleResourceTest.createRequest(test, 1), ADMIN_AUTH_HEADERS); Role role2 = roleResourceTest.createEntity(roleResourceTest.createRequest(test, 2), ADMIN_AUTH_HEADERS); - List roles = Arrays.asList(role1.getId(), role2.getId()); + List roles = + Arrays.asList(role1.getFullyQualifiedName(), role2.getFullyQualifiedName()); CreateTeam create = createRequest(test) @@ -236,12 +238,12 @@ void delete_validTeam_200_OK(TestInfo test) throws IOException { UserResourceTest userResourceTest = new UserResourceTest(); User user1 = userResourceTest.createEntity(userResourceTest.createRequest(test, 1), ADMIN_AUTH_HEADERS); - List users = Collections.singletonList(user1.getId()); + List users = Collections.singletonList(user1.getFullyQualifiedName()); RoleResourceTest roleResourceTest = new RoleResourceTest(); Role role1 = roleResourceTest.createEntity(roleResourceTest.createRequest(test, 1), ADMIN_AUTH_HEADERS); - List roles = Collections.singletonList(role1.getId()); + List roles = Collections.singletonList(role1.getFullyQualifiedName()); CreateTeam create = createRequest(test).withUsers(users).withDefaultRoles(roles); Team team = createAndCheckEntity(create, ADMIN_AUTH_HEADERS); @@ -587,7 +589,9 @@ void put_patch_hierarchicalTeams() throws IOException { // Change bu2 parent from Organization to bu1 using PUT operation CreateTeam create = - createRequest("put2").withTeamType(BUSINESS_UNIT).withParents(List.of(bu1.getId())); + createRequest("put2") + .withTeamType(BUSINESS_UNIT) + .withParents(List.of(bu1.getFullyQualifiedName())); ChangeDescription change = getChangeDescription(bu2, MINOR_UPDATE); fieldDeleted(change, "parents", List.of(ORG_TEAM.getEntityReference())); fieldAdded(change, "parents", List.of(bu1.getEntityReference())); @@ -639,18 +643,19 @@ void patch_isJoinable_200(TestInfo test) throws IOException { void patch_deleteUserAndDefaultRolesFromTeam_200(TestInfo test) throws IOException { UserResourceTest userResourceTest = new UserResourceTest(); final int totalUsers = 20; - ArrayList users = new ArrayList<>(); + List users = new ArrayList<>(); for (int i = 0; i < totalUsers; i++) { User user = userResourceTest.createEntity( userResourceTest.createRequest(test, i), ADMIN_AUTH_HEADERS); - users.add(user.getId()); + users.add(user.getFullyQualifiedName()); } RoleResourceTest roleResourceTest = new RoleResourceTest(); roleResourceTest.createRoles(test, 5, 0); List roles = roleResourceTest.listEntities(Map.of(), ADMIN_AUTH_HEADERS).getData(); - List rolesIds = roles.stream().map(Role::getId).collect(Collectors.toList()); + List rolesIds = + roles.stream().map(Role::getFullyQualifiedName).collect(Collectors.toList()); CreateTeam create = createRequest(getEntityName(test), "description", "displayName", null) @@ -682,7 +687,9 @@ void patch_deleteUserAndDefaultRolesFromTeam_200(TestInfo test) throws IOExcepti @Test void post_teamWithPolicies(TestInfo test) throws IOException { CreateTeam create = - createRequest(getEntityName(test)).withPolicies(List.of(POLICY1.getId(), POLICY2.getId())); + createRequest(getEntityName(test)) + .withPolicies( + List.of(POLICY1.getFullyQualifiedName(), POLICY2.getFullyQualifiedName())); createAndCheckEntity(create, ADMIN_AUTH_HEADERS); } @@ -694,7 +701,7 @@ void put_teamWithPolicies(TestInfo test) throws IOException { // Add policies to the team create = createRequest(getEntityName(test)) - .withPolicies(List.of(POLICY1.getId(), POLICY2.getId())) + .withPolicies(List.of(POLICY1.getFullyQualifiedName(), POLICY2.getFullyQualifiedName())) .withName(team.getName()); ChangeDescription change = getChangeDescription(team, MINOR_UPDATE); fieldAdded( @@ -917,7 +924,7 @@ void test_inheritDomain(TestInfo test) throws IOException { Team team = createEntity(createTeam, ADMIN_AUTH_HEADERS); // Create a children team without domain and ensure it inherits domain from the parent - createTeam = createRequest("team1").withParents(listOf(team.getId())); + createTeam = createRequest("team1").withParents(listOf(team.getFullyQualifiedName())); assertDomainInheritance(createTeam, DOMAIN.getEntityReference()); } @@ -1086,15 +1093,15 @@ public void validateCreatedEntity( TestUtils.validateEntityReferences(team.getOwns()); List expectedUsers = new ArrayList<>(); - for (UUID userId : listOrEmpty(createRequest.getUsers())) { - expectedUsers.add(new EntityReference().withId(userId).withType(Entity.USER)); + for (String fqn : listOrEmpty(createRequest.getUsers())) { + expectedUsers.add(new EntityReference().withFullyQualifiedName(fqn).withType(Entity.USER)); } expectedUsers = expectedUsers.isEmpty() ? null : expectedUsers; TestUtils.assertEntityReferences(expectedUsers, team.getUsers()); - TestUtils.assertEntityReferenceIds(createRequest.getDefaultRoles(), team.getDefaultRoles()); - TestUtils.assertEntityReferenceIds(createRequest.getParents(), team.getParents()); - TestUtils.assertEntityReferenceIds(createRequest.getChildren(), team.getChildren()); - TestUtils.assertEntityReferenceIds(createRequest.getPolicies(), team.getPolicies()); + TestUtils.assertEntityReferenceFqn(createRequest.getDefaultRoles(), team.getDefaultRoles()); + TestUtils.assertEntityReferenceFqn(createRequest.getParents(), team.getParents()); + TestUtils.assertEntityReferenceFqn(createRequest.getChildren(), team.getChildren()); + TestUtils.assertEntityReferenceFqn(createRequest.getPolicies(), team.getPolicies()); } @Override @@ -1152,7 +1159,7 @@ private Team createWithParents( String teamName, TeamType teamType, Boolean isJoinable, EntityReference... parents) throws HttpResponseException { List parentList = List.of(parents); - List parentIds = EntityUtil.refToIds(parentList); + List parentIds = EntityUtil.refToFqns(parentList); Team team = createEntity( createRequest(teamName) @@ -1167,7 +1174,7 @@ private Team createWithParents( private Team createWithChildren(String teamName, TeamType teamType, EntityReference... children) throws HttpResponseException { List childrenList = List.of(children); - List childIds = EntityUtil.refToIds(childrenList); + List childIds = EntityUtil.refToFqns(childrenList); Team team = createEntity( createRequest(teamName).withChildren(childIds).withTeamType(teamType), diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java b/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java index 2892e10a2c40..4628ad8a290a 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java @@ -529,8 +529,7 @@ public static void assertEntityReferenceIds(List expected, List expected, List actual) { + public static void assertEntityReferenceFqn(List expected, List actual) { if (expected == null && actual == null) { return; } From 14a64f4d1dfb7bf6210d6fe04980997bd5648487 Mon Sep 17 00:00:00 2001 From: mohitdeuex Date: Mon, 16 Dec 2024 15:50:35 +0530 Subject: [PATCH 4/9] Fix Team Tests --- .../service/resources/teams/TeamResourceTest.java | 2 +- .../org/openmetadata/service/util/TestUtils.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/TeamResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/TeamResourceTest.java index 22f0b5f30b87..30e1e3964357 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/TeamResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/teams/TeamResourceTest.java @@ -1097,7 +1097,7 @@ public void validateCreatedEntity( expectedUsers.add(new EntityReference().withFullyQualifiedName(fqn).withType(Entity.USER)); } expectedUsers = expectedUsers.isEmpty() ? null : expectedUsers; - TestUtils.assertEntityReferences(expectedUsers, team.getUsers()); + TestUtils.assertEntityReferencesFqn(expectedUsers, team.getUsers()); TestUtils.assertEntityReferenceFqn(createRequest.getDefaultRoles(), team.getDefaultRoles()); TestUtils.assertEntityReferenceFqn(createRequest.getParents(), team.getParents()); TestUtils.assertEntityReferenceFqn(createRequest.getChildren(), team.getChildren()); diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java b/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java index 4628ad8a290a..dce6e380d7dc 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/util/TestUtils.java @@ -563,6 +563,20 @@ public static void assertEntityReferences( } } + public static void assertEntityReferencesFqn( + List expected, List actual) { + if (expected == actual) { // Take care of both being null + return; + } + if (expected != null) { + actual = listOrEmpty(actual); + assertEquals(expected.size(), actual.size()); + for (EntityReference e : expected) { + TestUtils.existsInEntityReferenceList(actual, e.getFullyQualifiedName(), true); + } + } + } + public static void assertEntityReferenceNames( List expected, List actual) { if (expected != null) { From 6362f3d2f90203c880ea92aa1e9ed9bce2ef59d1 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Mon, 16 Dec 2024 17:25:17 +0530 Subject: [PATCH 5/9] change the team create parent id to fqn and fix some minor bugs --- .../e2e/Features/ActivityFeed.spec.ts | 6 +++--- .../ui/playwright/e2e/Pages/Tag.spec.ts | 6 ++++-- .../ui/playwright/e2e/Pages/Teams.spec.ts | 12 +++++++---- .../ui/playwright/support/user/UserClass.ts | 6 +++--- .../Team/TeamDetails/TeamDetailsV1.tsx | 3 ++- .../TeamDetails/UserTab/UserTab.component.tsx | 14 ++++++------- .../UserSelectableList.component.tsx | 4 +++- .../UserSelectableList.test.tsx | 20 ++++++++++++++++++- .../ui/src/pages/TeamsPage/TeamsPage.tsx | 2 +- 9 files changed, 50 insertions(+), 23 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Features/ActivityFeed.spec.ts b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Features/ActivityFeed.spec.ts index 954bd2c3f272..2b27a0fbd2f6 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Features/ActivityFeed.spec.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Features/ActivityFeed.spec.ts @@ -949,9 +949,9 @@ base.describe('Activity feed with Data Consumer User', () => { displayName: `PW Team ${id}`, description: 'playwright team description', teamType: 'Group', - users: [viewAllUser.responseData.id], - defaultRoles: viewAllRoles.responseData.id - ? [viewAllRoles.responseData.id] + users: [viewAllUser.responseData.fullyQualifiedName], + defaultRoles: viewAllRoles.responseData.fullyQualifiedName + ? [viewAllRoles.responseData.fullyQualifiedName] : [], }); await viewAllTeam.create(apiContext); diff --git a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Tag.spec.ts b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Tag.spec.ts index 8ef44d871d39..8aca7ac685a6 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Tag.spec.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Tag.spec.ts @@ -329,8 +329,10 @@ test.describe('Tag Page with Limited EditTag Permission', () => { displayName: `PW Limited User Access Team ${id}`, description: 'playwright data steward team description', teamType: 'Group', - users: [limitedAccessUser.responseData.id], - defaultRoles: role.responseData.id ? [role.responseData.id] : [], + users: [limitedAccessUser.responseData.fullyQualifiedName], + defaultRoles: role.responseData.fullyQualifiedName + ? [role.responseData.fullyQualifiedName] + : [], }); await limitedAccessTeam.create(apiContext); diff --git a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Teams.spec.ts b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Teams.spec.ts index 0e8a26acec81..d6f000570593 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Teams.spec.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Teams.spec.ts @@ -684,8 +684,10 @@ test.describe('Teams Page with EditUser Permission', () => { displayName: `PW Edit User Team ${id}`, description: 'playwright edit user team description', teamType: 'Group', - users: [editOnlyUser.responseData.id], - defaultRoles: role.responseData.id ? [role.responseData.id] : [], + users: [editOnlyUser.responseData.fullyQualifiedName], + defaultRoles: role.responseData.fullyQualifiedName + ? [role.responseData.fullyQualifiedName] + : [], }); await team.create(apiContext); await team2.create(apiContext); @@ -758,8 +760,10 @@ test.describe('Teams Page with Data Consumer User', () => { displayName: `PW Data Consumer Team ${id}`, description: 'playwright data consumer team description', teamType: 'Group', - users: [user.responseData.id], - defaultRoles: role.responseData.id ? [role.responseData.id] : [], + users: [user.responseData.fullyQualifiedName], + defaultRoles: role.responseData.fullyQualifiedName + ? [role.responseData.fullyQualifiedName] + : [], }); await team.create(apiContext); await team2.create(apiContext); diff --git a/openmetadata-ui/src/main/resources/ui/playwright/support/user/UserClass.ts b/openmetadata-ui/src/main/resources/ui/playwright/support/user/UserClass.ts index 04ae6924ca57..982962d46751 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/support/user/UserClass.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/support/user/UserClass.ts @@ -119,9 +119,9 @@ export class UserClass { displayName: `PW Data Steward Team ${id}`, description: 'playwright data steward team description', teamType: 'Group', - users: [this.responseData.id], - defaultRoles: dataStewardRoles.responseData.id - ? [dataStewardRoles.responseData.id] + users: [this.responseData.fullyQualifiedName], + defaultRoles: dataStewardRoles.responseData.fullyQualifiedName + ? [dataStewardRoles.responseData.fullyQualifiedName] : [], }); await dataStewardTeam.create(apiContext); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Team/TeamDetails/TeamDetailsV1.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Team/TeamDetails/TeamDetailsV1.tsx index ba4dee350f5e..b0536d4f6862 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Team/TeamDetails/TeamDetailsV1.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Team/TeamDetails/TeamDetailsV1.tsx @@ -918,6 +918,7 @@ const TeamDetailsV1 = ({ !isOrganization && !isUndefined(currentUser) && isGroupType && + !isTeamDeleted && (isAlreadyJoinedTeam ? (