Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into MOSIP-35404-Comm…
Browse files Browse the repository at this point in the history
…ons-Cleanup
  • Loading branch information
nandhu-kumar committed Jan 6, 2025
2 parents 5937f6f + d0d665d commit 94daa3b
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
public enum BlocklistedWordsErrorCode {
NO_BLOCKLISTED_WORDS_FOUND("KER-MSD-008", "Blocklisted word not found"),
BLOCKLISTED_WORDS_INVALID_LANGUAGE_CODE("KER-MSD-023", "Invalid language code"),
DUPLICATE_BLOCKLISTED_WORDS_FOUND("KER-MSD-071", "Duplicate Blocklisted word request"),
BLOCKLISTED_WORDS_FETCH_EXCEPTION("KER-MSD-007", "Error occurred while fetching Blocklisted words"),
BLOCKLISTED_WORDS_INSERT_EXCEPTION("KER-MSD-070", "Error occurred while inserting Blocklisted words"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
public enum LanguageErrorCode {

INVALID_LANGUAGE_CODE("KER-MSD-023", "Invalid language code"),
NO_LANGUAGE_FOUND_EXCEPTION("KER-MSD-24", "Language not found"),
LANGUAGE_FETCH_EXCEPTION("KER-MSD-23", "Error occured while fetching Languages"),
LANGUAGE_CREATE_EXCEPTION("KER-MSD-049", "Error occurred while inserting Language details"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.mosip.kernel.core.dataaccess.exception.DataAccessLayerException;
import io.mosip.kernel.core.datamapper.spi.DataMapper;
import io.mosip.kernel.masterdata.constant.BlocklistedWordsErrorCode;
import io.mosip.kernel.masterdata.constant.LanguageErrorCode;
import io.mosip.kernel.masterdata.constant.MachineErrorCode;
import io.mosip.kernel.masterdata.constant.MasterDataConstant;
import io.mosip.kernel.masterdata.constant.UpdateQueryConstants;
Expand Down Expand Up @@ -146,12 +147,13 @@ public BlocklistedWordsResponseDto getAllBlocklistedWordsBylangCode(String langC

private void validateLangCode(String langCode) {
if (langCode == null || langCode.trim().isEmpty()) {
throw new IllegalArgumentException("Language code cannot be null or empty");
throw new DataNotFoundException(LanguageErrorCode.NO_LANGUAGE_FOUND_EXCEPTION.getErrorCode(),
LanguageErrorCode.NO_LANGUAGE_FOUND_EXCEPTION.getErrorMessage());
}
Set<String> supportedLanguagesSet = new HashSet<>(Arrays.asList(supportedLanguages.split(",")));
if (!supportedLanguagesSet.contains(langCode)){
throw new DataNotFoundException(BlocklistedWordsErrorCode.BLOCKLISTED_WORDS_INVALID_LANGUAGE_CODE.getErrorCode(),
BlocklistedWordsErrorCode.BLOCKLISTED_WORDS_INVALID_LANGUAGE_CODE.getErrorMessage());
throw new DataNotFoundException(LanguageErrorCode.INVALID_LANGUAGE_CODE.getErrorCode(),
LanguageErrorCode.INVALID_LANGUAGE_CODE.getErrorMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
package io.mosip.kernel.masterdata.service.impl;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import jakarta.transaction.Transactional;

import io.mosip.kernel.masterdata.dto.response.FilterResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import io.mosip.kernel.core.dataaccess.exception.DataAccessLayerException;
import io.mosip.kernel.core.util.EmptyCheckUtils;
import io.mosip.kernel.masterdata.constant.DeviceTypeErrorCode;
import io.mosip.kernel.masterdata.constant.DocumentCategoryErrorCode;
import io.mosip.kernel.masterdata.constant.LanguageErrorCode;
import io.mosip.kernel.masterdata.constant.MasterDataConstant;
import io.mosip.kernel.masterdata.dto.DocumentCategoryDto;
import io.mosip.kernel.masterdata.dto.DocumentCategoryPutDto;
Expand All @@ -39,6 +20,7 @@
import io.mosip.kernel.masterdata.dto.request.SearchSort;
import io.mosip.kernel.masterdata.dto.response.ColumnValue;
import io.mosip.kernel.masterdata.dto.response.FilterResponseDto;
import io.mosip.kernel.masterdata.dto.response.FilterResult;
import io.mosip.kernel.masterdata.dto.response.PageResponseDto;
import io.mosip.kernel.masterdata.entity.DocumentCategory;
import io.mosip.kernel.masterdata.entity.ValidDocument;
Expand All @@ -60,6 +42,29 @@
import io.mosip.kernel.masterdata.validator.FilterColumnEnum;
import io.mosip.kernel.masterdata.validator.FilterColumnValidator;
import io.mosip.kernel.masterdata.validator.FilterTypeValidator;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Optional;
import java.util.Collections;

/**
* This class have methods to fetch list of valid document category, create
Expand Down Expand Up @@ -107,6 +112,9 @@ public class DocumentCategoryServiceImpl implements DocumentCategoryService {
@Autowired
private MasterdataCreationUtil masterdataCreationUtil;

@Value("${mosip.supported-languages}")
private String supportedLanguages;

/*
* (non-Javadoc)
*
Expand Down Expand Up @@ -151,10 +159,11 @@ public DocumentCategoryResponseDto getAllDocumentCategory() {
@Cacheable(value = "document-category", key = "'documentcategory'.concat('-').concat(#langCode)", condition="#langCode != null")
@Override
public DocumentCategoryResponseDto getAllDocumentCategoryByLaguageCode(String langCode) {
validateLangCode(langCode.toLowerCase());
List<DocumentCategoryDto> documentCategoryDtoList = new ArrayList<>();
try {
documentCategoryList = documentCategoryRepository
.findAllByLangCodeAndIsDeletedFalseOrIsDeletedIsNull(langCode);
.findAllByLangCodeAndIsDeletedFalseOrIsDeletedIsNull(langCode.toLowerCase());
} catch (DataAccessException | DataAccessLayerException e) {
throw new MasterDataServiceException(
DocumentCategoryErrorCode.DOCUMENT_CATEGORY_FETCH_EXCEPTION.getErrorCode(),
Expand All @@ -176,6 +185,18 @@ public DocumentCategoryResponseDto getAllDocumentCategoryByLaguageCode(String la
return documentCategoryResponseDto;
}

private void validateLangCode(String langCode) {
if (langCode == null || langCode.trim().isEmpty()) {
throw new DataNotFoundException(LanguageErrorCode.NO_LANGUAGE_FOUND_EXCEPTION.getErrorCode(),
LanguageErrorCode.NO_LANGUAGE_FOUND_EXCEPTION.getErrorMessage());
}
Set<String> supportedLanguagesSet = new HashSet<>(Arrays.asList(supportedLanguages.split(",")));
if (!supportedLanguagesSet.contains(langCode)){
throw new DataNotFoundException(LanguageErrorCode.INVALID_LANGUAGE_CODE.getErrorCode(),
LanguageErrorCode.INVALID_LANGUAGE_CODE.getErrorMessage());
}
}

/*
* (non-Javadoc)
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
package io.mosip.kernel.masterdata.service.impl;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;

import jakarta.transaction.Transactional;

import io.mosip.kernel.masterdata.dto.response.FilterResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import io.mosip.kernel.core.dataaccess.exception.DataAccessLayerException;
import io.mosip.kernel.core.util.EmptyCheckUtils;
import io.mosip.kernel.masterdata.constant.ApplicationErrorCode;
import io.mosip.kernel.masterdata.constant.DocumentTypeErrorCode;
import io.mosip.kernel.masterdata.constant.LanguageErrorCode;
import io.mosip.kernel.masterdata.constant.MasterDataConstant;
import io.mosip.kernel.masterdata.dto.DeviceTypeDto;
import io.mosip.kernel.masterdata.dto.DocumentTypeDto;
import io.mosip.kernel.masterdata.dto.DocumentTypePutReqDto;
import io.mosip.kernel.masterdata.dto.MissingCodeDataDto;
import io.mosip.kernel.masterdata.dto.getresponse.DocumentTypeResponseDto;
import io.mosip.kernel.masterdata.dto.getresponse.PageDto;
import io.mosip.kernel.masterdata.dto.getresponse.StatusResponseDto;
Expand All @@ -42,6 +23,7 @@
import io.mosip.kernel.masterdata.dto.request.SearchSort;
import io.mosip.kernel.masterdata.dto.response.ColumnValue;
import io.mosip.kernel.masterdata.dto.response.FilterResponseDto;
import io.mosip.kernel.masterdata.dto.response.FilterResult;
import io.mosip.kernel.masterdata.dto.response.PageResponseDto;
import io.mosip.kernel.masterdata.entity.DeviceType;
import io.mosip.kernel.masterdata.entity.DocumentType;
Expand All @@ -62,6 +44,32 @@
import io.mosip.kernel.masterdata.utils.PageUtils;
import io.mosip.kernel.masterdata.validator.FilterColumnValidator;
import io.mosip.kernel.masterdata.validator.FilterTypeValidator;
import jakarta.transaction.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Optional;
import java.util.Collections;
import java.util.Objects;

/**
* This class have methods to fetch list of valid document type, create document
Expand Down Expand Up @@ -111,6 +119,9 @@ public class DocumentTypeServiceImpl implements DocumentTypeService {

@Autowired
private AuditUtil auditUtil;

@Value("${mosip.supported-languages}")
private String supportedLanguages;

/*
* (non-Javadoc)
Expand Down Expand Up @@ -403,6 +414,7 @@ public PageResponseDto<DocumentTypeExtnDto> searchDocumentTypes(SearchDto dto) {
@Cacheable(value = "document-type", key = "'documenttype'.concat('-').concat(#langCode)", condition = "#langCode != null")
@Override
public DocumentTypeResponseDto getAllDocumentTypeByLaguageCode(String langCode) {
validateLangCode(langCode.toLowerCase());
DocumentTypeResponseDto documentTypeResponseDto = new DocumentTypeResponseDto();
List<DocumentTypeDto> documentTypeDtoList = new ArrayList<>();
List<DocumentType> documentTypesList = null;
Expand All @@ -428,6 +440,18 @@ public DocumentTypeResponseDto getAllDocumentTypeByLaguageCode(String langCode)
return documentTypeResponseDto;
}

private void validateLangCode(String langCode) {
if (langCode == null || langCode.trim().isEmpty()) {
throw new DataNotFoundException(LanguageErrorCode.NO_LANGUAGE_FOUND_EXCEPTION.getErrorCode(),
LanguageErrorCode.NO_LANGUAGE_FOUND_EXCEPTION.getErrorMessage());
}
Set<String> supportedLanguagesSet = new HashSet<>(Arrays.asList(supportedLanguages.split(",")));
if (!supportedLanguagesSet.contains(langCode)){
throw new DataNotFoundException(LanguageErrorCode.INVALID_LANGUAGE_CODE.getErrorCode(),
LanguageErrorCode.INVALID_LANGUAGE_CODE.getErrorMessage());
}
}

@CacheEvict(value = "document-type", allEntries = true)
@Override
public StatusResponseDto updateDocumentType(String code, boolean isActive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void getAllDocumentCategories_Success() throws Exception {
@WithUserDetails("global-admin")
public void testGetAllDocumentCategoriesByLanguageCode_InvalidLanguage_Error() throws Exception {

MasterDataTest.checkResponse(mockMvc.perform(MockMvcRequestBuilders.get("/documentcategories/eng1")).andReturn(),"KER-MSD-014");
MasterDataTest.checkResponse(mockMvc.perform(MockMvcRequestBuilders.get("/documentcategories/eng1")).andReturn(),"KER-MSD-023");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package io.mosip.kernel.masterdata.test.controller;

import static org.mockito.Mockito.doNothing;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.mosip.kernel.core.http.RequestWrapper;
import io.mosip.kernel.core.websub.model.EventModel;
import io.mosip.kernel.core.websub.spi.PublisherClient;
import io.mosip.kernel.masterdata.dto.DocumentTypeDto;
import io.mosip.kernel.masterdata.dto.DocumentTypePutReqDto;
import io.mosip.kernel.masterdata.dto.request.FilterDto;
import io.mosip.kernel.masterdata.dto.request.FilterValueDto;
import io.mosip.kernel.masterdata.dto.request.Pagination;
import io.mosip.kernel.masterdata.dto.request.SearchDto;
import io.mosip.kernel.masterdata.dto.request.SearchSort;
import io.mosip.kernel.masterdata.test.TestBootApplication;
import io.mosip.kernel.masterdata.test.utils.MasterDataTest;
import io.mosip.kernel.masterdata.utils.AuditUtil;
import io.mosip.kernel.masterdata.validator.FilterColumnEnum;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
Expand All @@ -22,23 +33,10 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.util.ArrayList;
import java.util.List;

import io.mosip.kernel.core.http.RequestWrapper;
import io.mosip.kernel.core.websub.model.EventModel;
import io.mosip.kernel.core.websub.spi.PublisherClient;
import io.mosip.kernel.masterdata.dto.DocumentTypeDto;
import io.mosip.kernel.masterdata.dto.DocumentTypePutReqDto;
import io.mosip.kernel.masterdata.dto.request.FilterDto;
import io.mosip.kernel.masterdata.dto.request.FilterValueDto;
import io.mosip.kernel.masterdata.dto.request.Pagination;
import io.mosip.kernel.masterdata.dto.request.SearchDto;
import io.mosip.kernel.masterdata.dto.request.SearchSort;
import io.mosip.kernel.masterdata.test.TestBootApplication;
import io.mosip.kernel.masterdata.test.utils.MasterDataTest;
import io.mosip.kernel.masterdata.utils.AuditUtil;
import io.mosip.kernel.masterdata.validator.FilterColumnEnum;
import static org.mockito.Mockito.doNothing;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestBootApplication.class)
Expand Down Expand Up @@ -194,7 +192,7 @@ public void t018deleteDocumentTypeTest() throws Exception {
public void t019deleteDocumentTypeFailTest() throws Exception {

MasterDataTest.checkResponse(mockMvc.perform(MockMvcRequestBuilders.get("/documenttypes/CINN"))
.andReturn(),"KER-MSD-118");
.andReturn(),"KER-MSD-023");
}

@Test
Expand Down Expand Up @@ -282,7 +280,7 @@ public void t014getAllDocumentTypeByLaguageCodeTest() throws Exception {
public void t015getAllDocumentTypeByLaguageCodeFailTest() throws Exception {

MasterDataTest.checkResponse(mockMvc.perform(MockMvcRequestBuilders.get("/documenttypes/eng1"))
.andReturn(),"KER-MSD-118");
.andReturn(),"KER-MSD-023");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ public void getAllWordsBylangCodeFetchExceptionTest() throws Exception {
@Test
@WithUserDetails("individual")
public void getAllWordsBylangCodeNullArgExceptionTest() throws Exception {
mockMvc.perform(get("/blocklistedwords/{langcode}", " ")).andExpect(status().isInternalServerError());
mockMvc.perform(get("/blocklistedwords/{langcode}", " ")).andExpect(status().isOk());
}

// -----------------------------GenderTypeTest----------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ public void testGetAllBlocklistedWordsNullvalue() {
blocklistedWordsService.getAllBlocklistedWordsBylangCode(null);
}

@Test(expected = IllegalArgumentException.class)
@Test(expected = DataNotFoundException.class)
public void testGetAllBlocklistedWordsEmptyvalue() {
blocklistedWordsService.getAllBlocklistedWordsBylangCode("");
}
Expand Down Expand Up @@ -1760,20 +1760,14 @@ public void getAllDocumentCategoryByLaguageCodeSuccessTest() {
documentCategoryResponseDto.getDocumentcategories().get(0).getName());
}

@Test(expected = MasterDataServiceException.class)
public void getAllDocumentCategoryByLaguageCodeFetchException() {
Mockito.when(
documentCategoryRepository.findAllByLangCodeAndIsDeletedFalseOrIsDeletedIsNull(Mockito.anyString()))
.thenThrow(DataRetrievalFailureException.class);
documentCategoryService.getAllDocumentCategoryByLaguageCode(Mockito.anyString());
@Test(expected = DataNotFoundException.class)
public void getAllDocumentCategoryByLanguageCodeFetchException() {
documentCategoryService.getAllDocumentCategoryByLaguageCode("eng");
}

@Test(expected = DataNotFoundException.class)
public void getAllDocumentCategoryByLaguageCodeNotFound() {
Mockito.when(
documentCategoryRepository.findAllByLangCodeAndIsDeletedFalseOrIsDeletedIsNull(Mockito.anyString()))
.thenReturn(new ArrayList<DocumentCategory>());
documentCategoryService.getAllDocumentCategoryByLaguageCode(Mockito.anyString());
public void getAllDocumentCategoryByLanguageCodeNotFound() {
documentCategoryService.getAllDocumentCategoryByLaguageCode("GER");
}

@Test
Expand Down
Loading

0 comments on commit 94daa3b

Please sign in to comment.