I have given a query and code snippets that are related to the query. You have to answer the query using those snippets. Query: what does addOrUpdateWebhookApi do
 snippets: public JSONObject addorUpdateTicketWebhookApi(HttpServletRequest request, HttpServletResponse response, JSONObject jsonObject) {
        InternalSessionManager internalSessionManager = StaticContextAccessor.getBean(InternalSessionManager.class);
        JSONObject responseJSONObject = TicketConfigurationUtility.getResponseJSONObject();
        try {
            String[] mandatoryFields = { "callBackUrl", "ticketType", "authKey" };
            responseJSONObject = TicketConfigurationUtility.checkMandatoryFields(jsonObject, mandatoryFields);
            if (responseJSONObject.containsKey("Error")) {
                return responseJSONObject;
            }
            int cmId = internalSessionManager.getPartner(request).getCmId();
            WebHookDataPrivilege[] webHookprivileges = WebHookDataPrivilege.values();
            int id = TicketConfigurationUtility.getIntegerFromJSONObject(jsonObject, "id", 0);
            String callBackUrl = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "callBackUrl", "");
            String authKey = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "authKey", "");
            String ticketType = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "ticketType", "");
            StringBuffer privilegeBuff = new StringBuffer();
            if (!validateUrl(callBackUrl)) {
                responseJSONObject.put("reason", "Enter a valid URL.");
                return responseJSONObject;
            }
            if (webHookprivileges != null && webHookprivileges.length > 0) {
                for (WebHookDataPrivilege privilege : webHookprivileges) {
                    if (StringUtilityClass.isNotNullAndNotEmpty(jsonObject.getString(privilege.getKey()))) {
                        if (privilegeBuff.length() > 0) {
                            privilegeBuff.append(",");
                        }
                        privilegeBuff.append(privilege.getKey());
                    }
                }
            }
            TicketWebhook webHookAPI = id > 0 && ticketWebhookCache.getByCmId(cmId) != null ? ticketWebhookCache.getByCmId(cmId)
                    : new TicketWebhook();
            webHookAPI.setCmId(cmId);
            webHookAPI.setCreateTime(CommonUtils.getCurrentTimestamp());
            webHookAPI.setUrl(callBackUrl);
            webHookAPI.setTicketType(ticketType);
            webHookAPI.setLastUpdateTime(CommonUtils.getCurrentTimestamp());
            webHookAPI.setPrivileges(privilegeBuff.toString());
            webHookAPI.setAuthKey(authKey);
            webHookAPI.setTicketTypeSet(CommonUtils.getStringSetFromString(ticketType, ","));
            webHookAPI.setPrivilegesSet(CommonUtils.getStringSetFromString(privilegeBuff.toString(), ","));
            if (webHookAPI.getId() > 0) {
                if (webhookDao.saveTicketWebhook(webHookAPI)) {
                    kafkaTicketWebhookListner.send(topic, webHookAPI);
                    monolithicSyncUtil.sendObjectToMonolith(webHookAPI, "update");
                    responseJSONObject.put("status", "success");
                    responseJSONObject.put("id", webHookAPI.getId());
                    responseJSONObject.put("reason", "TicketWebhook updated successfully");
                } else {
                    responseJSONObject.put("reason", "Failed to add TicketWebhook data");
                }
            } else {
                if (webhookDao.saveTicketWebhook(webHookAPI)) {
                    kafkaTicketWebhookListner.send(topic, webHookAPI);
                    monolithicSyncUtil.sendObjectToMonolith(webHookAPI, "add");
                    responseJSONObject.put("status", "success");
                    responseJSONObject.put("id", webHookAPI.getId());
                    responseJSONObject.put("reason", "TicketWebhook created successfully");
                } else {
                    responseJSONObject.put("reason", "Failed to add TicketWebhook data");
                }
            }
        } catch (Exception e) {
            LOGGER.error("Error in addorUpdateTicketWebhookApi() method !!", e);
        }
        return responseJSONObject;

    }
@PostMapping("add-update-ticketwebhook")
    public ResponseEntity<JSONObject> addOrUpdateticketWebhook(@RequestBody JSONObject jsonObject) {
        JSONObject responseJSONObject = null;
        try {
            responseJSONObject = ticketWebhookApiService.addorUpdateTicketWebhookApi(request, response, jsonObject);
        } catch (Exception e) {
            LOGGER.error("Error in addOrUpdateticketWebhook() method !!", e);
        }
        return new ResponseEntity<JSONObject>(responseJSONObject, HttpStatus.CREATED);
    }
