static final private Logger theLogger = Logger.getLogger(AddComment.class.getName());
@Override
public void handleCommand(HttpServletRequest req, HttpServletResponse resp, IUser user)
throws IOException {
Comment comment = extractComment(req);
IUserManager userManager = ServerManager.getServerManager().getUserManager();
String designerName = comment.getDesignerId();
IUser designer = null;
try {
if(ServerManager.LOCAL_INSTALL && IDavinciServerConstants.LOCAL_INSTALL_USER.equalsIgnoreCase(designerName)) {
designer = userManager.getUser(IDavinciServerConstants.LOCAL_INSTALL_USER);
} else {
designer = userManager.getUser(designerName);
}
} catch (UserException e) {
errorString = "Failure getting user for 'designer'. Reason: " + e.getMessage();
theLogger.severe((String) errorString);
return;
}
//Set up project based on designer
DavinciProject project = new DavinciProject();
project.setOwnerId(designer.getUserID());
comment.setProject(project);
comment.setEmail(user.getPerson().getEmail());
IDesignerUser du = ReviewManager.getReviewManager()
.getDesignerUser(designerName);
Version version = du.getVersion(comment.getPageVersion());
if (version != null && version.isClosed()){
errorString = "The version was closed by another user while editing. Please reload the review data.";
return;
}
List<Comment> commentList = new ArrayList<Comment>(1);
commentList.add(comment);
ReviewCacheManager.$.updateComments(commentList);
String emailResult = null;
if (version != null && version.isReceiveEmail()) { // Send the notification only the designer want receive it.
Boolean zazl = req.getParameter("zazl") != null;
emailResult = notifyRelatedPersons(user, designer, comment, req, zazl);
}
SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATE_PATTERN);
sdf.setCalendar(Calendar.getInstance(new SimpleTimeZone(0, "GMT")));
try {
JSONObject json = new JSONObject()
.put("id", comment.getId())
.put("created", sdf.format(comment.getCreated()))
// .put("order", comment.getOrder())
.put("email", user.getPerson().getEmail())
.put("reviewer", user.getUserID());
if (emailResult != null) {
json.put("emailResult", emailResult);