Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSIP-37899: Added request body for deactivate PATCH endpoints #1050

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.mosip.pms.device.request.dto.DeviceDetailUpdateDto;
import io.mosip.pms.device.request.dto.DeviceSearchDto;
import io.mosip.pms.device.request.dto.UpdateDeviceDetailStatusDto;
import io.mosip.pms.device.request.dto.DeactivateDeviceRequestDto;
import io.mosip.pms.device.response.dto.DeviceDetailSearchResponseDto;
import io.mosip.pms.device.response.dto.FilterResponseCodeDto;
import io.mosip.pms.device.response.dto.IdDto;
Expand Down Expand Up @@ -92,7 +93,7 @@ public interface DeviceDetailService {
*/
public FilterResponseCodeDto deviceTypeFilterValues(DeviceFilterValueDto deviceFilterValueDto);

public ResponseWrapperV2<DeviceDetailResponseDto> deactivateDevice(String deviceDetailId);
public ResponseWrapperV2<DeviceDetailResponseDto> deactivateDevice(String deviceDetailId, DeactivateDeviceRequestDto requestDto);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.mosip.pms.common.dto.PageResponseDto;
import io.mosip.pms.device.authdevice.entity.FTPChipDetail;
import io.mosip.pms.device.request.dto.DeviceSearchDto;
import io.mosip.pms.device.request.dto.DeactivateFtmRequestDto;
import io.mosip.pms.device.request.dto.FtpChipCertDownloadRequestDto;
import io.mosip.pms.device.request.dto.FtpChipCertificateRequestDto;
import io.mosip.pms.device.request.dto.FtpChipDetailDto;
Expand Down Expand Up @@ -88,7 +89,7 @@ public interface FtpChipDetailService {
*/
public <E> PageResponseDto<FTPSearchResponseDto> searchFTPChipDetails(Class<E> entity, DeviceSearchDto dto);

public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(String ftmId);
public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(String ftmId, DeactivateFtmRequestDto requestDto);

public ResponseWrapperV2<FtmCertificateDownloadResponseDto> getFtmCertificateData(String ftmId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.mosip.pms.common.dto.PageResponseDto;
import io.mosip.pms.device.request.dto.DeviceDetailSBIMappingDto;
import io.mosip.pms.device.request.dto.DeviceSearchDto;
import io.mosip.pms.device.request.dto.DeactivateSbiRequestDto;
import io.mosip.pms.device.request.dto.SecureBiometricInterfaceCreateDto;
import io.mosip.pms.device.request.dto.SecureBiometricInterfaceStatusUpdateDto;
import io.mosip.pms.device.request.dto.SecureBiometricInterfaceUpdateDto;
Expand Down Expand Up @@ -50,7 +51,7 @@ public interface SecureBiometricInterfaceService {

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

public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(String id);
public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(String id, DeactivateSbiRequestDto deactivateSbiRequestDto);

public ResponseWrapperV2<PageResponseV2Dto<SbiSummaryDto>> getAllSbiDetails(String sortFieldName, String sortType, int pageNo, int pageSize, SbiFilterDto filterDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import io.mosip.pms.device.request.dto.DeviceDetailDto;
import io.mosip.pms.device.request.dto.DeviceDetailUpdateDto;
import io.mosip.pms.device.request.dto.DeviceSearchDto;
import io.mosip.pms.device.request.dto.DeactivateDeviceRequestDto;
import io.mosip.pms.device.request.dto.UpdateDeviceDetailStatusDto;
import io.mosip.pms.device.response.dto.ColumnCodeValue;
import io.mosip.pms.device.response.dto.DeviceDetailSearchResponseDto;
Expand Down Expand Up @@ -425,9 +426,15 @@ public static void validatePartnerId(Partner partner, String userId) {
}

@Override
public ResponseWrapperV2<DeviceDetailResponseDto> deactivateDevice(String deviceDetailId) {
public ResponseWrapperV2<DeviceDetailResponseDto> deactivateDevice(String deviceDetailId, DeactivateDeviceRequestDto requestDto) {
ResponseWrapperV2<DeviceDetailResponseDto> responseWrapper = new ResponseWrapperV2<>();
try {
String status = requestDto.getStatus();
if (Objects.isNull(status) || status.equals(BLANK_STRING) || !status.equals(PartnerConstants.DEACTIVATE)) {
LOGGER.info(status + " : is Invalid Input Parameter, it should be (De-Activate)");
throw new PartnerServiceException(ErrorCode.DEACTIVATE_STATUS_CODE.getErrorCode(),
ErrorCode.DEACTIVATE_STATUS_CODE.getErrorMessage());
}
String userId = getUserId();
List<Partner> partnerList = partnerRepository.findByUserId(userId);
if (partnerList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import io.mosip.pms.device.constant.DeviceConstant;
import io.mosip.pms.device.constant.FoundationalTrustProviderErrorMessages;
import io.mosip.pms.device.request.dto.DeviceSearchDto;
import io.mosip.pms.device.request.dto.DeactivateFtmRequestDto;
import io.mosip.pms.device.request.dto.FtpCertificateRequestDto;
import io.mosip.pms.device.request.dto.FtpChipCertDownloadRequestDto;
import io.mosip.pms.device.request.dto.FtpChipCertificateRequestDto;
Expand Down Expand Up @@ -547,9 +548,15 @@ private void notify(String certData, String partnerDomain) {
}

@Override
public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(String ftmId) {
public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(String ftmId, DeactivateFtmRequestDto requestDto) {
ResponseWrapperV2<FtmDetailResponseDto> responseWrapper = new ResponseWrapperV2<>();
try {
String status = requestDto.getStatus();
if (Objects.isNull(status) || status.equals(BLANK_STRING) || !status.equals(PartnerConstants.DEACTIVATE)) {
LOGGER.info(status + " : is Invalid Input Parameter, it should be (De-Activate)");
throw new PartnerServiceException(ErrorCode.DEACTIVATE_STATUS_CODE.getErrorCode(),
ErrorCode.DEACTIVATE_STATUS_CODE.getErrorMessage());
}
String userId = getUserId();
List<Partner> partnerList = partnerRepository.findByUserId(userId);
if (partnerList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.mosip.pms.device.dto.SbiFilterDto;
import io.mosip.pms.device.util.DeviceUtil;
import io.mosip.pms.partner.constant.ErrorCode;
import io.mosip.pms.partner.constant.PartnerConstants;
import io.mosip.pms.partner.dto.DeviceDto;
import io.mosip.pms.device.dto.SbiDetailsDto;
import io.mosip.pms.partner.exception.PartnerServiceException;
Expand Down Expand Up @@ -76,6 +77,7 @@
import io.mosip.pms.device.request.dto.SecureBiometricInterfaceStatusUpdateDto;
import io.mosip.pms.device.request.dto.SecureBiometricInterfaceUpdateDto;
import io.mosip.pms.device.request.dto.DeviceDetailDto;
import io.mosip.pms.device.request.dto.DeactivateSbiRequestDto;
import io.mosip.pms.device.response.dto.ColumnCodeValue;
import io.mosip.pms.device.response.dto.FilterResponseCodeDto;
import io.mosip.pms.device.response.dto.IdDto;
Expand Down Expand Up @@ -1008,9 +1010,15 @@ private void validateDevicePartnerType(Partner partner, String userId) {
}

@Override
public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(String sbiId) {
public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(String sbiId, DeactivateSbiRequestDto requestDto) {
ResponseWrapperV2<SbiDetailsResponseDto> responseWrapper = new ResponseWrapperV2<>();
try {
String status = requestDto.getStatus();
if (Objects.isNull(status) || status.equals(BLANK_STRING) || !status.equals(PartnerConstants.DEACTIVATE)) {
LOGGER.info(status + " : is Invalid Input Parameter, it should be (De-Activate)");
throw new PartnerServiceException(ErrorCode.DEACTIVATE_STATUS_CODE.getErrorCode(),
ErrorCode.DEACTIVATE_STATUS_CODE.getErrorMessage());
}
String userId = getUserId();
List<Partner> partnerList = partnerRepository.findByUserId(userId);
if (partnerList.isEmpty()) {
Expand Down Expand Up @@ -1052,6 +1060,8 @@ public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(String sbiId) {
if (!approvedDevices.isEmpty()) {
for (DeviceDetail deviceDetail : approvedDevices) {
deviceDetail.setIsActive(false);
deviceDetail.setUpdDtimes(LocalDateTime.now());
deviceDetail.setUpdBy(getUserId());
deviceDetailRepository.save(deviceDetail);
}
}
Expand All @@ -1060,6 +1070,8 @@ public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(String sbiId) {
if (!pendingApprovalDevices.isEmpty()) {
for (DeviceDetail deviceDetail : pendingApprovalDevices) {
deviceDetail.setApprovalStatus(REJECTED);
deviceDetail.setUpdDtimes(LocalDateTime.now());
deviceDetail.setUpdBy(getUserId());
deviceDetailRepository.save(deviceDetail);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.mosip.pms.device.request.dto.DeviceDetailDto;
import io.mosip.pms.device.request.dto.DeviceDetailUpdateDto;
import io.mosip.pms.device.request.dto.DeviceSearchDto;
import io.mosip.pms.device.request.dto.DeactivateDeviceRequestDto;
import io.mosip.pms.device.request.dto.UpdateDeviceDetailStatusDto;
import io.mosip.pms.device.response.dto.DeviceDetailSearchResponseDto;
import io.mosip.pms.device.response.dto.FilterResponseCodeDto;
Expand All @@ -59,8 +60,12 @@
@RequestMapping(value = "/devicedetail")
@Api(tags = { "DeviceDetail" })
public class DeviceDetailController {

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

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

@Autowired
AuditUtil auditUtil;
Expand Down Expand Up @@ -237,8 +242,13 @@ public ResponseWrapper<FilterResponseCodeDto> filterDeviceSubType(
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))
})
public ResponseWrapperV2<DeviceDetailResponseDto> deactivateDevice(@PathVariable("deviceId") @NotBlank String deviceId) {
return deviceDetaillService.deactivateDevice(deviceId);
public ResponseWrapperV2<DeviceDetailResponseDto> deactivateDevice(@PathVariable("deviceId") @NotBlank String deviceId, @RequestBody @Valid RequestWrapperV2<DeactivateDeviceRequestDto>
requestWrapper) {
Optional<ResponseWrapperV2<DeviceDetailResponseDto>> validationResponse = requestValidator.validate(patchDeactivateDevice, requestWrapper);
if (validationResponse.isPresent()) {
return validationResponse.get();
}
return deviceDetaillService.deactivateDevice(deviceId, requestWrapper.getRequest());
}

@PreAuthorize("hasAnyRole(@authorizedRoles.getPostdevicewithsbimapping())")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import java.io.IOException;
import java.security.cert.CertificateException;
import java.util.List;
import java.util.Optional;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import io.mosip.pms.common.dto.PageResponseV2Dto;
import io.mosip.pms.common.request.dto.RequestWrapperV2;
import io.mosip.pms.common.response.dto.ResponseWrapperV2;
import io.mosip.pms.device.dto.FtmChipDetailsDto;
import io.mosip.pms.device.dto.FtmChipFilterDto;
Expand Down Expand Up @@ -71,6 +73,9 @@ public class FTPChipDetailController {
@Autowired
RequestValidator requestValidator;

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

/**
* Post API to insert a new row of ftpChipDetail data
*
Expand Down Expand Up @@ -254,8 +259,13 @@ public ResponseWrapper<PageResponseDto<FTPSearchResponseDto>> searchFtpChipDetai
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))
})
public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(@PathVariable("ftmId") @NotBlank String ftmId) {
return ftpChipDetaillService.deactivateFtm(ftmId);
public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(@PathVariable("ftmId") @NotBlank String ftmId, @RequestBody @Valid RequestWrapperV2<DeactivateFtmRequestDto>
requestWrapper) {
Optional<ResponseWrapperV2<FtmDetailResponseDto>> validationResponse = requestValidator.validate(patchDeactivateFtm, requestWrapper);
if (validationResponse.isPresent()) {
return validationResponse.get();
}
return ftpChipDetaillService.deactivateFtm(ftmId, requestWrapper.getRequest());
}

@PreAuthorize("hasAnyRole(@authorizedRoles.getGetoriginalftmcertificate())")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import io.mosip.pms.device.constant.DeviceConstant;
import io.mosip.pms.device.request.dto.DeviceDetailSBIMappingDto;
import io.mosip.pms.device.request.dto.DeviceSearchDto;
import io.mosip.pms.device.request.dto.DeactivateSbiRequestDto;
import io.mosip.pms.device.request.dto.SecureBiometricInterfaceCreateDto;
import io.mosip.pms.device.request.dto.SecureBiometricInterfaceStatusUpdateDto;
import io.mosip.pms.device.request.dto.SecureBiometricInterfaceUpdateDto;
Expand Down Expand Up @@ -67,6 +68,9 @@ public class SecureBiometricInterfaceController {
@Value("${mosip.pms.api.id.add.device.to.sbi.id.post}")
private String postAddDeviceToSbi;

@Value("${mosip.pms.api.id.deactivate.sbi.patch}")
private String patchDeactivateSbi;

@Autowired
SecureBiometricInterfaceService secureBiometricInterface;

Expand Down Expand Up @@ -263,8 +267,13 @@ public ResponseWrapperV2<List<SbiDetailsDto>> getSbiDetails() {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))
})
public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(@PathVariable("sbiId") @NotBlank String sbiId) {
return secureBiometricInterface.deactivateSbi(sbiId);
public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(@PathVariable("sbiId") @NotBlank String sbiId, @RequestBody @Valid RequestWrapperV2<DeactivateSbiRequestDto>
requestWrapper) {
Optional<ResponseWrapperV2<SbiDetailsResponseDto>> validationResponse = requestValidator.validate(patchDeactivateSbi, requestWrapper);
if (validationResponse.isPresent()) {
return validationResponse.get();
}
return secureBiometricInterface.deactivateSbi(sbiId, requestWrapper.getRequest());
}

@PreAuthorize("hasAnyRole(@authorizedRoles.getGetallsbidetails())")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.mosip.pms.device.request.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class DeactivateDeviceRequestDto {

@Schema(description = "Status for deactivate device", example = "De-Activate")
private String status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.mosip.pms.device.request.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class DeactivateFtmRequestDto {

@Schema(description = "Status for deactivate FTM", example = "De-Activate")
private String status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.mosip.pms.device.request.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class DeactivateSbiRequestDto {

@Schema(description = "Status for deactivate SBI", example = "De-Activate")
private String status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public enum ErrorCode {
DEVICE_NOT_APPROVED("PMS_DEVICE_ERROR_023", "The selected Device is not in an approved status."),
NO_SBI_FOUND_FOR_APPROVE("PMS_DEVICE_ERROR_024", "This device cannot be approved as it does not have any SBI associated to it."),
NO_SBI_FOUND_FOR_REJECT("PMS_DEVICE_ERROR_025", "This device cannot be rejected as it does not have any SBI associated to it."),
DEACTIVATE_STATUS_CODE("PMS_DEVICE_ERROR_026", "Request status should be De-Activate"),
GET_ALL_DEVICE_DETAILS_FETCH_ERROR("PMS_FTM_ERROR_024", "Error occurred while retrieving all device details"),
FTM_CHIP_DETAILS_LIST_FETCH_ERROR("PMS_FTM_ERROR_001", "Error while fetching the FTM chip details"),
DEACTIVATE_FTM_ERROR("PMS_FTM_ERROR_003", "Error while deactivating the FTM"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ public final class PartnerConstants {
public static final String DESC = "desc";

public static final String PARTNER_ADMIN = "PARTNER_ADMIN";

public static final String DEACTIVATE = "De-Activate";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.mosip.pms.device.request.dto.DeviceDetailDto;
import io.mosip.pms.device.request.dto.DeviceDetailUpdateDto;
import io.mosip.pms.device.request.dto.DeviceSearchDto;
import io.mosip.pms.device.request.dto.DeactivateDeviceRequestDto;
import io.mosip.pms.device.request.dto.UpdateDeviceDetailStatusDto;
import io.mosip.pms.device.response.dto.*;
import io.mosip.pms.device.util.AuditUtil;
Expand Down Expand Up @@ -449,16 +450,18 @@ public void filterDeviceSubTypeTest() throws JsonProcessingException, Exception
@Test
@WithMockUser(roles = {"DEVICE_PROVIDER"})
public void deactivateDeviceTest() throws Exception {
RequestWrapperV2<DeactivateDeviceRequestDto> requestWrapper = new RequestWrapperV2<>();
DeactivateDeviceRequestDto requestDto = new DeactivateDeviceRequestDto();
requestDto.setStatus("De-Activate");
requestWrapper.setRequest(requestDto);
ResponseWrapperV2<DeviceDetailResponseDto> responseWrapper = new ResponseWrapperV2<>();
DeviceDetailResponseDto deviceDetailResponseDto = new DeviceDetailResponseDto();
responseWrapper.setResponse(deviceDetailResponseDto);

Mockito.when(deviceDetaillService.deactivateDevice(Mockito.anyString())).thenReturn(responseWrapper);

mockMvc.perform(MockMvcRequestBuilders.patch("/devicedetail/12345")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk());
Mockito.when(deviceDetaillService.deactivateDevice(Mockito.anyString(), Mockito.any())).thenReturn(responseWrapper);

mockMvc.perform(MockMvcRequestBuilders.patch("/devicedetail/12345").contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,15 @@ public void getPartnerCertificateTest_02() throws JsonProcessingException, Excep
@WithMockUser(roles = {"FTM_PROVIDER"})
public void deactivateFtmTest() throws Exception {
ResponseWrapperV2<FtmDetailResponseDto> responseWrapper = new ResponseWrapperV2<>();
RequestWrapperV2<DeactivateFtmRequestDto> requestWrapper = new RequestWrapperV2<>();
DeactivateFtmRequestDto requestDto = new DeactivateFtmRequestDto();
requestDto.setStatus("De-Activate");
requestWrapper.setRequest(requestDto);
FtmDetailResponseDto ftmDetailResponseDto = new FtmDetailResponseDto();
responseWrapper.setResponse(ftmDetailResponseDto);
Mockito.when(ftpChipDetaillService.deactivateFtm(Mockito.any())).thenReturn(responseWrapper);
mockMvc.perform(MockMvcRequestBuilders.patch("/ftpchipdetail/1232")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk());
Mockito.when(ftpChipDetaillService.deactivateFtm(Mockito.any(), Mockito.any())).thenReturn(responseWrapper);
mockMvc.perform(MockMvcRequestBuilders.patch("/ftpchipdetail/1232").contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk());
}

@Test
Expand Down
Loading
Loading