Refactor/to x content fragments2 (elastic/x-pack-elasticsearch#2329)
* Moves more classes over to ToXContentObject/Fragment * Removes ToXContentToBytes * Removes ToXContent from Enums * review comment fix * slight change to use XContantHelper Original commit: elastic/x-pack-elasticsearch@0f2d3f328b
This commit is contained in:
parent
18d15ef2d2
commit
de6c275dca
|
@ -5,16 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.common.http;
|
||||
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
|
||||
|
||||
public enum HttpContentType implements ToXContent {
|
||||
public enum HttpContentType {
|
||||
|
||||
JSON() {
|
||||
@Override
|
||||
|
@ -39,11 +36,6 @@ public enum HttpContentType implements ToXContent {
|
|||
|
||||
public abstract XContentType contentType();
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(id());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return id();
|
||||
|
|
|
@ -5,13 +5,9 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.common.http;
|
||||
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
public enum HttpMethod implements ToXContent {
|
||||
public enum HttpMethod {
|
||||
|
||||
HEAD("HEAD"),
|
||||
GET("GET"),
|
||||
|
@ -47,9 +43,7 @@ public enum HttpMethod implements ToXContent {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
public String value() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,8 +140,8 @@ public class HttpRequest implements ToXContentObject {
|
|||
builder.startObject();
|
||||
builder.field(Field.HOST.getPreferredName(), host);
|
||||
builder.field(Field.PORT.getPreferredName(), port);
|
||||
builder.field(Field.SCHEME.getPreferredName(), scheme, params);
|
||||
builder.field(Field.METHOD.getPreferredName(), method, params);
|
||||
builder.field(Field.SCHEME.getPreferredName(), scheme.value());
|
||||
builder.field(Field.METHOD.getPreferredName(), method.value());
|
||||
if (path != null) {
|
||||
builder.field(Field.PATH.getPreferredName(), path);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.xpack.common.http;
|
||||
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -162,10 +163,10 @@ public class HttpRequestTemplate implements ToXContentObject {
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(HttpRequest.Field.SCHEME.getPreferredName(), scheme, params);
|
||||
builder.field(HttpRequest.Field.SCHEME.getPreferredName(), scheme.value());
|
||||
builder.field(HttpRequest.Field.HOST.getPreferredName(), host);
|
||||
builder.field(HttpRequest.Field.PORT.getPreferredName(), port);
|
||||
builder.field(HttpRequest.Field.METHOD.getPreferredName(), method, params);
|
||||
builder.field(HttpRequest.Field.METHOD.getPreferredName(), method.value());
|
||||
if (path != null) {
|
||||
builder.field(HttpRequest.Field.PATH.getPreferredName(), path, params);
|
||||
}
|
||||
|
|
|
@ -5,13 +5,9 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.common.http;
|
||||
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
public enum Scheme implements ToXContent {
|
||||
public enum Scheme {
|
||||
|
||||
HTTP("http", 80),
|
||||
HTTPS("https", 443);
|
||||
|
@ -44,9 +40,7 @@ public enum Scheme implements ToXContent {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
public String value() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class BasicAuth implements HttpAuth {
|
|||
builder.startObject();
|
||||
builder.field(Field.USERNAME.getPreferredName(), username);
|
||||
if (!WatcherParams.hideSecrets(params)) {
|
||||
builder.field(Field.PASSWORD.getPreferredName(), password, params);
|
||||
builder.field(Field.PASSWORD.getPreferredName(), password.value());
|
||||
}
|
||||
return builder.endObject();
|
||||
}
|
||||
|
|
|
@ -5,14 +5,12 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.common.secret;
|
||||
|
||||
import org.elasticsearch.xpack.security.crypto.CryptoService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.xpack.security.crypto.CryptoService;
|
||||
|
||||
public class Secret implements ToXContent {
|
||||
public class Secret {
|
||||
|
||||
protected final char[] text;
|
||||
|
||||
|
@ -27,9 +25,8 @@ public class Secret implements ToXContent {
|
|||
return service.decrypt(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(new String(text));
|
||||
public String value() throws IOException {
|
||||
return new String(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,8 +9,6 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
@ -21,7 +19,7 @@ import java.util.Locale;
|
|||
* When a job is created it is initialised in to the state closed
|
||||
* i.e. it is not running.
|
||||
*/
|
||||
public enum JobState implements ToXContent, Writeable {
|
||||
public enum JobState implements Writeable {
|
||||
|
||||
CLOSING, CLOSED, OPENED, FAILED, OPENING;
|
||||
|
||||
|
@ -43,15 +41,8 @@ public enum JobState implements ToXContent, Writeable {
|
|||
out.writeEnum(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.value(name().toLowerCase(Locale.ROOT));
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFragment() {
|
||||
return true;
|
||||
public String value() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ public class JobTaskStatus implements Task.Status {
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(STATE.getPreferredName(), state, params);
|
||||
builder.field(STATE.getPreferredName(), state.value());
|
||||
builder.field(ALLOCATION_ID.getPreferredName(), allocationId);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.elasticsearch.xpack.notification.email;
|
|||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -119,13 +118,13 @@ public class Email implements ToXContentObject {
|
|||
builder.startObject();
|
||||
builder.field(Field.ID.getPreferredName(), id);
|
||||
if (from != null) {
|
||||
builder.field(Field.FROM.getPreferredName(), from, params);
|
||||
builder.field(Field.FROM.getPreferredName(), from.toUnicodeString());
|
||||
}
|
||||
if (replyTo != null) {
|
||||
builder.field(Field.REPLY_TO.getPreferredName(), replyTo, params);
|
||||
}
|
||||
if (priority != null) {
|
||||
builder.field(Field.PRIORITY.getPreferredName(), priority, params);
|
||||
builder.field(Field.PRIORITY.getPreferredName(), priority.value());
|
||||
}
|
||||
builder.field(Field.SENT_DATE.getPreferredName(), sentDate);
|
||||
if (to != null) {
|
||||
|
@ -362,7 +361,7 @@ public class Email implements ToXContentObject {
|
|||
|
||||
}
|
||||
|
||||
public enum Priority implements ToXContent {
|
||||
public enum Priority {
|
||||
|
||||
HIGHEST(1),
|
||||
HIGH(2),
|
||||
|
@ -382,10 +381,8 @@ public class Email implements ToXContentObject {
|
|||
message.setHeader(HEADER, String.valueOf(value));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
public String value() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public static Priority resolve(String name) {
|
||||
|
@ -420,7 +417,7 @@ public class Email implements ToXContentObject {
|
|||
}
|
||||
}
|
||||
|
||||
public static class Address extends javax.mail.internet.InternetAddress implements ToXContent {
|
||||
public static class Address extends javax.mail.internet.InternetAddress {
|
||||
|
||||
public static final ParseField ADDRESS_NAME_FIELD = new ParseField("name");
|
||||
public static final ParseField ADDRESS_EMAIL_FIELD = new ParseField("email");
|
||||
|
@ -433,11 +430,6 @@ public class Email implements ToXContentObject {
|
|||
super(address, personal, StandardCharsets.UTF_8.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(toUnicodeString());
|
||||
}
|
||||
|
||||
public static Address parse(String field, XContentParser.Token token, XContentParser parser) throws IOException {
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
String text = parser.text();
|
||||
|
@ -523,7 +515,7 @@ public class Email implements ToXContentObject {
|
|||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startArray();
|
||||
for (Address address : addresses) {
|
||||
address.toXContent(builder, params);
|
||||
builder.value(address.toUnicodeString());
|
||||
}
|
||||
return builder.endArray();
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.notification.email;
|
||||
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
|
@ -14,15 +15,12 @@ import javax.mail.Session;
|
|||
import javax.mail.internet.MimeBodyPart;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* A profile of an email client, can be seen as a strategy to emulate a real world email client
|
||||
* (different clients potentially support different mime message structures)
|
||||
*/
|
||||
public enum Profile implements ToXContent {
|
||||
public enum Profile {
|
||||
|
||||
STANDARD() {
|
||||
|
||||
|
@ -172,11 +170,6 @@ public enum Profile implements ToXContent {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
static MimeMessage createCommon(Email email, Session session) throws MessagingException {
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
message.setHeader(MESSAGE_ID_HEADER, email.id);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.notification.email.attachment;
|
||||
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentFragment;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.xpack.notification.email.Attachment;
|
||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||
|
@ -19,7 +19,7 @@ import java.io.IOException;
|
|||
*/
|
||||
public interface EmailAttachmentParser<T extends EmailAttachmentParser.EmailAttachment> {
|
||||
|
||||
interface EmailAttachment extends ToXContent {
|
||||
interface EmailAttachment extends ToXContentFragment {
|
||||
/**
|
||||
* @return A type to identify the email attachment, same as the parser identifier
|
||||
*/
|
||||
|
|
|
@ -9,8 +9,6 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.SettingsException;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.xpack.common.http.HttpClient;
|
||||
import org.elasticsearch.xpack.common.http.HttpProxy;
|
||||
|
@ -60,7 +58,7 @@ public abstract class HipChatAccount {
|
|||
|
||||
public abstract SentMessages send(HipChatMessage message, @Nullable HttpProxy proxy);
|
||||
|
||||
public enum Profile implements ToXContent {
|
||||
public enum Profile {
|
||||
|
||||
V1() {
|
||||
@Override
|
||||
|
@ -87,11 +85,6 @@ public abstract class HipChatAccount {
|
|||
abstract HipChatAccount createAccount(String name, Settings settings, HipChatServer defaultServer, HttpClient httpClient,
|
||||
Logger logger);
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.ElasticsearchParseException;
|
|||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -124,10 +123,10 @@ public class HipChatMessage implements ToXContentObject {
|
|||
}
|
||||
builder.field(Field.BODY.getPreferredName(), body);
|
||||
if (format != null) {
|
||||
builder.field(Field.FORMAT.getPreferredName(), format, params);
|
||||
builder.field(Field.FORMAT.getPreferredName(), format.value());
|
||||
}
|
||||
if (color != null) {
|
||||
builder.field(Field.COLOR.getPreferredName(), color, params);
|
||||
builder.field(Field.COLOR.getPreferredName(), color.value());
|
||||
}
|
||||
if (notify != null) {
|
||||
builder.field(Field.NOTIFY.getPreferredName(), notify);
|
||||
|
@ -224,7 +223,7 @@ public class HipChatMessage implements ToXContentObject {
|
|||
}
|
||||
builder.field(Field.BODY.getPreferredName(), body, params);
|
||||
if (format != null) {
|
||||
builder.field(Field.FORMAT.getPreferredName(), format, params);
|
||||
builder.field(Field.FORMAT.getPreferredName(), format.value());
|
||||
}
|
||||
if (color != null) {
|
||||
builder.field(Field.COLOR.getPreferredName(), color, params);
|
||||
|
@ -390,7 +389,7 @@ public class HipChatMessage implements ToXContentObject {
|
|||
}
|
||||
|
||||
|
||||
public enum Color implements ToXContent {
|
||||
public enum Color {
|
||||
YELLOW, GREEN, RED, PURPLE, GRAY, RANDOM;
|
||||
|
||||
private final TextTemplate template = new TextTemplate(name());
|
||||
|
@ -399,11 +398,6 @@ public class HipChatMessage implements ToXContentObject {
|
|||
return template;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
@ -433,7 +427,7 @@ public class HipChatMessage implements ToXContentObject {
|
|||
}
|
||||
}
|
||||
|
||||
public enum Format implements ToXContent {
|
||||
public enum Format {
|
||||
|
||||
TEXT,
|
||||
HTML;
|
||||
|
@ -444,11 +438,6 @@ public class HipChatMessage implements ToXContentObject {
|
|||
return template;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
package org.elasticsearch.xpack.persistent;
|
||||
|
||||
import org.elasticsearch.common.io.stream.NamedWriteable;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
|
||||
/**
|
||||
* Parameters used to start persistent task
|
||||
*/
|
||||
public interface PersistentTaskParams extends NamedWriteable, ToXContent {
|
||||
public interface PersistentTaskParams extends NamedWriteable, ToXContentObject {
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.elasticsearch.xpack.watcher.actions;
|
|||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.logging.LoggerMessageFormat;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentFragment;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -22,7 +21,7 @@ public interface Action extends ToXContentObject {
|
|||
|
||||
abstract class Result implements ToXContentFragment {
|
||||
|
||||
public enum Status implements ToXContent {
|
||||
public enum Status {
|
||||
SUCCESS,
|
||||
FAILURE,
|
||||
PARTIAL_FAILURE,
|
||||
|
@ -31,9 +30,8 @@ public interface Action extends ToXContentObject {
|
|||
CONDITION_FAILED,
|
||||
SIMULATED;
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
public String value() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ public class ActionWrapper implements ToXContentObject {
|
|||
builder.startObject();
|
||||
builder.field(Field.ID.getPreferredName(), id);
|
||||
builder.field(Field.TYPE.getPreferredName(), action.type());
|
||||
builder.field(Field.STATUS.getPreferredName(), action.status(), params);
|
||||
builder.field(Field.STATUS.getPreferredName(), action.status().value());
|
||||
if (condition != null) {
|
||||
builder.field(Watch.Field.CONDITION.getPreferredName(), condition, params);
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class EmailAction implements Action {
|
|||
if (auth != null) {
|
||||
builder.field(Field.USER.getPreferredName(), auth.user());
|
||||
if (WatcherParams.hideSecrets(params) == false) {
|
||||
builder.field(Field.PASSWORD.getPreferredName(), auth.password(), params);
|
||||
builder.field(Field.PASSWORD.getPreferredName(), auth.password().value());
|
||||
}
|
||||
}
|
||||
if (profile != null) {
|
||||
|
|
|
@ -10,8 +10,8 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.xpack.watcher.actions.Action;
|
||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||
import org.elasticsearch.xpack.watcher.actions.Action;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
@ -61,7 +61,7 @@ public class LoggingAction implements Action {
|
|||
if (category != null) {
|
||||
builder.field(Field.CATEGORY.getPreferredName(), category);
|
||||
}
|
||||
builder.field(Field.LEVEL.getPreferredName(), level, params);
|
||||
builder.field(Field.LEVEL.getPreferredName(), level.value());
|
||||
builder.field(Field.TEXT.getPreferredName(), text, params);
|
||||
return builder.endObject();
|
||||
}
|
||||
|
|
|
@ -7,13 +7,10 @@ package org.elasticsearch.xpack.watcher.actions.logging;
|
|||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.common.SuppressLoggerChecks;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
public enum LoggingLevel implements ToXContent {
|
||||
public enum LoggingLevel {
|
||||
|
||||
ERROR() {
|
||||
@Override
|
||||
|
@ -53,9 +50,7 @@ public enum LoggingLevel implements ToXContent {
|
|||
|
||||
abstract void log(Logger logger, String text);
|
||||
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
public String value() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,15 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.watcher.client;
|
||||
|
||||
import org.elasticsearch.action.support.ToXContentToBytes;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.xpack.watcher.actions.Action;
|
||||
import org.elasticsearch.xpack.watcher.actions.throttler.Throttler;
|
||||
import org.elasticsearch.xpack.watcher.condition.AlwaysCondition;
|
||||
|
@ -29,7 +32,7 @@ import java.util.Map;
|
|||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
|
||||
public class WatchSourceBuilder extends ToXContentToBytes implements ToXContentObject {
|
||||
public class WatchSourceBuilder implements ToXContentObject {
|
||||
|
||||
private Trigger trigger;
|
||||
private Input input = NoneInput.INSTANCE;
|
||||
|
@ -165,6 +168,19 @@ public class WatchSourceBuilder extends ToXContentToBytes implements ToXContentO
|
|||
return builder.endObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link org.elasticsearch.common.bytes.BytesReference}
|
||||
* containing the {@link ToXContent} output in binary format. Builds the
|
||||
* request as the provided <code>contentType</code>
|
||||
*/
|
||||
public final BytesReference buildAsBytes(XContentType contentType) {
|
||||
try {
|
||||
return XContentHelper.toXContent(this, contentType, false);
|
||||
} catch (Exception e) {
|
||||
throw new ElasticsearchException("Failed to build ToXContent", e);
|
||||
}
|
||||
}
|
||||
|
||||
static class TransformedAction implements ToXContentObject {
|
||||
|
||||
private final String id;
|
||||
|
|
|
@ -10,10 +10,10 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.xpack.watcher.input.Input;
|
||||
import org.elasticsearch.xpack.common.http.HttpContentType;
|
||||
import org.elasticsearch.xpack.common.http.HttpRequest;
|
||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.xpack.watcher.input.Input;
|
||||
import org.elasticsearch.xpack.watcher.watch.Payload;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -64,7 +64,7 @@ public class HttpInput implements Input {
|
|||
builder.field(Field.EXTRACT.getPreferredName(), extractKeys);
|
||||
}
|
||||
if (expectedResponseXContentType != null) {
|
||||
builder.field(Field.RESPONSE_CONTENT_TYPE.getPreferredName(), expectedResponseXContentType, params);
|
||||
builder.field(Field.RESPONSE_CONTENT_TYPE.getPreferredName(), expectedResponseXContentType.id());
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.elasticsearch.xpack.watcher.transform;
|
|||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.xpack.watcher.watch.Payload;
|
||||
|
@ -16,7 +15,7 @@ import org.elasticsearch.xpack.watcher.watch.Payload;
|
|||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
public interface Transform extends ToXContent {
|
||||
public interface Transform extends ToXContentObject {
|
||||
|
||||
ParseField TRANSFORM = new ParseField("transform");
|
||||
|
||||
|
|
|
@ -6,14 +6,11 @@
|
|||
package org.elasticsearch.xpack.watcher.trigger.schedule.support;
|
||||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
|
||||
public enum DayOfWeek implements ToXContent {
|
||||
public enum DayOfWeek {
|
||||
|
||||
SUNDAY("SUN"),
|
||||
MONDAY("MON"),
|
||||
|
@ -29,11 +26,6 @@ public enum DayOfWeek implements ToXContent {
|
|||
this.cronKey = cronKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public static String cronPart(EnumSet<DayOfWeek> days) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (DayOfWeek day : days) {
|
||||
|
|
|
@ -6,14 +6,11 @@
|
|||
package org.elasticsearch.xpack.watcher.trigger.schedule.support;
|
||||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
|
||||
public enum Month implements ToXContent {
|
||||
public enum Month {
|
||||
|
||||
JANUARY("JAN"),
|
||||
FEBRUARY("FEB"),
|
||||
|
@ -34,11 +31,6 @@ public enum Month implements ToXContent {
|
|||
this.cronKey = cronKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.value(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public static String cronPart(EnumSet<Month> days) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Month day : days) {
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
package org.elasticsearch.xpack.watcher.trigger.schedule.support;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
|
||||
public interface Times extends ToXContent {
|
||||
public interface Times extends ToXContentObject {
|
||||
|
||||
ParseField MONTH_FIELD = new ParseField("in", "month");
|
||||
ParseField DAY_FIELD = new ParseField("on", "day");
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package org.elasticsearch.xpack.watcher.watch;
|
||||
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
|
@ -18,7 +17,7 @@ import java.util.Objects;
|
|||
|
||||
import static org.elasticsearch.xpack.watcher.support.WatcherUtils.responseToData;
|
||||
|
||||
public interface Payload extends ToXContent {
|
||||
public interface Payload extends ToXContentObject {
|
||||
|
||||
Simple EMPTY = new Simple(Collections.emptyMap());
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ public class HipChatMessageTests extends ESTestCase {
|
|||
HipChatMessage.Format format = null;
|
||||
if (randomBoolean()) {
|
||||
format = randomFrom(HipChatMessage.Format.values());
|
||||
jsonBuilder.field("format", format, ToXContent.EMPTY_PARAMS);
|
||||
jsonBuilder.field("format", format.value());
|
||||
}
|
||||
Boolean notify = null;
|
||||
if (randomBoolean()) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
|
@ -192,7 +193,7 @@ public class WatcherUtilsTests extends ESTestCase {
|
|||
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.searchSource().query(QueryBuilders.matchAllQuery()).size(11);
|
||||
XContentBuilder searchSourceJsonBuilder = jsonBuilder();
|
||||
searchSourceBuilder.toXContent(searchSourceJsonBuilder, ToXContent.EMPTY_PARAMS);
|
||||
source = searchSourceBuilder.buildAsBytes(XContentType.JSON);
|
||||
source = XContentHelper.toXContent(searchSourceBuilder, XContentType.JSON, false);
|
||||
builder.rawField("body", source);
|
||||
}
|
||||
Script template = null;
|
||||
|
|
|
@ -244,7 +244,7 @@ public class ChainTransformTests extends ESTestCase {
|
|||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return builder.startObject().endArray();
|
||||
return builder.startObject().endObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue