예제 #1
0
  /** {@inheritDoc} */
  @Override
  public void spaceAccessEdited(SpaceLifeCycleEvent event) {
    Space space = event.getSpace();

    // Update space's activity
    Identity spaceIdentity =
        identityManager.getOrCreateIdentity(
            SpaceIdentityProvider.NAME, space.getPrettyName(), false);
    String spaceActivityId =
        getStorage()
            .getProfileActivityId(spaceIdentity.getProfile(), Profile.AttachedActivityType.SPACE);
    if (spaceActivityId != null) {
      ExoSocialActivity activity =
          (ExoSocialActivityImpl) activityManager.getActivity(spaceActivityId);
      if (activity != null) {
        if (Space.HIDDEN.equals(space.getVisibility())) {
          activity.isHidden(true);
        }
        if (Space.PRIVATE.equals(space.getVisibility())) {
          activity.isHidden(false);
        }
        activityManager.updateActivity(activity);
      }
    }

    // Update user space activity of all member of space
    String[] members = space.getMembers();
    for (String member : members) {
      Identity identity =
          identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, member, false);
      String userSpaceActivityId =
          getStorage()
              .getProfileActivityId(identity.getProfile(), Profile.AttachedActivityType.RELATION);
      if (userSpaceActivityId != null) {
        ExoSocialActivity activity =
            (ExoSocialActivityImpl) activityManager.getActivity(userSpaceActivityId);
        if (activity != null) {
          int numberOfSpacesOfMember =
              getSpaceStorage().getNumberOfMemberPublicSpaces(identity.getRemoteId());
          Map<String, String> templateParams = activity.getTemplateParams();
          templateParams.put(NUMBER_OF_PUBLIC_SPACE, String.valueOf(numberOfSpacesOfMember));
          templateParams.put(
              BaseActivityProcessorPlugin.TEMPLATE_PARAM_TO_PROCESS, NUMBER_OF_PUBLIC_SPACE);
          activity.setTemplateParams(templateParams);

          if (numberOfSpacesOfMember > 1) {
            activity.setTitle("I now member of " + numberOfSpacesOfMember + " spaces");
            activity.setTitleId(USER_JOINED_PUBLIC_SPACES_TITLE_ID);
          } else {
            activity.setTitle("I now member of " + numberOfSpacesOfMember + " space");
            activity.setTitleId(USER_JOINED_PUBLIC_SPACE_TITLE_ID);
          }
          activityManager.updateActivity(activity);
        }
      }
    }
  }
  @Override
  protected void extendUIActivity(BaseUIActivity uiActivity, ExoSocialActivity activity) {
    UIDocActivity docActivity = (UIDocActivity) uiActivity;
    //
    if (activity.getTemplateParams() == null) {
      saveToNewDataFormat(activity);
    }
    //
    Map<String, String> activityParams = activity.getTemplateParams();
    docActivity.docLink = activityParams.get(UIDocActivity.DOCLINK);
    docActivity.docName = activityParams.get(UIDocActivity.DOCNAME);
    docActivity.message = activityParams.get(UIDocActivity.MESSAGE);
    docActivity.docPath = activityParams.get(UIDocActivity.DOCPATH);
    docActivity.repository = activityParams.get(UIDocActivity.REPOSITORY);
    docActivity.workspace = activityParams.get(UIDocActivity.WORKSPACE);

    // escape node name for special characters
    docActivity.docPath = escapeIllegalJcrCharsOnNodeName(docActivity.docPath);
  }
 @Override
 public void onEvent(Event<ExoSocialActivity, String> event) throws Exception {
   ExoSocialActivity activity = event.getSource();
   if (CalendarSpaceActivityPublisher.CALENDAR_APP_ID.equals(activity.getType())) {
     String eventId =
         activity.getTemplateParams().get(CalendarSpaceActivityPublisher.EVENT_ID_KEY);
     String calendarId =
         activity.getTemplateParams().get(CalendarSpaceActivityPublisher.CALENDAR_ID_KEY);
     //
     Node calendarNode = getJCRDataStorage().getPublicCalendarHome().getNode(calendarId);
     Node eventNode = calendarNode.getNode(eventId);
     ActivityTypeUtils.attachActivityId(eventNode, event.getData());
     //
     eventNode.getSession().save();
     LOG.info(
         String.format(
             "Done migration the calendar activity with old id's %s and new id's %s",
             activity.getId(), event.getData()));
   }
 }
예제 #4
0
  private static void updateMainActivity(
      ActivityManager activityManager, Node contentNode, ExoSocialActivity activity) {
    Map<String, String> activityParams = activity.getTemplateParams();
    String state;
    String nodeTitle;
    String nodeType = null;
    String nodeIconName = null;
    String documentTypeLabel;
    String currentVersion = null;
    TemplateService templateService = WCMCoreUtils.getService(TemplateService.class);
    try {
      nodeType = contentNode.getPrimaryNodeType().getName();
      documentTypeLabel = templateService.getTemplateLabel(nodeType);
    } catch (Exception e) {
      documentTypeLabel = "";
    }
    try {
      nodeTitle = org.exoplatform.ecm.webui.utils.Utils.getTitle(contentNode);
    } catch (Exception e1) {
      nodeTitle = "";
    }
    try {
      state =
          contentNode.hasProperty(CURRENT_STATE_PROP)
              ? contentNode.getProperty(CURRENT_STATE_PROP).getValue().getString()
              : "";
    } catch (Exception e) {
      state = "";
    }
    try {
      currentVersion = contentNode.getBaseVersion().getName();

      // TODO Must improve this hardcode later, need specification
      if (currentVersion.contains("jcr:rootVersion")) currentVersion = "0";
    } catch (Exception e) {
      currentVersion = "";
    }
    activityParams.put(ContentUIActivity.STATE, state);
    activityParams.put(ContentUIActivity.DOCUMENT_TYPE_LABEL, documentTypeLabel);
    activityParams.put(ContentUIActivity.DOCUMENT_TITLE, nodeTitle);
    activityParams.put(ContentUIActivity.DOCUMENT_VERSION, currentVersion);
    String summary = getSummary(contentNode);
    summary = getFirstSummaryLines(summary, MAX_SUMMARY_LINES_COUNT);
    activityParams.put(ContentUIActivity.DOCUMENT_SUMMARY, summary);
    activity.setTemplateParams(activityParams);
    activityManager.updateActivity(activity);
  }
예제 #5
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;
    }
  }
 private void updateCommentTemplateParms(ExoSocialActivity comment, String link) {
   Map<String, String> commentTemplateParams = comment.getTemplateParams();
   if (commentTemplateParams == null) commentTemplateParams = new HashMap<String, String>();
   commentTemplateParams.put(LINK_KEY, link);
   comment.setTemplateParams(commentTemplateParams);
 }