-
Notifications
You must be signed in to change notification settings - Fork 11
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
4.8.16 dev #4
base: cbrelease-4.8.16
Are you sure you want to change the base?
4.8.16 dev #4
Changes from all commits
9b584ab
773b67e
9f4e088
e30a7e3
ae558fb
2a7c02c
445dda5
5a2b7f8
38fdfb1
f6fcad7
c033df0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import org.sunbird.dao.user.impl.UserSelfDeclarationDaoImpl; | ||
import org.sunbird.exception.ProjectCommonException; | ||
import org.sunbird.exception.ResponseCode; | ||
import org.sunbird.kafka.InstructionEventGenerator; | ||
import org.sunbird.keys.JsonKey; | ||
import org.sunbird.model.location.Location; | ||
import org.sunbird.model.user.User; | ||
|
@@ -293,6 +294,15 @@ private void updateUser(Request actorMessage) { | |
Map<String, Object> completeUserDetails = new HashMap<>(userDbRecord); | ||
completeUserDetails.putAll(requestMap); | ||
saveUserDetailsToEs(completeUserDetails, actorMessage.getRequestContext()); | ||
String topic = ProjectUtil.getConfigValue("kafka_mentorship_user_update_topic"); | ||
try { | ||
HashMap<String,String> userDetails = new HashMap<>(); | ||
userDetails.put(JsonKey.USER_ID,user.getUserId()); | ||
InstructionEventGenerator.mentorshipUserUpdateEvent("", topic, userDetails); | ||
logger.info("kafka_mentorship_user_update_topic event pushed"); | ||
}catch (Exception e){ | ||
logger.info("error while generating mentorship event"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error should give proper msg and it should be error |
||
} | ||
} | ||
generateUserTelemetry( | ||
userMap, actorMessage, (String) userMap.get(JsonKey.USER_ID), JsonKey.UPDATE); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,37 @@ public Response getUserProfileData(Request actorMessage) { | |
result.put(JsonKey.IDENTIFIER, userId); | ||
|
||
mapUserRoles(result); | ||
if(result.containsKey(JsonKey.ROLES) && CollectionUtils.isNotEmpty((Collection) result.get(JsonKey.ROLES))){ | ||
List<String> mentoringRoles = new ArrayList<>(); | ||
List<String> roles = new ArrayList<>(); | ||
if (result.get(JsonKey.ROLES) instanceof List) { | ||
List<?> list = (List<?>) result.get(JsonKey.ROLES); | ||
|
||
if (!list.isEmpty() && list.get(0) instanceof HashMap) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please handle null pointer and try to use collectionUtils as it handle the proper null pointer |
||
for (Object element : list) { | ||
HashMap<?, ?> hashmap = (HashMap<?, ?>) element; | ||
if (hashmap.containsKey(JsonKey.ROLE) && hashmap.get(JsonKey.ROLE) instanceof String) { | ||
roles.add((String) hashmap.get(JsonKey.ROLE)); | ||
} | ||
} | ||
} else if (!list.isEmpty() && list.get(0) instanceof String) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please handle null pointer and try to use collectionUtils as it handle the proper null pointer |
||
for (Object element : list) { | ||
roles.add((String) element); | ||
} | ||
} | ||
} | ||
List<String> mentorRoles = List.of(ProjectUtil.getConfigValue(JsonKey.MENTORING_ROLES).split(",")); | ||
for (String element : roles) { | ||
if (mentorRoles.contains(element)) { | ||
mentoringRoles.add(element); | ||
} | ||
} | ||
if (!mentoringRoles.isEmpty()){ | ||
Map<String, Object> mentorObj = new HashMap<>(); | ||
mentorObj.put(JsonKey.ROLES,mentoringRoles); | ||
result.put(JsonKey.MENTORING,mentorObj); | ||
} | ||
} | ||
|
||
// Record the start time for measuring the execution time. | ||
long startTime = System.currentTimeMillis(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import org.apache.commons.collections.MapUtils; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.sunbird.cassandra.CassandraOperation; | ||
import org.sunbird.common.ElasticSearchHelper; | ||
import org.sunbird.dao.user.UserDao; | ||
import org.sunbird.dao.user.UserLookupDao; | ||
|
@@ -22,6 +23,7 @@ | |
import org.sunbird.dto.SearchDTO; | ||
import org.sunbird.exception.ProjectCommonException; | ||
import org.sunbird.exception.ResponseCode; | ||
import org.sunbird.helper.ServiceFactory; | ||
import org.sunbird.keys.JsonKey; | ||
import org.sunbird.logging.LoggerUtil; | ||
import org.sunbird.model.adminutil.AdminUtilRequestData; | ||
|
@@ -55,6 +57,7 @@ public class UserServiceImpl implements UserService { | |
private final OrgService orgService = OrgServiceImpl.getInstance(); | ||
private final UserRoleService userRoleService = UserRoleServiceImpl.getInstance(); | ||
private final ObjectMapper mapper = new ObjectMapper(); | ||
private final CassandraOperation cassandraOperation = ServiceFactory.getInstance(); | ||
|
||
public static UserService getInstance() { | ||
if (userService == null) { | ||
|
@@ -211,6 +214,7 @@ public List<Map<String, Object>> searchUserNameInUserLookup( | |
public Response userLookUpByKey( | ||
String key, String value, List<String> fields, RequestContext context) { | ||
Response response; | ||
Map<String, List<String>> userRoleMap = new HashMap<>(); | ||
if (JsonKey.ID.equalsIgnoreCase(key)) { | ||
List<String> ids = new ArrayList<>(2); | ||
ids.add(value); | ||
|
@@ -226,6 +230,28 @@ record -> { | |
ids.add((String) record.get(JsonKey.USER_ID)); | ||
}); | ||
response = userDao.getUserPropertiesById(ids, fields, context); | ||
if (fields.contains(JsonKey.ROLES)) { | ||
Response cassandraResponse = cassandraOperation.getRecordsByProperties( | ||
JsonKey.SUNBIRD, JsonKey.USER_ROLES, | ||
Collections.singletonMap(JsonKey.USERID, ids), | ||
Arrays.asList(JsonKey.ROLE, JsonKey.USERID), context); | ||
|
||
((List<Map<String, Object>>) cassandraResponse.getResult().get(JsonKey.RESPONSE)).stream() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plead do formatting |
||
.filter(userRole -> userRole.get(JsonKey.ROLE) != null && !((String) userRole.get(JsonKey.ROLE)).isEmpty()) | ||
.forEach(userRole -> | ||
userRoleMap.computeIfAbsent((String) userRole.get(JsonKey.USER_ID), k -> new ArrayList<>()) | ||
.add((String) userRole.get(JsonKey.ROLE)) | ||
); | ||
|
||
((List<Map<String, Object>>) response.getResult().get(JsonKey.RESPONSE)).stream() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why you do typecast of not assign to any variable |
||
.forEach(user -> { | ||
if (userRoleMap.containsKey((String) user.get(JsonKey.ID))) { | ||
user.put(JsonKey.ROLES, userRoleMap.get((String) user.get(JsonKey.ID))); | ||
} | ||
UserUtility.decryptUserDataFrmES(user); | ||
}); | ||
} | ||
return response; | ||
} | ||
for (Map<String, Object> userMap : | ||
(List<Map<String, Object>>) response.getResult().get(JsonKey.RESPONSE)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do formatting