Skip to content

Commit

Permalink
feature/registration-otp-mail-sending
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-zip committed May 20, 2024
1 parent 6078ea6 commit 046bb21
Show file tree
Hide file tree
Showing 31 changed files with 1,188 additions and 2 deletions.
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
<artifactId>logstash-logback-encoder</artifactId>
<version>6.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright © 2023-2024 Rohit Parihar and Bloggios
* All rights reserved.
* This software is the property of Rohit Parihar and is protected by copyright law.
* The software, including its source code, documentation, and associated files, may not be used, copied, modified, distributed, or sublicensed without the express written consent of Rohit Parihar.
* For licensing and usage inquiries, please contact Rohit Parihar at [email protected], or you can also contact [email protected].
* This software is provided as-is, and no warranties or guarantees are made regarding its fitness for any particular purpose or compatibility with any specific technology.
* For license information and terms of use, please refer to the accompanying LICENSE file or visit http://www.apache.org/licenses/LICENSE-2.0.
* Unauthorized use of this software may result in legal action and liability for damages.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bloggios.email.configuration;

import com.bloggios.email.constants.BeanNameConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
* Owner - Rohit Parihar
* Author - rohit
* Project - bloggios-email-service
* Package - com.bloggios.email.configuration
* Created_on - 04 May-2024
* Created_at - 20 : 07
*/

@Configuration
public class ApplicationBeans {

@Bean(BeanNameConstants.ASYNC_TASK_INTERNAL_POOL)
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(20);
executor.setThreadNamePrefix("mail-internal-pool-");
executor.setAllowCoreThreadTimeOut(true);
executor.setKeepAliveSeconds(60);
executor.initialize();
return executor;
}

@Bean(BeanNameConstants.ASYNC_TASK_EXTERNAL_POOL)
public TaskExecutor externalExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(7);
executor.setMaxPoolSize(16);
executor.setQueueCapacity(40);
executor.setThreadNamePrefix("user-external-pool-");
executor.setAllowCoreThreadTimeOut(true);
executor.setKeepAliveSeconds(60);
executor.initialize();
return executor;
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/bloggios/email/configuration/MailConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.bloggios.email.configuration;

import com.bloggios.email.constants.BeanNameConstants;
import com.bloggios.email.constants.EnvironmentConstants;
import com.bloggios.email.properties.MailProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Objects;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - bloggios-email-service
* Package - com.bloggios.email.configuration
* Created_on - May 05 - 2024
* Created_at - 16:17
*/

