public String getTitle() throws Exception {
    String title = (String) request_.getAttribute(REQUEST_TITLE);

    //
    if (title == null) {
      UIPortal uiportal = Util.getUIPortal();

      //
      UserNode node = uiportal.getSelectedUserNode();
      if (node != null) {
        ExoContainer container = getApplication().getApplicationServiceContainer();
        container.getComponentInstanceOfType(UserPortalConfigService.class);
        UserPortalConfigService configService =
            (UserPortalConfigService)
                container.getComponentInstanceOfType(UserPortalConfigService.class);
        Page page = configService.getPage(node.getPageRef(), getRemoteUser());

        //
        if (page != null) {
          title = page.getTitle();
          return ExpressionUtil.getExpressionValue(this.getApplicationResourceBundle(), title);
        } else {
          title = node.getResolvedLabel();
        }
      }
    }

    //
    return title;
  }
Esempio n. 2
0
 /**
  * Gets the service.
  *
  * @param clazz the class
  * @param containerName the container's name
  * @return the service
  */
 public static <T> T getService(Class<T> clazz, String containerName) {
   ExoContainer container = ExoContainerContext.getCurrentContainer();
   if (containerName != null) {
     container = RootContainer.getInstance().getPortalContainer(containerName);
   }
   if (container.getComponentInstanceOfType(clazz) == null) {
     containerName = PortalContainer.getCurrentPortalContainerName();
     container = RootContainer.getInstance().getPortalContainer(containerName);
   }
   return clazz.cast(container.getComponentInstanceOfType(clazz));
 }
 private void refreshActivity(String questionId, String questionActivityId) {
   try {
     ExoContainer exoContainer = ExoContainerContext.getCurrentContainer();
     FAQService faqS = (FAQService) exoContainer.getComponentInstanceOfType(FAQService.class);
     Question question = faqS.getQuestionById(questionId);
     ActivityManager activityM =
         (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class);
     ExoSocialActivity activity = activityM.getActivity(questionActivityId);
     updateActivity(activity, question);
     activityM.updateActivity(activity);
   } catch (Exception e) {
     LOG.debug("Fail to refresh activity " + e.getMessage());
   }
 }
Esempio n. 4
0
 /**
  * Gets UserACL
  *
  * @return userACL
  */
 private UserACL getUserACL() {
   if (userACL == null) {
     ExoContainer container = ExoContainerContext.getCurrentContainer();
     return (UserACL) container.getComponentInstanceOfType(UserACL.class);
   }
   return userACL;
 }
Esempio n. 5
0
 /**
  * Gets OrganizationService
  *
  * @return organizationService
  */
 private OrganizationService getOrgService() {
   if (orgService == null) {
     ExoContainer container = ExoContainerContext.getCurrentContainer();
     orgService =
         (OrganizationService) container.getComponentInstanceOfType(OrganizationService.class);
   }
   return orgService;
 }
Esempio n. 6
0
 private Session getSession(SessionProvider sprovider) throws Exception {
   ExoContainer container = ExoContainerContext.getCurrentContainer();
   RepositoryService repositoryService =
       (RepositoryService) container.getComponentInstanceOfType(RepositoryService.class);
   ManageableRepository currentRepo = repositoryService.getCurrentRepository();
   return sprovider.getSession(
       currentRepo.getConfiguration().getDefaultWorkspaceName(), currentRepo);
 }
Esempio n. 7
0
 public static String getRestContextName() {
   ExoContainer container = ExoContainerContext.getCurrentContainer();
   PortalContainerConfig portalContainerConfig =
       (PortalContainerConfig) container.getComponentInstance(PortalContainerConfig.class);
   PortalContainerInfo containerInfo =
       (PortalContainerInfo) container.getComponentInstanceOfType(PortalContainerInfo.class);
   return portalContainerConfig.getRestContextName(containerInfo.getContainerName());
 }
 public void removeAnswer(String questionPath, String answerActivityId) {
   try {
     ExoContainer exoContainer = ExoContainerContext.getCurrentContainer();
     FAQService faqS = (FAQService) exoContainer.getComponentInstanceOfType(FAQService.class);
     String questionActivityId = faqS.getActivityIdForQuestion(questionPath);
     ActivityManager activityM =
         (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class);
     for (String id : answerActivityId.split(",")) {
       ExoSocialActivity activity = activityM.getActivity(id);
       if (activity != null) {
         activityM.deleteComment(questionActivityId, id);
       }
     }
     refreshActivity(questionPath, questionActivityId);
   } catch (Exception e) {
     LOG.debug("Fail to remove comment when remove question's answer " + e.getMessage());
   }
 }
