From 32e9ae337f8fb20cf8f423bb0bdcc4f248b2fc6a Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Wed, 12 Apr 2023 01:32:29 -0700 Subject: [PATCH] Remove space before : in before update activity feed message (#10992) * Misc WIP * Remove space before : in before update activity feed message --------- Co-authored-by: Pere Miquel Brull --- .../service/events/ChangeEventHandler.java | 3 +- .../service/jdbi3/FeedRepository.java | 7 +- .../IngestionPipelineResource.java | 2 +- .../service/util/ChangeEventParser.java | 121 +++++++++--------- .../ChangeEventParserResourceTest.java | 39 +++--- .../resources/feeds/FeedResourceTest.java | 6 +- 6 files changed, 84 insertions(+), 94 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/events/ChangeEventHandler.java b/openmetadata-service/src/main/java/org/openmetadata/service/events/ChangeEventHandler.java index 8e13acd7027..cd55af2a7e3 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/events/ChangeEventHandler.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/events/ChangeEventHandler.java @@ -44,6 +44,7 @@ import org.openmetadata.service.jdbi3.FeedRepository; import org.openmetadata.service.resources.feeds.MessageParser.EntityLink; import org.openmetadata.service.socket.WebSocketManager; import org.openmetadata.service.util.ChangeEventParser; +import org.openmetadata.service.util.ChangeEventParser.PublishTo; import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.NotificationHandler; import org.openmetadata.service.util.RestUtil; @@ -269,7 +270,7 @@ public class ChangeEventHandler implements EventHandler { EntityInterface entity, ChangeDescription changeDescription, String loggedInUserName) { List threads = new ArrayList<>(); Map messages = - ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, entity); + ChangeEventParser.getFormattedMessages(PublishTo.FEED, changeDescription, entity); // Create an automated thread for (EntityLink link : messages.keySet()) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java index 3ef455353c5..ff7fbdb23ac 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java @@ -90,6 +90,7 @@ import org.openmetadata.service.resources.feeds.FeedUtil; import org.openmetadata.service.resources.feeds.MessageParser; import org.openmetadata.service.resources.feeds.MessageParser.EntityLink; import org.openmetadata.service.util.*; +import org.openmetadata.service.util.ChangeEventParser.PublishTo; import org.openmetadata.service.util.RestUtil.DeleteResponse; import org.openmetadata.service.util.RestUtil.PatchResponse; @@ -458,7 +459,7 @@ public class FeedRepository { message = String.format( "Resolved the Task with Description - %s", - getPlaintextDiff(ChangeEventParser.PUBLISH_TO.FEED, oldValue, task.getNewValue())); + getPlaintextDiff(PublishTo.FEED, oldValue, task.getNewValue())); } else if (List.of(TaskType.RequestTag, TaskType.UpdateTag).contains(type)) { List tags; if (task.getOldValue() != null) { @@ -468,9 +469,7 @@ public class FeedRepository { tags = JsonUtils.readObjects(task.getNewValue(), TagLabel.class); String newValue = getTagFQNs(tags); message = - String.format( - "Resolved the Task with Tag(s) - %s", - getPlaintextDiff(ChangeEventParser.PUBLISH_TO.FEED, oldValue, newValue)); + String.format("Resolved the Task with Tag(s) - %s", getPlaintextDiff(PublishTo.FEED, oldValue, newValue)); } else { message = "Resolved the Task."; } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/services/ingestionpipelines/IngestionPipelineResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/services/ingestionpipelines/IngestionPipelineResource.java index db6b1113666..20aee634545 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/services/ingestionpipelines/IngestionPipelineResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/services/ingestionpipelines/IngestionPipelineResource.java @@ -82,7 +82,7 @@ import org.openmetadata.service.util.ResultList; // TODO merge with workflows @Slf4j -@Path("/v1/services/ingestionPipelines/") +@Path("/v1/services/ingestionPipelines") @Tag( name = "Ingestion Pipelines", description = "APIs related pipelines/workflows created by the system to ingest metadata.") diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/ChangeEventParser.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/ChangeEventParser.java index 4a2f74287a7..06411df3c01 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/ChangeEventParser.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/ChangeEventParser.java @@ -17,6 +17,7 @@ import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; import static org.openmetadata.service.Entity.FIELD_DISPLAY_NAME; import static org.openmetadata.service.Entity.FIELD_NAME; import static org.openmetadata.service.Entity.FIELD_OWNER; +import static org.openmetadata.service.Entity.FIELD_TAGS; import static org.openmetadata.service.Entity.INGESTION_PIPELINE; import static org.openmetadata.service.Entity.KPI; import static org.openmetadata.service.Entity.TEST_CASE; @@ -43,7 +44,6 @@ import org.apache.commons.lang.StringUtils; import org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch; import org.openmetadata.common.utils.CommonUtil; import org.openmetadata.schema.EntityInterface; -import org.openmetadata.schema.dataInsight.kpi.Kpi; import org.openmetadata.schema.dataInsight.type.KpiResult; import org.openmetadata.schema.dataInsight.type.KpiTarget; import org.openmetadata.schema.entity.data.Query; @@ -74,17 +74,15 @@ public final class ChangeEventParser { public static final String FEED_LINE_BREAK = "
"; public static final String SLACK_LINE_BREAK = "\n"; - private static volatile boolean INITIALIZED = false; - private ChangeEventParser() {} - public enum CHANGE_TYPE { + public enum ChangeType { UPDATE, ADD, DELETE } - public enum PUBLISH_TO { + public enum PublishTo { FEED, SLACK, TEAMS, @@ -92,7 +90,7 @@ public final class ChangeEventParser { EMAIL } - public static String getBold(PUBLISH_TO publishTo) { + public static String getBold(PublishTo publishTo) { switch (publishTo) { case FEED: case TEAMS: @@ -108,7 +106,7 @@ public final class ChangeEventParser { } } - public static String getLineBreak(PUBLISH_TO publishTo) { + public static String getLineBreak(PublishTo publishTo) { switch (publishTo) { case FEED: case TEAMS: @@ -123,7 +121,7 @@ public final class ChangeEventParser { } } - public static String getAddMarker(PUBLISH_TO publishTo) { + public static String getAddMarker(PublishTo publishTo) { switch (publishTo) { case FEED: return FEED_SPAN_ADD; @@ -139,7 +137,7 @@ public final class ChangeEventParser { } } - public static String getAddMarkerClose(PUBLISH_TO publishTo) { + public static String getAddMarkerClose(PublishTo publishTo) { switch (publishTo) { case FEED: return FEED_SPAN_CLOSE; @@ -155,7 +153,7 @@ public final class ChangeEventParser { } } - public static String getRemoveMarker(PUBLISH_TO publishTo) { + public static String getRemoveMarker(PublishTo publishTo) { switch (publishTo) { case FEED: return FEED_SPAN_REMOVE; @@ -171,7 +169,7 @@ public final class ChangeEventParser { } } - public static String getRemoveMarkerClose(PUBLISH_TO publishTo) { + public static String getRemoveMarkerClose(PublishTo publishTo) { switch (publishTo) { case FEED: return FEED_SPAN_CLOSE; @@ -187,7 +185,7 @@ public final class ChangeEventParser { } } - public static String getEntityUrl(PUBLISH_TO publishTo, ChangeEvent event) { + public static String getEntityUrl(PublishTo publishTo, ChangeEvent event) { String fqn; String entityType; EntityInterface entity = (EntityInterface) event.getEntity(); @@ -198,14 +196,13 @@ public final class ChangeEventParser { fqn = event.getEntityFullyQualifiedName(); entityType = event.getEntityType(); } - if (publishTo == PUBLISH_TO.SLACK || publishTo == PUBLISH_TO.GCHAT) { + if (publishTo == PublishTo.SLACK || publishTo == PublishTo.GCHAT) { return String.format( "<%s/%s/%s|%s>", ChangeEventConfig.getInstance().getOmUri(), entityType, fqn.trim().replaceAll(" ", "%20"), fqn.trim()); - } else if (publishTo == PUBLISH_TO.TEAMS) { - return String.format( - "[%s](/%s/%s)", fqn.trim(), ChangeEventConfig.getInstance().getOmUri(), entityType, fqn.trim()); - } else if (publishTo == PUBLISH_TO.EMAIL) { + } else if (publishTo == PublishTo.TEAMS) { + return String.format("[%s](/%s/%s)", fqn.trim(), ChangeEventConfig.getInstance().getOmUri(), entityType); + } else if (publishTo == PublishTo.EMAIL) { return String.format( "%s", ChangeEventConfig.getInstance().getOmUri(), entityType, fqn.trim(), fqn.trim()); @@ -231,12 +228,12 @@ public final class ChangeEventParser { headerText = String.format(headerTxt, event.getUserName()); } else { headerTxt = "%s posted on " + eventType + " %s"; - headerText = String.format(headerTxt, event.getUserName(), getEntityUrl(PUBLISH_TO.SLACK, event)); + headerText = String.format(headerTxt, event.getUserName(), getEntityUrl(PublishTo.SLACK, event)); } slackMessage.setText(headerText); } Map messages = - getFormattedMessages(PUBLISH_TO.SLACK, event.getChangeDescription(), (EntityInterface) event.getEntity()); + getFormattedMessages(PublishTo.SLACK, event.getChangeDescription(), (EntityInterface) event.getEntity()); List attachmentList = new ArrayList<>(); for (Entry entry : messages.entrySet()) { SlackAttachment attachment = new SlackAttachment(); @@ -258,11 +255,11 @@ public final class ChangeEventParser { if (event.getEntityType().equals(Entity.QUERY)) { emailMessage.setEntityUrl(Entity.QUERY); } else { - emailMessage.setEntityUrl(getEntityUrl(PUBLISH_TO.EMAIL, event)); + emailMessage.setEntityUrl(getEntityUrl(PublishTo.EMAIL, event)); } } Map messages = - getFormattedMessages(PUBLISH_TO.EMAIL, event.getChangeDescription(), (EntityInterface) event.getEntity()); + getFormattedMessages(PublishTo.EMAIL, event.getChangeDescription(), (EntityInterface) event.getEntity()); List changeMessage = new ArrayList<>(); for (Entry entry : messages.entrySet()) { changeMessage.add(entry.getValue()); @@ -277,11 +274,11 @@ public final class ChangeEventParser { TeamsMessage.Section teamsSections = new TeamsMessage.Section(); if (event.getEntity() != null) { String headerTxt = "%s posted on " + event.getEntityType() + " %s"; - String headerText = String.format(headerTxt, event.getUserName(), getEntityUrl(PUBLISH_TO.TEAMS, event)); + String headerText = String.format(headerTxt, event.getUserName(), getEntityUrl(PublishTo.TEAMS, event)); teamsSections.setActivityTitle(headerText); } Map messages = - getFormattedMessages(PUBLISH_TO.TEAMS, event.getChangeDescription(), (EntityInterface) event.getEntity()); + getFormattedMessages(PublishTo.TEAMS, event.getChangeDescription(), (EntityInterface) event.getEntity()); List attachmentList = new ArrayList<>(); for (Entry entry : messages.entrySet()) { TeamsMessage.Section section = new TeamsMessage.Section(); @@ -302,7 +299,7 @@ public final class ChangeEventParser { String headerTemplate = "%s posted on %s %s"; String headerText = String.format( - headerTemplate, event.getUserName(), event.getEntityType(), getEntityUrl(PUBLISH_TO.GCHAT, event)); + headerTemplate, event.getUserName(), event.getEntityType(), getEntityUrl(PublishTo.GCHAT, event)); gChatMessage.setText(headerText); GChatMessage.CardHeader cardHeader = new GChatMessage.CardHeader(); String cardHeaderText = @@ -315,7 +312,7 @@ public final class ChangeEventParser { card.setHeader(cardHeader); } Map messages = - getFormattedMessages(PUBLISH_TO.GCHAT, event.getChangeDescription(), (EntityInterface) event.getEntity()); + getFormattedMessages(PublishTo.GCHAT, event.getChangeDescription(), (EntityInterface) event.getEntity()); List widgets = new ArrayList<>(); for (Entry entry : messages.entrySet()) { GChatMessage.Widget widget = new GChatMessage.Widget(); @@ -330,24 +327,24 @@ public final class ChangeEventParser { } public static Map getFormattedMessages( - PUBLISH_TO publishTo, ChangeDescription changeDescription, EntityInterface entity) { + PublishTo publishTo, ChangeDescription changeDescription, EntityInterface entity) { // Store a map of entityLink -> message Map messages; List fieldsUpdated = changeDescription.getFieldsUpdated(); - messages = getFormattedMessagesForAllFieldChange(publishTo, entity, fieldsUpdated, CHANGE_TYPE.UPDATE); + messages = getFormattedMessagesForAllFieldChange(publishTo, entity, fieldsUpdated, ChangeType.UPDATE); // fieldsAdded and fieldsDeleted need special handling since // there is a possibility to merge them as one update message. List fieldsAdded = changeDescription.getFieldsAdded(); List fieldsDeleted = changeDescription.getFieldsDeleted(); - messages.putAll(mergeAddtionsDeletion(publishTo, entity, fieldsAdded, fieldsDeleted)); + messages.putAll(mergeAdditionsDeletion(publishTo, entity, fieldsAdded, fieldsDeleted)); return messages; } private static Map getFormattedMessagesForAllFieldChange( - PUBLISH_TO publishTo, EntityInterface entity, List fields, CHANGE_TYPE changeType) { + PublishTo publishTo, EntityInterface entity, List fields, ChangeType changeType) { Map messages = new HashMap<>(); for (FieldChange field : fields) { @@ -366,14 +363,13 @@ public final class ChangeEventParser { oldFieldValue = getFieldValue(field.getOldValue()); } if (link.getEntityType().equals(TEST_CASE) && link.getFieldName().equals("testCaseResult")) { - String message = handleTestCaseResult(publishTo, entity, link, field.getOldValue(), field.getNewValue()); + String message = handleTestCaseResult(publishTo, entity, field.getNewValue()); messages.put(link, message); } else if (link.getEntityType().equals(KPI) && link.getFieldName().equals("kpiResult")) { - String message = handleKpiResult(publishTo, entity, link, field.getOldValue(), field.getNewValue()); + String message = handleKpiResult(publishTo, entity, field.getNewValue()); messages.put(link, message); } else if (link.getEntityType().equals(INGESTION_PIPELINE) && link.getFieldName().equals("pipelineStatus")) { - String message = - handleIngestionPipelineResult(publishTo, entity, link, field.getOldValue(), field.getNewValue()); + String message = handleIngestionPipelineResult(publishTo, entity, field.getNewValue()); messages.put(link, message); } else if (!fieldName.equals("failureDetails")) { String message = createMessageForField(publishTo, link, changeType, fieldName, oldFieldValue, newFieldValue); @@ -434,8 +430,8 @@ public final class ChangeEventParser { Object newValue, Object oldValue, EntityInterface entity, - PUBLISH_TO publishTo, - CHANGE_TYPE changeType, + PublishTo publishTo, + ChangeType changeType, EntityLink link) { String fieldName = "queryUsage"; String newVal = getFieldValueForQuery(newValue, entity, publishTo); @@ -443,11 +439,12 @@ public final class ChangeEventParser { return createMessageForField(publishTo, link, changeType, fieldName, oldVal, newVal); } - private static String getFieldValueForQuery(Object fieldValue, EntityInterface entity, PUBLISH_TO publishTo) { + private static String getFieldValueForQuery(Object fieldValue, EntityInterface entity, PublishTo publishTo) { Query query = (Query) entity; StringBuilder field = new StringBuilder(); + @SuppressWarnings("unchecked") List queryUsedIn = (List) fieldValue; - field.append("for ").append("'" + query.getQuery() + "'").append(", ").append(getLineBreak(publishTo)); + field.append("for ").append("'").append(query.getQuery()).append("'").append(", ").append(getLineBreak(publishTo)); field.append("Query Used in :- "); int i = 1; for (EntityReference queryUsage : queryUsedIn) { @@ -460,14 +457,14 @@ public final class ChangeEventParser { return field.toString(); } - private static String getQueryUsageUrl(PUBLISH_TO publishTo, String fqn, String entityType) { - if (publishTo == PUBLISH_TO.SLACK || publishTo == PUBLISH_TO.GCHAT) { + private static String getQueryUsageUrl(PublishTo publishTo, String fqn, String entityType) { + if (publishTo == PublishTo.SLACK || publishTo == PublishTo.GCHAT) { return String.format( "<%s/%s/%s|%s>", ChangeEventConfig.getInstance().getOmUri(), entityType, fqn.trim().replaceAll(" ", "%20"), fqn.trim()); - } else if (publishTo == PUBLISH_TO.TEAMS) { - return String.format("[%s](/%s/%s)", fqn, ChangeEventConfig.getInstance().getOmUri(), entityType, fqn.trim()); - } else if (publishTo == PUBLISH_TO.EMAIL) { + } else if (publishTo == PublishTo.TEAMS) { + return String.format("[%s](/%s/%s)", fqn, ChangeEventConfig.getInstance().getOmUri(), entityType); + } else if (publishTo == PublishTo.EMAIL) { return String.format( "%s", ChangeEventConfig.getInstance().getOmUri(), entityType, fqn.trim(), fqn.trim()); @@ -476,8 +473,8 @@ public final class ChangeEventParser { } /** Tries to merge additions and deletions into updates and returns a map of formatted messages. */ - private static Map mergeAddtionsDeletion( - PUBLISH_TO publishTo, EntityInterface entity, List addedFields, List deletedFields) { + private static Map mergeAdditionsDeletion( + PublishTo publishTo, EntityInterface entity, List addedFields, List deletedFields) { // Major schema version changes such as renaming a column from colA to colB // will be recorded as "Removed column colA" and "Added column colB" // This method will try to detect such changes and combine those events into one update. @@ -487,9 +484,9 @@ public final class ChangeEventParser { // if there is only added fields or only deleted fields, we cannot merge if (addedFields.isEmpty() || deletedFields.isEmpty()) { if (!addedFields.isEmpty()) { - messages = getFormattedMessagesForAllFieldChange(publishTo, entity, addedFields, CHANGE_TYPE.ADD); + messages = getFormattedMessagesForAllFieldChange(publishTo, entity, addedFields, ChangeType.ADD); } else if (!deletedFields.isEmpty()) { - messages = getFormattedMessagesForAllFieldChange(publishTo, entity, deletedFields, CHANGE_TYPE.DELETE); + messages = getFormattedMessagesForAllFieldChange(publishTo, entity, deletedFields, ChangeType.DELETE); } return messages; } @@ -502,7 +499,7 @@ public final class ChangeEventParser { // convert the added field and deleted field into one update message String message = createMessageForField( - publishTo, link, CHANGE_TYPE.UPDATE, fieldName, field.getOldValue(), addedField.get().getNewValue()); + publishTo, link, ChangeType.UPDATE, fieldName, field.getOldValue(), addedField.get().getNewValue()); messages.put(link, message); // Remove the field from addedFields list to avoid double processing addedFields = addedFields.stream().filter(f -> !f.equals(addedField.get())).collect(Collectors.toList()); @@ -510,12 +507,12 @@ public final class ChangeEventParser { // process the deleted field messages.putAll( getFormattedMessagesForAllFieldChange( - publishTo, entity, Collections.singletonList(field), CHANGE_TYPE.DELETE)); + publishTo, entity, Collections.singletonList(field), ChangeType.DELETE)); } } // process the remaining added fields if (!addedFields.isEmpty()) { - messages.putAll(getFormattedMessagesForAllFieldChange(publishTo, entity, addedFields, CHANGE_TYPE.ADD)); + messages.putAll(getFormattedMessagesForAllFieldChange(publishTo, entity, addedFields, ChangeType.ADD)); } return messages; } @@ -543,9 +540,9 @@ public final class ChangeEventParser { } private static String createMessageForField( - PUBLISH_TO publishTo, + PublishTo publishTo, EntityLink link, - CHANGE_TYPE changeType, + ChangeType changeType, String fieldName, Object oldFieldValue, Object newFieldValue) { @@ -591,19 +588,19 @@ public final class ChangeEventParser { } private static String getPlainTextUpdateMessage( - PUBLISH_TO publishTo, String updatedField, String oldValue, String newValue) { + PublishTo publishTo, String updatedField, String oldValue, String newValue) { // Get diff of old value and new value String diff = getPlaintextDiff(publishTo, oldValue, newValue); if (nullOrEmpty(diff)) { return StringUtils.EMPTY; } else { - String field = String.format("Updated %s : %s", getBold(publishTo), diff); + String field = String.format("Updated %s: %s", getBold(publishTo), diff); return String.format(field, updatedField); } } private static String getObjectUpdateMessage( - PUBLISH_TO publishTo, String updatedField, JsonObject oldJson, JsonObject newJson) { + PublishTo publishTo, String updatedField, JsonObject oldJson, JsonObject newJson) { List labels = new ArrayList<>(); Set keys = newJson.keySet(); // check if each key's value is the same @@ -623,7 +620,7 @@ public final class ChangeEventParser { return String.format(format, updatedField); } - private static String getUpdateMessage(PUBLISH_TO publishTo, String updatedField, Object oldValue, Object newValue) { + private static String getUpdateMessage(PublishTo publishTo, String updatedField, Object oldValue, Object newValue) { // New value should not be null in any case for an update if (newValue == null) { return StringUtils.EMPTY; @@ -632,7 +629,7 @@ public final class ChangeEventParser { if (nullOrEmpty(oldValue)) { String format = String.format("Updated %s to %s", getBold(publishTo), getFieldValue(newValue)); return String.format(format, updatedField); - } else if (updatedField.contains("tags") || updatedField.contains(FIELD_OWNER)) { + } else if (updatedField.contains(FIELD_TAGS) || updatedField.contains(FIELD_OWNER)) { return getPlainTextUpdateMessage(publishTo, updatedField, getFieldValue(oldValue), getFieldValue(newValue)); } // if old value is not empty, and is of type array or object, the updates can be across multiple keys @@ -673,8 +670,7 @@ public final class ChangeEventParser { return getPlainTextUpdateMessage(publishTo, updatedField, oldValue.toString(), newValue.toString()); } - public static String handleTestCaseResult( - PUBLISH_TO publishTo, EntityInterface entity, EntityLink link, Object oldValue, Object newValue) { + public static String handleTestCaseResult(PublishTo publishTo, EntityInterface entity, Object newValue) { String testCaseName = entity.getName(); TestCaseResult result = (TestCaseResult) newValue; TestCase testCaseEntity = (TestCase) entity; @@ -698,8 +694,7 @@ public final class ChangeEventParser { } } - public static String handleIngestionPipelineResult( - PUBLISH_TO publishTo, EntityInterface entity, EntityLink link, Object oldValue, Object newValue) { + public static String handleIngestionPipelineResult(PublishTo publishTo, EntityInterface entity, Object newValue) { String ingestionPipelineName = entity.getName(); PipelineStatus status = (PipelineStatus) newValue; if (status != null) { @@ -712,11 +707,9 @@ public final class ChangeEventParser { } } - public static String handleKpiResult( - PUBLISH_TO publishTo, EntityInterface entity, EntityLink link, Object oldValue, Object newValue) { + public static String handleKpiResult(PublishTo publishTo, EntityInterface entity, Object newValue) { String kpiName = entity.getName(); KpiResult result = (KpiResult) newValue; - Kpi kpiEntity = (Kpi) entity; if (result != null) { String format = String.format( @@ -730,7 +723,7 @@ public final class ChangeEventParser { } } - public static String getPlaintextDiff(PUBLISH_TO publishTo, String oldValue, String newValue) { + public static String getPlaintextDiff(PublishTo publishTo, String oldValue, String newValue) { // create a configured DiffRowGenerator String addMarker = FEED_ADD_MARKER; String removeMarker = FEED_REMOVE_MARKER; diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/ChangeEventParserResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/ChangeEventParserResourceTest.java index f715579996d..ce9087013af 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/ChangeEventParserResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/ChangeEventParserResourceTest.java @@ -44,6 +44,7 @@ import org.openmetadata.service.OpenMetadataApplicationTest; import org.openmetadata.service.resources.databases.TableResourceTest; import org.openmetadata.service.resources.feeds.MessageParser.EntityLink; import org.openmetadata.service.util.ChangeEventParser; +import org.openmetadata.service.util.ChangeEventParser.PublishTo; import org.openmetadata.service.util.JsonUtils; @Slf4j @@ -69,8 +70,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { deleteTag.withName("tags").withOldValue("tag1"); changeDescription.withFieldsAdded(List.of(addTag)).withFieldsDeleted(List.of(deleteTag)).withPreviousVersion(1.0); - Map messages = - ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, TABLE); + Map messages = ChangeEventParser.getFormattedMessages(PublishTo.FEED, changeDescription, TABLE); assertEquals(1, messages.size()); TagLabel tag1 = new TagLabel(); @@ -83,7 +83,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { deleteTag.withOldValue(JsonUtils.pojoToJson(List.of(tag1))); Map jsonMessages = - ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, TABLE); + ChangeEventParser.getFormattedMessages(PublishTo.FEED, changeDescription, TABLE); assertEquals(1, jsonMessages.size()); // The entity links and values of both the messages should be the same @@ -98,8 +98,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { entityReference.withId(UUID.randomUUID()).withName("user1").withDisplayName("User One"); fieldAdded(changeDescription, FIELD_OWNER, JsonUtils.pojoToJson(entityReference)); - Map messages = - ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, TABLE); + Map messages = ChangeEventParser.getFormattedMessages(PublishTo.FEED, changeDescription, TABLE); assertEquals(1, messages.size()); assertEquals("Added **owner**: **User One**", messages.values().iterator().next()); @@ -111,12 +110,11 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { ChangeDescription changeDescription = new ChangeDescription(); fieldUpdated(changeDescription, "description", "old description", "new description"); - Map messages = - ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, TABLE); + Map messages = ChangeEventParser.getFormattedMessages(PublishTo.FEED, changeDescription, TABLE); assertEquals(1, messages.size()); assertEquals( - "Updated **description** : old " + "Updated **description**: old " + "new description", messages.values().iterator().next()); @@ -127,7 +125,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { // now test if both the type of updates give the same message Map updatedMessages = - ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, TABLE); + ChangeEventParser.getFormattedMessages(PublishTo.FEED, changeDescription, TABLE); assertEquals(1, updatedMessages.size()); assertEquals(messages.keySet().iterator().next(), updatedMessages.keySet().iterator().next()); @@ -141,10 +139,10 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { fieldUpdated(changeDescription, "description", "old description", "new description"); Map messages = - ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.SLACK, changeDescription, TABLE); + ChangeEventParser.getFormattedMessages(PublishTo.SLACK, changeDescription, TABLE); assertEquals(1, messages.size()); - assertEquals("Updated *description* : ~old~ *new* description", messages.values().iterator().next()); + assertEquals("Updated *description*: ~old~ *new* description", messages.values().iterator().next()); // test if it updates correctly with one add and one delete change changeDescription = new ChangeDescription().withPreviousVersion(1.0); @@ -153,7 +151,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { // now test if both the type of updates give the same message Map updatedMessages = - ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.SLACK, changeDescription, TABLE); + ChangeEventParser.getFormattedMessages(PublishTo.SLACK, changeDescription, TABLE); assertEquals(1, updatedMessages.size()); assertEquals(messages.keySet().iterator().next(), updatedMessages.keySet().iterator().next()); @@ -174,8 +172,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { "columns", "[{\"name\":\"lo_order\",\"displayName\":\"lo_order\",\"dataType\":\"INT\",\"dataLength\":1,\"dataTypeDisplay\":\"int\",\"fullyQualifiedName\":\"local_mysql.sample_db.lineorder.lo_order\",\"constraint\":\"NOT_NULL\"}]"); - Map messages = - ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, TABLE); + Map messages = ChangeEventParser.getFormattedMessages(PublishTo.FEED, changeDescription, TABLE); assertEquals(1, messages.size()); assertEquals( @@ -193,7 +190,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { "columns", "[{\"name\":\"lo_orderpriority\",\"displayName\":\"lo_orderpriority\",\"dataType\":\"BLOB\",\"dataLength\":1,\"dataTypeDisplay\":\"blob\",\"fullyQualifiedName\":\"local_mysql.sample_db.lineorder.lo_orderpriority\",\"tags\":[],\"constraint\":\"NOT_NULL\"}]"); - messages = ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, TABLE); + messages = ChangeEventParser.getFormattedMessages(PublishTo.FEED, changeDescription, TABLE); assertEquals(1, messages.size()); assertEquals( @@ -211,11 +208,11 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { "columns", "[{\"name\":\"lo_orderpriority\",\"displayName\":\"lo_orderpriority\",\"dataType\":\"BLOB\",\"dataLength\":1,\"dataTypeDisplay\":\"blob\",\"fullyQualifiedName\":\"local_mysql.sample_db.lineorder.lo_orderpriority\"}]"); - messages = ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, TABLE); + messages = ChangeEventParser.getFormattedMessages(PublishTo.FEED, changeDescription, TABLE); assertEquals(1, messages.size()); assertEquals( - "Updated **columns** : lo_orderpriority , newColumn", + "Updated **columns**: lo_orderpriority , newColumn", messages.values().iterator().next()); } @@ -234,7 +231,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { "[{\"name\":\"lo_order\",\"displayName\":\"lo_order\",\"dataType\":\"INT\",\"dataLength\":1,\"dataTypeDisplay\":\"int\",\"fullyQualifiedName\":\"local_mysql.sample_db.lineorder.lo_order\",\"constraint\":\"NOT_NULL\"}]"); Map messages = - ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.SLACK, changeDescription, TABLE); + ChangeEventParser.getFormattedMessages(PublishTo.SLACK, changeDescription, TABLE); assertEquals(1, messages.size()); assertEquals( @@ -255,7 +252,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { "columns", "[{\"name\":\"lo_orderpriority\",\"displayName\":\"lo_orderpriority\",\"dataType\":\"BLOB\",\"dataLength\":1,\"dataTypeDisplay\":\"blob\",\"fullyQualifiedName\":\"local_mysql.sample_db.lineorder.lo_orderpriority\",\"tags\":[],\"constraint\":\"NOT_NULL\"}]"); - messages = ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.SLACK, changeDescription, TABLE); + messages = ChangeEventParser.getFormattedMessages(PublishTo.SLACK, changeDescription, TABLE); assertEquals(1, messages.size()); assertEquals( @@ -275,9 +272,9 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest { "columns", "[{\"name\":\"lo_orderpriority\",\"displayName\":\"lo_orderpriority\",\"dataType\":\"BLOB\",\"dataLength\":1,\"dataTypeDisplay\":\"blob\",\"fullyQualifiedName\":\"local_mysql.sample_db.lineorder.lo_orderpriority\"}]"); - messages = ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.SLACK, changeDescription, TABLE); + messages = ChangeEventParser.getFormattedMessages(PublishTo.SLACK, changeDescription, TABLE); assertEquals(1, messages.size()); - assertEquals("Updated *columns* : lo_orderpriority *, newColumn*", messages.values().iterator().next()); + assertEquals("Updated *columns*: lo_orderpriority *, newColumn*", messages.values().iterator().next()); } } diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/FeedResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/FeedResourceTest.java index 38032d43dc6..4fd8cbe84c5 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/FeedResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/feeds/FeedResourceTest.java @@ -107,7 +107,7 @@ import org.openmetadata.service.resources.feeds.FeedResource.PostList; import org.openmetadata.service.resources.feeds.FeedResource.ThreadList; import org.openmetadata.service.resources.teams.TeamResourceTest; import org.openmetadata.service.resources.teams.UserResourceTest; -import org.openmetadata.service.util.ChangeEventParser; +import org.openmetadata.service.util.ChangeEventParser.PublishTo; import org.openmetadata.service.util.EntityUtil; import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.TestUtils; @@ -599,7 +599,7 @@ public class FeedResourceTest extends OpenMetadataApplicationTest { assertEquals(TaskStatus.Closed, task.getStatus()); assertEquals(1, taskThread.getPostsCount()); assertEquals(1, taskThread.getPosts().size()); - String diff = getPlaintextDiff(ChangeEventParser.PUBLISH_TO.FEED, "old description", "accepted description"); + String diff = getPlaintextDiff(PublishTo.FEED, "old description", "accepted description"); String expectedMessage = String.format("Resolved the Task with Description - %s", diff); assertEquals(expectedMessage, taskThread.getPosts().get(0).getMessage()); } @@ -687,7 +687,7 @@ public class FeedResourceTest extends OpenMetadataApplicationTest { assertEquals(TaskStatus.Closed, task.getStatus()); assertEquals(1, taskThread.getPostsCount()); assertEquals(1, taskThread.getPosts().size()); - String diff = getPlaintextDiff(ChangeEventParser.PUBLISH_TO.FEED, "", USER_ADDRESS_TAG_LABEL.getTagFQN()); + String diff = getPlaintextDiff(PublishTo.FEED, "", USER_ADDRESS_TAG_LABEL.getTagFQN()); String expectedMessage = String.format("Resolved the Task with Tag(s) - %s", diff); assertEquals(expectedMessage, taskThread.getPosts().get(0).getMessage()); }