View Javadoc
1   /*
2    * The contents of this file are subject to the terms of the Common Development and
3    * Distribution License (the License). You may not use this file except in compliance with the
4    * License.
5    *
6    * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7    * specific language governing permission and limitations under the License.
8    *
9    * When distributing Covered Software, include this CDDL Header Notice in each file and include
10   * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11   * Header, with the fields enclosed by brackets [] replaced by your own identifying
12   * information: "Portions copyright [year] [name of copyright owner]".
13   *
14   * Copyright 2016 ForgeRock AS.
15   * Portions Copyright 2026 Wren Security.
16   */
17  package org.forgerock.api.transform;
18  
19  import com.fasterxml.jackson.annotation.JsonIgnore;
20  import com.fasterxml.jackson.annotation.JsonProperty;
21  import io.swagger.v3.oas.models.Operation;
22  import java.util.ArrayList;
23  import java.util.List;
24  import org.forgerock.util.i18n.LocalizableString;
25  
26  /**
27   * Localizable {@link Operation}.
28   */
29  public class LocalizableOperation extends Operation implements LocalizableDescription<Operation> {
30  
31      private LocalizableString description;
32      private List<LocalizableString> localizableTags;
33  
34      @Override
35      public LocalizableOperation description(LocalizableString desc) {
36          this.description = desc;
37          return this;
38      }
39  
40      @Override
41      public LocalizableOperation description(String description) {
42          setDescription(description);
43          return this;
44      }
45  
46      @Override
47      public void setDescription(String description) {
48          super.setDescription(description);
49          this.description = new LocalizableString(description);
50      }
51  
52      @Override
53      @JsonProperty("description")
54      public LocalizableString getLocalizableDescription() {
55          return description;
56      }
57  
58      @Override
59      @JsonIgnore
60      public String getDescription() {
61          return super.getDescription();
62      }
63  
64      @Override
65      public Operation addTagsItem(String tag) {
66          super.addTagsItem(tag);
67          addTag(new LocalizableString(tag));
68          return this;
69      }
70  
71      /**
72       * Adds a Tag, a String value that is metadata related to the Operation.
73       * @param tag a LocalizableString
74       */
75      public void addTag(LocalizableString tag) {
76          if (localizableTags == null) {
77              localizableTags = new ArrayList<>();
78          }
79          localizableTags.add(tag);
80      }
81  
82      @Override
83      public void setTags(List<String> tags) {
84          super.setTags(tags);
85          localizableTags = new ArrayList<>();
86          if (tags != null) {
87              for (String tag : tags) {
88                  addTag(new LocalizableString(tag));
89              }
90          }
91      }
92  
93      /**
94       * Returns the localizable tags for this operation.
95       *
96       * @return the localizable tags for this operation
97       */
98      @JsonProperty("tags")
99      public List<LocalizableString> getLocalizableTags() {
100         return localizableTags;
101     }
102 
103     @Override
104     @JsonIgnore
105     public List<String> getTags() {
106         return super.getTags();
107     }
108 
109     /**
110      * Sets a vendor extension on this operation.
111      *
112      * @param name Extension name (must start with "x-").
113      * @param value Extension value.
114      */
115     public void setVendorExtension(String name, Object value) {
116         addExtension(name, value);
117     }
118 
119 }