Skip to content

Commit 5c7b81c

Browse files
sonika-shahSiddhantsiddhant1
authored
fix Disabled Default Certifications Still Visible on Assets (#24826)
* fix Disabled Default Certifications Still Visible on Assets * make disabled query param field optional as tag can be disabled at individual level * added backend test * fix disabled certifications * added backend test for disabled Certification/tags Not Visible On Assets * add certification disable dropdown spec * write specs for Certifications * fix language translations * fix issues * specs for ClassificationDetails Page * add s[ecs for tags enable/disable * retrigger * run tests in isloation * fix the query param * fix flakey spec * refactor * add disabled test * add enabled header --------- Co-authored-by: Siddhant <siddhant@Siddhants-MacBook-Pro.local> Co-authored-by: Sid <30566406+siddhant1@users.noreply.github.com>
1 parent 6f7c21c commit 5c7b81c

37 files changed

Lines changed: 1964 additions & 260 deletions

File tree

openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java

Lines changed: 42 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -4466,195 +4466,80 @@ default String getNameHashColumn() {
44664466
return "fqnHash";
44674467
}
44684468

4469-
@Override
4470-
default int listCount(ListFilter filter) {
4469+
private Pair<String, String> buildTagQueryConditions(ListFilter filter) {
44714470
String parent = filter.getQueryParam("parent");
4471+
boolean disabled = Boolean.parseBoolean(filter.getQueryParam("classification.disabled"));
4472+
4473+
String baseJoin =
4474+
String.format(
4475+
"INNER JOIN entity_relationship er ON tag.id=er.toId AND er.relation=%s AND er.fromEntity='%s' "
4476+
+ "INNER JOIN classification c ON er.fromId=c.id",
4477+
CONTAINS.ordinal(), Entity.CLASSIFICATION);
4478+
4479+
StringBuilder mySqlCondition = new StringBuilder(baseJoin);
4480+
StringBuilder postgresCondition = new StringBuilder(baseJoin);
44724481

4473-
// If parent parameter is provided, filter tags by parent classification FQN
44744482
if (parent != null) {
44754483
String parentFqnHash = FullyQualifiedName.buildHash(parent);
44764484
filter.queryParams.put("parentFqnPrefix", parentFqnHash + ".%");
4477-
String condition = filter.getCondition("tag");
4478-
if (!condition.isEmpty()) {
4479-
condition = String.format("%s AND fqnHash LIKE :parentFqnPrefix", condition);
4480-
} else {
4481-
condition = "WHERE fqnHash LIKE :parentFqnPrefix";
4482-
}
4483-
return listCount(
4484-
getTableName(), getNameHashColumn(), filter.getQueryParams(), condition, condition);
4485+
mySqlCondition.append(" AND tag.fqnHash LIKE :parentFqnPrefix");
4486+
postgresCondition.append(" AND tag.fqnHash LIKE :parentFqnPrefix");
44854487
}
44864488

4487-
// Original behavior for classification.disabled parameter
4488-
boolean disabled = Boolean.parseBoolean(filter.getQueryParam("classification.disabled"));
4489-
String condition =
4490-
String.format(
4491-
"INNER JOIN entity_relationship er ON tag.id=er.toId AND er.relation=%s AND er.fromEntity='%s' "
4492-
+ "INNER JOIN classification c on er.fromId=c.id",
4493-
CONTAINS.ordinal(), Entity.CLASSIFICATION);
4494-
String mySqlCondition = condition;
4495-
String postgresCondition = condition;
4496-
44974489
if (disabled) {
4498-
mySqlCondition =
4499-
String.format(
4500-
"%s AND (JSON_EXTRACT(c.json, '$.disabled') IS NULL OR JSON_EXTRACT(c.json, '$.disabled') = TRUE)",
4501-
mySqlCondition);
4502-
postgresCondition =
4503-
String.format(
4504-
"%s AND ((c.json#>'{disabled}') IS NULL OR ((c.json#>'{disabled}')::boolean) = TRUE)",
4505-
postgresCondition);
4506-
} else {
4507-
mySqlCondition =
4508-
String.format(
4509-
"%s AND (JSON_EXTRACT(c.json, '$.disabled') IS NULL OR JSON_EXTRACT(c.json, '$.disabled') = FALSE)",
4510-
mySqlCondition);
4511-
postgresCondition =
4512-
String.format(
4513-
"%s AND ((c.json#>'{disabled}') IS NULL OR ((c.json#>'{disabled}')::boolean) = FALSE)",
4514-
postgresCondition);
4490+
mySqlCondition.append(
4491+
" AND (JSON_EXTRACT(c.json, '$.disabled') = TRUE OR JSON_EXTRACT(tag.json, '$.disabled') = TRUE)");
4492+
postgresCondition.append(
4493+
" AND (COALESCE((c.json#>'{disabled}')::boolean, FALSE) = TRUE OR COALESCE((tag.json#>'{disabled}')::boolean, FALSE) = TRUE)");
4494+
} else if (filter.getQueryParam("classification.disabled") != null) {
4495+
mySqlCondition.append(
4496+
" AND (JSON_EXTRACT(c.json, '$.disabled') = FALSE AND JSON_EXTRACT(tag.json, '$.disabled') = FALSE)");
4497+
postgresCondition.append(
4498+
" AND (COALESCE((c.json#>'{disabled}')::boolean, FALSE) = FALSE AND COALESCE((tag.json#>'{disabled}')::boolean, FALSE) = FALSE)");
45154499
}
45164500

4517-
mySqlCondition = String.format("%s %s", mySqlCondition, filter.getCondition("tag"));
4518-
postgresCondition = String.format("%s %s", postgresCondition, filter.getCondition("tag"));
4501+
String tagCondition = filter.getCondition("tag");
4502+
if (!tagCondition.isEmpty()) {
4503+
mySqlCondition.append(" ").append(tagCondition);
4504+
postgresCondition.append(" ").append(tagCondition);
4505+
}
4506+
4507+
return Pair.of(mySqlCondition.toString(), postgresCondition.toString());
4508+
}
4509+
4510+
@Override
4511+
default int listCount(ListFilter filter) {
4512+
Pair<String, String> conditions = buildTagQueryConditions(filter);
45194513
return listCount(
45204514
getTableName(),
45214515
getNameHashColumn(),
45224516
filter.getQueryParams(),
4523-
mySqlCondition,
4524-
postgresCondition);
4517+
conditions.getLeft(),
4518+
conditions.getRight());
45254519
}
45264520

45274521
@Override
45284522
default List<String> listBefore(
45294523
ListFilter filter, int limit, String beforeName, String beforeId) {
4530-
String parent = filter.getQueryParam("parent");
4531-
4532-
// If parent parameter is provided, filter tags by parent classification FQN
4533-
if (parent != null) {
4534-
String parentFqnHash = FullyQualifiedName.buildHash(parent);
4535-
filter.queryParams.put("parentFqnPrefix", parentFqnHash + ".%");
4536-
String condition = filter.getCondition("tag");
4537-
if (!condition.isEmpty()) {
4538-
condition = String.format("%s AND fqnHash LIKE :parentFqnPrefix", condition);
4539-
} else {
4540-
condition = "WHERE fqnHash LIKE :parentFqnPrefix";
4541-
}
4542-
return listBefore(
4543-
getTableName(),
4544-
filter.getQueryParams(),
4545-
condition,
4546-
condition,
4547-
limit,
4548-
beforeName,
4549-
beforeId);
4550-
}
4551-
4552-
// Original behavior for classification.disabled parameter
4553-
boolean disabled = Boolean.parseBoolean(filter.getQueryParam("classification.disabled"));
4554-
String condition =
4555-
String.format(
4556-
"INNER JOIN entity_relationship er ON tag.id=er.toId AND er.relation=%s AND er.fromEntity='%s' "
4557-
+ "INNER JOIN classification c on er.fromId=c.id",
4558-
CONTAINS.ordinal(), Entity.CLASSIFICATION);
4559-
4560-
String mySqlCondition = condition;
4561-
String postgresCondition = condition;
4562-
4563-
if (disabled) {
4564-
mySqlCondition =
4565-
String.format(
4566-
"%s AND (JSON_EXTRACT(c.json, '$.disabled') IS NULL OR JSON_EXTRACT(c.json, '$.disabled') = TRUE)",
4567-
mySqlCondition);
4568-
postgresCondition =
4569-
String.format(
4570-
"%s AND ((c.json#>'{disabled}') IS NULL OR ((c.json#>'{disabled}')::boolean) = TRUE)",
4571-
postgresCondition);
4572-
} else {
4573-
mySqlCondition =
4574-
String.format(
4575-
"%s AND (JSON_EXTRACT(c.json, '$.disabled') IS NULL OR JSON_EXTRACT(c.json, '$.disabled') = FALSE)",
4576-
mySqlCondition);
4577-
postgresCondition =
4578-
String.format(
4579-
"%s AND ((c.json#>'{disabled}') IS NULL OR ((c.json#>'{disabled}')::boolean) = FALSE)",
4580-
postgresCondition);
4581-
}
4582-
4583-
mySqlCondition = String.format("%s %s", mySqlCondition, filter.getCondition("tag"));
4584-
postgresCondition = String.format("%s %s", postgresCondition, filter.getCondition("tag"));
4585-
4524+
Pair<String, String> conditions = buildTagQueryConditions(filter);
45864525
return listBefore(
45874526
getTableName(),
45884527
filter.getQueryParams(),
4589-
mySqlCondition,
4590-
postgresCondition,
4528+
conditions.getLeft(),
4529+
conditions.getRight(),
45914530
limit,
45924531
beforeName,
45934532
beforeId);
45944533
}
45954534

45964535
@Override
45974536
default List<String> listAfter(ListFilter filter, int limit, String afterName, String afterId) {
4598-
String parent = filter.getQueryParam("parent");
4599-
4600-
// If parent parameter is provided, filter tags by parent classification FQN
4601-
if (parent != null) {
4602-
String parentFqnHash = FullyQualifiedName.buildHash(parent);
4603-
filter.queryParams.put("parentFqnPrefix", parentFqnHash + ".%");
4604-
String condition = filter.getCondition("tag");
4605-
if (!condition.isEmpty()) {
4606-
condition = String.format("%s AND fqnHash LIKE :parentFqnPrefix", condition);
4607-
} else {
4608-
condition = "WHERE fqnHash LIKE :parentFqnPrefix";
4609-
}
4610-
return listAfter(
4611-
getTableName(),
4612-
filter.getQueryParams(),
4613-
condition,
4614-
condition,
4615-
limit,
4616-
afterName,
4617-
afterId);
4618-
}
4619-
4620-
// Original behavior for classification.disabled parameter
4621-
boolean disabled = Boolean.parseBoolean(filter.getQueryParam("classification.disabled"));
4622-
String condition =
4623-
String.format(
4624-
"INNER JOIN entity_relationship er ON tag.id=er.toId AND er.relation=%s AND er.fromEntity='%s' "
4625-
+ "INNER JOIN classification c on er.fromId=c.id",
4626-
CONTAINS.ordinal(), Entity.CLASSIFICATION);
4627-
4628-
String mySqlCondition = condition;
4629-
String postgresCondition = condition;
4630-
4631-
if (disabled) {
4632-
mySqlCondition =
4633-
String.format(
4634-
"%s AND (JSON_EXTRACT(c.json, '$.disabled') IS NULL OR JSON_EXTRACT(c.json, '$.disabled') = TRUE)",
4635-
mySqlCondition);
4636-
postgresCondition =
4637-
String.format(
4638-
"%s AND ((c.json#>'{disabled}') IS NULL OR ((c.json#>'{disabled}')::boolean) = TRUE)",
4639-
postgresCondition);
4640-
} else {
4641-
mySqlCondition =
4642-
String.format(
4643-
"%s AND (JSON_EXTRACT(c.json, '$.disabled') IS NULL OR JSON_EXTRACT(c.json, '$.disabled') = FALSE)",
4644-
mySqlCondition);
4645-
postgresCondition =
4646-
String.format(
4647-
"%s AND ((c.json#>'{disabled}') IS NULL OR ((c.json#>'{disabled}')::boolean) = FALSE)",
4648-
postgresCondition);
4649-
}
4650-
4651-
mySqlCondition = String.format("%s %s", mySqlCondition, filter.getCondition("tag"));
4652-
postgresCondition = String.format("%s %s", postgresCondition, filter.getCondition("tag"));
4537+
Pair<String, String> conditions = buildTagQueryConditions(filter);
46534538
return listAfter(
46544539
getTableName(),
46554540
filter.getQueryParams(),
4656-
mySqlCondition,
4657-
postgresCondition,
4541+
conditions.getLeft(),
4542+
conditions.getRight(),
46584543
limit,
46594544
afterName,
46604545
afterId);

openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagResource.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public ResultList<Tag> list(
183183
description = "Filter Disabled Classifications",
184184
schema = @Schema(type = "string", example = FIELDS))
185185
@QueryParam("disabled")
186-
@DefaultValue("false")
187186
Boolean disabled,
188187
@Parameter(description = "Limit the number tags returned. (1 to 1000000, default = 10)")
189188
@DefaultValue("10")
@@ -207,10 +206,10 @@ public ResultList<Tag> list(
207206
@QueryParam("include")
208207
@DefaultValue("non-deleted")
209208
Include include) {
210-
ListFilter filter =
211-
new ListFilter(include)
212-
.addQueryParam("parent", parent)
213-
.addQueryParam("classification.disabled", disabled);
209+
ListFilter filter = new ListFilter(include).addQueryParam("parent", parent);
210+
if (disabled != null) {
211+
filter.addQueryParam("classification.disabled", disabled);
212+
}
214213
return super.listInternal(
215214
uriInfo, securityContext, fieldsParam, filter, limitParam, before, after);
216215
}

0 commit comments

Comments
 (0)