Esempio n. 9
0
  private void initAllWorkspaceComponentEntries(ExoContainer parent) {
    SystemParametersPersistenceConfigurator sppc =
        (SystemParametersPersistenceConfigurator)
            parent.getComponentInstanceOfType(SystemParametersPersistenceConfigurator.class);

    for (WorkspaceEntry workspaceEntry : config.getWorkspaceEntries()) {
      initWorkspaceComponentEntries(sppc, workspaceEntry);
    }
  }
 /**
  * This method simply delegates the incoming call to the WebAppController stored in the Portal
  * Container object
  */
 @Override
 protected void onService(ExoContainer container, HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException {
   try {
     WebAppController controller =
         (WebAppController) container.getComponentInstanceOfType(WebAppController.class);
     controller.service(req, res);
   } catch (Throwable t) {
     throw new ServletException(t);
   }
 }
 public ResourceBundle getBundle(UserNavigation navigation) {
   ExoContainer container = ExoContainerContext.getCurrentContainer();
   ResourceBundleManager rbMgr =
       (ResourceBundleManager)
           container.getComponentInstanceOfType(ResourceBundleManager.class);
   Locale locale = Util.getPortalRequestContext().getLocale();
   return rbMgr.getNavigationResourceBundle(
       locale.getLanguage(),
       navigation.getKey().getTypeName(),
       navigation.getKey().getName());
 }
 public void removeQuestion(String questionActivityId) {
   try {
     ExoContainer exoContainer = ExoContainerContext.getCurrentContainer();
     ActivityManager activityM =
         (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class);
     ExoSocialActivity activity = activityM.getActivity(questionActivityId);
     activityM.deleteActivity(activity);
   } catch (Exception e) {
     LOG.debug("Fail to remove activity when remove question " + e.getMessage());
   }
 }
Esempio n. 13
0
 public void postSave(User user, boolean isNew) throws Exception {
   ExoContainer pcontainer = ExoContainerContext.getCurrentContainer();
   OrganizationService service =
       (OrganizationService) pcontainer.getComponentInstanceOfType(OrganizationService.class);
   UserProfile up = service.getUserProfileHandler().createUserProfileInstance();
   up.setUserName(user.getUserName());
   service.getUserProfileHandler().saveUserProfile(up, false);
   if (config_ == null) return;
   if (isNew && !config_.isIgnoreUser(user.getUserName())) {
     createDefaultUserMemberships(user, service);
   }
 }
 public void removeComment(
     String questionActivityId, String commentActivityId, String questionPath) {
   try {
     ExoContainer exoContainer = ExoContainerContext.getCurrentContainer();
     ActivityManager activityM =
         (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class);
     activityM.deleteComment(questionActivityId, commentActivityId);
     refreshActivity(questionPath, questionActivityId);
   } catch (Exception e) {
     LOG.debug("Fail to remove comment when remove question's comment " + e.getMessage());
   }
 }
Esempio n. 15
0
  public static void deleteFileActivity(Node node) throws RepositoryException {
    // get services
    ExoContainer container = ExoContainerContext.getCurrentContainer();
    ActivityManager activityManager =
        (ActivityManager) container.getComponentInstanceOfType(ActivityManager.class);
    IdentityManager identityManager =
        (IdentityManager) container.getComponentInstanceOfType(IdentityManager.class);

    // get owner
    String activityOwnerId = getActivityOwnerId(node);
    String nodeActivityID = StringUtils.EMPTY;
    ExoSocialActivity exa = null;
    if (node.isNodeType(ActivityTypeUtils.EXO_ACTIVITY_INFO)) {
      try {
        nodeActivityID = node.getProperty(ActivityTypeUtils.EXO_ACTIVITY_ID).getString();
        activityManager.deleteActivity(nodeActivityID);
      } catch (Exception e) {
        LOG.info("No activity is deleted, return no related activity");
      }
    }
  }
Esempio n. 16
0
  /**
   * Gets space application handlers
   *
   * @return
   */
  @SuppressWarnings("unchecked")
  private Map<String, SpaceApplicationHandler> getSpaceApplicationHandlers() {
    if (this.spaceApplicationHandlers == null) {
      this.spaceApplicationHandlers = new HashMap();

      ExoContainer container = ExoContainerContext.getCurrentContainer();
      SpaceApplicationHandler appHandler =
          (DefaultSpaceApplicationHandler)
              container.getComponentInstanceOfType(DefaultSpaceApplicationHandler.class);
      this.spaceApplicationHandlers.put(appHandler.getName(), appHandler);
    }
    return this.spaceApplicationHandlers;
  }
  public void unVoteQuestion(String questionId) {
    try {
      ExoContainer exoContainer = ExoContainerContext.getCurrentContainer();
      FAQService faqS = (FAQService) exoContainer.getComponentInstanceOfType(FAQService.class);
      Question question = faqS.getQuestionById(questionId);

      // No event is created because old and new values are equal but we must update the activity's
      // content
      question.setEditedQuestionRating(question.getMarkVote());
      saveQuestion(question, false);
    } catch (Exception e) {
      LOG.debug("Fail to unvote question " + e.getMessage());
    }
  }
Esempio n. 18
0
  public void setUp() throws Exception {
    super.setUp();
    ExoContainer myContainer = ExoContainerContext.getCurrentContainer();
    favoriteService =
        (FavoriteService) myContainer.getComponentInstanceOfType(FavoriteService.class);

    SessionProviderService sessionProviderService =
        (SessionProviderService)
            myContainer.getComponentInstanceOfType(SessionProviderService.class);

    SessionProvider sessionProvider = sessionProviderService.getSystemSessionProvider(null);

    ManageableRepository manageableRepository = repositoryService.getRepository("repository");

    Session session = sessionProvider.getSession(COLLABORATION_WS, manageableRepository);
    Node rootNode = session.getRootNode();
    String[] names = new String[] {"root", "demo", "james", "john", "marry"};
    for (String name : names)
      if (rootNode.hasNode(name)) {
        rootNode.getNode(name).remove();
        rootNode.save();
      }
  }
Esempio n. 19
0
 /**
  * refine node for validation
  *
  * @param currentNode
  * @throws Exception
  */
 private static void refineNode(Node currentNode) throws Exception {
   if (currentNode instanceof NodeImpl && !((NodeImpl) currentNode).isValid()) {
     ExoContainer container = ExoContainerContext.getCurrentContainer();
     LinkManager linkManager =
         (LinkManager) container.getComponentInstanceOfType(LinkManager.class);
     if (linkManager.isLink(currentNode)) {
       try {
         currentNode = linkManager.getTarget(currentNode, false);
       } catch (RepositoryException ex) {
         currentNode = linkManager.getTarget(currentNode, true);
       }
     }
   }
 }
  @Override
  public void execute(JobExecutionContext jec) throws JobExecutionException {

    if (log.isInfoEnabled()) {
      log.info("Job Scheduler ready to send emails");
    }
    ExoContainer containerContext = ExoContainerContext.getCurrentContainer();
    SocialNotificationService socialNotificationService =
        (SocialNotificationService)
            containerContext.getComponentInstanceOfType(SocialNotificationService.class);
    socialNotificationService.spaceNotification();
    if (log.isInfoEnabled()) {
      log.info("Job Scheduler done sending emails");
    }
  }
  public UserPortalConfig getUserPortalConfig() {
    if (userPortalConfig == null) {
      String portalName = null;
      String remoteUser = getRemoteUser();
      SiteType siteType = getSiteType();

      ExoContainer appContainer = getApplication().getApplicationServiceContainer();
      UserPortalConfigService service_ =
          (UserPortalConfigService)
              appContainer.getComponentInstanceOfType(UserPortalConfigService.class);
      if (SiteType.PORTAL == siteType) {
        portalName = getSiteName();
      }

      HttpSession session = request_.getSession();
      if (portalName == null) {
        if (session != null) {
          portalName = (String) session.getAttribute(LAST_PORTAL_NAME);
        }
      }

      if (portalName == null) {
        portalName = service_.getDefaultPortal();
      }
      try {
        userPortalConfig =
            service_.getUserPortalConfig(
                portalName, remoteUser, PortalRequestContext.USER_PORTAL_CONTEXT);
        if (userPortalConfig != null) {
          session.setAttribute(LAST_PORTAL_NAME, portalName);
        }
      } catch (Exception e) {
        return null;
      }
    }

    return userPortalConfig;
  }
Esempio n. 22
0
 /**
  * @param : node: nt:file node with have the data stream
  * @return : Link to download the jcr:data of the given node
  * @throws Exception
  */
 public static String getDownloadRestServiceLink(Node node) throws Exception {
   ExoContainer container = ExoContainerContext.getCurrentContainer();
   PortalContainerInfo containerInfo =
       (PortalContainerInfo) container.getComponentInstanceOfType(PortalContainerInfo.class);
   String portalName = containerInfo.getContainerName();
   PortalContainerConfig portalContainerConfig =
       (PortalContainerConfig) container.getComponentInstance(PortalContainerConfig.class);
   String restContextName = portalContainerConfig.getRestContextName(portalName);
   StringBuilder sb = new StringBuilder();
   Node currentNode = org.exoplatform.wcm.webui.Utils.getRealNode(node);
   String ndPath = currentNode.getPath();
   if (ndPath.startsWith("/")) {
     ndPath = ndPath.substring(1);
   }
   String encodedPath = URLEncoder.encode(ndPath, "utf-8");
   encodedPath =
       encodedPath.replaceAll("%2F", "/"); // we won't encode the slash characters in the path
   sb.append("/").append(restContextName).append("/contents/download/");
   sb.append(currentNode.getSession().getWorkspace().getName()).append("/").append(encodedPath);
   if (node.isNodeType("nt:frozenNode")) {
     sb.append("?version=" + node.getParent().getName());
   }
   return sb.toString();
 }
  @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);
    }
  }
 @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);
   }
 }
