org.elasticsearch.client.license.StartTrialResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-rest-high-level-client Show documentation
Show all versions of elasticsearch-rest-high-level-client Show documentation
Elasticsearch subproject :client:rest-high-level
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.client.license;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.XContentParseException;
import org.elasticsearch.xcontent.XContentParser;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;
public class StartTrialResponse {
private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(
"start_trial_response",
true,
(Object[] arguments, Void aVoid) -> {
final boolean acknowledged = (boolean) arguments[0];
final boolean trialWasStarted = (boolean) arguments[1];
final String licenseType = (String) arguments[2];
final String errorMessage = (String) arguments[3];
@SuppressWarnings("unchecked")
final Tuple> acknowledgeDetails = (Tuple>) arguments[4];
final String acknowledgeHeader;
final Map acknowledgeMessages;
if (acknowledgeDetails != null) {
acknowledgeHeader = acknowledgeDetails.v1();
acknowledgeMessages = acknowledgeDetails.v2();
} else {
acknowledgeHeader = null;
acknowledgeMessages = null;
}
return new StartTrialResponse(acknowledged, trialWasStarted, licenseType, errorMessage, acknowledgeHeader, acknowledgeMessages);
}
);
static {
PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged"));
PARSER.declareBoolean(constructorArg(), new ParseField("trial_was_started"));
PARSER.declareString(optionalConstructorArg(), new ParseField("type"));
PARSER.declareString(optionalConstructorArg(), new ParseField("error_message"));
// todo consolidate this parsing with the parsing in PutLicenseResponse
PARSER.declareObject(optionalConstructorArg(), (parser, aVoid) -> {
final Map acknowledgeMessages = new HashMap<>();
String message = null;
final Map parsedMap = parser.map();
for (Map.Entry entry : parsedMap.entrySet()) {
if (entry.getKey().equals("message")) {
if (entry.getValue() instanceof String) {
message = (String) entry.getValue();
} else {
throw new XContentParseException(parser.getTokenLocation(), "unexpected acknowledgement header type");
}
} else {
if (entry.getValue() instanceof List) {
final List messageStrings = new ArrayList<>();
@SuppressWarnings("unchecked")
final List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy