Skip to content

Commit

Permalink
MOSIP-37899: API Review Comments (#1045)
Browse files Browse the repository at this point in the history
* MOSIP:37899 - APi review comment changes

Signed-off-by: sudeep <[email protected]>

* MOSIP:37899 - APi review comment changes

Signed-off-by: sudeep <[email protected]>

* MOSIP:37899 - APi review comment changes

Signed-off-by: sudeep <[email protected]>

* MOSIP:37899 - APi review comment changes

Signed-off-by: sudeep <[email protected]>

* MOSIP:37899 - APi review comment changes

Signed-off-by: sudeep <[email protected]>

* MOSIP:37899 - APi review comment changes

Signed-off-by: sudeep <[email protected]>

* MOSIP:37899 - APi review comment changes

Signed-off-by: sudeep <[email protected]>

* MOSIP:37899 - APi review comment changes

Signed-off-by: sudeep <[email protected]>

* MOSIP:37899 - APi review comment changes

Signed-off-by: sudeep <[email protected]>

* MOSIP:37899 - APi review comment changes

Signed-off-by: sudeep <[email protected]>

---------

Signed-off-by: sudeep <[email protected]>
  • Loading branch information
Sudeep7353 authored Dec 19, 2024
1 parent 5558383 commit 1bc24c7
Show file tree
Hide file tree
Showing 48 changed files with 1,421 additions and 1,733 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ public interface DeviceDetailService {
public ResponseWrapperV2<DeviceDetailResponseDto> deactivateDevice(String deviceDetailId);

ResponseWrapperV2<PageResponseV2Dto<DeviceDetailSummaryDto>> getAllDeviceDetails(String sortFieldName, String sortType, int pageNo, int pageSize, DeviceDetailFilterDto filterDto);

public ResponseWrapperV2<Boolean> approveOrRejectMappingDeviceToSbi(String deviceId, SbiAndDeviceMappingRequestDto requestDto);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.mosip.pms.device.authdevice.service;

import java.io.IOException;
import java.util.List;

import io.mosip.pms.common.dto.PageResponseV2Dto;
import io.mosip.pms.common.response.dto.ResponseWrapperV2;
import io.mosip.pms.device.dto.FtmChipDetailsDto;
import io.mosip.pms.device.dto.FtmChipFilterDto;
import io.mosip.pms.device.response.dto.*;
import io.mosip.pms.partner.response.dto.FtmCertificateDownloadResponseDto;
Expand Down Expand Up @@ -88,8 +90,10 @@ public interface FtpChipDetailService {

public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(String ftmId);

public ResponseWrapperV2<FtmCertificateDownloadResponseDto> getOriginalFtmCertificate(String ftmId);
public ResponseWrapperV2<FtmCertificateDownloadResponseDto> getFtmCertificateData(String ftmId);

public ResponseWrapperV2<PageResponseV2Dto<FtmDetailSummaryDto>> getPartnersFtmChipDetails(String sortFieldName, String sortType, int pageNo, int pageSize, FtmChipFilterDto filterDto);

public ResponseWrapperV2<List<FtmChipDetailsDto>> ftmChipDetail();

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.mosip.pms.device.response.dto.SbiSummaryDto;
import io.mosip.pms.device.dto.SbiFilterDto;

import io.mosip.pms.device.dto.SbiDetailsDto;
import org.springframework.stereotype.Service;

import io.mosip.pms.common.dto.FilterValueDto;
Expand Down Expand Up @@ -42,6 +43,8 @@ public interface SecureBiometricInterfaceService {

public FilterResponseCodeDto filterValues(FilterValueDto filterValueDto);

public ResponseWrapperV2<List<SbiDetailsDto>> getSbiDetails();

public ResponseWrapperV2<List<DeviceDetailDto>> getAllDevicesForSbi(String sbiId);

public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(String id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Map;
import java.util.Set;

import io.mosip.kernel.core.authmanager.authadapter.model.AuthUserDetails;
import io.mosip.kernel.core.logger.spi.Logger;
Expand Down Expand Up @@ -87,12 +88,15 @@ public class DeviceDetailServiceImpl implements DeviceDetailService {
@Value("${mosip.pms.api.id.add.inactive.mapping.device.to.sbi.id.post}")
private String postInactiveMappingDeviceToSbiId;

@Value("${mosip.pms.api.id.deactivate.device.post}")
private String postDeactivateDevice;
@Value("${mosip.pms.api.id.deactivate.device.patch}")
private String patchDeactivateDevice;

@Value("${mosip.pms.api.id.get.all.device.details.get}")
private String getAllDeviceDetailsId;

@Value("${mosip.pms.api.id.mapping.device.to.sbi.post:mosip.pms.mapping.device.to.sbi.post}")
private String postMappingDeviceToSbiId;

@Autowired
DeviceDetailSbiRepository deviceDetailSbiRepository;

Expand Down Expand Up @@ -585,7 +589,72 @@ public ResponseWrapperV2<DeviceDetailResponseDto> deactivateDevice(String device
String errorMessage = ErrorCode.DEACTIVATE_DEVICE_ERROR.getErrorMessage();
responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage));
}
responseWrapper.setId(postDeactivateDevice);
responseWrapper.setId(patchDeactivateDevice);
responseWrapper.setVersion(VERSION);
return responseWrapper;
}

@Override
public ResponseWrapperV2<Boolean> approveOrRejectMappingDeviceToSbi(String deviceId, SbiAndDeviceMappingRequestDto requestDto) {
ResponseWrapperV2<Boolean> responseWrapper = new ResponseWrapperV2<>();
try {
String partnerId = requestDto.getPartnerId();
String sbiId = requestDto.getSbiId();
String status = requestDto.getStatus();
if (Objects.isNull(partnerId) || Objects.isNull(deviceId) || Objects.isNull(status)) {
LOGGER.info("sessionId", "idType", "id", "Partner/Device id does not exist.");
throw new PartnerServiceException(ErrorCode.INVALID_REQUEST_PARAM.getErrorCode(),
ErrorCode.INVALID_REQUEST_PARAM.getErrorMessage());
}
if (!Set.of(DeviceConstant.APPROVE, DeviceConstant.REJECT).contains(status)) {
throw new PartnerServiceException(ErrorCode.NO_SBI_FOUND_FOR_APPROVE.getErrorCode(),
ErrorCode.NO_SBI_FOUND_FOR_APPROVE.getErrorMessage());
}
if (Objects.isNull(sbiId)) {
LOGGER.info("sessionId", "idType", "id", "SBI id is null.");
if (status.equals(DeviceConstant.APPROVE)) {
throw new PartnerServiceException(ErrorCode.NO_SBI_FOUND_FOR_APPROVE.getErrorCode(),
ErrorCode.NO_SBI_FOUND_FOR_APPROVE.getErrorMessage());
} else {
throw new PartnerServiceException(ErrorCode.NO_SBI_FOUND_FOR_REJECT.getErrorCode(),
ErrorCode.NO_SBI_FOUND_FOR_REJECT.getErrorMessage());
}
}
// validate sbi and device mapping
partnerHelper.validateSbiDeviceMapping(partnerId, sbiId, deviceId);

DeviceDetailSBI deviceDetailSBI = deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(partnerId, sbiId, deviceId);
if (Objects.isNull(deviceDetailSBI)) {
LOGGER.info("sessionId", "idType", "id", "SBI and Device mapping already exists in DB.");
throw new PartnerServiceException(ErrorCode.SBI_DEVICE_MAPPING_NOT_EXISTS.getErrorCode(),
ErrorCode.SBI_DEVICE_MAPPING_NOT_EXISTS.getErrorMessage());
}

UpdateDeviceDetailStatusDto deviceDetails = new UpdateDeviceDetailStatusDto();
deviceDetails.setId(deviceId);
if (status.equals(DeviceConstant.REJECT)) {
deviceDetails.setApprovalStatus(DeviceConstant.REJECT);
} else {
deviceDetails.setApprovalStatus(DeviceConstant.APPROVE);
}
updateDeviceDetailStatus(deviceDetails);

deviceDetailSBI.setIsActive(true);
deviceDetailSbiRepository.save(deviceDetailSBI);
LOGGER.info("sessionId", "idType", "id", "updated device mapping to sbi successfully in Db.");
responseWrapper.setResponse(true);
} catch (PartnerServiceException ex) {
LOGGER.info("sessionId", "idType", "id", "In approveOrRejectMappingDeviceToSbi method of DeviceDetailServiceImpl - " + ex.getMessage());
responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText()));
} catch (Exception ex) {
LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace());
LOGGER.error("sessionId", "idType", "id",
"In approveOrRejectMappingDeviceToSbi method of DeviceDetailServiceImplN - " + ex.getMessage());
String errorCode = ErrorCode.APPROVE_OR_REJECT_DEVICE_WITH_SBI_MAPPING_ERROR.getErrorCode();
String errorMessage = ErrorCode.APPROVE_OR_REJECT_DEVICE_WITH_SBI_MAPPING_ERROR.getErrorMessage();
responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage));
}
responseWrapper.setId(postMappingDeviceToSbiId);
responseWrapper.setVersion(VERSION);
return responseWrapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;

