From af4acf6dc8660e7fb6a852ceb34e4d4857b939f5 Mon Sep 17 00:00:00 2001 From: niharikasingh84 Date: Fri, 12 Jul 2019 15:57:02 +0530 Subject: [PATCH] Changes for validatementors method for handling multiple calls to User/Org APIs --- .../CourseBatchManagementActor.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/actors/sunbird-lms-mw/actors/common/src/main/java/org/sunbird/learner/actors/coursebatch/CourseBatchManagementActor.java b/actors/sunbird-lms-mw/actors/common/src/main/java/org/sunbird/learner/actors/coursebatch/CourseBatchManagementActor.java index 78a865a8dc..2491b602b9 100644 --- a/actors/sunbird-lms-mw/actors/common/src/main/java/org/sunbird/learner/actors/coursebatch/CourseBatchManagementActor.java +++ b/actors/sunbird-lms-mw/actors/common/src/main/java/org/sunbird/learner/actors/coursebatch/CourseBatchManagementActor.java @@ -18,6 +18,7 @@ import org.apache.commons.lang3.StringUtils; import org.sunbird.actor.core.BaseActor; import org.sunbird.actor.router.ActorConfig; +import java.util.stream.Collectors; import org.sunbird.common.ElasticSearchHelper; import org.sunbird.common.exception.ProjectCommonException; import org.sunbird.common.factory.EsClientFactory; @@ -500,27 +501,31 @@ private void validateMentors(CourseBatch courseBatch) { List mentors = courseBatch.getMentors(); if (CollectionUtils.isNotEmpty(mentors)) { String batchCreatorRootOrgId = getRootOrg(courseBatch.getCreatedBy()); - + List> mentorDetailList = userOrgService.getUsersByIds(mentors); + Map> mentorDetails = + mentorDetailList + .stream() + .collect(Collectors.toMap(map -> (String) map.get(JsonKey.ID), map -> map)); for (String userId : mentors) { - Map result = userOrgService.getUserById(userId); - String mentorRootOrgId = getRootOrg(userId); + Map result = mentorDetails.get(userId); + String mentorRootOrgId = getRootOrgFromUserMap(result); if (!batchCreatorRootOrgId.equals(mentorRootOrgId)) { throw new ProjectCommonException( - ResponseCode.userNotAssociatedToRootOrg.getErrorCode(), - ResponseCode.userNotAssociatedToRootOrg.getErrorMessage(), - ResponseCode.CLIENT_ERROR.getResponseCode(), - userId); + ResponseCode.userNotAssociatedToRootOrg.getErrorCode(), + ResponseCode.userNotAssociatedToRootOrg.getErrorMessage(), + ResponseCode.CLIENT_ERROR.getResponseCode(), + userId); } if ((ProjectUtil.isNull(result)) - || (ProjectUtil.isNotNull(result) && result.isEmpty()) - || (ProjectUtil.isNotNull(result) + || (ProjectUtil.isNotNull(result) && result.isEmpty()) + || (ProjectUtil.isNotNull(result) && result.containsKey(JsonKey.IS_DELETED) && ProjectUtil.isNotNull(result.get(JsonKey.IS_DELETED)) && (Boolean) result.get(JsonKey.IS_DELETED))) { throw new ProjectCommonException( - ResponseCode.invalidUserId.getErrorCode(), - ResponseCode.invalidUserId.getErrorMessage(), - ResponseCode.CLIENT_ERROR.getResponseCode()); + ResponseCode.invalidUserId.getErrorCode(), + ResponseCode.invalidUserId.getErrorMessage(), + ResponseCode.CLIENT_ERROR.getResponseCode()); } } }