Skip to content

Commit

Permalink
Merge pull request #93 from wilkysingh-tarento/cbrelease-4.0.1-lastna…
Browse files Browse the repository at this point in the history
…me_firstname_added

Reply for Publisher feature added and timestamp bug fixed
  • Loading branch information
pkranga authored May 25, 2022
2 parents b0c85c9 + a7b434c commit f282dfe
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/sunbird/ratings/model/LookupRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
12 changes: 11 additions & 1 deletion src/main/java/org/sunbird/ratings/model/LookupResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/sunbird/ratings/model/RatingModelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/sunbird/ratings/model/RequestRating.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
39 changes: 26 additions & 13 deletions src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -198,17 +207,23 @@ public SBApiResponse upsertRating(RequestRating requestRating) {
if (!CollectionUtils.isEmpty(existingDataList)) {

Map<String, Object> 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<String, Object> 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()));
Expand All @@ -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(),
Expand Down Expand Up @@ -250,7 +264,7 @@ public SBApiResponse upsertRating(RequestRating requestRating) {
public SBApiResponse ratingLookUp(LookupRequest lookupRequest) {
List<String> listOfUserId = new ArrayList<>();
SBApiResponse response = new SBApiResponse(Constants.API_RATINGS_LOOKUP);
UUID uuid;
String uuid;

try {
validationBody = new ValidationBody();
Expand All @@ -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<String, Object> 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<LookupResponse> listOfLookupResponse = new ArrayList<>();

if (!CollectionUtils.isEmpty(existingDataList)) {
Expand All @@ -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() : "",
Expand Down

0 comments on commit f282dfe

Please sign in to comment.