Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2026 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openmetadata.it.tests;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.http.HttpResponse;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openmetadata.it.util.CsvJobClient;

/** The column documentation the bulk import page shows for the type it imports into. */
@Execution(ExecutionMode.CONCURRENT)
public class CsvDocumentationResourceIT {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final CsvJobClient CLIENT = CsvJobClient.onDefaultServer();

@Test
void test_glossaryTermImportGetsTheGlossaryDocumentation() throws Exception {
HttpResponse<String> glossary = CLIENT.request("GET", "/v1/csv/documentation/glossary", null);
HttpResponse<String> glossaryTerm =
CLIENT.request("GET", "/v1/csv/documentation/glossaryTerm", null);

assertEquals(200, glossaryTerm.statusCode(), glossaryTerm.body());
JsonNode termDocumentation = MAPPER.readTree(glossaryTerm.body());
assertFalse(termDocumentation.path("headers").isEmpty());
assertEquals(MAPPER.readTree(glossary.body()), termDocumentation);
}

@Test
void test_unknownEntityTypeIsNotFound() throws Exception {
HttpResponse<String> response =
CLIENT.request("GET", "/v1/csv/documentation/notAnEntityType", null);

assertEquals(404, response.statusCode(), response.body());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

Expand All @@ -38,13 +39,16 @@
import org.openmetadata.it.util.TestNamespaceExtension;
import org.openmetadata.schema.api.data.CreateGlossary;
import org.openmetadata.schema.api.data.CreateGlossaryTerm;
import org.openmetadata.schema.api.tasks.ResolveTask;
import org.openmetadata.schema.entity.data.Glossary;
import org.openmetadata.schema.entity.data.GlossaryTerm;
import org.openmetadata.schema.entity.tasks.Task;
import org.openmetadata.schema.entity.teams.User;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.EntityStatus;
import org.openmetadata.schema.type.TaskEntityStatus;
import org.openmetadata.schema.type.TaskResolutionType;
import org.openmetadata.sdk.exceptions.ForbiddenException;
import org.openmetadata.sdk.models.ListResponse;
import org.openmetadata.sdk.network.HttpMethod;
import org.openmetadata.sdk.network.RequestOptions;
Expand Down Expand Up @@ -125,6 +129,53 @@ void test_directReviewerOnTerm_createsOpenApprovalTask(TestNamespace ns) throws
waitForTermStatus(term.getId(), EntityStatus.IN_REVIEW);
}

/**
* Whoever the task policy lets resolve the approval, here an admin who is not a reviewer, must be
* able to apply it. The workflow used to reject the status change as "not a reviewer", leaving the
* term In Review behind an approved task.
*/
@Test
void test_nonReviewerApprovingTheTask_movesTermToApproved(TestNamespace ns) throws Exception {
Glossary glossary = createGlossary(ns, /* withReviewer */ false);
GlossaryTerm term =
createTerm(glossary, "admin_approved_term", /* attachReviewerDirectly */ true);

Task task = awaitOpenApprovalTask(term.getId(), term.getFullyQualifiedName());
waitForTermStatus(term.getId(), EntityStatus.IN_REVIEW);

SdkClients.adminClient()
.tasks()
.resolve(
task.getId().toString(),
new ResolveTask().withResolutionType(TaskResolutionType.Approved));

waitForTermStatus(term.getId(), EntityStatus.APPROVED);
}

/** Only the workflow is exempt: a non-reviewer approving by a direct edit is still rejected. */
@Test
void test_nonReviewerApprovingByDirectEdit_isRejected(TestNamespace ns) throws Exception {
Glossary glossary = createGlossary(ns, /* withReviewer */ false);
GlossaryTerm term =
createTerm(glossary, "directly_approved_term", /* attachReviewerDirectly */ true);
awaitOpenApprovalTask(term.getId(), term.getFullyQualifiedName());
waitForTermStatus(term.getId(), EntityStatus.IN_REVIEW);

JsonNode approve =
new ObjectMapper()
.readTree(
String.format(
"[{\"op\":\"replace\",\"path\":\"/entityStatus\",\"value\":\"%s\"}]",
EntityStatus.APPROVED.value()));
ForbiddenException denied =
assertThrows(
ForbiddenException.class,
() -> SdkClients.adminClient().glossaryTerms().patch(term.getId().toString(), approve));

assertTrue(denied.getMessage().contains("is not a reviewer"), denied.getMessage());
assertEquals(EntityStatus.IN_REVIEW, safeCurrentStatus(term.getId()));
}

/**
* Bug: the glossary carries the reviewer and the term attaches none, so the term inherits the
* reviewer. The approval workflow must produce the SAME outcome as the direct case — {@code In
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.openmetadata.it.util.SdkClients;
import org.openmetadata.it.util.TestNamespace;
import org.openmetadata.it.util.TestNamespaceExtension;
Expand All @@ -42,6 +44,7 @@
import org.openmetadata.schema.type.MessageSchema;
import org.openmetadata.schema.type.SchemaType;
import org.openmetadata.sdk.client.OpenMetadataClient;
import org.openmetadata.sdk.exceptions.InvalidRequestException;

/**
* Integration tests for Search functionality using fluent API.
Expand Down Expand Up @@ -1801,10 +1804,22 @@ void testSearchWithVeryLargeSize(TestNamespace ns) throws Exception {
void testSearchWithNegativeOffset(TestNamespace ns) throws Exception {
OpenMetadataClient client = SdkClients.adminClient();

// Negative offset is invalid - Elasticsearch rejects it
assertThrows(
org.openmetadata.sdk.exceptions.ApiException.class,
() -> client.search().query("*").index("table_search_index").from(-1).size(10).execute());
// The engine would also reject it; the message shows the request never reached it.
InvalidRequestException thrown =
assertThrows(
InvalidRequestException.class,
() ->
client
.search()
.query("*")
.index("table_search_index")
.from(-25)
.size(25)
.execute());

assertTrue(
thrown.getMessage().contains("query param from must be greater than or equal to 0"),
thrown.getMessage());
}

@Test
Expand Down Expand Up @@ -1985,4 +2000,60 @@ void testExportWithFromBeyondResults(TestNamespace ns) throws Exception {
String[] lines = response.body().split("\n");
assertEquals(1, lines.length, "Export beyond results should only contain header");
}

@ParameterizedTest
@ValueSource(
strings = {
"/v1/search/query?q=*&index=table_search_index&size=-1",
"/v1/search/nlq/query?q=tables&index=table_search_index&from=-25",
"/v1/search/fieldQuery?fieldName=name&fieldValue=orders&index=table_search_index&from=-25",
"/v1/search/fieldQuery?fieldName=name&fieldValue=orders&index=table_search_index&size=-1"
})
void testNegativePaginationIsRejectedAsBadRequest(String path) throws Exception {
HttpResponse<String> response = httpGetSearch(path);

assertEquals(400, response.statusCode(), path + " returned " + response.body());
assertTrue(
response.body().contains("must be greater than or equal to 0"),
path + " returned " + response.body());
}

@Test
void testPreviewSearchWithNegativeOffsetIsRejectedAsBadRequest() throws Exception {
String previewRequest =
"""
{"query": "*", "index": "table", "from": -25, "size": 25, "searchSettings": {}}
""";

HttpResponse<String> response = httpPostJson("/v1/search/preview", previewRequest);

assertEquals(400, response.statusCode(), response.body());
assertTrue(
response.body().contains("from must be greater than or equal to 0"), response.body());
}

private HttpResponse<String> httpGetSearch(String path) throws Exception {
HttpRequest request =
HttpRequest.newBuilder()
.uri(URI.create(SdkClients.getServerUrl() + path))
.header("Authorization", "Bearer " + SdkClients.getAdminToken())
.header("Accept", "application/json")
.timeout(Duration.ofSeconds(30))
.GET()
.build();
return HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
}

private HttpResponse<String> httpPostJson(String path, String jsonBody) throws Exception {
HttpRequest request =
HttpRequest.newBuilder()
.uri(URI.create(SdkClients.getServerUrl() + path))
.header("Authorization", "Bearer " + SdkClients.getAdminToken())
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.timeout(Duration.ofSeconds(30))
.POST(HttpRequest.BodyPublishers.ofString(jsonBody))
.build();
return HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public abstract class EntityCsv<T extends EntityInterface> {

public static final int DEFAULT_BATCH_SIZE = 100;

// Glossary terms are imported and exported through GlossaryCsv, so they share its documentation.
private static final Map<String, String> CSV_DOCUMENTATION_TYPES =
Map.of(Entity.GLOSSARY_TERM, Entity.GLOSSARY);

private final String entityType;
private final List<CsvHeader> csvHeaders;
private final List<String> expectedHeaders;
Expand Down Expand Up @@ -324,7 +328,8 @@ public final String exportCsv(List<T> entities, CsvExportProgressCallback callba
}

public static CsvDocumentation getCsvDocumentation(String entityType, boolean recursive) {
String effectiveEntityType = (recursive) ? "entity" : entityType;
String effectiveEntityType =
recursive ? "entity" : CSV_DOCUMENTATION_TYPES.getOrDefault(entityType, entityType);
LOG.info("Initializing CSV documentation for entity {}", effectiveEntityType);

String path =
Expand All @@ -334,24 +339,19 @@ public static CsvDocumentation getCsvDocumentation(String entityType, boolean re
try {
List<String> jsonDataFiles = EntityUtil.getJsonDataResources(path);
if (jsonDataFiles.isEmpty()) {
String message =
String.format(
"Failed to load CSV documentation for entity %s from path %s",
effectiveEntityType, path);
LOG.error("FATAL - {}", message);
throw new IllegalStateException(message);
throw EntityNotFoundException.byMessage(
String.format("No CSV documentation exists for entity type %s", entityType));
}
String json =
CommonUtil.getResourceAsStream(
EntityRepository.class.getClassLoader(), jsonDataFiles.get(0));
return JsonUtils.readValue(json, CsvDocumentation.class);
} catch (IOException | JsonParsingException e) {
String message =
throw new IllegalStateException(
String.format(
"Failed to load CSV documentation for entity %s from path %s",
effectiveEntityType, path);
LOG.error("FATAL - {}", message, e);
throw new IllegalStateException(message, e);
effectiveEntityType, path),
e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.openmetadata.schema.type.Include;
import org.openmetadata.schema.utils.JsonUtils;
import org.openmetadata.service.Entity;
import org.openmetadata.service.governance.workflows.WorkflowEventConsumer;
import org.openmetadata.service.governance.workflows.WorkflowVariableHandler;
import org.openmetadata.service.governance.workflows.WorkflowVariableHandler.InputNamespaces;
import org.openmetadata.service.jdbi3.GlossaryTermRepository;
Expand Down Expand Up @@ -85,7 +86,8 @@ private void setStatus(GlossaryTerm glossaryTerm, String user, String status) {

GlossaryTermRepository entityRepository =
(GlossaryTermRepository) Entity.getEntityRepository(Entity.GLOSSARY_TERM);
entityRepository.patch(null, glossaryTerm.getId(), user, patch);
entityRepository.patch(
null, glossaryTerm.getId(), user, patch, null, WorkflowEventConsumer.GOVERNANCE_BOT);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import static org.openmetadata.service.exception.CatalogExceptionMessage.notTaskAssignee;
import static org.openmetadata.service.governance.workflows.Workflow.RESULT_VARIABLE;
import static org.openmetadata.service.governance.workflows.Workflow.UPDATED_BY_VARIABLE;
import static org.openmetadata.service.governance.workflows.WorkflowEventConsumer.GOVERNANCE_BOT;
import static org.openmetadata.service.monitoring.RequestLatencyContext.phase;
import static org.openmetadata.service.resources.tags.TagLabelUtil.addDerivedTags;
import static org.openmetadata.service.resources.tags.TagLabelUtil.addDerivedTagsGracefully;
Expand Down Expand Up @@ -543,7 +544,7 @@
@Getter protected final Set<String> allowedFields;
public final boolean supportsSoftDelete;
@Getter protected final boolean supportsTags;
@Getter protected final boolean supportsOwners;

Check warning on line 547 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / build

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 547 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / openmetadata-service-unit-tests

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 547 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / maven-sonarcloud-ci

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 547 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / build-image

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 547 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / build-image

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 547 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / py-run-build-tests

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 547 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / search-it-nightly

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 547 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / ui-it-nightly (opensearch)

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 547 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / ui-it-nightly (elasticsearch)

Not generating isSupportsOwners(): A method with that name already exists
@Getter protected final boolean supportsStyle;
@Getter protected final boolean supportsLifeCycle;
@Getter protected final boolean supportsCertification;
Expand Down Expand Up @@ -9340,17 +9341,25 @@
if (original.getEntityStatus() == updated.getEntityStatus()) {
return;
}
// Only reviewers can change from IN_REVIEW status to APPROVED/REJECTED status
// Only reviewers can change from IN_REVIEW status to APPROVED/REJECTED status. A workflow's
// approval task already decided who may approve, so the rule only guards direct edits.
if (!consolidatingChanges
&& original.getEntityStatus() == EntityStatus.IN_REVIEW
&& (updated.getEntityStatus() == EntityStatus.APPROVED
|| updated.getEntityStatus() == EntityStatus.REJECTED)) {
|| updated.getEntityStatus() == EntityStatus.REJECTED)
&& !isWorkflowChange(updated)) {
checkUpdatedByReviewer(original, updated.getUpdatedBy());
}
recordChange("entityStatus", original.getEntityStatus(), updated.getEntityStatus());
}
}

// Workflows change entities as, or impersonating, the governance bot.
private static boolean isWorkflowChange(EntityInterface entity) {
return GOVERNANCE_BOT.equals(entity.getUpdatedBy())
|| GOVERNANCE_BOT.equals(entity.getImpersonatedBy());
}

public static void checkUpdatedByReviewer(EntityInterface entity, String updatedBy) {
// Only list of allowed reviewers can change the status from DRAFT to APPROVED
List<EntityReference> reviewers = entity.getReviewers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openmetadata.schema.type.ChangeEvent;
import org.openmetadata.schema.type.Include;
import org.openmetadata.service.Entity;
import org.openmetadata.service.exception.EntityNotFoundException;
import org.openmetadata.service.notifications.recipients.context.Recipient;
import org.openmetadata.service.notifications.recipients.strategy.RecipientResolutionStrategy;

Expand Down Expand Up @@ -76,6 +77,10 @@ private Recipient resolveTeamByName(
try {
Team team = Entity.getEntityByName(Entity.TEAM, teamName, TEAM_FIELDS, Include.NON_DELETED);
return Recipient.fromTeam(team, notificationType);
} catch (EntityNotFoundException e) {
// A team an alert names can be deleted later; that leaves no one to notify, not a failure.
LOG.debug("Skipping team recipient {}: {}", teamName, e.getMessage());
return null;
} catch (Exception e) {
LOG.error("Failed to resolve team recipient for team {}", teamName, e);
return null;
Expand Down Expand Up @@ -113,6 +118,9 @@ private Recipient resolveTeamById(
try {
Team team = Entity.getEntity(Entity.TEAM, teamId, TEAM_FIELDS, Include.NON_DELETED);
return Recipient.fromTeam(team, notificationType);
} catch (EntityNotFoundException e) {
LOG.debug("Skipping team recipient {}: {}", teamId, e.getMessage());
return null;
} catch (Exception e) {
LOG.error("Failed to resolve team recipient for team {}", teamId, e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openmetadata.schema.type.ChangeEvent;
import org.openmetadata.schema.type.Include;
import org.openmetadata.service.Entity;
import org.openmetadata.service.exception.EntityNotFoundException;
import org.openmetadata.service.notifications.recipients.context.Recipient;
import org.openmetadata.service.notifications.recipients.strategy.RecipientResolutionStrategy;

Expand Down Expand Up @@ -76,6 +77,10 @@ private Recipient resolveUserByName(
try {
User user = Entity.getEntityByName(Entity.USER, userName, USER_FIELDS, Include.NON_DELETED);
return Recipient.fromUser(user, notificationType);
} catch (EntityNotFoundException e) {
// A user an alert names can be deleted later; that leaves no one to notify, not a failure.
LOG.debug("Skipping user recipient {}: {}", userName, e.getMessage());
return null;
} catch (Exception e) {
LOG.error("Failed to resolve user recipient for user {}", userName, e);
return null;
Expand Down Expand Up @@ -112,6 +117,9 @@ private Recipient resolveUserById(
try {
User user = Entity.getEntity(Entity.USER, userId, USER_FIELDS, Include.NON_DELETED);
return Recipient.fromUser(user, notificationType);
} catch (EntityNotFoundException e) {
LOG.debug("Skipping user recipient {}: {}", userId, e.getMessage());
return null;
} catch (Exception e) {
LOG.error("Failed to resolve user recipient for user {}", userId, e);
return null;
Expand Down
Loading
Loading