From b34aba030278916c71e8a8488ea32a68ce6c9913 Mon Sep 17 00:00:00 2001
From: Balaji Alluru <74903654+balaji-alluru@users.noreply.github.com>
Date: Mon, 22 Jan 2024 00:03:38 +0530
Subject: [PATCH] [MOSIP-29094]Updated sql queries with case insensitive search
(#920)
* Updated sql queries with case insensitive search
Signed-off-by: Balaji <74903654+balaji-alluru@users.noreply.github.com>
* updated getter methods
Signed-off-by: Balaji <74903654+balaji-alluru@users.noreply.github.com>
* Updated user detail History and zone user history repositories
Signed-off-by: Balaji <74903654+balaji-alluru@users.noreply.github.com>
* Updated zone user repository
Signed-off-by: Balaji <74903654+balaji-alluru@users.noreply.github.com>
* Fixed admin build issues
Signed-off-by: Balaji <74903654+balaji-alluru@users.noreply.github.com>
---------
Signed-off-by: Balaji <74903654+balaji-alluru@users.noreply.github.com>
---
admin/admin-service/pom.xml | 27 ++++++++++++++++++-
.../io/mosip/admin/TestBootApplication.java | 8 ++++++
.../controller/UserDetailsController.java | 2 +-
.../kernel/masterdata/dto/UserDetailsDto.java | 5 ++++
.../kernel/masterdata/entity/ZoneUser.java | 4 +++
.../UserDetailsHistoryRepository.java | 4 +--
.../repository/UserDetailsRepository.java | 10 +++----
.../repository/ZoneUserHistoryRepository.java | 2 +-
.../repository/ZoneUserRepository.java | 22 +++++++++------
.../service/UserDetailsService.java | 2 +-
.../service/impl/UserDetailsServiceImpl.java | 2 +-
.../service/impl/ZoneUserServiceImpl.java | 3 +--
12 files changed, 69 insertions(+), 22 deletions(-)
diff --git a/admin/admin-service/pom.xml b/admin/admin-service/pom.xml
index 2f24157900b..72c33550af4 100644
--- a/admin/admin-service/pom.xml
+++ b/admin/admin-service/pom.xml
@@ -36,6 +36,26 @@
+
+ com.fasterxml.jackson.core
+ jackson-core
+ 2.12.0
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.12.0
+
+
+ com.fasterxml.jackson.core
+ jackson-annotations
+ 2.12.0
+
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-xml
+ 2.12.0
+
org.projectlombok
lombok
@@ -129,7 +149,12 @@
-
+
+ javax.validation
+ validation-api
+ 2.0.1.Final
+
+
io.mosip.commons
commons-packet-manager
diff --git a/admin/admin-service/src/test/java/io/mosip/admin/TestBootApplication.java b/admin/admin-service/src/test/java/io/mosip/admin/TestBootApplication.java
index 57022f9d24e..17592a1a5d1 100644
--- a/admin/admin-service/src/test/java/io/mosip/admin/TestBootApplication.java
+++ b/admin/admin-service/src/test/java/io/mosip/admin/TestBootApplication.java
@@ -2,9 +2,13 @@
import io.mosip.commons.packet.impl.OnlinePacketCryptoServiceImpl;
import io.mosip.commons.packet.keeper.PacketKeeper;
+
+import javax.validation.Validator;
+
import org.mockito.Mockito;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.web.client.RestTemplate;
@@ -36,4 +40,8 @@ public PacketKeeper packetKeeper() {
return Mockito.mock(PacketKeeper.class);
}
+ @Bean
+ public Validator validator() {
+ return Mockito.mock(Validator.class);
+ }
}
diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/controller/UserDetailsController.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/controller/UserDetailsController.java
index 3d6dd76a08f..6ad6fcdbc1e 100644
--- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/controller/UserDetailsController.java
+++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/controller/UserDetailsController.java
@@ -267,7 +267,7 @@ public ResponseWrapper> serachUserCent
auditUtil.auditRequest(MasterDataConstant.SEARCH_USER_DETAILS_API_IS_CALLED + SearchDto.class.getCanonicalName(),
MasterDataConstant.AUDIT_SYSTEM,
MasterDataConstant.SEARCH_USER_DETAILS_API_IS_CALLED + SearchDto.class.getCanonicalName(),"ADM-922");
- responseWrapper.setResponse(userDetailsService.serachUserCenterMappingDetails(dto.getRequest()));
+ responseWrapper.setResponse(userDetailsService.searchUserCenterMappingDetails(dto.getRequest()));
return responseWrapper;
}
diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/dto/UserDetailsDto.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/dto/UserDetailsDto.java
index 558c7103934..aabb5b4a794 100644
--- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/dto/UserDetailsDto.java
+++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/dto/UserDetailsDto.java
@@ -37,5 +37,10 @@ public class UserDetailsDto {
private String langCode;
+
+
+ public String getId() {
+ return this.id.toLowerCase();
+ }
}
diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/entity/ZoneUser.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/entity/ZoneUser.java
index 902f5d2b96b..e277d317822 100644
--- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/entity/ZoneUser.java
+++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/entity/ZoneUser.java
@@ -35,5 +35,9 @@ public class ZoneUser extends BaseEntity implements Serializable {
@Column(name = "lang_code", nullable = true, length = 3)
private String langCode;
+
+ public String getUserId() {
+ return this.userId.toLowerCase();
+ }
}
diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/UserDetailsHistoryRepository.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/UserDetailsHistoryRepository.java
index 1dea216e648..bb3e807ebea 100644
--- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/UserDetailsHistoryRepository.java
+++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/UserDetailsHistoryRepository.java
@@ -25,11 +25,11 @@ public interface UserDetailsHistoryRepository extends BaseRepository getByUserIdAndTimestamp(String userId, LocalDateTime effDTimes);
// (?2 BETWEEN effDTimes AND CURRENT_TIMESTAMP)
- @Query(value = "Select * from master.user_detail_h m where m.regcntr_id = ?1 and m.id = ?2 and m.eff_dtimes <= ?3 and ( m.is_deleted = false or m.is_deleted is null) order by m.eff_dtimes desc ", nativeQuery = true)
+ @Query(value = "Select * from master.user_detail_h m where m.regcntr_id = ?1 and LOWER(m.id) = LOWER(?2) and m.eff_dtimes <= ?3 and ( m.is_deleted = false or m.is_deleted is null) order by m.eff_dtimes desc ", nativeQuery = true)
List findByCntrIdAndUsrIdAndEffectivetimesLessThanEqualAndIsDeletedFalseOrIsDeletedIsNull(
String registrationCenterId, String userId, LocalDateTime lDateAndTime);
diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/UserDetailsRepository.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/UserDetailsRepository.java
index a04b5660ec4..dfe5e90fa06 100644
--- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/UserDetailsRepository.java
+++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/UserDetailsRepository.java
@@ -28,25 +28,25 @@ public interface UserDetailsRepository extends BaseRepository findByRegIdAndIsDeletedFalseOrIsDeletedIsNull(String centerId, Pageable pageable);
- @Query("FROM UserDetails m where m.id = ?1 and (m.isDeleted is null or m.isDeleted = false)")
+ @Query("FROM UserDetails m where LOWER(m.id) = LOWER(?1) and (m.isDeleted is null or m.isDeleted = false)")
UserDetails findByIdAndIsDeletedFalseorIsDeletedIsNull(String id);
- @Query("FROM UserDetails m where m.id = ?1")
+ @Query("FROM UserDetails m where LOWER(m.id) = LOWER(?1)")
UserDetails findUserDetailsById(String id);
@Query("FROM UserDetails m where (m.isDeleted is null or m.isDeleted = false)")
List findAllByAndIsDeletedFalseorIsDeletedIsNull();
- @Query("FROM UserDetails m where m.id = ?1 and (m.isDeleted is null or m.isDeleted = false) and isActive = true")
+ @Query("FROM UserDetails m where LOWER(m.id) = LOWER(?1) and (m.isDeleted is null or m.isDeleted = false) and isActive = true")
UserDetails findByIdAndIsDeletedFalseorIsDeletedIsNullAndIsActive(String id);
@Query("FROM UserDetails m where (m.isDeleted is null or m.isDeleted = false) and m.isActive = true")
Page findAllByIsDeletedFalseorIsDeletedIsNull(Pageable pageable);
- @Query("FROM UserDetails m where m.id = ?1 and m.langCode = ?2 and (m.isDeleted is null or m.isDeleted = false)")
+ @Query("FROM UserDetails m where LOWER(m.id) = LOWER(?1) and m.langCode = ?2 and (m.isDeleted is null or m.isDeleted = false)")
UserDetails findByIdAndIsDeletedFalseorIsDeletedIsNull(String id,String langCode);
@Modifying
- @Query("UPDATE UserDetails m SET m.updatedBy=?3, m.isDeleted =true, m.isActive = false, m.updatedDateTime=?2 ,m.deletedDateTime = ?2 WHERE m.id =?1 and (m.isDeleted is null or m.isDeleted =false)")
+ @Query("UPDATE UserDetails m SET m.updatedBy=?3, m.isDeleted =true, m.isActive = false, m.updatedDateTime=?2 ,m.deletedDateTime = ?2 WHERE LOWER(m.id) = LOWER(?1) and (m.isDeleted is null or m.isDeleted =false)")
int deleteUserCenterMapping(String id, LocalDateTime deletedDateTime, String updatedBy);
}
diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/ZoneUserHistoryRepository.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/ZoneUserHistoryRepository.java
index 5f605907454..2e7ed573522 100644
--- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/ZoneUserHistoryRepository.java
+++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/ZoneUserHistoryRepository.java
@@ -11,7 +11,7 @@
import io.mosip.kernel.masterdata.entity.id.ZoneUserHistoryId;
@Repository
public interface ZoneUserHistoryRepository extends BaseRepository{
- @Query(value = "SELECT * FROM master.zone_user_h m WHERE usr_id = ?1 AND eff_dtimes>= ?2 ORDER BY eff_dtimes DESC ", nativeQuery = true)
+ @Query(value = "SELECT * FROM master.zone_user_h m WHERE LOWER(usr_id) = LOWER(?1) AND eff_dtimes>= ?2 ORDER BY eff_dtimes DESC ", nativeQuery = true)
List getByUserIdAndTimestamp(String userId, LocalDateTime localDateTime);
}
diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/ZoneUserRepository.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/ZoneUserRepository.java
index bcea2fb5584..7bc5f11ff2e 100644
--- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/ZoneUserRepository.java
+++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/ZoneUserRepository.java
@@ -21,34 +21,40 @@
*/
public interface ZoneUserRepository extends BaseRepository {
- @Query("FROM ZoneUser zu WHERE zu.userId=?1 and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
+ @Query("FROM ZoneUser zu WHERE LOWER(zu.userId)=LOWER(?1) and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
public List findByUserIdNonDeleted(String userId);
- @Query("FROM ZoneUser zu WHERE zu.userId=?1 and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
+ @Query("FROM ZoneUser zu WHERE LOWER(zu.userId)=LOWER(?1) and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
public ZoneUser findZoneByUserIdNonDeleted(String userId);
- @Query("FROM ZoneUser zu WHERE zu.userId=?1 ")
+ @Query("FROM ZoneUser zu WHERE LOWER(zu.userId)=LOWER(?1) ")
public ZoneUser findByUserId(String userId);
- @Query("FROM ZoneUser zu WHERE zu.userId=?1 and zu.zoneCode=?2 ")
+ @Query("FROM ZoneUser zu WHERE LOWER(zu.userId)=LOWER(?1) and zu.zoneCode=?2 ")
public List findByUserIdAndZoneCode(String userId, String zoneCode);
- @Query("FROM ZoneUser zu WHERE zu.userId=?1 and zu.zoneCode=?2 and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
+ @Query("FROM ZoneUser zu WHERE LOWER(zu.userId)=LOWER(?1) and zu.zoneCode=?2 and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
public ZoneUser findByIdAndIsDeletedFalseOrIsDeletedIsNull(String userId, String zoneCode);
@Query("FROM ZoneUser zu WHERE zu.zoneCode=?1 and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
public List findtoUpdateZoneUserByCode(String zoneCode);
- @Query("FROM ZoneUser zu WHERE zu.userId=?1 and zu.langCode=?2 and zu.zoneCode=?3 and (zu.isDeleted IS NULL OR zu.isDeleted = false) and zu.isActive=true")
+ @Query("FROM ZoneUser zu WHERE LOWER(zu.userId)=LOWER(?1) and zu.langCode=?2 and zu.zoneCode=?3 and (zu.isDeleted IS NULL OR zu.isDeleted = false) and zu.isActive=true")
public ZoneUser findZoneUserByUserIdZoneCodeLangCodeIsActive(String userId, String langCode, String zoneCode);
@Query("FROM ZoneUser zu WHERE zu.userId IN :userids")
public List findByUserIds(@Param("userids") List userIds);
- @Query("FROM ZoneUser zu WHERE zu.userId=?1 and zu.isActive=true and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
+ @Query("FROM ZoneUser zu WHERE LOWER(zu.userId)=LOWER(?1) and zu.isActive=true and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
public ZoneUser findZoneByUserIdActiveAndNonDeleted(String userId);
- @Query("FROM ZoneUser zu WHERE LOWER(zu.zoneCode) like (%?1%) and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
+ /*
+ * This is a query used by a deprecated end point /users/search, this should be removed in next release.
+ * The end point using this query was added in version 1.2.0-rc1 and marked as deprecated in version 1.2.0
+ * For security reason, we replaced the 'LIKE' query with equals in where clause.
+ */
+
+ @Query("FROM ZoneUser zu WHERE LOWER(zu.zoneCode)=?1 and (zu.isDeleted IS NULL OR zu.isDeleted = false) ")
public List findZoneByZoneCodeActiveAndNonDeleted(String zoneCode);
@Modifying
diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/UserDetailsService.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/UserDetailsService.java
index 0cb388b2e05..cc83b6f9649 100644
--- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/UserDetailsService.java
+++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/UserDetailsService.java
@@ -126,6 +126,6 @@ public UsersDto getUsers(String roleName,int pageStart, int pageFetch,
public StatusResponseDto updateUserStatus(String id, @Valid boolean isActive);
- public PageResponseDto serachUserCenterMappingDetails(SearchDtoWithoutLangCode request);
+ public PageResponseDto searchUserCenterMappingDetails(SearchDtoWithoutLangCode request);
}
diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/UserDetailsServiceImpl.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/UserDetailsServiceImpl.java
index bcc1384d6a7..773dd4dfd7a 100644
--- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/UserDetailsServiceImpl.java
+++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/UserDetailsServiceImpl.java
@@ -653,7 +653,7 @@ public PageResponseDto searchUserDetails(SearchDtoWithoutLan
}
@Override
- public PageResponseDto serachUserCenterMappingDetails(SearchDtoWithoutLangCode searchDto) {
+ public PageResponseDto searchUserCenterMappingDetails(SearchDtoWithoutLangCode searchDto) {
PageResponseDto pageDto = new PageResponseDto<>();
PageResponseDto userCenterPageDto = new PageResponseDto<>();
List userCenterMappingExtnDtos = null;
diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/ZoneUserServiceImpl.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/ZoneUserServiceImpl.java
index 55b1d5db121..b91dde392fb 100644
--- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/ZoneUserServiceImpl.java
+++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/ZoneUserServiceImpl.java
@@ -127,7 +127,6 @@ public ZoneUserExtnDto createZoneUserMapping(ZoneUserDto zoneUserDto) {
// Throws exception if not found
zoneservice.getZone(zoneUserDto.getZoneCode(), languageUtils.getDefaultLanguage());
-
zu = zoneUserRepo.save(zu);
ZoneUserHistory zuh = new ZoneUserHistory();
MapperUtils.map(zu, zuh);
@@ -309,7 +308,7 @@ public StatusResponseDto updateZoneUserMapping(String userId, boolean isActive)
throw new MasterDataServiceException(ZoneUserErrorCode.USER_MAPPING_EXIST.getErrorCode(),
ZoneUserErrorCode.USER_MAPPING_EXIST.getErrorMessage());
}
- masterdataCreationUtil.updateMasterDataStatus(ZoneUser.class, userId, isActive, "userId");
+ masterdataCreationUtil.updateMasterDataStatus(ZoneUser.class, userId.toLowerCase(), isActive, "userId");
ZoneUserHistory zoneUserHistory = new ZoneUserHistory();
MetaDataUtils.setUpdateMetaData(zoneUser, zoneUserHistory, true);