Skip to content

Commit

Permalink
MOSIP-24818 Changed deprecated admin module proxy API endpoint. (#852)
Browse files Browse the repository at this point in the history
* Fixed service history issue.

* MOSIP-24818 Changed deprecated admin module proxy API endpoint.

* MOSIP-24818 Removed un-necessary commits.
  • Loading branch information
kameshsr authored Apr 11, 2023
1 parent 49348b5 commit 6c0f085
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public enum ApiName {
GET_ORDER_STATUS_URL,
TEMPLATES_BY_LANGCODE_AND_TEMPLATETYPECODE_URL,
IDREPO_IDENTITY_UPDATE_COUNT,
GENDER_TYPE_BY_LANGCODE,
DYNAMIC_FIELD_BASED_ON_LANG_CODE_AND_FIELD_NAME,
GET_RID_BY_INDIVIDUAL_ID,
PDFSIGN,
PARTNER_DETAILS_NEW_URL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,21 +376,23 @@ public ResponseWrapper<?> getAllTemplateBylangCodeAndTemplateTypeCode(@PathVaria
* @throws ResidentServiceCheckedException
*/
@ResponseFilter
@GetMapping("/auth-proxy/masterdata/gendertypes/{langcode}")
@Operation(summary = "getGenderTypesByLangCode", description = "getGenderTypesByLangCode", tags = {
@GetMapping("/auth-proxy/masterdata/dynamicfields/{fieldName}/{langCode}")
@Operation(summary = "getDynamicFieldBasedOnLangCodeAndFieldName", description = "Service to fetch dynamic field based on langcode and field name", tags = {
"proxy-masterdata-controller" })
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(hidden = true))) })
public ResponseWrapper<?> getGenderTypesByLangCode(@PathVariable("langcode") String langCode)
public ResponseWrapper<?> getDynamicFieldBasedOnLangCodeAndFieldName(@PathVariable("fieldName") String fieldName,
@PathVariable("langCode") String langCode,
@RequestParam(value = "withValue", defaultValue = "false") boolean withValue)
throws ResidentServiceCheckedException {
logger.debug("ProxyMasterdataController::getGenderTypesByLangCode()::entry");
auditUtil.setAuditRequestDto(EventEnum.GET_GENDER_TYPES);
ResponseWrapper<?> responseWrapper = proxyMasterdataService.getGenderTypesByLangCode(langCode);
logger.debug("ProxyMasterdataController::getDynamicFieldBasedOnLangCodeAndFieldName()::entry");
auditUtil.setAuditRequestDto(EventEnum.GET_DYNAMIC_FIELD_BASED_ON_LANG_CODE_AND_FIELD_NAME);
ResponseWrapper<?> responseWrapper = proxyMasterdataService.getDynamicFieldBasedOnLangCodeAndFieldName(fieldName, langCode, withValue);
auditUtil.setAuditRequestDto(EventEnum.GET_GENDER_TYPES_SUCCESS);
logger.debug("ProxyMasterdataController::getGenderTypesByLangCode()::exit");
logger.debug("ProxyMasterdataController::getDynamicFieldBasedOnLangCodeAndFieldName()::exit");
return responseWrapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ public ResponseWrapper<?> getAllTemplateBylangCodeAndTemplateTypeCode(String lan
throws ResidentServiceCheckedException;

/**
* Get gender types by language code.
*
* @param langCode
* @return ResponseWrapper object
* @throws ResidentServiceCheckedException
*/
public ResponseWrapper<?> getGenderTypesByLangCode(String langCode) throws ResidentServiceCheckedException;
* Get gender types by language code.
*
* @param fieldName
* @param langCode
* @param withValue
* @return ResponseWrapper object
* @throws ResidentServiceCheckedException
*/
public ResponseWrapper<?> getDynamicFieldBasedOnLangCodeAndFieldName(String fieldName, String langCode, boolean withValue) throws ResidentServiceCheckedException;

public ResponseWrapper<?> getDocumentTypesByDocumentCategoryAndLangCode(String documentcategorycode, String langCode) throws ResidentServiceCheckedException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

import static io.mosip.resident.constant.MappingJsonConstants.GENDER;

/**
* Resident proxy masterdata service implementation class.
*
Expand Down Expand Up @@ -438,14 +440,20 @@ public ResponseWrapper<?> getAllTemplateBylangCodeAndTemplateTypeCode(String lan
}

@Override
public ResponseWrapper<?> getGenderTypesByLangCode(String langCode) throws ResidentServiceCheckedException {
logger.debug("ProxyMasterdataServiceImpl::getGenderTypesByLangCode()::entry");
public ResponseWrapper<?> getDynamicFieldBasedOnLangCodeAndFieldName(String fieldName, String langCode, boolean withValue) throws ResidentServiceCheckedException {
logger.debug("ProxyMasterdataServiceImpl::getDynamicFieldBasedOnLangCodeAndFieldName()::entry");
ResponseWrapper<?> responseWrapper = new ResponseWrapper<>();
Map<String, String> pathsegments = new HashMap<String, String>();
pathsegments.put("langcode", langCode);
pathsegments.put("fieldName", fieldName);
List<String> queryParamName = new ArrayList<String>();
queryParamName.add("withValue");

List<Object> queryParamValue = new ArrayList<>();
queryParamValue.add(withValue);
try {
responseWrapper = residentServiceRestClient.getApi(ApiName.GENDER_TYPE_BY_LANGCODE, pathsegments,
ResponseWrapper.class);
responseWrapper = residentServiceRestClient.getApi(ApiName.DYNAMIC_FIELD_BASED_ON_LANG_CODE_AND_FIELD_NAME, pathsegments, queryParamName,
queryParamValue, ResponseWrapper.class);
if (responseWrapper.getErrors() != null && !responseWrapper.getErrors().isEmpty()) {
logger.debug(responseWrapper.getErrors().get(0).toString());
throw new ResidentServiceCheckedException(ResidentErrorCode.BAD_REQUEST.getErrorCode(),
Expand All @@ -457,7 +465,7 @@ public ResponseWrapper<?> getGenderTypesByLangCode(String langCode) throws Resid
throw new ResidentServiceCheckedException(ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorCode(),
ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorMessage(), e);
}
logger.debug("ProxyMasterdataServiceImpl::getGenderTypesByLangCode()::exit");
logger.debug("ProxyMasterdataServiceImpl::getDynamicFieldBasedOnLangCodeAndFieldName()::exit");
return responseWrapper;
}

Expand Down Expand Up @@ -491,7 +499,7 @@ public ResponseWrapper<GenderCodeResponseDTO> getGenderCodeByGenderTypeAndLangCo
logger.debug("ProxyMasterdataServiceImpl::getGenderCodeByGenderTypeAndLangCode()::entry");
ResponseWrapper<GenderCodeResponseDTO> responseWrapper = new ResponseWrapper<>();
GenderCodeResponseDTO genderCodeResponseDTO = new GenderCodeResponseDTO();
ResponseWrapper<?> res = getGenderTypesByLangCode(langCode);
ResponseWrapper<?> res = getDynamicFieldBasedOnLangCodeAndFieldName(GENDER, langCode, true);
GenderTypeListDTO response = JsonUtil.readValue(JsonUtil.writeValueAsString(res.getResponse()),
GenderTypeListDTO.class);
Optional<String> genderCode = response.getGenderType().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ public enum EventEnum {
DOWNLOAD_SERVICE_HISTORY_SUCCESS("RES-SER-266", RegistrationConstants.SYSTEM, "download service history success", "download service history success based on language code", "RES-SER",
"Resident service", "RS-DOWN_SER", "Download service history", RegistrationConstants.RESIDENT_APPLICATION_ID, RegistrationConstants.RESIDENT_APPLICATION_NAME),

GET_GENDER_TYPES("RES-SER-261", RegistrationConstants.SYSTEM, "get gender types",
"get gender types by langCode", "RES-SER", "Residence service", "RS-GEND", "Gender",
GET_DYNAMIC_FIELD_BASED_ON_LANG_CODE_AND_FIELD_NAME("RES-SER-261", RegistrationConstants.SYSTEM, "get dynamic field based on lang code and field name",
"get dynamic field based on langCode and field name", "RES-SER", "Residence service", "RS-GEND", "Dynamic Field",
RegistrationConstants.RESIDENT_APPLICATION_ID, RegistrationConstants.RESIDENT_APPLICATION_NAME),
GET_GENDER_TYPES_SUCCESS("RES-SER-262", RegistrationConstants.SYSTEM, "get gender types success",
"get gender types by langCode is succeeded", "RES-SER", "Residence service", "RS-GEND",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ public void testGetAllTemplateBylangCodeAndTemplateTypeCode() throws Exception {

@Test
public void testGetGenderTypesByLangCode() throws Exception {
Mockito.when(proxyMasterdataService.getGenderTypesByLangCode(Mockito.anyString())).thenReturn(responseWrapper);
mockMvc.perform(MockMvcRequestBuilders.get("/auth-proxy/masterdata/gendertypes/langcode"))
Mockito.when(proxyMasterdataService.getDynamicFieldBasedOnLangCodeAndFieldName(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(responseWrapper);
mockMvc.perform(MockMvcRequestBuilders.get("/auth-proxy/masterdata/dynamicfields/gender/eng?withValue=true"))
.andExpect(status().isOk());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
package io.mosip.resident.test.service;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

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

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;

import io.mosip.kernel.core.exception.ServiceError;
import io.mosip.kernel.core.http.ResponseWrapper;
import io.mosip.resident.constant.ApiName;
Expand All @@ -35,8 +15,27 @@
import io.mosip.resident.service.impl.ProxyMasterdataServiceImpl;
import io.mosip.resident.util.AuditUtil;
import io.mosip.resident.util.ResidentServiceRestClient;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;
import reactor.util.function.Tuple2;

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

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

/**
* Resident proxy masterdata service test class.
*
Expand All @@ -63,6 +62,9 @@ public class ProxyMasterdataServiceTest {

private ResponseWrapper<TemplateResponseDto> templateWrapper;

private String fieldName;
private boolean withValue;

@Before
public void setup() {
responseWrapper = new ResponseWrapper<>();
Expand All @@ -78,6 +80,8 @@ public void setup() {
templateList.add(templateDto);
templateResp.setTemplates(templateList);
templateWrapper.setResponse(templateResp);
fieldName = "gender";
withValue = true;
}

@Test
Expand Down Expand Up @@ -558,14 +562,16 @@ public void testGetAllTemplateBylangCodeAndTemplateTypeCodeWithApisResourceAcces

@Test
public void testGetGenderTypesByLangCode() throws ApisResourceAccessException, ResidentServiceCheckedException {
when(residentServiceRestClient.getApi((ApiName) any(), any(), any())).thenReturn(responseWrapper);
ResponseWrapper<?> result = proxyMasterdataService.getGenderTypesByLangCode("eng");
when(residentServiceRestClient.getApi((ApiName) any(), (Map<String, ?>) any(), any(), any(),
any())).thenReturn(responseWrapper);
ResponseWrapper<?> result = proxyMasterdataService.getDynamicFieldBasedOnLangCodeAndFieldName(fieldName, "eng", withValue);
assertNotNull(result);
}

@Test(expected = ResidentServiceCheckedException.class)
public void testGetGenderTypesByLangCodeIf() throws ApisResourceAccessException, ResidentServiceCheckedException {
when(residentServiceRestClient.getApi((ApiName) any(), any(), any())).thenReturn(responseWrapper);
when(residentServiceRestClient.getApi((ApiName) any(), (Map<String, ?>) any(), any(), any(),
any())).thenReturn(responseWrapper);
ServiceError error = new ServiceError();
error.setErrorCode("101");
error.setMessage("errors");
Expand All @@ -574,23 +580,25 @@ public void testGetGenderTypesByLangCodeIf() throws ApisResourceAccessException,
errorList.add(error);

responseWrapper.setErrors(errorList);
proxyMasterdataService.getGenderTypesByLangCode("xyz");
proxyMasterdataService.getDynamicFieldBasedOnLangCodeAndFieldName(fieldName, "xyz", withValue);
}

@Test
public void testGetGenderTypesByLangCodeElse() throws ApisResourceAccessException, ResidentServiceCheckedException {
when(residentServiceRestClient.getApi((ApiName) any(), any(), any())).thenReturn(responseWrapper);
when(residentServiceRestClient.getApi((ApiName) any(), (Map<String, ?>) any(), any(), any(),
any())).thenReturn(responseWrapper);
responseWrapper.setErrors(null);
ResponseWrapper<?> result = proxyMasterdataService.getGenderTypesByLangCode("eng");
ResponseWrapper<?> result = proxyMasterdataService.getDynamicFieldBasedOnLangCodeAndFieldName(fieldName, "eng", withValue);
assertNotNull(result);
}

@Test(expected = ResidentServiceCheckedException.class)
public void testGetGenderTypesByLangCodeWithApisResourceAccessException()
throws ApisResourceAccessException, ResidentServiceCheckedException {
when(residentServiceRestClient.getApi((ApiName) any(), any(), any()))
when(residentServiceRestClient.getApi((ApiName) any(), (Map<String, ?>) any(), any(), any(),
any()))
.thenThrow(new ApisResourceAccessException());
proxyMasterdataService.getGenderTypesByLangCode("eng");
proxyMasterdataService.getDynamicFieldBasedOnLangCodeAndFieldName(fieldName, "eng", withValue);
}

@Test
Expand Down Expand Up @@ -638,7 +646,8 @@ public void testGetGenderCodeByGenderTypeAndLangCode()
response.setGenderType(List.of(genderTypeDTO));
ResponseWrapper res = new ResponseWrapper();
res.setResponse(response);
when(residentServiceRestClient.getApi((ApiName) any(), any(), any())).thenReturn(res);
when(residentServiceRestClient.getApi((ApiName) any(), (Map<String, ?>) any(), any(), any(),
any())).thenReturn(res);
ResponseWrapper<GenderCodeResponseDTO> responseWrapper = proxyMasterdataService.getGenderCodeByGenderTypeAndLangCode("Male", "eng");
assertEquals(genderTypeDTO.getCode(),responseWrapper.getResponse().getGenderCode());
}
Expand All @@ -650,7 +659,8 @@ public void testGetGenderCodeByGenderTypeAndLangCodeNoValue()
response.setGenderType(List.of());
ResponseWrapper res = new ResponseWrapper();
res.setResponse(response);
when(residentServiceRestClient.getApi((ApiName) any(), any(), any())).thenReturn(res);
when(residentServiceRestClient.getApi((ApiName) any(), (Map<String, ?>) any(), any(), any(),
any())).thenReturn(res);
ResponseWrapper<GenderCodeResponseDTO> responseWrapper = proxyMasterdataService.getGenderCodeByGenderTypeAndLangCode("Male", "eng");
}

Expand Down

0 comments on commit 6c0f085

Please sign in to comment.