Skip to content

Commit

Permalink
MOSIP-37875: Created v2 endpoint for ftpChipDetails (#1006)
Browse files Browse the repository at this point in the history
* MOSIP-37875: Created v2 endpoint for ftpChipDetails

Signed-off-by: Swetha K <[email protected]>

* MOSIP-37875: Created v2 endpoint for ftpChipDetails

Signed-off-by: Swetha K <[email protected]>

* MOSIP-37875: Created v2 endpoint for ftpChipDetails

Signed-off-by: Swetha K <[email protected]>

* MOSIP-37875: Created v2 endpoint for ftpChipDetails

Signed-off-by: Swetha K <[email protected]>

---------

Signed-off-by: Swetha K <[email protected]>
Co-authored-by: Swetha K <[email protected]>
  • Loading branch information
SwethaKrish4 and Swetha K authored Nov 29, 2024
1 parent 02f846d commit caf40db
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.mosip.pms.device.authdevice.entity;

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

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity
@Getter
@Setter
@ToString
@SqlResultSetMapping(
name = "Mapping.FtmDetailSummaryEntity",
classes = { @ConstructorResult(
targetClass = FtmDetailSummaryEntity.class,
columns = {
@ColumnResult(name = "ftmId", type = String.class),
@ColumnResult(name = "partnerId", type = String.class),
@ColumnResult(name = "orgName", type = String.class),
@ColumnResult(name = "make", type = String.class),
@ColumnResult(name = "model", type = String.class),
@ColumnResult(name = "status", type = String.class),
@ColumnResult(name = "isActive", type = Boolean.class),
@ColumnResult(name = "isCertificateAvailable", type = Boolean.class),
@ColumnResult(name = "createdDateTime", type = LocalDateTime.class)
})
}
)
public class FtmDetailSummaryEntity {

public FtmDetailSummaryEntity(String ftmId, String partnerId, String orgName, String make, String model,
String status, Boolean isActive, Boolean isCertificateAvailable,
LocalDateTime createdDateTime) {
this.ftmId = ftmId;
this.partnerId = partnerId;
this.orgName = orgName;
this.make = make;
this.model = model;
this.status = status;
this.isActive = isActive;
this.isCertificateAvailable = isCertificateAvailable;
this.createdDateTime = createdDateTime;
}

// No-argument constructor
public FtmDetailSummaryEntity() {
super();
}

@Id
private String ftmId;

private String partnerId;

private String orgName;

private String make;

private String model;

private String status;

private Boolean isActive;

private Boolean isCertificateAvailable;

private LocalDateTime createdDateTime;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.mosip.pms.device.authdevice.repository;

import io.mosip.kernel.core.dataaccess.spi.repository.BaseRepository;
import io.mosip.pms.device.authdevice.entity.FtmDetailSummaryEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository("FtmDetailsSummaryRepository")
public interface FtmDetailsSummaryRepository extends BaseRepository<FtmDetailSummaryEntity, String> {

@Query(value = "SELECT new FtmDetailSummaryEntity(" +
"f.ftpChipDetailId, f.ftpProviderId, f.partnerOrganizationName, f.make, f.model, " +
"CASE " +
"WHEN f.approvalStatus = 'approved' AND f.isActive = true THEN 'approved' " +
"WHEN f.approvalStatus = 'approved' AND f.isActive = false THEN 'deactivated' " +
"WHEN f.approvalStatus = 'rejected' THEN 'rejected' " +
"WHEN f.approvalStatus = 'pending_approval' THEN 'pending_approval' " +
"WHEN f.approvalStatus = 'pending_cert_upload' THEN 'pending_cert_upload' " +
"END AS approvalStatus, " +
"f.isActive, CASE WHEN f.certificateAlias IS NULL THEN false ELSE true END, f.crDtimes) " +
"FROM FTPChipDetail f " +
"WHERE (:partnerId IS NULL OR lower(f.ftpProviderId) LIKE %:partnerId%) " +
"AND (:orgName IS NULL OR lower(f.partnerOrganizationName) LIKE %:orgName%) " +
"AND (:make IS NULL OR lower(f.make) LIKE %:make%) " +
"AND (:model IS NULL OR lower(f.model) LIKE %:model%) " +
"AND (:status IS NULL OR " +
"(:status = 'deactivated' AND f.approvalStatus = 'approved' AND f.isActive = false) " +
"OR (:status = 'approved' AND f.approvalStatus = 'approved' AND f.isActive = true) " +
"OR (:status = 'rejected' AND f.approvalStatus = 'rejected') " +
"OR (:status = 'pending_approval' AND f.approvalStatus = 'pending_approval') " +
"OR (:status = 'pending_cert_upload' AND f.approvalStatus = 'pending_cert_upload'))"
)
Page<FtmDetailSummaryEntity> getSummaryOfPartnersFtmDetails(
@Param("partnerId") String partnerId,
@Param("orgName") String orgName,
@Param("make") String make,
@Param("model") String model,
@Param("status") String status,
Pageable pageable
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.io.IOException;

import io.mosip.pms.common.dto.PageResponseV2Dto;
import io.mosip.pms.common.response.dto.ResponseWrapperV2;
import io.mosip.pms.device.dto.FtmChipFilterDto;
import io.mosip.pms.device.response.dto.*;
import io.mosip.pms.partner.response.dto.OriginalCertDownloadResponseDto;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -88,4 +90,6 @@ public interface FtpChipDetailService {

public ResponseWrapperV2<OriginalCertDownloadResponseDto> getOriginalFtmCertificate(String ftmId);

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
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.FtmChipFilterDto;
import io.mosip.pms.device.response.dto.*;
import io.mosip.pms.partner.constant.PartnerConstants;
import io.mosip.pms.partner.response.dto.OriginalCertDownloadResponseDto;
import io.mosip.pms.partner.util.MultiPartnerUtil;
import io.mosip.pms.partner.util.PartnerHelper;
Expand All @@ -20,6 +25,9 @@
import org.springframework.core.env.Environment;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
Expand Down Expand Up @@ -101,6 +109,9 @@ public class FTPChipDetailServiceImpl implements FtpChipDetailService {

@Autowired
PartnerServiceRepository partnerRepository;

@Autowired
FtmDetailsSummaryRepository ftmDetailsSummaryRepository;

@Autowired
private ObjectMapper mapper;
Expand Down Expand Up @@ -132,6 +143,9 @@ public class FTPChipDetailServiceImpl implements FtpChipDetailService {

@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;

@Autowired
private WebSubPublisher webSubPublisher;
Expand Down Expand Up @@ -631,6 +645,49 @@ public ResponseWrapperV2<OriginalCertDownloadResponseDto> getOriginalFtmCertific
return responseWrapper;
}

@Override
public ResponseWrapperV2<PageResponseV2Dto<FtmDetailSummaryDto>> getPartnersFtmChipDetails(String sortFieldName, String sortType, int pageNo, int pageSize, FtmChipFilterDto filterDto) {
ResponseWrapperV2<PageResponseV2Dto<FtmDetailSummaryDto>> responseWrapper = new ResponseWrapperV2<>();
try {
PageResponseV2Dto pageResponseV2Dto = new PageResponseV2Dto();
// Pagination
Pageable pageable = PageRequest.of(pageNo, pageSize);

//Sorting
if (Objects.nonNull(sortFieldName) && Objects.nonNull(sortType)) {
Sort sort = partnerHelper.getSortingRequest(getSortColumn(partnerHelper.ftmAliasToColumnMap, sortFieldName), sortType);
pageable = PageRequest.of(pageNo, pageSize, sort);
}
Page<FtmDetailSummaryEntity> page = ftmDetailsSummaryRepository.getSummaryOfPartnersFtmDetails(filterDto.getPartnerId(), filterDto.getOrgName(),
filterDto.getMake(), filterDto.getModel(), filterDto.getStatus(), pageable);
if (Objects.nonNull(page) && !page.getContent().isEmpty()) {
List<FtmDetailSummaryDto> ftmDetailSummaryDtoList = MapperUtils.mapAll(page.getContent(), FtmDetailSummaryDto.class);
pageResponseV2Dto.setPageNo(pageNo);
pageResponseV2Dto.setPageSize(pageSize);
pageResponseV2Dto.setTotalResults(page.getTotalElements());
pageResponseV2Dto.setData(ftmDetailSummaryDtoList);
}
responseWrapper.setResponse(pageResponseV2Dto);
} catch (PartnerServiceException ex) {
LOGGER.info("sessionId", "idType", "id", "In getPartnersFtmChipDetails 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 getPartnersFtmChipDetails 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(getPartnersFtmChipDetailsId);
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
}

public static void validateFtmId(String ftmId) {
if (Objects.isNull(ftmId) || ftmId.equals(BLANK_STRING)) {
LOGGER.info("sessionId", "idType", "id", "FTM id is null or empty.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
import javax.validation.Valid;
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.FtmChipFilterDto;
import io.mosip.pms.device.request.dto.*;
import io.mosip.pms.device.response.dto.*;
import io.mosip.pms.partner.response.dto.OriginalCertDownloadResponseDto;
import io.mosip.pms.partner.util.PartnerHelper;
import io.mosip.pms.partner.util.RequestValidator;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -27,6 +32,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -57,6 +64,9 @@ public class FTPChipDetailController {
@Autowired
FtpChipDetailService ftpChipDetaillService;

@Autowired
PartnerHelper partnerHelper;

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

Expand Down Expand Up @@ -264,4 +274,48 @@ public ResponseWrapperV2<OriginalCertDownloadResponseDto> getOriginalFtmCertific
@ApiParam("To download original FTM certificate.") @PathVariable("ftmId") @NotNull String ftmId) throws JsonParseException, JsonMappingException, JsonProcessingException, IOException, CertificateException {
return ftpChipDetaillService.getOriginalFtmCertificate(ftmId);
}

@PreAuthorize("hasAnyRole(@authorizedRoles.getGetpartnersftmchipdetails())")
@GetMapping(value = "search/v2")
@Operation(summary = "Get all partners FTM chip details", description = "This endpoint will fetch a list of all the partners FTM chip details")
@io.swagger.v3.oas.annotations.responses.ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "OK"),
@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)))
})
ResponseWrapperV2<PageResponseV2Dto<FtmDetailSummaryDto>> getPartnersFtmChipDetails(
@RequestParam(value = "sortFieldName", required = false) String sortFieldName,
@RequestParam(value = "sortType", required = false) String sortType,
@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize", defaultValue = "8") int pageSize,
@RequestParam(value = "partnerId", required = false) String partnerId,
@RequestParam(value = "orgName", required = false) String orgName,
@RequestParam(value = "make", required = false) String make,
@RequestParam(value = "model", required = false) String model,
@Parameter(
description = "Status of certificate upload",
in = ParameterIn.QUERY,
schema = @Schema(allowableValues = {"approved", "rejected", "pending_cert_upload", "pending_approval", "deactivated"})
)
@RequestParam(value = "status", required = false) String status
) {
partnerHelper.validateRequestParameters(partnerHelper.ftmAliasToColumnMap, sortFieldName, sortType, pageNo, pageSize);
FtmChipFilterDto filterDto = new FtmChipFilterDto();
if (partnerId != null) {
filterDto.setPartnerId(partnerId.toLowerCase());
}
if (orgName != null) {
filterDto.setOrgName(orgName.toLowerCase());
}
if (make != null) {
filterDto.setMake(make.toLowerCase());
}
if (model != null) {
filterDto.setModel(model.toLowerCase());
}
if (status != null) {
filterDto.setStatus(status);
}
return ftpChipDetaillService.getPartnersFtmChipDetails(sortFieldName, sortType, pageNo, pageSize, filterDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.mosip.pms.device.dto;

import lombok.Data;

@Data
public class FtmChipFilterDto {
private String partnerId;
private String orgName;
private String make;
private String model;
private String status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.mosip.pms.device.response.dto;

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

import java.time.LocalDateTime;
import java.util.Date;

@Data
public class FtmDetailSummaryDto {

@Schema(description = "Unique identifier for the FTM Chip details added by the partner", example = "ftp-001")
private String ftmId;

@Schema(description = "Unique identifier for the partner", example = "partner123")
private String partnerId;

@Schema(description = "Name of the organisation", example = "org123")
private String orgName;

@Schema(description = "Make of the FTM chip", example = "make-123")
private String make;

@Schema(description = "Model of the FTM chip", example = "model-123")
private String model;

@Schema(description = "Current status of the FTM chip details added by the partner. Possible values are pending_cert_upload, pending_approval, rejected, approved, deactivated", example = "pending_approval")
private String status;

@Schema(description = "Indicates whether the FTM chip details is active (true if active, false otherwise)", example = "false")
private Boolean isActive;

@Schema(description = "Indicates whether the FTM Chip certificate is available (true if available, false otherwise)", example = "true")
private Boolean isCertificateAvailable;

@Schema(description = "Date and time in ISO format indicating when the FTM Chip details were added by the partner", example = "2024-08-01T14:30:00Z")
private LocalDateTime createdDateTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class AuthorizedRolesDto {

private List<String> postftpchipdetailsearch;

private List<String> getpartnersftmchipdetails;

//Secure Biometric Interface controller

private List<String> postsecurebiometricinterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public class PartnerHelper {
apiKeyAliasToColumnMap.put("createdDateTime", "createdDateTime");
}

public final Map<String, String> ftmAliasToColumnMap = new HashMap<>();
{
ftmAliasToColumnMap.put("partnerId", "ftpProviderId");
ftmAliasToColumnMap.put("orgName", "partnerOrganizationName");
ftmAliasToColumnMap.put("make", "make");
ftmAliasToColumnMap.put("model", "model");
ftmAliasToColumnMap.put("status", "approvalStatus");
ftmAliasToColumnMap.put("createdDateTime", "crDtimes");
}


@Autowired
SecureBiometricInterfaceRepository secureBiometricInterfaceRepository;
Expand Down
Loading

0 comments on commit caf40db

Please sign in to comment.