com.microsoft.azure.cosmosdb.Trigger Maven / Gradle / Ivy
/*
* The MIT License (MIT)
* Copyright (c) 2018 Microsoft Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.microsoft.azure.cosmosdb;
import org.apache.commons.text.WordUtils;
import com.microsoft.azure.cosmosdb.internal.Constants;
/**
* Represents a trigger in the Azure Cosmos DB database service.
*
* Cosmos DB supports pre and post triggers defined in JavaScript to be executed on creates, updates and deletes. For
* additional details, refer to the server-side JavaScript API documentation.
*/
public class Trigger extends Resource {
/**
* Constructor.
*/
public Trigger() {
super();
}
/**
* Constructor.
*
* @param jsonString the json string that represents the trigger.
*/
public Trigger(String jsonString) {
super(jsonString);
}
/**
* Get the body of the trigger.
*
* @return the body of the trigger.
*/
public String getBody() {
return super.getString(Constants.Properties.BODY);
}
/**
* Set the body of the trigger.
*
* @param body the body of the trigger.
*/
public void setBody(String body) {
super.set(Constants.Properties.BODY, body);
}
/**
* Get the type of the trigger.
*
* @return the trigger type.
*/
public TriggerType getTriggerType() {
TriggerType result = TriggerType.Pre;
try {
result = TriggerType.valueOf(
WordUtils.capitalize(super.getString(Constants.Properties.TRIGGER_TYPE)));
} catch (IllegalArgumentException e) {
// ignore the exception and return the default
this.getLogger().warn("Invalid triggerType value {}.", super.getString(Constants.Properties.TRIGGER_TYPE));
}
return result;
}
/**
* Set the type of the resource.
*
* @param triggerType the trigger type.
*/
public void setTriggerType(TriggerType triggerType) {
super.set(Constants.Properties.TRIGGER_TYPE, triggerType.name());
}
/**
* Get the operation type of the trigger.
*
* @return the trigger operation.
*/
public TriggerOperation getTriggerOperation() {
TriggerOperation result = TriggerOperation.Create;
try {
result = TriggerOperation.valueOf(
WordUtils.capitalize(super.getString(Constants.Properties.TRIGGER_OPERATION)));
} catch (IllegalArgumentException e) {
// ignore the exception and return the default
this.getLogger().warn("Invalid triggerOperation value {}.", super.getString(Constants.Properties.TRIGGER_OPERATION));
}
return result;
}
/**
* Set the operation type of the trigger.
*
* @param triggerOperation the trigger operation.
*/
public void setTriggerOperation(TriggerOperation triggerOperation) {
super.set(Constants.Properties.TRIGGER_OPERATION, triggerOperation.name());
}
}