/**
   * publish a new event activity
   *
   * @param event
   * @param calendarId
   * @param eventType
   */
  private void publishActivity(CalendarEvent event, String calendarId, String eventType) {
    try {
      Class.forName("org.exoplatform.social.core.space.spi.SpaceService");
    } catch (ClassNotFoundException e) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("eXo Social components not found!", e);
      }
      return;
    }
    if (calendarId == null
        || calendarId.indexOf(CalendarDataInitialize.SPACE_CALENDAR_ID_SUFFIX) < 0) {
      return;
    }
    try {
      IdentityManager identityM =
          (IdentityManager)
              PortalContainer.getInstance().getComponentInstanceOfType(IdentityManager.class);
      ActivityManager activityM =
          (ActivityManager)
              PortalContainer.getInstance().getComponentInstanceOfType(ActivityManager.class);
      SpaceService spaceService =
          (SpaceService)
              PortalContainer.getInstance().getComponentInstanceOfType(SpaceService.class);

      String spaceGroupId = Utils.getSpaceGroupIdFromCalendarId(calendarId);
      Space space = spaceService.getSpaceByGroupId(spaceGroupId);
      if (space != null) {
        String userId = ConversationState.getCurrent().getIdentity().getUserId();
        Identity spaceIdentity =
            identityM.getOrCreateIdentity(SpaceIdentityProvider.NAME, space.getPrettyName(), false);
        Identity userIdentity =
            identityM.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId, false);
        ExoSocialActivity activity = new ExoSocialActivityImpl();
        activity.setUserId(userIdentity.getId());
        activity.setTitle(event.getSummary());
        activity.setBody(event.getDescription());
        activity.setType("cs-calendar:spaces");
        activity.setTemplateParams(makeActivityParams(event, calendarId, eventType));
        activityM.saveActivityNoReturn(spaceIdentity, activity);
        event.setActivityId(activity.getId());
      }
    } catch (ExoSocialException e) {
      if (LOG.isDebugEnabled()) LOG.error("Can not record Activity for space when event added ", e);
    }
  }
示例#2
0
  public static ExoSocialActivity createActivity(
      IdentityManager identityManager,
      String activityOwnerId,
      Node node,
      String activityMsgBundleKey,
      String activityType,
      boolean isSystemComment,
      String systemComment)
      throws Exception {
    // Populate activity data
    Map<String, String> activityParams =
        populateActivityData(
            node, activityOwnerId, activityMsgBundleKey, isSystemComment, systemComment);

    String title =
        node.hasProperty(NodetypeConstant.EXO_TITLE)
            ? node.getProperty(NodetypeConstant.EXO_TITLE).getString()
            : org.exoplatform.ecm.webui.utils.Utils.getTitle(node);
    ExoSocialActivity activity = new ExoSocialActivityImpl();
    String userId = "";
    if (ConversationState.getCurrent() != null) {
      userId = ConversationState.getCurrent().getIdentity().getUserId();
    } else {
      userId = activityOwnerId;
    }
    Identity identity =
        identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId, false);
    activity.setUserId(identity.getId());
    activity.setType(activityType);
    activity.setUrl(node.getPath());
    activity.setTitle(title);
    activity.setTemplateParams(activityParams);
    return activity;
  }
 /**
  * An identity posts an activity to an identity's activity stream with a number of activities.
  *
  * @param posterIdentity the identity who posts activity
  * @param identityStream the identity who has activity stream to be posted.
  * @param number the number of activities
  */
 private void createActivities(Identity posterIdentity, Identity identityStream, int number) {
   for (int i = 0; i < number; i++) {
     ExoSocialActivity activity = new ExoSocialActivityImpl();
     activity.setType("exosocial:core");
     activity.setTitle("title " + i);
     activity.setUserId(posterIdentity.getId());
     activity = activityManager.saveActivity(identityStream, activity);
     tearDownActivityList.add(activity);
   }
 }
 private ExoSocialActivity newActivity(
     Identity author, String title, String body, Map<String, String> templateParams) {
   ExoSocialActivity activity = new ExoSocialActivityImpl();
   activity.setTitle(CommonUtils.decodeSpecialCharToHTMLnumber(title));
   activity.setTitleId("add-question");
   activity.setBody(body);
   activity.setType(SPACE_APP_ID);
   activity.setTemplateParams(templateParams);
   activity.setUserId(author.getId());
   return activity;
 }
