@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()));
   }
 }
コード例 #2
0
  private ExoSocialActivity saveActivity(
      Map<String, String> activityParams,
      ActivityManager activityManager,
      IdentityManager identityManager,
      Identity ownerIdentity,
      String remoteUser)
      throws ActivityStorageException, RepositoryException {
    Node node =
        getDocNode(
            activityParams.get(UIDocActivity.REPOSITORY),
            activityParams.get(UIDocActivity.WORKSPACE),
            activityParams.get(UIDocActivity.DOCPATH));
    String activity_type = UIDocActivity.ACTIVITY_TYPE;
    if (node.getPrimaryNodeType().getName().equals(NodetypeConstant.NT_FILE)) {
      activity_type = FILE_SPACES;
    }

    Identity userIdentity =
        identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, remoteUser, true);
    String title = activityParams.get(UIDocActivity.MESSAGE);
    if (title == null || title.length() == 0) {
      title = docActivityTitle;
    }
    ExoSocialActivity activity =
        new ExoSocialActivityImpl(userIdentity.getId(), activity_type, title, null);
    activity.setTemplateParams(activityParams);
    activityManager.saveActivityNoReturn(ownerIdentity, activity);

    String activityId = activity.getId();
    if (!StringUtils.isEmpty(activityId)) {
      ActivityTypeUtils.attachActivityId(node, activityId);
      node.save();
    }

    return activityManager.getActivity(activity.getId());
  }
コード例 #3
0
ファイル: Utils.java プロジェクト: hanhvq/integration
  /**
   * @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;
    }
  }