public JsonNode addOrUpdateWebhookApi(HttpServletRequest request, Optional<Integer> id, JsonNode requestNode) {
        ObjectNode responseNode = objectMapper.createObjectNode().put("status", "failure");
        int cmId = SessionManager.getPartner(request).getCmId();
        TicketWebhook ticketWebhook = null;
        TicketWebhook defaultWebhook = ticketWebhookCache.getByCmId(cmId);
        if (id.isPresent()) {
            if ((ticketWebhook = ticketWebhookCache.getByCmIdAndId(cmId, id.get())) == null) {
                return responseNode.put("reason", "no webhook apis found for cmId " + cmId);
            } else if (requestNode.path("isDefault").asBoolean() && defaultWebhook != null && ticketWebhook.getId() != defaultWebhook.getId()) {
                return responseNode.put("reason", "more than one default api");
            } else if (!requestNode.path("url").isMissingNode() && !validateUrl(requestNode.path("url").asText())) {
                return responseNode.put("reason", "invalid url");
            }
        } else {
            if (requestNode.path("configId").asInt() == 0) {
                if (StringUtils.isBlank(requestNode.path("name").asText(""))) {
                    return responseNode.put("reason", "invalid name");
                } else if (!validateUrl(requestNode.path("url").asText())) {
                    return responseNode.put("reason", "invalid url");
                }
            } else if (requestNode.path("isDefault").asBoolean() && defaultWebhook != null) {
                return responseNode.put("reason", "more than one default api");
            }
        }
        try {
            TicketWebhook oldTicketWebhook = GenericUtility.createNewReference(mapper, ticketWebhook);
            TicketWebhook newTicketWebhook = oldTicketWebhook != null ?
                    mapper.readerForUpdating(ticketWebhook).readValue(requestNode) :
                    mapper.readerFor(TicketWebhook.class).readValue(requestNode);
            newTicketWebhook.setCmId(cmId);
            Timestamp currentTime = CommonUtils.getCurrentTimestamp();
            newTicketWebhook.setCreateTime(oldTicketWebhook == null ? currentTime : oldTicketWebhook.getCreateTime());
            newTicketWebhook.setLastUpdateTime(currentTime);
            newTicketWebhook.setUrl(newTicketWebhook.getUrl() == null ? "" : newTicketWebhook.getUrl());
            newTicketWebhook.setTicketTypeSet(CommonUtils.getStringSetFromString(newTicketWebhook.getTicketType(), ","));
            newTicketWebhook.setPrivilegesSet(CommonUtils.getStringSetFromString(newTicketWebhook.getPrivileges(), ","));
            ObjectNode settings = getSettingsJsonFromPR(newTicketWebhook, newTicketWebhook.getCmId());
            ObjectNode settingJson = putOrGetSettingsDetails(newTicketWebhook, (ObjectNode) requestNode, settings, false);
            if (settingJson != null) {
                newTicketWebhook.setSettings(settingJson.toString());
            }
            if (webhookDao.saveTicketWebhook(newTicketWebhook)) {
                kafkaTicketWebhookListner.send(topic, newTicketWebhook);
                monolithicSyncUtil.sendObjectToMonolith(newTicketWebhook, oldTicketWebhook == null ? "add" : "update");
                responseNode.put("status", "success");
                responseNode.put("id", newTicketWebhook.getId());
                responseNode.put("response", "webhook api " + (oldTicketWebhook == null ? "added" : "updated") + " successfully");
            }
        } catch (Exception e) {
            LOGGER.error("Error in addOrUpdateWebhookApi()", e);
        }
        return responseNode;
    }
@PostMapping("/add-update-bb-department")
    public ResponseEntity<JSONObject> addOrUpdateBBDepartment(@RequestBody JSONObject jsonObject) {
        JSONObject responseJson = null;
        try {
            responseJson = bbService.addOrUpdateBBDepartment(jsonObject);
        } catch (Exception e) {
            LOGGER.error("Error in addOrUpdateBBDepartment() method !! ", e);
        }
        return new ResponseEntity<JSONObject>(responseJson, HttpStatus.CREATED);
    }
