@Override public void saveAnswer(String questionId, Answer answer, boolean isNew) { 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); Identity userIdentity = identityM.getOrCreateIdentity( OrganizationIdentityProvider.NAME, answer.getResponseBy(), false); String activityId = faqS.getActivityIdForQuestion(questionId); // String answerContent = ActivityUtils.processContent(answer.getResponses()); if (activityId != null && answer.getApprovedAnswers()) { try { ExoSocialActivity activity = activityM.getActivity(activityId); ExoSocialActivity comment = createCommentForAnswer(userIdentity, answer); if (!comment.getTitle().equals("")) { // Case update answer or promote comment to answer String promotedAnswer = "Comment " + answerContent + " has been promoted as an answer"; if (promotedAnswer.equals(comment.getTitle())) { // promote a comment to an answer updateCommentTemplateParms(comment, answer.getId()); activityM.saveComment(activity, comment); faqS.saveActivityIdForAnswer(questionId, answer, comment.getId()); // update question activity content updateActivity(activity, question); activityM.updateActivity(activity); } else { // update answer activityM.saveComment(activity, comment); String answerActivityId = faqS.getActivityIdForAnswer(questionId, answer); faqS.saveActivityIdForAnswer( questionId, answer, answerActivityId + "," + comment.getId()); } } else { // Case submit new answer comment.setTitle("Answer has been submitted: " + answerContent); I18NActivityUtils.addResourceKey(comment, "answer-add", answerContent); updateActivity(activity, question); activityM.updateActivity(activity); updateCommentTemplateParms(comment, answer.getId()); activityM.saveComment(activity, comment); faqS.saveActivityIdForAnswer(questionId, answer, comment.getId()); } } catch (Exception e) { LOG.debug("Run in case of activity deleted and reupdate"); activityId = null; } } if (activityId == null) { saveQuestion(question, false); String newActivityId = faqS.getActivityIdForQuestion(question.getId()); ExoSocialActivity activity = activityM.getActivity(newActivityId); ExoSocialActivity comment = createCommentForAnswer(userIdentity, answer); if (comment.getTitle().equals("")) { comment.setTitle("Answer has been submitted: " + answerContent); I18NActivityUtils.addResourceKey(comment, "answer-add", answerContent); updateCommentTemplateParms(comment, answer.getId()); } activityM.saveComment(activity, comment); } } catch (Exception e) { // FQAService LOG.error("Can not record Activity for space when post answer ", e); } }