diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DashboardServiceRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DashboardServiceRepository.java index a6685f4d67a..2e4464ac750 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DashboardServiceRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DashboardServiceRepository.java @@ -25,9 +25,8 @@ import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.type.Schedule; import org.openmetadata.catalog.type.TagLabel; import org.openmetadata.catalog.util.EntityInterface; -import org.openmetadata.catalog.util.EntityUtil.Fields; +import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.JsonUtils; -import org.openmetadata.catalog.util.Utils; import java.io.IOException; import java.net.URI; @@ -50,7 +49,7 @@ public class DashboardServiceRepository extends EntityRepository public DatabaseService update(UUID id, String description, JdbcInfo jdbc, Schedule ingestionSchedule) throws IOException { - Utils.validateIngestionSchedule(ingestionSchedule); + EntityUtil.validateIngestionSchedule(ingestionSchedule); DatabaseService dbService = dao.dbServiceDAO().findEntityById(id); // Update fields dbService.withDescription(description).withJdbc((jdbc)).withIngestionSchedule(ingestionSchedule); @@ -84,7 +83,7 @@ public class DatabaseServiceRepository extends EntityRepository @Override public void validate(DatabaseService entity) throws IOException { - Utils.validateIngestionSchedule(entity.getIngestionSchedule()); + EntityUtil.validateIngestionSchedule(entity.getIngestionSchedule()); } @Override diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MessagingServiceRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MessagingServiceRepository.java index 5ac6c8bc050..cff7b384785 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MessagingServiceRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MessagingServiceRepository.java @@ -25,9 +25,8 @@ import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.type.Schedule; import org.openmetadata.catalog.type.TagLabel; import org.openmetadata.catalog.util.EntityInterface; -import org.openmetadata.catalog.util.EntityUtil.Fields; +import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.JsonUtils; -import org.openmetadata.catalog.util.Utils; import java.io.IOException; import java.net.URI; @@ -50,7 +49,7 @@ public class MessagingServiceRepository extends EntityRepository brokers, URI schemaRegistry, Schedule ingestionSchedule) throws IOException { - Utils.validateIngestionSchedule(ingestionSchedule); + EntityUtil.validateIngestionSchedule(ingestionSchedule); MessagingService dbService = dao.messagingServiceDAO().findEntityById(id); // Update fields dbService.withDescription(description).withIngestionSchedule(ingestionSchedule) @@ -85,7 +84,7 @@ public class MessagingServiceRepository extends EntityRepository public PipelineService update(UUID id, String description, URI url, Schedule ingestionSchedule) throws IOException { - Utils.validateIngestionSchedule(ingestionSchedule); + EntityUtil.validateIngestionSchedule(ingestionSchedule); PipelineService pipelineService = dao.pipelineServiceDAO().findEntityById(id); // Update fields pipelineService.withDescription(description).withIngestionSchedule(ingestionSchedule) @@ -86,7 +85,7 @@ public class PipelineServiceRepository extends EntityRepository @Override public void validate(PipelineService entity) throws IOException { - Utils.validateIngestionSchedule(entity.getIngestionSchedule()); + EntityUtil.validateIngestionSchedule(entity.getIngestionSchedule()); } @Override diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/EntityUtil.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/EntityUtil.java index 7351c087dca..30e726d2ced 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/EntityUtil.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/EntityUtil.java @@ -72,6 +72,34 @@ public final class EntityUtil { } + /** + * Validate Ingestion Schedule + */ + public static void validateIngestionSchedule(Schedule ingestion) { + if (ingestion == null) { + return; + } + String duration = ingestion.getRepeatFrequency(); + + // ISO8601 duration format is P{y}Y{m}M{d}DT{h}H{m}M{s}S. + String[] splits = duration.split("T"); + if (splits[0].contains("Y") || splits[0].contains("M") || + (splits.length == 2 && splits[1].contains("S"))) { + throw new IllegalArgumentException("Ingestion repeatFrequency can only contain Days, Hours, and Minutes - " + + "example P{d}DT{h}H{m}M"); + } + + Period period; + try { + period = ISOPeriodFormat.standard().parsePeriod(duration); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("Invalid ingestion repeatFrequency " + duration, e); + } + if (period.toStandardMinutes().getMinutes() < 60) { + throw new IllegalArgumentException("Ingestion repeatFrequency is too short and must be more than 60 minutes"); + } + } + /** * Validate that JSON payload can be turned into POJO object */ diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/Utils.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/Utils.java deleted file mode 100644 index 328e1e568b6..00000000000 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/Utils.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openmetadata.catalog.util; - -import org.joda.time.Period; -import org.joda.time.format.ISOPeriodFormat; -import org.openmetadata.catalog.type.Schedule; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class Utils { - private static final Logger LOG = LoggerFactory.getLogger(Utils.class); - - private Utils() {} - - public static void validateIngestionSchedule(Schedule ingestion) { - if (ingestion == null) { - return; - } - String duration = ingestion.getRepeatFrequency(); - - // ISO8601 duration format is P{y}Y{m}M{d}DT{h}H{m}M{s}S. - String[] splits = duration.split("T"); - if (splits[0].contains("Y") || splits[0].contains("M") || - (splits.length == 2 && splits[1].contains("S"))) { - throw new IllegalArgumentException("Ingestion repeatFrequency can only contain Days, Hours, and Minutes - " + - "example P{d}DT{h}H{m}M"); - } - - Period period; - try { - period = ISOPeriodFormat.standard().parsePeriod(duration); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("Invalid ingestion repeatFrequency " + duration, e); - } - if (period.toStandardMinutes().getMinutes() < 60) { - throw new IllegalArgumentException("Ingestion repeatFrequency is too short and must be more than 60 minutes"); - } - } - -}