import io.mosip.kernel.core.authmanager.authadapter.model.AuthUserDetails;
import io.mosip.pms.common.dto.PageResponseV2Dto;
import io.mosip.pms.common.response.dto.ResponseWrapperV2;
import io.mosip.pms.device.authdevice.entity.FtmDetailSummaryEntity;
import io.mosip.pms.device.authdevice.repository.FtmDetailsSummaryRepository;
import io.mosip.pms.device.dto.FtmChipDetailsDto;
import io.mosip.pms.device.dto.FtmChipFilterDto;
import io.mosip.pms.device.response.dto.*;
import io.mosip.pms.partner.constant.PartnerConstants;
Expand Down Expand Up @@ -138,15 +141,18 @@ public class FTPChipDetailServiceImpl implements FtpChipDetailService {
@Value("${pms.certs.datashare.policyId}")
private String policyId;

@Value("${mosip.pms.api.id.deactivate.ftm.post}")
private String postDeactivateFtm;
@Value("${mosip.pms.api.id.deactivate.ftm.patch}")
private String patchDeactivateFtm;

@Value("${mosip.pms.api.id.original.ftm.certificate.get}")
private String getOriginalFtmCertificateId;

@Value("${mosip.pms.api.id.partners.ftm.chip.details.get}")
private String getPartnersFtmChipDetailsId;


@Value("${mosip.pms.api.id.ftm.chip.details.get}")
private String getFtmChipDetailsId;

@Autowired
private WebSubPublisher webSubPublisher;

Expand Down Expand Up @@ -595,13 +601,13 @@ public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(String ftmId) {
String errorMessage = ErrorCode.DEACTIVATE_FTM_ERROR.getErrorMessage();
responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage));
}
responseWrapper.setId(postDeactivateFtm);
responseWrapper.setId(patchDeactivateFtm);
responseWrapper.setVersion(VERSION);
return responseWrapper;
}

