Training Template with Object Builder
Change-Id: I9d5c778083767488baa8b4e4d9ab3b292b952ebf
diff --git a/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/TrainingTemplate.java b/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/TrainingTemplate.java
new file mode 100644
index 0000000..331f8bb
--- /dev/null
+++ b/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/TrainingTemplate.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2024-present Open Networking Foundation
+ *
+ * Licensed 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 aiplugin.api;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+import java.util.UUID;
+
+/**
+ * Represents a training template with all necessary configurations for model training.
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonDeserialize(builder = TrainingTemplate.Builder.class)
+public final class TrainingTemplate {
+
+ private final String templateVersion;
+ private final String type;
+ private final UUID id;
+ private final String datasource;
+ private final Selector selector;
+ private final Group group;
+ private final Sort sort;
+ private final Condition condition;
+ private final String window;
+ private final String horizon;
+ private final String target;
+
+ private TrainingTemplate(Builder builder) {
+ this.templateVersion = builder.templateVersion;
+ this.type = builder.type;
+ this.id = builder.id == null ? UUID.randomUUID() : builder.id;
+ this.datasource = builder.datasource;
+ this.selector = builder.selector;
+ this.group = builder.group;
+ this.sort = builder.sort;
+ this.condition = builder.condition;
+ this.window = builder.window;
+ this.horizon = builder.horizon;
+ this.target = builder.target;
+ }
+
+ /**
+ * Static method to create a new Builder instance.
+ *
+ * @return A new Builder for creating a TrainingTemplate instance.
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder class for Training Template.
+ */
+ @JsonPOJOBuilder(withPrefix = "")
+ public static class Builder {
+ private String templateVersion;
+ private String type;
+ private UUID id;
+ private String datasource;
+ private Selector selector;
+ private Group group;
+ private Sort sort;
+ private Condition condition;
+ private String window;
+ private String horizon;
+ private String target;
+
+ public Builder() {
+ }
+
+ /**
+ * Builds and returns the Training Template instance.
+ * This method ensures that all necessary fields are set and validates the template's state.
+ *
+ * @return the constructed TrainingTemplate instance.
+ * @throws NullPointerException if any required field is not set or invalid.
+ */
+ public TrainingTemplate build() {
+ Preconditions.checkNotNull(templateVersion, "Template version cannot be null");
+ Preconditions.checkNotNull(type, "Type cannot be null");
+ Preconditions.checkNotNull(target, "Target cannot be null");
+ Preconditions.checkNotNull(datasource, "Datasource cannot be null");
+ Preconditions.checkNotNull(selector, "Selector cannot be null");
+
+ return new TrainingTemplate(this);
+ }
+ }
+
+ /**
+ * Returns a string representation of the Training Template object. This includes all relevant fields
+ * of the template, providing a comprehensive overview of its state.
+ *
+ * @return A string representation of the Training Template object, including its fields and their values.
+ */
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("templateVersion", templateVersion)
+ .add("type", type)
+ .add("id", id)
+ .add("datasource", datasource)
+ .add("selector", selector)
+ .add("group", group)
+ .add("sort", sort)
+ .add("condition", condition)
+ .add("window", window)
+ .add("horizon", horizon)
+ .add("target", target)
+ .toString();
+ }
+}