Unverified Commit 3cd770f9 authored by Shishir Suman's avatar Shishir Suman Committed by GitHub
Browse files

Merge pull request #34 from UPHRH-platform/UPHRH_7903_mobile_otp

Uphrh 7903 mobile otp
No related merge requests found
Showing with 259 additions and 8 deletions
+259 -8
...@@ -118,6 +118,7 @@ ...@@ -118,6 +118,7 @@
<artifactId>maven-artifact-manager</artifactId> <artifactId>maven-artifact-manager</artifactId>
<version>2.2.1</version> <version>2.2.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
......
package org.upsmf.grievance; package org.upsmf.grievance;
import lombok.extern.slf4j.Slf4j;
import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.app.VelocityEngine;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
...@@ -7,12 +8,19 @@ import org.springframework.context.annotation.Bean; ...@@ -7,12 +8,19 @@ import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import java.util.Date;
import java.util.TimeZone;
@SpringBootApplication @SpringBootApplication
@EnableScheduling @EnableScheduling
@EnableJpaRepositories(basePackages = "org.upsmf.grievance") @EnableJpaRepositories(basePackages = "org.upsmf.grievance")
@Slf4j
public class GrievanceServiceApplication { public class GrievanceServiceApplication {
public static void main(String[] args) { public static void main(String[] args) {
TimeZone.setDefault(TimeZone.getTimeZone("GMT+5:30"));
log.info("Application time zone time is IST: " + new Date().toString());
SpringApplication.run(GrievanceServiceApplication.class, args); SpringApplication.run(GrievanceServiceApplication.class, args);
} }
......
...@@ -39,5 +39,19 @@ public class OtpController { ...@@ -39,5 +39,19 @@ public class OtpController {
} }
} }
@PostMapping("/generate-mobile-otp")
public ResponseEntity<String> generateMobileOtp(@RequestBody OtpRequest otpRequest) {
otpService.generateAndSendMobileOtp(otpRequest);
return ResponseEntity.ok("OTP generated and sent successfully");
}
@PostMapping("/validate-mobile-otp")
public ResponseEntity<String> validateMobileOtp(@RequestBody OtpValidationRequest otpValidationRequest) {
boolean isValid = otpService.validateMobileOtp(otpValidationRequest.getPhone(), otpValidationRequest.getOtp());
if (isValid) {
return ResponseEntity.ok("OTP validation successful.");
} else {
return ResponseEntity.badRequest().body("Invalid OTP.");
}
}
} }
package org.upsmf.grievance.controller; package org.upsmf.grievance.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -8,11 +9,16 @@ import org.springframework.web.bind.annotation.*; ...@@ -8,11 +9,16 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.upsmf.grievance.dto.TicketRequest; import org.upsmf.grievance.dto.TicketRequest;
import org.upsmf.grievance.dto.UpdateTicketRequest; import org.upsmf.grievance.dto.UpdateTicketRequest;
import org.upsmf.grievance.exception.CustomException;
import org.upsmf.grievance.exception.TicketException;
import org.upsmf.grievance.exception.UserException;
import org.upsmf.grievance.model.Ticket; import org.upsmf.grievance.model.Ticket;
import org.upsmf.grievance.model.reponse.Response; import org.upsmf.grievance.model.reponse.Response;
import org.upsmf.grievance.service.AttachmentService; import org.upsmf.grievance.service.AttachmentService;
import org.upsmf.grievance.service.TicketService; import org.upsmf.grievance.service.TicketService;
import org.upsmf.grievance.util.ErrorCode;
@Slf4j
@Controller @Controller
@RequestMapping("/api/ticket") @RequestMapping("/api/ticket")
public class TicketController { public class TicketController {
...@@ -28,9 +34,12 @@ public class TicketController { ...@@ -28,9 +34,12 @@ public class TicketController {
Ticket responseTicket = null; Ticket responseTicket = null;
try { try {
responseTicket = ticketService.save(ticketRequest); responseTicket = ticketService.save(ticketRequest);
} catch (CustomException e) {
log.error("Error in while creating ticket - at controller");
throw new TicketException(e.getMessage(), ErrorCode.TKT_001, "Error while trying to create ticket");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("Internal server error while creating ticket", e);
throw new RuntimeException(e.getMessage()); throw new TicketException("Internal server error while creating ticket", ErrorCode.TKT_002, e.getMessage());
} }
Response response = new Response(HttpStatus.OK.value(), responseTicket); Response response = new Response(HttpStatus.OK.value(), responseTicket);
return new ResponseEntity<Response>(response, HttpStatus.OK); return new ResponseEntity<Response>(response, HttpStatus.OK);
......
package org.upsmf.grievance.controller; package org.upsmf.grievance.controller;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -9,13 +10,16 @@ import org.springframework.web.bind.annotation.*; ...@@ -9,13 +10,16 @@ import org.springframework.web.bind.annotation.*;
import org.upsmf.grievance.dto.CreateUserDto; import org.upsmf.grievance.dto.CreateUserDto;
import org.upsmf.grievance.dto.UpdateUserDto; import org.upsmf.grievance.dto.UpdateUserDto;
import org.upsmf.grievance.dto.UserResponseDto; import org.upsmf.grievance.dto.UserResponseDto;
import org.upsmf.grievance.exception.CustomException;
import org.upsmf.grievance.exception.UserException;
import org.upsmf.grievance.model.Department; import org.upsmf.grievance.model.Department;
import org.upsmf.grievance.model.User; import org.upsmf.grievance.model.User;
import org.upsmf.grievance.service.IntegrationService; import org.upsmf.grievance.service.IntegrationService;
import org.upsmf.grievance.util.ErrorCode;
import java.util.*; import java.util.*;
@Slf4j
@Controller @Controller
@RequestMapping("/api/user") @RequestMapping("/api/user")
public class UserController { public class UserController {
...@@ -38,14 +42,18 @@ public class UserController { ...@@ -38,14 +42,18 @@ public class UserController {
@PostMapping("/create-user") @PostMapping("/create-user")
public ResponseEntity createUser(@RequestBody CreateUserDto userRequest) { public ResponseEntity createUser(@RequestBody CreateUserDto userRequest) {
try { try {
ResponseEntity<User> user = integrationService.createUser(userRequest); ResponseEntity<User> user = integrationService.createUser(userRequest);
if(user.getStatusCode() == HttpStatus.OK) { if (user.getStatusCode() == HttpStatus.OK) {
return createUserResponse(user.getBody()); return createUserResponse(user.getBody());
} else { } else {
return ResponseEntity.internalServerError().build(); log.error("Error unable to create user - doesn't receive created user");
throw new UserException("Unable to create user", ErrorCode.USER_003, "Error while trying to create user");
} }
} catch (CustomException e) {
log.error("Error in while creating user - at controller");
throw new UserException(e.getMessage(), ErrorCode.USER_003, "Error while trying to create user");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("Error while creating user", e);
return ResponseEntity.internalServerError().body(e.getLocalizedMessage()); return ResponseEntity.internalServerError().body(e.getLocalizedMessage());
} }
} }
......
...@@ -23,5 +23,6 @@ public class TicketRequest { ...@@ -23,5 +23,6 @@ public class TicketRequest {
private String description; private String description;
private List<String> attachmentUrls; private List<String> attachmentUrls;
private String otp; private String otp;
private String mobileOtp;
} }
...@@ -23,4 +23,5 @@ public class UpdateTicketRequest { ...@@ -23,4 +23,5 @@ public class UpdateTicketRequest {
private String comment; private String comment;
private List<String> assigneeAttachmentURLs; private List<String> assigneeAttachmentURLs;
private Boolean isJunk; private Boolean isJunk;
private Boolean isNudged;
} }
...@@ -2,7 +2,7 @@ package org.upsmf.grievance.enums; ...@@ -2,7 +2,7 @@ package org.upsmf.grievance.enums;
public enum RequesterType { public enum RequesterType {
CANDIDATE(1), INSTITUTE(2), FACULTY(3), OTHERS(4); CANDIDATE(1), INSTITUTE(2), FACULTY(3), OTHERS(4), PUBLIC(5);
private int id; private int id;
RequesterType(int id) { RequesterType(int id) {
......
package org.upsmf.grievance.exception;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.upsmf.grievance.util.ErrorCode;
@Data
@NoArgsConstructor
public class CustomException extends RuntimeException {
private String description;
private ErrorCode errorCode;
public CustomException(String message) {
super(message);
}
public CustomException(String message, String description) {
super(message);
this.description = description;
}
public CustomException(String message, ErrorCode errorCode) {
super(message);
this.errorCode = errorCode;
}
public CustomException(String message, ErrorCode errorCode, String description) {
super(message);
this.description = description;
this.errorCode = errorCode;
}
}
package org.upsmf.grievance.exception;
import org.upsmf.grievance.util.ErrorCode;
public class DataUnavailabilityException extends CustomException {
public DataUnavailabilityException(String message) {
super(message);
}
public DataUnavailabilityException(String message, String description) {
super(message, description);
}
public DataUnavailabilityException(String message, ErrorCode errorCode) {
super(message, errorCode);
}
public DataUnavailabilityException(String message, ErrorCode errorCode, String description) {
super(message, errorCode, description);
}
}
package org.upsmf.grievance.exception;
import org.upsmf.grievance.util.ErrorCode;
public class OtpException extends CustomException {
public OtpException(String message) {
super(message);
}
public OtpException(String message, String description) {
super(message, description);
}
public OtpException(String message, ErrorCode errorCode) {
super(message, errorCode);
}
public OtpException(String message, ErrorCode errorCode, String description) {
super(message, errorCode, description);
}
}
package org.upsmf.grievance.exception;
import org.upsmf.grievance.util.ErrorCode;
public class TicketException extends CustomException {
public TicketException(String message) {
super(message);
}
public TicketException(String message, String description) {
super(message, description);
}
public TicketException(String message, ErrorCode errorCode) {
super(message, errorCode);
}
public TicketException(String message, ErrorCode errorCode, String description) {
super(message, errorCode, description);
}
}
package org.upsmf.grievance.exception;
import org.upsmf.grievance.util.ErrorCode;
public class UserException extends CustomException {
public UserException(String message) {
super(message);
}
public UserException(String message, String description) {
super(message, description);
}
public UserException(String message, ErrorCode errorCode) {
super(message, errorCode);
}
public UserException(String message, ErrorCode errorCode, String description) {
super(message, errorCode, description);
}
}
package org.upsmf.grievance.exception.controller; package org.upsmf.grievance.exception.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.upsmf.grievance.dto.ErrorResponseDto; import org.upsmf.grievance.dto.ErrorResponseDto;
import org.upsmf.grievance.exception.CustomException;
import org.upsmf.grievance.exception.runtime.InvalidRequestException; import org.upsmf.grievance.exception.runtime.InvalidRequestException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ControllerAdvice @ControllerAdvice
public class ExceptionHandler4xxController { public class ExceptionHandler4xxController {
private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionHandler4xxController.class);
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<Map<String, List<String>>> handleValidationErrors(MethodArgumentNotValidException exception) {
List<String> errors = exception.getBindingResult().getFieldErrors().stream()
.map(FieldError::getDefaultMessage)
.collect(Collectors.toList());
return new ResponseEntity<>(getErrorsMap(errors), new HttpHeaders(), HttpStatus.BAD_REQUEST);
}
/** /**
* Exception handler for Invalid request exception * Exception handler for Invalid request exception
* @param e * @param e
...@@ -21,4 +45,26 @@ public class ExceptionHandler4xxController { ...@@ -21,4 +45,26 @@ public class ExceptionHandler4xxController {
return new ErrorResponseDto(HttpStatus.BAD_REQUEST.value(), e.getMessage()); return new ErrorResponseDto(HttpStatus.BAD_REQUEST.value(), e.getMessage());
} }
@ExceptionHandler(CustomException.class)
public ResponseEntity<Map<String, Object>> handleNotFoundException(CustomException exception) {
return new ResponseEntity<>(generateErrorMap(exception), new HttpHeaders(), HttpStatus.BAD_REQUEST);
}
private Map<String, List<String>> getErrorsMap(List<String> errors) {
Map<String, List<String>> errorResponse = new HashMap<>();
errorResponse.put("errors", errors);
return errorResponse;
}
private Map<String, Object> generateErrorMap(CustomException exception) {
Map<String, Object> errorResponse = new HashMap<>();
String errorCode = exception.getErrorCode() != null ? exception.getErrorCode().name() : "NA";
errorResponse.put("error_code", errorCode);
errorResponse.put("error_message", exception.getMessage());
errorResponse.put("description", exception.getDescription());
return errorResponse;
}
} }
...@@ -12,4 +12,5 @@ public class OtpValidationRequest { ...@@ -12,4 +12,5 @@ public class OtpValidationRequest {
private String email; private String email;
private String otp; private String otp;
private String phone;
} }
package org.upsmf.grievance.model; package org.upsmf.grievance.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*; import lombok.*;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
...@@ -49,9 +50,14 @@ public class Ticket { ...@@ -49,9 +50,14 @@ public class Ticket {
@Column(name = "is_junk") @Column(name = "is_junk")
private boolean junk = false; private boolean junk = false;
@Column(name = "junked_by")
private String junkedBy;
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.S", timezone = "Asia/Kolkata")
@Column(name = "created_date") @Column(name = "created_date")
private Timestamp createdDate; private Timestamp createdDate;
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.S", timezone = "Asia/Kolkata")
@Column(name = "updated_date") @Column(name = "updated_date")
private Timestamp updatedDate; private Timestamp updatedDate;
...@@ -64,6 +70,7 @@ public class Ticket { ...@@ -64,6 +70,7 @@ public class Ticket {
@Column(name = "is_escalated_to_admin") @Column(name = "is_escalated_to_admin")
private boolean escalatedToAdmin; private boolean escalatedToAdmin;
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.S", timezone = "Asia/Kolkata")
@Column(name = "escalated_date") @Column(name = "escalated_date")
private Timestamp escalatedDate; private Timestamp escalatedDate;
...@@ -83,6 +90,9 @@ public class Ticket { ...@@ -83,6 +90,9 @@ public class Ticket {
@Column(name = "escalated_by") @Column(name = "escalated_by")
private String escalatedBy = "-1"; private String escalatedBy = "-1";
@Column(name = "reminder_counter")
private Long reminderCounter = 0L;
@OneToMany(targetEntity = Comments.class, mappedBy = "ticketId", fetch = FetchType.EAGER) @OneToMany(targetEntity = Comments.class, mappedBy = "ticketId", fetch = FetchType.EAGER)
@Fetch(value = FetchMode.SUBSELECT) @Fetch(value = FetchMode.SUBSELECT)
private List<Comments> comments; private List<Comments> comments;
......
package org.upsmf.grievance.model.es; package org.upsmf.grievance.model.es;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*; import lombok.*;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
...@@ -8,6 +9,8 @@ import org.upsmf.grievance.enums.RequesterType; ...@@ -8,6 +9,8 @@ import org.upsmf.grievance.enums.RequesterType;
import org.upsmf.grievance.enums.TicketPriority; import org.upsmf.grievance.enums.TicketPriority;
import org.upsmf.grievance.enums.TicketStatus; import org.upsmf.grievance.enums.TicketStatus;
import javax.persistence.Column;
@Document(indexName = "ticket", createIndex = false) @Document(indexName = "ticket", createIndex = false)
@Getter @Getter
@Setter @Setter
...@@ -50,9 +53,14 @@ public class Ticket { ...@@ -50,9 +53,14 @@ public class Ticket {
@Field(name = "is_junk") @Field(name = "is_junk")
private Boolean junk = false; private Boolean junk = false;
@Field(name = "junked_by")
private String junkedBy;
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.S", timezone = "Asia/Kolkata")
@Field(name = "created_date") @Field(name = "created_date")
private String createdDate; private String createdDate;
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.S", timezone = "Asia/Kolkata")
@Field(name = "updated_date") @Field(name = "updated_date")
private String updatedDate; private String updatedDate;
...@@ -68,6 +76,7 @@ public class Ticket { ...@@ -68,6 +76,7 @@ public class Ticket {
@Field(name = "is_escalated") @Field(name = "is_escalated")
private Boolean escalated; private Boolean escalated;
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.S", timezone = "Asia/Kolkata")
@Field(name = "escalated_date") @Field(name = "escalated_date")
private String escalatedDate; private String escalatedDate;
...@@ -96,4 +105,7 @@ public class Ticket { ...@@ -96,4 +105,7 @@ public class Ticket {
@Field(name ="is_escalated_to_admin") @Field(name ="is_escalated_to_admin")
private Boolean escalatedToAdmin; private Boolean escalatedToAdmin;
@Field(name = "reminder_counter")
private Long reminderCounter;
} }
package org.upsmf.grievance.repository; package org.upsmf.grievance.repository;
import io.lettuce.core.dynamic.annotation.Param; import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -17,4 +19,10 @@ public interface UserRepository extends PagingAndSortingRepository<User,Long> { ...@@ -17,4 +19,10 @@ public interface UserRepository extends PagingAndSortingRepository<User,Long> {
@Query(value = "select u from users u where u.id = :id", nativeQuery = true) @Query(value = "select u from users u where u.id = :id", nativeQuery = true)
User findByUserId(@Param("id") Long id); User findByUserId(@Param("id") Long id);
@Query("SELECT u FROM User u WHERE LOWER(u.email) LIKE LOWER(CONCAT('%', ?1,'%')) "
+ "OR LOWER(u.firstName) LIKE LOWER(CONCAT('%', ?1,'%'))"
+ "OR LOWER(u.lastname) LIKE LOWER(CONCAT('%', ?1,'%'))"
+ "OR LOWER(u.phoneNumber) LIKE LOWER(CONCAT('%', ?1,'%'))")
Page<User> findByEmailWithPagination(String searchKeyword, Pageable pageable);
} }
...@@ -24,4 +24,6 @@ public interface EmailService { ...@@ -24,4 +24,6 @@ public interface EmailService {
void sendMailWithAttachment(EmailDetails details); void sendMailWithAttachment(EmailDetails details);
void sendMailToDGME(EmailDetails details, JsonNode assessmentMatrix); void sendMailToDGME(EmailDetails details, JsonNode assessmentMatrix);
public void sendMailToNodalOfficers(EmailDetails details, Ticket ticket);
} }
...@@ -6,6 +6,7 @@ import org.springframework.http.ResponseEntity; ...@@ -6,6 +6,7 @@ import org.springframework.http.ResponseEntity;
import org.upsmf.grievance.dto.CreateUserDto; import org.upsmf.grievance.dto.CreateUserDto;
import org.upsmf.grievance.dto.UpdateUserDto; import org.upsmf.grievance.dto.UpdateUserDto;
import org.upsmf.grievance.dto.UserResponseDto; import org.upsmf.grievance.dto.UserResponseDto;
import org.upsmf.grievance.model.OtpRequest;
import org.upsmf.grievance.model.User; import org.upsmf.grievance.model.User;
public interface IntegrationService { public interface IntegrationService {
...@@ -30,4 +31,6 @@ public interface IntegrationService { ...@@ -30,4 +31,6 @@ public interface IntegrationService {
User deactivateUser(JsonNode payload) throws Exception; User deactivateUser(JsonNode payload) throws Exception;
ResponseEntity<String> login(JsonNode body); ResponseEntity<String> login(JsonNode body);
Boolean sendMobileOTP(String name, String phoneNumber, String otp);
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment