Skip to content

Commit

Permalink
Fix Charts Tasks for description update (#14456)
Browse files Browse the repository at this point in the history
* Fix Charts Tasks for description update

* Fix Charts Tasks for description update
  • Loading branch information
mohityadav766 authored Dec 21, 2023
1 parent c9a00f3 commit 417e352
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.openmetadata.schema.type.Include.ALL;
import static org.openmetadata.service.Entity.DASHBOARD;
import static org.openmetadata.service.Entity.FIELD_DESCRIPTION;
import static org.openmetadata.service.Entity.FIELD_TAGS;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -68,19 +69,19 @@ public TaskWorkflow getTaskWorkflow(ThreadContext threadContext) {
EntityLink entityLink = threadContext.getAbout();
if (entityLink.getFieldName().equals("charts")) {
TaskType taskType = threadContext.getThread().getTask().getType();
if (!entityLink.getFieldName().equals(FIELD_DESCRIPTION)) {
// Only description field can be updated
throw new IllegalArgumentException(
CatalogExceptionMessage.invalidFieldForTask(entityLink.getFieldName(), taskType));
if (entityLink.getArrayFieldValue() != null) {
return new ChartDescriptionAndTagTaskWorkflow(threadContext);
}
return new ChartDescriptionTaskWorkflow(threadContext);
throw new IllegalArgumentException(
CatalogExceptionMessage.invalidFieldForTask(entityLink.getFieldName(), taskType));
}
return super.getTaskWorkflow(threadContext);
}

static class ChartDescriptionTaskWorkflow extends DescriptionTaskWorkflow {
ChartDescriptionTaskWorkflow(ThreadContext threadContext) {
static class ChartDescriptionAndTagTaskWorkflow extends DescriptionTaskWorkflow {
ChartDescriptionAndTagTaskWorkflow(ThreadContext threadContext) {
super(threadContext);
EntityLink entityLink = threadContext.getAbout();
Dashboard dashboard =
Entity.getEntity(DASHBOARD, threadContext.getAboutEntity().getId(), "charts", ALL);
String chartName = threadContext.getAbout().getArrayFieldName();
Expand All @@ -93,6 +94,14 @@ static class ChartDescriptionTaskWorkflow extends DescriptionTaskWorkflow {
new IllegalArgumentException(
CatalogExceptionMessage.invalidFieldName("chart", chartName)));
Chart chart = Entity.getEntity(chartReference, "", ALL);
if (entityLink.getArrayFieldValue().equals(FIELD_DESCRIPTION)) {
threadContext.setAbout(
new EntityLink(
Entity.CHART, chart.getFullyQualifiedName(), FIELD_DESCRIPTION, null, null));
} else if (entityLink.getArrayFieldValue().equals(FIELD_TAGS)) {
threadContext.setAbout(
new EntityLink(Entity.CHART, chart.getFullyQualifiedName(), FIELD_TAGS, null, null));
}
threadContext.setAboutEntity(chart);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public int getNextTaskId() {

public static class ThreadContext {
@Getter protected final Thread thread;
@Getter protected final EntityLink about;
@Getter @Setter protected EntityLink about;
@Getter @Setter protected EntityInterface aboutEntity;
@Getter private final EntityReference createdBy;

Expand Down

0 comments on commit 417e352

Please sign in to comment.