Skip to content

Commit

Permalink
Code cleanup (open-metadata#14030)
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshms authored Nov 20, 2023
1 parent c4d6f68 commit c788100
Show file tree
Hide file tree
Showing 71 changed files with 153 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public static void addResource(
ResourceDescriptor resourceDescriptor =
new ResourceDescriptor()
.withName(resourceName)
.withOperations(getOperations(resourceName, entitySpecificOperations, new ArrayList<>(entityFields)));
.withOperations(getOperations(entitySpecificOperations, new ArrayList<>(entityFields)));
RESOURCE_DESCRIPTORS.sort(Comparator.comparing(ResourceDescriptor::getName));
RESOURCE_DESCRIPTORS.add(resourceDescriptor);
}

private static List<MetadataOperation> getOperations(
String resourceName, List<MetadataOperation> entitySpecificOperations, List<String> entityFields) {
List<MetadataOperation> entitySpecificOperations, List<String> entityFields) {
Set<MetadataOperation> operations = new TreeSet<>(COMMON_OPERATIONS);
if (!nullOrEmpty(entitySpecificOperations)) {
operations.addAll(entitySpecificOperations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ public static AppRuntime getAppRuntime(App app) {
return JsonUtils.convertValue(app.getRuntime(), ScheduledExecutionContext.class);
}

protected IngestionPipeline getIngestionPipeline(CreateIngestionPipeline create, String botname, String user) {
protected IngestionPipeline getIngestionPipeline(CreateIngestionPipeline create, String botName, String user) {
IngestionPipelineRepository ingestionPipelineRepository =
(IngestionPipelineRepository) Entity.getEntityRepository(Entity.INGESTION_PIPELINE);
OpenMetadataConnection openMetadataServerConnection =
new OpenMetadataConnectionBuilder(ingestionPipelineRepository.getOpenMetadataApplicationConfig(), botname)
new OpenMetadataConnectionBuilder(ingestionPipelineRepository.getOpenMetadataApplicationConfig(), botName)
.build();
return ingestionPipelineRepository
.copy(new IngestionPipeline(), create, user)
Expand All @@ -224,8 +224,8 @@ protected AppRunRecord getJobRecord(JobExecutionContext jobExecutionContext) {
}

@SneakyThrows
protected void pushAppStausUpdates(JobExecutionContext jobExecutionContext, AppRunRecord record, boolean update) {
protected void pushAppStatusUpdates(JobExecutionContext jobExecutionContext, AppRunRecord appRecord, boolean update) {
OmAppJobListener listener = getJobListener(jobExecutionContext);
listener.pushApplicationStatusUpdates(jobExecutionContext, record, update);
listener.pushApplicationStatusUpdates(jobExecutionContext, appRecord, update);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void updateRecordToDb(JobExecutionContext jobExecutionContext) {
appRecord.setSuccessContext(new SuccessContext().withAdditionalProperty("stats", jobData.getStats()));
}

pushAppStausUpdates(jobExecutionContext, appRecord, true);
pushAppStatusUpdates(jobExecutionContext, appRecord, true);
}

private void entitiesReIndex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ public void pushApplicationStatusUpdates(JobExecutionContext context, AppRunReco
}
}

private void updateStatus(UUID appId, AppRunRecord record, boolean update) {
private void updateStatus(UUID appId, AppRunRecord appRunRecord, boolean update) {
if (update) {
collectionDAO
.appExtensionTimeSeriesDao()
.update(appId.toString(), JsonUtils.pojoToJson(record), record.getTimestamp());
.update(appId.toString(), JsonUtils.pojoToJson(appRunRecord), appRunRecord.getTimestamp());
} else {
collectionDAO.appExtensionTimeSeriesDao().insert(JsonUtils.pojoToJson(record));
collectionDAO.appExtensionTimeSeriesDao().insert(JsonUtils.pojoToJson(appRunRecord));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public abstract class AggregatedUnusedAssetsCountAggregator<A, H, B, S> implements DataInsightAggregatorInterface {
private final A aggregations;

public AggregatedUnusedAssetsCountAggregator(A aggregations) {
protected AggregatedUnusedAssetsCountAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public abstract class AggregatedUnusedAssetsSizeAggregator<A, H, B, S> implements DataInsightAggregatorInterface {
private final A aggregations;

public AggregatedUnusedAssetsSizeAggregator(A aggregations) {
protected AggregatedUnusedAssetsSizeAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class AggregatedUsedvsUnusedAssetsCountAggregator<A, H, B, S>
implements DataInsightAggregatorInterface {
private final A aggregations;

public AggregatedUsedvsUnusedAssetsCountAggregator(A aggregations) {
protected AggregatedUsedvsUnusedAssetsCountAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand All @@ -26,8 +26,8 @@ public List<Object> aggregate() throws ParseException {
Double used = Objects.requireNonNullElse(getValue(totalUsed), 0.0);
Double unused = Objects.requireNonNullElse(getValue(totalUnused), 0.0);
Double total = used + unused;
Double usedPercentage = 0.0;
Double unusedPercentage = 0.0;
double usedPercentage = 0.0;
double unusedPercentage = 0.0;
if (total != 0.0) {
usedPercentage = used / total;
unusedPercentage = unused / total;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public abstract class AggregatedUsedvsUnusedAssetsSizeAggregator<A, H, B, S> implements DataInsightAggregatorInterface {
private final A aggregations;

public AggregatedUsedvsUnusedAssetsSizeAggregator(A aggregations) {
protected AggregatedUsedvsUnusedAssetsSizeAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand All @@ -25,8 +25,8 @@ public List<Object> aggregate() throws ParseException {
Double used = Objects.requireNonNullElse(getValue(totalUsed), 0.0);
Double unused = Objects.requireNonNullElse(getValue(totalUnused), 0.0);
Double total = used + unused;
Double usedPercentage = 0.0;
Double unusedPercentage = 0.0;
double usedPercentage = 0.0;
double unusedPercentage = 0.0;
if (total != 0.0) {
usedPercentage = used / total;
unusedPercentage = unused / total;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public abstract class EntitiesDescriptionAggregator<A, B, M, S> implements DataInsightAggregatorInterface {
private final A aggregations;

public EntitiesDescriptionAggregator(A aggregations) {
protected EntitiesDescriptionAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public abstract class EntitiesOwnerAggregator<A, B, M, S> implements DataInsightAggregatorInterface {
private final A aggregations;

public EntitiesOwnerAggregator(A aggregations) {
protected EntitiesOwnerAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public abstract class MostActiveUsersAggregator<A, B, M, S, X> implements DataInsightAggregatorInterface {
private final A aggregations;

public MostActiveUsersAggregator(A aggregations) {
protected MostActiveUsersAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public abstract class MostViewedEntitiesAggregator<A, B, M, S> implements DataInsightAggregatorInterface {
protected final A aggregations;

public MostViewedEntitiesAggregator(A aggregations) {
protected MostViewedEntitiesAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public abstract class ServicesDescriptionAggregator<A, B, M, S> implements DataInsightAggregatorInterface {
private final A aggregations;

public ServicesDescriptionAggregator(A aggregations) {
protected ServicesDescriptionAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public abstract class ServicesOwnerAggregator<A, B, M, S> implements DataInsightAggregatorInterface {
protected final A aggregations;

public ServicesOwnerAggregator(A aggregations) {
protected ServicesOwnerAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public abstract class TotalEntitiesAggregator<A, B, M, S> implements DataInsightAggregatorInterface {
private final A aggregations;

public TotalEntitiesAggregator(A aggregations) {
protected TotalEntitiesAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public abstract class TotalEntitiesByTierAggregator<A, B, M, S> implements DataInsightAggregatorInterface {
private final A aggregations;

public TotalEntitiesByTierAggregator(A aggregations) {
protected TotalEntitiesByTierAggregator(A aggregations) {
this.aggregations = aggregations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public abstract class UnusedAssetsAggregator<H extends Iterable<S>, S, T> implements DataInsightAggregatorInterface {
private final H hits;

public UnusedAssetsAggregator(H hits) {
protected UnusedAssetsAggregator(H hits) {
this.hits = hits;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PipelineServiceStatusJobHandler {
private final Integer healthCheckInterval;
private final Scheduler scheduler = new StdSchedulerFactory().getScheduler();

private static PipelineServiceStatusJobHandler INSTANCE;
private static PipelineServiceStatusJobHandler instance;

private PipelineServiceStatusJobHandler(PipelineServiceClientConfiguration config, String clusterName)
throws SchedulerException {
Expand All @@ -46,15 +46,14 @@ private PipelineServiceStatusJobHandler(PipelineServiceClientConfiguration confi
}

public static PipelineServiceStatusJobHandler create(PipelineServiceClientConfiguration config, String clusterName) {
if (INSTANCE != null) return INSTANCE;
if (instance != null) return instance;

try {
INSTANCE = new PipelineServiceStatusJobHandler(config, clusterName);
instance = new PipelineServiceStatusJobHandler(config, clusterName);
} catch (Exception ex) {
LOG.error("Failed to initialize the Pipeline Service Status Handler");
}

return INSTANCE;
return instance;
}

private JobDetail jobBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ public static void validateSubscriptionConfig(EventSubscription eventSubscriptio
}
}

public static <T> T validateExpression(String condition, Class<T> clz) {
public static <T> void validateExpression(String condition, Class<T> clz) {
if (condition == null) {
return null;
return;
}
Expression expression = parseExpression(condition);
AlertsRuleEvaluator ruleEvaluator = new AlertsRuleEvaluator(null);
try {
return expression.getValue(ruleEvaluator, clz);
expression.getValue(ruleEvaluator, clz);
} catch (Exception exception) {
// Remove unnecessary class details in the exception message
String message = exception.getMessage().replaceAll("on type .*$", "").replaceAll("on object .*$", "");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

@Slf4j
public class AppRepository extends EntityRepository<App> {
public static String APP_BOT_ROLE = "ApplicationBotRole";
public static final String APP_BOT_ROLE = "ApplicationBotRole";

public static final String UPDATE_FIELDS = "appConfiguration,appSchedule";

Expand Down Expand Up @@ -199,8 +199,7 @@ public ResultList<AppRunRecord> listAppRuns(UUID appId, int limitParam, int offs
protected void cleanup(App app) {
// Remove the Pipelines for Application
List<EntityReference> pipelineRef = getIngestionPipelines(app);
pipelineRef.forEach(
(reference) -> Entity.deleteEntity("admin", reference.getType(), reference.getId(), true, true));
pipelineRef.forEach(reference -> Entity.deleteEntity("admin", reference.getType(), reference.getId(), true, true));
super.cleanup(app);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ public class EntityUpdater {
protected T previous;
protected T original;
protected T updated;
protected Operation operation;
protected final Operation operation;
protected ChangeDescription changeDescription = null;
protected boolean majorVersionChange = false;
protected final User updatingUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ protected void postDelete(GlossaryTerm entity) {
daoCollection.tagUsageDAO().deleteTagLabels(TagSource.GLOSSARY.ordinal(), entity.getFullyQualifiedName());
}

@Override
public TaskWorkflow getTaskWorkflow(ThreadContext threadContext) {
validateTaskThread(threadContext);
TaskType taskType = threadContext.getThread().getTask().getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ private String getTestSuiteTypeCondition() {

switch (testSuiteType) {
case ("executable"):
if (DatasourceConfig.getInstance().isMySQL()) {
if (Boolean.TRUE.equals(DatasourceConfig.getInstance().isMySQL())) {
return "(JSON_UNQUOTE(JSON_EXTRACT(json, '$.executable')) = 'true')";
}
return "(json->>'executable' = 'true')";
case ("logical"):
if (DatasourceConfig.getInstance().isMySQL()) {
if (Boolean.TRUE.equals(DatasourceConfig.getInstance().isMySQL())) {
return "(JSON_UNQUOTE(JSON_EXTRACT(json, '$.executable')) = 'false' OR JSON_UNQUOTE(JSON_EXTRACT(json, '$.executable')) IS NULL)";
}
return "(json->>'executable' = 'false' or json -> 'executable' is null)";
Expand All @@ -218,7 +218,7 @@ private String getWebhookTypePrefixCondition(String tableName, String typePrefix
private String getPipelineTypePrefixCondition(String tableName, String pipelineType) {
pipelineType = escape(pipelineType);
String inCondition = getInConditionFromString(pipelineType);
if (DatasourceConfig.getInstance().isMySQL()) {
if (Boolean.TRUE.equals(DatasourceConfig.getInstance().isMySQL())) {
return tableName == null
? String.format(
"JSON_UNQUOTE(JSON_EXTRACT(ingestion_pipeline_entity.json, '$.pipelineType')) IN (%s)", inCondition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void storeQueryUsedIn(
}
}

public RestUtil.PutResponse<?> AddQueryUser(
public RestUtil.PutResponse<?> addQueryUser(
UriInfo uriInfo, String updatedBy, UUID queryId, List<String> userFqnList) {
Query query = Entity.getEntity(Entity.QUERY, queryId, QUERY_USERS_FIELD, Include.NON_DELETED);
List<EntityReference> oldValue = query.getUsers();
Expand All @@ -146,7 +146,7 @@ public RestUtil.PutResponse<?> AddQueryUser(
return new RestUtil.PutResponse<>(Response.Status.CREATED, changeEvent, RestUtil.ENTITY_FIELDS_CHANGED);
}

public RestUtil.PutResponse<?> AddQueryUsedBy(
public RestUtil.PutResponse<?> addQueryUsedBy(
UriInfo uriInfo, String updatedBy, UUID queryId, List<String> userList) {
Query query = Entity.getEntity(Entity.QUERY, queryId, QUERY_UPDATE_FIELDS, Include.NON_DELETED);
Query oldQuery = JsonUtils.readValue(JsonUtils.pojoToJson(query), Query.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@
import org.openmetadata.schema.analytics.ReportData;
import org.openmetadata.schema.analytics.ReportData.ReportDataType;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.SearchRepository;
import org.openmetadata.service.util.JsonUtils;
import org.openmetadata.service.util.ResultList;

public class ReportDataRepository extends EntityTimeSeriesRepository<ReportData> {
public static final String COLLECTION_PATH = "/v1/analytics/report";
public static final String REPORT_DATA_EXTENSION = "reportData.reportDataResult";

private final SearchRepository searchRepository;

public ReportDataRepository() {
super(
COLLECTION_PATH,
Entity.getCollectionDAO().reportDataTimeSeriesDao(),
ReportData.class,
Entity.ENTITY_REPORT_DATA);
searchRepository = Entity.getSearchRepository();
}

public ResultList<ReportData> getReportData(ReportDataType reportDataType, Long startTs, Long endTs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ public RestUtil.DeleteResponse<TestCase> deleteTestCaseFromLogicalTestSuite(UUID
return new RestUtil.DeleteResponse<>(testCase, RestUtil.ENTITY_DELETED);
}

@Transaction
/** Remove test case from test suite summary and update test suite */
@Transaction
private void removeTestCaseFromTestSuiteResultSummary(UUID testSuiteId, String testCaseFqn) {
TestSuite testSuite = Entity.getEntity(TEST_SUITE, testSuiteId, "*", Include.ALL, false);
testSuite.setSummary(null); // we don't want to store the summary in the database
Expand Down
Loading

0 comments on commit c788100

Please sign in to comment.