Skip to content

Commit

Permalink
Lost UIN request
Browse files Browse the repository at this point in the history
  • Loading branch information
joelethan committed Oct 28, 2022
1 parent fd1924e commit 7e40f2c
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
public class PreRegistrationApplication {
public static void main(String[] args) {
SpringApplication.run(PreRegistrationApplication.class, args);
System.out.println("PreRegistrationApplication.............");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.mosip.preregistration.application.repository;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import io.mosip.kernel.core.dataaccess.spi.repository.BaseRepository;
import io.mosip.preregistration.core.common.entity.LostUINEntity;


/**
*
** This repository interface is used to define the JPA methods for LostUINRepository
*
* @author Joel K
* @since 1.0.0
*
*/
@Repository
@Transactional
public interface LostUINRepository extends BaseRepository<LostUINEntity, String> {

@Query("SELECT e FROM LostUINEntity e WHERE e.crBy= ?1 order by e.crDtime desc")
public List<LostUINEntity> findByCreatedBy(String userId);

@Modifying
@Query("DELETE FROM ApplicationEntity e WHERE e.applicationId = ?1")
public void deleteById(int applicationId);

@Modifying
@Query(value = "INSERT INTO application_replacements (replacement_id, demographic_id, application_id, lang_code, cr_by) VALUES (?, ?, ?, ?, ?)", nativeQuery = true)
LostUINEntity save(Integer replacementId, String demographicId, String applicationId, String langCode, String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
Expand Down Expand Up @@ -40,13 +41,17 @@
import io.mosip.preregistration.application.dto.UIAuditRequest;
import io.mosip.preregistration.application.errorcodes.ApplicationErrorCodes;
import io.mosip.preregistration.application.errorcodes.ApplicationErrorMessages;
import io.mosip.preregistration.application.errorcodes.DemographicErrorCodes;
import io.mosip.preregistration.application.errorcodes.DemographicErrorMessages;
import io.mosip.preregistration.application.exception.AuditFailedException;
import io.mosip.preregistration.application.exception.BookingDeletionFailedException;
import io.mosip.preregistration.application.exception.DemographicServiceException;
import io.mosip.preregistration.application.exception.InvalidDateFormatException;
import io.mosip.preregistration.application.exception.RecordNotFoundException;
import io.mosip.preregistration.application.exception.util.DemographicExceptionCatcher;
import io.mosip.preregistration.application.repository.ApplicationRepostiory;
import io.mosip.preregistration.application.repository.DemographicRepository;
import io.mosip.preregistration.application.repository.LostUINRepository;
import io.mosip.preregistration.application.service.util.DemographicServiceUtil;
import io.mosip.preregistration.core.code.ApplicationStatusCode;
import io.mosip.preregistration.core.code.AuditLogVariables;
Expand All @@ -57,14 +62,19 @@
import io.mosip.preregistration.core.code.StatusCodes;
import io.mosip.preregistration.core.common.dto.AuditRequestDto;
import io.mosip.preregistration.core.common.dto.DeleteBookingDTO;
import io.mosip.preregistration.core.common.dto.DemographicResponseDTO;
import io.mosip.preregistration.core.common.dto.MainRequestDTO;
import io.mosip.preregistration.core.common.dto.MainResponseDTO;
import io.mosip.preregistration.core.common.entity.ApplicationEntity;
import io.mosip.preregistration.core.common.entity.DemographicEntity;
import io.mosip.preregistration.core.common.entity.LostUINEntity;
import io.mosip.preregistration.core.config.LoggerConfiguration;
import io.mosip.preregistration.core.exception.HashingException;
import io.mosip.preregistration.core.exception.InvalidPreRegistrationIdException;
import io.mosip.preregistration.core.exception.InvalidRequestParameterException;
import io.mosip.preregistration.core.exception.PreIdInvalidForUserIdException;
import io.mosip.preregistration.core.util.AuditLogUtil;
import io.mosip.preregistration.core.util.HashUtill;
import io.mosip.preregistration.core.util.ValidationUtil;

@Service
Expand All @@ -76,6 +86,15 @@ public class ApplicationService implements ApplicationServiceIntf {
@Autowired
ApplicationRepostiory applicationRepository;

@Autowired
private LostUINRepository lostUINRepository;

/**
* Autowired reference for {@link #RegistrationRepository}
*/
@Autowired
private DemographicRepository demographicRepository;

@Autowired
AuditLogUtil auditUtil;

Expand Down Expand Up @@ -295,6 +314,19 @@ public MainResponseDTO<ApplicationResponseDTO> addLostOrUpdateApplication(
ApplicationStatusCode.SUBMITTED.getApplicationStatusCode(),
StatusCodes.PENDING_APPOINTMENT.getCode(), authUserDetails().getUserId());
isSuccess = true;

if (bookingType.equals(BookingTypeCodes.LOST_FORGOTTEN_UIN.toString())) {
LostUINEntity lostUINEntity = new LostUINEntity();

lostUINEntity.setDemographicId(request.getRequest().getPreregistrationId());
lostUINEntity.setApplicationId(applicationEntity.getApplicationId());
lostUINEntity.setLangCode(request.getRequest().getLangCode());
lostUINEntity.setCrBy(applicationEntity.getCrBy());
lostUINEntity.setCrDtime(LocalDateTime.now(ZoneId.of("UTC")));

lostUINRepository.save(lostUINEntity);
}

ApplicationResponseDTO appplicationResponse = new ApplicationResponseDTO();
appplicationResponse.setApplicationId(applicationEntity.getApplicationId());
appplicationResponse.setBookingType(applicationEntity.getBookingType());
Expand All @@ -305,6 +337,34 @@ public MainResponseDTO<ApplicationResponseDTO> addLostOrUpdateApplication(
appplicationResponse.setCreatedDateTime(serviceUtil.getLocalDateString(applicationEntity.getCrDtime()));
appplicationResponse.setUpdatedBy(applicationEntity.getUpdBy());
appplicationResponse.setUpdatedDateTime(serviceUtil.getLocalDateString(applicationEntity.getUpdDtime()));

DemographicEntity demographicEntity = demographicRepository.findBypreRegistrationId(request.getRequest().getPreregistrationId());
System.out.println("demographicEntity...." + demographicEntity);
if (demographicEntity != null) {
List<String> list = listAuth(authUserDetails().getAuthorities());
log.info("sessionId", "idType", "id",
"In getDemographicData method of pre-registration service with list " + list);
if (list.contains("ROLE_INDIVIDUAL")) {
userValidationz(authUserDetails().getUserId(), demographicEntity.getCreatedBy());
}
String hashString = HashUtill.hashUtill(demographicEntity.getApplicantDetailJson());

if (HashUtill.isHashEqual(demographicEntity.getDemogDetailHash().getBytes(),
hashString.getBytes())) {

DemographicResponseDTO demographicData = serviceUtil.setterForCreateDTO(demographicEntity);
appplicationResponse.setDemographicData(demographicData);
} else {
throw new HashingException(
io.mosip.preregistration.core.errorcodes.ErrorCodes.PRG_CORE_REQ_010.name(),
io.mosip.preregistration.core.errorcodes.ErrorMessages.HASHING_FAILED.name());

}
} else {
throw new RecordNotFoundException(DemographicErrorCodes.PRG_PAM_APP_005.getCode(),
DemographicErrorMessages.UNABLE_TO_FETCH_THE_PRE_REGISTRATION.getMessage());
}

mainResponseDTO.setResponse(appplicationResponse);
mainResponseDTO.setResponsetime(serviceUtil.getCurrentResponseTime());
log.info("sessionId", "idType", "id",
Expand Down Expand Up @@ -514,6 +574,16 @@ private void userValidation(ApplicationEntity applicationEntity) {

}


public void userValidationz(String authUserId, String preregUserId) {
log.info("sessionId", "idType", "id", "In getDemographicData method of userValidation with priid "
+ preregUserId + " and userID " + authUserId);
if (!authUserId.trim().equals(preregUserId.trim())) {
throw new PreIdInvalidForUserIdException(DemographicErrorCodes.PRG_PAM_APP_017.getCode(),
DemographicErrorMessages.INVALID_PREID_FOR_USER.getMessage());
}
}

/**
* This method is used to get the list of authorization role
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ public class ApplicationRequestDTO implements Serializable {
*/
private String langCode;

// pre pre registration ID
private String preregistrationId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;

import io.mosip.preregistration.core.common.dto.DemographicResponseDTO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand Down Expand Up @@ -61,4 +62,8 @@ public class ApplicationResponseDTO implements Serializable {
*/
private String bookingType;

/**
* the respective demographic data
*/
private DemographicResponseDTO demographicData;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.mosip.preregistration.application.dto;

import java.io.Serializable;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;


/**
* This DTO class defines the variables to accept the input parameter from
* request.
*
* @author Joel K
* @since 1.2.0
*
*/
@Getter
@Setter
@NoArgsConstructor
@ToString
public class LostUINRequestDTO implements Serializable {

/**
*
*/
private static final long serialVersionUID = 686366342082625076L;
/**
* language code
*/
private String langCode;

// pre pre registration ID
private String preregistrationId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.mosip.preregistration.application.dto;

import java.io.Serializable;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
*
* The Class LostUINResponseDTO.
*
* @author Joel K
* @since 1.2.0
*
*/
@Getter
@Setter
@NoArgsConstructor
@ToString
public class LostUINResponseDTO implements Serializable {

/**
*
*/
private static final long serialVersionUID = -667562552980002417L;

/** The application-Id. */
private String applicationId;

/** The created by. */
private String createdBy;

/** The create date time. */
private String createdDateTime;

/** The updated by. */
private String updatedBy;

/** The update date time. */
private String updatedDateTime;

/**
* application status code
*/
private String applicationStatusCode;

/**
* booking status code
*/
private String bookingStatusCode;

/**
* language code
*/
private String langCode;

/**
* the booking type
*/
private String bookingType;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright
*
*/
package io.mosip.preregistration.core.common.entity;

import java.io.Serializable;
import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.NamedQuery;
import org.springframework.stereotype.Component;

import lombok.NoArgsConstructor;

/**
* This entity class defines the database table details for LostUINEntity.
*
* @author Joel K
* @since 1.0.0
*
*/
@Component
@Entity
@Table(name = "application_replacements", schema = "prereg")
@NoArgsConstructor
@NamedQuery(name = "LostUINEntity.findByCreatedByOrderByCreateDateTime", query = "SELECT e FROM LostUINEntity e WHERE e.crBy=:userId order by e.crDtime desc")
@NamedQuery(name = "LostUINEntity.findByCreatedBy", query = "SELECT e FROM LostUINEntity e WHERE e.crBy=:userId order by e.crDtime desc")
public class LostUINEntity implements Serializable {

/** The Constant serialVersionUID. */
private static final long serialVersionUID = 6705845720255847210L;

@Id
@Column(name = "application_id")
private String applicationId;

@Column(name = "demographic_id", nullable = false)
private String demographicId;

@Column(name = "lang_code", nullable = false)
private String langCode;

@Column(name = "created_by")
private String crBy;

@Column(name = "created_at")
private LocalDateTime crDtime;

public static long getSerialversionuid() {
return serialVersionUID;
}

public void setDemographicId(String demographicId) {
this.demographicId = demographicId;
}

public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}

public void setCrBy(String crBy) {
this.crBy = crBy;
}

public void setCrDtime(LocalDateTime crDtime) {
this.crDtime = crDtime;
}

public void setLangCode(String langCode) {
this.langCode = langCode;
}
}

0 comments on commit 7e40f2c

Please sign in to comment.