Esempio n. 25
0
  @SuppressWarnings("unchecked")
  public UIPageForm(InitParams initParams) throws Exception {
    super("UIPageForm");
    PortalRequestContext pcontext = Util.getPortalRequestContext();
    UserPortalConfigService configService = getApplicationComponent(UserPortalConfigService.class);
    List<SelectItemOption<String>> ownerTypes = new ArrayList<SelectItemOption<String>>();
    ownerTypes.add(new SelectItemOption<String>(PortalConfig.USER_TYPE));

    UserPortalConfig userPortalConfig =
        configService.getUserPortalConfig(pcontext.getPortalOwner(), pcontext.getRemoteUser());
    ExoContainer container = ExoContainerContext.getCurrentContainer();
    UserACL acl = (UserACL) container.getComponentInstanceOfType(UserACL.class);
    if (acl.hasEditPermission(userPortalConfig.getPortalConfig())) {
      ownerTypes.add(new SelectItemOption<String>(PortalConfig.PORTAL_TYPE));
    }
    ownerIdInput = new UIFormStringInput(OWNER_ID, OWNER_ID, null);
    ownerIdInput.setEditable(false).setValue(pcontext.getRemoteUser());

    UIFormSelectBox uiSelectBoxOwnerType = new UIFormSelectBox(OWNER_TYPE, OWNER_TYPE, ownerTypes);
    uiSelectBoxOwnerType.setOnChange("ChangeOwnerType");

    UIFormInputSet uiSettingSet = new UIFormInputSet("PageSetting");
    uiSettingSet
        .addUIFormInput(new UIFormStringInput("pageId", "pageId", null).setEditable(false))
        .addUIFormInput(uiSelectBoxOwnerType)
        .addUIFormInput(ownerIdInput)
        .addUIFormInput(
            new UIFormStringInput("name", "name", null)
                .addValidator(StringLengthValidator.class, 3, 30)
                .addValidator(IdentifierValidator.class)
                .addValidator(MandatoryValidator.class))
        .addUIFormInput(
            new UIFormStringInput("title", "title", null)
                .addValidator(StringLengthValidator.class, 3, 120))
        .addUIFormInput(new UIFormCheckBoxInput("showMaxWindow", "showMaxWindow", false));
    addUIFormInput(uiSettingSet);
    setSelectedTab(uiSettingSet.getId());

    // WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
    // Param param = initParams.getParam("PageTemplate");
    // List<SelectItemCategory> itemCategories =
    // (List<SelectItemCategory>)param.getMapGroovyObject(context);
    // UIFormInputItemSelector uiTemplate = new UIFormInputItemSelector("Template", "template");
    // uiTemplate.setItemCategories(itemCategories);
    // addUIFormInput(uiTemplate);

    uiPermissionSetting = createUIComponent(UIFormInputSet.class, "PermissionSetting", null);
    UIListPermissionSelector uiListPermissionSelector =
        createUIComponent(UIListPermissionSelector.class, null, null);
    uiListPermissionSelector.configure("UIListPermissionSelector", "accessPermissions");
    uiListPermissionSelector.addValidator(EmptyIteratorValidator.class);
    uiPermissionSetting.addChild(uiListPermissionSelector);
    uiPermissionSetting.setSelectedComponent(uiListPermissionSelector.getId());
    UIPermissionSelector uiEditPermission =
        createUIComponent(UIPermissionSelector.class, null, null);
    uiEditPermission.setRendered(false);
    uiEditPermission.addValidator(
        org.exoplatform.webui.organization.UIPermissionSelector.MandatoryValidator.class);
    uiEditPermission.setEditable(false);
    uiEditPermission.configure("UIPermissionSelector", "editPermission");
    uiPermissionSetting.addChild(uiEditPermission);

    // TODO: This following line is fixed for bug PORTAL-2127
    uiListPermissionSelector
        .getChild(UIFormPopupWindow.class)
        .setId("UIPageFormPopupGroupMembershipSelector");

    List<String> groups = configService.getMakableNavigations(pcontext.getRemoteUser(), true);
    if (groups.size() > 0) {
      Collections.sort(groups);
      ownerTypes.add(new SelectItemOption<String>(PortalConfig.GROUP_TYPE));
      List<SelectItemOption<String>> groupsItem = new ArrayList<SelectItemOption<String>>();
      for (String group : groups) {
        groupsItem.add(new SelectItemOption<String>(group));
      }
      groupIdSelectBox = new UIFormSelectBox(OWNER_ID, OWNER_ID, groupsItem);
      groupIdSelectBox.setOnChange("ChangeOwnerId");
      groupIdSelectBox.setParent(uiSettingSet);
    }
    setActions(new String[] {"Save", "Close"});
  }
  @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);
    }
  }
