Skip to content

Commit

Permalink
[Java21]
Browse files Browse the repository at this point in the history
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
  • Loading branch information
JanardhanBS-SyncByte committed Jun 12, 2024
1 parent 8aa4e9b commit eb1329f
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import io.mosip.preregistration.application.service.LoginService;
import io.mosip.preregistration.core.config.LoggerConfiguration;

import static io.mosip.preregistration.application.constant.PreRegLoginConstant.LOGGER_SESSIONID;
import static io.mosip.preregistration.application.constant.PreRegLoginConstant.LOGGER_IDTYPE;
import static io.mosip.preregistration.application.constant.PreRegLoginConstant.LOGGER_ID;

@Configuration
public class ApplicationEventListerner {

Expand All @@ -27,15 +31,14 @@ public class ApplicationEventListerner {

@EventListener(ApplicationStartedEvent.class)
public void applicationStartedEvent() {
log.info("sessionId", "idType", "id", "In applicationStartedEvent method of ApplicationEventListerner");
log.info("sessionId", "idType", "id",
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID, "In applicationStartedEvent method of ApplicationEventListerner");
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID,
"In applicationStartedEvent method of ApplicationEventListerner login service setupLoginService method called");
demographicService.setup();
log.info("sessionId", "idType", "id",
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID,
"In applicationStartedEvent method of ApplicationEventListerner demographic Service setup() method is called");
documentService.setup();
log.info("sessionId", "idType", "id",
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID,
"In applicationStartedEvent method of ApplicationEventListerner documentService setup() method is called");
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package io.mosip.preregistration.application.constant;

public class PreRegLoginConstant {
private PreRegLoginConstant() {
throw new IllegalStateException("PreRegLoginConstant class");
}

public static final String LOGGER_SESSIONID = "PRE-REGISTRATION";
public static final String LOGGER_IDTYPE = "APPLICATION SERVICE";
public static final String LOGGER_ID = "";

public static final String OTP_SMS_TEMPLATE = "pre.reg.login.otp.sms.template";
public static final String OTP_SUBJECT_TEMPLATE = "pre.reg.login.otp.mail.subject.template";
public static final String OTP_CONTENT_TEMPLATE = "pre.reg.login.otp.mail.content.template";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

import static io.mosip.preregistration.application.constant.PreRegLoginConstant.LOGGER_SESSIONID;
import static io.mosip.preregistration.application.constant.PreRegLoginConstant.LOGGER_IDTYPE;
import static io.mosip.preregistration.application.constant.PreRegLoginConstant.LOGGER_ID;

/**
* This class provides different API's to perform operations on
* pre-registration.
Expand Down Expand Up @@ -115,7 +119,7 @@ public void initBinder(WebDataBinder binder) {
public ResponseEntity<MainResponseDTO<DemographicCreateResponseDTO>> addPreRegDemographicData(
@Validated @RequestBody(required = true) MainRequestDTO<DemographicRequestDTO> jsonObject,
@ApiParam(hidden = true) Errors errors) {
log.info("sessionId", "idType", "id",
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID,
"In pre-registration controller for add preregistration with json object" + jsonObject);
requestValidator.validateId(CREATE, jsonObject.getId(), errors);
DataValidationUtil.validate(errors, CREATE);
Expand Down Expand Up @@ -145,7 +149,7 @@ public ResponseEntity<MainResponseDTO<DemographicUpdateResponseDTO>> updatePreRe
@Validated @RequestBody(required = true) MainRequestDTO<DemographicRequestDTO> jsonObject,
@ApiParam(hidden = true) Errors errors) {
String userId = preRegistrationService.authUserDetails().getUserId();
log.info("sessionId", "idType", "id",
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID,
"In pre-registration controller for Update preregistration with json object" + jsonObject);
requestValidator.validateId(UPDATE, jsonObject.getId(), errors);
DataValidationUtil.validate(errors, UPDATE);
Expand All @@ -170,7 +174,7 @@ public ResponseEntity<MainResponseDTO<DemographicUpdateResponseDTO>> updatePreRe
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(hidden = true))) })
public ResponseEntity<MainResponseDTO<DemographicResponseDTO>> getPreRegDemographicData(
@PathVariable("preRegistrationId") String preRegistraionId) {
log.info("sessionId", "idType", "id",
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID,
"In pre-registration controller for fetching all demographic data with preregistrationId"
+ preRegistraionId);
return ResponseEntity.status(HttpStatus.OK).body(preRegistrationService.getDemographicData(preRegistraionId));
Expand Down Expand Up @@ -198,7 +202,7 @@ public ResponseEntity<MainResponseDTO<String>> updatePreRegApplicationStatus(
@PathVariable("preRegistrationId") String preRegId,
@RequestParam(value = "statusCode", required = true) String status) {
String userId = preRegistrationService.authUserDetails().getUserId();
log.info("sessionId", "idType", "id",
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID,
"In pre-registration controller for fetching all demographic data with preRegId " + preRegId
+ " and status " + status);
return ResponseEntity.status(HttpStatus.OK)
Expand All @@ -225,7 +229,7 @@ public ResponseEntity<MainResponseDTO<String>> updatePreRegApplicationStatus(
public ResponseEntity<MainResponseDTO<DemographicMetadataDTO>> getAllPreRegApplications(HttpServletRequest res,
@RequestParam(value = "pageIndex", required = false) String pageIdx) {
String userId = preRegistrationService.authUserDetails().getUserId();
log.info("sessionId", "idType", "id",
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID,
"In pre-registration controller for fetching all applications with userId ");
return ResponseEntity.status(HttpStatus.OK)
.body(preRegistrationService.getAllApplicationDetails(userId, pageIdx));
Expand All @@ -250,7 +254,7 @@ public ResponseEntity<MainResponseDTO<DemographicMetadataDTO>> getAllPreRegAppli
public ResponseEntity<MainResponseDTO<PreRegistartionStatusDTO>> getPreRegApplicationStatus(
@PathVariable("preRegistrationId") String preId) {
String userId = preRegistrationService.authUserDetails().getUserId();
log.info("sessionId", "idType", "id",
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID,
"In pre-registration controller for fetching all applicationStatus with preId " + preId);
return ResponseEntity.status(HttpStatus.OK).body(preRegistrationService.getApplicationStatus(preId, userId));
}
Expand All @@ -274,7 +278,7 @@ public ResponseEntity<MainResponseDTO<PreRegistartionStatusDTO>> getPreRegApplic
public ResponseEntity<MainResponseDTO<DeletePreRegistartionDTO>> deletePreRegApplication(
@PathVariable("preRegistrationId") String preId) {
String userId = preRegistrationService.authUserDetails().getUserId();
log.info("sessionId", "idType", "id",
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID,
"In pre-registration controller for deletion of individual with preId " + preId);

return ResponseEntity.status(HttpStatus.OK).body(preRegistrationService.deleteIndividual(preId, userId));
Expand Down Expand Up @@ -309,9 +313,8 @@ public ResponseEntity<MainResponseDTO<Map<String, String>>> getUpdatedDateTimeBy
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(hidden = true))) })
public ResponseEntity<MainResponseDTO<?>> getPreRegDemographicAndDocumentData(
@PathVariable("preregistrationId") String preregistrationId) {
log.info("In demographic controller to getFullPreRegApplication {}", preregistrationId);
log.info(LOGGER_SESSIONID, LOGGER_IDTYPE, LOGGER_ID, "In demographic controller to getFullPreRegApplication " + preregistrationId);
return ResponseEntity.status(HttpStatus.OK)
.body(preRegistrationService.getPregistrationInfo(preregistrationId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand All @@ -19,7 +18,6 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
Expand All @@ -43,8 +41,6 @@
import io.mosip.kernel.core.util.JsonUtils;
import io.mosip.kernel.core.util.exception.JsonProcessingException;
import io.mosip.preregistration.application.code.DemographicRequestCodes;
import io.mosip.preregistration.application.dto.ApplicantTypeRequestDTO;
import io.mosip.preregistration.application.dto.ApplicantValidDocumentDto;
import io.mosip.preregistration.application.dto.ApplicationInfoMetadataDTO;
import io.mosip.preregistration.application.dto.DeletePreRegistartionDTO;
import io.mosip.preregistration.application.dto.DemographicCreateResponseDTO;
Expand All @@ -53,15 +49,13 @@
import io.mosip.preregistration.application.dto.DemographicUpdateResponseDTO;
import io.mosip.preregistration.application.dto.DemographicViewDTO;
import io.mosip.preregistration.application.dto.IdSchemaDto;
import io.mosip.preregistration.application.dto.SchemaResponseDto;
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.BookingDeletionFailedException;
import io.mosip.preregistration.application.exception.DemographicServiceException;
import io.mosip.preregistration.application.exception.DocumentNotFoundException;
import io.mosip.preregistration.application.exception.RecordFailedToUpdateException;
import io.mosip.preregistration.application.exception.RecordNotFoundException;
import io.mosip.preregistration.application.exception.RecordNotFoundForPreIdsException;
import io.mosip.preregistration.application.exception.util.DemographicExceptionCatcher;
Expand All @@ -80,7 +74,6 @@
import io.mosip.preregistration.core.common.dto.DemographicResponseDTO;
import io.mosip.preregistration.core.common.dto.DocumentMultipartResponseDTO;
import io.mosip.preregistration.core.common.dto.DocumentsMetaData;
import io.mosip.preregistration.core.common.dto.ExceptionJSONInfoDTO;
import io.mosip.preregistration.core.common.dto.MainRequestDTO;
import io.mosip.preregistration.core.common.dto.MainResponseDTO;
import io.mosip.preregistration.core.common.dto.PreRegIdsByRegCenterIdDTO;
Expand All @@ -91,15 +84,13 @@
import io.mosip.preregistration.core.common.entity.DocumentEntity;
import io.mosip.preregistration.core.config.LoggerConfiguration;
import io.mosip.preregistration.core.exception.EncryptionFailedException;
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.exception.PreRegistrationException;
import io.mosip.preregistration.core.exception.RecordFailedToDeleteException;
import io.mosip.preregistration.core.util.AuditLogUtil;
import io.mosip.preregistration.core.util.CryptoUtil;
import io.mosip.preregistration.core.util.HashUtill;
import io.mosip.preregistration.core.util.ValidationUtil;
import io.mosip.preregistration.demographic.exception.system.SystemFileIOException;

Expand Down Expand Up @@ -144,7 +135,7 @@ public class DemographicService implements DemographicServiceIntf {
private DocumentServiceIntf documentServiceImpl;

@Autowired
private CommonServiceUtil commonServiceUtil;
CommonServiceUtil commonServiceUtil;

/**
* Autowired reference for {@link #AuditLogUtil}
Expand Down Expand Up @@ -178,11 +169,6 @@ public class DemographicService implements DemographicServiceIntf {
*/
@Value("${mosip.preregistration.demographic.retrieve.basic.id}")
private String retrieveId;
/**
* Reference for ${retrieveDetailsId} from property file
*/
@Value("${mosip.preregistration.demographic.retrieve.details.id}")
private String retrieveDetailsId;

/**
* Reference for ${retrieveStatusId} from property file
Expand Down Expand Up @@ -227,12 +213,6 @@ public class DemographicService implements DemographicServiceIntf {
@Value("${mosip.pregistration.pagesize}")
private String pageSize;

/**
* Reference for ${mosip.utc-datetime-pattern} from property file
*/
@Value("${mosip.utc-datetime-pattern}")
private String dateFormat;

@Value("${preregistration.config.identityjson}")
private String preregistrationIdJson;
/**
Expand All @@ -255,7 +235,6 @@ public class DemographicService implements DemographicServiceIntf {
@Value("${mosip.utc-datetime-pattern}")
private String mosipDateTimeFormat;


/**
* This method acts as a post constructor to initialize the required request
* parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -57,6 +58,7 @@
* @since 1.0.0
*/
@Component
@RefreshScope
public class CommonServiceUtil {
/**
* logger instance
Expand Down Expand Up @@ -235,11 +237,9 @@ public List<String> validMandatoryDocumentsForApplicant(DemographicEntity demogr
Set<String> mandatoryDocCat = demographicServiceUtil.getMandatoryDocCatogery();

log.info("mandatory Docs category --> {}", mandatoryDocCat);
List<String> validMandatoryDocumentForApplicant = applicantValidDocuments.getDocumentCategories().stream()
return applicantValidDocuments.getDocumentCategories().stream()
.filter(docCat -> mandatoryDocCat.contains(docCat.getCode())).map(docCat -> docCat.getCode())
.collect(Collectors.toList());

return validMandatoryDocumentForApplicant;
}

public MainResponseDTO<String> updatePreRegistrationStatus(String preRegId, String status, String userId) {
Expand All @@ -262,7 +262,6 @@ public MainResponseDTO<String> updatePreRegistrationStatus(String preRegId, Stri
log.error("sessionId", "idType", "id", ExceptionUtils.getStackTrace(ex));
log.error("sessionId", "idType", "id",
"Error in updatePreRegistrationStatus method of pre-registration service- " + ex.getMessage());
// new DemographicExceptionCatcher().handle(ex, response);
ExceptionJSONInfoDTO errorDetails = new ExceptionJSONInfoDTO(ex.getErrorCode(), ex.getErrorText());
List<ExceptionJSONInfoDTO> errorList = new ArrayList<>();
errorList.add(errorDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import io.mosip.preregistration.application.exception.DocumentNotValidException;
import io.mosip.preregistration.application.exception.DocumentSizeExceedException;
import io.mosip.preregistration.application.exception.InvalidDocumentIdExcepion;
import io.mosip.preregistration.application.service.DemographicService;
import io.mosip.preregistration.core.code.StatusCodes;
import io.mosip.preregistration.core.common.dto.DemographicResponseDTO;
import io.mosip.preregistration.core.common.dto.MainRequestDTO;
Expand Down Expand Up @@ -235,7 +234,6 @@ public Integer parseDocumentId(String documentId) {
throw new InvalidDocumentIdExcepion(DocumentErrorCodes.PRG_PAM_DOC_019.toString(),
DocumentErrorMessages.INVALID_DOCUMENT_ID.getMessage());
}

}

public boolean isValidCatCode(String catCode) {
Expand Down Expand Up @@ -306,9 +304,10 @@ public boolean fileSizeCheck(long uploadedFileSize) {
*/
public boolean fileExtensionCheck(MultipartFile file) {
log.info("sessionId", "idType", "id", "In fileExtensionCheck method of document service util");
//List<String> fileExtensionList = Arrays.asList(fileExtension.split("\\s*,\\s*"));
// List<String> fileExtensionList =
// Arrays.asList(fileExtension.split("\\s*,\\s*"));
List<String> fileExtensionList = Arrays.asList(fileExtension.split(","));
List<String> fileExtensionTrimmedList = new ArrayList<String>();
List<String> fileExtensionTrimmedList = new ArrayList<String>();
fileExtensionList.forEach(str -> fileExtensionTrimmedList.add(str.trim()));
if (fileExtensionTrimmedList.contains(FilenameUtils.getExtension(file.getOriginalFilename()).toUpperCase())) {
return true;
Expand All @@ -324,7 +323,6 @@ public boolean fileExtensionCheck(MultipartFile file) {
* @param documentDto DocumentRequestDTO
* @return boolean
*/

public boolean isValidRequest(DocumentRequestDTO documentDto, String preRegistrationId) {
log.info("sessionId", "idType", "id", "In isValidRequest method of document service util");
if (isNull(preRegistrationId)) {
Expand All @@ -338,24 +336,24 @@ public boolean isValidRequest(DocumentRequestDTO documentDto, String preRegistra
* This method checks the file extension
*
* @param file pass uploaded file
* @throws java.io.IOException
* @throws java.io.IOException
* @throws DocumentNotValidException if uploaded document is not valid
*/
public void virusScanCheck(MultipartFile file) throws java.io.IOException {
try {
log.info("sessionId", "idType", "id", "In isVirusScanSuccess method of document service util");
Boolean scanSuccess = virusScan.scanDocument(file.getBytes());
if (!scanSuccess) {
throw new VirusScannerException(DocumentErrorCodes.PRG_PAM_DOC_010.toString(),
DocumentErrorMessages.DOCUMENT_FAILED_IN_VIRUS_SCAN.getMessage());
}
} catch (VirusScannerException e) {
log.error("sessionId", "idType", "id", ExceptionUtils.getStackTrace(e));
log.error("sessionId", "idType", "id", e.getMessage());
throw new VirusScannerException(DocumentErrorCodes.PRG_PAM_DOC_010.toString(),
DocumentErrorMessages.DOCUMENT_FAILED_IN_VIRUS_SCAN.getMessage());
}
}
public void virusScanCheck(MultipartFile file) throws java.io.IOException {
try {
log.info("sessionId", "idType", "id", "In isVirusScanSuccess method of document service util");
Boolean scanSuccess = virusScan.scanDocument(file.getBytes());
if (!scanSuccess) {
throw new VirusScannerException(DocumentErrorCodes.PRG_PAM_DOC_010.toString(),
DocumentErrorMessages.DOCUMENT_FAILED_IN_VIRUS_SCAN.getMessage());
}
} catch (VirusScannerException e) {
log.error("sessionId", "idType", "id", ExceptionUtils.getStackTrace(e));
log.error("sessionId", "idType", "id", e.getMessage());
throw new VirusScannerException(DocumentErrorCodes.PRG_PAM_DOC_010.toString(),
DocumentErrorMessages.DOCUMENT_FAILED_IN_VIRUS_SCAN.getMessage());
}
}

public DemographicResponseDTO getPreRegInfoRestService(String preId) {
log.info("sessionId", "idType", "id", "In callGetPreRegInfoRestService method of document service util");
Expand Down Expand Up @@ -397,7 +395,6 @@ private boolean compareUploadedDocListAndValidMandatoryDocList(List<String> avai
return false;
}
}

}

@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)
Expand Down
Loading

0 comments on commit eb1329f

Please sign in to comment.