• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.codegen.model.intermediate;
17 
18 import com.fasterxml.jackson.annotation.JsonIgnore;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Map;
22 import software.amazon.awssdk.codegen.checksum.HttpChecksum;
23 import software.amazon.awssdk.codegen.compression.RequestCompression;
24 import software.amazon.awssdk.codegen.docs.ClientType;
25 import software.amazon.awssdk.codegen.docs.DocConfiguration;
26 import software.amazon.awssdk.codegen.docs.OperationDocs;
27 import software.amazon.awssdk.codegen.docs.SimpleMethodOverload;
28 import software.amazon.awssdk.codegen.internal.Utils;
29 import software.amazon.awssdk.codegen.model.service.AuthType;
30 import software.amazon.awssdk.codegen.model.service.EndpointTrait;
31 import software.amazon.awssdk.codegen.model.service.StaticContextParam;
32 
33 public class OperationModel extends DocumentationModel {
34 
35     private String operationName;
36 
37     private String serviceProtocol;
38 
39     private boolean deprecated;
40 
41     private String deprecatedMessage;
42 
43     private VariableModel input;
44 
45     private ReturnTypeModel returnType;
46 
47     private List<ExceptionModel> exceptions = new ArrayList<>();
48 
49     private List<SimpleMethodFormModel> simpleMethods;
50 
51     private boolean hasBlobMemberAsPayload;
52 
53     private boolean hasStringMemberAsPayload;
54 
55     private boolean isAuthenticated = true;
56 
57     private AuthType authType;
58 
59     private List<AuthType> auth;
60 
61     private boolean isPaginated;
62 
63     private boolean endpointOperation;
64 
65     private boolean endpointCacheRequired;
66 
67     private EndpointDiscovery endpointDiscovery;
68 
69     @JsonIgnore
70     private ShapeModel inputShape;
71 
72     @JsonIgnore
73     private ShapeModel outputShape;
74 
75     private EndpointTrait endpointTrait;
76 
77     private boolean httpChecksumRequired;
78 
79     private HttpChecksum httpChecksum;
80 
81     private RequestCompression requestcompression;
82 
83     @JsonIgnore
84     private Map<String, StaticContextParam> staticContextParams;
85 
getOperationName()86     public String getOperationName() {
87         return operationName;
88     }
89 
setOperationName(String operationName)90     public void setOperationName(String operationName) {
91         this.operationName = operationName;
92     }
93 
getMethodName()94     public String getMethodName() {
95         return Utils.unCapitalize(operationName);
96     }
97 
getServiceProtocol()98     public String getServiceProtocol() {
99         return serviceProtocol;
100     }
101 
setServiceProtocol(String serviceProtocol)102     public void setServiceProtocol(String serviceProtocol) {
103         this.serviceProtocol = serviceProtocol;
104     }
105 
isDeprecated()106     public boolean isDeprecated() {
107         return deprecated;
108     }
109 
setDeprecated(boolean deprecated)110     public void setDeprecated(boolean deprecated) {
111         this.deprecated = deprecated;
112     }
113 
getDeprecatedMessage()114     public String getDeprecatedMessage() {
115         return deprecatedMessage;
116     }
117 
setDeprecatedMessage(String deprecatedMessage)118     public void setDeprecatedMessage(String deprecatedMessage) {
119         this.deprecatedMessage = deprecatedMessage;
120     }
121 
getDocs(IntermediateModel model, ClientType clientType)122     public String getDocs(IntermediateModel model,
123                           ClientType clientType) {
124         return OperationDocs.getDocs(model, this, clientType);
125     }
126 
getDocs(IntermediateModel model, ClientType clientType, SimpleMethodOverload methodOverload)127     public String getDocs(IntermediateModel model,
128                           ClientType clientType,
129                           SimpleMethodOverload methodOverload) {
130         return OperationDocs.getDocs(model, this, clientType, methodOverload);
131     }
132 
getDocs(IntermediateModel model, ClientType clientType, SimpleMethodOverload methodOverload, DocConfiguration config)133     public String getDocs(IntermediateModel model,
134                           ClientType clientType,
135                           SimpleMethodOverload methodOverload,
136                           DocConfiguration config) {
137         return OperationDocs.getDocs(model, this, clientType, methodOverload, config);
138     }
139 
isAuthenticated()140     public boolean isAuthenticated() {
141         return isAuthenticated;
142     }
143 
setIsAuthenticated(boolean isAuthenticated)144     public void setIsAuthenticated(boolean isAuthenticated) {
145         this.isAuthenticated = isAuthenticated;
146     }
147 
getAuthType()148     public AuthType getAuthType() {
149         return authType;
150     }
151 
setAuthType(AuthType authType)152     public void setAuthType(AuthType authType) {
153         this.authType = authType;
154     }
155 
getAuth()156     public List<AuthType> getAuth() {
157         return auth;
158     }
159 
setAuth(List<AuthType> auth)160     public void setAuth(List<AuthType> auth) {
161         this.auth = auth;
162     }
163 
getInputShape()164     public ShapeModel getInputShape() {
165         return inputShape;
166     }
167 
setInputShape(ShapeModel inputShape)168     public void setInputShape(ShapeModel inputShape) {
169         this.inputShape = inputShape;
170     }
171 
getOutputShape()172     public ShapeModel getOutputShape() {
173         return outputShape;
174     }
175 
setOutputShape(ShapeModel outputShape)176     public void setOutputShape(ShapeModel outputShape) {
177         this.outputShape = outputShape;
178     }
179 
getInput()180     public VariableModel getInput() {
181         return input;
182     }
183 
setInput(VariableModel input)184     public void setInput(VariableModel input) {
185         this.input = input;
186     }
187 
getReturnType()188     public ReturnTypeModel getReturnType() {
189         return returnType;
190     }
191 
setReturnType(ReturnTypeModel returnType)192     public void setReturnType(ReturnTypeModel returnType) {
193         this.returnType = returnType;
194     }
195 
getSyncReturnType()196     public String getSyncReturnType() {
197         return returnType.getReturnType();
198     }
199 
getExceptions()200     public List<ExceptionModel> getExceptions() {
201         return exceptions;
202     }
203 
setExceptions(List<ExceptionModel> exceptions)204     public void setExceptions(List<ExceptionModel> exceptions) {
205         this.exceptions = exceptions;
206     }
207 
addException(ExceptionModel exception)208     public void addException(ExceptionModel exception) {
209         exceptions.add(exception);
210     }
211 
212     @JsonIgnore
getSimpleMethodForms()213     public List<SimpleMethodFormModel> getSimpleMethodForms() {
214         return simpleMethods;
215     }
216 
addSimpleMethodForm(List<ArgumentModel> arguments)217     public void addSimpleMethodForm(List<ArgumentModel> arguments) {
218         if (this.simpleMethods == null) {
219             this.simpleMethods = new ArrayList<>();
220         }
221 
222         SimpleMethodFormModel form = new SimpleMethodFormModel();
223         form.setArguments(arguments);
224 
225         this.simpleMethods.add(form);
226     }
227 
getHasBlobMemberAsPayload()228     public boolean getHasBlobMemberAsPayload() {
229         return this.hasBlobMemberAsPayload;
230     }
231 
setHasBlobMemberAsPayload(boolean hasBlobMemberAsPayload)232     public void setHasBlobMemberAsPayload(boolean hasBlobMemberAsPayload) {
233         this.hasBlobMemberAsPayload = hasBlobMemberAsPayload;
234     }
235 
getHasStringMemberAsPayload()236     public boolean getHasStringMemberAsPayload() {
237         return this.hasStringMemberAsPayload;
238     }
239 
setHasStringMemberAsPayload(boolean hasStringMemberAsPayload)240     public void setHasStringMemberAsPayload(boolean hasStringMemberAsPayload) {
241         this.hasStringMemberAsPayload = hasStringMemberAsPayload;
242     }
243 
hasStreamingInput()244     public boolean hasStreamingInput() {
245         return inputShape != null && inputShape.isHasStreamingMember();
246     }
247 
hasStreamingOutput()248     public boolean hasStreamingOutput() {
249         return outputShape != null && outputShape.isHasStreamingMember();
250     }
251 
252     @JsonIgnore
isStreaming()253     public boolean isStreaming() {
254         return hasStreamingInput() || hasStreamingOutput();
255     }
256 
isEndpointOperation()257     public boolean isEndpointOperation() {
258         return endpointOperation;
259     }
260 
setEndpointOperation(boolean endpointOperation)261     public void setEndpointOperation(boolean endpointOperation) {
262         this.endpointOperation = endpointOperation;
263     }
264 
isEndpointCacheRequired()265     public boolean isEndpointCacheRequired() {
266         return endpointCacheRequired;
267     }
268 
setEndpointCacheRequired(boolean endpointCacheRequired)269     public void setEndpointCacheRequired(boolean endpointCacheRequired) {
270         this.endpointCacheRequired = endpointCacheRequired;
271     }
272 
isPaginated()273     public boolean isPaginated() {
274         return isPaginated;
275     }
276 
setPaginated(boolean paginated)277     public void setPaginated(boolean paginated) {
278         isPaginated = paginated;
279     }
280 
getEndpointDiscovery()281     public EndpointDiscovery getEndpointDiscovery() {
282         return endpointDiscovery;
283     }
284 
setEndpointDiscovery(EndpointDiscovery endpointDiscovery)285     public void setEndpointDiscovery(EndpointDiscovery endpointDiscovery) {
286         this.endpointDiscovery = endpointDiscovery;
287     }
288 
289     /**
290      * Returns the endpoint trait that will be used to resolve the endpoint of an API.
291      */
getEndpointTrait()292     public EndpointTrait getEndpointTrait() {
293         return endpointTrait;
294     }
295 
296     /**
297      * Sets the endpoint trait that will be used to resolve the endpoint of an API.
298      */
setEndpointTrait(EndpointTrait endpointTrait)299     public void setEndpointTrait(EndpointTrait endpointTrait) {
300         this.endpointTrait = endpointTrait;
301     }
302 
303     /**
304      * @return True if the operation has an event stream member in the output shape. False otherwise.
305      */
hasEventStreamOutput()306     public boolean hasEventStreamOutput() {
307         return containsEventStream(outputShape);
308     }
309 
310     /**
311      * @return True if the operation has an event stream member in the input shape. False otherwise.
312      */
hasEventStreamInput()313     public boolean hasEventStreamInput() {
314         return containsEventStream(inputShape);
315     }
316 
hasRequiresLengthInInput()317     public boolean hasRequiresLengthInInput() {
318         return inputShape != null && inputShape.isHasRequiresLengthMember();
319     }
320 
containsEventStream(ShapeModel shapeModel)321     private boolean containsEventStream(ShapeModel shapeModel) {
322         return shapeModel != null
323                && shapeModel.getMembers() != null
324                && shapeModel.getMembers().stream()
325                             .filter(m -> m.getShape() != null)
326                             .anyMatch(m -> m.getShape().isEventStream());
327     }
328 
isHttpChecksumRequired()329     public boolean isHttpChecksumRequired() {
330         return httpChecksumRequired;
331     }
332 
setHttpChecksumRequired(boolean httpChecksumRequired)333     public void setHttpChecksumRequired(boolean httpChecksumRequired) {
334         this.httpChecksumRequired = httpChecksumRequired;
335     }
336 
getHttpChecksum()337     public HttpChecksum getHttpChecksum() {
338         return httpChecksum;
339     }
340 
setHttpChecksum(HttpChecksum httpChecksum)341     public void setHttpChecksum(HttpChecksum httpChecksum) {
342         this.httpChecksum = httpChecksum;
343     }
344 
getRequestcompression()345     public RequestCompression getRequestcompression() {
346         return requestcompression;
347     }
348 
setRequestcompression(RequestCompression requestcompression)349     public void setRequestcompression(RequestCompression requestcompression) {
350         this.requestcompression = requestcompression;
351     }
352 
getStaticContextParams()353     public Map<String, StaticContextParam> getStaticContextParams() {
354         return staticContextParams;
355     }
356 
setStaticContextParams(Map<String, StaticContextParam> staticContextParams)357     public void setStaticContextParams(Map<String, StaticContextParam> staticContextParams) {
358         this.staticContextParams = staticContextParams;
359     }
360 }
361