
com.azure.resourcemanager.frontdoor.models.RulesEngineRule Maven / Gradle / Ivy
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.
package com.azure.resourcemanager.frontdoor.models;
import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.List;
/**
* Contains a list of match conditions, and an action on how to modify the request/response. If multiple rules match,
* the actions from one rule that conflict with a previous rule overwrite for a singular action, or append in the case
* of headers manipulation.
*/
@Fluent
public final class RulesEngineRule implements JsonSerializable {
/*
* A name to refer to this specific rule.
*/
private String name;
/*
* A priority assigned to this rule.
*/
private int priority;
/*
* Actions to perform on the request and response if all of the match conditions are met.
*/
private RulesEngineAction action;
/*
* A list of match conditions that must meet in order for the actions of this rule to run. Having no match
* conditions means the actions will always run.
*/
private List matchConditions;
/*
* If this rule is a match should the rules engine continue running the remaining rules or stop. If not present,
* defaults to Continue.
*/
private MatchProcessingBehavior matchProcessingBehavior;
/**
* Creates an instance of RulesEngineRule class.
*/
public RulesEngineRule() {
}
/**
* Get the name property: A name to refer to this specific rule.
*
* @return the name value.
*/
public String name() {
return this.name;
}
/**
* Set the name property: A name to refer to this specific rule.
*
* @param name the name value to set.
* @return the RulesEngineRule object itself.
*/
public RulesEngineRule withName(String name) {
this.name = name;
return this;
}
/**
* Get the priority property: A priority assigned to this rule.
*
* @return the priority value.
*/
public int priority() {
return this.priority;
}
/**
* Set the priority property: A priority assigned to this rule.
*
* @param priority the priority value to set.
* @return the RulesEngineRule object itself.
*/
public RulesEngineRule withPriority(int priority) {
this.priority = priority;
return this;
}
/**
* Get the action property: Actions to perform on the request and response if all of the match conditions are met.
*
* @return the action value.
*/
public RulesEngineAction action() {
return this.action;
}
/**
* Set the action property: Actions to perform on the request and response if all of the match conditions are met.
*
* @param action the action value to set.
* @return the RulesEngineRule object itself.
*/
public RulesEngineRule withAction(RulesEngineAction action) {
this.action = action;
return this;
}
/**
* Get the matchConditions property: A list of match conditions that must meet in order for the actions of this rule
* to run. Having no match conditions means the actions will always run.
*
* @return the matchConditions value.
*/
public List matchConditions() {
return this.matchConditions;
}
/**
* Set the matchConditions property: A list of match conditions that must meet in order for the actions of this rule
* to run. Having no match conditions means the actions will always run.
*
* @param matchConditions the matchConditions value to set.
* @return the RulesEngineRule object itself.
*/
public RulesEngineRule withMatchConditions(List matchConditions) {
this.matchConditions = matchConditions;
return this;
}
/**
* Get the matchProcessingBehavior property: If this rule is a match should the rules engine continue running the
* remaining rules or stop. If not present, defaults to Continue.
*
* @return the matchProcessingBehavior value.
*/
public MatchProcessingBehavior matchProcessingBehavior() {
return this.matchProcessingBehavior;
}
/**
* Set the matchProcessingBehavior property: If this rule is a match should the rules engine continue running the
* remaining rules or stop. If not present, defaults to Continue.
*
* @param matchProcessingBehavior the matchProcessingBehavior value to set.
* @return the RulesEngineRule object itself.
*/
public RulesEngineRule withMatchProcessingBehavior(MatchProcessingBehavior matchProcessingBehavior) {
this.matchProcessingBehavior = matchProcessingBehavior;
return this;
}
/**
* Validates the instance.
*
* @throws IllegalArgumentException thrown if the instance is not valid.
*/
public void validate() {
if (name() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException("Missing required property name in model RulesEngineRule"));
}
if (action() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException("Missing required property action in model RulesEngineRule"));
} else {
action().validate();
}
if (matchConditions() != null) {
matchConditions().forEach(e -> e.validate());
}
}
private static final ClientLogger LOGGER = new ClientLogger(RulesEngineRule.class);
/**
* {@inheritDoc}
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("name", this.name);
jsonWriter.writeIntField("priority", this.priority);
jsonWriter.writeJsonField("action", this.action);
jsonWriter.writeArrayField("matchConditions", this.matchConditions,
(writer, element) -> writer.writeJson(element));
jsonWriter.writeStringField("matchProcessingBehavior",
this.matchProcessingBehavior == null ? null : this.matchProcessingBehavior.toString());
return jsonWriter.writeEndObject();
}
/**
* Reads an instance of RulesEngineRule from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of RulesEngineRule if the JsonReader was pointing to an instance of it, or null if it was
* pointing to JSON null.
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
* @throws IOException If an error occurs while reading the RulesEngineRule.
*/
public static RulesEngineRule fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
RulesEngineRule deserializedRulesEngineRule = new RulesEngineRule();
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("name".equals(fieldName)) {
deserializedRulesEngineRule.name = reader.getString();
} else if ("priority".equals(fieldName)) {
deserializedRulesEngineRule.priority = reader.getInt();
} else if ("action".equals(fieldName)) {
deserializedRulesEngineRule.action = RulesEngineAction.fromJson(reader);
} else if ("matchConditions".equals(fieldName)) {
List matchConditions
= reader.readArray(reader1 -> RulesEngineMatchCondition.fromJson(reader1));
deserializedRulesEngineRule.matchConditions = matchConditions;
} else if ("matchProcessingBehavior".equals(fieldName)) {
deserializedRulesEngineRule.matchProcessingBehavior
= MatchProcessingBehavior.fromString(reader.getString());
} else {
reader.skipChildren();
}
}
return deserializedRulesEngineRule;
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy