-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathPetApiController.java
More file actions
182 lines (166 loc) · 6.01 KB
/
PetApiController.java
File metadata and controls
182 lines (166 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package controllers;
import java.io.InputStream;
import apimodels.ModelApiResponse;
import apimodels.Pet;
import com.typesafe.config.Config;
import play.mvc.Controller;
import play.mvc.Result;
import play.mvc.Http;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.inject.Inject;
import java.io.File;
import openapitools.OpenAPIUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import javax.validation.constraints.*;
import com.typesafe.config.Config;
import openapitools.OpenAPIUtils.ApiAction;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaPlayFrameworkCodegen")
public class PetApiController extends Controller {
private final PetApiControllerImpInterface imp;
private final ObjectMapper mapper;
private final Config configuration;
@Inject
private PetApiController(Config configuration, PetApiControllerImpInterface imp) {
this.imp = imp;
mapper = new ObjectMapper();
this.configuration = configuration;
}
@ApiAction
public Result addPet() throws Exception {
JsonNode nodebody = request().body().asJson();
Pet body;
if (nodebody != null) {
body = mapper.readValue(nodebody.toString(), Pet.class);
if (configuration.getBoolean("useInputBeanValidation")) {
OpenAPIUtils.validate(body);
}
} else {
throw new IllegalArgumentException("'body' parameter is required");
}
imp.addPet(body);
return ok();
}
@ApiAction
public Result deletePet(Long petId) throws Exception {
String valueapiKey = request().getHeader("api_key");
String apiKey;
if (valueapiKey != null) {
apiKey = valueapiKey;
} else {
apiKey = null;
}
imp.deletePet(petId, apiKey);
return ok();
}
@ApiAction
public Result findPetsByStatus() throws Exception {
String[] statusArray = request().queryString().get("status");
if (statusArray == null) {
throw new IllegalArgumentException("'status' parameter is required");
}
List<String> statusList = OpenAPIUtils.parametersToList("csv", statusArray);
List<String> status = new ArrayList<>();
for (String curParam : statusList) {
if (!curParam.isEmpty()) {
//noinspection UseBulkOperation
status.add(curParam);
}
}
List<Pet> obj = imp.findPetsByStatus(status);
if (configuration.getBoolean("useOutputBeanValidation")) {
for (Pet curItem : obj) {
OpenAPIUtils.validate(curItem);
}
}
JsonNode result = mapper.valueToTree(obj);
return ok(result);
}
@ApiAction
public Result findPetsByTags() throws Exception {
String[] tagsArray = request().queryString().get("tags");
if (tagsArray == null) {
throw new IllegalArgumentException("'tags' parameter is required");
}
List<String> tagsList = OpenAPIUtils.parametersToList("csv", tagsArray);
List<String> tags = new ArrayList<>();
for (String curParam : tagsList) {
if (!curParam.isEmpty()) {
//noinspection UseBulkOperation
tags.add(curParam);
}
}
List<Pet> obj = imp.findPetsByTags(tags);
if (configuration.getBoolean("useOutputBeanValidation")) {
for (Pet curItem : obj) {
OpenAPIUtils.validate(curItem);
}
}
JsonNode result = mapper.valueToTree(obj);
return ok(result);
}
@ApiAction
public Result getPetById(Long petId) throws Exception {
Pet obj = imp.getPetById(petId);
if (configuration.getBoolean("useOutputBeanValidation")) {
OpenAPIUtils.validate(obj);
}
JsonNode result = mapper.valueToTree(obj);
return ok(result);
}
@ApiAction
public Result updatePet() throws Exception {
JsonNode nodebody = request().body().asJson();
Pet body;
if (nodebody != null) {
body = mapper.readValue(nodebody.toString(), Pet.class);
if (configuration.getBoolean("useInputBeanValidation")) {
OpenAPIUtils.validate(body);
}
} else {
throw new IllegalArgumentException("'body' parameter is required");
}
imp.updatePet(body);
return ok();
}
@ApiAction
public Result updatePetWithForm(Long petId) throws Exception {
String valuename = (request().body().asMultipartFormData().asFormUrlEncoded().get("name"))[0];
String name;
if (valuename != null) {
name = valuename;
} else {
name = null;
}
String valuestatus = (request().body().asMultipartFormData().asFormUrlEncoded().get("status"))[0];
String status;
if (valuestatus != null) {
status = valuestatus;
} else {
status = null;
}
imp.updatePetWithForm(petId, name, status);
return ok();
}
@ApiAction
public Result uploadFile(Long petId) throws Exception {
String valueadditionalMetadata = (request().body().asMultipartFormData().asFormUrlEncoded().get("additionalMetadata"))[0];
String additionalMetadata;
if (valueadditionalMetadata != null) {
additionalMetadata = valueadditionalMetadata;
} else {
additionalMetadata = null;
}
Http.MultipartFormData.FilePart file = request().body().asMultipartFormData().getFile("file");
ModelApiResponse obj = imp.uploadFile(petId, additionalMetadata, file);
if (configuration.getBoolean("useOutputBeanValidation")) {
OpenAPIUtils.validate(obj);
}
JsonNode result = mapper.valueToTree(obj);
return ok(result);
}
}