Skip to content

Commit

Permalink
Adopt Java 17 features (#14430)
Browse files Browse the repository at this point in the history
* Adopt Java 17 features

* Make the code comments compact
  • Loading branch information
sureshms authored Dec 19, 2023
1 parent 1294f93 commit 451a20b
Show file tree
Hide file tree
Showing 77 changed files with 664 additions and 1,164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ public void run(OpenMetadataApplicationConfig catalogConfig, Environment environ
Entity.setCollectionDAO(collectionDAO);

// initialize Search Repository, all repositories use SearchRepository this line should always
// before initializing
// repository
// before initializing repository
new SearchRepository(catalogConfig.getElasticSearchConfiguration(), new SearchIndexFactory());
// as first step register all the repositories
Entity.initializeRepositories(catalogConfig, jdbi);
Expand Down Expand Up @@ -423,15 +422,11 @@ private void registerAuthenticator(OpenMetadataApplicationConfig catalogConfig)
AuthenticationConfiguration authenticationConfiguration =
catalogConfig.getAuthenticationConfiguration();
switch (authenticationConfiguration.getProvider()) {
case BASIC:
authenticatorHandler = new BasicAuthenticator();
break;
case LDAP:
authenticatorHandler = new LdapAuthenticator();
break;
default:
// For all other types, google, okta etc. auth is handled externally
authenticatorHandler = new NoopAuthenticator();
case BASIC -> authenticatorHandler = new BasicAuthenticator();
case LDAP -> authenticatorHandler = new LdapAuthenticator();
default ->
// For all other types, google, okta etc. auth is handled externally
authenticatorHandler = new NoopAuthenticator();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ public Void process(
try {
EntityReference entityReference;
// TODO: EntityInterface and EntityTimeSeriesInterface share some common implementation and
// diverge
// at the edge (e.g. EntityTimeSeriesInterface does not expect owners, etc.). We should
// implement
// a parent class that captures the common fields and then have EntityInterface and
// EntityTimeSeriesInterface
// extend it.
if (responseContext.getEntity() instanceof EntityTimeSeriesInterface) {
EntityTimeSeriesInterface entityTimeSeriesInterface =
(EntityTimeSeriesInterface) responseContext.getEntity();
// diverge at the edge (e.g. EntityTimeSeriesInterface does not expect owners, etc.).
// We should implement a parent class that captures the common fields and then have
// EntityInterface and EntityTimeSeriesInterface extend it.
if (responseContext.getEntity()
instanceof EntityTimeSeriesInterface entityTimeSeriesInterface) {
entityReference = entityTimeSeriesInterface.getEntityReference();
} else {
entityReference = ((EntityInterface) responseContext.getEntity()).getEntityReference();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,23 @@ public DataInsightDescriptionAndOwnerTemplate(
}

private String getMetricTypeMessage(MetricType metricType) {
switch (metricType) {
case DESCRIPTION:
return "<strong>Completed Description</strong>";
case OWNER:
return "<strong>Assigned Ownership</strong>";
case TIER:
return "<strong>Assets Assigned with Tiers</strong>";
}
return "";
return switch (metricType) {
case DESCRIPTION -> "<strong>Completed Description</strong>";
case OWNER -> "<strong>Assigned Ownership</strong>";
case TIER -> "<strong>Assets Assigned with Tiers</strong>";
};
}

private String getKpiCriteriaMessage(MetricType metricType, KpiCriteria criteria) {
if (metricType != MetricType.TIER) {
if (kpiAvailable) {
switch (criteria) {
case MET:
return "Great the Target Set for KPIs has been achieved. It's time to restructure your goals, set new KPIs and progress faster.";
case IN_PROGRESS:
return String.format(
"To meet the KPIs you will need a minimum of %s per cent completed description in the next %s days.",
targetKpi, numberOfDaysLeft);
case NOT_MET:
return "The Target set for KPIs was not met it’s time to restructure your goals and progress faster.";
}
return switch (criteria) {
case MET -> "Great the Target Set for KPIs has been achieved. It's time to restructure your goals, set new KPIs and progress faster.";
case IN_PROGRESS -> String.format(
"To meet the KPIs you will need a minimum of %s per cent completed description in the next %s days.",
targetKpi, numberOfDaysLeft);
case NOT_MET -> "The Target set for KPIs was not met it’s time to restructure your goals and progress faster.";
};
}
return "You have not set any KPIS yet, it’s time to restructure your goals, set KPIs and progress faster.";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import javax.annotation.CheckForNull;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.openmetadata.schema.entity.events.EventSubscription;
import org.openmetadata.schema.type.Include;
Expand Down Expand Up @@ -36,7 +37,7 @@ public static EventSubscription getActivityFeedAlert() {

static class ActivityFeedAlertLoader extends CacheLoader<String, EventSubscription> {
@Override
public EventSubscription load(@CheckForNull String alertName) {
public @NonNull EventSubscription load(@CheckForNull String alertName) {
EventSubscription alert =
Entity.getEntityByName(Entity.EVENT_SUBSCRIPTION, alertName, "*", Include.NON_DELETED);
LOG.debug("Loaded Alert {}", alert);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,16 @@ private AlertUtil() {}
public static SubscriptionPublisher getNotificationsPublisher(
EventSubscription subscription, CollectionDAO daoCollection) {
validateSubscriptionConfig(subscription);
SubscriptionPublisher publisher;
switch (subscription.getSubscriptionType()) {
case SLACK_WEBHOOK:
publisher = new SlackEventPublisher(subscription, daoCollection);
break;
case MS_TEAMS_WEBHOOK:
publisher = new MSTeamsPublisher(subscription, daoCollection);
break;
case G_CHAT_WEBHOOK:
publisher = new GChatPublisher(subscription, daoCollection);
break;
case GENERIC_WEBHOOK:
publisher = new GenericPublisher(subscription, daoCollection);
break;
case EMAIL:
publisher = new EmailPublisher(subscription, daoCollection);
break;
case ACTIVITY_FEED:
throw new IllegalArgumentException("Cannot create Activity Feed as Publisher.");
default:
throw new IllegalArgumentException("Invalid Alert Action Specified.");
}
return publisher;
return switch (subscription.getSubscriptionType()) {
case SLACK_WEBHOOK -> new SlackEventPublisher(subscription, daoCollection);
case MS_TEAMS_WEBHOOK -> new MSTeamsPublisher(subscription, daoCollection);
case G_CHAT_WEBHOOK -> new GChatPublisher(subscription, daoCollection);
case GENERIC_WEBHOOK -> new GenericPublisher(subscription, daoCollection);
case EMAIL -> new EmailPublisher(subscription, daoCollection);
case ACTIVITY_FEED -> throw new IllegalArgumentException(
"Cannot create Activity Feed as Publisher.");
default -> throw new IllegalArgumentException("Invalid Alert Action Specified.");
};
}

public static void validateSubscriptionConfig(EventSubscription eventSubscription) {
Expand Down Expand Up @@ -119,39 +106,30 @@ public static Map<String, Function> getAlertFilterFunctions() {
SubscriptionFilterOperation type = SubscriptionFilterOperation.valueOf(func.getName());
ParamAdditionalContext paramAdditionalContext = new ParamAdditionalContext();
switch (type) {
case matchAnySource:
func.setParamAdditionalContext(
paramAdditionalContext.withData(new HashSet<>(Entity.getEntityList())));
break;
case matchUpdatedBy:
case matchAnyOwnerName:
func.setParamAdditionalContext(
paramAdditionalContext.withData(getEntitiesIndex(List.of(USER, TEAM))));
break;
case matchAnyEntityFqn:
case matchAnyEntityId:
func.setParamAdditionalContext(
paramAdditionalContext.withData(getEntitiesIndex(Entity.getEntityList())));
break;
case matchAnyEventType:
case matchAnySource -> func.setParamAdditionalContext(
paramAdditionalContext.withData(new HashSet<>(Entity.getEntityList())));
case matchUpdatedBy, matchAnyOwnerName -> func.setParamAdditionalContext(
paramAdditionalContext.withData(getEntitiesIndex(List.of(USER, TEAM))));
case matchAnyEntityFqn, matchAnyEntityId -> func.setParamAdditionalContext(
paramAdditionalContext.withData(getEntitiesIndex(Entity.getEntityList())));
case matchAnyEventType -> {
List<String> eventTypes = Stream.of(EventType.values()).map(EventType::value).toList();
func.setParamAdditionalContext(
paramAdditionalContext.withData(new HashSet<>(eventTypes)));
break;
case matchIngestionPipelineState:
}
case matchIngestionPipelineState -> {
List<String> ingestionPipelineState =
Stream.of(PipelineStatusType.values()).map(PipelineStatusType::value).toList();
func.setParamAdditionalContext(
paramAdditionalContext.withData(new HashSet<>(ingestionPipelineState)));
break;
case matchTestResult:
}
case matchTestResult -> {
List<String> testResultStatus =
Stream.of(TestCaseStatus.values()).map(TestCaseStatus::value).toList();
func.setParamAdditionalContext(
paramAdditionalContext.withData(new HashSet<>(testResultStatus)));
break;
default:
LOG.error("Invalid Function name : {}", type);
}
default -> LOG.error("Invalid Function name : {}", type);
}
alertFunctions.put(func.getName(), func);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,10 @@ private String transformTestCaseResult(
}

private String getStatusMessage(TestCaseStatus status) {
switch (status) {
case Success:
return "<span style=\"color:#48CA9E\">Passed</span>";
case Failed:
return "<span style=\"color:#F24822\">Failed</span>";
case Aborted:
return "<span style=\"color:#FFBE0E\">Aborted</span>";
}
return status.value();
return switch (status) {
case Success -> "<span style=\"color:#48CA9E\">Passed</span>";
case Failed -> "<span style=\"color:#F24822\">Failed</span>";
case Aborted -> "<span style=\"color:#FFBE0E\">Aborted</span>";
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ public final class ParserFactory {
private ParserFactory() {}

public static EntityFormatter getEntityParser(String entityType) {
switch (entityType) {
case Entity.QUERY:
return new QueryFormatter();
case Entity.TEST_CASE:
return new TestCaseFormatter();
case Entity.KPI:
return new KpiFormatter();
case Entity.INGESTION_PIPELINE:
return new IngestionPipelineFormatter();
default:
return new DefaultEntityFormatter();
}
return switch (entityType) {
case Entity.QUERY -> new QueryFormatter();
case Entity.TEST_CASE -> new TestCaseFormatter();
case Entity.KPI -> new KpiFormatter();
case Entity.INGESTION_PIPELINE -> new IngestionPipelineFormatter();
default -> new DefaultEntityFormatter();
};
}

public static DefaultFieldFormatter getFieldParserObject(
Expand All @@ -51,19 +46,15 @@ public static DefaultFieldFormatter getFieldParserObject(
String fieldNewValue,
String fieldChangeName,
MessageParser.EntityLink entityLink) {
switch (fieldChangeName) {
case Entity.FIELD_TAGS:
return new TagFormatter(
decorator, fieldOldValue, fieldNewValue, fieldChangeName, entityLink);
case Entity.FIELD_FOLLOWERS:
return new FollowersFormatter(
decorator, fieldOldValue, fieldNewValue, fieldChangeName, entityLink);
case Entity.FIELD_OWNER:
return new OwnerFormatter(
decorator, fieldOldValue, fieldNewValue, fieldChangeName, entityLink);
default:
return new DefaultFieldFormatter(
decorator, fieldOldValue, fieldNewValue, fieldChangeName, entityLink);
}
return switch (fieldChangeName) {
case Entity.FIELD_TAGS -> new TagFormatter(
decorator, fieldOldValue, fieldNewValue, fieldChangeName, entityLink);
case Entity.FIELD_FOLLOWERS -> new FollowersFormatter(
decorator, fieldOldValue, fieldNewValue, fieldChangeName, entityLink);
case Entity.FIELD_OWNER -> new OwnerFormatter(
decorator, fieldOldValue, fieldNewValue, fieldChangeName, entityLink);
default -> new DefaultFieldFormatter(
decorator, fieldOldValue, fieldNewValue, fieldChangeName, entityLink);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,9 @@ public String getFieldNewValue() {
public String getFormattedMessage(FormatterUtil.CHANGE_TYPE changeType) {
String message = "";
switch (changeType) {
case ADD:
message = formatAddedField();
break;
case UPDATE:
message = formatUpdatedField();
break;
case DELETE:
message = formatDeletedField();
break;
default:
break;
case ADD -> message = formatAddedField();
case UPDATE -> message = formatUpdatedField();
case DELETE -> message = formatDeletedField();
}
return message;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,14 @@ public static ChangeEvent getChangeEventFromResponseContext(
if (changeType != null && changeType.equals(RestUtil.ENTITY_FIELDS_CHANGED)) {
changeEvent = (ChangeEvent) responseContext.getEntity();
} else if (responseContext.getEntity() != null
&& responseContext.getEntity() instanceof EntityInterface) {
EntityInterface entityInterface = (EntityInterface) responseContext.getEntity();
&& responseContext.getEntity() instanceof EntityInterface entityInterface) {
EntityReference entityReference = entityInterface.getEntityReference();
String entityType = entityReference.getType();
String entityFQN = entityReference.getFullyQualifiedName();
EventType eventType = changeType != null ? EventType.fromValue(changeType) : null;

// Entity was created by either POST .../entities or PUT .../entities
if (responseCode == Response.Status.CREATED.getStatusCode()
&& !RestUtil.ENTITY_FIELDS_CHANGED.equals(changeType)
&& !responseContext.getEntity().getClass().equals(Thread.class)) {
changeEvent =
getChangeEvent(updateBy, EventType.ENTITY_CREATED, entityType, entityInterface)
Expand Down
Loading

0 comments on commit 451a20b

Please sign in to comment.