Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KB-1722 - Create an API to get the user login details and raise the kafka event #58

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -644,5 +644,7 @@ public final class JsonKey {
public static final String FIRST_LOGIN = "first_login";
public static final String EDATA = "edata";

public static final String SELF_REGISTRATION = "self_registration";
public static final String CREATEDBY = "createdby";
private JsonKey() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,12 @@ public Response getUserLoggedInDetails(Request actorMessage) throws Exception {
Map<String, Object> userDetailsMap = new HashMap<>();
List<Map<String, Object>> list = (List<Map<String, Object>>) response.get(JsonKey.RESPONSE);
list.forEach(a -> a.forEach(userDetailsMap::putIfAbsent));
Map<String, Object> map = new HashMap<>();
list.forEach(map ->
map.forEach((key, value) ->
userDetailsMap.putIfAbsent(key.toLowerCase(), value)
)
);
Map<String, Object> map = new HashMap<>();
if (userDetailsMap.get("first_login") == null) {
map.put(JsonKey.ID, userId);
map.put(JsonKey.LAST_LOGIN, new Timestamp(Calendar.getInstance().getTime().getTime()));
Expand All @@ -757,18 +762,20 @@ public Response getUserLoggedInDetails(Request actorMessage) throws Exception {
requestMap.put(JsonKey.ID, map.get(JsonKey.ID));
requestMap.put(JsonKey.LAST_LOGIN, map.get(JsonKey.LAST_LOGIN));
requestMap.put(JsonKey.FIRST_LOGIN, map.get(JsonKey.FIRST_LOGIN));
dataMap.put("edata", requestMap);
requestMap.put(JsonKey.SELF_REGISTRATION, userDetailsMap.get(JsonKey.CREATEDBY) == null);
dataMap.put(JsonKey.EDATA, requestMap);
String topic = ProjectUtil.getConfigValue("kafka_user_first_login_event_topic");
InstructionEventGenerator.createFirstLoginDetailsEvent("", topic, dataMap);
} else {
map.put(JsonKey.ID, userId);
map.put(JsonKey.LAST_LOGIN, new Timestamp(Calendar.getInstance().getTime().getTime()));
cassandraOperation.upsertRecord(JsonKey.SUNBIRD, JsonKey.USER, map, actorMessage.getRequestContext());
map.put(JsonKey.FIRST_LOGIN,userDetailsMap.get("first_login"));
map.put(JsonKey.FIRST_LOGIN,userDetailsMap.get(JsonKey.FIRST_LOGIN));
}
response.put("first_login",map.get(JsonKey.FIRST_LOGIN));
response.put("last_login",map.get(JsonKey.LAST_LOGIN));
response.put("user_id",userId);
response.put(JsonKey.FIRST_LOGIN,map.get(JsonKey.FIRST_LOGIN));
response.put(JsonKey.LAST_LOGIN,map.get(JsonKey.LAST_LOGIN));
response.put(JsonKey.CONSENT_USER_ID,userId);
response.put(JsonKey.SELF_REGISTRATION,userDetailsMap.get(JsonKey.CREATEDBY) == null);
return response;
}
}
Loading