mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-16 13:41:37 +00:00
parent
c4902cc809
commit
ad39b38b10
@ -16,6 +16,8 @@ package org.openmetadata.service.formatter.util;
|
||||
import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty;
|
||||
import static org.openmetadata.schema.type.EventType.ENTITY_CREATED;
|
||||
import static org.openmetadata.service.Entity.FIELD_EXTENSION;
|
||||
import static org.openmetadata.service.Entity.TEST_CASE;
|
||||
import static org.openmetadata.service.Entity.TEST_CASE_RESULT;
|
||||
import static org.openmetadata.service.Entity.THREAD;
|
||||
import static org.openmetadata.service.formatter.factory.ParserFactory.getFieldParserObject;
|
||||
import static org.openmetadata.service.formatter.field.DefaultFieldFormatter.getFieldNameChange;
|
||||
@ -31,11 +33,16 @@ import javax.ws.rs.container.ContainerResponseContext;
|
||||
import javax.ws.rs.core.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.openmetadata.schema.EntityInterface;
|
||||
import org.openmetadata.schema.EntityTimeSeriesInterface;
|
||||
import org.openmetadata.schema.entity.feed.Thread;
|
||||
import org.openmetadata.schema.tests.TestCase;
|
||||
import org.openmetadata.schema.tests.type.TestCaseResult;
|
||||
import org.openmetadata.schema.type.ChangeDescription;
|
||||
import org.openmetadata.schema.type.ChangeEvent;
|
||||
import org.openmetadata.schema.type.EventType;
|
||||
import org.openmetadata.schema.type.FieldChange;
|
||||
import org.openmetadata.schema.type.Include;
|
||||
import org.openmetadata.service.Entity;
|
||||
import org.openmetadata.service.formatter.decorators.MessageDecorator;
|
||||
import org.openmetadata.service.formatter.factory.ParserFactory;
|
||||
import org.openmetadata.service.formatter.field.DefaultFieldFormatter;
|
||||
@ -237,6 +244,11 @@ public class FormatterUtil {
|
||||
return createChangeEventForThread(updateBy, eventType, thread);
|
||||
}
|
||||
|
||||
// if the response entity is an EntityTimeseriesInterface, then create a ChangeEvent from it
|
||||
if (responseContext.getEntity() instanceof EntityTimeSeriesInterface entityTimeSeries) {
|
||||
return createChangeEventForEntity(updateBy, eventType, entityTimeSeries);
|
||||
}
|
||||
|
||||
LOG.debug("Unknown event type in Change Event : {}", eventType.value());
|
||||
return null;
|
||||
}
|
||||
@ -253,6 +265,12 @@ public class FormatterUtil {
|
||||
.withEntityFullyQualifiedName(entityInterface.getEntityReference().getFullyQualifiedName());
|
||||
}
|
||||
|
||||
private static ChangeEvent createChangeEventForEntity(
|
||||
String updateBy, EventType eventType, EntityTimeSeriesInterface entityTimeSeries) {
|
||||
return getChangeEventForEntityTimeSeries(
|
||||
updateBy, eventType, entityTimeSeries.getEntityReference().getType(), entityTimeSeries);
|
||||
}
|
||||
|
||||
private static ChangeEvent createChangeEventForThread(
|
||||
String updateBy, EventType eventType, Thread threadEntity) {
|
||||
return getChangeEventForThread(updateBy, eventType, THREAD, threadEntity)
|
||||
@ -285,6 +303,36 @@ public class FormatterUtil {
|
||||
.withCurrentVersion(entityInterface.getVersion());
|
||||
}
|
||||
|
||||
private static ChangeEvent getChangeEventForEntityTimeSeries(
|
||||
String updateBy,
|
||||
EventType eventType,
|
||||
String entityType,
|
||||
EntityTimeSeriesInterface entityTimeSeries) {
|
||||
if (entityTimeSeries instanceof TestCaseResult) {
|
||||
eventType =
|
||||
EventType
|
||||
.ENTITY_UPDATED; // workaround as adding a test case result is sent as a POST request
|
||||
TestCaseResult testCaseResult =
|
||||
JsonUtils.readOrConvertValue(entityTimeSeries, TestCaseResult.class);
|
||||
TestCase testCase =
|
||||
Entity.getEntityByName(
|
||||
TEST_CASE, testCaseResult.getTestCaseFQN(), TEST_CASE_RESULT, Include.ALL);
|
||||
ChangeEvent changeEvent =
|
||||
getChangeEvent(updateBy, eventType, testCase.getEntityReference().getType(), testCase);
|
||||
return changeEvent
|
||||
.withChangeDescription(
|
||||
new ChangeDescription()
|
||||
.withFieldsUpdated(
|
||||
List.of(
|
||||
new FieldChange()
|
||||
.withName(TEST_CASE_RESULT)
|
||||
.withNewValue(testCase.getTestCaseResult()))))
|
||||
.withEntity(testCase)
|
||||
.withEntityFullyQualifiedName(testCase.getFullyQualifiedName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ChangeEvent getChangeEventForThread(
|
||||
String updateBy, EventType eventType, String entityType, Thread thread) {
|
||||
return new ChangeEvent()
|
||||
|
Loading…
x
Reference in New Issue
Block a user