package io.vertx.ext.web.api;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.core.MultiMap;
import io.vertx.core.http.CaseInsensitiveHeaders;
import io.vertx.core.json.JsonObject;
import java.util.Map;
import java.util.function.Function;
@DataObject(generateConverter = true, publicConverter = false)
public class OperationRequest {
private JsonObject params;
private MultiMap ;
private JsonObject user;
private JsonObject ;
public OperationRequest() {
init();
}
public OperationRequest(JsonObject json) {
init();
OperationRequestConverter.fromJson(json, this);
JsonObject hdrs = json.getJsonObject("headers", null);
if (hdrs != null) {
headers = new CaseInsensitiveHeaders();
for (Map.Entry<String, Object> entry: hdrs) {
if (!(entry.getValue() instanceof String)) {
throw new IllegalStateException("Invalid type for message header value " + entry.getValue().getClass());
}
headers.set(entry.getKey(), (String)entry.getValue());
}
}
}
public OperationRequest(JsonObject params, MultiMap headers, JsonObject user, JsonObject extra) {
this.params = params;
this.headers = headers;
this.user = user;
this.extra = extra;
}
public OperationRequest(OperationRequest other) {
this.params = other.getParams();
this.headers = other.getHeaders();
this.user = other.getUser();
this.extra = other.getExtra();
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
OperationRequestConverter.toJson(this, json);
if (headers != null) {
JsonObject hJson = new JsonObject();
headers.entries().forEach(entry -> hJson.put(entry.getKey(), entry.getValue()));
json.put("headers", hJson);
}
return json;
}
private void init() {
this.params = new JsonObject();
this.headers = MultiMap.caseInsensitiveMultiMap();
this.user = null;
this.extra = null;
}
public JsonObject getParams() {
return params;
}
public MultiMap () {
return headers;
}
public JsonObject getUser() { return user; }
public JsonObject () {
return extra;
}
@Fluent public OperationRequest setParams(JsonObject params) {
this.params = params;
return this;
}
@Fluent public OperationRequest (MultiMap headers) {
this.headers = headers;
return this;
}
@Fluent public OperationRequest setUser(JsonObject user) {
this.user = user;
return this;
}
@Fluent
public OperationRequest (JsonObject extra) {
this.extra = extra;
return this;
}
}