From dc24217892146b12efe0a3b47297201244d7b63c Mon Sep 17 00:00:00 2001 From: Karthikeyan Rajendran <70887864+karthik-tarento@users.noreply.github.com> Date: Thu, 27 Jul 2023 15:11:10 +0530 Subject: [PATCH 1/8] Dev 4.8.4 (#266) * changes for group * group list (#258) * group list * Fix for batch read API response * group validation (#261) * Fixed issue in tag validation for bulk upload --------- Co-authored-by: Juhi Co-authored-by: Manas-tarento <107806230+Manas-tarento@users.noreply.github.com> --- .../CassandraConnectionManagerImpl.java | 2 +- .../common/util/CbExtServerProperties.java | 11 ++++++++++ .../org/sunbird/common/util/Constants.java | 2 ++ .../org/sunbird/common/util/ProjectUtil.java | 21 ++++++------------- .../profile/controller/ProfileController.java | 6 ++++++ .../profile/service/ProfileService.java | 2 ++ .../profile/service/ProfileServiceImpl.java | 14 +++++++++++++ .../service/UserBulkUploadService.java | 5 ++++- .../service/UserRegistrationServiceImpl.java | 10 +++++++-- 9 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/sunbird/common/helper/cassandra/CassandraConnectionManagerImpl.java b/src/main/java/org/sunbird/common/helper/cassandra/CassandraConnectionManagerImpl.java index a652e4d2b..1436bdff3 100644 --- a/src/main/java/org/sunbird/common/helper/cassandra/CassandraConnectionManagerImpl.java +++ b/src/main/java/org/sunbird/common/helper/cassandra/CassandraConnectionManagerImpl.java @@ -108,7 +108,7 @@ private static Cluster createCluster(String[] hosts, PoolingOptions poolingOptio } private static ConsistencyLevel getConsistencyLevel() { - String consistency = ProjectUtil.getConfigValue(Constants.SUNBIRD_CASSANDRA_CONSISTENCY_LEVEL); + String consistency = PropertiesCache.getInstance().readProperty(Constants.SUNBIRD_CASSANDRA_CONSISTENCY_LEVEL); logger.info("CassandraConnectionManagerImpl:getConsistencyLevel: level = " + consistency); diff --git a/src/main/java/org/sunbird/common/util/CbExtServerProperties.java b/src/main/java/org/sunbird/common/util/CbExtServerProperties.java index c943e227a..7bb3e6302 100644 --- a/src/main/java/org/sunbird/common/util/CbExtServerProperties.java +++ b/src/main/java/org/sunbird/common/util/CbExtServerProperties.java @@ -467,6 +467,9 @@ public class CbExtServerProperties { @Value("${assessment.ratake.count.verification.enabled}") private boolean assessmentRetakeCountVerificationEnabled; + @Value("${bulk.upload.tag.verification.regex}") + private String bulkUploadTagVerificationRegex; + public String getAssessmentSubmitTopic() { return assessmentSubmitTopic; } @@ -1705,4 +1708,12 @@ public boolean isAssessmentRetakeCountVerificationEnabled() { public void setAssessmentRetakeCountVerificationEnabled(boolean assessmentRetakeCountVerificationEnabled) { this.assessmentRetakeCountVerificationEnabled = assessmentRetakeCountVerificationEnabled; } + + public String getBulkUploadTagVerificationRegex() { + return bulkUploadTagVerificationRegex; + } + + public void setBulkUploadTagVerificationRegex(String bulkUploadTagVerificationRegex) { + this.bulkUploadTagVerificationRegex = bulkUploadTagVerificationRegex; + } } \ No newline at end of file diff --git a/src/main/java/org/sunbird/common/util/Constants.java b/src/main/java/org/sunbird/common/util/Constants.java index a4b8784b6..bfe7cd917 100644 --- a/src/main/java/org/sunbird/common/util/Constants.java +++ b/src/main/java/org/sunbird/common/util/Constants.java @@ -681,6 +681,7 @@ public class Constants { public static final String BULK_USER_UPDATE_API_FAILED = "Bulk User Update API Failed"; public static final String SECURE_SETTINGS = "secureSettings"; public static final String API_USER_ENROLMENT = "user.enrolment"; + public static final String USER_REGISTRATION_GROUP_LIST = "api.user.registration.group.list"; public static final String SUBMIT_ASSESSMENT_RESPONSE_KEY = "submitAssessmentResponse"; public static final String API_READ_ASSESSMENT = "api.assessment.read"; public static final String API_READ_ASSESSMENT_RESULT = "api.assessment.read.result"; @@ -688,6 +689,7 @@ public class Constants { public static final String ASSESSMENT_SUBMIT_IN_PROGRESS = "SUBMIT_IN_PROGRESS"; public static final String ASSESSMENT_READ_RESPONSE_KEY = "assessmentReadResponse"; public static final String START_TIME_KEY = "startTime"; + public static final String BULK_UPLOAD_VERIFICATION_REGEX = "bulk.upload.tag.verification.regex"; private Constants() { throw new IllegalStateException("Utility class"); diff --git a/src/main/java/org/sunbird/common/util/ProjectUtil.java b/src/main/java/org/sunbird/common/util/ProjectUtil.java index 137610109..5d0153380 100644 --- a/src/main/java/org/sunbird/common/util/ProjectUtil.java +++ b/src/main/java/org/sunbird/common/util/ProjectUtil.java @@ -24,19 +24,7 @@ public class ProjectUtil { public static CbExtLogger logger = new CbExtLogger(ProjectUtil.class.getName()); - - public static PropertiesCache propertiesCache; - - static { - propertiesCache = PropertiesCache.getInstance(); - } - - public static String getConfigValue(String key) { - if (StringUtils.isNotBlank(System.getenv(key))) { - return System.getenv(key); - } - return propertiesCache.readProperty(key); - } + public static String DEFAULT_BULK_UPLOAD_VERIFICATION_REGEX = "^[a-zA-Z\\s,]+$"; /** * This method will check incoming value is null or empty it will do empty check @@ -119,7 +107,6 @@ public static String firstLetterCapitalWithSingleSpace(final String words) { public static Boolean validateEmailPattern(String email) { String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\." + "[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+\\.)+[a-z" + "A-Z]{2,7}$"; - Boolean retValue = Boolean.FALSE; Pattern pat = Pattern.compile(emailRegex); if (pat.matcher(email).matches()) { return Boolean.TRUE; @@ -148,8 +135,12 @@ public static Boolean validateFullName(String firstName ) { } public static Boolean validateTag(List tags) { + String regEx = PropertiesCache.getInstance().getProperty(Constants.BULK_UPLOAD_VERIFICATION_REGEX); + if (StringUtils.isBlank(regEx)) { + regEx = DEFAULT_BULK_UPLOAD_VERIFICATION_REGEX; + } for (String tag : tags) { - if (!tag.matches("^[a-zA-Z]+(?: [a-zA-Z]+)*$")) { + if (!tag.matches(regEx)) { return false; } } diff --git a/src/main/java/org/sunbird/profile/controller/ProfileController.java b/src/main/java/org/sunbird/profile/controller/ProfileController.java index bb6525a22..15cf0486f 100644 --- a/src/main/java/org/sunbird/profile/controller/ProfileController.java +++ b/src/main/java/org/sunbird/profile/controller/ProfileController.java @@ -107,4 +107,10 @@ public ResponseEntity generateUserReport() { public ResponseEntity downloadFile(@PathVariable("fileName") String fileName) { return profileService.downloadFile(fileName); } + + @GetMapping("/user/v1/groups") + public ResponseEntity getGroupList() throws Exception { + SBApiResponse response = profileService.getGroupList(); + return new ResponseEntity<>(response, response.getResponseCode()); + } } diff --git a/src/main/java/org/sunbird/profile/service/ProfileService.java b/src/main/java/org/sunbird/profile/service/ProfileService.java index ef3ba2bdf..605d59035 100644 --- a/src/main/java/org/sunbird/profile/service/ProfileService.java +++ b/src/main/java/org/sunbird/profile/service/ProfileService.java @@ -33,4 +33,6 @@ public interface ProfileService { SBApiResponse getUserReport(); ResponseEntity downloadFile(String fileName); + + SBApiResponse getGroupList(); } diff --git a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java index c35231b5c..679f9fe37 100644 --- a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java +++ b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java @@ -1582,4 +1582,18 @@ public ResponseEntity downloadFile(String fileName) { } } } + + @Override + public SBApiResponse getGroupList() { + SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.USER_REGISTRATION_GROUP_LIST); + List groupList = serverConfig.getBulkUploadGroupValue(); + if (CollectionUtils.isNotEmpty(groupList)) { + response.getResult().put(Constants.COUNT, groupList.size()); + response.getResult().put(Constants.RESPONSE, groupList); + } else { + response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR); + response.getParams().setStatus(Constants.FAILED); + } + return response; + } } diff --git a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java index 93d385e02..94812ff88 100644 --- a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java +++ b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java @@ -188,7 +188,10 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx String tagStr = nextRow.getCell(4).getStringCellValue().trim(); List tagList = new ArrayList(); if (!StringUtils.isEmpty(tagStr)) { - tagList = Arrays.asList(tagStr.split(",", -1)); + String[] tagStrList = tagStr.split(",", -1); + for(String tag : tagStrList) { + tagList.add(tag.trim()); + } } userRegistration.setTag(tagList); if (!ProjectUtil.validateTag(userRegistration.getTag())) { diff --git a/src/main/java/org/sunbird/user/registration/service/UserRegistrationServiceImpl.java b/src/main/java/org/sunbird/user/registration/service/UserRegistrationServiceImpl.java index d5f9f5f08..7277e128a 100644 --- a/src/main/java/org/sunbird/user/registration/service/UserRegistrationServiceImpl.java +++ b/src/main/java/org/sunbird/user/registration/service/UserRegistrationServiceImpl.java @@ -281,8 +281,8 @@ private String validateRegisterationPayload(UserRegistrationInfo userRegInfo) { if (StringUtils.isBlank(userRegInfo.getOrgName())) { errList.add("OrgName"); } - if (StringUtils.isBlank(userRegInfo.getPosition())) { - errList.add("Position"); + if (StringUtils.isBlank(userRegInfo.getGroup())) { + errList.add("group"); } if (StringUtils.isBlank(userRegInfo.getSource())) { errList.add("Source"); @@ -302,6 +302,11 @@ private String validateRegisterationPayload(UserRegistrationInfo userRegInfo) { str.setLength(0); str.append("Invalid phone number"); } + //group validation + if (StringUtils.isNotBlank(userRegInfo.getGroup()) && !serverProperties.getBulkUploadGroupValue().contains(userRegInfo.getGroup())) { + str.setLength(0); + str.append("Invalid Group : Group can be only among one of these ").append(serverProperties.getBulkUploadGroupValue()); + } return str.toString(); } @@ -331,6 +336,7 @@ private UserRegistration getRegistrationObject(UserRegistrationInfo userRegInfo) userRegistration.setOrganisationType(userRegInfo.getOrganisationType()); userRegistration.setOrganisationSubType(userRegInfo.getOrganisationSubType()); userRegistration.setPhone(userRegInfo.getPhone()); + userRegistration.setGroup(userRegInfo.getGroup()); if (StringUtils.isBlank(userRegInfo.getRegistrationCode())) { userRegistration.setRegistrationCode(serverProperties.getUserRegCodePrefix() + "-" From defe7f165a989ef98befdaba514d1f81c38e8e8c Mon Sep 17 00:00:00 2001 From: SaipradeepR <53404427+SaipradeepR@users.noreply.github.com> Date: Thu, 27 Jul 2023 16:24:21 +0530 Subject: [PATCH 2/8] =?UTF-8?q?Removed=20Position=20as=20mandatory=20param?= =?UTF-8?q?=20&=20added=20Group=20as=20mandatory=20param=20=E2=80=A6=20(#2?= =?UTF-8?q?65)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * changes for group --- .../java/org/sunbird/profile/service/ProfileServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java index 679f9fe37..e3de1f75f 100644 --- a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java +++ b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java @@ -873,7 +873,7 @@ private String validateBasicProfilePayload(Map requestObj) { errList.add(Constants.REQUEST); } else { Map request = (Map) requestObj.get(Constants.REQUEST); - List keys = Arrays.asList(Constants.USER_ID, Constants.POSITION, Constants.CHANNEL, + List keys = Arrays.asList(Constants.USER_ID, Constants.GROUP, Constants.CHANNEL, Constants.MAP_ID, Constants.ORGANIZATION_TYPE, Constants.ORGANIZATION_SUB_TYPE); for (String key : keys) { if (StringUtils.isBlank((String) request.get(key))) { @@ -1004,7 +1004,7 @@ private String updateUserProfile(Map request) { }; existingProfile.put(Constants.PROFESSIONAL_DETAILS, professionalDetails); } - professionalDetails.get(0).put(Constants.DESIGNATION, request.get(Constants.POSITION)); + professionalDetails.get(0).put(Constants.GROUP, request.get(Constants.GROUP)); professionalDetails.get(0).put(Constants.ORGANIZATION_TYPE, Constants.GOVERNMENT); Map empDetails; From 0b0f6ac2583f4890d18408a7bb1f720d4c40c457 Mon Sep 17 00:00:00 2001 From: karthik-tarento Date: Thu, 3 Aug 2023 14:34:32 +0530 Subject: [PATCH 3/8] Added the property for TAG validation --- src/main/resources/application.properties | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 237cb8bd4..31de382d6 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -295,4 +295,6 @@ assessment.user.submit.data.table=user_assessment_data kafka.topics.user.assessment.async.submit.handler=dev.assessment.async.submit.handler kafka.topics.user.assessment.async.submit.handler.group=assessmentAsyncSubmitHandlerGroup -assessment.ratake.count.verification.enabled=true \ No newline at end of file +assessment.ratake.count.verification.enabled=true + +bulk.upload.tag.verification.regex=^[a-zA-Z\\s,]+$ \ No newline at end of file From f86e18fe2c936c16f987f3e57610e68c72db955b Mon Sep 17 00:00:00 2001 From: karthik-tarento Date: Thu, 3 Aug 2023 14:51:31 +0530 Subject: [PATCH 4/8] Profile Update fix --- .../java/org/sunbird/profile/service/ProfileServiceImpl.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java index 09ce6e7a4..27c83a3cb 100644 --- a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java +++ b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java @@ -144,9 +144,6 @@ public SBApiResponse profileUpdate(Map request, String userToken for (String keys : profileDetailsMap.keySet()) { listOfChangedDetails.add(keys); } - if (listOfChangedDetails.contains(Constants.EMPLOYMENTDETAILS)) { - listOfChangedDetails.remove(Constants.EMPLOYMENTDETAILS); - } for (String changedObj : listOfChangedDetails) { if (profileDetailsMap.get(changedObj) instanceof ArrayList) { existingProfileDetails.put(changedObj, profileDetailsMap.get(changedObj)); From 9ffb7698434e5790f5e6850e13ea43377a97813f Mon Sep 17 00:00:00 2001 From: karthik-tarento Date: Thu, 10 Aug 2023 12:39:05 +0530 Subject: [PATCH 5/8] Added API for rating to fetch with list of user ids. Optimized other rating APIs. --- .../org/sunbird/common/util/Constants.java | 6 +- .../ratings/controller/RatingsController.java | 20 ++- .../ratings/model/LookupDataModel.java | 44 +++---- .../ratings/service/RatingService.java | 4 + .../ratings/service/RatingServiceImpl.java | 122 ++++++++++++++---- .../resources/cassandratablecolumn.properties | 6 + 6 files changed, 145 insertions(+), 57 deletions(-) diff --git a/src/main/java/org/sunbird/common/util/Constants.java b/src/main/java/org/sunbird/common/util/Constants.java index 7db1001fa..b0ee74371 100644 --- a/src/main/java/org/sunbird/common/util/Constants.java +++ b/src/main/java/org/sunbird/common/util/Constants.java @@ -169,11 +169,11 @@ public class Constants { public static final String USERID = "id"; public static final String COMMENT = "comment"; public static final String COMMENT_BY = "commentBy"; - public static final String COMMENT_UPDATED_ON = "commentupdatedon"; - public static final String CREATED_ON = "createdon"; + public static final String COMMENT_UPDATED_ON = "commentUpdatedOn"; + public static final String CREATED_ON = "createdOn"; public static final String RATING = "rating"; public static final String REVIEW = "review"; - public static final String UPDATED_ON = "updatedon"; + public static final String UPDATED_ON = "updatedOn"; public static final String LATEST50REVIEWS = "latest50reviews"; public static final String SUMMARY_ACTIVITY_ID = "activityid"; public static final String SUMMARY_ACTIVITY_TYPE = "activitytype"; diff --git a/src/main/java/org/sunbird/ratings/controller/RatingsController.java b/src/main/java/org/sunbird/ratings/controller/RatingsController.java index 7d04ccf60..da32fa351 100644 --- a/src/main/java/org/sunbird/ratings/controller/RatingsController.java +++ b/src/main/java/org/sunbird/ratings/controller/RatingsController.java @@ -1,15 +1,21 @@ package org.sunbird.ratings.controller; +import java.util.Map; + +import javax.validation.Valid; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; import org.sunbird.common.model.SBApiResponse; import org.sunbird.ratings.model.LookupRequest; import org.sunbird.ratings.model.RequestRating; import org.sunbird.ratings.service.RatingService; -import javax.validation.Valid; - @RestController public class RatingsController { @@ -22,7 +28,6 @@ public class RatingsController { public ResponseEntity upsertRating(@Valid @RequestBody RequestRating requestRatingBody) { SBApiResponse response = ratingService.upsertRating(requestRatingBody); return new ResponseEntity<>(response, response.getResponseCode()); - } @GetMapping("/ratings/v1/read/{activityId}/{activityType}/{userId}") @@ -31,7 +36,6 @@ public ResponseEntity getRating(@PathVariable("activityId") String activityId @PathVariable("userId") String userId) { SBApiResponse response = ratingService.getRatings(activityId, activityType, userId); return new ResponseEntity<>(response, response.getResponseCode()); - } @GetMapping("/ratings/v1/summary/{activityId}/{activityType}") @@ -46,5 +50,11 @@ public ResponseEntity ratingLookUp(@RequestBody LookupRequest request) { SBApiResponse response = ratingService.ratingLookUp(request); return new ResponseEntity<>(response, response.getResponseCode()); } + + @PostMapping("/ratings/v1/read") + public ResponseEntity readRating(@RequestBody Map request) { + SBApiResponse response = ratingService.readRatings(request); + return new ResponseEntity<>(response, response.getResponseCode()); + } } diff --git a/src/main/java/org/sunbird/ratings/model/LookupDataModel.java b/src/main/java/org/sunbird/ratings/model/LookupDataModel.java index 9e4214e3c..5d39539b5 100644 --- a/src/main/java/org/sunbird/ratings/model/LookupDataModel.java +++ b/src/main/java/org/sunbird/ratings/model/LookupDataModel.java @@ -3,32 +3,32 @@ import java.util.UUID; public class LookupDataModel { - private String activityid; + private String activityId; private String review; private Float rating; - private String updatedon; - private String activitytype; + private String updatedOn; + private String activityType; private String userId; public LookupDataModel() { } - public LookupDataModel(String activityid, String review, Float rating, UUID updatedon, String activitytype, String userId) { - this.activityid = activityid; + public LookupDataModel(String activityId, String review, Float rating, UUID updatedOn, String activityType, String userId) { + this.activityId = activityId; this.review = review; this.rating = rating; - this.updatedon = updatedon.toString(); - this.activitytype = activitytype; + this.updatedOn = updatedOn.toString(); + this.activityType = activityType; this.userId = userId; } - public String getActivityid() { - return activityid; + public String getActivityId() { + return activityId; } - public void setActivityid(String activityid) { - this.activityid = activityid; + public void setActivityId(String activityId) { + this.activityId = activityId; } public String getReview() { @@ -48,20 +48,20 @@ public void setRating(Float rating) { } - public String getUpdatedon() { - return updatedon; + public String getUpdatedOn() { + return updatedOn; } - public void setUpdatedon(UUID updatedon) { - this.updatedon = updatedon.toString(); + public void setUpdatedon(UUID updatedOn) { + this.updatedOn = updatedOn.toString(); } - public String getActivitytype() { - return activitytype; + public String getActivityType() { + return activityType; } - public void setActivitytype(String activitytype) { - this.activitytype = activitytype; + public void setActivitytype(String activityType) { + this.activityType = activityType; } public String getUserId() { @@ -75,11 +75,11 @@ public void setUserId(String userId) { @Override public String toString() { return "LookupDataModel{" + - "activityid='" + activityid + '\'' + + "activityId='" + activityId + '\'' + ", review='" + review + '\'' + ", rating=" + rating + - ", updatedon='" + updatedon + '\'' + - ", activitytype='" + activitytype + '\'' + + ", updatedOn='" + updatedOn + '\'' + + ", activityType='" + activityType + '\'' + ", userId='" + userId + '\'' + '}'; } diff --git a/src/main/java/org/sunbird/ratings/service/RatingService.java b/src/main/java/org/sunbird/ratings/service/RatingService.java index c2bfe5ad6..cdbabfa9e 100644 --- a/src/main/java/org/sunbird/ratings/service/RatingService.java +++ b/src/main/java/org/sunbird/ratings/service/RatingService.java @@ -1,5 +1,7 @@ package org.sunbird.ratings.service; +import java.util.Map; + import org.sunbird.common.model.SBApiResponse; import org.sunbird.ratings.model.LookupRequest; import org.sunbird.ratings.model.RequestRating; @@ -12,4 +14,6 @@ public interface RatingService { public SBApiResponse getRatingSummary(String activityId, String activityType); public SBApiResponse ratingLookUp(LookupRequest request); + + public SBApiResponse readRatings(Map request); } diff --git a/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java b/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java index 235baa9de..c697773f2 100644 --- a/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java +++ b/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java @@ -10,9 +10,11 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import org.sunbird.cassandra.utils.CassandraOperation; import org.sunbird.common.model.SBApiResponse; import org.sunbird.common.util.Constants; +import org.sunbird.common.util.ProjectUtil; import org.sunbird.core.logger.CbExtLogger; import org.sunbird.core.producer.Producer; import org.sunbird.ratings.exception.ValidationException; @@ -57,29 +59,29 @@ public SBApiResponse getRatings(String activityId, String activityType, String u request.put(Constants.ACTIVITY_ID, activityId); request.put(Constants.ACTIVITY_TYPE, activityType); request.put(Constants.RATINGS_USER_ID, userId); - List> existingDataList = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD, + List> existingDataList = cassandraOperation.getRecordsByPropertiesWithoutFiltering(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_RATINGS, request, null); if (!CollectionUtils.isEmpty(existingDataList)) { Map ratingData = existingDataList.get(0); RatingModelInfo ratingModelInfo = new RatingModelInfo(); - ratingModelInfo.setActivityId((String) ratingData.get("activityid")); - ratingModelInfo.setReview((String) ratingData.get("review")); - ratingModelInfo.setRating((Float) ratingData.get("rating")); - ratingModelInfo.setComment(ratingData.get("comment")!=null ?(String) ratingData.get("comment") : null); - ratingModelInfo.setCommentBy(ratingData.get("commentby")!=null ?(String) ratingData.get("commentby") : null); - - if(ratingData.get("commentupdatedon")!=null){ - UUID commentupdatedOn = (UUID) ratingData.get("commentupdatedon"); + ratingModelInfo.setActivityId((String) ratingData.get(Constants.ACTIVITY_ID)); + ratingModelInfo.setReview((String) ratingData.get(Constants.REVIEW)); + ratingModelInfo.setRating((Float) ratingData.get(Constants.RATING)); + ratingModelInfo.setComment(ratingData.get(Constants.COMMENT)!=null ?(String) ratingData.get(Constants.COMMENT) : null); + ratingModelInfo.setCommentBy(ratingData.get(Constants.COMMENT_BY)!=null ?(String) ratingData.get(Constants.COMMENT_BY) : null); + + if(ratingData.get(Constants.COMMENT_UPDATED_ON)!=null){ + UUID commentupdatedOn = (UUID) ratingData.get(Constants.COMMENT_UPDATED_ON); Long CommentUpdatedTime = (commentupdatedOn.timestamp() - 0x01b21dd213814000L) / 10000L; ratingModelInfo.setCommentUpdatedOn(new Timestamp(CommentUpdatedTime)); } - timeBasedUuid = (UUID) ratingData.get("updatedon"); + timeBasedUuid = (UUID) ratingData.get(Constants.UPDATED_ON); Long updatedTime = (timeBasedUuid.timestamp() - 0x01b21dd213814000L) / 10000L; ratingModelInfo.setUpdatedOn(new Timestamp(updatedTime)); - ratingModelInfo.setActivityType((String) ratingData.get("activitytype")); - ratingModelInfo.setUserId((String) ratingData.get("userId")); - timeBasedUuid = (UUID) ratingData.get("createdon"); + ratingModelInfo.setActivityType((String) ratingData.get(Constants.ACTIVITY_TYPE)); + ratingModelInfo.setUserId((String) ratingData.get(Constants.USER_ID)); + timeBasedUuid = (UUID) ratingData.get(Constants.CREATED_ON); Long createdTime = (timeBasedUuid.timestamp() - 0x01b21dd213814000L) / 10000L; ratingModelInfo.setCreatedOn(new Timestamp(createdTime)); response.put(Constants.MESSAGE, Constants.SUCCESSFUL); @@ -111,7 +113,7 @@ public SBApiResponse getRatingSummary(String activityId, String activityType) { request.put(Constants.ACTIVITY_ID, activityId); request.put(Constants.ACTIVITY_TYPE, activityType); - List> existingDataList = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD, + List> existingDataList = cassandraOperation.getRecordsByPropertiesWithoutFiltering(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_RATINGS_SUMMARY, request, null); if (!CollectionUtils.isEmpty(existingDataList)) { @@ -135,7 +137,7 @@ public SBApiResponse getRatingSummary(String activityId, String activityType) { fields.add(Constants.ID); fields.add(Constants.FIRSTNAME); - Map existingUserList = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD, + Map existingUserList = cassandraOperation.getRecordsByPropertiesWithoutFiltering(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_USER, userRequest, fields, Constants.ID); for (String user : userList) { @@ -154,8 +156,8 @@ public SBApiResponse getRatingSummary(String activityId, String activityType) { } } SummaryModel summaryModel = new SummaryModel( - summaryData.get(Constants.SUMMARY_ACTIVITY_ID).toString(), - summaryData.get(Constants.SUMMARY_ACTIVITY_TYPE).toString(), + summaryData.get(Constants.ACTIVITY_ID).toString(), + summaryData.get(Constants.ACTIVITY_TYPE).toString(), (Float) summaryData.get(Constants.TOTALCOUNT1STARS), (Float) summaryData.get(Constants.TOTALCOUNT2STARS), (Float) summaryData.get(Constants.TOTALCOUNT3STARS), @@ -198,7 +200,7 @@ public SBApiResponse upsertRating(RequestRating requestRating) { request.put(Constants.RATINGS_USER_ID, requestRating.getUserId()); - List> existingDataList = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD, + List> existingDataList = cassandraOperation.getRecordsByPropertiesWithoutFiltering(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_RATINGS, request, null); if (!CollectionUtils.isEmpty(existingDataList)) { @@ -218,10 +220,10 @@ public SBApiResponse upsertRating(RequestRating requestRating) { cassandraOperation.updateRecord(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_RATINGS, updateRequest, request); ratingMessage = new RatingMessage("ratingUpdate", requestRating.getActivityId(), requestRating.getActivityType(), - requestRating.getUserId(), String.valueOf((prevInfo.get("createdon")))); + requestRating.getUserId(), String.valueOf((prevInfo.get(Constants.CREATED_ON)))); - ratingMessage.setPrevValues(processEventMessage(String.valueOf(prevInfo.get("updatedon")), - (Float) prevInfo.get("rating"), (String) prevInfo.get("review"))); + ratingMessage.setPrevValues(processEventMessage(String.valueOf(prevInfo.get(Constants.UPDATED_ON)), + (Float) prevInfo.get(Constants.RATING), (String) prevInfo.get(Constants.REVIEW))); ratingMessage.setUpdatedValues(processEventMessage(String.valueOf(updateRequest.get(Constants.UPDATED_ON)), requestRating.getRating(), requestRating.getReview())); } else { @@ -286,7 +288,7 @@ public SBApiResponse ratingLookUp(LookupRequest lookupRequest) { } Map existingDataList = cassandraOperation.getRecordsByPropertiesWithPagination(Constants.KEYSPACE_SUNBIRD, - Constants.TABLE_RATINGS_LOOKUP, request, null, lookupRequest.getLimit(), uuid, "userId"); + Constants.TABLE_RATINGS_LOOKUP, request, null, lookupRequest.getLimit(), uuid, Constants.USER_ID); List listOfLookupResponse = new ArrayList<>(); if (!CollectionUtils.isEmpty(existingDataList)) { @@ -301,20 +303,20 @@ public SBApiResponse ratingLookUp(LookupRequest lookupRequest) { fields.add(Constants.USERID); fields.add(Constants.FIRSTNAME); - Map existingUserList = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD, + Map existingUserList = cassandraOperation.getRecordsByPropertiesWithoutFiltering(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_USER, userRequest, fields, Constants.ID); for (String user : listOfUserId) { final ObjectMapper mapper = new ObjectMapper(); final UserModel userModel = mapper.convertValue(existingUserList.get(user), UserModel.class); final LookupDataModel lookupModel = mapper.convertValue(existingDataList.get(user), LookupDataModel.class); - Long updatedTime= ((UUID.fromString(lookupModel.getUpdatedon()).timestamp() - 0x01b21dd213814000L) )/ 10000L; - listOfLookupResponse.add(new LookupResponse(lookupModel.getActivityid(), + Long updatedTime= ((UUID.fromString(lookupModel.getUpdatedOn()).timestamp() - 0x01b21dd213814000L) )/ 10000L; + listOfLookupResponse.add(new LookupResponse(lookupModel.getActivityId(), lookupModel.getReview(), lookupModel.getRating().toString(), updatedTime, - lookupModel.getUpdatedon(), - lookupModel.getActivitytype(), + lookupModel.getUpdatedOn(), + lookupModel.getActivityType(), lookupModel.getUserId(), (userModel.getFirstName() != null) ? userModel.getFirstName() : "" )); @@ -418,4 +420,70 @@ public void processExceptionBody(SBApiResponse response, Exception ex, response.setResponseCode(status); } + public SBApiResponse readRatings(Map request) { + SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.API_RATINGS_READ); + String errMsg = ""; + String activityId = ""; + try { + errMsg = validateRequest(request); + if (StringUtils.isNotBlank(errMsg)) { + updateErrorDetails(response, errMsg, HttpStatus.INTERNAL_SERVER_ERROR); + return response; + } + + Map requestBody = (Map) request.get(Constants.REQUEST); + Map compositeKey = new HashMap(); + + activityId = (String) requestBody.get(Constants.ACTIVITY_ID); + compositeKey.put(Constants.ACTIVITY_ID, activityId); + compositeKey.put(Constants.ACTIVITY_TYPE, (String) requestBody.get(Constants.ACTIVITY_TYPE)); + compositeKey.put(Constants.RATINGS_USER_ID, (List) requestBody.get(Constants.USER_ID)); + List> existingDataList = cassandraOperation.getRecordsByPropertiesWithoutFiltering( + Constants.KEYSPACE_SUNBIRD, + Constants.TABLE_RATINGS, compositeKey, null); + if (!CollectionUtils.isEmpty(existingDataList)) { + response.put(Constants.COUNT, existingDataList.size()); + response.put(Constants.CONTENT, existingDataList); + } + } catch (Exception e) { + errMsg = String.format("Failed to read rating for %s Course. Exception: %s", activityId, e.getMessage()); + logger.error("updateRatingTopicName", e); + } + return response; + } + + private String validateRequest(Map request) { + StringBuilder strBuilder = new StringBuilder(); + Map requestBody = (Map) request.get(Constants.REQUEST); + if (ObjectUtils.isEmpty(requestBody)) { + strBuilder.append("Invalid Request Body."); + return strBuilder.toString(); + } + + List missingAttrib = new ArrayList(); + if (!requestBody.containsKey(Constants.ACTIVITY_ID)) { + missingAttrib.add(Constants.ACTIVITY_ID); + } + if (!requestBody.containsKey(Constants.ACTIVITY_TYPE)) { + missingAttrib.add(Constants.ACTIVITY_TYPE); + } + + if (!requestBody.containsKey(Constants.USER_ID)) { + missingAttrib.add(Constants.USER_ID); + } + + if (missingAttrib.size() > 0) { + strBuilder.append("The following parameter(s) are missing. Missing params - [") + .append(missingAttrib.toString()).append("]"); + } + + return strBuilder.toString(); + } + + private void updateErrorDetails(SBApiResponse response, String errMsg, HttpStatus responseCode) { + response.getParams().setStatus(Constants.FAILED); + response.getParams().setErrmsg(errMsg); + response.setResponseCode(responseCode); + } + } diff --git a/src/main/resources/cassandratablecolumn.properties b/src/main/resources/cassandratablecolumn.properties index 64ec9ed0b..11a6a942c 100644 --- a/src/main/resources/cassandratablecolumn.properties +++ b/src/main/resources/cassandratablecolumn.properties @@ -57,3 +57,9 @@ failedrecordscount=failedRecordsCount submitassessmentresponse=submitAssessmentResponse assessmentreadresponse=assessmentReadResponse submitassessmentrequest=submitAssessmentRequest +activityid=activityId +activitytype=activityType +commentby=commentBy +commentupdatedon=commentUpdatedOn +createdon=createdOn +updatedon=updatedOn \ No newline at end of file From 052b1b6a59bdc2f309ef78aab702dc1a416d7261 Mon Sep 17 00:00:00 2001 From: karthik-tarento Date: Thu, 10 Aug 2023 17:37:49 +0530 Subject: [PATCH 6/8] Updated phone number properly for Parichay User. --- .../profile/service/ProfileServiceImpl.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java index 27c83a3cb..9c211fde9 100644 --- a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java +++ b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java @@ -543,6 +543,9 @@ public SBApiResponse userBasicInfo(String userId) { Map personalDetail = (Map) profileData .get(Constants.PERSONAL_DETAILS); responseMap.put(Constants.EMAIL, personalDetail.get(Constants.PRIMARY_EMAIL)); + if (personalDetail.containsKey(Constants.MOBILE)) { + responseMap.put(Constants.PHONE, String.valueOf(personalDetail.get(Constants.MOBILE))); + } } responseMap.put(Constants.FIRSTNAME, userData.get(Constants.FIRSTNAME)); @@ -1186,6 +1189,17 @@ private boolean updateUser(Map requestObject) { Map requestBody = (Map) requestObject.get(Constants.REQUEST); personalDetails.put(Constants.FIRSTNAME.toLowerCase(), requestBody.get(Constants.FIRSTNAME)); personalDetails.put(Constants.PRIMARY_EMAIL, requestBody.get(Constants.EMAIL)); + if (requestBody.containsKey(Constants.PHONE)) { + String incomingPhoneValue = ""; + try { + incomingPhoneValue = (String) requestBody.get(Constants.PHONE); + long mobileNumber = Long.parseLong(incomingPhoneValue); + personalDetails.put(Constants.MOBILE, mobileNumber); + } catch (NumberFormatException e) { + log.error("Failed to parse mobile number from signup request. Received Phone: " + incomingPhoneValue + + ", Exception: " + e.getMessage(), e); + } + } profileDetails.put(Constants.PERSONAL_DETAILS, personalDetails); Map professionDetailObj = new HashMap(); From 29a00291ebaa076637db6c3ef904810e316d7d97 Mon Sep 17 00:00:00 2001 From: karthik-tarento Date: Wed, 19 Jul 2023 09:50:30 +0530 Subject: [PATCH 7/8] Fixed issue in tag validation for bulk upload --- .classpath | 25 ++++++++++++++++++++++++ .project | 11 +++++++++++ .settings/org.eclipse.jdt.apt.core.prefs | 4 ++++ .settings/org.eclipse.jdt.core.prefs | 1 + .vscode/launch.json | 14 +++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 .settings/org.eclipse.jdt.apt.core.prefs create mode 100644 .vscode/launch.json diff --git a/.classpath b/.classpath index a5d95095c..a97cb0ebb 100644 --- a/.classpath +++ b/.classpath @@ -9,6 +9,7 @@ + @@ -28,5 +29,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project index 0d3c7a9ee..3f2f99e0d 100644 --- a/.project +++ b/.project @@ -20,4 +20,15 @@ org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + + + 1691054016055 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/.settings/org.eclipse.jdt.apt.core.prefs b/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 000000000..dfa4f3adb --- /dev/null +++ b/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=true +org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations +org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 71df5229c..90b69d45c 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -5,5 +5,6 @@ org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=enabled org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..13a744b24 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + "configurations": [ + { + "type": "java", + "name": "Spring Boot-SbCbExtApplication", + "request": "launch", + "cwd": "${workspaceFolder}", + "mainClass": "org.sunbird.portal.SbCbExtApplication", + "projectName": "sb-cb-ext", + "args": "", + "envFile": "${workspaceFolder}/.env" + } + ] +} \ No newline at end of file From 6e4d9748cc8ca36a7dc413e06a2742d896f24c39 Mon Sep 17 00:00:00 2001 From: karthik-tarento Date: Mon, 14 Aug 2023 14:40:34 +0530 Subject: [PATCH 8/8] Updated ratings POST API version as v2 --- .../java/org/sunbird/ratings/controller/RatingsController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/sunbird/ratings/controller/RatingsController.java b/src/main/java/org/sunbird/ratings/controller/RatingsController.java index da32fa351..05c47aacf 100644 --- a/src/main/java/org/sunbird/ratings/controller/RatingsController.java +++ b/src/main/java/org/sunbird/ratings/controller/RatingsController.java @@ -51,7 +51,7 @@ public ResponseEntity ratingLookUp(@RequestBody LookupRequest request) { return new ResponseEntity<>(response, response.getResponseCode()); } - @PostMapping("/ratings/v1/read") + @PostMapping("/ratings/v2/read") public ResponseEntity readRating(@RequestBody Map request) { SBApiResponse response = ratingService.readRatings(request); return new ResponseEntity<>(response, response.getResponseCode());