entity update with audit

This commit is contained in:
Lincpay Tech
2025-12-10 10:03:15 +05:30
83 changed files with 734 additions and 569 deletions
@@ -1,42 +0,0 @@
package com.billpaymentservice.bbps.audit;
import java.io.Serializable;
import java.util.Date;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.Data;
@Data
@MappedSuperclass
public abstract class Auditable<U> implements Serializable {
private static final long serialVersionUID = 1L;
@CreatedDate
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "create_date_time")
protected Date createDateTime;
@LastModifiedDate
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "updated_date_time")
protected Date updatedDateTime;
@LastModifiedBy
@Column(name = "updated_by")
protected U updatedBy;
@CreatedBy
@Column(name = "create_by")
protected U createdBy;
@Column(name = "is_deleted")
protected boolean isDeleted = false;
}
@@ -45,7 +45,7 @@ public class PaymentController {
@ApiResponse(responseCode = BBPSConstant.OK_STR, description = "Payment initiated successfully", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResponseModel.class))) })
@ApiDocCommonResponses
public ResponseEntity<ResponseModel> requestBillFetch(
@Validated @RequestBody BillPaymentRequest billPaymentRequest) {
@RequestBody BillPaymentRequest billPaymentRequest) {
ResponseModel response = paymentService.initiatePayment(billPaymentRequest);
return ResponseEntity.ok(response);
@@ -11,43 +11,33 @@ import lombok.Setter;
@Setter
public class BillPaymentRequest extends BaseClass {
@NotBlank(message = "ref id cannot be null or empty")
private String refId;
@NotBlank(message = "bill id cannot be null or empty")
private String billId;
// Change the field to Boolean (wrapper) type to allow @NotNull validation
@NotNull(message = "Amount options cannot be null.")
private boolean amountOptions; // Changed to Boolean (wrapper type)
@NotBlank(message = "payment mode cannot be null or empty")
private String paymentMode;
@NotBlank(message = "payment information cannot be null or empty")
private String paymentInformation;
@NotBlank(message = "biller id cannot be null or empty")
private String billerId;
@NotBlank(message = "biller name cannot be null or empty")
private String billerName;
@NotBlank(message = "biller category cannot be null or empty")
private String billerCategory;
private String macAdress;
private String customerMobNo;
@NotNull(message = "Transaction amount cannot be null.")
private Integer txnAmount; // Changed to @NotNull as it's an Integer (non-nullable)
private String txnAmount; // Changed to @NotNull as it's an Integer (non-nullable)
private String paymentRefId;
private String clientReqId;
@NotBlank(message = "payment channel cannot be null or empty")
private String paymentChannel;
private List<DeviceBlockTagRequest> deviceBlockTags;
@@ -29,7 +29,7 @@ public class BillPaymentForwardRequest {
private String billerCategory;
private String macAdress;
private String customerMobNo;
private Integer txnAmount;
private String txnAmount;
private String paymentRefId;
private String clientReqId;
private String paymentChannel;
@@ -15,7 +15,7 @@ import lombok.Setter;
@Table(name = "bbps_additional_info_bill")
@Getter
@Setter
public class AdditionalInfoBill {
public class AdditionalInfoBill extends Auditable {
@Id
@GeneratedValue
private Long id;
@@ -27,4 +27,4 @@ public class AdditionalInfoBill {
@JoinColumn(name = "bill_master_id")
private BillMaster billMaster;
}
}
@@ -14,7 +14,7 @@ import lombok.Setter;
@Table(name = "bbps_additional_info_bill_validate")
@Getter
@Setter
public class AdditionalInfoBillValidate {
public class AdditionalInfoBillValidate extends Auditable {
@Id
@GeneratedValue
private Long id;
@@ -26,4 +26,4 @@ public class AdditionalInfoBillValidate {
@JoinColumn(name = "bill_id_fk")
private BillValidation bill;
}
}
@@ -19,7 +19,7 @@ import lombok.Setter;
@Table(name = "bbps_plan_additional_info")
@Getter
@Setter
public class AdditionalInfoPlans {
public class AdditionalInfoPlans extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -30,4 +30,4 @@ public class AdditionalInfoPlans {
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "additionalInfo")
private List<PlanTag> tags;
}
}
@@ -15,7 +15,7 @@ import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
public class AgentFundTransfer {
public class AgentFundTransfer extends Auditable {
@Id
@@ -53,4 +53,4 @@ public class AgentFundTransfer {
@Column(name = "fund_status")
private String fundStatus;
}
}
@@ -14,7 +14,7 @@ import lombok.Setter;
@Getter
@Setter
@Table(name = "bbps_agent_fund_transfer")
public class AgentFundTransferEntity {
public class AgentFundTransferEntity extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -33,5 +33,4 @@ public class AgentFundTransferEntity {
private String agentNpciId;
private String txnRefId;
private String fundStatus;
}
}
@@ -19,7 +19,7 @@ import lombok.Setter;
@Table(name = "bbps_amount_option")
@Getter
@Setter
public class AmountOption {
public class AmountOption extends Auditable {
@Id
@Column(name = "amount_option_id")
@@ -2,8 +2,6 @@ package com.billpaymentservice.bbps.entites;
import java.util.List;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@@ -19,8 +17,9 @@ import lombok.Setter;
@Getter
@Setter
@Entity
@Table(name = "bbps_amount_option_biller_id")
public class AmountOptionByBillerId extends Auditable<String> {
public class AmountOptionByBillerId extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -33,4 +32,4 @@ public class AmountOptionByBillerId extends Auditable<String> {
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "amount_option_id_long") // Foreign key field that links to the 'Long' column
private List<AmountOptionDetails> amountOptionDetails; // List of AmountOptionDetails
}
}
@@ -13,7 +13,8 @@ import lombok.Setter;
@Setter
@Entity
@Table(name = "bbps_amount_option_details")
public class AmountOptionDetails {
public class AmountOptionDetails extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -38,4 +39,4 @@ public class AmountOptionDetails {
@Column(name = "user_id")
private String userId;
}
}
@@ -0,0 +1,82 @@
package com.billpaymentservice.bbps.entites;
import java.lang.reflect.Field;
import java.time.LocalDateTime;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
/**
* Generic JPA entity listener that populates common audit fields on entities.
*
* Behavior:
* - On PrePersist: sets createdAt/creationDate/createdEpochDate if present (only when null),
* and forces isDeleted/deleted to false if those fields exist.
* - On PreUpdate: sets modifiedDate/modifiedEpochDate/updatedAt/updatedOn if present.
*
* This uses reflection so entities don't need to extend a specific base class.
*/
public class AuditListener {
@PrePersist
public void prePersist(Object entity) {
LocalDateTime now = LocalDateTime.now();
setIfNull(entity, "createdAt", now);
setIfNull(entity, "createdOn", now);
setIfNull(entity, "creationDate", now == null ? null : now.toString());
setIfNull(entity, "createdEpochDate", System.currentTimeMillis());
// Ensure isDeleted / deleted exists and is set to false on create
setAlways(entity, "isDeleted", Boolean.FALSE);
}
/*@PreUpdate
public void preUpdate(Object entity) {
LocalDateTime now = LocalDateTime.now();
setIfNull(entity, "modifiedDate", now == null ? null : now.toString());
setIfNull(entity, "modifiedEpochDate", System.currentTimeMillis());
setIfNull(entity, "updatedAt", now);
setIfNull(entity, "updatedOn", now);
}
*/
private void setIfNull(Object entity, String fieldName, Object value) {
try {
Field f = findField(entity.getClass(), fieldName);
if (f == null) return;
boolean accessible = f.canAccess(entity);
f.setAccessible(true);
Object current = f.get(entity);
if (current == null && value != null) {
f.set(entity, value);
}
f.setAccessible(accessible);
} catch (Exception e) {
// ignore reflection failures
}
}
private void setAlways(Object entity, String fieldName, Object value) {
try {
Field f = findField(entity.getClass(), fieldName);
if (f == null) return;
boolean accessible = f.canAccess(entity);
f.setAccessible(true);
f.set(entity, value);
f.setAccessible(accessible);
} catch (Exception e) {
// ignore reflection failures
}
}
private Field findField(Class<?> cls, String name) {
Class<?> cur = cls;
while (cur != null && cur != Object.class) {
try {
return cur.getDeclaredField(name);
} catch (NoSuchFieldException e) {
cur = cur.getSuperclass();
}
}
return null;
}
}
@@ -0,0 +1,41 @@
package com.billpaymentservice.bbps.entites;
import java.time.LocalDateTime;
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.Setter;
/**
* Base mapped superclass for audit fields. All JPA entities should extend this to
* get automatic population of createdAt/updatedAt/isDeleted via AuditListener.
*/
@MappedSuperclass
@EntityListeners(AuditListener.class)
@Getter
@Setter
public abstract class Auditable {
@Column(name = "created_at")
private LocalDateTime createdAt;
@Column(name = "updated_at")
private LocalDateTime updatedAt;
@Column(name = "created_on")
private LocalDateTime createdOn;
@Column(name = "updated_on")
private LocalDateTime updatedOn;
@Column(name = "created_epoch_date")
private Long createdEpochDate;
@Column(name = "modified_epoch_date")
private Long modifiedEpochDate;
@Column(name = "is_deleted")
private Boolean isDeleted = Boolean.FALSE;
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -21,7 +19,7 @@ import lombok.Setter;
@Getter
@Setter
@Table(name = "bbps_master_data")
public class BBPSMastersData extends Auditable<String> {
public class BBPSMastersData extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -43,4 +41,4 @@ public class BBPSMastersData extends Auditable<String> {
@Column(name = "user_name")
private String userName;
}
}
@@ -17,7 +17,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@Builder
@Table(name = "bbps_merchant_validation")
public class BBPSMerchantValidation {
public class BBPSMerchantValidation extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -42,5 +42,5 @@ public class BBPSMerchantValidation {
private String txtId;
private boolean is_deleted;
}
// Removed local is_deleted field, now handled by Auditable
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@@ -18,7 +16,7 @@ import lombok.Setter;
@NoArgsConstructor
@Entity
@Table(name = "bbps_bharat_connect_master")
public class BharatConnectMaster extends Auditable<String> {
public class BharatConnectMaster extends Auditable {
@Id
@Column(name = "org_id", nullable = false, unique = true, length = 50)
@@ -46,4 +44,4 @@ public class BharatConnectMaster extends Auditable<String> {
@Column(name = "is_active")
private boolean isActive=false;
}
}
@@ -14,7 +14,8 @@ import lombok.Setter;
@Setter
@Entity
@Table(name = "bbps_bill_additional_info")
public class BillAdditionalInfo {
public class BillAdditionalInfo extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -28,4 +29,4 @@ public class BillAdditionalInfo {
@JoinColumn(name = "biller_response_id")
private CheckClientBillerData billerResponse;
}
}
@@ -13,7 +13,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@Entity
@Table(name = "bbps_bill_initiate")
public class BillInitiate {
public class BillInitiate extends Auditable {
@Id
@Column(name = "req_id")
private String reqId;
@@ -27,4 +28,4 @@ public class BillInitiate {
@Column(name = "client_user_id")
private String clientUserId;
}
}
@@ -23,7 +23,7 @@ import lombok.Setter;
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class BillMaster {
public class BillMaster extends Auditable {
@Id
private String billId; // primary key
@@ -43,10 +43,6 @@ public class BillMaster {
private List<AdditionalInfoBill> additionalInfo;
@OneToMany(mappedBy = "billMaster", cascade = CascadeType.ALL)
private List<CustomerParamBill> customerParams;
private String creationDate;
private String modifiedDate;
private Long createdEpochDate;
private Long modifiedEpochDate;
// getters and setters
}
}
@@ -1,6 +1,5 @@
package com.billpaymentservice.bbps.entites;
import java.time.LocalDateTime;
import java.util.List;
import jakarta.persistence.CascadeType;
@@ -17,7 +16,8 @@ import lombok.Setter;
@Setter
@Entity
@Table(name = "bbps_bill_payment")
public class BillPayment {
public class BillPayment extends Auditable {
@Id
@Column(name = "txn_id")
@@ -53,10 +53,7 @@ public class BillPayment {
@Column(name = "customer_mobile")
private String customerMobNo;
@Column(name = "created_at")
private LocalDateTime createdAt = LocalDateTime.now();
// 🔗 One bill payment has many remitter identities
@OneToMany(mappedBy = "billPayment", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private List<RemitterIdentity> remitterIdentities;
}
}
@@ -14,7 +14,8 @@ import lombok.Setter;
@Setter
@Entity
@Table(name = "bbps_bill_tag_list")
public class BillTag {
public class BillTag extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -27,4 +28,4 @@ public class BillTag {
@JoinColumn(name = "biller_response_id")
private CheckClientBillerData billerResponse;
}
}
@@ -12,7 +12,7 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BillValidation {
public class BillValidation extends Auditable {
@Id
@Column(name = "bill_id", nullable = false, length = 100)
@@ -46,18 +46,6 @@ public class BillValidation {
@Column(name = "plan_info_daos", columnDefinition = "TEXT")
private String planInfoDaos;
@Column(name = "creation_date", length = 50)
private String creationDate;
@Column(name = "modified_date", length = 50)
private String modifiedDate;
@Column(name = "created_epoch_date", length = 50)
private String createdEpochDate;
@Column(name = "modified_epoch_date", length = 50)
private String modifiedEpochDate;
@Column(name = "txn_id")
private String txnId;
@@ -66,4 +54,7 @@ public class BillValidation {
@Column(name = "client_user_id")
private String clientUserId;
}
// Removed local audit fields: creationDate, modifiedDate, createdEpochDate, modifiedEpochDate
// They are now handled by Auditable base class
}
@@ -15,7 +15,7 @@ import lombok.Setter;
@Setter
@Table(name = "bbps_biller_additional_info_payment")
@Entity
public class BillerAdditionalInfoPayment {
public class BillerAdditionalInfoPayment extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // primary key for the table
@@ -42,4 +42,4 @@ public class BillerAdditionalInfoPayment {
@ManyToOne
@JoinColumn(name = "biller_id", nullable = false)
private BillerDetails biller;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
@@ -23,7 +21,7 @@ import lombok.Setter;
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class BillerCategoryIcon extends Auditable<String>{
public class BillerCategoryIcon extends Auditable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -42,4 +40,4 @@ public class BillerCategoryIcon extends Auditable<String>{
foreignKey = @ForeignKey(name = "fk_icon_biller"))
private BillerCategoryWise biller;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@@ -20,7 +18,7 @@ import lombok.Setter;
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class BillerCategoryWise extends Auditable<String> {
public class BillerCategoryWise extends Auditable {
@Id
@Column(name = "biller_id")
@@ -66,4 +64,4 @@ public class BillerCategoryWise extends Auditable<String> {
@OneToOne(mappedBy = "biller", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private BillerCategoryIcon icon;
}
}
@@ -2,12 +2,12 @@ package com.billpaymentservice.bbps.entites;
import java.util.List;
import com.billpaymentservice.bbps.audit.Auditable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
@@ -21,6 +21,7 @@ import lombok.ToString;
@Getter
@Setter
@Entity
@EntityListeners(AuditListener.class)
@ToString(exclude = {
"billerPaymentModes",
"billerPaymentChannels",
@@ -36,7 +37,7 @@ import lombok.ToString;
@Table(name = "bbps_biller_details")
@JsonIgnoreProperties(ignoreUnknown = true)
public class BillerDetails{
public class BillerDetails extends Auditable {
@Id
@Column(name = "biller_id", length = 14, nullable = false, unique = true)
@@ -160,4 +161,4 @@ public class BillerDetails{
@OneToOne(mappedBy = "biller", cascade = CascadeType.ALL)
private BillerPlanResponseParams billerPlanResponseParams;
}
}
@@ -18,7 +18,8 @@ import lombok.ToString;
@Entity
@ToString
@Table(name = "bbps_biller_plan_response_params")
public class BillerPlanResponseParams {
public class BillerPlanResponseParams extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // Primary Key
@@ -36,5 +37,4 @@ public class BillerPlanResponseParams {
@OneToOne
@JoinColumn(name = "biller_id", nullable = false)
private BillerDetails biller;
}
}
@@ -14,7 +14,7 @@ import lombok.Setter;
@Table(name = "bbps_biller_response")
@Getter
@Setter
public class BillerResponse {
public class BillerResponse extends Auditable {
@Id
@GeneratedValue
@@ -55,4 +55,4 @@ public class BillerResponse {
private BillMaster billMaster;
// getters and setters
}
}
@@ -21,7 +21,8 @@ import lombok.Setter;
@Setter
@Entity
@Table(name = "bbps_biller_response_params")
public class BillerResponseParams {
public class BillerResponseParams extends Auditable {
@Id
@Column(name = "biller_response_id", nullable = false, unique = true)
@@ -46,4 +47,4 @@ public class BillerResponseParams {
@OneToMany(mappedBy = "billerResponseParams", cascade = CascadeType.ALL, orphanRemoval = true)
private List<AmountOption> amountOptions;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -15,7 +13,7 @@ import lombok.Setter;
@Table(name = "bbps_category_response_list")
@Getter
@Setter
public class CategoryResponseList extends Auditable<String> {
public class CategoryResponseList extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -33,4 +31,4 @@ public class CategoryResponseList extends Auditable<String> {
@Column(name = "user_id")
private String userId;
}
}
@@ -19,7 +19,7 @@ import lombok.Setter;
@Table(name = "bbps_check_client_biller_data")
@Getter
@Setter
public class CheckClientBillerData {
public class CheckClientBillerData extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -65,4 +65,4 @@ public class CheckClientBillerData {
@OneToMany(mappedBy = "billerResponse", cascade = CascadeType.ALL)
private List<BillCustomerParams> customerParams;
}
}
@@ -13,7 +13,7 @@ import lombok.Setter;
@Table(name = "bbps_check_client_status_req_id")
@Getter
@Setter
public class CheckClientStatusReqId {
public class CheckClientStatusReqId extends Auditable {
@Id
@Column(name = "bill_id", length = 200)
@@ -34,18 +34,6 @@ public class CheckClientStatusReqId {
@Column(name = "user_id")
private String userId;
@Column(name = "creation_date")
private String creationDate;
@Column(name = "modified_date")
private String modifiedDate;
@Column(name = "created_epoch_date")
private Long createdEpochDate;
@Column(name = "modified_epoch_date")
private Long modifiedEpochDate;
@Column(name = "req_id")
private String reqId;
@@ -57,4 +45,4 @@ public class CheckClientStatusReqId {
private CheckClientBillerData billerResponse;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -17,7 +15,7 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CloseComplaint extends Auditable<String> {
public class CloseComplaint extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -104,4 +102,4 @@ public class CloseComplaint extends Auditable<String> {
@Column(name = "system_txn_id")
private String systemTxnId;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -17,7 +15,7 @@ import lombok.Setter;
@Table(name = "bbps_complaint_status")
@Getter
@Setter
public class ComplainStatus extends Auditable<String> {
public class ComplainStatus extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -78,3 +76,4 @@ public class ComplainStatus extends Auditable<String> {
@JoinColumn(name = "complaint_response_id")
private ComplaintResponseEntity complaintResponse;
}
@@ -9,7 +9,7 @@ import lombok.ToString;
@Getter
@Setter
@ToString
public class ComplaintDetails {
public class ComplaintDetails extends Auditable {
@Id
@Column(name = "complaint_id", nullable = false, unique = true)
@@ -68,4 +68,4 @@ public class ComplaintDetails {
@Column(name = "modified_epoch_date")
private Long modifiedEpochDate;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -21,7 +19,7 @@ import lombok.Setter;
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ComplaintHistory extends Auditable<String> {
public class ComplaintHistory extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -2,7 +2,6 @@ package com.billpaymentservice.bbps.entites;
import java.util.List;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
@@ -21,7 +20,8 @@ import lombok.ToString;
@Setter
@ToString
@Table(name = "bbps_complaint_responses")
public class ComplaintResponseEntity extends Auditable<String> {
public class ComplaintResponseEntity extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@@ -85,3 +85,4 @@ public class ComplaintResponseEntity extends Auditable<String> {
private List<ViewAllComplaintTicketStatusDetails> viewAllList;
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -17,7 +15,8 @@ import lombok.Setter;
@Getter
@Setter
@Table(name = "bbps_view_ticket_status")
public class ComplaintStatusDetails extends Auditable<String> {
public class ComplaintStatusDetails extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -15,7 +15,7 @@ import lombok.ToString;
@Getter
@Setter
@ToString
public class ComplaintStatusOptionsMaster {
public class ComplaintStatusOptionsMaster extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -24,7 +24,5 @@ public class ComplaintStatusOptionsMaster {
@Column(name = "status_label_name")
private String statusLabelName;
@Column(name = "is_deleted")
private Boolean isDeleted = false;
}
// Removed local isDeleted field, now handled by Auditable
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -19,7 +17,7 @@ import lombok.Setter;
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ContactMasterData extends Auditable<String> {
public class ContactMasterData extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -36,4 +34,4 @@ public class ContactMasterData extends Auditable<String> {
@Column(name = "user_id")
private String userId;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -17,7 +15,9 @@ import lombok.ToString;
@Entity
@ToString
@Table(name = "bbps_custom_param")
public class CustomParam extends Auditable<String> {
public class CustomParam extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -53,4 +53,4 @@ public class CustomParam extends Auditable<String> {
@Column(name = "user_id")
private String userId;
}
}
@@ -24,7 +24,7 @@ import lombok.ToString;
@Entity
@Table(name = "bbps_customer_param")
@ToString
public class CustomerParam {
public class CustomerParam extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -68,4 +68,4 @@ public class CustomerParam {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "biller_id")
private BillerDetails biller;
}
}
@@ -13,7 +13,8 @@ import lombok.Setter;
@Getter
@Setter
@Table(name = "bbps_customer_param_bill")
public class CustomerParamBill {
public class CustomerParamBill extends Auditable {
@Id
@GeneratedValue
@@ -28,4 +29,4 @@ public class CustomerParamBill {
private BillMaster billMaster;
// getters and setters
}
}
@@ -10,7 +10,7 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CustomerParamBillValidation {
public class CustomerParamBillValidation extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -30,4 +30,4 @@ public class CustomerParamBillValidation {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "bill_id_fk")
private BillValidation bill;
}
}
@@ -13,7 +13,8 @@ import lombok.Setter;
@Getter
@Setter
@Table(name = "bbps_customer_params")
public class CustomerParamDAO {
public class CustomerParamDAO extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -2,8 +2,6 @@ package com.billpaymentservice.bbps.entites;
import java.util.List;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@@ -21,7 +19,9 @@ import lombok.Setter;
@Setter
@Entity
@Table(name = "bbps_customer_param_group_by_biller_id")
public class CustomerParamGroupById extends Auditable<String> {
public class CustomerParamGroupById extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -58,4 +58,4 @@ public class CustomerParamGroupById extends Auditable<String> {
@Column(name = "user_id")
private String userId;
}
}
@@ -22,7 +22,8 @@ import lombok.ToString;
@Entity
@ToString
@Table(name = "bbps_customer_param_groups")
public class CustomerParamGroups {
public class CustomerParamGroups extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -37,5 +38,4 @@ public class CustomerParamGroups {
// 🔗 One CustomerParamGroups contains multiple Group objects
@OneToMany(mappedBy = "customerParamGroups", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Group> groups;
}
}
@@ -15,7 +15,8 @@ import lombok.Setter;
@Getter
@Setter
@Table(name = "bbps_customer_params_transaction")
public class CustomerParamTransaction {
public class CustomerParamTransaction extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -29,5 +30,4 @@ public class CustomerParamTransaction {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "txn_id", referencedColumnName = "bank_txn_id")
private TransactionMaster transactionMaster;
}
}
@@ -16,7 +16,8 @@ import lombok.Setter;
@Getter
@Setter
@Table(name = "bbps_device_block_tag")
public class DeviceBlockTag {
public class DeviceBlockTag extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -35,4 +36,4 @@ public class DeviceBlockTag {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "txn_id", referencedColumnName = "bank_txn_id")
private TransactionMaster transactionMaster;
}
}
@@ -13,7 +13,7 @@ import lombok.ToString;
@Entity
@Table(name = "bbps_disposition_details")
@ToString
public class DispositionDetails {
public class DispositionDetails extends Auditable {
@Id
@Column(name = "disposition_id", nullable = false, unique = true)
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -19,7 +17,8 @@ import lombok.Setter;
@NoArgsConstructor
@Entity
@Table(name = "bbps_fetch_bill_validate_response")
public class FetchBillValidate extends Auditable<String> {
public class FetchBillValidate extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -63,10 +62,10 @@ public class FetchBillValidate extends Auditable<String> {
private String modifiedDate;
@Column(name = "created_epoch_date")
private long createdEpochDate;
private Long createdEpochDate;
@Column(name = "modified_epoch_date")
private long modifiedEpochDate;
private Long modifiedEpochDate;
@Column(name = "request_id")
private String requestId;
@@ -74,4 +73,4 @@ public class FetchBillValidate extends Auditable<String> {
@Column(name = "txn_id")
private String txnId;
}
}
@@ -26,7 +26,8 @@ import lombok.Setter;
@Setter
@Entity
@Table(name = "bbps_biller_groups")
public class Group {
public class Group extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -59,4 +60,4 @@ public class Group {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "group_container_id")
private CustomerParamGroups customerParamGroups;
}
}
@@ -15,7 +15,8 @@ import lombok.Setter;
@Setter
@Entity
@Table(name = "bbps_group_params")
public class GroupParam {
public class GroupParam extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -28,4 +29,4 @@ public class GroupParam {
@JoinColumn(name = "group_id")
private CustomerParamGroupById group; // Link to the group this parameter belongs to
}
}
@@ -22,7 +22,8 @@ import lombok.ToString;
@Entity
@ToString
@Table(name = "bbps_interchange_fee")
public class InterchangeFee {
public class InterchangeFee extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -48,4 +49,4 @@ public class InterchangeFee {
@ManyToOne
@JoinColumn(name = "biller_id", nullable = false)
private BillerDetails biller;
}
}
@@ -20,7 +20,8 @@ import lombok.Setter;
@Setter
@Entity
@Table(name = "bbps_interchange_fee_conf")
public class InterchangeFeeConf {
public class InterchangeFeeConf extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -63,4 +64,4 @@ public class InterchangeFeeConf {
@ManyToOne
@JoinColumn(name = "biller_id", nullable = false)
private BillerDetails biller;
}
}
@@ -15,7 +15,7 @@ import lombok.Setter;
@Table(name = "bbps_interchange_fee_detail")
@Getter
@Setter
public class InterchangeFeeDetail {
public class InterchangeFeeDetail extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -43,4 +43,4 @@ public class InterchangeFeeDetail {
@ManyToOne
@JoinColumn(name = "interchange_fee_id", nullable = false)
private InterchangeFee interchangeFee;
}
}
@@ -8,7 +8,6 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@@ -18,7 +17,7 @@ import lombok.ToString;
@Entity
@ToString
@Table(name = "bbps_payment_channel")
public class PaymentChannel {
public class PaymentChannel extends Auditable {
@Id
@Column(name = "payment_channel_limit_id")
@@ -13,7 +13,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@Entity
@Table(name = "bbps_payment_initiate")
public class PaymentInitiate {
public class PaymentInitiate extends Auditable {
@Id
@Column(name = "req_id")
@@ -36,4 +37,4 @@ public class PaymentInitiate {
@Column(name = "user_id")
private String userId;
}
}
@@ -21,7 +21,7 @@ import lombok.ToString;
@Entity
@Table(name = "bbps_biller_payment_modes")
@ToString
public class PaymentMode {
public class PaymentMode extends Auditable {
@Id //
@@ -46,5 +46,4 @@ public class PaymentMode {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "biller_id", nullable = false)
private BillerDetails biller;
}
}
@@ -1,24 +1,25 @@
package com.billpaymentservice.bbps.entites;
import java.time.LocalDateTime;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Getter
@Setter
@Table(name = "bbps_payment_start_record")
public class PaymentStartRecord {
public class PaymentStartRecord extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -50,9 +51,10 @@ public class PaymentStartRecord {
@Column(name = "qr_string", columnDefinition = "TEXT")
private String qrString;
@Column(name = "created_on", nullable = false)
private String createdOn;
// `createdOn` is provided by the base `Auditable` class as a LocalDateTime field,
// so we must not redeclare it here (it caused an incompatible return-type error).
// The Auditable base class already defines `createdOn` of type LocalDateTime.
// New callback-related fields
@Column(name = "callback_status")
private String callbackStatus;
@@ -21,7 +21,7 @@ import lombok.Setter;
@Table(name = "bbps_plan")
@Getter
@Setter
public class Plan {
public class Plan extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -62,4 +62,4 @@ public class Plan {
@JoinColumn(name = "additional_info_id", referencedColumnName = "id")
private AdditionalInfoPlans additionalInfo;
}
}
@@ -15,7 +15,7 @@ import lombok.Setter;
@Table(name = "bbps_plan_category_sub_type")
@Getter
@Setter
public class PlanCategorySubType {
public class PlanCategorySubType extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -27,4 +27,4 @@ public class PlanCategorySubType {
@JoinColumn(name = "plan_id")
private Plan plan;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@@ -19,7 +17,7 @@ import lombok.Setter;
@Table(name = "bbps_plan_response")
@Getter
@Setter
public class PlanResponses extends Auditable<String> {
public class PlanResponses extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -50,4 +48,4 @@ public class PlanResponses extends Auditable<String> {
@Column(name = "user_id")
private String userId;
}
}
@@ -8,7 +8,7 @@ import lombok.Setter;
@Table(name = "bbps_plan_tag")
@Getter
@Setter
public class PlanTag {
public class PlanTag extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -30,4 +30,4 @@ public class PlanTag {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "additional_info_id", referencedColumnName = "id")
private AdditionalInfoPlans additionalInfo;
}
}
@@ -17,7 +17,7 @@ import lombok.Setter;
@Table(name = "bbps_plans_list")
@Getter
@Setter
public class PlansList {
public class PlansList extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -26,4 +26,4 @@ public class PlansList {
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "plansList")
private List<Plan> plans;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -15,7 +13,7 @@ import lombok.Setter;
@Table(name = "bbps_reopen_complaint")
@Getter
@Setter
public class ReOpenComplain extends Auditable<String> {
public class ReOpenComplain extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -92,10 +90,10 @@ public class ReOpenComplain extends Auditable<String> {
private String category;
@Column(name = "created_epoch_date")
private long createdEpochDate;
private Long createdEpochDate;
@Column(name = "modified_epoch_date")
private long modifiedEpochDate;
private Long modifiedEpochDate;
@Column(name = "req_id")
private String reqId;
@@ -103,4 +101,4 @@ public class ReOpenComplain extends Auditable<String> {
@Column(name = "system_txn_id")
private String systemTxnId;
}
}
@@ -16,7 +16,8 @@ import lombok.Setter;
@Setter
@Entity
@Table(name = "bbps_remitter_identity")
public class RemitterIdentity {
public class RemitterIdentity extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -33,4 +34,4 @@ public class RemitterIdentity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "txn_id")
private BillPayment billPayment;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -17,7 +15,7 @@ import lombok.ToString;
@Entity
@Table(name = "bbps_ticket_disposition_details")
@ToString
public class TicketDispositionDetails extends Auditable<String> {
public class TicketDispositionDetails extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -43,4 +41,4 @@ public class TicketDispositionDetails extends Auditable<String> {
@Column(name = "user_id")
private String userId;
}
}
@@ -24,7 +24,7 @@ import lombok.ToString;
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class TransactionMaster {
public class TransactionMaster extends Auditable {
// 👇 JSON me "txn_id" aayega, ye DB me bank_txn_id column me save hoga
@Id
@@ -166,4 +166,4 @@ public class TransactionMaster {
@Column(name = "modified_epoch_date")
private Long modifiedEpochDate;
}
}
@@ -1,5 +1,5 @@
package com.billpaymentservice.bbps.entites;
public class TxnStatus {
public class TxnStatus extends Auditable {
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -19,7 +17,7 @@ import lombok.Setter;
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class UserEntity extends Auditable<String> {
public class UserEntity extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -1,6 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -16,7 +15,8 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@Entity
@Table(name = "bbps_user_details")
public class UsersDetails extends Auditable<String> {
public class UsersDetails extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -35,4 +35,4 @@ public class UsersDetails extends Auditable<String> {
@Column(name = "user_age")
private String userAge;
}
}
@@ -1,7 +1,5 @@
package com.billpaymentservice.bbps.entites;
import com.billpaymentservice.bbps.audit.Auditable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -17,7 +15,8 @@ import lombok.Setter;
@Getter
@Setter
@Table(name = "bbps_view_all_complaint_ticket_status")
public class ViewAllComplaintTicketStatusDetails extends Auditable<String> {
public class ViewAllComplaintTicketStatusDetails extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -6,79 +6,181 @@ import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.*;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.NoHandlerFoundException;
import com.billpaymentservice.bbps.dto.ResponseModel;
import jakarta.servlet.http.HttpServletRequest;
@ControllerAdvice
public class GlobalExceptionHandler {
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ResponseModel<?>> handleValidation(MethodArgumentNotValidException ex) {
List<Map<String, String>> fieldErrors = ex.getBindingResult().getFieldErrors()
.stream()
.map(fe -> Map.of("field", fe.getField(), "message", fe.getDefaultMessage()))
.collect(Collectors.toList());
logger.warn("Validation failed: {}", fieldErrors);
ResponseModel<List<Map<String, String>>> resp = new ResponseModel<>(
"Validation failed for request",
"FAILED",
HttpStatus.BAD_REQUEST.value(),
null
/**
* 🔥 Common logger formatter for all exceptions
*/
private String buildErrorContext(Exception ex, HttpServletRequest request, HandlerMethod handlerMethod) {
// API endpoint
String endpoint = (request != null)
? request.getMethod() + " " + request.getRequestURI()
: "unknown";
// Controller method
String controllerMethod = (handlerMethod != null)
? handlerMethod.getBeanType().getSimpleName() + "." + handlerMethod.getMethod().getName()
: "NoControllerMethodMatched";
// Root cause (actual throw point)
StackTraceElement root = ex.getStackTrace()[0];
String rootCause = root.getClassName() + "." + root.getMethodName() + "():" + root.getLineNumber();
return String.format(
"API: %s | Controller: %s | Thrown From: %s | Exception: %s",
endpoint,
controllerMethod,
rootCause,
ex.getClass().getSimpleName()
);
// put validation errors into data or duplicate field in ResponseModel as required
resp.setData(fieldErrors);
}
// ------------------------- VALIDATION EXCEPTION ------------------------
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ResponseModel<?>> handleValidation(
MethodArgumentNotValidException ex,
HttpServletRequest request,
HandlerMethod handlerMethod) {
String context = buildErrorContext(ex, request, handlerMethod);
logger.warn("ValidationException → {}", context);
List<Map<String, String>> fieldErrors = ex.getBindingResult()
.getFieldErrors()
.stream()
.map(fe -> Map.of("field", fe.getField(), "message", fe.getDefaultMessage()))
.collect(Collectors.toList());
ResponseModel<List<Map<String, String>>> resp = new ResponseModel<>(
"Validation failed",
"FAILED",
HttpStatus.BAD_REQUEST.value(),
fieldErrors
);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resp);
}
// ------------------------- MALFORMED/INVALID JSON ------------------------
@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<ResponseModel<?>> handleInvalidJson(
HttpMessageNotReadableException ex,
HttpServletRequest request,
HandlerMethod handlerMethod) {
String endpoint = (request != null) ? request.getMethod() + " " + request.getRequestURI() : "unknown";
// prefer the root Jackson message if present
String rootMsg = ex.getMostSpecificCause() != null ? ex.getMostSpecificCause().getMessage() : ex.getMessage();
String shortMsg = (rootMsg != null && rootMsg.length() > 200) ? rootMsg.substring(0, 200) + "..." : rootMsg;
logger.warn("Invalid JSON received for endpoint {}: {}", endpoint, shortMsg);
Map<String, Object> data = Map.of(
"exception", ex.getClass().getName(),
"message", shortMsg
);
ResponseModel<?> resp = new ResponseModel<>(
"[" + endpoint + "] Invalid JSON received",
"FAILED",
HttpStatus.BAD_REQUEST.value(),
data
);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resp);
}
// ------------------------- NO HANDLER (404 NOT FOUND) ------------------------
@ExceptionHandler(NoHandlerFoundException.class)
public ResponseEntity<ResponseModel<?>> handleNotFound(NoHandlerFoundException ex) {
logger.warn("Endpoint not found: {}", ex.getRequestURL());
logger.warn("404 Not Found → {}", ex.getRequestURL());
ResponseModel<?> resp = new ResponseModel<>(
"Endpoint not found: " + ex.getRequestURL(),
"FAILED",
HttpStatus.NOT_FOUND.value(),
null
"Endpoint not found: " + ex.getRequestURL(),
"FAILED",
HttpStatus.NOT_FOUND.value(),
null
);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(resp);
}
// ------------------------- CUSTOM APP EXCEPTION ------------------------
@ExceptionHandler(AppException.class)
public ResponseEntity<ResponseModel<?>> handleAppException(AppException ex) {
logger.warn("AppException: status={}, message={}", ex.getStatus(), ex.getMessage());
ResponseModel<?> resp = new ResponseModel<>(ex.getMessage(), ex.getStatus(), ex.getStatusCode(), ex.getData());
public ResponseEntity<ResponseModel<?>> handleAppException(
AppException ex,
HttpServletRequest request,
HandlerMethod handlerMethod) {
String context = buildErrorContext(ex, request, handlerMethod);
logger.warn("AppException → {}", context);
ResponseModel<?> resp = new ResponseModel<>(
ex.getMessage(),
ex.getStatus(),
ex.getStatusCode(),
ex.getData()
);
return ResponseEntity.status(HttpStatus.valueOf(ex.getStatusCode())).body(resp);
}
// ------------------------- CUSTOMException ------------------------
@ExceptionHandler(CustomException.class)
public ResponseEntity<ResponseModel<?>> handleCustomException(CustomException ex) {
logger.warn("CustomException: {}", ex.getMessage());
ResponseModel<?> resp = new ResponseModel<>(
ex.getMessage(),
"FAILED",
HttpStatus.BAD_REQUEST.value(),
null
);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resp);
public ResponseEntity<ResponseModel<?>> handleCustomException(
CustomException ex,
HttpServletRequest request,
HandlerMethod handlerMethod) {
String context = buildErrorContext(ex, request, handlerMethod);
logger.warn("CustomException → {}", context);
// Use the ResponseModel carried by CustomException so callers get the original status/code/data
ResponseModel<?> resp = ex.getResponseModel();
HttpStatus httpStatus = HttpStatus.BAD_REQUEST;
try {
httpStatus = HttpStatus.valueOf(resp.getStatusCode());
} catch (Exception e) {
// fallback
}
return ResponseEntity.status(httpStatus).body(resp);
}
// ------------------------- GENERIC EXCEPTION ------------------------
@ExceptionHandler(Exception.class)
public ResponseEntity<ResponseModel<?>> handleAll(Exception ex) {
logger.error("Unhandled exception", ex);
public ResponseEntity<ResponseModel<?>> handleAll(
Exception ex,
HttpServletRequest request,
HandlerMethod handlerMethod) {
String context = buildErrorContext(ex, request, handlerMethod);
logger.error("UnhandledException → {}", context, ex);
ResponseModel<?> response = new ResponseModel<>(
"Service temporarily unavailable. Please try again later.",
"FAILED",
HttpStatus.INTERNAL_SERVER_ERROR.value(),
null
"Internal Server Error",
"FAILED",
HttpStatus.INTERNAL_SERVER_ERROR.value(),
null
);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}
}
@@ -3,6 +3,7 @@ package com.billpaymentservice.bbps.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.billpaymentservice.bbps.entites.BBPSMerchantValidation;
@@ -17,3 +18,5 @@ public interface MerchantRepository extends JpaRepository<BBPSMerchantValidation
BBPSMerchantValidation findByMidNative(@Param("mid") String mid);
}
@@ -46,7 +46,7 @@ public class AuthServiceImpl implements AuthService {
@Autowired
public AuthServiceImpl(UserRepository userRepository, OtpClient otpClient, Helper helper,
UsersDetailsRepository userRepo, JwtUtil jwtUtil) {
UsersDetailsRepository userRepo, JwtUtil jwtUtil) {
this.userRepository = userRepository;
this.otpClient = otpClient;
this.helper = helper;
@@ -56,21 +56,18 @@ public class AuthServiceImpl implements AuthService {
@Override
public ResponseModel<?> sendOtp(LoginRequest request) {
try {
OtpSendResponse resp = otpClient.sendOtp(request.getMobile());
if (resp == null) {
return ResponseModel.builder().message("OTP send service returned null").status("Failure")
.statusCode(500).data(null).build();
}
String status = resp.isSuccess() ? "Success" : "Failure";
int code = resp.isSuccess() ? 200 : 400;
return ResponseModel.builder().message(resp.getMessage()).status(status).statusCode(code).data(resp)
.build();
} catch (Exception ex) {
LOGGER.error("Error in sendOtp: {}", ex.getMessage(), ex);
return ResponseModel.builder().message("An unexpected error occurred while sending OTP").status("Failure")
.statusCode(500).data(null).build();
// validate minimal inputs
if (request == null || request.getMobile() == null || request.getMobile().isBlank()) {
throw new CustomException("Mobile number is required", "FAILED", 400, "missing mobile");
}
// Delegate attempts to helper — it will throw CustomException on unrecoverable issues
OtpSendResponse resp = attemptSendOtpWithRetry(request.getMobile(), 1);
// If the downstream returned a response indicating failure, return that as a ResponseModel
String status = resp.isSuccess() ? "Success" : "Failure";
int code = resp.isSuccess() ? 200 : 400;
return ResponseModel.builder().message(resp.getMessage()).status(status).statusCode(code).data(resp).build();
}
@Override
@@ -121,6 +118,40 @@ public class AuthServiceImpl implements AuthService {
}
}
/**
* Helper that attempts to send OTP and retries up to `retryCount` times on null/unsuccessful responses.
* Throws CustomException when the OTP service returns null after retries or when unexpected errors occur.
*/
private OtpSendResponse attemptSendOtpWithRetry(String mobile, int retryCount) {
int attempts = 0;
OtpSendResponse resp = null;
while (attempts <= retryCount) {
attempts++;
try {
LOGGER.info("Attempt #{} to send OTP to {}", attempts, mobile);
resp = otpClient.sendOtp(mobile);
if (resp != null && resp.isSuccess()) {
LOGGER.info("OTP send succeeded on attempt #{} for {}", attempts, mobile);
return resp;
}
// If response is non-null but indicates failure, we still may not want to retry for logical errors
if (resp != null && !resp.isSuccess()) {
LOGGER.warn("OTP service responded with failure on attempt #{} for {}: {}", attempts, mobile, resp.getMessage());
// Do not retry for application-level failures (invalid number etc.)
return resp;
}
} catch (Exception ex) {
LOGGER.error("Exception while sending OTP on attempt #{} for {}: {}", attempts, mobile, ex.getMessage(), ex);
// continue to retry if attempts remain
}
// loop continues to retry if attempts <= retryCount
}
// After retries, if resp is null (no response received), treat as unrecoverable and let global handler handle it via exception
LOGGER.error("OTP service returned null after {} attempts for {}", attempts - 1, mobile);
throw new CustomException("OTP send service returned null", "FAILED", 500, "OtpClient returned null after retries");
}
@Override
@Transactional
public ResponseModel<?> registerUser(RegisterRequest request) {
@@ -172,23 +203,23 @@ public class AuthServiceImpl implements AuthService {
@Override
public ResponseModel<?> authenticateUser(LoginRequest loginRequest) {
// LOGGER.info("Processing login for Request: {}", loginRequest);
//
//
// try {
// String mobileNo = loginRequest.getMobile();
//
//
// Optional<UsersDetails> byMobileNo = userRepo.findByUserMobNo(mobileNo);
//
//
// if (byMobileNo.isPresent()) {
// UsersDetails user = (UsersDetails) byMobileNo.get();
// String token = jwtUtil.generateToken(user.getUserMobNo());
//
//
// LOGGER.info("Generated JWT token for mobileNo: " + mobileNo);
//
//
// Object userDetailsDTO = null;
//
//
// if (user != null) {
// userDetailsDTO = UserDetailsDTO.builder().id(user.getId()).userEmailId(user.getUserEmailId())
// .userMobNo(user.getUserMobNo()).userName(user.getUserName()).build();
// .userMobNo(user.getUserMobNo()).userName(user.getUserName()).build();
// }
// AuthResponses authResp = new AuthResponses(token, "Success", "Login Done", 200, userDetailsDTO);
// return ResponseModel.builder().message("Login Done").status("Success").statusCode(200).data(authResp)
@@ -199,7 +230,7 @@ public class AuthServiceImpl implements AuthService {
// .data(authResp).build();
// }
//
//
//
// } catch (Exception ex) {
// LOGGER.error("Error occurred during login for mobile no: {} Exception: {}", loginRequest.getMobile(),
// ex.getMessage(), ex);
@@ -213,4 +244,4 @@ public class AuthServiceImpl implements AuthService {
public UserEntity findByMobile(String mobile) {
return userRepository.findByMobile(mobile).orElse(null);
}
}
}
@@ -113,7 +113,6 @@ public class MasterDataServiceImpl implements MasterDataService {
@Override
public ResponseModel getMasterData(MasterRequest masterRequest) {
String apiName = BBPSConstant.API_GET_MASTER_DATA;
String requestId = masterRequest.getReqId();
String mid = masterRequest.getMid();
@@ -220,7 +219,7 @@ public class MasterDataServiceImpl implements MasterDataService {
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
BillerDetails entity = mapper.map(responseWrapper.getBillerDAO(), BillerDetails.class);
EntityRelationshipUtil.linkBillerRelationships(entity);// linking nesting entity foreign key
// mapperHelper.saveOrUpdateBillerData(entity);
mapperHelper.saveOrUpdateBillerData(entity);
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
@@ -888,7 +887,7 @@ public class MasterDataServiceImpl implements MasterDataService {
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
return responseModel;
} catch (JsonProcessingException e) {
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
LOGGER.error("Error parsing responseData JSON: {} :: class :: method ", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
throw new CustomException("Invalid JSON received from API");
}
@@ -90,11 +90,14 @@ public class PaymentServiceImpl implements PaymentService {
@Override
public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest) {
String apiName = BBPSConstant.API_INITIATE_PAYMENT;
LOGGER.info("[{}] START | reqId={} | mid={}", apiName, billPaymentRequest.getReqId(),
billPaymentRequest.getMid());
String txnId = helper.generateTxnId(15);
String requestId = billPaymentRequest.getReqId();
String userId = billPaymentRequest.getClientReqId();
String url = paymentUrl + BBPSConstant.PAYMENT_URL;
billPaymentRequest.setClientReqId(txnId);
LOGGER.info("Initiating payment for reqId={} and txnId={} and userId={}", requestId, txnId, userId);
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
@@ -214,7 +214,6 @@ public class BillerMapperHelper {
biller.setPlanMDMRequirement(dto.getPlanMDMRequirement());
biller.setAdhocBiller(dto.getAdhocBiller());
biller.setPaymentAmountExactness(dto.getPaymentAmountExactness());
biller.setCreateDateTime(new Date());
biller.setRequestId(requestId);
biller.setTxnId(txnId);
biller.setUserId(userId);
@@ -279,7 +278,6 @@ public class BillerMapperHelper {
groupEntity.setRequestId(requestId);
groupEntity.setTxnId(txnId);
groupEntity.setUserId(userId);
groupEntity.setCreateDateTime(new Date());
// Save group parameters (if any)
if (groupDTO.getParams() != null && !groupDTO.getParams().isEmpty()) {
List<GroupParam> groupParams = new ArrayList<>();
@@ -367,7 +365,6 @@ public class BillerMapperHelper {
List<AmountOptionDetails> amountOptionDetailsList = mapAmountOptionDTOToEntity(
responseWrapper.getAmountOptionDAOS(), requestId, txnId, userId);
entity.setAmountOptionDetails(amountOptionDetailsList);
entity.setCreateDateTime(new Date());
amountOptionByBillerIdRepository.save(entity); // Saves the entity and cascades to AmountOptionDetails
@@ -416,7 +413,6 @@ public class BillerMapperHelper {
response.setTotalPages(planResponse.getTotalPages());
response.setTxnId(txnId);
response.setUserId(userId);
response.setCreateDateTime(new Date());
PlansList plansList = new PlansList();
List<Plan> planEntities = new ArrayList<>();
@@ -489,7 +485,6 @@ public class BillerMapperHelper {
category.setCategoryRespList(item);
category.setRequestId(txnId);
category.setRequestId(requestId);
category.setCreateDateTime(new Date());
category.setUserId(userId);
categoryResponseListRepository.save(category);
savedCount++;
@@ -536,7 +531,6 @@ public class BillerMapperHelper {
entity.setNpciTicketType(dto.getNpciTicketType());
entity.setNpciTicketStatus(dto.getNpciTicketStatus());
entity.setCreatedTime(dto.getCreatedTime());
entity.setCreateDateTime(new Date());
entity.setUserId(userId);
try {
@@ -567,7 +561,6 @@ public class BillerMapperHelper {
entity.setHistoryStatus(dto.getHistoryStatus());
entity.setReqId(reqId);
entity.setTxnId(txnId);
entity.setCreateDateTime(new Date());
entity.setUserId(userId);
complaintHistoryRepository.save(entity);
@@ -683,7 +676,6 @@ public class BillerMapperHelper {
entity.setTotalElements(String.valueOf(responseWrapper.getTotalElements()));
entity.setPage(String.valueOf(responseWrapper.getPage()));
entity.setPageSize(String.valueOf(responseWrapper.getPageSize()));
entity.setCreateDateTime(new Date());
entity.setUserId(userId);
}
@@ -726,8 +718,11 @@ public class BillerMapperHelper {
parent.setStatus(responseWrapper.getStatus());
parent.setActionType(responseWrapper.getActionType());
parent.setUserId(responseWrapper.getUserId());
parent.setCreationDate(responseWrapper.getCreationDate());
parent.setModifiedDate(responseWrapper.getModifiedDate());
// Map incoming DTO date strings into Auditable LocalDateTime fields
LocalDateTime parentCreatedOn = parseToLocalDateTime(responseWrapper.getCreationDate());
if (parentCreatedOn != null) parent.setCreatedOn(parentCreatedOn);
LocalDateTime parentUpdatedOn = parseToLocalDateTime(responseWrapper.getModifiedDate());
if (parentUpdatedOn != null) parent.setUpdatedOn(parentUpdatedOn);
parent.setCreatedEpochDate(responseWrapper.getCreatedEpochDate());
parent.setModifiedEpochDate(responseWrapper.getModifiedEpochDate());
parent.setReqId(reqId);
@@ -828,7 +823,6 @@ public class BillerMapperHelper {
entity.setDispositionCode(dto.getDispositionCode());
// Set current datetime
entity.setCreateDateTime(new Date());
entity.setTxnId(txnId);
entity.setReqId(requestId);
entity.setUserId(userId);
@@ -862,7 +856,6 @@ public class BillerMapperHelper {
entity.setPageSize(String.valueOf(responseWrapper.getPageSize()));
entity.setTotalPages(String.valueOf(responseWrapper.getTotalPages()));
entity.setTotalElements(String.valueOf(responseWrapper.getTotalElements()));
entity.setCreateDateTime(new Date());
entity.setUserId(userId);
}
@@ -887,7 +880,6 @@ public class BillerMapperHelper {
entity.setReqId(requestId);
entity.setTxnId(txnID);
entity.setUserId(userId);
entity.setCreateDateTime(new Date());
return entity;
}).collect(Collectors.toList());
@@ -926,7 +918,7 @@ public class BillerMapperHelper {
billMaster.setUserId(userId);
billMaster.setClientUserId(billFetchByBillIdRequest.getClientUserId());
// BILLER RESPONSE
// BILLER RESPONSE
BillerResponse billerResponse = new BillerResponse();
if (responseWrapper.getBillerResponse() != null) {
billerResponse.setBillId(responseWrapper.getBillerResponse().getBillId());
@@ -943,7 +935,7 @@ public class BillerMapperHelper {
}
billMaster.setBillerResponse(billerResponse);
// ADDITIONAL INFO
// ADDITIONAL INFO
List<AdditionalInfoBill> additionalInfos = new ArrayList<>();
if (responseWrapper.getAdditionalInfo() != null) {
for (AdditionalInfoBillDTO info : responseWrapper.getAdditionalInfo()) {
@@ -956,7 +948,7 @@ public class BillerMapperHelper {
}
billMaster.setAdditionalInfo(additionalInfos);
// CUSTOMER PARAMS
// CUSTOMER PARAMS
List<CustomerParamBill> customerParams = new ArrayList<>();
if (responseWrapper.getCustomerParams() != null) {
for (CustomerParamDAO param : responseWrapper.getCustomerParams()) {
@@ -970,170 +962,45 @@ public class BillerMapperHelper {
}
billMaster.setCustomerParams(customerParams);
// DATES
billMaster.setCreationDate(responseWrapper.getCreationDate());
billMaster.setModifiedDate(responseWrapper.getModifiedDate());
// DATES
// Map incoming DTO date strings into Auditable LocalDateTime fields
LocalDateTime bmCreatedOn = parseToLocalDateTime(responseWrapper.getCreationDate());
if (bmCreatedOn != null) {
billMaster.setCreatedOn(bmCreatedOn);
}
LocalDateTime bmUpdatedOn = parseToLocalDateTime(responseWrapper.getModifiedDate());
if (bmUpdatedOn != null) {
billMaster.setUpdatedOn(bmUpdatedOn);
}
billMaster.setCreatedEpochDate(responseWrapper.getCreatedEpochDate());
billMaster.setModifiedEpochDate(responseWrapper.getModifiedEpochDate());
billMasterRepository.save(billMaster);
}
public void saveBillValidation(FetchBillValidateResponse responseWrapper, BillFetchByBillIdRequest billRequest,
String txnId) {
System.out.println("responseWrapper");
ModelMapper modelMapper = new ModelMapper();
try {
LOGGER.info("Saving bill validation data for billId={}", responseWrapper.getBillId());
// ✅ Map the main object
BillValidation billEntity = modelMapper.map(responseWrapper, BillValidation.class);
// ✅ Manually handle only the nested relationship part
if (responseWrapper.getCustomerParams() != null) {
List<CustomerParamBillValidation> customerParams = responseWrapper.getCustomerParams().stream()
.map(param -> {
CustomerParamBillValidation cp = modelMapper.map(param, CustomerParamBillValidation.class);
cp.setBill(billEntity); // maintain relation
return cp;
}).collect(Collectors.toList());
billEntity.setCustomerParams(customerParams);
}
if (responseWrapper.getAdditionalInfo() != null) {
List<AdditionalInfoBillValidate> additionalInfos = responseWrapper.getAdditionalInfo().stream()
.map(info -> {
AdditionalInfoBillValidate ai = modelMapper.map(info, AdditionalInfoBillValidate.class);
ai.setBill(billEntity); // maintain relation
return ai;
}).collect(Collectors.toList());
billEntity.setAdditionalInfo(additionalInfos);
billEntity.setClientUserId(billRequest.getClientUserId());
billEntity.setTxnId(txnId);
billEntity.setRefId(billRequest.getReqId());
}
// ✅ Save everything (cascade handles child)
billValidationRepository.save(billEntity);
LOGGER.info("Bill validation saved successfully for billId={}", billEntity.getBillId());
} catch (Exception ex) {
LOGGER.error("Error saving BillValidation data: {}", ex.getMessage(), ex);
throw new RuntimeException("Failed to save bill validation data", ex);
}
}
public FetchBillForwardRequest fetchBillForwardRequestMap(FetchBillRequest req) {
FetchBillForwardRequest forward = new FetchBillForwardRequest();
forward.setBillerId(req.getBillerId());
forward.setBillerName(req.getBillerName());
forward.setBillerCategory(req.getBillerCategory());
forward.setClientReqId(req.getClientReqId());
forward.setMacAdress(req.getMacAdress());
forward.setCustomerMobNo(req.getCustomerMobNo());
forward.setRemitterName(req.getRemitterName());
forward.setPaymentChannel(req.getPaymentChannel());
forward.setDeviceBlockTags(req.getDeviceBlockTags());
forward.setCustomerParamsRequest(req.getCustomerParamsRequest());
forward.setRemitterIdentity(req.getRemitterIdentity());
return forward;
}
public FetchBillValidatestForwardRequest fetchBillValidatestForwardRequest(FetchBillValidatestRequest req) {
FetchBillValidatestForwardRequest forward = new FetchBillValidatestForwardRequest();
forward.setBillerId(req.getBillerId());
forward.setBillerName(req.getBillerName());
forward.setBillerCategory(req.getBillerCategory());
forward.setCustomerMobNo(req.getCustomerMobNo());
forward.setClientReqId(req.getClientReqId());
forward.setMacAddress(req.getMacAddress());
forward.setCustomerParamsRequest(req.getCustomerParamsRequest());
return forward;
}
public BillPaymentForwardRequest billPaymentForwardRequest(BillPaymentRequest req) {
BillPaymentForwardRequest forward = new BillPaymentForwardRequest();
// forward.setTenantId(req.getTenantId());
forward.setRefId(req.getRefId());
forward.setBillId(req.getBillId());
forward.setAmountOptions(req.isAmountOptions());
forward.setPaymentMode(req.getPaymentMode());
forward.setPaymentInformation(req.getPaymentInformation());
forward.setBillerId(req.getBillerId());
forward.setBillerName(req.getBillerName());
forward.setBillerCategory(req.getBillerCategory());
forward.setMacAdress(req.getMacAdress());
forward.setCustomerMobNo(req.getCustomerMobNo());
forward.setTxnAmount(req.getTxnAmount());
forward.setPaymentRefId(req.getPaymentRefId());
forward.setClientReqId(req.getClientReqId());
forward.setPaymentChannel(req.getPaymentChannel());
forward.setDeviceBlockTags(req.getDeviceBlockTags());
forward.setCustomerParamsRequest(req.getCustomerParams());
forward.setRemitterIdentity(req.getRemitterIdentity());
forward.setAmountBreakSet(req.getAmountBreakSet());
return forward;
}
public FetchComplaintForwardRequest fetchComplaintForwardRequestMap(ComplaintRequestDTO complainRequestDTO) {
FetchComplaintForwardRequest forward = new FetchComplaintForwardRequest();
forward.setTicketDescription(complainRequestDTO.getTicketDescription());
forward.setTicketDisposition(complainRequestDTO.getTicketDisposition());
forward.setTicketDispositionCode(complainRequestDTO.getTicketDispositionCode());
forward.setTxnId(complainRequestDTO.getTxnId());
return forward;
}
public FetchTicketLatestStatusRequest fetchTicketLatestStatusRequestMap(GetTicketLatestStausRequest request) {
FetchTicketLatestStatusRequest forward = new FetchTicketLatestStatusRequest();
forward.setTicketId(request.getTicketId());
forward.setTxnNpciId(request.getTxnNpciId());
return forward;
}
public void savePaymentStartRecord(PaymentStartUserRequest request, PaymentStartApiResponse apiResponse,
String txnId, String orderNo, String requestJson, String rawResponse, String responseType) {
PaymentStartRecord record = new PaymentStartRecord();
record.setOrderNo(orderNo);
record.setRequestId(request.getReqId());
record.setClientMid(request.getMid());
record.setClientUserId(request.getClientUserId());
record.setInternalTxnId(txnId);
record.setAmount(Optional.ofNullable(apiResponse.getResponseData().getAmount()).orElse("0.00"));
record.setMid(Optional.ofNullable(apiResponse.getResponseData().getMid()).orElse("DUMMY_MID"));
record.setTxnId(Optional.ofNullable(apiResponse.getResponseData().getTxnId()).orElse("DUMMY_TXN"));
record.setQrString(Optional.ofNullable(apiResponse.getResponseData().getQrString()).orElse("NO_QR"));
record.setCreatedOn(Optional.ofNullable(apiResponse.getResponseData().getCreatedOn()).orElse(LocalDateTime.now().toString()));
record.setTxnStatus("PENDING");
// store the original request body and raw response
record.setRequestBody(requestJson);
record.setResponseBody(rawResponse);
record.setResponseType(responseType);
paymentStartRecordRepository.save(record);
}
public TransactionHistoryMasterDTO toDTO(TransactionMaster transactionMaster) {
if (transactionMaster == null) {
// Helper to parse incoming ISO date/time strings (with optional offset) into LocalDateTime
private LocalDateTime parseToLocalDateTime(String dateStr) {
if (dateStr == null || dateStr.isBlank()) {
return null;
}
try {
// Try parsing with offset first (e.g., 2023-04-19T17:28:05.508679Z or with +05:30)
OffsetDateTime odt = OffsetDateTime.parse(dateStr);
return odt.toLocalDateTime();
} catch (Exception e) {
try {
// Fallback to LocalDateTime without offset
return LocalDateTime.parse(dateStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
} catch (Exception ex) {
LOGGER.warn("Unable to parse date string to LocalDateTime: {}", dateStr);
return null;
}
}
}
// Create a new DTO and set the values from the entity
// Convert TransactionMaster to master DTO
public TransactionHistoryMasterDTO toDTO(TransactionMaster transactionMaster) {
if (transactionMaster == null) return null;
TransactionHistoryMasterDTO dto = new TransactionHistoryMasterDTO();
dto.setBankTxnId(transactionMaster.getBankTxnId());
dto.setTxnId(transactionMaster.getTxnId());
@@ -1174,16 +1041,12 @@ record.setTxnStatus("PENDING");
dto.setModifiedDate(transactionMaster.getModifiedDate());
dto.setCreatedEpochDate(transactionMaster.getCreatedEpochDate());
dto.setModifiedEpochDate(transactionMaster.getModifiedEpochDate());
return dto;
}
// Convert TransactionMaster to particular details DTO (used with method references)
public TransactionHistoryParticularDetailsDTO billerRemainingDetails(TransactionMaster transactionMaster) {
if (transactionMaster == null) {
return null;
}
// Create a new DTO and set the values from the entity
if (transactionMaster == null) return null;
TransactionHistoryParticularDetailsDTO dto = new TransactionHistoryParticularDetailsDTO();
dto.setBankTxnId(transactionMaster.getBankTxnId());
dto.setTxnId(transactionMaster.getTxnId());
@@ -1192,45 +1055,110 @@ record.setTxnStatus("PENDING");
dto.setBillerName(transactionMaster.getBillerName());
dto.setStatus(transactionMaster.getStatus());
dto.setTotalTxnAmount(transactionMaster.getTotalTxnAmount());
return dto;
}
// Map BillPaymentRequest to forward request used by external BBPS API
public BillPaymentForwardRequest billPaymentForwardRequest(BillPaymentRequest req) {
BillPaymentForwardRequest forward = new BillPaymentForwardRequest();
forward.setRefId(req.getRefId());
forward.setBillId(req.getBillId());
forward.setAmountOptions(req.isAmountOptions());
forward.setPaymentMode(req.getPaymentMode());
forward.setPaymentInformation(req.getPaymentInformation());
forward.setBillerId(req.getBillerId());
forward.setBillerName(req.getBillerName());
forward.setBillerCategory(req.getBillerCategory());
forward.setMacAdress(req.getMacAdress());
forward.setCustomerMobNo(req.getCustomerMobNo());
forward.setTxnAmount(req.getTxnAmount());
forward.setPaymentRefId(req.getPaymentRefId());
forward.setClientReqId(req.getClientReqId());
forward.setPaymentChannel(req.getPaymentChannel());
forward.setDeviceBlockTags(req.getDeviceBlockTags());
forward.setCustomerParamsRequest(req.getCustomerParams());
forward.setRemitterIdentity(req.getRemitterIdentity());
forward.setAmountBreakSet(req.getAmountBreakSet());
return forward;
}
// Map PaymentStartUserRequest + API response into PaymentStartRecord and persist
public void savePaymentStartRecord(PaymentStartUserRequest request, PaymentStartApiResponse apiResponse,
String txnId, String orderNo, String requestJson, String rawResponse, String responseType) {
PaymentStartRecord record = new PaymentStartRecord();
record.setOrderNo(orderNo);
record.setRequestId(request.getReqId());
record.setClientMid(request.getMid());
record.setClientUserId(request.getClientUserId());
record.setInternalTxnId(txnId);
if (apiResponse != null && apiResponse.getResponseData() != null) {
record.setAmount(Optional.ofNullable(apiResponse.getResponseData().getAmount()).orElse("0.00"));
record.setMid(Optional.ofNullable(apiResponse.getResponseData().getMid()).orElse("DUMMY_MID"));
record.setTxnId(Optional.ofNullable(apiResponse.getResponseData().getTxnId()).orElse("DUMMY_TXN"));
record.setQrString(Optional.ofNullable(apiResponse.getResponseData().getQrString()).orElse("NO_QR"));
// parse createdOn string into LocalDateTime and set on Auditable
LocalDateTime createdOn = parseToLocalDateTime(apiResponse.getResponseData().getCreatedOn());
if (createdOn == null) createdOn = LocalDateTime.now();
record.setCreatedOn(createdOn);
// default status pending
record.setTxnStatus("PENDING");
} else {
record.setAmount("0.00");
record.setMid(request.getMid());
record.setTxnStatus("PENDING");
record.setCreatedOn(LocalDateTime.now());
}
// store the original request body and raw response
record.setRequestBody(requestJson);
record.setResponseBody(rawResponse);
record.setResponseType(responseType);
paymentStartRecordRepository.save(record);
}
// Map ComplaintRequestDTO to forward request for complaint API
public FetchComplaintForwardRequest fetchComplaintForwardRequestMap(ComplaintRequestDTO complainRequestDTO) {
FetchComplaintForwardRequest forward = new FetchComplaintForwardRequest();
forward.setTicketDescription(complainRequestDTO.getTicketDescription());
forward.setTicketDisposition(complainRequestDTO.getTicketDisposition());
forward.setTicketDispositionCode(complainRequestDTO.getTicketDispositionCode());
forward.setTxnId(complainRequestDTO.getTxnId());
return forward;
}
// Map GetTicketLatestStausRequest to forward request
public FetchTicketLatestStatusRequest fetchTicketLatestStatusRequestMap(GetTicketLatestStausRequest request) {
FetchTicketLatestStatusRequest forward = new FetchTicketLatestStatusRequest();
forward.setTicketId(request.getTicketId());
forward.setTxnNpciId(request.getTxnNpciId());
return forward;
}
// Check if complaint can be raised (true if within 24 hours of transactionCreatedDateString)
public static boolean isComplaintAllowed(String transactionCreatedDateString) {
// Define the format of the transaction creation date including the time zone
// offset
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
if (transactionCreatedDateString == null || transactionCreatedDateString.isBlank()) return false;
try {
// Parse the transaction creation date string to OffsetDateTime (handles time
// zone)
OffsetDateTime transactionCreatedDate = OffsetDateTime.parse(transactionCreatedDateString, formatter);
// Get the current time (with offset)
OffsetDateTime transactionCreatedDate = OffsetDateTime.parse(transactionCreatedDateString);
OffsetDateTime currentTime = OffsetDateTime.now();
// Calculate the difference in hours
long hoursDifference = ChronoUnit.HOURS.between(transactionCreatedDate, currentTime);
// Return true if complaint can be raised (i.e., within 24 hours)
return hoursDifference >= 24;
// complaint allowed if within 24 hours
return hoursDifference <= 24;
} catch (Exception e) {
// Handle invalid date format or other parsing issues
System.err.println("Invalid date format: " + e.getMessage());
LOGGER.warn("isComplaintAllowed - invalid date string: {}", transactionCreatedDateString);
return false;
}
}
// Persist complaint response entity
public String saveComplaintResponseEntity(ComplaintResponse responseWrapper, String requestId, String txnId,
String userId) {
// 1. Convert ComplaintResponse DTO to ComplaintResponseEntity
if (responseWrapper == null || responseWrapper.getTicketDetails() == null) {
return "No data";
}
ComplaintResponseEntity complaintResponseEntity = new ComplaintResponseEntity();
// Map fields from DTO to entity
complaintResponseEntity.setRefId(responseWrapper.getTicketDetails().getRefId()); // For example, generate a
// unique ID
complaintResponseEntity.setRefId(responseWrapper.getTicketDetails().getRefId());
complaintResponseEntity.setTxnNpciId(responseWrapper.getTicketDetails().getTxnNpciId());
complaintResponseEntity.setTicketId(responseWrapper.getTicketDetails().getTicketId());
complaintResponseEntity.setTicketType(responseWrapper.getTicketDetails().getTicketType());
@@ -1238,36 +1166,107 @@ record.setTxnStatus("PENDING");
complaintResponseEntity.setTicketDesp(responseWrapper.getTicketDetails().getTicketDesp());
complaintResponseEntity.setTicketDesr(responseWrapper.getTicketDetails().getTicketDesr());
// Additional fields from ComplaintResponse DTO
complaintResponseEntity.setMessage(responseWrapper.getMessage());
complaintResponseEntity.setRemarks(responseWrapper.getRemarks());
complaintResponseEntity.setStatus(responseWrapper.getStatus());
complaintResponseEntity.setStatusCode(responseWrapper.getStatusCode());
// Set requestId and txnId from parameters
complaintResponseEntity.setReqId(requestId);
complaintResponseEntity.setTxnId(txnId);
complaintResponseEntity.setUserId(userId);
complaintResponseEntity.setCreateDateTime(new Date());
// If you need a separate complaintTicketId, you can set it here
complaintResponseEntity.setComplaintTicketId(generateComplaintTicketId()); // Generate or set manually
complaintResponseEntity.setComplaintTicketId(generateComplaintTicketId());
// Save the entity
complaintResponseRepository.save(complaintResponseEntity);
ComplaintResponseEntity savedEntity = complaintResponseRepository.save(complaintResponseEntity);
// Check if the entity is saved successfully and return count (1 for success)
if (savedEntity != null) {
return "1 record saved with RefId: " + savedEntity.toString();
} else {
return "Failed to save complaint response.";
ComplaintResponseEntity saved = complaintResponseRepository.save(complaintResponseEntity);
if (saved != null) {
return "1 record saved with id=" + saved.getId();
}
return "Failed to save";
}
// Save Complain Response From DB
private String generateComplaintTicketId() {
// Logic for generating complaint ticket ID
return "CMP-" + UUID.randomUUID().toString();
}
// Minimal mapping helpers used by AgentServiceImpl
public com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest fetchBillForwardRequestMap(
com.billpaymentservice.bbps.dto.request.FetchBillRequest req) {
if (req == null) return null;
com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest f = new com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest();
f.setBillerId(req.getBillerId());
f.setBillerName(req.getBillerName());
f.setBillerCategory(req.getBillerCategory());
f.setClientReqId(req.getClientReqId());
f.setMacAdress(req.getMacAdress());
f.setCustomerMobNo(req.getCustomerMobNo());
f.setRemitterName(req.getRemitterName());
f.setPaymentChannel(req.getPaymentChannel());
f.setDeviceBlockTags(req.getDeviceBlockTags());
f.setCustomerParamsRequest(req.getCustomerParamsRequest());
f.setRemitterIdentity(req.getRemitterIdentity());
return f;
}
public com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest fetchBillValidatestForwardRequest(
com.billpaymentservice.bbps.dto.request.FetchBillValidatestRequest req) {
if (req == null) return null;
com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest f = new com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest();
f.setBillerId(req.getBillerId());
f.setBillerName(req.getBillerName());
f.setBillerCategory(req.getBillerCategory());
f.setCustomerMobNo(req.getCustomerMobNo());
f.setClientReqId(req.getClientReqId());
f.setMacAddress(req.getMacAddress());
f.setCustomerParamsRequest(req.getCustomerParamsRequest());
return f;
}
public void saveBillValidation(com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse responseWrapper,
com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest billRequest, String txnId) {
if (responseWrapper == null || billRequest == null) return;
BillValidation entity = new BillValidation();
entity.setBillId(responseWrapper.getBillId());
entity.setRefId(responseWrapper.getRefId());
entity.setBillerId(responseWrapper.getBillerId());
entity.setStatus(responseWrapper.getStatus());
entity.setActionType(responseWrapper.getActionType());
entity.setUserId(responseWrapper.getUserId());
entity.setBillerResponse(responseWrapper.getBillerResponse());
entity.setTxnId(txnId);
entity.setReqId(billRequest.getReqId());
// Map additionalInfo if present (minimal mapping)
if (responseWrapper.getAdditionalInfo() != null) {
List<AdditionalInfoBillValidate> addList = new ArrayList<>();
for (com.billpaymentservice.bbps.dto.AdditionalInfoBillValidateDTO ai : responseWrapper.getAdditionalInfo()) {
AdditionalInfoBillValidate info = new AdditionalInfoBillValidate();
// DTO only has name & value
info.setName(ai.getName());
info.setValue(ai.getValue());
info.setBill(entity);
addList.add(info);
}
entity.setAdditionalInfo(addList);
}
// Map customerParams if present (minimal mapping)
if (responseWrapper.getCustomerParams() != null) {
List<CustomerParamBillValidation> cpList = new ArrayList<>();
for (com.billpaymentservice.bbps.dto.CustomerParamDAO cp : responseWrapper.getCustomerParams()) {
CustomerParamBillValidation param = new CustomerParamBillValidation();
param.setName(cp.getName());
param.setValue(cp.getValue());
param.setType(cp.getType());
param.setBill(entity);
cpList.add(param);
}
entity.setCustomerParams(cpList);
}
// Persist
try {
billValidationRepository.save(entity);
} catch (Exception e) {
LOGGER.error("Error saving BillValidation: {}", e.getMessage(), e);
}
}
}
@@ -94,7 +94,6 @@ public class Helper {
public static String generateTxnId(int n) {
StringBuilder sb = new StringBuilder(n);
for (int i = 0; i < n; i++) {
int index = secureRandom.nextInt(CHARACTERS.length());
sb.append(CHARACTERS.charAt(index));
@@ -185,7 +184,8 @@ public class Helper {
user.setName(request.getName());
user.setEmail(request.getEmail());
user.setMid(request.getMid());
user.setCreateDateTime(new Date());
// set audit createdOn timestamp
user.setCreatedOn(LocalDateTime.now());
// Generate a unique userId (UUID)
String uniqueUserId = generateUniqueUserId();
user.setUserId(uniqueUserId);
@@ -19,11 +19,12 @@ swagger.server.description=Local Development Server
# DataSource
spring.datasource.url=jdbc:postgresql://localhost:5432/devdbuat
#spring.datasource.url=jdbc:postgresql://localhost:5432/devdbuat
spring.datasource.url=jdbc:postgresql://localhost:5432/bbps_enhanced
spring.datasource.username=postgres
spring.datasource.password=UAT@DB_2025
#spring.datasource.password=UAT@DB_2025
#spring.datasource.password=himanshu@123
spring.datasource.password=himanshu@123
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
+1 -1
View File
@@ -21,7 +21,7 @@ spring.profiles.active=local
# DataSource
spring.datasource.url=jdbc:postgresql://localhost:5432/BBPS
spring.datasource.url=jdbc:postgresql://localhost:5432/BBPS_Enhanced
spring.datasource.username=postgres
#spring.datasource.password=UAT@DB_2025