Esempio n. 27
0
  /**
   * @param node : activity raised from this source
   * @param activityMsgBundleKey
   * @param isSystemComment
   * @param systemComment the new value of System Posted activity, if (isSystemComment)
   *     systemComment can not be set to null, set to empty string instead of.
   * @throws Exception
   */
  public static ExoSocialActivity postFileActivity(
      Node node,
      String activityMsgBundleKey,
      boolean needUpdate,
      boolean isSystemComment,
      String systemComment)
      throws Exception {
    Object isSkipRaiseAct =
        DocumentContext.getCurrent().getAttributes().get(DocumentContext.IS_SKIP_RAISE_ACT);
    if (isSkipRaiseAct != null && Boolean.valueOf(isSkipRaiseAct.toString())) {
      return null;
    }
    if (!isSupportedContent(node)) {
      return null;
    }

    // get services
    ExoContainer container = ExoContainerContext.getCurrentContainer();
    ActivityManager activityManager =
        (ActivityManager) container.getComponentInstanceOfType(ActivityManager.class);
    IdentityManager identityManager =
        (IdentityManager) container.getComponentInstanceOfType(IdentityManager.class);
    ActivityCommonService activityCommonService =
        (ActivityCommonService) container.getComponentInstanceOfType(ActivityCommonService.class);

    SpaceService spaceService = WCMCoreUtils.getService(SpaceService.class);

    // refine to get the valid node
    refineNode(node);

    // get owner
    String activityOwnerId = getActivityOwnerId(node);
    String nodeActivityID = StringUtils.EMPTY;
    ExoSocialActivity exa = null;
    if (node.isNodeType(ActivityTypeUtils.EXO_ACTIVITY_INFO)) {
      try {
        nodeActivityID = node.getProperty(ActivityTypeUtils.EXO_ACTIVITY_ID).getString();
        exa = activityManager.getActivity(nodeActivityID);
      } catch (Exception e) {
        LOG.info("No activity is deleted, return no related activity");
      }
    }
    ExoSocialActivity activity = null;
    String commentID;
    boolean commentFlag = false;
    if (node.isNodeType(MIX_COMMENT) && activityCommonService.isEditing(node)) {
      if (node.hasProperty(MIX_COMMENT_ID)) {
        commentID = node.getProperty(MIX_COMMENT_ID).getString();
        if (StringUtils.isNotBlank(commentID)) activity = activityManager.getActivity(commentID);
        commentFlag = (activity != null);
      }
    }
    if (activity == null) {
      activity =
          createActivity(
              identityManager,
              activityOwnerId,
              node,
              activityMsgBundleKey,
              FILE_SPACES,
              isSystemComment,
              systemComment);
    }

    if (exa != null) {
      if (commentFlag) {
        Map<String, String> paramsMap = activity.getTemplateParams();
        String paramMessage = paramsMap.get(ContentUIActivity.MESSAGE);
        String paramContent = paramsMap.get(ContentUIActivity.SYSTEM_COMMENT);
        if (!StringUtils.isEmpty(paramMessage)) {
          paramMessage += ActivityCommonService.VALUE_SEPERATOR + activityMsgBundleKey;
          if (StringUtils.isEmpty(systemComment)) {
            paramContent += ActivityCommonService.VALUE_SEPERATOR + " ";
          } else {
            paramContent += ActivityCommonService.VALUE_SEPERATOR + systemComment;
          }
        } else {
          paramMessage = activityMsgBundleKey;
          paramContent = systemComment;
        }
        paramsMap.put(ContentUIActivity.MESSAGE, paramMessage);
        paramsMap.put(ContentUIActivity.SYSTEM_COMMENT, paramContent);
        activity.setTemplateParams(paramsMap);
        activityManager.updateActivity(activity);
      } else {
        activityManager.saveComment(exa, activity);
        if (activityCommonService.isEditing(node)) {
          commentID = activity.getId();
          if (node.canAddMixin(MIX_COMMENT)) node.addMixin(MIX_COMMENT);
          if (node.isNodeType(MIX_COMMENT)) node.setProperty(MIX_COMMENT_ID, commentID);
        }
      }
      return activity;
    } else {
      String spaceName = getSpaceName(node);
      if (spaceName != null
          && spaceName.length() > 0
          && spaceService.getSpaceByPrettyName(spaceName) != null) {
        // post activity to space stream
        Identity spaceIdentity =
            identityManager.getOrCreateIdentity(SpaceIdentityProvider.NAME, spaceName, true);
        activityManager.saveActivityNoReturn(spaceIdentity, activity);
      } else if (activityOwnerId != null && activityOwnerId.length() > 0) {
        // post activity to user status stream
        Identity ownerIdentity =
            identityManager.getOrCreateIdentity(
                OrganizationIdentityProvider.NAME, activityOwnerId, true);
        activityManager.saveActivityNoReturn(ownerIdentity, activity);
      } else {
        return null;
      }
      String activityId = activity.getId();
      if (!StringUtils.isEmpty(activityId)) {
        ActivityTypeUtils.attachActivityId(node, activityId);
      }

      if (node.isNodeType(ActivityTypeUtils.EXO_ACTIVITY_INFO)) {
        try {
          nodeActivityID = node.getProperty(ActivityTypeUtils.EXO_ACTIVITY_ID).getString();
          exa = activityManager.getActivity(nodeActivityID);
        } catch (Exception e) {
          LOG.info("No activity is deleted, return no related activity");
        }
        if (exa != null && !commentFlag && isSystemComment) {
          activityManager.saveComment(exa, activity);
          if (activityCommonService.isEditing(node)) {
            commentID = activity.getId();
            if (node.canAddMixin(MIX_COMMENT)) node.addMixin(MIX_COMMENT);
            if (node.isNodeType(MIX_COMMENT)) node.setProperty(MIX_COMMENT_ID, commentID);
          }
        }
      }

      return activity;
    }
  }
Esempio n. 28
0
 private String getPortalName() {
   ExoContainer container = ExoContainerContext.getCurrentContainer();
   PortalContainerInfo containerInfo =
       (PortalContainerInfo) container.getComponentInstanceOfType(PortalContainerInfo.class);
   return containerInfo.getContainerName();
 }