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.info.Info;
22  import org.forgerock.util.i18n.LocalizableString;
23  
24  /**
25   * A localizable {@code Info}.
26   */
27  class LocalizableInfo extends Info implements LocalizableTitleAndDescription<Info> {
28  
29      private LocalizableString locTitle;
30      private LocalizableString locDescription;
31  
32      @Override
33      public LocalizableInfo title(LocalizableString title) {
34          this.locTitle = title;
35          return this;
36      }
37  
38      @Override
39      public LocalizableInfo description(LocalizableString description) {
40          this.locDescription = description;
41          return this;
42      }
43  
44      @Override
45      public LocalizableInfo title(String title) {
46          setTitle(title);
47          return this;
48      }
49  
50      @Override
51      public void setTitle(String title) {
52          super.setTitle(title);
53          this.locTitle = new LocalizableString(title);
54      }
55  
56      @Override
57      public LocalizableInfo description(String description) {
58          setDescription(description);
59          return this;
60      }
61  
62      @Override
63      public void setDescription(String description) {
64          super.setDescription(description);
65          this.locDescription = new LocalizableString(description);
66      }
67  
68      @Override
69      @JsonProperty("title")
70      public LocalizableString getLocalizableTitle() {
71          return locTitle;
72      }
73  
74      @Override
75      @JsonProperty("description")
76      public LocalizableString getLocalizableDescription() {
77          return locDescription;
78      }
79  
80      @Override
81      @JsonIgnore
82      public String getTitle() {
83          return super.getTitle();
84      }
85  
86      @Override
87      @JsonIgnore
88      public String getDescription() {
89          return super.getDescription();
90      }
91  
92      /**
93       * Merge another Info's values into this one (existing values take precedence).
94       *
95       * @param info The info to merge.
96       * @return This info.
97       */
98      public LocalizableInfo mergeWith(Info info) {
99          if (info == null) {
100             return this;
101         }
102         if (info instanceof LocalizableInfo) {
103             LocalizableInfo localizableInfo = (LocalizableInfo) info;
104             if (localizableInfo.locDescription != null && this.locDescription == null) {
105                 this.locDescription = localizableInfo.locDescription;
106                 super.setDescription(localizableInfo.getDescription());
107             }
108             if (localizableInfo.locTitle != null && this.locTitle == null) {
109                 this.locTitle = localizableInfo.locTitle;
110                 super.setTitle(localizableInfo.getTitle());
111             }
112         } else {
113             if (info.getDescription() != null && getDescription() == null) {
114                 description(info.getDescription());
115             }
116             if (info.getTitle() != null && getTitle() == null) {
117                 title(info.getTitle());
118             }
119         }
120         if (info.getVersion() != null && getVersion() == null) {
121             setVersion(info.getVersion());
122         }
123         return this;
124     }
125 }