/**
   * 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
  @MaxQueryNumber(500)
  public void testViewerOwnerAllCases() throws Exception {
    publisher =
        (RelationshipPublisher)
            this.getContainer().getComponentInstanceOfType(RelationshipPublisher.class);
    assertNotNull(publisher);
    relationshipManager.addListenerPlugin(publisher);
    connectIdentities(demoIdentity, johnIdentity, true);

    //
    ExoSocialActivity activity1 = new ExoSocialActivityImpl();
    activity1.setTitle("title @demo hi");
    activityStorage.saveActivity(rootIdentity, activity1);

    //
    ExoSocialActivity activity2 = new ExoSocialActivityImpl();
    activity2.setTitle("john title");
    activityStorage.saveActivity(rootIdentity, activity2);

    // owner poster comment
    createComment(activity2, demoIdentity, 2);

    List<ExoSocialActivity> list = activityStorage.getActivities(demoIdentity, johnIdentity, 0, 10);
    // only show demo's activity when John is viewer
    assertEquals(1, list.size());

    tearDownActivityList.addAll(list);
    relationshipManager.unregisterListener(publisher);
  }
 private void saveToNewDataFormat(ExoSocialActivity activity) {
   try {
     final JSONObject jsonObject = new JSONObject(activity.getTitle());
     final String docActivityTitle =
         "<a href=\"${" + UIDocActivity.DOCLINK + "}\">" + "${" + UIDocActivity.DOCNAME + "}</a>";
     //
     activity.setTitle(docActivityTitle);
     //
     Map<String, String> activityParams = new HashMap<String, String>();
     activityParams.put(UIDocActivity.DOCNAME, jsonObject.getString(UIDocActivity.DOCNAME));
     activityParams.put(UIDocActivity.DOCLINK, jsonObject.getString(UIDocActivity.DOCLINK));
     activityParams.put(UIDocActivity.DOCPATH, jsonObject.getString(UIDocActivity.DOCPATH));
     activityParams.put(UIDocActivity.REPOSITORY, jsonObject.getString(UIDocActivity.REPOSITORY));
     activityParams.put(UIDocActivity.WORKSPACE, jsonObject.getString(UIDocActivity.WORKSPACE));
     activityParams.put(UIDocActivity.MESSAGE, jsonObject.getString(UIDocActivity.MESSAGE));
     activity.setTemplateParams(activityParams);
     //
     ActivityManager activityManager = CommonsUtils.getService(ActivityManager.class);
     //
     activityManager.saveActivityNoReturn(activity);
     activity = activityManager.getActivity(activity.getId());
   } catch (JSONException je) {
     LOG.error("Error with activity's title data");
   } catch (ActivityStorageException ase) {
     LOG.error("Could not save new data format for document activity.", ase);
   } catch (Exception e) {
     LOG.error("Unknown error  to save document activity.", e);
   }
 }
Пример #4
0
  @MaxQueryNumber(500)
  public void testViewerOwnerPosterActivities() throws Exception {

    //
    ExoSocialActivity activity1 = new ExoSocialActivityImpl();
    activity1.setTitle("title @demo hi");
    activityStorage.saveActivity(rootIdentity, activity1);

    // owner poster comment
    ExoSocialActivity activity2 = new ExoSocialActivityImpl();
    activity2.setTitle("john title");
    activityStorage.saveActivity(rootIdentity, activity2);

    createComment(activity2, demoIdentity, 2);

    List<ExoSocialActivity> list = activityStorage.getActivities(demoIdentity, johnIdentity, 0, 10);

    // only show activity (not comment) posted by demo
    assertEquals(0, list.size());

    // john view root'as --> only show activity (not comment) posted by root
    list = activityStorage.getActivities(rootIdentity, johnIdentity, 0, 10);
    assertEquals(2, list.size());

    tearDownActivityList.addAll(list);
  }
Пример #5
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);
        }
      }
    }
  }
Пример #6
0
 /**
  * Creates a comment to an existing activity.
  *
  * @param existingActivity the existing activity
  * @param posterIdentity the identity who comments
  * @param number the number of comments
  */
 private void createComment(
     ExoSocialActivity existingActivity, Identity posterIdentity, int number) {
   for (int i = 0; i < number; i++) {
     ExoSocialActivity comment = new ExoSocialActivityImpl();
     comment.setTitle("comment " + i);
     comment.setUserId(posterIdentity.getId());
     activityStorage.saveComment(existingActivity, comment);
   }
 }
