mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-08 15:04:29 +00:00
This commit is contained in:
parent
3d70d55926
commit
d45498e603
@ -782,20 +782,31 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
Table table = (Table) entity;
|
||||
for (Column col : table.getColumns()) {
|
||||
if (col.getFullyQualifiedName().equals(columnFQN)) {
|
||||
if (suggestion.getType().equals(SuggestionType.SuggestTagLabel)) {
|
||||
List<TagLabel> tags = new ArrayList<>(col.getTags());
|
||||
tags.addAll(suggestion.getTagLabels());
|
||||
col.setTags(tags);
|
||||
} else if (suggestion.getType().equals(SuggestionType.SuggestDescription)) {
|
||||
col.setDescription(suggestion.getDescription());
|
||||
} else {
|
||||
throw new SuggestionException("Invalid suggestion Type");
|
||||
applySuggestionToColumn(col, suggestion);
|
||||
}
|
||||
if (col.getChildren() != null && !col.getChildren().isEmpty()) {
|
||||
for (Column child : col.getChildren()) {
|
||||
if (child.getFullyQualifiedName().equals(columnFQN)) {
|
||||
applySuggestionToColumn(child, suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
public void applySuggestionToColumn(Column column, Suggestion suggestion) {
|
||||
if (suggestion.getType().equals(SuggestionType.SuggestTagLabel)) {
|
||||
List<TagLabel> tags = new ArrayList<>(column.getTags());
|
||||
tags.addAll(suggestion.getTagLabels());
|
||||
column.setTags(tags);
|
||||
} else if (suggestion.getType().equals(SuggestionType.SuggestDescription)) {
|
||||
column.setDescription(suggestion.getDescription());
|
||||
} else {
|
||||
throw new SuggestionException("Invalid suggestion Type");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String exportToCsv(String name, String user, boolean recursive) throws IOException {
|
||||
// Validate table
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package org.openmetadata.service.resources.feeds;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||
import static javax.ws.rs.core.Response.Status.CREATED;
|
||||
import static javax.ws.rs.core.Response.Status.FORBIDDEN;
|
||||
@ -7,6 +8,8 @@ import static javax.ws.rs.core.Response.Status.NOT_FOUND;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.openmetadata.schema.type.ColumnDataType.INT;
|
||||
import static org.openmetadata.schema.type.ColumnDataType.STRUCT;
|
||||
import static org.openmetadata.service.exception.CatalogExceptionMessage.entityNotFound;
|
||||
import static org.openmetadata.service.resources.EntityResourceTest.C1;
|
||||
import static org.openmetadata.service.resources.EntityResourceTest.C2;
|
||||
@ -14,6 +17,8 @@ import static org.openmetadata.service.resources.EntityResourceTest.PERSONAL_DAT
|
||||
import static org.openmetadata.service.resources.EntityResourceTest.PII_SENSITIVE_TAG_LABEL;
|
||||
import static org.openmetadata.service.resources.EntityResourceTest.TIER1_TAG_LABEL;
|
||||
import static org.openmetadata.service.resources.EntityResourceTest.TIER2_TAG_LABEL;
|
||||
import static org.openmetadata.service.resources.EntityResourceTest.USER_ADDRESS_TAG_LABEL;
|
||||
import static org.openmetadata.service.resources.databases.TableResourceTest.getColumn;
|
||||
import static org.openmetadata.service.security.SecurityUtil.authHeaders;
|
||||
import static org.openmetadata.service.util.TestUtils.ADMIN_AUTH_HEADERS;
|
||||
import static org.openmetadata.service.util.TestUtils.assertResponse;
|
||||
@ -67,6 +72,7 @@ import org.openmetadata.service.util.TestUtils;
|
||||
public class SuggestionsResourceTest extends OpenMetadataApplicationTest {
|
||||
public static Table TABLE;
|
||||
public static Table TABLE2;
|
||||
public static Table TABLE_NESTED;
|
||||
|
||||
public static Table TABLE_WITHOUT_OWNER;
|
||||
public static String TABLE_LINK;
|
||||
@ -74,6 +80,7 @@ public class SuggestionsResourceTest extends OpenMetadataApplicationTest {
|
||||
public static String TABLE_WITHOUT_OWNER_LINK;
|
||||
public static String TABLE_COLUMN1_LINK;
|
||||
public static String TABLE_COLUMN2_LINK;
|
||||
public static String TABLE_NESTED_LINK;
|
||||
public static List<Column> COLUMNS;
|
||||
public static User USER;
|
||||
public static String USER_LINK;
|
||||
@ -119,6 +126,22 @@ public class SuggestionsResourceTest extends OpenMetadataApplicationTest {
|
||||
TABLE_WITHOUT_OWNER =
|
||||
TABLE_RESOURCE_TEST.createAndCheckEntity(createTable3, ADMIN_AUTH_HEADERS);
|
||||
|
||||
Column c2_c_d = getColumn("d", INT, USER_ADDRESS_TAG_LABEL);
|
||||
Column c2_c =
|
||||
getColumn("c", STRUCT, USER_ADDRESS_TAG_LABEL)
|
||||
.withChildren(new ArrayList<>(singletonList(c2_c_d)));
|
||||
|
||||
CreateTable createTableNested =
|
||||
TABLE_RESOURCE_TEST
|
||||
.createRequest(test)
|
||||
.withColumns(new ArrayList<>(singletonList(c2_c)))
|
||||
.withName("table_with_nested_suggestion")
|
||||
.withTableConstraints(null);
|
||||
|
||||
TABLE_NESTED = TABLE_RESOURCE_TEST.createAndCheckEntity(createTableNested, ADMIN_AUTH_HEADERS);
|
||||
TABLE_NESTED_LINK =
|
||||
String.format("<#E::table::%s::columns::c.d>", TABLE_NESTED.getFullyQualifiedName());
|
||||
|
||||
COLUMNS =
|
||||
Collections.singletonList(
|
||||
new Column().withName("column1").withDataType(ColumnDataType.BIGINT));
|
||||
@ -561,6 +584,22 @@ public class SuggestionsResourceTest extends OpenMetadataApplicationTest {
|
||||
validateAppliedTags(expectedTags, table.getTags());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void put_acceptSuggestionNested_200(TestInfo test) throws IOException {
|
||||
CreateSuggestion create = create().withEntityLink(TABLE_NESTED_LINK);
|
||||
Suggestion suggestion = createSuggestion(create, USER_AUTH_HEADERS);
|
||||
Assertions.assertEquals(create.getEntityLink(), suggestion.getEntityLink());
|
||||
|
||||
// When accepting the suggestion, the nested column column1.column2 should have the Updated
|
||||
// Description
|
||||
acceptSuggestion(suggestion.getId(), USER_AUTH_HEADERS);
|
||||
TableResourceTest tableResourceTest = new TableResourceTest();
|
||||
Table table = tableResourceTest.getEntity(TABLE_NESTED.getId(), "columns", USER_AUTH_HEADERS);
|
||||
Column nestedColumn = table.getColumns().get(0).getChildren().get(0);
|
||||
assertEquals("Update description", nestedColumn.getDescription());
|
||||
}
|
||||
|
||||
public Suggestion createSuggestion(CreateSuggestion create, Map<String, String> authHeaders)
|
||||
throws HttpResponseException {
|
||||
return TestUtils.post(getResource("suggestions"), create, Suggestion.class, authHeaders);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user