DeleteSynonymRuleAction.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
  3. * or more contributor license agreements. Licensed under the "Elastic License
  4. * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
  5. * Public License v 1"; you may not use this file except in compliance with, at
  6. * your election, the "Elastic License 2.0", the "GNU Affero General Public
  7. * License v3.0 only", or the "Server Side Public License, v 1".
  8. */
  9. package org.elasticsearch.action.synonyms;
  10. import org.elasticsearch.TransportVersions;
  11. import org.elasticsearch.action.ActionRequestValidationException;
  12. import org.elasticsearch.action.ActionType;
  13. import org.elasticsearch.action.LegacyActionRequest;
  14. import org.elasticsearch.action.ValidateActions;
  15. import org.elasticsearch.common.Strings;
  16. import org.elasticsearch.common.io.stream.StreamInput;
  17. import org.elasticsearch.common.io.stream.StreamOutput;
  18. import java.io.IOException;
  19. import java.util.Objects;
  20. public class DeleteSynonymRuleAction extends ActionType<SynonymUpdateResponse> {
  21. public static final DeleteSynonymRuleAction INSTANCE = new DeleteSynonymRuleAction();
  22. public static final String NAME = "cluster:admin/synonym_rules/delete";
  23. public DeleteSynonymRuleAction() {
  24. super(NAME);
  25. }
  26. public static class Request extends LegacyActionRequest {
  27. private final String synonymsSetId;
  28. private final String synonymRuleId;
  29. private final boolean refresh;
  30. public Request(StreamInput in) throws IOException {
  31. super(in);
  32. this.synonymsSetId = in.readString();
  33. this.synonymRuleId = in.readString();
  34. if (in.getTransportVersion().onOrAfter(TransportVersions.SYNONYMS_REFRESH_PARAM)) {
  35. this.refresh = in.readBoolean();
  36. } else {
  37. this.refresh = true;
  38. }
  39. }
  40. public Request(String synonymsSetId, String synonymRuleId, boolean refresh) {
  41. this.synonymsSetId = synonymsSetId;
  42. this.synonymRuleId = synonymRuleId;
  43. this.refresh = refresh;
  44. }
  45. @Override
  46. public ActionRequestValidationException validate() {
  47. ActionRequestValidationException validationException = null;
  48. if (Strings.isNullOrEmpty(synonymsSetId)) {
  49. validationException = ValidateActions.addValidationError("synonyms set must be specified", validationException);
  50. }
  51. if (Strings.isNullOrEmpty(synonymRuleId)) {
  52. validationException = ValidateActions.addValidationError("synonym rule id must be specified", validationException);
  53. }
  54. return validationException;
  55. }
  56. @Override
  57. public void writeTo(StreamOutput out) throws IOException {
  58. super.writeTo(out);
  59. out.writeString(synonymsSetId);
  60. out.writeString(synonymRuleId);
  61. if (out.getTransportVersion().onOrAfter(TransportVersions.SYNONYMS_REFRESH_PARAM)) {
  62. out.writeBoolean(refresh);
  63. }
  64. }
  65. public String synonymsSetId() {
  66. return synonymsSetId;
  67. }
  68. public String synonymRuleId() {
  69. return synonymRuleId;
  70. }
  71. public boolean refresh() {
  72. return refresh;
  73. }
  74. @Override
  75. public boolean equals(Object o) {
  76. if (this == o) return true;
  77. if (o == null || getClass() != o.getClass()) return false;
  78. Request request = (Request) o;
  79. return Objects.equals(synonymsSetId, request.synonymsSetId) && Objects.equals(synonymRuleId, request.synonymRuleId);
  80. }
  81. @Override
  82. public int hashCode() {
  83. return Objects.hash(synonymsSetId, synonymRuleId);
  84. }
  85. }
  86. }