示例#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);
        }
      }
    }
  }
 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;
 }
  /**
   * 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;
  }
示例#4
0
  /**
   * Records an activity for user space based on space lifecyle event and the activity object.
   *
   * @param event the space life-cycle event
   * @param activityMessage the message of activity object
   * @param titleId the title of activity (comment)
   * @param templateParams
   */
  private void recordActivityForUserSpace(
      SpaceLifeCycleEvent event,
      String userSpaceActivityMessage,
      String titleId,
      Map<String, String> templateParams,
      boolean isJoined) {
    Space space = event.getSpace();
    if (space.getVisibility().equals(Space.HIDDEN)) {
      return;
    }
    Identity identity =
        identityManager.getOrCreateIdentity(
            OrganizationIdentityProvider.NAME, event.getTarget(), false);
    String activityId =
        getStorage()
            .getProfileActivityId(identity.getProfile(), Profile.AttachedActivityType.RELATION);

    // not go to create new with these kind of activities
    if (activityId == null) {
      return;
    }

    int numberOfSpacesOfMember =
        getSpaceStorage().getNumberOfMemberPublicSpaces(identity.getRemoteId());

    //
    ExoSocialActivity activity = null;
    if (activityId != null) {
      activity = (ExoSocialActivityImpl) activityManager.getActivity(activityId);
    }

    if (activity == null) {
      return;
    }

    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);
    }

    if (activityId != null) {
      if (isJoined) {
        try {
          // Create comment when user join space
          ExoSocialActivity comment =
              createComment(
                  userSpaceActivityMessage,
                  titleId,
                  event.getSpace().getDisplayName(),
                  USER_ACTIVITIES_FOR_SPACE,
                  identity,
                  new LinkedHashMap<String, String>());
          activityManager.updateActivity(activity);
          activityManager.saveComment(activity, comment);
        } catch (Exception e) {
          LOG.debug("Run in case of activity deleted");
          activityId = null;
        }
      } else { // for Spec then left space have no affect on comments
        //
        activityManager.updateActivity(activity);
      }
    }
  }