diff --git a/core/src/main/java/io/aiven/klaw/model/enums/MailType.java b/core/src/main/java/io/aiven/klaw/model/enums/MailType.java deleted file mode 100644 index c4952be31c..0000000000 --- a/core/src/main/java/io/aiven/klaw/model/enums/MailType.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.aiven.klaw.model.enums; - -public enum MailType { - TOPIC_CREATE_REQUESTED, - TOPIC_PROMOTION_REQUESTED, - CONNECTOR_CREATE_REQUESTED, - TOPIC_DELETE_REQUESTED, - CONNECTOR_DELETE_REQUESTED, - TOPIC_CLAIM_REQUESTED, - CONNECTOR_CLAIM_REQUESTED, - TOPIC_REQUEST_APPROVED, - CONNECTOR_REQUEST_APPROVED, - TOPIC_REQUEST_DENIED, - CONNECTOR_REQUEST_DENIED, - ACL_REQUESTED, - ACL_DELETE_REQUESTED, - ACL_REQUEST_APPROVED, - ACL_REQUEST_APPROVAL_ADDED, - ACL_REQUEST_DENIED, - ACL_REQUEST_FAILURE, - SCHEMA_REQUESTED, - SCHEMA_REQUEST_APPROVED, - SCHEMA_REQUEST_DENIED, - REGISTER_USER_REQUEST, - TOPIC_UPDATE_REQUESTED, - SCHEMA_PROMOTION_REQUESTED, - SCHEMA_APPROVED_NOTIFY_SUBSCRIBERS, - NEW_USER_ADDED, - RESET_CONSUMER_OFFSET_REQUESTED, - RESET_CONSUMER_OFFSET_APPROVED, - RESET_CONSUMER_OFFSET_DENIED -} diff --git a/core/src/main/java/io/aiven/klaw/service/AclControllerService.java b/core/src/main/java/io/aiven/klaw/service/AclControllerService.java index 68ac90aad7..9a293924f1 100644 --- a/core/src/main/java/io/aiven/klaw/service/AclControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/AclControllerService.java @@ -10,7 +10,12 @@ import static io.aiven.klaw.error.KlawErrorMessages.REQ_ERR_101; import static io.aiven.klaw.helpers.KwConstants.REQUESTOR_SUBSCRIPTIONS; import static io.aiven.klaw.helpers.UtilMethods.updateEnvStatus; -import static io.aiven.klaw.model.enums.MailType.*; +import static io.aiven.klaw.service.MailUtils.MailType.ACL_DELETE_REQUESTED; +import static io.aiven.klaw.service.MailUtils.MailType.ACL_REQUESTED; +import static io.aiven.klaw.service.MailUtils.MailType.ACL_REQUEST_APPROVAL_ADDED; +import static io.aiven.klaw.service.MailUtils.MailType.ACL_REQUEST_APPROVED; +import static io.aiven.klaw.service.MailUtils.MailType.ACL_REQUEST_DENIED; +import static io.aiven.klaw.service.MailUtils.MailType.ACL_REQUEST_FAILURE; import static org.springframework.beans.BeanUtils.copyProperties; import com.fasterxml.jackson.databind.ObjectMapper; @@ -34,6 +39,7 @@ import io.aiven.klaw.model.response.AclRequestsResponseModel; import io.aiven.klaw.model.response.OffsetDetails; import io.aiven.klaw.model.response.ServiceAccountDetails; +import io.aiven.klaw.service.MailUtils.MailType; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -206,7 +212,8 @@ void handleIpAddressAndCNString(AclRequestsModel aclRequestsModel, AclRequests a } private ApiResponse executeAclRequestModel( - String userDetails, AclRequests aclRequestsDao, MailType mailType) throws KlawException { + String userDetails, AclRequests aclRequestsDao, MailUtils.MailType mailType) + throws KlawException { try { String execRes = manageDatabase.getHandleDbRequests().requestForAcl(aclRequestsDao).get("result"); @@ -662,7 +669,7 @@ public ApiResponse approveAclRequests(String req_no) updateAclReqStatus = handleAclRequestClusterApiResponse(userDetails, dbHandle, aclReq, response, tenantId); - MailType notifyUserType = ACL_REQUEST_APPROVED; + MailUtils.MailType notifyUserType = ACL_REQUEST_APPROVED; if (!updateAclReqStatus.equals(ApiResultStatus.SUCCESS.value)) { notifyUserType = ACL_REQUEST_FAILURE; } else { diff --git a/core/src/main/java/io/aiven/klaw/service/ApprovalService.java b/core/src/main/java/io/aiven/klaw/service/ApprovalService.java index 7e034d4adf..d4b4769d6b 100644 --- a/core/src/main/java/io/aiven/klaw/service/ApprovalService.java +++ b/core/src/main/java/io/aiven/klaw/service/ApprovalService.java @@ -8,9 +8,9 @@ import io.aiven.klaw.error.KlawException; import io.aiven.klaw.helpers.HandleDbRequests; import io.aiven.klaw.model.enums.ApprovalType; -import io.aiven.klaw.model.enums.MailType; import io.aiven.klaw.model.enums.RequestEntityType; import io.aiven.klaw.model.enums.RequestOperationType; +import io.aiven.klaw.service.MailUtils.MailType; import java.util.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; diff --git a/core/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java b/core/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java index cfcbdf1967..259aafdc9d 100644 --- a/core/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java @@ -2,11 +2,11 @@ import static io.aiven.klaw.error.KlawErrorMessages.*; import static io.aiven.klaw.helpers.KwConstants.ORDER_OF_KAFKA_CONNECT_ENVS; -import static io.aiven.klaw.model.enums.MailType.CONNECTOR_CLAIM_REQUESTED; -import static io.aiven.klaw.model.enums.MailType.CONNECTOR_CREATE_REQUESTED; -import static io.aiven.klaw.model.enums.MailType.CONNECTOR_DELETE_REQUESTED; -import static io.aiven.klaw.model.enums.MailType.CONNECTOR_REQUEST_APPROVED; -import static io.aiven.klaw.model.enums.MailType.CONNECTOR_REQUEST_DENIED; +import static io.aiven.klaw.service.MailUtils.MailType.CONNECTOR_CLAIM_REQUESTED; +import static io.aiven.klaw.service.MailUtils.MailType.CONNECTOR_CREATE_REQUESTED; +import static io.aiven.klaw.service.MailUtils.MailType.CONNECTOR_DELETE_REQUESTED; +import static io.aiven.klaw.service.MailUtils.MailType.CONNECTOR_REQUEST_APPROVED; +import static io.aiven.klaw.service.MailUtils.MailType.CONNECTOR_REQUEST_DENIED; import static org.springframework.beans.BeanUtils.copyProperties; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/core/src/main/java/io/aiven/klaw/service/MailUtils.java b/core/src/main/java/io/aiven/klaw/service/MailUtils.java index 1ad0981392..2b5bcb9a48 100644 --- a/core/src/main/java/io/aiven/klaw/service/MailUtils.java +++ b/core/src/main/java/io/aiven/klaw/service/MailUtils.java @@ -8,7 +8,6 @@ import io.aiven.klaw.helpers.KwConstants; import io.aiven.klaw.helpers.UtilMethods; import io.aiven.klaw.model.enums.ApiResultStatus; -import io.aiven.klaw.model.enums.MailType; import io.aiven.klaw.model.enums.PermissionType; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +19,10 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.function.Function; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.function.TriFunction; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; @@ -68,34 +69,6 @@ public class MailUtils { private static final String REGISTER_USER_SAASADMIN_TOUSER_KEY = "klaw.mail.registerusertouser.saasadmin.content"; private static final String RECONCILIATION_TOPICS_KEY = "klaw.mail.recontopics.content"; - private String topicRequestMail; - - private String topicPromotionRequestMail; - private String topicUpdateRequestMail; - private String topicDeleteRequestMail; - private String topicClaimRequestMail; - private String topicRequestApproved; - private String topicRequestDenied; - private String aclRequestMail; - private String aclDeleteRequestMail; - private String aclRequestApproved; - private String aclRequestDenied; - - private void loadKwProps(int tenantId) { - this.topicRequestMail = manageDatabase.getKwPropertyValue(TOPIC_REQ_KEY, tenantId); - - this.topicUpdateRequestMail = manageDatabase.getKwPropertyValue(TOPIC_UPDATE_REQ_KEY, tenantId); - this.topicPromotionRequestMail = - manageDatabase.getKwPropertyValue(TOPIC_PROMOTION_REQ_KEY, tenantId); - this.topicDeleteRequestMail = manageDatabase.getKwPropertyValue(TOPIC_REQ_DEL_KEY, tenantId); - this.topicClaimRequestMail = manageDatabase.getKwPropertyValue(TOPIC_REQ_CLAIM_KEY, tenantId); - this.topicRequestApproved = manageDatabase.getKwPropertyValue(TOPIC_REQ_APPRVL_KEY, tenantId); - this.topicRequestDenied = manageDatabase.getKwPropertyValue(TOPIC_REQ_DENY_KEY, tenantId); - this.aclRequestMail = manageDatabase.getKwPropertyValue(ACL_REQ_KEY, tenantId); - this.aclDeleteRequestMail = manageDatabase.getKwPropertyValue(ACL_DELETE_REQ_KEY, tenantId); - this.aclRequestApproved = manageDatabase.getKwPropertyValue(ACL_REQ_APPRVL_KEY, tenantId); - this.aclRequestDenied = manageDatabase.getKwPropertyValue(ACL_REQ_DENY_KEY, tenantId); - } @Autowired ManageDatabase manageDatabase; @@ -119,168 +92,22 @@ void sendMail( HandleDbRequests dbHandle, MailType mailType, String loginUrl) { - String formattedStr = null, subject = null; int tenantId = manageDatabase .getHandleDbRequests() .getUsersInfo( getUserName(SecurityContextHolder.getContext().getAuthentication().getPrincipal())) .getTenantId(); - loadKwProps(tenantId); - boolean requiresApproval = false; - switch (mailType) { - case TOPIC_CREATE_REQUESTED -> { - formattedStr = String.format(topicRequestMail, "'" + topicName + "'"); - subject = "Create Topic Request"; - requiresApproval = true; - } - case TOPIC_PROMOTION_REQUESTED -> { - formattedStr = String.format(topicPromotionRequestMail, "'" + topicName + "'"); - subject = "Topic Promotion Request"; - requiresApproval = true; - } - case TOPIC_UPDATE_REQUESTED -> { - formattedStr = String.format(topicUpdateRequestMail, "'" + topicName + "'"); - subject = "Topic Update Request"; - requiresApproval = true; - } - case TOPIC_DELETE_REQUESTED -> { - formattedStr = String.format(topicDeleteRequestMail, "'" + topicName + "'"); - subject = "Delete Topic Request"; - requiresApproval = true; - } - case TOPIC_CLAIM_REQUESTED -> { - formattedStr = String.format(topicClaimRequestMail, "'" + topicName + "'"); - subject = "Claim Topic Request"; - requiresApproval = true; - } - case TOPIC_REQUEST_APPROVED -> { - formattedStr = String.format(topicRequestApproved, "'" + topicName + "'"); - subject = "Topic Request Approved"; - } - case TOPIC_REQUEST_DENIED -> { - formattedStr = - String.format(topicRequestDenied, "'" + topicName + "'", "'" + reasonToDecline + "'"); - subject = "Topic Request Denied"; - } - case ACL_REQUESTED -> { - formattedStr = String.format(aclRequestMail, "'" + acl + "'", "'" + topicName + "'"); - subject = "New Acl Request"; - requiresApproval = true; - } - case ACL_DELETE_REQUESTED -> { - formattedStr = String.format(aclDeleteRequestMail, "'" + acl + "'", "'" + topicName + "'"); - subject = "Acl Delete Request"; - requiresApproval = true; - } - case ACL_REQUEST_APPROVED -> { - formattedStr = String.format(aclRequestApproved, "'" + acl + "'", "'" + topicName + "'"); - subject = "Acl Request Approved"; - } - case ACL_REQUEST_APPROVAL_ADDED -> { - formattedStr = - String.format( - "Acl Request %s for topic %s has had an approval added to it.", - "'" + acl + "'", "'" + topicName + "'"); - subject = "Acl Request Approval Addded"; - } - case ACL_REQUEST_DENIED -> { - formattedStr = - String.format( - aclRequestDenied, - "'" + acl + "'", - "'" + topicName + "'", - "'" + reasonToDecline + "'"); - subject = "Acl Request Denied"; - } - case ACL_REQUEST_FAILURE -> { - formattedStr = "Acl Request processing failed : " + acl + ", " + topicName; - subject = "Request processing failed."; - } - case SCHEMA_REQUESTED -> { - requiresApproval = true; - subject = "New Schema Request"; - formattedStr = "New Schema Request on " + topicName; - } - case SCHEMA_PROMOTION_REQUESTED -> { - requiresApproval = true; - subject = "New Schema Promotion Request"; - formattedStr = "New Schema Promotion Request on " + topicName; - } - case CONNECTOR_DELETE_REQUESTED, CONNECTOR_CREATE_REQUESTED -> { - // all remaining requests that require approvals are grouped here. - requiresApproval = true; - subject = "New Connector Request"; - formattedStr = "New Connector Request on " + topicName; - } - case SCHEMA_REQUEST_APPROVED -> { - subject = "Schema Request Approved"; - formattedStr = "Schema Request on " + topicName + " approved by " + approverUsername; - } - case SCHEMA_REQUEST_DENIED -> { - subject = "Schema Request Denied"; - formattedStr = - "Schema Request on " - + topicName - + " denied by " - + approverUsername - + "because : " - + reasonToDecline; - } - case CONNECTOR_REQUEST_DENIED -> { - subject = "Connector Request Denied"; - formattedStr = - "Connector Request on " - + topicName - + " denied by " - + approverUsername - + "because : " - + reasonToDecline; - } - case CONNECTOR_REQUEST_APPROVED -> { - subject = "Connector Request Approved"; - formattedStr = "Connector Request on " + topicName + " approved by " + approverUsername; - } - case CONNECTOR_CLAIM_REQUESTED -> { - requiresApproval = true; - subject = "New Connector Claim Request"; - formattedStr = "New Claim on Connector " + topicName; - } - case RESET_CONSUMER_OFFSET_REQUESTED -> { - requiresApproval = true; - subject = "Reset Consumer Offsets Request"; - formattedStr = "Reset Consumer Offsets topic :" + topicName + "consumerGroup : " + acl; - } - case RESET_CONSUMER_OFFSET_APPROVED -> { - subject = "Reset Consumer Offsets Request Approved"; - formattedStr = - "Reset Consumer Offsets Request on " - + topicName - + " \n OffsetDetails : " - + acl - + "\napproved by " - + approverUsername; - } - case RESET_CONSUMER_OFFSET_DENIED -> { - subject = "Reset Consumer Offsets Request Denied"; - formattedStr = - "Reset Consumer Offsets Request on " - + topicName - + " \n Consumer group : " - + acl - + "\ndenied by " - + approverUsername; - } - } + MailInfo mailInfo = MailInfo.of(topicName, acl, reasonToDecline, username, approverUsername); sendRequestMail( approverUsername, username, ownerTeamId, dbHandle, - formattedStr, - subject, - requiresApproval, + mailType.apply(manageDatabase, tenantId, mailInfo), + mailType.getSubject(), + mailType.isRequiresApproval(), tenantId, loginUrl); } @@ -715,4 +542,263 @@ public String sendMailToSaasAdmin(int tenantId, String userName, String period, userName, kwAdminMailId, "Tenant Extension", mailtext, tenantId, loginUrl); return ApiResultStatus.SUCCESS.value; } + + public enum MailType { + TOPIC_CREATE_REQUESTED( + "Create Topic Request", + (manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(TOPIC_REQ_KEY, tenantId), + "'" + mailInfo.topicName + "'"), + true), + TOPIC_PROMOTION_REQUESTED( + "Topic Promotion Request", + (manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(TOPIC_PROMOTION_REQ_KEY, tenantId), + "'" + mailInfo.topicName + "'"), + true), + CONNECTOR_CREATE_REQUESTED( + "New Connector Request", m -> "New Connector Request on " + m.topicName, true), + TOPIC_DELETE_REQUESTED( + "Delete Topic Request", + (manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(TOPIC_REQ_DEL_KEY, tenantId), + "'" + mailInfo.topicName + "'"), + true), + CONNECTOR_DELETE_REQUESTED( + "New Connector Request", m -> "New Connector Request on " + m.topicName, true), + TOPIC_CLAIM_REQUESTED( + "Claim Topic Request", + (manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(TOPIC_REQ_CLAIM_KEY, tenantId), + "'" + mailInfo.topicName + "'"), + true), + CONNECTOR_CLAIM_REQUESTED( + "New Connector Claim Request", m -> "New Claim on Connector " + m.topicName, true), + TOPIC_REQUEST_APPROVED( + "Topic Request Approved", + (manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(TOPIC_REQ_APPRVL_KEY, tenantId), + "'" + mailInfo.topicName + "'"), + false), + CONNECTOR_REQUEST_APPROVED( + "Connector Request Approved", + m -> "Connector Request on " + m.topicName + " approved by " + m.approverUsername), + TOPIC_REQUEST_DENIED( + "Topic Request Denied", + (manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(TOPIC_REQ_DENY_KEY, tenantId), + "'" + mailInfo.topicName + "'", + "'" + mailInfo.reasonToDecline + "'"), + false), + CONNECTOR_REQUEST_DENIED( + "Connector Request Denied", + m -> + "Connector Request on " + + m.topicName + + " denied by " + + m.approverUsername + + "because : " + + m.reasonToDecline), + ACL_REQUESTED( + "New Acl Request", + (manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(ACL_REQ_KEY, tenantId), + "'" + mailInfo.acl + "'", + "'" + mailInfo.topicName + "'"), + true), + ACL_DELETE_REQUESTED( + "Acl Delete Request", + (manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(ACL_DELETE_REQ_KEY, tenantId), + "'" + mailInfo.acl + "'", + "'" + mailInfo.topicName + "'"), + true), + ACL_REQUEST_APPROVED( + "Acl Request Approved", + (manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(ACL_REQ_APPRVL_KEY, tenantId), + "'" + mailInfo.acl + "'", + "'" + mailInfo.topicName + "'"), + false), + ACL_REQUEST_APPROVAL_ADDED( + "Acl Request Approval Addded", + m -> + String.format( + "Acl Request %s for topic %s has had an approval added to it.", + "'" + m.acl + "'", "'" + m.topicName + "'")), + + ACL_REQUEST_DENIED( + "Acl Request Denied", + ((manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(ACL_REQ_DENY_KEY, tenantId), + "'" + mailInfo.acl + "'", + "'" + mailInfo.topicName + "'", + "'" + mailInfo.reasonToDecline + "'")), + false), + ACL_REQUEST_FAILURE( + "Request processing failed.", + m -> "Acl Request processing failed : " + m.acl + ", " + m.topicName), + SCHEMA_REQUESTED("New Schema Request", m -> "New Schema Request on " + m.topicName, true), + SCHEMA_REQUEST_APPROVED( + "Schema Request Approved", + m -> "Schema Request on " + m.topicName + " approved by " + m.approverUsername), + SCHEMA_REQUEST_DENIED( + "Schema Request Denied", + m -> + "Schema Request on " + + m.topicName + + " denied by " + + m.approverUsername + + "because : " + + m.reasonToDecline), + REGISTER_USER_REQUEST("TODO", (Function) null), + TOPIC_UPDATE_REQUESTED( + "Topic Update Request", + (manageDatabase, tenantId, mailInfo) -> + String.format( + manageDatabase.getKwPropertyValue(TOPIC_UPDATE_REQ_KEY, tenantId), + "'" + mailInfo.topicName + "'"), + false), + SCHEMA_PROMOTION_REQUESTED( + "New Schema Promotion Request", + m -> "New Schema Promotion Request on " + m.topicName, + true), + SCHEMA_APPROVED_NOTIFY_SUBSCRIBERS( + "New schema on a topic", + m -> + "A schema has been uploaded on Topic :" + + m.topicName + + " Environment : " + + m.acl + + " by team : " + + m.username), + NEW_USER_ADDED("TODO", (Function) null), + RESET_CONSUMER_OFFSET_REQUESTED( + "Reset Consumer Offsets Request", + m -> "Reset Consumer Offsets topic :" + m.topicName + "consumerGroup : " + m.acl, + true), + RESET_CONSUMER_OFFSET_APPROVED( + "Reset Consumer Offsets Request Approved", + m -> + "Reset Consumer Offsets Request on " + + m.topicName + + " \n OffsetDetails : " + + m.acl + + "\napproved by " + + m.approverUsername), + RESET_CONSUMER_OFFSET_DENIED( + "Reset Consumer Offsets Request Denied", + m -> + "Reset Consumer Offsets Request on " + + m.topicName + + " \n Consumer group : " + + m.acl + + "\ndenied by " + + m.approverUsername); + + private final String subject; + private final Function function; + private final TriFunction triFunction; + private final boolean requiresApproval; + + MailType(String subject, Function function, boolean requiresApproval) { + this.requiresApproval = requiresApproval; + this.subject = subject; + this.function = function; + this.triFunction = null; + } + + MailType( + String subject, + TriFunction triFunction, + boolean requiresApproval) { + this.requiresApproval = requiresApproval; + this.subject = subject; + this.triFunction = triFunction; + this.function = null; + } + + MailType(String subject, Function function) { + this(subject, function, false); + } + + MailType(String subject, TriFunction triFunction) { + this(subject, triFunction, false); + } + + public String apply(ManageDatabase manageDatabase, int tenantId, MailInfo mailInfo) { + if (triFunction != null) { + return triFunction.apply(manageDatabase, tenantId, mailInfo); + } + return function.apply(mailInfo); + } + + public String getSubject() { + return subject; + } + + public boolean isRequiresApproval() { + return requiresApproval; + } + } + + public static class MailInfo { + private final String topicName; + private final String acl; + private final String reasonToDecline; + private final String username; + private final String approverUsername; + + private MailInfo( + String topicName, + String acl, + String reasonToDecline, + String username, + String approverUsername) { + this.topicName = topicName; + this.acl = acl; + this.reasonToDecline = reasonToDecline; + this.username = username; + this.approverUsername = approverUsername; + } + + public static MailInfo of( + String topicName, + String acl, + String reasonToDecline, + String username, + String approverUsername) { + return new MailInfo(topicName, acl, reasonToDecline, username, approverUsername); + } + + public String getTopicName() { + return topicName; + } + + public String getAcl() { + return acl; + } + + public String getReasonToDecline() { + return reasonToDecline; + } + + public String getUsername() { + return username; + } + + public String getApproverUsername() { + return approverUsername; + } + } } diff --git a/core/src/main/java/io/aiven/klaw/service/OperationalRequestsService.java b/core/src/main/java/io/aiven/klaw/service/OperationalRequestsService.java index b17b04b724..544bfb8f2f 100644 --- a/core/src/main/java/io/aiven/klaw/service/OperationalRequestsService.java +++ b/core/src/main/java/io/aiven/klaw/service/OperationalRequestsService.java @@ -5,7 +5,7 @@ import static io.aiven.klaw.error.KlawErrorMessages.OP_REQS_ERR_103; import static io.aiven.klaw.error.KlawErrorMessages.REQ_ERR_101; import static io.aiven.klaw.error.KlawErrorMessages.TOPICS_ERR_101; -import static io.aiven.klaw.model.enums.MailType.RESET_CONSUMER_OFFSET_DENIED; +import static io.aiven.klaw.service.MailUtils.MailType.RESET_CONSUMER_OFFSET_DENIED; import static org.springframework.beans.BeanUtils.copyProperties; import io.aiven.klaw.config.ManageDatabase; @@ -21,7 +21,6 @@ import io.aiven.klaw.model.cluster.consumergroup.OffsetsTiming; import io.aiven.klaw.model.cluster.consumergroup.ResetConsumerGroupOffsetsRequest; import io.aiven.klaw.model.enums.ApiResultStatus; -import io.aiven.klaw.model.enums.MailType; import io.aiven.klaw.model.enums.OperationalRequestType; import io.aiven.klaw.model.enums.Order; import io.aiven.klaw.model.enums.PermissionType; @@ -131,7 +130,7 @@ public ApiResponse createConsumerOffsetsResetRequest( operationalRequest.getApprover(), operationalRequest.getRequestingTeamId(), dbHandle, - MailType.RESET_CONSUMER_OFFSET_REQUESTED, + MailUtils.MailType.RESET_CONSUMER_OFFSET_REQUESTED, commonUtilsService.getLoginUrl()); return ApiResultStatus.SUCCESS.value.equals(result) @@ -465,7 +464,7 @@ public ApiResponse approveOperationalRequests(String reqId) { operationalRequest.getApprover(), operationalRequest.getRequestingTeamId(), dbHandle, - MailType.RESET_CONSUMER_OFFSET_APPROVED, + MailUtils.MailType.RESET_CONSUMER_OFFSET_APPROVED, commonUtilsService.getLoginUrl()); } } diff --git a/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java b/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java index a9ffaf0832..c380a1e1a8 100644 --- a/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java @@ -12,7 +12,10 @@ import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_110; import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_111; import static io.aiven.klaw.helpers.UtilMethods.updateEnvStatus; -import static io.aiven.klaw.model.enums.MailType.*; +import static io.aiven.klaw.service.MailUtils.MailType.SCHEMA_APPROVED_NOTIFY_SUBSCRIBERS; +import static io.aiven.klaw.service.MailUtils.MailType.SCHEMA_REQUESTED; +import static io.aiven.klaw.service.MailUtils.MailType.SCHEMA_REQUEST_APPROVED; +import static io.aiven.klaw.service.MailUtils.MailType.SCHEMA_REQUEST_DENIED; import static org.springframework.beans.BeanUtils.copyProperties; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/core/src/main/java/io/aiven/klaw/service/TopicControllerService.java b/core/src/main/java/io/aiven/klaw/service/TopicControllerService.java index 7d1c662cbb..5195c41c19 100644 --- a/core/src/main/java/io/aiven/klaw/service/TopicControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/TopicControllerService.java @@ -19,7 +19,13 @@ import static io.aiven.klaw.error.KlawErrorMessages.TOPICS_VLD_ERR_121; import static io.aiven.klaw.helpers.KwConstants.ORDER_OF_TOPIC_ENVS; import static io.aiven.klaw.helpers.UtilMethods.updateEnvStatus; -import static io.aiven.klaw.model.enums.MailType.*; +import static io.aiven.klaw.service.MailUtils.MailType.TOPIC_CLAIM_REQUESTED; +import static io.aiven.klaw.service.MailUtils.MailType.TOPIC_CREATE_REQUESTED; +import static io.aiven.klaw.service.MailUtils.MailType.TOPIC_DELETE_REQUESTED; +import static io.aiven.klaw.service.MailUtils.MailType.TOPIC_PROMOTION_REQUESTED; +import static io.aiven.klaw.service.MailUtils.MailType.TOPIC_REQUEST_APPROVED; +import static io.aiven.klaw.service.MailUtils.MailType.TOPIC_REQUEST_DENIED; +import static io.aiven.klaw.service.MailUtils.MailType.TOPIC_UPDATE_REQUESTED; import static org.springframework.beans.BeanUtils.copyProperties; import com.fasterxml.jackson.core.JsonProcessingException; @@ -173,7 +179,7 @@ private ApiResponse createTopicRequest(TopicRequestModel topicRequestReq) throws : ApiResponse.notOk(result); } - private static MailType getMailType(TopicRequestModel topicRequestReq) { + private static MailUtils.MailType getMailType(TopicRequestModel topicRequestReq) { // default to Topic_CREATE which is the old hard coded return topicRequestReq.getRequestOperationType().equals(RequestOperationType.CREATE) ? TOPIC_CREATE_REQUESTED diff --git a/core/src/test/java/io/aiven/klaw/service/ApprovalServiceTest.java b/core/src/test/java/io/aiven/klaw/service/ApprovalServiceTest.java index d50bfa9de8..9403c4634d 100644 --- a/core/src/test/java/io/aiven/klaw/service/ApprovalServiceTest.java +++ b/core/src/test/java/io/aiven/klaw/service/ApprovalServiceTest.java @@ -13,7 +13,6 @@ import io.aiven.klaw.error.KlawException; import io.aiven.klaw.helpers.db.rdbms.HandleDbRequestsJdbc; import io.aiven.klaw.model.enums.ApprovalType; -import io.aiven.klaw.model.enums.MailType; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -329,7 +328,7 @@ public void sendEmailToApprovers() { createApproval(ALICE, 2, ApprovalType.TOPIC_TEAM_OWNER, null, null, null)); approvalService.sendEmailToApprovers( - JOHN, "SimpleTopic", null, null, MailType.TOPIC_CREATE_REQUESTED, approvals, 101); + JOHN, "SimpleTopic", null, null, MailUtils.MailType.TOPIC_CREATE_REQUESTED, approvals, 101); } @Test diff --git a/core/src/test/java/io/aiven/klaw/service/MailUtilsTest.java b/core/src/test/java/io/aiven/klaw/service/MailUtilsTest.java index c69ad15a65..3ede03f14c 100644 --- a/core/src/test/java/io/aiven/klaw/service/MailUtilsTest.java +++ b/core/src/test/java/io/aiven/klaw/service/MailUtilsTest.java @@ -10,8 +10,8 @@ import io.aiven.klaw.dao.UserInfo; import io.aiven.klaw.helpers.KwConstants; import io.aiven.klaw.helpers.db.rdbms.HandleDbRequestsJdbc; -import io.aiven.klaw.model.enums.MailType; import io.aiven.klaw.model.enums.PermissionType; +import io.aiven.klaw.service.MailUtils.MailType; import java.util.Collections; import java.util.HashMap; import java.util.List; diff --git a/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java b/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java index 6c8ae48c5c..9019c2430d 100644 --- a/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java +++ b/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java @@ -1,6 +1,6 @@ package io.aiven.klaw.service; -import static io.aiven.klaw.model.enums.MailType.SCHEMA_APPROVED_NOTIFY_SUBSCRIBERS; +import static io.aiven.klaw.service.MailUtils.MailType.SCHEMA_APPROVED_NOTIFY_SUBSCRIBERS; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any;