@Override public void saveComment(String questionId, Comment cm, String language) { try { ExoContainer exoContainer = ExoContainerContext.getCurrentContainer(); IdentityManager identityM = (IdentityManager) exoContainer.getComponentInstanceOfType(IdentityManager.class); ActivityManager activityM = (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class); FAQService faqS = (FAQService) exoContainer.getComponentInstanceOfType(FAQService.class); Question question = faqS.getQuestionById(questionId); String message = ActivityUtils.processContent(cm.getComments()); Identity userIdentity = identityM.getOrCreateIdentity( OrganizationIdentityProvider.NAME, cm.getCommentBy(), false); String activityId = faqS.getActivityIdForQuestion(questionId); if (activityId != null) { try { ExoSocialActivity activity = activityM.getActivity(activityId); ExoSocialActivityImpl comment = new ExoSocialActivityImpl(); String commentActivityId = faqS.getActivityIdForComment(questionId, cm.getId(), language); Map<String, String> commentTemplateParams = new HashMap<String, String>(); commentTemplateParams.put(LINK_KEY, cm.getId()); if (commentActivityId != null) { // try to update activity's comment ExoSocialActivityImpl oldComment = (ExoSocialActivityImpl) activityM.getActivity(commentActivityId); if (oldComment != null) { comment = oldComment; comment.setTitle(message); comment.setTitleId("update-comment"); activityM.updateActivity(comment); } else { commentActivityId = null; } } if (commentActivityId == null) { // create new activity's comment comment.setTemplateParams(commentTemplateParams); comment.setTitle(message); comment.setTitleId("add-comment"); comment.setUserId(userIdentity.getId()); updateActivity(activity, question); activityM.updateActivity(activity); activityM.saveComment(activity, comment); faqS.saveActivityIdForComment(questionId, cm.getId(), language, comment.getId()); } } catch (Exception e) { LOG.debug("Run in case of activity deleted and reupdate"); activityId = null; } } if (activityId == null) { // Create new activity for the question and add new comment saveQuestion(question, false); String newActivityId = faqS.getActivityIdForQuestion(questionId); ExoSocialActivity activity = activityM.getActivity(newActivityId); ExoSocialActivity comment = new ExoSocialActivityImpl(); comment.setUserId(userIdentity.getId()); Map<String, String> commentTemplateParams = new HashMap<String, String>(); commentTemplateParams.put(LINK_KEY, cm.getId()); comment.setTitle(message); comment.setTemplateParams(commentTemplateParams); activityM.saveComment(activity, comment); } } catch (Exception e) { // FQAService LOG.error("Can not record Activity for space when post comment ", e); } }