Skip to content

Commit

Permalink
Merge pull request #314 from mosip/develop
Browse files Browse the repository at this point in the history
MOSIP-16354 MOSIP-17580
  • Loading branch information
mandeepdhiman123 authored Sep 21, 2021
2 parents d87fb55 + c6c83b3 commit 3c0e666
Show file tree
Hide file tree
Showing 21 changed files with 511 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,8 @@ public class LoginConfig {

@Bean
public OpenAPI customOpenAPI() {

return new OpenAPI()

.info(new Info()

.title(buildProperties.getName())

.version(buildProperties.getVersion())

.description("Maven Spring Boot Project of MOSIP Pre-Registration Service"));
return new OpenAPI().info(new Info().title(buildProperties.getName()).version(buildProperties.getVersion())
.description("Maven Spring Boot Project of MOSIP Pre-Registration Service"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public enum DemographicErrorCodes {
PRG_PAM_APP_021("PRG_PAM_APP_021"),

/* ErrorCode for BookedorExpired status can not be update */
PRG_PAM_APP_022("PRG_PAM_APP_022");
PRG_PAM_APP_022("PRG_PAM_APP_022"),

PRG_PAM_APP_023("PRG_PAM_APP_023"); // failed to update status to pending appointment

private DemographicErrorCodes(String code) {
this.code = code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,30 @@ public enum DemographicErrorMessages {
* PRG_PAM_APP_018
*/
UBALE_TO_READ_IDENTITY_JSON("Failed to read the identity json from the server"),

/**
* PRG_PAM_APP_020
*/
PRID_RESTCALL_FAIL("Rest call to get prid failed"),

MASTERDATA_RESTCALL_FAIL("masterdata restcall failed"),

ID_SCHEMA_FETCH_FAILED("Id schema fetch failed"),

/**
* PRG_PAM_APP_019
*/
INVALID_PAGE_INDEX_VALUE("Invalid page index value"),

/**
* PRG_PAM_APP_021
*/
DUPLICATE_KEY("Duplicate key for prid"),

SERVER_ERROR("Error while calling config server"),


FAILED_TO_UPDATE_STATUS_PENDING_APPOINTMENT("Failed to update status to pending appointment"),

NOT_POSSIBLE_TO_UPDATE("Application can not be updated!!");

private DemographicErrorMessages(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import io.mosip.kernel.core.dataaccess.exception.DataAccessLayerException;
import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.preregistration.core.common.entity.DemographicEntity;
import io.mosip.preregistration.core.common.entity.DocumentEntity;
import io.mosip.preregistration.core.config.LoggerConfiguration;
import io.mosip.preregistration.core.exception.TableNotAccessibleException;
Expand Down Expand Up @@ -116,7 +117,7 @@ public DocumentEntity saveDocument(DocumentEntity entity) {
DocumentErrorMessages.DOCUMENT_TABLE_NOTACCESSIBLE.getMessage(), ex.getCause());
}
}

public DocumentEntity updateDocument(DocumentEntity entity) {
try {
return documentRepository.update(entity);
Expand All @@ -127,4 +128,14 @@ public DocumentEntity updateDocument(DocumentEntity entity) {
}
}

public DemographicEntity getDemographicEntityForPrid(String prid) {
try {
return documentRepository.getDemographicEntityForPreRegistrationId(prid);
} catch (DataAccessLayerException ex) {
log.error("sessionId", "idType", "id", "In getDemographicEntityForPrid method of DocumnetDAO - " + ex);
throw new TableNotAccessibleException(DocumentErrorCodes.PRG_PAM_DOC_012.toString(),
DocumentErrorMessages.DOCUMENT_TABLE_NOTACCESSIBLE.getMessage(), ex.getCause());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

/**
Expand All @@ -29,47 +31,43 @@
@Transactional(rollbackOn = { Exception.class })
public interface DocumentRepository extends BaseRepository<DocumentEntity, String> {
/**
* @param preregId
* pass preRegistrationId
* @param preregId pass preRegistrationId
* @return true or false for a preRegistrationId
*/
public boolean existsByDemographicEntityPreRegistrationId(String preregId);

/**
* @param preId
* pass preRegistrationId
* @param preId pass preRegistrationId
* @return all the documents for a preRegistrationId
*/
public List<DocumentEntity> findByDemographicEntityPreRegistrationId(String preId);

/**
* @param documentId
* pass documentId
* @param documentId pass documentId
* @return the document for a document Id
*/
public DocumentEntity findBydocumentId(String documentId);

/**
* @param preId
* pass preRegistrationId
* @param catCode
* pass category code
* @param preId pass preRegistrationId
* @param catCode pass category code
* @return the document for a preId and Document category
*/
public DocumentEntity findSingleDocument(@Param("preId") String preId, @Param("catCode") String catCode);

/**
* @param documentId
* pass documentId
* @param documentId pass documentId
* @return the number of records deleted for a document Id
*/
public int deleteAllBydocumentId(String documentId);

/**
* @param preregId
* pass preRegistrationId
* @param preregId pass preRegistrationId
* @return the number of records deleted for a preRegistrationId
*/
public int deleteAllByDemographicEntityPreRegistrationId(String preregId);

@Query("SELECT d.demographicEntity FROM DocumentEntity d WHERE d.demographicEntity.preRegistrationId= ?1")
public DemographicEntity getDemographicEntityForPreRegistrationId(String preregId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;

Expand All @@ -39,6 +41,8 @@
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.DeletePreRegistartionDTO;
import io.mosip.preregistration.application.dto.DemographicCreateResponseDTO;
import io.mosip.preregistration.application.dto.DemographicMetadataDTO;
Expand All @@ -57,7 +61,6 @@
import io.mosip.preregistration.application.exception.util.DemographicExceptionCatcher;
import io.mosip.preregistration.application.repository.DemographicRepository;
import io.mosip.preregistration.application.service.util.DemographicServiceUtil;
//import io.mosip.preregistration.booking.service.BookingServiceIntf;
import io.mosip.preregistration.core.code.AuditLogVariables;
import io.mosip.preregistration.core.code.EventId;
import io.mosip.preregistration.core.code.EventName;
Expand Down Expand Up @@ -837,12 +840,31 @@ public MainResponseDTO<String> updatePreRegistrationStatus(String preRegId, Stri
* @param demographicEntity pass demographicEntity
* @param status pass status
*/

public void statusCheck(DemographicEntity demographicEntity, String status, String userId) {
if (demographicEntity != null) {
if (serviceUtil.isStatusValid(status)) {
demographicEntity.setStatusCode(StatusCodes.valueOf(status.toUpperCase()).getCode());
demographicRepository.update(demographicEntity);
serviceUtil.updateApplicationStatus(demographicEntity.getPreRegistrationId(), status, userId);
if (status.toLowerCase().equals(StatusCodes.PENDING_APPOINTMENT.getCode().toLowerCase())) {
if (isupdateStausToPendingAppointmentValid(demographicEntity)) {
String prid = demographicEntity.getPreRegistrationId();
serviceUtil.updateApplicationStatus(prid, status, userId);
log.info("Application booking status updated succesfully --> {}", status);
demographicRepository.update(demographicEntity);
log.info("demographic booking status updated succesfully --> {}", status);

} else {
throw new RecordFailedToUpdateException(DemographicErrorCodes.PRG_PAM_APP_023.getCode(),
DemographicErrorMessages.FAILED_TO_UPDATE_STATUS_PENDING_APPOINTMENT.getMessage());
}
} else {
String prid = demographicEntity.getPreRegistrationId();
serviceUtil.updateApplicationStatus(prid, status, userId);
log.info("Application booking status updated succesfully --> {}", status);
demographicRepository.update(demographicEntity);
log.info("demographic booking status updated succesfully --> {}", status);

}
} else {
throw new RecordFailedToUpdateException(DemographicErrorCodes.PRG_PAM_APP_005.getCode(),
DemographicErrorMessages.INVALID_STATUS_CODE.getMessage());
Expand All @@ -853,6 +875,65 @@ public void statusCheck(DemographicEntity demographicEntity, String status, Stri
}
}

public boolean isupdateStausToPendingAppointmentValid(DemographicEntity demographicEntity) {
boolean isValid = false;
try {
List<String> validMandatoryDocForApplicant = validMandatoryDocumentsForApplicant(demographicEntity);

log.info("valid mandatory Docs category for applicant-->{}", validMandatoryDocForApplicant);
List<String> uploadedDocs = demographicEntity.getDocumentEntity().stream().map(doc -> doc.getDocCatCode())
.collect(Collectors.toList());
log.info("uploaded Docs category --> {}", uploadedDocs);

isValid = compareUploadedDocListAndValidMandatoryDocList(uploadedDocs, validMandatoryDocForApplicant);

} catch (Exception ex) {

log.error("Exception Docs category -->", ex);
throw new DemographicServiceException(((DemographicServiceException) ex).getErrorCode(),
((DemographicServiceException) ex).getErrorText());

}
return isValid;

}

public List<String> validMandatoryDocumentsForApplicant(DemographicEntity demographicEntity) throws ParseException {

String applicantTypeCode = null;
ApplicantValidDocumentDto applicantValidDocuments = null;

ApplicantTypeRequestDTO applicantTypeRequest = serviceUtil.createApplicantTypeRequest(demographicEntity);

applicantTypeCode = serviceUtil.getApplicantypeCode(applicantTypeRequest);

applicantValidDocuments = serviceUtil.getDocCatAndTypeForApplicantCode(applicantTypeCode,
demographicEntity.getLangCode());
Set<String> mandatoryDocCat = serviceUtil.getMandatoryDocCatogery();

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

return validMandatoryDocumentForApplicant;
}

private boolean compareUploadedDocListAndValidMandatoryDocList(List<String> uploadedDocs,
List<String> validMandatoryDocForApplicant) {
if (validMandatoryDocForApplicant.size() == 0) {
return true;
} else {
uploadedDocs.forEach(docCat -> validMandatoryDocForApplicant.remove(docCat));
if (validMandatoryDocForApplicant.size() > 0) {
return false;
} else {
return true;
}
}

}

/**
* This private Method is used to call rest service to delete document by preId
*
Expand Down
Loading

0 comments on commit 3c0e666

Please sign in to comment.