Scala SDK Samples - Taxes Operations
package com.zoho.crm.sample.taxes
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.taxes.TaxesOperations.DeleteTaxesParam
import com.zoho.crm.api.taxes.{APIException, ActionWrapper, BodyWrapper, ResponseWrapper, SuccessResponse, Tax, TaxesOperations}
import scala.collection.mutable.ArrayBuffer
object Taxes {
/**
* Get Taxes
* This method is used to get all the Organization Taxes and print the response.
*
* @throws Exception
*/
@throws[Exception]
def getTaxes(): Unit = { //Get instance of TaxesOperations Class
val taxesOperations = new TaxesOperations
//Call getTaxes method
val responseOption = taxesOperations.getTaxes
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (util.Arrays.asList(204, 304).contains(response.getStatusCode)) {
println(if (response.getStatusCode == 204) "No Content"
else "Not Modified")
return
}
//Check if expected response is received
if (response.isExpected) { //Get object from response
val responseHandler = response.getObject
if (responseHandler.isInstanceOf[ResponseWrapper]) { //Get the received ResponseWrapper instance
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
//Get the list of obtained Tax instances
val taxes = responseWrapper.getTaxes
for (tax {
println(entry._1 + ": " + entry._2)
})
//Get the Message
println("Message: " + exception.getMessage.getValue)
}
}
}
else { //If response is not as expected
//Get model object from response
val responseObject = response.getModel
//Get the response object's class
val clas = responseObject.getClass
//Get all declared fields of the response class
val fields = clas.getDeclaredFields
for (field
package com.zoho.crm.sample.taxes
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.taxes.TaxesOperations.DeleteTaxesParam
import com.zoho.crm.api.taxes.{APIException, ActionWrapper, BodyWrapper, ResponseWrapper, SuccessResponse, Tax, TaxesOperations}
import scala.collection.mutable.ArrayBuffer
object Taxes {
/**
* Create Taxes
* This method is used to create Organization Taxes and print the response.
*
* @throws Exception
*/
@throws[Exception]
def createTaxes(): Unit = {
val taxesOperations = new TaxesOperations
//Get instance of BodyWrapper Class that will contain the request body
val request = new BodyWrapper
//List of Tax instances
val taxList = new ArrayBuffer[Tax]
//Get instance of Tax Class
var tax1 = new Tax
tax1.setName(Option("MyTsdax1122"))
tax1.setSequenceNumber(Option(2))
tax1.setValue(Option(10.0))
taxList.addOne(tax1)
tax1 = new Tax
tax1.setName(Option("MyTsax2122"))
tax1.setValue(Option(12.0))
taxList.addOne(tax1)
request.setTaxes(taxList)
//Call createTaxes method that takes BodyWrapper class instance as parameter
val responseOption = taxesOperations.createTaxes(request)
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionHandler = response.getObject
if (actionHandler.isInstanceOf[ActionWrapper]) { //Get the received ActionWrapper instance
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
//Get the list of obtained ActionResponse instances
val actionResponses = actionWrapper.getTaxes
for (actionResponse {
println(entry._1 + ": " + entry._2)
})
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field
package com.zoho.crm.sample.taxes
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.taxes.TaxesOperations.DeleteTaxesParam
import com.zoho.crm.api.taxes.{APIException, ActionWrapper, BodyWrapper, ResponseWrapper, SuccessResponse, Tax, TaxesOperations}
import scala.collection.mutable.ArrayBuffer
object Taxes {
/**
* Update Taxes
* This method is used to update Organization Taxes and print the response.
*
* @throws Exception
*/
@throws[Exception]
def updateTaxes(): Unit = {
val taxesOperations = new TaxesOperations
val request = new BodyWrapper
val taxList = new ArrayBuffer[Tax]
var tax1 = new Tax
tax1.setId(Option(35240336093001l))
tax1.setName(Option("MyT2ax1134"))
tax1.setSequenceNumber(Option(1))
tax1.setValue(Option(15.0))
taxList.addOne(tax1)
tax1 = new Tax
tax1.setId(Option(35240335022001l))
tax1.setValue(Option(25.0))
taxList.addOne(tax1)
tax1 = new Tax
tax1.setId(Option(35240335711001l))
tax1.setSequenceNumber(Option(2))
taxList.addOne(tax1)
request.setTaxes(taxList)
//Call updateTaxes method that takes BodyWrapper instance as parameter
val responseOption = taxesOperations.updateTaxes(request)
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionHandler = response.getObject
if (actionHandler.isInstanceOf[ActionWrapper]) {
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
val actionResponses = actionWrapper.getTaxes
for (actionResponse {
println(entry._1 + ": " + entry._2)
})
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field
package com.zoho.crm.sample.taxes
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.taxes.TaxesOperations.DeleteTaxesParam
import com.zoho.crm.api.taxes.{APIException, ActionWrapper, BodyWrapper, ResponseWrapper, SuccessResponse, Tax, TaxesOperations}
import scala.collection.mutable.ArrayBuffer
object Taxes {
/**
* Delete Taxes
* This method is used to delete Organization Taxes and print the response.
*
* @param taxIds - The List of the tax IDs to be deleted
* @throws Exception
*/
@throws[Exception]
def deleteTaxes(taxIds: ArrayBuffer[Long]): Unit = { //example
//ArrayList taxIds = new ArrayList(Arrays.asList(34770616198032l,347706105682038l))
val taxesOperations = new TaxesOperations
//Get instance of ParameterMap Class
val paramInstance = new ParameterMap
for (taxId {
println(entry._1 + ": " + entry._2)
})
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field
package com.zoho.crm.sample.taxes
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.taxes.TaxesOperations.DeleteTaxesParam
import com.zoho.crm.api.taxes.{APIException, ActionWrapper, BodyWrapper, ResponseWrapper, SuccessResponse, Tax, TaxesOperations}
import scala.collection.mutable.ArrayBuffer
object Taxes {
/**
* Delete Tax
* This method is used to delete Organization Tax and print the response.
*
* @param taxId - The ID of the tax to be deleted
* @throws Exception
*/
@throws[Exception]
def deleteTax(taxId: Long): Unit = {
val taxesOperations = new TaxesOperations
//Call deleteTax method that takes taxId as parameter
val responseOption = taxesOperations.deleteTax(taxId)
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionHandler = response.getObject
if (actionHandler.isInstanceOf[ActionWrapper]) {
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
val actionResponses = actionWrapper.getTaxes
for (actionResponse {
println(entry._1 + ": " + entry._2)
})
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field