diff --git a/src/main/java/org/sunbird/common/util/Constants.java b/src/main/java/org/sunbird/common/util/Constants.java index 2333c78b9..e78c0b003 100644 --- a/src/main/java/org/sunbird/common/util/Constants.java +++ b/src/main/java/org/sunbird/common/util/Constants.java @@ -153,7 +153,7 @@ public class Constants { public static final String USER_LAST_NAME = "lastName"; public static final String USERID = "id"; public static final String COMMENT = "comment"; - public static final String COMMENT_BY = "commentby"; + 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 RATING = "rating"; diff --git a/src/main/java/org/sunbird/ratings/model/LookupRequest.java b/src/main/java/org/sunbird/ratings/model/LookupRequest.java index f503154fc..2d4b36edc 100644 --- a/src/main/java/org/sunbird/ratings/model/LookupRequest.java +++ b/src/main/java/org/sunbird/ratings/model/LookupRequest.java @@ -6,7 +6,7 @@ public class LookupRequest { private String activityType; private Float rating; private int limit; - private Long updateOn; + private String updateOn; public String getActivityId() { return activityId; @@ -40,11 +40,11 @@ public void setLimit(int limit) { this.limit = limit; } - public Long getUpdateOn() { + public String getUpdateOn() { return updateOn; } - public void setUpdateOn(Long updateOn) { + public void setUpdateOn(String updateOn) { this.updateOn = updateOn; } } diff --git a/src/main/java/org/sunbird/ratings/model/LookupResponse.java b/src/main/java/org/sunbird/ratings/model/LookupResponse.java index 99e5185a9..a36bcbab5 100644 --- a/src/main/java/org/sunbird/ratings/model/LookupResponse.java +++ b/src/main/java/org/sunbird/ratings/model/LookupResponse.java @@ -7,16 +7,18 @@ public class LookupResponse { private String review; private String rating; private Long updatedon; + private String updatedOnUUID; private String activityType; private String userId; private String firstName; private String lastName; - public LookupResponse(String activityId, String review, String rating, Long updatedon, String activityType, String userId, String firstName, String lastName) { + public LookupResponse(String activityId, String review, String rating, Long updatedon,String updatedOnUUID, String activityType, String userId, String firstName, String lastName) { this.activityId = activityId; this.review = review; this.rating = rating; this.updatedon = updatedon; + this.updatedOnUUID = updatedOnUUID; this.activityType = activityType; this.userId = userId; this.firstName = firstName; @@ -55,6 +57,14 @@ public void setUpdatedon(Long updatedon) { this.updatedon = updatedon; } + public String getUpdatedOnUUID() { + return updatedOnUUID; + } + + public void setUpdatedOnUUID(String updatedOnUUID) { + this.updatedOnUUID = updatedOnUUID; + } + public String getActivityType() { return activityType; } diff --git a/src/main/java/org/sunbird/ratings/model/RatingModelInfo.java b/src/main/java/org/sunbird/ratings/model/RatingModelInfo.java index bc5c16207..868833c15 100644 --- a/src/main/java/org/sunbird/ratings/model/RatingModelInfo.java +++ b/src/main/java/org/sunbird/ratings/model/RatingModelInfo.java @@ -4,7 +4,7 @@ public class RatingModelInfo { private String activityId; - private String commentUpdatedOn; + private Timestamp commentUpdatedOn; private String commentBy; private String review; private Float rating; @@ -17,7 +17,7 @@ public class RatingModelInfo { public RatingModelInfo() { } - public RatingModelInfo(String activityId, String commentUpdatedOn, String commentBy, String review, Float rating, String comment, Timestamp updatedOn, String activityType, String userId, Timestamp createdOn) { + public RatingModelInfo(String activityId, Timestamp commentUpdatedOn, String commentBy, String review, Float rating, String comment, Timestamp updatedOn, String activityType, String userId, Timestamp createdOn) { this.activityId = activityId; this.commentUpdatedOn = commentUpdatedOn; this.commentBy = commentBy; @@ -38,11 +38,11 @@ public void setActivityId(String activityId) { this.activityId = activityId; } - public String getCommentUpdatedOn() { + public Timestamp getCommentUpdatedOn() { return commentUpdatedOn; } - public void setCommentUpdatedOn(String commentUpdatedOn) { + public void setCommentUpdatedOn(Timestamp commentUpdatedOn) { this.commentUpdatedOn = commentUpdatedOn; } diff --git a/src/main/java/org/sunbird/ratings/model/RequestRating.java b/src/main/java/org/sunbird/ratings/model/RequestRating.java index d9805014d..0a1ed4d98 100644 --- a/src/main/java/org/sunbird/ratings/model/RequestRating.java +++ b/src/main/java/org/sunbird/ratings/model/RequestRating.java @@ -6,6 +6,8 @@ public class RequestRating { private String activityType; private Float rating; private String review ; + private String comment; + private String commentBy; public String getActivityId() { return activityId; @@ -46,4 +48,20 @@ public String getReview() { public void setReview(String review) { this.review = review; } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getCommentBy() { + return commentBy; + } + + public void setCommentBy(String commentBy) { + this.commentBy = commentBy; + } } diff --git a/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java b/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java index a6602da68..ec21464c2 100644 --- a/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java +++ b/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java @@ -66,6 +66,15 @@ public SBApiResponse getRatings(String activityId, String activityType, String u 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"); + Long CommentUpdatedTime = (commentupdatedOn.timestamp() - 0x01b21dd213814000L) / 10000L; + ratingModelInfo.setCommentUpdatedOn(new Timestamp(CommentUpdatedTime)); + } + timeBasedUuid = (UUID) ratingData.get("updatedon"); Long updatedTime = (timeBasedUuid.timestamp() - 0x01b21dd213814000L) / 10000L; ratingModelInfo.setUpdatedOn(new Timestamp(updatedTime)); @@ -198,17 +207,23 @@ public SBApiResponse upsertRating(RequestRating requestRating) { if (!CollectionUtils.isEmpty(existingDataList)) { Map updateRequest = new HashMap<>(); - updateRequest.put(Constants.RATING, requestRating.getRating()); - updateRequest.put(Constants.REVIEW, requestRating.getReview()); - updateRequest.put(Constants.UPDATED_ON, timeBasedUuid); - + if(requestRating.getComment()==null) { + updateRequest.put(Constants.RATING, requestRating.getRating()); + updateRequest.put(Constants.REVIEW, requestRating.getReview()); + updateRequest.put(Constants.UPDATED_ON, timeBasedUuid); + } + if(requestRating.getComment()!=null && requestRating.getCommentBy()!=null) { + updateRequest.put(Constants.COMMENT, requestRating.getComment()); + updateRequest.put(Constants.COMMENT_BY, requestRating.getCommentBy()); + updateRequest.put(Constants.COMMENT_UPDATED_ON,timeBasedUuid); + } Map prevInfo = existingDataList.get(0); 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")))); - ratingMessage.setPrevValues(processEventMessage(String.valueOf(prevInfo.get("createdon")), + ratingMessage.setPrevValues(processEventMessage(String.valueOf(prevInfo.get("updatedon")), (Float) prevInfo.get("rating"), (String) prevInfo.get("review"))); ratingMessage.setUpdatedValues(processEventMessage(String.valueOf(updateRequest.get(Constants.UPDATED_ON)), requestRating.getRating(), requestRating.getReview())); @@ -217,7 +232,6 @@ public SBApiResponse upsertRating(RequestRating requestRating) { request.put(Constants.RATING, requestRating.getRating()); request.put(Constants.REVIEW, requestRating.getReview()); request.put(Constants.UPDATED_ON, timeBasedUuid); - cassandraOperation.insertRecord(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_RATINGS, request); ratingMessage = new RatingMessage("ratingAdd", requestRating.getActivityId(), requestRating.getActivityType(), @@ -250,7 +264,7 @@ public SBApiResponse upsertRating(RequestRating requestRating) { public SBApiResponse ratingLookUp(LookupRequest lookupRequest) { List listOfUserId = new ArrayList<>(); SBApiResponse response = new SBApiResponse(Constants.API_RATINGS_LOOKUP); - UUID uuid; + String uuid; try { validationBody = new ValidationBody(); @@ -265,15 +279,14 @@ public SBApiResponse ratingLookUp(LookupRequest lookupRequest) { request.put(Constants.RATING, lookupRequest.getRating()); } if(lookupRequest.getUpdateOn() !=null){ - java.util.Date time=new java.util.Date((lookupRequest.getUpdateOn())*10000L); - uuid = UUIDs.startOf(time.getTime()); + uuid = lookupRequest.getUpdateOn(); } else { - uuid = UUIDs.timeBased(); + uuid = String.valueOf(UUIDs.timeBased()); } Map existingDataList = cassandraOperation.getRecordsByPropertiesWithPagination(Constants.KEYSPACE_SUNBIRD, - Constants.TABLE_RATINGS_LOOKUP, request, null, lookupRequest.getLimit(), String.valueOf(uuid), "userId"); + Constants.TABLE_RATINGS_LOOKUP, request, null, lookupRequest.getLimit(), uuid, "userId"); List listOfLookupResponse = new ArrayList<>(); if (!CollectionUtils.isEmpty(existingDataList)) { @@ -296,12 +309,12 @@ public SBApiResponse ratingLookUp(LookupRequest lookupRequest) { 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()) / 10000L; - + 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.getUserId(), (userModel.getFirstName() != null) ? userModel.getFirstName() : "",