Scala SDK Samples - Notification Operations
package com.zoho.crm.sample.notification
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.notification.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Notification, NotificationOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notification.NotificationOperations.DisableNotificationsParam
import com.zoho.crm.api.notification.NotificationOperations.GetNotificationDetailsParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notifications {
/**
* Get Notification Details
* This method is used to get all the Notification and print the response.
*
* @throws Exception
*/
@throws[Exception]
def getNotificationDetails(): Unit = {
val notificationOperations = new NotificationOperations
val paramInstance = new ParameterMap
paramInstance.add(new GetNotificationDetailsParam().channelId, 16800211l)
// paramInstance.add(new GetNotificationDetailsParam().module, "Accounts")
// paramInstance.add(new GetNotificationDetailsParam().page, 1)
// paramInstance.add(new GetNotificationDetailsParam().perPage, 2)
//Call getNotificationDetails method
val responseOption= notificationOperations.getNotificationDetails(Option(paramInstance))
if (responseOption.isDefined ) { //Check response
val 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
}
if (response.isExpected) {
val responseHandler = response.getObject
if (responseHandler.isInstanceOf[ResponseWrapper]) { //Get the received ResponseWrapper instance
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
//Get the list of obtained Notification instances
val notifications = responseWrapper.getWatch
for (notification {
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
else if (response.getStatusCode != 204) {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field
package com.zoho.crm.sample.notification
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.notification.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Notification, NotificationOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notification.NotificationOperations.DisableNotificationsParam
import com.zoho.crm.api.notification.NotificationOperations.GetNotificationDetailsParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notifications {
/**
* Update Notifications
* This method is used to update Notifications and print the response.
*
* @throws Exception
*/
@throws[Exception]
def updateNotifications(): Unit = {
val notificationOperations = new NotificationOperations
val bodyWrapper = new BodyWrapper
val notificationList = new ArrayBuffer[Notification]
val notification = new Notification
//Set ChannelId to the Notification instance
notification.setChannelId(Option(16800211l))
val events = new ArrayBuffer[String]
events.addOne("Accounts.all")
notification.setEvents(events)
//Set name to the Notification instance
// notification.setChannelExpiry(OffsetDateTime.now)
notification.setToken(Option("TOKEN_FOR_VERIFICATION_OF_1068002"))
notification.setNotifyUrl(Option("https://www.zohoapis.com"))
notificationList.addOne(notification)
//Set the list to notification in BodyWrapper instance
bodyWrapper.setWatch(notificationList)
//Call updateNotifications method that takes BodyWrapper instance as parameter
val responseOption= notificationOperations.updateNotifications(bodyWrapper)
if (responseOption.isDefined ) { //Check response
val 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.getWatch
for (actionResponse {
if (entry._2.isInstanceOf[ArrayBuffer[Any]]) {
val dataList = entry._2.asInstanceOf[ArrayBuffer[Any]]
if (dataList.size > 0 && dataList(0).isInstanceOf[Notification]) {
@SuppressWarnings(Array("unchecked")) val eventList = dataList.asInstanceOf[ArrayBuffer[Notification]]
for (event {
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.notification
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.notification.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Notification, NotificationOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notification.NotificationOperations.DisableNotificationsParam
import com.zoho.crm.api.notification.NotificationOperations.GetNotificationDetailsParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notifications {
/**
* Update Specific Information of a Notification
* This method is used to update single Notification and print the response.
*
* @throws Exception
*/
@throws[Exception]
def updateNotification(): Unit = {
val notificationOperations = new NotificationOperations
val bodyWrapper = new BodyWrapper
val notificationList = new ArrayBuffer[Notification]
val notification = new Notification
notification.setChannelId(Option(10800212l))
val events = new ArrayBuffer[String]
events.addOne("Deals.all")
notification.setEvents(events)
// notification.setChannelExpiry(OffsetDateTime.now)
notification.setToken(Option("TOKEN_FOR_VERIFICATION_OF_108002"))
notification.setNotifyUrl(Option("https://www.zohoapis.com"))
notificationList.addOne(notification)
bodyWrapper.setWatch(notificationList)
//Call updateNotification method that takes BodyWrapper instance as parameters
val responseOption= notificationOperations.updateNotification(bodyWrapper)
if (responseOption.isDefined ) { //Check response
val 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.getWatch
for (actionResponse {
if (entry._2.isInstanceOf[ArrayBuffer[Any]]) {
val dataList = entry._2.asInstanceOf[ArrayBuffer[Any]]
if (dataList.size > 0 && dataList(0).isInstanceOf[Notification]) {
@SuppressWarnings(Array("unchecked")) val eventList = dataList.asInstanceOf[ArrayBuffer[Notification]]
for (event {
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.notification
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.notification.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Notification, NotificationOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notification.NotificationOperations.DisableNotificationsParam
import com.zoho.crm.api.notification.NotificationOperations.GetNotificationDetailsParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notifications {
/**
* Disable Notifications
* To stop all the instant notifications enabled by the user for a channel.
*
* @param channelIds - Specify the unique IDs of the notification channels to be disabled.
* @throws Exception
*/
@throws[Exception]
def disableNotifications(channelIds: ArrayBuffer[Long]): Unit = { //example
//ArrayList channelIds = new ArrayList(Arrays.asList(347706108001l))
val notificationOperations = new NotificationOperations
//Get instance of ParameterMap Class
val paramInstance = new ParameterMap
for (id {
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.notification
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.notification.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Notification, NotificationOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notification.NotificationOperations.DisableNotificationsParam
import com.zoho.crm.api.notification.NotificationOperations.GetNotificationDetailsParam
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notifications {
/**
* Disable Specific Notifications
* This method is used to disable notifications for the specified events in a channel.
*
* @throws Exception
*/
@throws[Exception]
def disableNotification(): Unit = {
val notificationOperations = new NotificationOperations
val bodyWrapper = new BodyWrapper
val notificationList = new ArrayBuffer[Notification]
val notification = new Notification
notification.setChannelId(Option(10800211l))
val events = new ArrayBuffer[String]
events.addOne("Deals.edit")
notification.setEvents(events)
notification.setDeleteevents(Option(true))
notificationList.addOne(notification)
bodyWrapper.setWatch(notificationList)
//Call disableNotification which takes BodyWrapper instance as parameter
val responseOption= notificationOperations.disableNotification(bodyWrapper)
if (responseOption.isDefined ) { //Check response
val 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.getWatch
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