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   */
16  
17  package org.forgerock.api.transform;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.forgerock.util.i18n.LocalizableString;
23  
24  import com.fasterxml.jackson.annotation.JsonIgnore;
25  import com.fasterxml.jackson.annotation.JsonProperty;
26  
27  import io.swagger.models.Operation;
28  
29  /**
30   * Localizable {@link Operation}.
31   */
32  public class LocalizableOperation extends Operation implements LocalizableDescription<Operation> {
33      private LocalizableString description;
34      private List<LocalizableString> tags;
35  
36      @Override
37      public LocalizableOperation description(LocalizableString desc) {
38          this.description = desc;
39          return this;
40      }
41  
42      @Override
43      public LocalizableOperation description(String description) {
44          setDescription(description);
45          return this;
46      }
47  
48      @Override
49      public void setDescription(String description) {
50          super.setDescription(description);
51          this.description = new LocalizableString(description);
52      }
53  
54      @Override
55      public LocalizableString getLocalizableDescription() {
56          return description;
57      }
58  
59      @Override
60      public void addTag(String tag) {
61          super.addTag(tag);
62          addTag(new LocalizableString(tag));
63      }
64  
65      /**
66       * Adds a Tag, a String value that is metadata related to the Operation.
67       * @param tag a LocalizableString
68       */
69      public void addTag(LocalizableString tag) {
70          if (tags == null) {
71              tags = new ArrayList<>();
72          }
73          tags.add(tag);
74      }
75  
76      @Override
77      public void setTags(List<String> tags) {
78          super.setTags(tags);
79          tags = new ArrayList<>();
80          for (String tag : tags) {
81              addTag(tag);
82          }
83      }
84  
85      /**
86       * Returns the localizable tags for this operation.
87       *
88       * @return the localizable tags for this operation
89       */
90      @JsonProperty("tags")
91      public List<LocalizableString> getLocalizableTags() {
92          return tags;
93      }
94  
95      @Override
96      @JsonIgnore
97      public List<String> getTags() {
98          return super.getTags();
99      }
100 }