Scala SDK Samples - Modules Operations
package com.zoho.crm.sample.modules
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.customviews.Criteria
import com.zoho.crm.api.customviews.CustomView
import com.zoho.crm.api.customviews.SharedDetails
import com.zoho.crm.api.modules.APIException
import com.zoho.crm.api.modules.ActionHandler
import com.zoho.crm.api.modules.ActionResponse
import com.zoho.crm.api.modules.ActionWrapper
import com.zoho.crm.api.modules.Argument
import com.zoho.crm.api.modules.BodyWrapper
import com.zoho.crm.api.modules.Module
import com.zoho.crm.api.modules.ModulesOperations
import com.zoho.crm.api.modules.ModulesOperations.GetModulesHeader
import com.zoho.crm.api.modules.RelatedListProperties
import com.zoho.crm.api.modules.ResponseHandler
import com.zoho.crm.api.modules.ResponseWrapper
import com.zoho.crm.api.modules.SuccessResponse
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Modules {
/**
* Get Modules
* This method is used to get metadata about all the modules and print the response.
*
* @throws Exception
*/
@throws[Exception]
def getModules(): Unit = { //Get instance of ModulesOperations Class
val moduleOperations = new ModulesOperations
val headerInstance = new HeaderMap
val ifmodifiedsince = OffsetDateTime.of(2020, 5, 20, 10, 0, 0, 1, ZoneOffset.of("+05:30"))
headerInstance.add(new GetModulesHeader().IfModifiedSince, ifmodifiedsince)
//Call getModules method that takes headerInstance as parameters
val responseOption = moduleOperations.getModules(Option(headerInstance))
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
}
//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 Module instances
val modules = responseWrapper.getModules
for (module <- modules) { //Get the Name of each Module
println("Module Name: " + module.getName)
//Get the GlobalSearchSupported of each Module
println("Module GlobalSearchSupported: " + module.getGlobalSearchSupported.toString)
//Get the Deletable of each Module
println("Module Deletable: " + module.getDeletable.toString)
//Get the Description of each Module
println("Module Description: " + module.getDescription)
//Get the Creatable of each Module
println("Module Creatable: " + module.getCreatable.toString)
//Get the InventoryTemplateSupported of each Module
println("Module InventoryTemplateSupported: " + module.getInventoryTemplateSupported.toString)
if (module.getModifiedTime != null) { //Get the ModifiedTime of each Module
println("Module ModifiedTime: " + module.getModifiedTime)
}
//Get the PluralLabel of each Module
println("Module PluralLabel: " + module.getPluralLabel)
//Get the PresenceSubMenu of each Module
println("Module PresenceSubMenu: " + module.getPresenceSubMenu.toString)
//Get the TriggersSupported of each Module
println("Module TriggersSupported: " + module.getTriggersSupported.toString)
//Get the Id of each Module
println("Module Id: " + module.getId.toString)
//Get the Visibility of each Module
println("Module Visibility: " + module.getVisibility.toString)
//Get the Convertable of each Module
println("Module Convertable: " + module.getConvertable.toString)
//Get the Editable of each Module
println("Module Editable: " + module.getEditable.toString)
//Get the EmailtemplateSupport of each Module
println("Module EmailtemplateSupport: " + module.getEmailtemplateSupport.toString)
//Get the list of Profile instance each Module
val profiles = module.getProfiles
//Check if profiles is not null
if (profiles != null) {
for (profile <- profiles) { //Get the Name of each Profile
println("Module Profile Name: " + profile.getName)
//Get the Id of each Profile
println("Module Profile Id: " + profile.getId.toString)
}
}
//Get the FilterSupported of each Module
println("Module FilterSupported: " + module.getFilterSupported.toString)
//Get the ShowAsTab of each Module
println("Module ShowAsTab: " + module.getShowAsTab.toString)
//Get the WebLink of each Module
println("Module WebLink: " + module.getWebLink)
//Get the SequenceNumber of each Module
println("Module SequenceNumber: " + module.getSequenceNumber.toString)
//Get the SingularLabel of each Module
println("Module SingularLabel: " + module.getSingularLabel)
//Get the Viewable of each Module
println("Module Viewable: " + module.getViewable.toString)
//Get the APISupported of each Module
println("Module APISupported: " + module.getAPISupported.toString)
//Get the APIName of each Module
println("Module APIName: " + module.getAPIName)
//Get the QuickCreate of each Module
println("Module QuickCreate: " + module.getQuickCreate.toString)
//Get the modifiedBy User instance of each Module
val modifiedByOption = module.getModifiedBy
//Check if modifiedBy is not null
if (modifiedByOption.isDefined) { //Get the Name of the modifiedBy User
val modifiedBy=modifiedByOption.get
println("Module Modified By User-Name: " + modifiedBy.getName)
//Get the ID of the modifiedBy User
println("Module Modified By User-ID: " + modifiedBy.getId)
}
//Get the GeneratedType of each Module
println("Module GeneratedType: " + module.getGeneratedType.getValue)
//Get the FeedsRequired of each Module
println("Module FeedsRequired: " + module.getFeedsRequired.toString)
//Get the ScoringSupported of each Module
println("Module ScoringSupported: " + module.getScoringSupported.toString)
//Get the WebformSupported of each Module
println("Module WebformSupported: " + module.getWebformSupported.toString)
//Get the list of Argument instance each Module
val arguments = module.getArguments
//Check if arguments is not null
if (arguments != null) {
for (argument <- arguments) { //Get the Name of each Argument
println("Module Argument Name: " + argument.getName)
//Get the Value of each Argument
println("Module Argument Value: " + argument.getValue)
}
}
//Get the ModuleName of each Module
println("Module ModuleName: " + module.getModuleName)
//Get the BusinessCardFieldLimit of each Module
println("Module BusinessCardFieldLimit: " + module.getBusinessCardFieldLimit.toString)
//Get the parentModule Module instance of each Module
val parentModuleOption = module.getParentModule
if (parentModuleOption.isDefined ) { //Get the Name of Parent Module
val parentModule = parentModuleOption.get
println("Module Parent Module Name: " + parentModule.getAPIName)
//Get the Value of Parent Module
println("Module Parent Module Id: " + parentModule.getId.toString)
}
}
}
else { //Check if the request returned an exception
if (responseHandler.isInstanceOf[APIException]) { //Get the received APIException instance
val exception = responseHandler.asInstanceOf[APIException]
//Get the Status
println("Status: " + exception.getStatus.getValue)
//Get the Code
println("Code: " + exception.getCode.getValue)
println("Details: ")
//Get the details map
exception.getDetails.foreach(entry=>{
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 <- fields) { //Get each value
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}
package com.zoho.crm.sample.modules
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.customviews.Criteria
import com.zoho.crm.api.customviews.CustomView
import com.zoho.crm.api.customviews.SharedDetails
import com.zoho.crm.api.modules.APIException
import com.zoho.crm.api.modules.ActionHandler
import com.zoho.crm.api.modules.ActionResponse
import com.zoho.crm.api.modules.ActionWrapper
import com.zoho.crm.api.modules.Argument
import com.zoho.crm.api.modules.BodyWrapper
import com.zoho.crm.api.modules.Module
import com.zoho.crm.api.modules.ModulesOperations
import com.zoho.crm.api.modules.ModulesOperations.GetModulesHeader
import com.zoho.crm.api.modules.RelatedListProperties
import com.zoho.crm.api.modules.ResponseHandler
import com.zoho.crm.api.modules.ResponseWrapper
import com.zoho.crm.api.modules.SuccessResponse
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Modules {
/**
* Update Module By APIName
* This method is used to update module details using module APIName and print the response.
*
* @param moduleAPIName The API Name of the module to update
* @throws Exception
*/
@throws[Exception]
def updateModuleByAPIName(moduleAPIName: String): Unit = {
val moduleOperations = new ModulesOperations
val modules = new ArrayBuffer[Module]
val profiles = new ArrayBuffer[Profile]
//Get instance of Profile Class
val profile = new Profile
//To set the Profile Id
profile.setId(Option(347706126014l))
// profile.setDelete(true)
profiles.addOne(profile)
val module = new Module
module.setProfiles(profiles)
modules.addOne(module)
val request = new BodyWrapper
request.setModules(modules)
//Call updateModuleByAPIName method that takes BodyWrapper instance and moduleAPIName as parameter
val responseOption = moduleOperations.updateModuleByAPIName(moduleAPIName,request )
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]) { //Get the received ActionWrapper instance
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
//Get the list of obtained ActionResponse instances
val actionResponses = actionWrapper.getModules
for (actionResponse <- actionResponses) { //Check if the request is successful
if (actionResponse.isInstanceOf[SuccessResponse]) { //Get the received SuccessResponse instance
val successResponse = actionResponse.asInstanceOf[SuccessResponse]
println("Status: " + successResponse.getStatus.getValue)
println("Code: " + successResponse.getCode.getValue)
println("Details: ")
successResponse.getDetails.foreach(entry=>{
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: ")
if (exception.getDetails != null) {
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 <- fields) {
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}
package com.zoho.crm.sample.modules
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.customviews.Criteria
import com.zoho.crm.api.customviews.CustomView
import com.zoho.crm.api.customviews.SharedDetails
import com.zoho.crm.api.modules.APIException
import com.zoho.crm.api.modules.ActionHandler
import com.zoho.crm.api.modules.ActionResponse
import com.zoho.crm.api.modules.ActionWrapper
import com.zoho.crm.api.modules.Argument
import com.zoho.crm.api.modules.BodyWrapper
import com.zoho.crm.api.modules.Module
import com.zoho.crm.api.modules.ModulesOperations
import com.zoho.crm.api.modules.ModulesOperations.GetModulesHeader
import com.zoho.crm.api.modules.RelatedListProperties
import com.zoho.crm.api.modules.ResponseHandler
import com.zoho.crm.api.modules.ResponseWrapper
import com.zoho.crm.api.modules.SuccessResponse
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Modules {
/**
* Update Module By Id
* This method is used to update module details using module Id and print the response.
*
* @param moduleId - The Id of the module to obtain metadata
* @throws Exception
*/
@throws[Exception]
def updateModuleById(moduleId: Long): Unit = { //Long moduleId = 34770613905003L
val moduleOperations = new ModulesOperations
val modules = new ArrayBuffer[Module]
val profiles = new ArrayBuffer[Profile]
val profile = new Profile
profile.setId(Option(347706106014l))
profiles.addOne(profile)
val module = new Module
module.setProfiles(profiles)
module.setAPIName(Option("apiName1"))
modules.addOne(module)
val request = new BodyWrapper
request.setModules(modules)
//Call updateModuleById method that takes BodyWrapper instance and moduleId as parameter
val responseOption = moduleOperations.updateModuleById(moduleId,request )
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.getModules
for (actionResponse <- actionResponses) {
if (actionResponse.isInstanceOf[SuccessResponse]) {
val successResponse = actionResponse.asInstanceOf[SuccessResponse]
println("Status: " + successResponse.getStatus.getValue)
println("Code: " + successResponse.getCode.getValue)
println("Details: ")
successResponse.getDetails.foreach(entry=>{
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: ")
if (exception.getDetails != null) {
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 <- fields) {
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}