@Configuration
public class MailConfig {

private final Environment environment;

public MailConfig(
Environment environment
) {
this.environment = environment;
}

@Bean(BeanNameConstants.GOOGLE_MAIL_SENDER_BEAN)
public JavaMailSender getGoogleMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(environment.getProperty(EnvironmentConstants.GOOGLE_MAIL_HOST));
mailSender.setPort(Integer.parseInt(Objects.requireNonNull(environment.getProperty(EnvironmentConstants.GOOGLE_MAIL_PORT))));
mailSender.setUsername(environment.getProperty(EnvironmentConstants.GOOGLE_MAIL_USERNAME));
mailSender.setPassword(environment.getProperty(EnvironmentConstants.GOOGLE_MAIL_PASSWORD));
MailProperties.mailProperties(mailSender);
return mailSender;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public class BeanNameConstants {

public static final String INCOMING_MESSAGE_FACTORY_COMPONENT = "incomingMessageFactoryComponent";
public static final String MANAGEMENT_CONSUMER_FACTORY = "managementConsumerFactory";
public static final String ASYNC_TASK_INTERNAL_POOL = "asyncTaskInternalPool";
public static final String ASYNC_TASK_EXTERNAL_POOL = "asyncTaskExternalPool";
public static final String GOOGLE_MAIL_SENDER_BEAN = "googleMailSenderBean";
public static final String ERROR_CODES_BEAN = "errorCodesBean";
public static final String REGISTER_OTP_EVENT_PROCESSOR = "registerOtpEventProcessor";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public class EnvironmentConstants {

public static final String KAFKA_GROUP_ID = "mail-service.kafka.group-id";
public static final String REGISTRATION_OTP_TOPIC = "mail-service.kafka.consumer.topics.registration-otp";
public static final String GOOGLE_MAIL_HOST = "mail-configuration.google-mail.host";
public static final String GOOGLE_MAIL_PORT = "mail-configuration.google-mail.port";
public static final String GOOGLE_MAIL_PASSWORD = "mail-configuration.google-mail.password";
public static final String GOOGLE_MAIL_USERNAME = "mail-configuration.google-mail.username";
public static final String APPLICATION_VERSION = "application.version";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
public class InternalErrorCodes {

public static final String JSON_DESERIALIZATION = "IE__MAIL-1001";
public static final String EXCEPTION_CODES = "IE__MAIL-1002";
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public class ServiceConstants {
public static final String TOPICS = "Topics";
public static final String SERVICE_NAME = "ServiceName";
public static final String SERVICE_CONTAINER_FACTORY_NAME = "ServiceContainerFactoryName";
public static final String RANDOM_UUID = "randomUUID";
public static final String BREADCRUMB_ID = "breadcrumbId";
}
62 changes: 62 additions & 0 deletions src/main/java/com/bloggios/email/dao/PgAbstractDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright © 2023-2024 Rohit Parihar and Bloggios
* All rights reserved.
* This software is the property of Rohit Parihar and is protected by copyright law.
* The software, including its source code, documentation, and associated files, may not be used, copied, modified, distributed, or sublicensed without the express written consent of Rohit Parihar.
* For licensing and usage inquiries, please contact Rohit Parihar at [email protected], or you can also contact [email protected].
* This software is provided as-is, and no warranties or guarantees are made regarding its fitness for any particular purpose or compatibility with any specific technology.
* For license information and terms of use, please refer to the accompanying LICENSE file or visit http://www.apache.org/licenses/LICENSE-2.0.
* Unauthorized use of this software may result in legal action and liability for damages.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bloggios.email.dao;

import com.bloggios.email.enums.DaoStatus;
import org.springframework.data.jpa.repository.JpaRepository;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - auth-server
* Package - com.bloggios.authserver.dao
* Created_on - May 02 - 2024
* Created_at - 12:33
*/

public abstract class PgAbstractDao<A, B extends JpaRepository<A, String>> {

protected final B repository;

protected PgAbstractDao(
B repository
) {
this.repository = repository;
}

public final A initOperation(DaoStatus status, A a) {
return switch (status) {
case CREATE -> initCreate(a);
case UPDATE -> initUpdate(a);
};
}

protected A initUpdate(A a) {
return repository.save(a);
}

protected A initCreate(A a) {
return repository.save(a);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bloggios.email.dao.implementation.pgabstractdao;

import com.bloggios.email.dao.PgAbstractDao;
import com.bloggios.email.dao.repository.pgrepository.MailHistoryRepository;
import com.bloggios.email.entity.MailHistoryEntity;
import org.springframework.stereotype.Component;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - bloggios-email-service
* Package - com.bloggios.email.dao.implementation.pgabstractdao
* Created_on - May 06 - 2024
* Created_at - 20:03
*/

@Component
public class MailHistoryEntityDao extends PgAbstractDao<MailHistoryEntity, MailHistoryRepository> {

public MailHistoryEntityDao(MailHistoryRepository repository) {
super(repository);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bloggios.email.dao.repository.pgrepository;

import com.bloggios.email.entity.MailHistoryEntity;
import org.springframework.data.jpa.repository.JpaRepository;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - bloggios-email-service
* Package - com.bloggios.email.dao.repository.pgrepository
* Created_on - May 06 - 2024
* Created_at - 20:02
*/

public interface MailHistoryRepository extends JpaRepository<MailHistoryEntity, String> {
}
46 changes: 46 additions & 0 deletions src/main/java/com/bloggios/email/entity/MailHistoryEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.bloggios.email.entity;

import com.bloggios.email.constants.ServiceConstants;
import com.bloggios.email.enums.MailFor;
import com.bloggios.email.enums.MailProvider;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - bloggios-email-service
* Package - com.bloggios.email.entity
* Created_on - May 06 - 2024
* Created_at - 19:49
*/

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@Table(name = "mail_history")
public class MailHistoryEntity {

@Id
@GeneratedValue(generator = ServiceConstants.RANDOM_UUID)
@GenericGenerator(name = ServiceConstants.RANDOM_UUID, strategy = "org.hibernate.id.UUIDGenerator")
private String mailHistoryId;

private String mailTo;
private String mailContent;
private MailProvider mailProvider;
private MailFor mailFor;
private Date dateSent;
private String apiVersion;
}
16 changes: 16 additions & 0 deletions src/main/java/com/bloggios/email/enums/DaoStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bloggios.email.enums;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - auth-server
* Package - com.bloggios.authserver.enums
* Created_on - May 02 - 2024
* Created_at - 15:25
*/

public enum DaoStatus {

CREATE,
UPDATE
}
15 changes: 15 additions & 0 deletions src/main/java/com/bloggios/email/enums/MailFor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.bloggios.email.enums;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - bloggios-email-service
* Package - com.bloggios.email.enums
* Created_on - May 06 - 2024
* Created_at - 19:57
*/

public enum MailFor {

REGISTER_OTP
}
16 changes: 16 additions & 0 deletions src/main/java/com/bloggios/email/enums/MailProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bloggios.email.enums;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - bloggios-email-service
* Package - com.bloggios.email.enums
* Created_on - May 06 - 2024
* Created_at - 19:56
*/

public enum MailProvider {

GMAIL,
GODADDY
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bloggios.email.exceptions.payloads;

import com.bloggios.email.exceptions.ExceptionProvider;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - bloggios-email-service
* Package - com.bloggios.email.exceptions.payloads
* Created_on - May 20 - 2024
* Created_at - 20:29
*/

@Getter
@EqualsAndHashCode(callSuper = true)
public class InternalException extends ExceptionProvider {

public InternalException(String code) {
super(code);
}
}
Loading

0 comments on commit 046bb21

Please sign in to comment.