public JSONObject addOrUpdateYoutubeConfiguration(HttpServletRequest request, HttpServletResponse response, JSONObject jsonObject) {
        JSONObject responseJsonObject = TicketConfigurationUtility.getResponseJSONObject();
        try {

            String[] mandatoryFileds = { "channelName", "channelId", "clientId", "authTokenExpireTime", "authToken", "createDate", "clientSecret",
                    "refreshToken" };

            responseJsonObject = TicketConfigurationUtility.checkMandatoryFields(jsonObject, mandatoryFileds);
            if (responseJsonObject.containsKey("Error")) {
                return responseJsonObject;
            }

            PartnerUser partnerUser = SessionManager.getPartnerUser(request);
            int cmId = partnerUser.getCmId();
            boolean enable = jsonObject.optBoolean("enabled");
            boolean isMerge = jsonObject.optBoolean("isMerge");
            int updateId = TicketConfigurationUtility.getIntegerFromJSONObject(jsonObject, "id", 0);
            int slaTime = TicketConfigurationUtility.getIntegerFromJSONObject(jsonObject, "slaTime", 0);
            int folderId = TicketConfigurationUtility.getIntegerFromJSONObject(jsonObject, "folderId", 0);
            String channelName = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "channelName", "");
            String channelId = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "channelId", "");
            String clientId = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "clientId", "");
            String queueKey = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "queueKey", "");
            String authToken = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "authToken", "");
            int mergingTime = TicketConfigurationUtility.getIntegerFromJSONObject(jsonObject, "mergingTime", 0);
            String mergeGroup = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "mergeGroup", "");
            String lastReadTime = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "lastReadTime", "");
            String videoJsonStr = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "videoJsonStr", "");
            String clientSecret = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "clientSecret", "");
            String refreshToken = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "refreshToken", "");
            Character customerType = TicketConfigurationUtility.getCharFromJSONObject(jsonObject, "customerType", '-');
            boolean isSourceRestricted = jsonObject.has("enabled") && jsonObject.optBoolean("isSourceRestricted");
            int restrictedFolderId = TicketConfigurationUtility.getIntegerFromJSONObject(jsonObject, "restrictedFolderId", 0);
            Character mergeTaskStatus = TicketConfigurationUtility.getCharFromJSONObject(jsonObject, "mergetaskStatus", '-');
            String authTokenExpireTime = TicketConfigurationUtility.getStringFromJSONObject(jsonObject, "authTokenExpireTime", "");
            if (!isMerge) {
                mergingTime = 0;
                customerType = '-';
                mergeTaskStatus = '-';
            }
            Timestamp lastReadTimeTs = Timestamp.valueOf(lastReadTime);
            Timestamp authTokenExpireTimeTs = Timestamp.valueOf(authTokenExpireTime);
            YoutubeConfiguration object = youtubeConfigurationCache.getYoutubeConfigurationBasedOnId(updateId) != null
                    ? youtubeConfigurationCache.getYoutubeConfigurationBasedOnId(updateId)
                    : new YoutubeConfiguration();
            object.setCmId(cmId);
            object.setSlaTime(slaTime);
            object.setIsMerge(isMerge);
            object.setEnabled(enable);
            object.setChannelId(channelId);
            object.setChannelName(channelName);
            object.setClientId(clientId);
            object.setFolderId(folderId);
            object.setQueueKey(queueKey);
            object.setAuthToken(authToken);
            object.setMergeGroup(mergeGroup);
            object.setMergingTime(mergingTime);
            object.setVideoJsonStr(videoJsonStr);
            object.setClientSecret(clientSecret);
            object.setRefreshToken(refreshToken);
            object.setCustomerType(customerType);
            object.setLastReadTime(lastReadTimeTs);
            object.setMergetaskStatus(mergeTaskStatus);
            object.setIsFolderRestricted(isSourceRestricted);
            object.setRestrictedFolderId(restrictedFolderId);
            object.setAuthTokenExpireTime(authTokenExpireTimeTs);
            Timestamp currentTime = CommonUtils.getCurrentTimestamp();
            object.setLastModifiedTime(currentTime);

            if (object.getId() > 0) {
                youtubeConfigurationDao.saveYoutubeConfiguration(object);
                kafkaYoutubeConfigListener.send(youtubeConfigTopic, object);
                responseJsonObject.put("status", "success");
                responseJsonObject.put("body", object.getId());
                responseJsonObject.put("reason", "YoutubeConfiguration is updated successfully");
            } else {
                object.setCreateDate(currentTime);
                youtubeConfigurationDao.saveYoutubeConfiguration(object);
                kafkaYoutubeConfigListener.send(youtubeConfigTopic, object);
                responseJsonObject.put("status", "success");
                responseJsonObject.put("id", object.getId());
                responseJsonObject.put("reason", "YoutubeConfiguration is added successfully");
            }

        } catch (Exception e) {

            LOGGER.error("Error in addOrUpdateYoutubeConfiguration() method  ", e);
        }
        return responseJsonObject;
    }