Пример #7
0
 /**
  * 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);
   }
 }
Пример #8
0
  @Override
  public boolean isValid(NotificationContext ctx) {
    ExoSocialActivity comment = ctx.value(SocialNotificationUtils.ACTIVITY);
    ExoSocialActivity activity = Utils.getActivityManager().getParentActivity(comment);

    Identity spaceIdentity =
        Utils.getIdentityManager()
            .getOrCreateIdentity(SpaceIdentityProvider.NAME, activity.getStreamOwner(), false);
    // if the space is not null and it's not the default activity of space, then it's valid to make
    // notification
    if (spaceIdentity != null && activity.getPosterId().equals(spaceIdentity.getId())) {
      return false;
    }
    return true;
  }
 private void updateActivity(ExoSocialActivity activity, Question question) {
   Map<String, String> activityTemplateParams =
       updateTemplateParams(
           new HashMap<String, String>(),
           question.getId(),
           ActivityUtils.getQuestionRate(question),
           ActivityUtils.getNbOfAnswers(question),
           ActivityUtils.getNbOfComments(question),
           question.getLanguage(),
           question.getLink(),
           Utils.getQuestionPoint(question));
   activity.setTemplateParams(activityTemplateParams);
   activity.setBody(null);
   activity.setTitle(null);
 }
Пример #10
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);
  }
Пример #11
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);
   }
 }
Пример #12
0
  @Override
  protected void tearDown() throws Exception {

    for (ExoSocialActivity activity : tearDownActivityList) {
      activityStorage.deleteActivity(activity.getId());
    }

    for (Relationship relationship : tearDownRelationshipList) {
      relationshipManager.delete(relationship);
    }

    identityStorage.deleteIdentity(rootIdentity);
    identityStorage.deleteIdentity(johnIdentity);
    identityStorage.deleteIdentity(maryIdentity);
    identityStorage.deleteIdentity(demoIdentity);

    super.tearDown();
  }
  @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()));
   }
 }
Пример #15
0
  @Override
  public NotificationInfo makeNotification(NotificationContext ctx) {
    ExoSocialActivity comment = ctx.value(SocialNotificationUtils.ACTIVITY);
    ExoSocialActivity activity = Utils.getActivityManager().getParentActivity(comment);
    // Send notification to all others users who have comment on this activity
    Set<String> receivers = new HashSet<String>();
    Utils.sendToCommeters(receivers, activity.getCommentedIds(), comment.getPosterId());
    Utils.sendToStreamOwner(receivers, activity.getStreamOwner(), comment.getPosterId());
    Utils.sendToActivityPoster(receivers, activity.getPosterId(), comment.getPosterId());

    //
    return NotificationInfo.instance()
        .to(new ArrayList<String>(receivers))
        .with(SocialNotificationUtils.ACTIVITY_ID.getKey(), comment.getId())
        .with(SocialNotificationUtils.POSTER.getKey(), Utils.getUserId(comment.getUserId()))
        .key(getId());
  }
Пример #16
0
  @MaxQueryNumber(1500)
  public void testMySpaceTab() throws Exception {
    // fill 5 activities
    for (int i = 0; i < 5; ++i) {
      ExoSocialActivity activity = new ExoSocialActivityImpl();
      activity.setTitle("title " + i);
      activityStorage.saveActivity(rootIdentity, activity);
    }

    // 5 activities
    Iterator<ExoSocialActivity> it = activityStorage.getUserActivities(rootIdentity).iterator();

    // fill 10 others
    for (int i = 0; i < 10; ++i) {
      ExoSocialActivity activity = new ExoSocialActivityImpl();
      activity.setTitle("title " + i);
      activityStorage.saveActivity(rootIdentity, activity);
      tearDownActivityList.add(activity);
    }

    // creates comments
    while (it.hasNext()) {
      ExoSocialActivity activity = it.next();
      createComment(activity, rootIdentity, 1);
      tearDownActivityList.add(activity);
    }

    List<ExoSocialActivity> activityies = activityStorage.getUserActivities(rootIdentity);
    int i = 0;
    int[] values = {0, 1, 2, 3, 4, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
    for (ExoSocialActivity activity : activityies) {
      assertEquals("title " + values[i], activity.getTitle());
      ++i;
    }
  }
Пример #17
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;
  }
 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;
 }
Пример #19
0
  @MaxQueryNumber(500)
  public void testConnectionsTab() throws Exception {
    publisher =
        (RelationshipPublisher)
            this.getContainer().getComponentInstanceOfType(RelationshipPublisher.class);
    assertNotNull(publisher);
    relationshipManager.addListenerPlugin(publisher);
    connectIdentities(demoIdentity, johnIdentity, true);

    List<ExoSocialActivity> list = activityStorage.getActivitiesOfConnections(demoIdentity, 0, 2);

    assertEquals(1, list.size());
    ExoSocialActivity firstActivity = list.get(0);

    //
    list = activityStorage.getActivitiesOfConnections(demoIdentity, 0, 2);
    assertEquals(1, list.size());

    assertEquals(firstActivity.getTitle(), list.get(0).getTitle());

    tearDownActivityList.add(firstActivity);
    relationshipManager.unregisterListener(publisher);
  }
  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());
  }
  /**
   * 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);
    }
  }
Пример #23
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);
      }
    }
  }
 @Override
 public void moveQuestions(List<String> questions, String catId) {
   ActivityManager activityM = CommonsUtils.getService(ActivityManager.class);
   FAQService faqS = CommonsUtils.getService(FAQService.class);
   IdentityManager identityM = CommonsUtils.getService(IdentityManager.class);
   for (String questionId : questions) {
     try {
       Question question = faqS.getQuestionById(questionId);
       String activityId = faqS.getActivityIdForQuestion(question.getPath());
       Identity streamOwner = null;
       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 questionDetail = ActivityUtils.processContent(question.getDetail());
       Identity spaceIdentity = getSpaceIdentity(catId);
       if (spaceIdentity != null) {
         streamOwner = spaceIdentity;
         templateParams.put(SPACE_GROUP_ID, ActivityUtils.getSpaceGroupId(catId));
       }
       if (activityId != null) {
         ExoSocialActivity oldActivity = activityM.getActivity(activityId);
         activityM.deleteActivity(oldActivity);
         Identity userIdentity =
             identityM.getOrCreateIdentity(
                 OrganizationIdentityProvider.NAME, question.getAuthor(), false);
         ExoSocialActivity activity =
             newActivity(userIdentity, question.getQuestion(), questionDetail, templateParams);
         streamOwner = streamOwner != null ? streamOwner : userIdentity;
         activityM.saveActivityNoReturn(streamOwner, activity);
         faqS.saveActivityIdForQuestion(questionId, activity.getId());
         for (Answer answer : question.getAnswers()) {
           ExoSocialActivity comment = createCommentForAnswer(userIdentity, answer);
           String answerContent = ActivityUtils.processContent(answer.getResponses());
           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());
         }
         for (Comment cm : question.getComments()) {
           String message = ActivityUtils.processContent(cm.getComments());
           ExoSocialActivityImpl comment = new ExoSocialActivityImpl();
           Map<String, String> commentTemplateParams = new HashMap<String, String>();
           commentTemplateParams.put(LINK_KEY, cm.getId());
           comment.setTemplateParams(commentTemplateParams);
           comment.setTitle(message);
           comment.setUserId(userIdentity.getId());
           updateActivity(activity, question);
           activityM.updateActivity(activity);
           activityM.saveComment(activity, comment);
           faqS.saveActivityIdForComment(
               questionId, cm.getId(), question.getLanguage(), comment.getId());
         }
       }
     } catch (Exception e) {
       LOG.error("Failed to move questions " + e.getMessage());
     }
   }
 }
  @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);
   }
 }
  @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);
    }
  }
 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);
 }
Пример #29
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;
    }
  }