From ac23fe90ddea2230c0595fafcdb5d4c8239ef1c6 Mon Sep 17 00:00:00 2001 From: anilgupta Date: Thu, 26 Oct 2023 11:08:56 +0530 Subject: [PATCH] Issue #LR-676 feat: Delete user --- .../dao/user/UserExternalIdentityDao.java | 2 ++ .../impl/UserExternalIdentityDaoImpl.java | 27 +++++++++++++++++-- .../user/UserExternalIdentityService.java | 2 ++ .../impl/UserExternalIdentityServiceImpl.java | 10 ++++++- .../UserExternalIdentityServiceImplTest.java | 22 +++++++++++++-- 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/service/src/main/java/org/sunbird/dao/user/UserExternalIdentityDao.java b/service/src/main/java/org/sunbird/dao/user/UserExternalIdentityDao.java index a06017ba00..e4504c6f6d 100644 --- a/service/src/main/java/org/sunbird/dao/user/UserExternalIdentityDao.java +++ b/service/src/main/java/org/sunbird/dao/user/UserExternalIdentityDao.java @@ -12,4 +12,6 @@ public interface UserExternalIdentityDao { public List> getUserSelfDeclaredDetails( String userId, RequestContext context); + + public void deleteUserExternalId(Map map, RequestContext context); } diff --git a/service/src/main/java/org/sunbird/dao/user/impl/UserExternalIdentityDaoImpl.java b/service/src/main/java/org/sunbird/dao/user/impl/UserExternalIdentityDaoImpl.java index 4f1d04b2f5..e02f7eb39c 100644 --- a/service/src/main/java/org/sunbird/dao/user/impl/UserExternalIdentityDaoImpl.java +++ b/service/src/main/java/org/sunbird/dao/user/impl/UserExternalIdentityDaoImpl.java @@ -50,7 +50,11 @@ public List> getUserExternalIds(String userId, RequestContex Map req = new HashMap<>(); req.put(JsonKey.USER_ID, userId); Response response = - cassandraOperation.getRecordById(ProjectUtil.getConfigValue(JsonKey.SUNBIRD_KEYSPACE), JsonKey.USR_EXT_IDNT_TABLE, req, context); + cassandraOperation.getRecordById( + ProjectUtil.getConfigValue(JsonKey.SUNBIRD_KEYSPACE), + JsonKey.USR_EXT_IDNT_TABLE, + req, + context); if (null != response && null != response.getResult()) { dbResExternalIds = (List>) response.getResult().get(JsonKey.RESPONSE); } @@ -65,10 +69,29 @@ public List> getUserSelfDeclaredDetails( req.put(JsonKey.USER_ID, userId); Response response = cassandraOperation.getRecordById( - ProjectUtil.getConfigValue(JsonKey.SUNBIRD_KEYSPACE), JsonKey.USER_DECLARATION_DB, req, context); + ProjectUtil.getConfigValue(JsonKey.SUNBIRD_KEYSPACE), + JsonKey.USER_DECLARATION_DB, + req, + context); if (null != response && null != response.getResult()) { dbResExternalIds = (List>) response.getResult().get(JsonKey.RESPONSE); } return dbResExternalIds; } + + @Override + public void deleteUserExternalId(Map map, RequestContext context) { + map.remove(JsonKey.LAST_UPDATED_BY); + map.remove(JsonKey.CREATED_BY); + map.remove(JsonKey.LAST_UPDATED_ON); + map.remove(JsonKey.CREATED_ON); + map.remove(JsonKey.ORIGINAL_EXTERNAL_ID); + map.remove(JsonKey.ORIGINAL_ID_TYPE); + map.remove(JsonKey.ORIGINAL_PROVIDER); + cassandraOperation.deleteRecord( + ProjectUtil.getConfigValue(JsonKey.SUNBIRD_KEYSPACE), + JsonKey.USR_EXT_IDNT_TABLE, + map, + context); + } } diff --git a/service/src/main/java/org/sunbird/service/user/UserExternalIdentityService.java b/service/src/main/java/org/sunbird/service/user/UserExternalIdentityService.java index 8ab6caea09..2bd346655b 100644 --- a/service/src/main/java/org/sunbird/service/user/UserExternalIdentityService.java +++ b/service/src/main/java/org/sunbird/service/user/UserExternalIdentityService.java @@ -16,4 +16,6 @@ List> getExternalIds( String getUserV1(String extId, String provider, String idType, RequestContext context); String getUserV2(String extId, String orgId, String idType, RequestContext context); + + void deleteUserExternalIds(List> dbUserExternalIds, RequestContext context); } diff --git a/service/src/main/java/org/sunbird/service/user/impl/UserExternalIdentityServiceImpl.java b/service/src/main/java/org/sunbird/service/user/impl/UserExternalIdentityServiceImpl.java index 378c454a36..f2579987a2 100644 --- a/service/src/main/java/org/sunbird/service/user/impl/UserExternalIdentityServiceImpl.java +++ b/service/src/main/java/org/sunbird/service/user/impl/UserExternalIdentityServiceImpl.java @@ -21,7 +21,7 @@ public class UserExternalIdentityServiceImpl implements UserExternalIdentityServ private final UserExternalIdentityDao userExternalIdentityDao = new UserExternalIdentityDaoImpl(); private final LocationService locationService = LocationServiceImpl.getInstance(); private static UserExternalIdentityService selfDeclarationService = null; - + public static UserExternalIdentityService getInstance() { if (selfDeclarationService == null) { selfDeclarationService = new UserExternalIdentityServiceImpl(); @@ -142,4 +142,12 @@ public String getUserV1(String extId, String provider, String idType, RequestCon public String getUserV2(String extId, String orgId, String idType, RequestContext context) { return userExternalIdentityDao.getUserIdByExternalId(extId.toLowerCase(), orgId, context); } + + @Override + public void deleteUserExternalIds( + List> dbUserExternalIds, RequestContext context) { + for (Map extIdMap : dbUserExternalIds) { + userExternalIdentityDao.deleteUserExternalId(extIdMap, context); + } + } } diff --git a/service/src/test/java/org/sunbird/service/user/impl/UserExternalIdentityServiceImplTest.java b/service/src/test/java/org/sunbird/service/user/impl/UserExternalIdentityServiceImplTest.java index 40ad74db45..6af91f8b52 100644 --- a/service/src/test/java/org/sunbird/service/user/impl/UserExternalIdentityServiceImplTest.java +++ b/service/src/test/java/org/sunbird/service/user/impl/UserExternalIdentityServiceImplTest.java @@ -1,7 +1,6 @@ package org.sunbird.service.user.impl; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.powermock.api.mockito.PowerMockito.*; import java.util.ArrayList; import java.util.HashMap; @@ -85,4 +84,23 @@ public void getExternalIdsTest() { userExternalIdentityService.getExternalIds("userId", true, new RequestContext()); Assert.assertNotNull(externalIds); } + + @Test + public void deleteExternalIdsTest() { + Map userExtIdMap = new HashMap<>(); + userExtIdMap.put("provider", "0132818330295992324"); + userExtIdMap.put("idtype", "teacherId"); + userExtIdMap.put("externalid", "cedd456"); + userExtIdMap.put("userid", "46545665465465"); + + List> userExtIdRespList = new ArrayList<>(); + userExtIdRespList.add(userExtIdMap); + + doNothing() + .when(cassandraOperationImpl) + .deleteRecord(Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any()); + + UserExternalIdentityService userExternalIdentityService = new UserExternalIdentityServiceImpl(); + userExternalIdentityService.deleteUserExternalIds(userExtIdRespList, new RequestContext()); + } }