roryqi commented on code in PR #13801:
URL: https://github.com/apache/gravitino/pull/13801#discussion_r4280640552


##########
api/src/main/java/org/apache/gravitino/policy/PolicyExecutionSpec.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * 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.apache.gravitino.policy;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Map;
+import java.util.Objects;
+import javax.annotation.Nullable;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * Immutable execution peer fields for executable policy contents: triggers, 
cooldown, and option
+ * bags.
+ *
+ * <p>JSON property names remain the flat peer keys on policy content ({@code 
timeTrigger}, {@code
+ * commitTrigger}, {@code minIntervalMs}, {@code jobOptions}, {@code 
updateOptions}). This type is
+ * the in-memory composition for {@link ExecutablePolicyContent}; persistence 
uses
+ * {@code @JsonUnwrapped} so those keys stay flat in stored policy content 
JSON.
+ */
+public final class PolicyExecutionSpec {
+
+  /** Spec with every peer unset. */
+  public static final PolicyExecutionSpec EMPTY =
+      new PolicyExecutionSpec(null, null, null, null, null);
+
+  @Nullable private final String timeTrigger;
+  @Nullable private final Boolean commitTrigger;
+  @Nullable private final Long minIntervalMs;
+  private final Map<String, String> jobOptions;
+  private final Map<String, String> updateOptions;
+
+  private PolicyExecutionSpec(
+      @Nullable String timeTrigger,
+      @Nullable Boolean commitTrigger,
+      @Nullable Long minIntervalMs,
+      @Nullable Map<String, String> jobOptions,
+      @Nullable Map<String, String> updateOptions) {
+    this.timeTrigger = StringUtils.isBlank(timeTrigger) ? null : timeTrigger;
+    this.commitTrigger = commitTrigger;
+    this.minIntervalMs = minIntervalMs;
+    this.jobOptions = PolicyExecutionFields.copyOptions(jobOptions);
+    this.updateOptions = PolicyExecutionFields.copyOptions(updateOptions);
+  }
+
+  /**
+   * Creates an immutable execution spec.
+   *
+   * <p>Annotated for Jackson so {@code POConverters} can rebuild executable 
policy content from
+   * stored JSON (including {@code @JsonUnwrapped} peers on {@link
+   * AbstractExecutablePolicyContent}).
+   *
+   * @param timeTrigger optional cron expression
+   * @param commitTrigger optional commit-trigger flag
+   * @param minIntervalMs optional cooldown ms
+   * @param jobOptions optional job options
+   * @param updateOptions optional update options
+   * @return immutable spec
+   */
+  @JsonCreator
+  public static PolicyExecutionSpec of(
+      @JsonProperty("timeTrigger") @Nullable String timeTrigger,
+      @JsonProperty("commitTrigger") @Nullable Boolean commitTrigger,
+      @JsonProperty("minIntervalMs") @Nullable Long minIntervalMs,
+      @JsonProperty("jobOptions") @Nullable Map<String, String> jobOptions,
+      @JsonProperty("updateOptions") @Nullable Map<String, String> 
updateOptions) {
+    if (!PolicyExecutionFields.hasAny(

Review Comment:
   `hasAny` treats `false` as unset, so `PolicyExecutionSpec.of(null, false, 
...)` returns `EMPTY` and changes `false` to `null`. But if any other peer is 
present, the same `false` is retained. This makes JSON round trips and 
`equals`/`hashCode` behavior depend on unrelated fields. Please either 
normalize `false` to `null` unconditionally, or treat every non-null `Boolean` 
as an explicitly supplied value.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to