Skip to content

Commit

Permalink
Issue #17012: Multi User/Team Ownership - Fix Tests - Part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
harshach committed Jul 18, 2024
1 parent c57c615 commit 29aea65
Show file tree
Hide file tree
Showing 107 changed files with 330 additions and 266 deletions.
6 changes: 5 additions & 1 deletion openmetadata-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,11 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr353</artifactId>
</dependency>

<dependency>
<groupId>com.flipkart.zjsonpatch</groupId>
<artifactId>zjsonpatch</artifactId>
<version>0.4.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ResourceRegistry {
mapFieldOperation(MetadataOperation.EDIT_DESCRIPTION, Entity.FIELD_DESCRIPTION);
mapFieldOperation(MetadataOperation.EDIT_DISPLAY_NAME, Entity.FIELD_DISPLAY_NAME);
mapFieldOperation(MetadataOperation.EDIT_TAGS, Entity.FIELD_TAGS);
mapFieldOperation(MetadataOperation.EDIT_OWNER, Entity.FIELD_OWNERS);
mapFieldOperation(MetadataOperation.EDIT_OWNERS, Entity.FIELD_OWNERS);
mapFieldOperation(MetadataOperation.EDIT_CUSTOM_FIELDS, "extension");
mapFieldOperation(MetadataOperation.EDIT_USERS, "users");
mapFieldOperation(MetadataOperation.EDIT_ROLE, "defaultRoles");
Expand Down Expand Up @@ -84,7 +84,7 @@ private static List<MetadataOperation> getOperations(
operations.add(MetadataOperation.EDIT_TAGS);
}
if (entityFields.contains(Entity.FIELD_OWNERS)) {
operations.add(MetadataOperation.EDIT_OWNER);
operations.add(MetadataOperation.EDIT_OWNERS);
}
if (entityFields.contains(Entity.FIELD_EXTENSION)) {
operations.add(MetadataOperation.EDIT_CUSTOM_FIELDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void prepare(Container container, boolean update) {
container.setServiceType(storageService.getServiceType());

if (container.getParent() != null) {
Container parent = Entity.getEntity(container.getParent(), "owner", ALL);
Container parent = Entity.getEntity(container.getParent(), "owners", ALL);
container.withParent(parent.getEntityReference());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void storeEntity(DashboardDataModel dashboardDataModel, boolean update) {
// Relationships and fields such as href are derived and not stored as part of json
EntityReference service = dashboardDataModel.getService();

// Don't store owner, database, href and tags as JSON. Build it on the fly based on
// Don't store owners, database, href and tags as JSON. Build it on the fly based on
// relationships
dashboardDataModel.withService(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DataInsightChartRepository extends EntityRepository<DataInsightChar
public static final String DATA_VIEWS = "data.views";
public static final String ENTITY_FQN = "entityFqn";
public static final String DATA_ENTITY_FQN = "data.entityFqn";
public static final String OWNER = "owner";
public static final String OWNER = "owners";
public static final String DATA_OWNER = "data.owner";
public static final String USER_NAME = "userName";
public static final String TEAM = "team";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public String exportToCsv(String name, String user) throws IOException {
(DatabaseSchemaRepository) Entity.getEntityRepository(DATABASE_SCHEMA);
ListFilter filter = new ListFilter(Include.NON_DELETED).addQueryParam("database", name);
List<DatabaseSchema> schemas =
repository.listAll(repository.getFields("owner,tags,domain"), filter);
repository.listAll(repository.getFields("owners,tags,domain"), filter);
schemas.sort(Comparator.comparing(EntityInterface::getFullyQualifiedName));
return new DatabaseCsv(database, user).exportCsv(schemas);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void setDefaultFields(DatabaseSchema schema) {
@Override
public void setInheritedFields(DatabaseSchema schema, Fields fields) {
Database database =
Entity.getEntity(Entity.DATABASE, schema.getDatabase().getId(), "owner,domain", ALL);
Entity.getEntity(Entity.DATABASE, schema.getDatabase().getId(), "owners,domain", ALL);
inheritOwners(schema, fields, database);
inheritDomain(schema, fields, database);
schema.withRetentionPeriod(
Expand Down Expand Up @@ -185,7 +185,7 @@ public String exportToCsv(String name, String user) throws IOException {
DatabaseSchema schema = getByName(null, name, Fields.EMPTY_FIELDS); // Validate database schema
TableRepository repository = (TableRepository) Entity.getEntityRepository(TABLE);
ListFilter filter = new ListFilter(Include.NON_DELETED).addQueryParam("databaseSchema", name);
List<Table> tables = repository.listAll(repository.getFields("owner,tags,domain"), filter);
List<Table> tables = repository.listAll(repository.getFields("owners,tags,domain"), filter);
tables.sort(Comparator.comparing(EntityInterface::getFullyQualifiedName));
return new DatabaseSchemaCsv(schema, user).exportCsv(tables);
}
Expand Down Expand Up @@ -280,7 +280,8 @@ protected void createEntity(CSVPrinter printer, List<CSVRecord> csvRecords) thro
.withDatabaseSchema(schema.getEntityReference());
}

// Headers: name, displayName, description, owner, tags, glossaryTerms, tiers retentionPeriod,
// Headers: name, displayName, description, owners, tags, glossaryTerms, tiers
// retentionPeriod,
// sourceUrl, domain
// Field 1,2,3,6,7 - database schema name, displayName, description
List<TagLabel> tagLabels =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public String exportToCsv(String name, String user) throws IOException {
DatabaseRepository repository = (DatabaseRepository) Entity.getEntityRepository(DATABASE);
ListFilter filter = new ListFilter(Include.NON_DELETED).addQueryParam("service", name);
List<Database> databases =
repository.listAll(repository.getFields("owner,tags,domain"), filter);
repository.listAll(repository.getFields("owners,tags,domain"), filter);
databases.sort(Comparator.comparing(EntityInterface::getFullyQualifiedName));
return new DatabaseServiceCsv(databaseService, user).exportCsv(databases);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ protected void createEntity(CSVPrinter printer, List<CSVRecord> csvRecords) thro
database = new Database().withService(service.getEntityReference());
}

// Headers: name, displayName, description, owner, tags, glossaryTerms, tiers, domain
// Headers: name, displayName, description, owners, tags, glossaryTerms, tiers, domain
// Field 1,2,3,6,7 - database service name, displayName, description
List<TagLabel> tagLabels =
getTagLabels(
Expand All @@ -131,7 +131,7 @@ protected void createEntity(CSVPrinter printer, List<CSVRecord> csvRecords) thro

@Override
protected void addRecord(CsvFile csvFile, Database entity) {
// Headers: name, displayName, description, owner, tags, glossaryTerms, tiers, domain
// Headers: name, displayName, description, owners, tags, glossaryTerms, tiers, domain
List<String> recordList = new ArrayList<>();
addField(recordList, entity.getName());
addField(recordList, entity.getDisplayName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public void storeRelationships(Domain entity) {

@Override
public void setInheritedFields(Domain domain, Fields fields) {
// If subdomain does not have owner and experts, then inherit it from parent domain
// If subdomain does not have owners and experts, then inherit it from parent domain
EntityReference parentRef = domain.getParent() != null ? domain.getParent() : getParent(domain);
if (parentRef != null) {
Domain parent = Entity.getEntity(DOMAIN, parentRef.getId(), "owner,experts", ALL);
Domain parent = Entity.getEntity(DOMAIN, parentRef.getId(), "owners,experts", ALL);
inheritOwners(domain, fields, parent);
inheritExperts(domain, fields, parent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ protected EntityRepository(
* document. It is always reconstructed based on relationship edges from the backend database. <br>
* <br>
* As an example, when <i>table</i> entity is stored, the attributes such as <i>href</i> and the relationships such as
* <i>owner</i>, <i>database</i>, and <i>tags</i> are set to null. These attributes are restored back after the JSON
* <i>owners</i>, <i>database</i>, and <i>tags</i> are set to null. These attributes are restored back after the JSON
* document is stored to be sent as response.
*
* @see TableRepository#storeEntity(Table, boolean) for an example implementation
Expand Down Expand Up @@ -1843,7 +1843,9 @@ final void validatePolicies(List<EntityReference> policies) {
}

public final List<EntityReference> getOwners(T entity) {
return supportsOwners ? findFrom(entity.getId(), entityType, Relationship.OWNS, null) : null;
return supportsOwners
? findFrom(entity.getId(), entityType, Relationship.OWNS, null)
: Collections.emptyList();
}

public final List<EntityReference> getOwners(EntityReference ref) {
Expand Down Expand Up @@ -1886,10 +1888,6 @@ protected List<EntityReference> getExperts(T entity) {
: null;
}

public final EntityReference getOwner(EntityReference ref) {
return !supportsOwners ? null : getFromEntityRef(ref.getId(), Relationship.OWNS, null, false);
}

public final void inheritDomain(T entity, Fields fields, EntityInterface parent) {
if (fields.contains(FIELD_DOMAIN) && entity.getDomain() == null && parent != null) {
entity.setDomain(parent.getDomain() != null ? parent.getDomain().withInherited(true) : null);
Expand All @@ -1898,7 +1896,8 @@ public final void inheritDomain(T entity, Fields fields, EntityInterface parent)

public final void inheritOwners(T entity, Fields fields, EntityInterface parent) {
if (fields.contains(FIELD_OWNERS) && nullOrEmpty(entity.getOwners()) && parent != null) {
entity.setOwners(!nullOrEmpty(parent.getOwners()) ? parent.getOwners() : null);
entity.setOwners(
!nullOrEmpty(parent.getOwners()) ? parent.getOwners() : Collections.emptyList());
listOrEmpty(entity.getOwners()).forEach(owner -> owner.setInherited(true));
}
}
Expand Down Expand Up @@ -2094,15 +2093,15 @@ public final void updateOwners(
diffLists(
newOwners,
originalOwners,
EntityReference::getFullyQualifiedName,
EntityReference::getFullyQualifiedName,
EntityReference::getId,
EntityReference::getId,
Function.identity());
List<EntityReference> removedOwners =
diffLists(
originalOwners,
newOwners,
EntityReference::getFullyQualifiedName,
EntityReference::getFullyQualifiedName,
EntityReference::getId,
EntityReference::getId,
Function.identity());
if (nullOrEmpty(addedOwners) && nullOrEmpty(removedOwners)) {
return;
Expand Down Expand Up @@ -2476,20 +2475,8 @@ private void updateDisplayName() {
private void updateOwners() {
List<EntityReference> origOwners = getEntityReferences(original.getOwners());
List<EntityReference> updatedOwners = getEntityReferences(updated.getOwners());
List<EntityReference> addedOwners =
diffLists(
updatedOwners,
origOwners,
EntityReference::getFullyQualifiedName,
EntityReference::getFullyQualifiedName,
Function.identity());
List<EntityReference> removedOwners =
diffLists(
origOwners,
updatedOwners,
EntityReference::getFullyQualifiedName,
EntityReference::getFullyQualifiedName,
Function.identity());
List<EntityReference> addedOwners = new ArrayList<>();
List<EntityReference> removedOwners = new ArrayList<>();
if ((operation.isPatch() || !nullOrEmpty(updatedOwners))
&& recordListChange(
FIELD_OWNERS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public String exportToCsv(String name, String user) throws IOException {
(GlossaryTermRepository) Entity.getEntityRepository(GLOSSARY_TERM);
ListFilter filter = new ListFilter(Include.NON_DELETED).addQueryParam("parent", name);
List<GlossaryTerm> terms =
repository.listAll(repository.getFields("owner,reviewers,tags,relatedTerms"), filter);
repository.listAll(repository.getFields("owners,reviewers,tags,relatedTerms"), filter);
terms.sort(Comparator.comparing(EntityInterface::getFullyQualifiedName));
return new GlossaryCsv(glossary, user).exportCsv(terms);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void clearFields(GlossaryTerm entity, Fields fields) {

@Override
public void setInheritedFields(GlossaryTerm glossaryTerm, Fields fields) {
EntityInterface parent = getParentEntity(glossaryTerm, "owner,domain,reviewers");
EntityInterface parent = getParentEntity(glossaryTerm, "owners,domain,reviewers");
inheritOwners(glossaryTerm, fields, parent);
inheritDomain(glossaryTerm, fields, parent);
inheritReviewers(glossaryTerm, fields, parent);
Expand Down Expand Up @@ -171,7 +171,7 @@ public void prepare(GlossaryTerm entity, boolean update) {
GlossaryTerm parentTerm =
entity.getParent() != null
? Entity.getEntity(
entity.getParent().withType(GLOSSARY_TERM), "owner,reviewers", Include.NON_DELETED)
entity.getParent().withType(GLOSSARY_TERM), "owners,reviewers", Include.NON_DELETED)
: null;
if (parentTerm != null) {
parentReviewers = parentTerm.getReviewers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ public static void addPipelineDetails(
if (pipelineRef.getType().equals(PIPELINE)) {
pipelineMap =
JsonUtils.getMap(
Entity.getEntity(pipelineRef, "pipelineStatus,tags,owner", Include.ALL));
Entity.getEntity(pipelineRef, "pipelineStatus,tags,owners", Include.ALL));
} else {
pipelineMap = JsonUtils.getMap(Entity.getEntity(pipelineRef, "tags,owner", Include.ALL));
pipelineMap = JsonUtils.getMap(Entity.getEntity(pipelineRef, "tags,owners", Include.ALL));
}
relationshipDetails.put("pipelineEntityType", pipelineRef.getType());
relationshipDetails.put(PIPELINE, pipelineMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void storeRelationships(StoredProcedure storedProcedure) {
public void setInheritedFields(StoredProcedure storedProcedure, EntityUtil.Fields fields) {
DatabaseSchema schema =
Entity.getEntity(
DATABASE_SCHEMA, storedProcedure.getDatabaseSchema().getId(), "owner,domain", ALL);
DATABASE_SCHEMA, storedProcedure.getDatabaseSchema().getId(), "owners,domain", ALL);
inheritOwners(storedProcedure, fields, schema);
inheritDomain(storedProcedure, fields, schema);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void clearFields(Table table, Fields fields) {
@Override
public void setInheritedFields(Table table, Fields fields) {
DatabaseSchema schema =
Entity.getEntity(DATABASE_SCHEMA, table.getDatabaseSchema().getId(), "owner,domain", ALL);
Entity.getEntity(DATABASE_SCHEMA, table.getDatabaseSchema().getId(), "owners,domain", ALL);
inheritOwners(table, fields, schema);
inheritDomain(table, fields, schema);
// If table does not have retention period, then inherit it from parent databaseSchema
Expand Down Expand Up @@ -618,7 +618,7 @@ public Table addDataModel(UUID tableId, DataModel dataModel) {
}
table.withDataModel(dataModel);

// Carry forward the table owner from the model to table entity, if empty
// Carry forward the table owners from the model to table entity, if empty
if (table.getOwners() == null) {
storeOwners(table, dataModel.getOwners());
}
Expand Down Expand Up @@ -765,7 +765,7 @@ public Table applySuggestion(EntityInterface entity, String columnFQN, Suggestio
@Override
public String exportToCsv(String name, String user) throws IOException {
// Validate table
Table table = getByName(null, name, new Fields(allowedFields, "owner,domain,tags,columns"));
Table table = getByName(null, name, new Fields(allowedFields, "owners,domain,tags,columns"));
return new TableCsv(table, user).exportCsv(listOf(table));
}

Expand All @@ -777,7 +777,8 @@ public CsvImportResult importFromCsv(String name, String csv, boolean dryRun, St
getByName(
null,
name,
new Fields(allowedFields, "owner,domain,tags,columns,database,service,databaseSchema"));
new Fields(
allowedFields, "owners,domain,tags,columns,database,service,databaseSchema"));
return new TableCsv(table, user).importCsv(csv, dryRun);
}

Expand Down Expand Up @@ -1151,7 +1152,8 @@ public static class TableCsv extends EntityCsv<Table> {
@Override
protected void createEntity(CSVPrinter printer, List<CSVRecord> csvRecords) throws IOException {
CSVRecord csvRecord = getNextRecord(printer, csvRecords);
// Headers: name, displayName, description, owner, tags, glossaryTerms, tiers retentionPeriod,
// Headers: name, displayName, description, owners, tags, glossaryTerms, tiers
// retentionPeriod,
// sourceUrl, domain, column.fullyQualifiedName, column.displayName, column.description,
// column.dataTypeDisplay,
// column.tags, column.glossaryTerms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ private List<Team> listTeams(

public String exportCsv() throws IOException {
TeamRepository repository = (TeamRepository) Entity.getEntityRepository(TEAM);
final Fields fields = repository.getFields("owner,defaultRoles,parents,policies");
final Fields fields = repository.getFields("owners,defaultRoles,parents,policies");
return exportCsv(listTeams(repository, team.getName(), new ArrayList<>(), fields));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
private static final String INCIDENTS_FIELD = "incidentId";
public static final String COLLECTION_PATH = "/v1/dataQuality/testCases";
private static final String UPDATE_FIELDS =
"owner,entityLink,testSuite,testSuites,testDefinition";
"owners,entityLink,testSuite,testSuites,testDefinition";
private static final String PATCH_FIELDS =
"owner,entityLink,testSuite,testDefinition,computePassedFailedRowCount,useDynamicAssertion";
"owners,entityLink,testSuite,testDefinition,computePassedFailedRowCount,useDynamicAssertion";
public static final String TESTCASE_RESULT_EXTENSION = "testCase.testCaseResult";
public static final String FAILED_ROWS_SAMPLE_EXTENSION = "testCase.failedRowsSample";

Expand Down Expand Up @@ -112,7 +112,7 @@ public void setFields(TestCase test, Fields fields) {
@Override
public void setInheritedFields(TestCase testCase, Fields fields) {
EntityLink entityLink = EntityLink.parse(testCase.getEntityLink());
Table table = Entity.getEntity(entityLink, "owner,domain,tags,columns", ALL);
Table table = Entity.getEntity(entityLink, "owners,domain,tags,columns", ALL);
inheritOwners(testCase, fields, table);
inheritDomain(testCase, fields, table);
inheritTags(testCase, fields, table);
Expand Down Expand Up @@ -767,7 +767,7 @@ public FeedRepository.TaskWorkflow getTaskWorkflow(FeedRepository.ThreadContext
public TestCase addFailedRowsSample(
TestCase testCase, TableData tableData, boolean validateColumns) {
EntityLink entityLink = EntityLink.parse(testCase.getEntityLink());
Table table = Entity.getEntity(entityLink, "owner", ALL);
Table table = Entity.getEntity(entityLink, FIELD_OWNERS, ALL);
// Validate all the columns
if (validateColumns) {
for (String columnName : tableData.getColumns()) {
Expand Down Expand Up @@ -984,7 +984,7 @@ public void entitySpecificUpdate() {
}

public TableData getSampleData(TestCase testCase, boolean authorizePII) {
Table table = Entity.getEntity(EntityLink.parse(testCase.getEntityLink()), "owner", ALL);
Table table = Entity.getEntity(EntityLink.parse(testCase.getEntityLink()), FIELD_OWNERS, ALL);
// Validate the request content
TableData sampleData =
JsonUtils.readValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public void inferIncidentSeverity(TestCaseResolutionStatus incident) {
Entity.getEntityByName(
entityLink.getEntityType(),
entityLink.getEntityFQN(),
"followers,owner,tags,votes",
"followers,owners,tags,votes",
Include.ALL);
Severity severity = incidentSeverityClassifier.classifyIncidentSeverity(entity);
incident.setSeverity(severity);
Expand Down
Loading

0 comments on commit 29aea65

Please sign in to comment.