Ejemplo n.º 1
0
 public void setInfor(Question question, String commentId, FAQSetting faqSetting, String language)
     throws Exception {
   if (!language.equals(question.getLanguage())) {
     try {
       QuestionLanguage questionLanguage =
           getFAQService().getQuestionLanguageByLanguage(question.getPath(), language);
       this.questionContent = questionLanguage.getQuestion();
       this.questionDetail = questionLanguage.getDetail();
       languageSelected = language;
     } catch (Exception e) {
       this.questionContent = question.getQuestion();
       this.questionDetail = question.getDetail();
       languageSelected = question.getLanguage();
     }
   } else {
     this.questionContent = question.getQuestion();
     this.questionDetail = question.getDetail();
     languageSelected = question.getLanguage();
   }
   this.question_ = question;
   this.faqSetting_ = faqSetting;
   FAQUtils.getEmailSetting(faqSetting_, false, false);
   if (commentId.indexOf("new") < 0) {
     comment = getFAQService().getCommentById(question.getPath(), commentId, language);
     ((UIFormWYSIWYGInput) this.getChildById(COMMENT_CONTENT)).setValue(comment.getComments());
   }
 }
 private String getQuestionMessage(
     PropertyChangeEvent e, Question question, ExoSocialActivity comment) {
   String questionDetail = ActivityUtils.processContent(question.getDetail());
   if ("questionName".equals(e.getPropertyName())) {
     String questionName = question.getQuestion();
     I18NActivityUtils.addResourceKey(
         comment,
         "question-update-title",
         CommonUtils.decodeSpecialCharToHTMLnumberIgnore(questionName));
     return "Title has been updated to: "
         + CommonUtils.decodeSpecialCharToHTMLnumber(questionName);
   } else if ("questionDetail".equals(e.getPropertyName())) {
     I18NActivityUtils.addResourceKey(comment, "question-update-detail", questionDetail);
     return "Details has been edited to: " + questionDetail;
   } else if ("questionActivated".equals(e.getPropertyName())) {
     if (question.isActivated()) {
       I18NActivityUtils.addResourceKey(comment, "question-activated", null);
       return "Question has been activated.";
     } else {
       I18NActivityUtils.addResourceKey(comment, "question-unactivated", null);
       return "Question has been unactivated.";
     }
   } else if ("questionAttachment".equals(e.getPropertyName())) {
     I18NActivityUtils.addResourceKey(comment, "question-add-attachment", null);
     return "Attachment(s) has been added.";
   } else { // case of add new language
     int length = question.getMultiLanguages().length;
     I18NActivityUtils.addResourceKey(
         comment, "question-add-language", question.getMultiLanguages()[length - 1].getLanguage());
     return "Question has been added in " + question.getMultiLanguages()[length - 1].getLanguage();
   }
 }
  @Override
  public void saveQuestion(Question question, 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);
      Identity userIdentity =
          identityM.getOrCreateIdentity(
              OrganizationIdentityProvider.NAME, question.getAuthor(), false);
      Map<String, String> templateParams =
          updateTemplateParams(
              new HashMap<String, String>(),
              question.getId(),
              ActivityUtils.getQuestionRate(question),
              ActivityUtils.getNbOfAnswers(question),
              ActivityUtils.getNbOfComments(question),
              question.getLanguage(),
              question.getLink(),
              Utils.getQuestionPoint(question));
      String activityId = faqS.getActivityIdForQuestion(question.getId());

      String questionDetail = ActivityUtils.processContent(question.getDetail());
      // in case deleted activity, if isUpdate, we will re-create new activity and add a comment
      // associated
      boolean isUpdate = false;
      // UserHelper.checkValueUser(values)
      if (activityId != null) {
        isUpdate = true;
        try {
          ExoSocialActivity activity = activityM.getActivity(activityId);
          if (UserHelper.getUserByUserId(question.getAuthor()) == null) {
            userIdentity = identityM.getIdentity(activity.getPosterId(), false);
          }
          activity.setTitle(CommonUtils.decodeSpecialCharToHTMLnumber(question.getQuestion()));
          activity.setBody(questionDetail);
          activity.setTemplateParams(templateParams);
          activityM.updateActivity(activity);

          ExoSocialActivity comment = createCommentWhenUpdateQuestion(userIdentity, question);
          if (!"".equals(comment.getTitle())) {
            activityM.saveComment(activity, comment);
          }
        } catch (Exception e) {
          LOG.debug("Run in case of activity deleted and reupdate");
          activityId = null;
        }
      }
      if (activityId == null) {
        Identity streamOwner = null;
        String catId =
            (String)
                faqS.readQuestionProperty(
                    question.getId(), FAQNodeTypes.EXO_CATEGORY_ID, String.class);
        Identity spaceIdentity = getSpaceIdentity(catId);
        if (spaceIdentity != null) {
          // publish the activity in the space stream.
          streamOwner = spaceIdentity;
          templateParams.put(SPACE_GROUP_ID, ActivityUtils.getSpaceGroupId(catId));
        }
        List<String> categoryIds = faqS.getCategoryPath(catId);
        Collections.reverse(categoryIds);
        if (streamOwner == null) {
          streamOwner = userIdentity;
        }
        ExoSocialActivity activity =
            newActivity(userIdentity, question.getQuestion(), questionDetail, templateParams);
        activityM.saveActivityNoReturn(streamOwner, activity);
        faqS.saveActivityIdForQuestion(question.getId(), activity.getId());

        if (isUpdate) {
          ExoSocialActivity comment = createCommentWhenUpdateQuestion(userIdentity, question);
          if (!"".equals(comment.getTitle())) {
            activityM.saveComment(activity, comment);
          }
        }
      }
    } catch (Exception e) { // FQAService
      LOG.error("Can not record Activity for space when add new question ", e);
    }
  }
 @Override
 public void moveQuestions(List<String> questions, String catId) {
   ActivityManager activityM = CommonsUtils.getService(ActivityManager.class);
   FAQService faqS = CommonsUtils.getService(FAQService.class);
   IdentityManager identityM = CommonsUtils.getService(IdentityManager.class);
   for (String questionId : questions) {
     try {
       Question question = faqS.getQuestionById(questionId);
       String activityId = faqS.getActivityIdForQuestion(question.getPath());
       Identity streamOwner = null;
       Map<String, String> templateParams =
           updateTemplateParams(
               new HashMap<String, String>(),
               question.getId(),
               ActivityUtils.getQuestionRate(question),
               ActivityUtils.getNbOfAnswers(question),
               ActivityUtils.getNbOfComments(question),
               question.getLanguage(),
               question.getLink(),
               Utils.getQuestionPoint(question));
       String questionDetail = ActivityUtils.processContent(question.getDetail());
       Identity spaceIdentity = getSpaceIdentity(catId);
       if (spaceIdentity != null) {
         streamOwner = spaceIdentity;
         templateParams.put(SPACE_GROUP_ID, ActivityUtils.getSpaceGroupId(catId));
       }
       if (activityId != null) {
         ExoSocialActivity oldActivity = activityM.getActivity(activityId);
         activityM.deleteActivity(oldActivity);
         Identity userIdentity =
             identityM.getOrCreateIdentity(
                 OrganizationIdentityProvider.NAME, question.getAuthor(), false);
         ExoSocialActivity activity =
             newActivity(userIdentity, question.getQuestion(), questionDetail, templateParams);
         streamOwner = streamOwner != null ? streamOwner : userIdentity;
         activityM.saveActivityNoReturn(streamOwner, activity);
         faqS.saveActivityIdForQuestion(questionId, activity.getId());
         for (Answer answer : question.getAnswers()) {
           ExoSocialActivity comment = createCommentForAnswer(userIdentity, answer);
           String answerContent = ActivityUtils.processContent(answer.getResponses());
           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());
         }
         for (Comment cm : question.getComments()) {
           String message = ActivityUtils.processContent(cm.getComments());
           ExoSocialActivityImpl comment = new ExoSocialActivityImpl();
           Map<String, String> commentTemplateParams = new HashMap<String, String>();
           commentTemplateParams.put(LINK_KEY, cm.getId());
           comment.setTemplateParams(commentTemplateParams);
           comment.setTitle(message);
           comment.setUserId(userIdentity.getId());
           updateActivity(activity, question);
           activityM.updateActivity(activity);
           activityM.saveComment(activity, comment);
           faqS.saveActivityIdForComment(
               questionId, cm.getId(), question.getLanguage(), comment.getId());
         }
       }
     } catch (Exception e) {
       LOG.error("Failed to move questions " + e.getMessage());
     }
   }
 }