1   /*
2    * Copyright 2023 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package com.linecorp.centraldogma.server.command;
18  
19  import static java.util.Objects.requireNonNull;
20  
21  import com.fasterxml.jackson.annotation.JsonCreator;
22  import com.fasterxml.jackson.annotation.JsonProperty;
23  import com.google.common.base.MoreObjects.ToStringHelper;
24  
25  /**
26   * A {@link Command} which is used to force-push {@code delegate} even the server is in read-only mode.
27   * This command is useful for migrating the repository content during maintenance mode.
28   */
29  public final class ForcePushCommand<T> extends AdministrativeCommand<T> {
30  
31      private final Command<T> delegate;
32  
33      @JsonCreator
34      ForcePushCommand(@JsonProperty("delegate") Command<T> delegate) {
35          super(CommandType.FORCE_PUSH, requireNonNull(delegate, "delegate").timestamp(), delegate.author());
36          this.delegate = delegate;
37      }
38  
39      /**
40       * Returns the {@link Command} to be force-pushed.
41       */
42      @JsonProperty("delegate")
43      public Command<T> delegate() {
44          return delegate;
45      }
46  
47      @Override
48      public boolean equals(Object o) {
49          if (this == o) {
50              return true;
51          }
52          if (!(o instanceof ForcePushCommand)) {
53              return false;
54          }
55          final ForcePushCommand<?> that = (ForcePushCommand<?>) o;
56          return super.equals(that) && delegate.equals(that.delegate);
57      }
58  
59      @Override
60      public int hashCode() {
61          return super.hashCode() * 31 + delegate.hashCode();
62      }
63  
64      @Override
65      ToStringHelper toStringHelper() {
66          return super.toStringHelper().add("delegate", delegate);
67      }
68  }