示例#5
0
 /**
  * Records an activity based on space lifecyle event and the activity object.
  *
  * @param event the space lifecyle event
  * @param activityMessage the message of activity object
  * @param titleId the title of activity (comment)
  * @param templateParams
  */
 private void recordActivity(
     SpaceLifeCycleEvent event,
     String activityMessage,
     String titleId,
     Map<String, String> templateParams) {
   Space space = event.getSpace();
   Identity spaceIdentity =
       identityManager.getOrCreateIdentity(
           SpaceIdentityProvider.NAME, space.getPrettyName(), false);
   Identity identity =
       identityManager.getOrCreateIdentity(
           OrganizationIdentityProvider.NAME, event.getTarget(), false);
   String activityId =
       getStorage()
           .getProfileActivityId(spaceIdentity.getProfile(), Profile.AttachedActivityType.SPACE);
   if (activityId != null) {
     try {
       if (!"Has left the space.".equals(activityMessage)) {
         ExoSocialActivity comment =
             createComment(activityMessage, titleId, null, SPACE_APP_ID, identity, templateParams);
         ExoSocialActivity activity =
             (ExoSocialActivityImpl) activityManager.getActivity(activityId);
         activityManager.saveComment(activity, comment);
       }
     } catch (Exception e) {
       LOG.debug("Run in case of activity deleted and reupdate");
       activityId = null;
     }
   }
   if (activityId == null) {
     ExoSocialActivity activity = new ExoSocialActivityImpl();
     activity.setType(SPACE_PROFILE_ACTIVITY);
     activity.setTitle("1 Member");
     if (Space.HIDDEN.equals(space.getVisibility())) {
       activity.isHidden(true);
     }
     activityManager.saveActivityNoReturn(spaceIdentity, activity);
     getStorage()
         .updateProfileActivityId(
             spaceIdentity, activity.getId(), Profile.AttachedActivityType.SPACE);
     if (SPACE_CREATED_TITLE_ID.equals(titleId)) titleId = USER_JOINED_TITLE_ID;
     ExoSocialActivity comment =
         createComment(activityMessage, titleId, null, SPACE_APP_ID, identity, templateParams);
     activityManager.saveComment(activity, comment);
   }
 }
  /**
   * creates a comment associated to updated fields
   *
   * @param userId
   * @param messagesParams
   * @return a comment object
   * @since activity-type
   */
  private ExoSocialActivity createComment(String userId, Map<String, String> messagesParams) {
    ExoSocialActivity newComment = new ExoSocialActivityImpl();
    newComment.isComment(true);
    newComment.setUserId(userId);
    newComment.setType("CALENDAR_ACTIVITY");
    StringBuilder fields = new StringBuilder();
    Map<String, String> data = new LinkedHashMap<String, String>();

    for (String field : messagesParams.keySet()) {
      String value = messagesParams.get(field);
      data.put(field, value); // store field changed and its new value
      fields.append("," + field);
    }
    String fieldsChanged = fields.toString().substring(1); // remove the first ","
    data.put(CALENDAR_FIELDS_CHANGED, fieldsChanged);
    newComment.setTitleId(fieldsChanged);
    newComment.setTemplateParams(data);
    //    newComment.setTitle(title.toString());
    return newComment;
  }
  /**
   * adds comment to existing event activity
   *
   * @param event
   * @param calendarId
   * @param eventType
   * @param messagesParams
   */
  private void updateToActivity(
      CalendarEvent event,
      String calendarId,
      String eventType,
      Map<String, String> messagesParams) {
    try {
      Class.forName("org.exoplatform.social.core.space.spi.SpaceService");
    } catch (ClassNotFoundException e) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("eXo Social components not found!", e);
      }
      return;
    }
    if (calendarId == null
        || calendarId.indexOf(CalendarDataInitialize.SPACE_CALENDAR_ID_SUFFIX) < 0) {
      return;
    }
    try {
      IdentityManager identityM =
          (IdentityManager)
              PortalContainer.getInstance().getComponentInstanceOfType(IdentityManager.class);
      ActivityManager activityM =
          (ActivityManager)
              PortalContainer.getInstance().getComponentInstanceOfType(ActivityManager.class);
      SpaceService spaceService =
          (SpaceService)
              PortalContainer.getInstance().getComponentInstanceOfType(SpaceService.class);

      String spaceGroupId = Utils.getSpaceGroupIdFromCalendarId(calendarId);
      Space space = spaceService.getSpaceByGroupId(spaceGroupId);
      if (space != null) {
        String userId = ConversationState.getCurrent().getIdentity().getUserId();
        Identity spaceIdentity =
            identityM.getOrCreateIdentity(SpaceIdentityProvider.NAME, space.getPrettyName(), false);
        Identity userIdentity =
            identityM.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId, false);

        ExoSocialActivity activity = null;

        if (event.getActivityId() != null) {
          activity = activityM.getActivity(event.getActivityId());
        }

        /*
         * if activity is still null, that means:
         * - activity was deleted
         * - or this event is a public event from plf 3.5, it has no activityId
         * In this case, we create new activity and add comments about the changes to the activity
         */
        if (activity == null) {

          // create activity
          ExoSocialActivity newActivity = new ExoSocialActivityImpl();
          newActivity.setUserId(userIdentity.getId());
          newActivity.setTitle(event.getSummary());
          newActivity.setBody(event.getDescription());
          newActivity.setType("cs-calendar:spaces");
          newActivity.setTemplateParams(makeActivityParams(event, calendarId, eventType));
          activityM.saveActivityNoReturn(spaceIdentity, newActivity);

          // add comments
          ExoSocialActivity newComment = createComment(userIdentity.getId(), messagesParams);
          activityM.saveComment(newActivity, newComment);

          // update activity id for event
          event.setActivityId(newActivity.getId());
          LOG.info(
              String.format(
                  "[CALENDAR] successfully re-created activity for event: %s", event.getSummary()));
        } else {
          activity.setTitle(event.getSummary());
          activity.setBody(event.getDescription());
          activity.setTemplateParams(makeActivityParams(event, calendarId, eventType));
          activityM.updateActivity(activity);
          ExoSocialActivity newComment = createComment(userIdentity.getId(), messagesParams);
          activityM.saveComment(activity, newComment);
          LOG.info(
              String.format(
                  "[CALENDAR] successfully added comment to activity of event: %s",
                  event.getSummary()));
        }
      }
    } catch (ExoSocialException e) {
      if (LOG.isDebugEnabled())
        LOG.error("Can not update Activity for space when event modified ", e);
    }
  }