Skip to content

Commit

Permalink
Issue #LR-676 feat: Delete user
Browse files Browse the repository at this point in the history
  • Loading branch information
AmiableAnil committed Oct 26, 2023
1 parent 168097f commit ac23fe9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface UserExternalIdentityDao {

public List<Map<String, Object>> getUserSelfDeclaredDetails(
String userId, RequestContext context);

public void deleteUserExternalId(Map<String, String> map, RequestContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public List<Map<String, String>> getUserExternalIds(String userId, RequestContex
Map<String, Object> 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<Map<String, String>>) response.getResult().get(JsonKey.RESPONSE);
}
Expand All @@ -65,10 +69,29 @@ public List<Map<String, Object>> 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<Map<String, Object>>) response.getResult().get(JsonKey.RESPONSE);
}
return dbResExternalIds;
}

@Override
public void deleteUserExternalId(Map<String, String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ List<Map<String, String>> getExternalIds(
String getUserV1(String extId, String provider, String idType, RequestContext context);

String getUserV2(String extId, String orgId, String idType, RequestContext context);

void deleteUserExternalIds(List<Map<String, String>> dbUserExternalIds, RequestContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<Map<String, String>> dbUserExternalIds, RequestContext context) {
for (Map<String, String> extIdMap : dbUserExternalIds) {
userExternalIdentityDao.deleteUserExternalId(extIdMap, context);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -85,4 +84,23 @@ public void getExternalIdsTest() {
userExternalIdentityService.getExternalIds("userId", true, new RequestContext());
Assert.assertNotNull(externalIds);
}

@Test
public void deleteExternalIdsTest() {
Map<String, String> userExtIdMap = new HashMap<>();
userExtIdMap.put("provider", "0132818330295992324");
userExtIdMap.put("idtype", "teacherId");
userExtIdMap.put("externalid", "cedd456");
userExtIdMap.put("userid", "46545665465465");

List<Map<String, String>> 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());
}
}

0 comments on commit ac23fe9

Please sign in to comment.