Skip to content
Permalink
Browse files

PN-378: Change the stored format for the status comments

  • Loading branch information...
veronikaslc committed Jan 12, 2019
1 parent bf81b32 commit f6931a5bbfc1d7629e97491c0da37432262e501f
@@ -131,13 +131,13 @@ boolean saveOutgoingMatches(List<? extends PatientSimilarityView> similarityView
boolean setUserContacted(Set<Long> matchesIds, boolean isUserContacted);

/**
* Sets comment to all matches with ids in {@code matchesIds} to a passed comment string.
* Saves comment to all matches with ids in {@code matchesIds} to a passed comment string.
*
* @param matchesIds list of ids of matches to set status
* @param matchesIds list of ids of matches to save comment
* @param comment comment text
* @return true if successful
*/
boolean setComment(Set<Long> matchesIds, String comment);
boolean saveComment(Set<Long> matchesIds, String comment);

/**
* Saves note to all matches with ids in {@code matchesIds}.
@@ -267,15 +267,15 @@ public boolean setUserContacted(Set<Long> matchesIds, boolean isUserContacted)
}

@Override
public boolean setComment(Set<Long> matchesIds, String comment)
public boolean saveComment(Set<Long> matchesIds, String comment)
{
boolean successful = false;
try {
List<PatientMatch> matches = this.matchStorageManager.loadMatchesByIds(matchesIds);

filterNonUsersMatches(matches);

successful = this.matchStorageManager.setComment(matches, comment);
successful = this.matchStorageManager.saveComment(matches, comment);
} catch (Exception e) {
this.logger.error("Error while setting comment for matches {} as {}",
Joiner.on(",").join(matchesIds), comment, e);
@@ -90,7 +90,25 @@
*
* @param comment comment text
*/
void setComment(String comment);
void setComments(String comment);

/**
* Updates a comment SON log string with new comment record.
* Record is a JSON String object, in the following format:
* <pre>
* { "comments":
* [ { "userinfo":{"id":"xwiki:XWiki.Mary",
* "name":"Mary Green"},
* "comment":"This is a good match"
* "date":"2018/12/06"},
* ...
* ]
* }
* </pre>
*
* @param commentRecord the new comment record JSON string
*/
void updateComments(String commentRecord);

/**
* Sets match notes as a JSON String object, in the following format:
@@ -147,7 +165,7 @@
/**
* @return match comment for a reason why the status was changed.
*/
String getComment();
String getComments();

/**
* @return currently logged user note about the match in general, if any.
@@ -28,6 +28,7 @@

import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.users.User;
import org.xwiki.users.UserManager;

import java.io.Serializable;
@@ -81,6 +82,8 @@

private static final String NOTES = "notes";

private static final String COMMENTS = "comments";

private static final UserManager USER_MANAGER;

/*
@@ -112,7 +115,8 @@
private String status;

@Basic
private String comment;
@Column(length = 0xFFFFFF)
private String comments;

@Basic
@Column(length = 0xFFFFFF)
@@ -259,6 +263,7 @@ private void initialize(PatientSimilarityView similarityView, String referenceSe
this.notifiedTimestamp = null;
this.notified = false;
this.notificationHistory = null;
this.comments = null;
this.notes = null;
this.status = "uncategorized";
this.score = similarityView.getScore();
@@ -313,9 +318,9 @@ public void setStatus(String newStatus)
}

@Override
public void setComment(String comment)
public void setComments(String comments)
{
this.comment = comment;
this.comments = comments;
}

@Override
@@ -369,9 +374,9 @@ public String getStatus()
}

@Override
public String getComment()
public String getComments()
{
return this.comment;
return this.comments;
}

@Override
@@ -506,7 +511,7 @@ public JSONObject toJSON()
json.put("genotypicScore", this.getGenotypeScore());
json.put("phenotypicScore", this.getPhenotypeScore());
json.put("href", this.isLocal() ? "" : this.getHref());
json.put("comment", this.getComment());
json.put("comments", this.getComments());
json.put("notificationHistory", this.notificationHistory);
json.put("notes", this.getNotes());

@@ -737,4 +742,48 @@ public void setUserContacted(boolean isUserContacted)
// error parsing notification history/ new record JSON string to JSON object happened
}
}

@Override
public void updateComments(String commentRecord)
{
try {
User currentUser = USER_MANAGER.getCurrentUser();
JSONObject allComments = (this.comments != null) ? new JSONObject(this.comments)
: new JSONObject();
JSONArray records = allComments.optJSONArray(COMMENTS);
JSONObject newRecord = new JSONObject();
JSONObject userInfo = new JSONObject();
userInfo.put("id", currentUser.getId());
userInfo.put("name", currentUser.getName());
newRecord.put("userinfo", userInfo);
newRecord.put("comment", commentRecord);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm");
newRecord.put("date", sdf.format(new Timestamp(System.currentTimeMillis())));

if (records == null) {
records = new JSONArray();
records.put(newRecord);
} else {
boolean updated = false;
for (Object record : records) {
JSONObject item = (JSONObject) record;
JSONObject userInfoJson = item.optJSONObject("userinfo");
if (userInfoJson != null && userInfoJson.optString("id", "").equals(currentUser.getId())) {
item.put("comment", commentRecord);
updated = true;
break;
}
}

if (!updated) {
records.put(newRecord);
}
}

allComments.put(COMMENTS, records);
this.comments = allComments.toString();
} catch (JSONException ex) {
// error parsing notes or new record JSON string to JSON object happened
}
}
}
@@ -93,13 +93,13 @@
boolean setStatus(List<PatientMatch> matches, String status);

/**
* Sets comment to all matches in {@code matches} to a passed status string.
* Saves comment to all matches in {@code matches} to a passed status string.
*
* @param matches list of matches to mark as notified.
* @param matches list of matches to save comment.
* @param comment comment text
* @return true if successful
*/
boolean setComment(List<PatientMatch> matches, String comment);
boolean saveComment(List<PatientMatch> matches, String comment);

/**
* Saves a note to all matches in {@code matches}.
@@ -180,7 +180,7 @@ public boolean saveLocalMatches(List<PatientMatch> matches, String patientId)
if (!existingMatch.isNotified()) {
match.setFoundTimestamp(existingMatch.getFoundTimestamp());
match.setStatus(existingMatch.getStatus());
match.setComment(existingMatch.getComment());
match.setComments(existingMatch.getComments());
match.setNotificationHistory(existingMatch.getNotificationHistory());
match.setNotes(existingMatch.getNotes());
}
@@ -526,14 +526,14 @@ public boolean setStatus(List<PatientMatch> matches, String status)
}

@Override
public boolean setComment(List<PatientMatch> matches, String comment)
public boolean saveComment(List<PatientMatch> matches, String comment)
{
Session session = this.beginTransaction();
boolean transactionCompleted = false;

try {
for (PatientMatch match : matches) {
match.setComment(comment);
match.updateComments(comment);
session.update(match);
}
transactionCompleted = true;
@@ -273,7 +273,7 @@ public Response saveComment(final Set<Long> matchesIds, final String comment)
return Response.status(Response.Status.BAD_REQUEST).build();
}

boolean success = this.matchingNotificationManager.setComment(matchesIds, comment);
boolean success = this.matchingNotificationManager.saveComment(matchesIds, comment);
JSONObject result = this.successfulIdsToJSON(matchesIds, success ? matchesIds
: Collections.<Long>emptyList());
return Response.ok(result, MediaType.APPLICATION_JSON_TYPE).build();

0 comments on commit f6931a5

Please sign in to comment.
You can’t perform that action at this time.