@Override
public ResponseWrapperV2<FtmCertificateDownloadResponseDto> getOriginalFtmCertificate(String ftmId) {
public ResponseWrapperV2<FtmCertificateDownloadResponseDto> getFtmCertificateData(String ftmId) {
ResponseWrapperV2<FtmCertificateDownloadResponseDto> responseWrapper = new ResponseWrapperV2<>();
try {
String userId = getUserId();
Expand Down Expand Up @@ -715,6 +721,73 @@ private Page<FtmDetailSummaryEntity> getFtmChipDetails(String sortFieldName, Str
filterDto.getMake(), filterDto.getModel(), filterDto.getStatus(), pageable);
}

@Override
public ResponseWrapperV2<List<FtmChipDetailsDto>> ftmChipDetail() {
ResponseWrapperV2<List<FtmChipDetailsDto>> responseWrapper = new ResponseWrapperV2<>();
try {
String userId = getUserId();
List<Partner> partnerList = partnerRepository.findByUserId(userId);
List<FtmChipDetailsDto> ftmChipDetailsDtoList = new ArrayList<>();
if (!partnerList.isEmpty()) {
for (Partner partner : partnerList) {
if (partnerHelper.checkIfPartnerIsFtmPartner(partner)) {
partnerHelper.validatePartnerId(partner, userId);
List<FTPChipDetail> ftpChipDetailList = ftpChipDetailRepository.findByProviderId(partner.getId());
if(!ftpChipDetailList.isEmpty()) {
for(FTPChipDetail ftpChipDetail: ftpChipDetailList) {
FtmChipDetailsDto ftmChipDetailsDto = new FtmChipDetailsDto();
// Get certificate data if available
if (ftpChipDetail.getCertificateAlias() != null) {
ftmChipDetailsDto.setIsCertificateAvailable(true);
FtpChipCertDownloadRequestDto requestDto = new FtpChipCertDownloadRequestDto();
requestDto.setFtpChipDetailId(ftpChipDetail.getFtpChipDetailId());
FtpCertDownloadResponeDto ftpCertDownloadResponeDto = getCertificate(requestDto);
X509Certificate cert = MultiPartnerUtil.decodeCertificateData(ftpCertDownloadResponeDto.getCertificateData());

ftmChipDetailsDto.setCertificateUploadDateTime(cert.getNotBefore());
ftmChipDetailsDto.setCertificateExpiryDateTime(cert.getNotAfter());

// Check the certificate expiration status
LocalDateTime currentDateTime = LocalDateTime.now(ZoneId.of("UTC"));
LocalDateTime certExpiryDate = cert.getNotAfter().toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime();
ftmChipDetailsDto.setIsCertificateExpired(certExpiryDate.isBefore(currentDateTime));
} else {
ftmChipDetailsDto.setIsCertificateAvailable(false);
ftmChipDetailsDto.setIsCertificateExpired(false);
}
ftmChipDetailsDto.setFtmId(ftpChipDetail.getFtpChipDetailId());
ftmChipDetailsDto.setPartnerId(ftpChipDetail.getFtpProviderId());
ftmChipDetailsDto.setMake(ftpChipDetail.getMake());
ftmChipDetailsDto.setModel(ftpChipDetail.getModel());
ftmChipDetailsDto.setStatus(ftpChipDetail.getApprovalStatus());
ftmChipDetailsDto.setIsActive(ftpChipDetail.isActive());
ftmChipDetailsDto.setCreatedDateTime(ftpChipDetail.getCrDtimes());
ftmChipDetailsDtoList.add(ftmChipDetailsDto);
}
}
}
}
}
responseWrapper.setResponse(ftmChipDetailsDtoList);
} catch (ApiAccessibleException ex) {
LOGGER.info("sessionId", "idType", "id", "In ftmChipDetails method of FTPChipDetailServiceImpl - " + ex.getMessage());
responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText()));
} catch (PartnerServiceException ex) {
LOGGER.info("sessionId", "idType", "id", "In ftmChipDetail method of FTPChipDetailServiceImpl - " + ex.getMessage());
responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText()));
} catch (Exception ex) {
LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace());
LOGGER.error("sessionId", "idType", "id",
"In ftmChipDetail method of FTPChipDetailServiceImpl - " + ex.getMessage());
String errorCode = ErrorCode.FTM_CHIP_DETAILS_LIST_FETCH_ERROR.getErrorCode();
String errorMessage = ErrorCode.FTM_CHIP_DETAILS_LIST_FETCH_ERROR.getErrorMessage();
responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage));
}
responseWrapper.setId(getFtmChipDetailsId);
responseWrapper.setVersion(VERSION);
return responseWrapper;
}

public String getSortColumn(Map<String, String> aliasToColumnMap, String alias) {
return aliasToColumnMap.getOrDefault(alias, alias); // Return alias if no match found
}
Expand Down
Loading

0 comments on commit 1bc24c7

Please sign in to comment.