Skip to content

Commit

Permalink
MOSIP-29771 Fixed transliteration issue (#1183)
Browse files Browse the repository at this point in the history
* MOSIP-29771 Fixed tranliteration issue

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

* MOSIP-29771 Fixed test case

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

---------

Signed-off-by: kameshsr <[email protected]>
  • Loading branch information
kameshsr authored Dec 20, 2023
1 parent 1f8758a commit 4c46798
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,5 @@ private ResidentConstants() {
public static final String REST_CLIENT_RESPONSE_TIME_ID = "rest.client.response.time";
public static final String UNDER_SCORE = "_";
public static final String IDENTITY = "identity";
public static final String HYPHEN = "-";
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
package io.mosip.resident.controller;

import static io.mosip.resident.constant.ResidentConstants.API_RESPONSE_TIME_DESCRIPTION;
import static io.mosip.resident.constant.ResidentConstants.API_RESPONSE_TIME_ID;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.micrometer.core.annotation.Timed;
import io.mosip.preregistration.application.dto.TransliterationRequestDTO;
import io.mosip.preregistration.application.dto.TransliterationResponseDTO;
Expand All @@ -32,6 +17,22 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import static io.mosip.resident.constant.ResidentConstants.API_RESPONSE_TIME_DESCRIPTION;
import static io.mosip.resident.constant.ResidentConstants.API_RESPONSE_TIME_ID;

/**
* This class provides different API's to perform operations on
Expand All @@ -45,6 +46,7 @@
@Tag(name = "Transliteration Controller", description = "Transliteration Controller")
public class TransliterationController {


/** Autowired reference for {@link #transliterationService}. */
@Autowired
private TransliterationService transliterationService;
Expand All @@ -55,6 +57,13 @@ public class TransliterationController {
@Autowired
private AuditUtil audit;

@Autowired
private Environment environment;

private static final String RESIDENT_TRANSLITERATION_WORKAROUND_PROPERTY = "resident-transliteration-workaround-for-%s-%s";
private static final int LANGUAGE_LIST_SIZE = 2;


/**
* Post API to transliterate from transliteration application.
*
Expand All @@ -78,6 +87,38 @@ public ResponseEntity<MainResponseDTO<TransliterationResponseDTO>> translitrator
e.setMetadata(Map.of(ResidentConstants.REQ_RES_ID, ResidentConstants.TRANSLITERATE_ID));
throw e;
}
return ResponseEntity.status(HttpStatus.OK).body(transliterationService.translitratorService(requestDTO));
String propertyValue = environment.getProperty(String.format(RESIDENT_TRANSLITERATION_WORKAROUND_PROPERTY,
requestDTO.getRequest().getFromFieldLang(), requestDTO.getRequest().getToFieldLang()));
if (propertyValue != null) {
List<String> propertyValueList = List.of(propertyValue.split(ResidentConstants.COMMA));
MainResponseDTO<TransliterationResponseDTO> responseDTO = null;
for(String languagePair:propertyValueList){
MainRequestDTO<TransliterationRequestDTO> transliterationRequestDTOMainRequestDTO = new MainRequestDTO<>();
TransliterationRequestDTO transliterationRequestDTO = new TransliterationRequestDTO();
List<String> languageList = List.of(languagePair.split(ResidentConstants.HYPHEN));
if(languageList.size() == LANGUAGE_LIST_SIZE){
transliterationRequestDTO.setFromFieldLang(languageList.get(0));
transliterationRequestDTO.setToFieldLang(languageList.get(1));
if(responseDTO!=null){
transliterationRequestDTO.setFromFieldValue(responseDTO.getResponse().getToFieldValue());
} else {
transliterationRequestDTO.setFromFieldValue(requestDTO.getRequest().getFromFieldValue());
}
transliterationRequestDTOMainRequestDTO.setRequest(transliterationRequestDTO);
transliterationRequestDTOMainRequestDTO.setId(requestDTO.getId());
transliterationRequestDTOMainRequestDTO.setVersion(requestDTO.getVersion());
transliterationRequestDTOMainRequestDTO.setRequesttime(requestDTO.getRequesttime());
responseDTO = transliterationService.translitratorService(transliterationRequestDTOMainRequestDTO);
}
}
TransliterationResponseDTO transliterationResponseDTO = responseDTO.getResponse();
transliterationResponseDTO.setToFieldLang(requestDTO.getRequest().getToFieldLang());
transliterationResponseDTO.setFromFieldValue(requestDTO.getRequest().getFromFieldValue());
transliterationResponseDTO.setFromFieldLang(requestDTO.getRequest().getFromFieldLang());
responseDTO.setResponse(transliterationResponseDTO);
return ResponseEntity.status(HttpStatus.OK).body(responseDTO);
} else {
return ResponseEntity.status(HttpStatus.OK).body(transliterationService.translitratorService(requestDTO));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
Expand Down Expand Up @@ -59,6 +60,9 @@ public class TransliterationControllerTest {
@Mock
private ResidentVidServiceImpl residentVidService;

@Mock
private Environment environment;

@MockBean
@Qualifier("selfTokenRestTemplate")
private RestTemplate residentRestTemplate;
Expand Down

0 comments on commit 4c46798

Please sign in to comment.