Skip to content

Commit

Permalink
mentorship changes from 4.8.16 dev (#7)
Browse files Browse the repository at this point in the history
* event added after user update for mentoring service (sunbird-cb#91)

* user search facets patch (sunbird-cb#70)

* 4.8.15 dev v1 (sunbird-cb#71)

* user search facets patch

* user search facets patch

* 4.8.15 dev v1 (sunbird-cb#72)

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* 4.8.15 dev v1 (sunbird-cb#73)

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* kafka topic after user profile update

* logger added

---------

Co-authored-by: anilkumarkammalapalli <[email protected]>

* mentoring topic data changes (sunbird-cb#92)

* user search facets patch (sunbird-cb#70)

* 4.8.15 dev v1 (sunbird-cb#71)

* user search facets patch

* user search facets patch

* 4.8.15 dev v1 (sunbird-cb#72)

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* 4.8.15 dev v1 (sunbird-cb#73)

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* kafka topic after user profile update

* logger added

* mentoring topic data updated

---------

Co-authored-by: anilkumarkammalapalli <[email protected]>

* added mentor roles (sunbird-cb#93)

* user search facets patch (sunbird-cb#70)

* 4.8.15 dev v1 (sunbird-cb#71)

* user search facets patch

* user search facets patch

* 4.8.15 dev v1 (sunbird-cb#72)

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* 4.8.15 dev v1 (sunbird-cb#73)

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* kafka topic after user profile update

* logger added

* mentoring topic data updated

* mentor roels added in user private read

* added constants

---------

Co-authored-by: anilkumarkammalapalli <[email protected]>

* added role section inside mentoring (sunbird-cb#94)

* user search facets patch (sunbird-cb#70)

* 4.8.15 dev v1 (sunbird-cb#71)

* user search facets patch

* user search facets patch

* 4.8.15 dev v1 (sunbird-cb#72)

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* 4.8.15 dev v1 (sunbird-cb#73)

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* kafka topic after user profile update

* logger added

* mentoring topic data updated

* mentor roels added in user private read

* added constants

* added role insied mentoring map

---------

Co-authored-by: anilkumarkammalapalli <[email protected]>

* bug fix for the v5 user read (sunbird-cb#95)

* user search facets patch (sunbird-cb#70)

* 4.8.15 dev v1 (sunbird-cb#71)

* user search facets patch

* user search facets patch

* 4.8.15 dev v1 (sunbird-cb#72)

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* 4.8.15 dev v1 (sunbird-cb#73)

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* user search facets patch

* kafka topic after user profile update

* logger added

* mentoring topic data updated

* mentor roels added in user private read

* added constants

* added role insied mentoring map

* bug fix for v5 user read

---------

Co-authored-by: anilkumarkammalapalli <[email protected]>

* handled roles from user_roles table for user lookup method

* handled roles from user_roles table for user lookup method (sunbird-cb#96)

* variable changed to roles insted of role

* changes for the portal client auth generation (sunbird-cb#98)

* 4.8.16 dev (sunbird-cb#99)

* changes for the portal client auth generation

* kafka event added after user role update for mentoring usage

* updated the pr as per review commments

---------

Co-authored-by: anilkumarkammalapalli <[email protected]>
Co-authored-by: Sahil-tarento <[email protected]>
  • Loading branch information
3 people authored Aug 19, 2024
1 parent d92255a commit 529f349
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,22 @@ private static String formEventData(Map<String, Object> data) {
}
return jsonMessage;
}

public static void mentorshipUserUpdateEvent(String key, String topic, Map<String, String> data) throws Exception {
String jsonMessage = null;
try {
jsonMessage = mapper.writeValueAsString(data);
} catch (Exception e) {
logger.error("Error creating JSON message: " + e.getMessage(), e);
}
if (StringUtils.isBlank(jsonMessage)) {
throw new ProjectCommonException(ResponseCode.valueOf("BE_JOB_REQUEST_EXCEPTION"), "mentorship user update Event is not generated properly.", ResponseCode.CLIENT_ERROR.getResponseCode());
}
if (StringUtils.isNotBlank(topic)) {
if (StringUtils.isNotBlank(key)) KafkaClient.send(key, jsonMessage, topic);
else KafkaClient.send(jsonMessage, topic);
} else {
throw new ProjectCommonException(ResponseCode.valueOf("BE_JOB_REQUEST_EXCEPTION"), "Invalid topic id.", ResponseCode.CLIENT_ERROR.getResponseCode());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -655,5 +655,8 @@ public final class JsonKey {
public static final String PHONE_CAPS = "Phone";
public static final String EMAIL_CAPS = "Email";
public static final String GCP = "GCP";
public static final String MENTORING_ROLES = "mentoring.roles";
public static final String MENTORING = "mentoring";
public static final String USERID= "userid";
private JsonKey() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ user_read_api_v2_non_mandatory_fields= profileDetails.employmentDetails.employee
kafka_user_first_login_event_topic= dev.user.first.login
otpValidationSecretKey=secretKey
otpExpirationTimeToken=300000
kafka_mentorship_user_update_topic=dev.mentorship.user.update
mentoring.roles=MENTOR

14 changes: 14 additions & 0 deletions service/src/main/java/org/sunbird/actor/role/UserRoleActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import akka.actor.ActorRef;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
Expand All @@ -11,6 +12,7 @@
import org.sunbird.actor.user.UserBaseActor;
import org.sunbird.exception.ProjectCommonException;
import org.sunbird.exception.ResponseCode;
import org.sunbird.kafka.InstructionEventGenerator;
import org.sunbird.keys.JsonKey;
import org.sunbird.operations.ActorOperations;
import org.sunbird.request.Request;
Expand All @@ -21,6 +23,7 @@
import org.sunbird.service.user.impl.UserRoleServiceImpl;
import org.sunbird.telemetry.dto.TelemetryEnvKey;
import org.sunbird.util.DataCacheHandler;
import org.sunbird.util.ProjectUtil;
import org.sunbird.util.PropertiesCache;
import org.sunbird.util.Util;

Expand Down Expand Up @@ -112,6 +115,17 @@ private void assignRoles(Request actorMessage) {
(String) requestMap.get(JsonKey.USER_ID),
userRolesList,
actorMessage.getRequestContext());
if (response.get(JsonKey.RESPONSE).equals(JsonKey.SUCCESS)) {
String topic = ProjectUtil.getConfigValue("kafka_mentorship_user_update_topic");
try {
HashMap<String,String> userDetails = new HashMap<>();
userDetails.put(JsonKey.USER_ID,(String) requestMap.get(JsonKey.USER_ID));
InstructionEventGenerator.mentorshipUserUpdateEvent("", topic, userDetails);
logger.info("kafka_mentorship_user_update_topic event pushed after role change");
}catch (Exception e){
logger.error("error while generating mentorship event :", e);
}
}
generateTelemetryEvent(
requestMap,
(String) requestMap.get(JsonKey.USER_ID),
Expand Down
10 changes: 10 additions & 0 deletions service/src/main/java/org/sunbird/actor/user/UserUpdateActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.error("error while generating mentorship event :", e);
}
}
generateUserTelemetry(
userMap, actorMessage, (String) userMap.get(JsonKey.USER_ID), JsonKey.UPDATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -211,8 +214,9 @@ 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);
List<String> ids = new ArrayList<>();
ids.add(value);
response = userDao.getUserPropertiesById(ids, fields, context);
} else {
Expand All @@ -227,9 +231,33 @@ record -> {
});
response = userDao.getUserPropertiesById(ids, fields, context);
}
for (Map<String, Object> userMap :
(List<Map<String, Object>>) response.getResult().get(JsonKey.RESPONSE)) {
UserUtility.decryptUserDataFrmES(userMap);

if (fields.contains(JsonKey.ROLES)) {
List<String> ids = ((List<Map<String, Object>>) response.getResult().get(JsonKey.RESPONSE)).stream()
.map(user -> (String) user.get(JsonKey.ID))
.collect(Collectors.toList());
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()
.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()
.forEach(user -> {
if (userRoleMap.containsKey((String) user.get(JsonKey.ID))) {
user.put(JsonKey.ROLES, userRoleMap.get((String) user.get(JsonKey.ID)));
}
UserUtility.decryptUserDataFrmES(user);
});
} else {
((List<Map<String, Object>>) response.getResult().get(JsonKey.RESPONSE)).stream()
.forEach(UserUtility::decryptUserDataFrmES);
}
return response;
}
Expand Down

0 comments on commit 529f349

Please sign in to comment.