/** * delete the event activity * * @param event * @param calendarId * @param eventType */ private void deleteActivity(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 { 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 && event.getActivityId() != null) { activityM.deleteActivity(event.getActivityId()); } } catch (ExoSocialException e) { if (LOG.isDebugEnabled()) LOG.error("Can not delete Activity for space when event deleted ", e); } }
/** * 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); } }
/** * Tests {@link SecurityManager#canCommentToActivity(PortalContainer, Identity, * ExoSocialActivity)}. */ public void testCanCommentToActivity() { createActivities(demoIdentity, demoIdentity, 1); ExoSocialActivity demoActivity = activityManager.getActivities(demoIdentity).get(0); boolean demoCommentToDemoActivity = SecurityManager.canCommentToActivity(getContainer(), demoIdentity, demoActivity); assertTrue("demoCommentToDemoActivity must be true", demoCommentToDemoActivity); connectIdentities(maryIdentity, demoIdentity, false); boolean maryCommentToDemoActivity = SecurityManager.canCommentToActivity(getContainer(), maryIdentity, demoActivity); assertFalse("maryCommentToDemoActivity must be false", maryCommentToDemoActivity); connectIdentities(maryIdentity, demoIdentity, true); maryCommentToDemoActivity = SecurityManager.canCommentToActivity(getContainer(), maryIdentity, demoActivity); assertTrue("maryCommentToDemoActivity must be true", maryCommentToDemoActivity); createSpaces(1); Space createdSpace = tearDownSpaceList.get(0); Identity spaceIdentity = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, createdSpace.getPrettyName(), false); tearDownIdentityList.add(spaceIdentity); createActivities(spaceIdentity, spaceIdentity, 1); ExoSocialActivity spaceActivity = activityManager.getActivities(spaceIdentity).get(0); boolean demoCommentToSpaceActivity = SecurityManager.canCommentToActivity(getContainer(), demoIdentity, spaceActivity); assertTrue("demoCommentToSpaceActivity must be true", demoCommentToSpaceActivity); boolean maryCommentToSpaceActivity = SecurityManager.canCommentToActivity(getContainer(), maryIdentity, spaceActivity); assertTrue("maryCommentToSpaceActivity must be true", maryCommentToSpaceActivity); boolean johnCommentToSpaceActivity = SecurityManager.canCommentToActivity(getContainer(), johnIdentity, spaceActivity); assertFalse("johnCommentToSpaceActivity must be false", johnCommentToSpaceActivity); }
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); } }
/** * Tests {@link SecurityManager#canDeleteActivity(PortalContainer, Identity, ExoSocialActivity)}. */ public void testCanDeleteActivity() { createActivities(demoIdentity, demoIdentity, 2); ExoSocialActivity demoActivity = activityManager.getActivities(demoIdentity).get(1); boolean demoDeleteDemoActivity = SecurityManager.canDeleteActivity(getContainer(), demoIdentity, demoActivity); assertTrue("demoDeleteDemoActivity must be true", demoDeleteDemoActivity); boolean maryDeleteDemoActivity = SecurityManager.canDeleteActivity(getContainer(), maryIdentity, demoActivity); assertFalse("maryDeleteDemoActivity must be false", maryDeleteDemoActivity); // demo connects to john createActivities(johnIdentity, johnIdentity, 1); connectIdentities(demoIdentity, johnIdentity, false); ExoSocialActivity johnActivity = activityManager.getActivities(johnIdentity).get(0); boolean demoDeleteJohnActivity = SecurityManager.canDeleteActivity(getContainer(), demoIdentity, johnActivity); assertFalse("demoDeleteDemoActivity must be false", demoDeleteJohnActivity); connectIdentities(demoIdentity, johnIdentity, true); createActivities(demoIdentity, johnIdentity, 1); demoActivity = activityManager.getActivities(johnIdentity).get(0); // newest demoDeleteDemoActivity = SecurityManager.canDeleteActivity(getContainer(), demoIdentity, demoActivity); assertTrue("demoDeleteDemoActivity must be true", demoDeleteDemoActivity); boolean johnDeleteDemoActivity = SecurityManager.canDeleteActivity(getContainer(), johnIdentity, demoActivity); assertTrue("johnDeleteDemoActivity must be true", johnDeleteDemoActivity); // demo, mary, john on a space createSpaces(1); Space createdSpace = tearDownSpaceList.get(0); Identity spaceIdentity = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, createdSpace.getPrettyName(), false); tearDownIdentityList.add(spaceIdentity); createActivities(spaceIdentity, spaceIdentity, 1); ExoSocialActivity spaceActivity = activityManager.getActivities(spaceIdentity).get(0); boolean demoDeleteSpaceActivity = SecurityManager.canDeleteActivity(getContainer(), demoIdentity, spaceActivity); assertTrue("demoDeleteDemoActivity must be true", demoDeleteSpaceActivity); boolean maryDeleteSpaceActivity = SecurityManager.canDeleteActivity(getContainer(), maryIdentity, spaceActivity); assertFalse("maryDeleteSpaceActivity must be false", maryDeleteSpaceActivity); boolean johnDeleteSpaceActivity = SecurityManager.canDeleteActivity(getContainer(), johnIdentity, spaceActivity); assertFalse("johnDeleteSpaceActivity must be false", johnDeleteSpaceActivity); createActivities(demoIdentity, spaceIdentity, 1); ExoSocialActivity demoToSpaceActivity = activityManager.getActivities(spaceIdentity).get(0); boolean demoDeleteDemoToSpaceActivity = SecurityManager.canDeleteActivity(getContainer(), demoIdentity, demoToSpaceActivity); assertTrue("demoDeleteDemoToSpaceActivity must be true", demoDeleteDemoToSpaceActivity); boolean maryDeleteDemoToSpaceActivity = SecurityManager.canDeleteActivity(getContainer(), maryIdentity, demoToSpaceActivity); assertFalse("maryDeleteDemoToSpaceActivity must be false", maryDeleteDemoToSpaceActivity); boolean johnDeleteDemoToSpaceActivity = SecurityManager.canDeleteActivity(getContainer(), johnIdentity, demoToSpaceActivity); assertFalse("johnDeleteDemoToSpaceActivity must be false", johnDeleteDemoToSpaceActivity); }
/** {@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); } } } }
/** * 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()); activityManager.saveComment(existingActivity, comment); comment = activityManager.getComments(existingActivity).get(0); } }
public void removeQuestion(String questionActivityId) { try { ExoContainer exoContainer = ExoContainerContext.getCurrentContainer(); ActivityManager activityM = (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class); ExoSocialActivity activity = activityM.getActivity(questionActivityId); activityM.deleteActivity(activity); } catch (Exception e) { LOG.debug("Fail to remove activity when remove question " + e.getMessage()); } }
public void removeComment( String questionActivityId, String commentActivityId, String questionPath) { try { ExoContainer exoContainer = ExoContainerContext.getCurrentContainer(); ActivityManager activityM = (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class); activityM.deleteComment(questionActivityId, commentActivityId); refreshActivity(questionPath, questionActivityId); } catch (Exception e) { LOG.debug("Fail to remove comment when remove question's comment " + e.getMessage()); } }
private void refreshActivity(String questionId, String questionActivityId) { try { ExoContainer exoContainer = ExoContainerContext.getCurrentContainer(); FAQService faqS = (FAQService) exoContainer.getComponentInstanceOfType(FAQService.class); Question question = faqS.getQuestionById(questionId); ActivityManager activityM = (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class); ExoSocialActivity activity = activityM.getActivity(questionActivityId); updateActivity(activity, question); activityM.updateActivity(activity); } catch (Exception e) { LOG.debug("Fail to refresh activity " + e.getMessage()); } }
/** * 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); } }
public void removeAnswer(String questionPath, String answerActivityId) { try { ExoContainer exoContainer = ExoContainerContext.getCurrentContainer(); FAQService faqS = (FAQService) exoContainer.getComponentInstanceOfType(FAQService.class); String questionActivityId = faqS.getActivityIdForQuestion(questionPath); ActivityManager activityM = (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class); for (String id : answerActivityId.split(",")) { ExoSocialActivity activity = activityM.getActivity(id); if (activity != null) { activityM.deleteComment(questionActivityId, id); } } refreshActivity(questionPath, questionActivityId); } catch (Exception e) { LOG.debug("Fail to remove comment when remove question's answer " + e.getMessage()); } }
/** * 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); } }
public static void deleteFileActivity(Node node) throws RepositoryException { // get services ExoContainer container = ExoContainerContext.getCurrentContainer(); ActivityManager activityManager = (ActivityManager) container.getComponentInstanceOfType(ActivityManager.class); IdentityManager identityManager = (IdentityManager) container.getComponentInstanceOfType(IdentityManager.class); // 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(); activityManager.deleteActivity(nodeActivityID); } catch (Exception e) { LOG.info("No activity is deleted, return no related activity"); } } }
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()); }
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); }
@Override public void tearDown() throws Exception { for (ExoSocialActivity activity : tearDownActivityList) { activityManager.deleteActivity(activity); } for (Space space : tearDownSpaceList) { spaceService.deleteSpace(space); } for (Identity identity : tearDownIdentityList) { identityManager.deleteIdentity(identity); } super.tearDown(); }
@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()); } } }
private void performActivityTest(String userPrefix, String spacePrefix) throws Exception { // String userBaseName = (userPrefix == null ? "bench.user" : userPrefix); String spaceBaseName = (spacePrefix == null ? "bench.space" : spacePrefix); String spacePrettyBaseName = spaceBaseName.replace(".", ""); assertClean(userBaseName, spacePrettyBaseName); // params.put("number", "5"); if (userPrefix != null) { params.put("prefix", userPrefix); } identityInjector.inject(params); // Identity user0 = identityManager.getOrCreateIdentity("organization", userBaseName + "0", false); Identity user1 = identityManager.getOrCreateIdentity("organization", userBaseName + "1", false); Identity user2 = identityManager.getOrCreateIdentity("organization", userBaseName + "2", false); Identity user3 = identityManager.getOrCreateIdentity("organization", userBaseName + "3", false); Identity user4 = identityManager.getOrCreateIdentity("organization", userBaseName + "4", false); // params.put("number", "5"); params.put("fromUser", "1"); params.put("toUser", "3"); params.put("type", "user"); if (userPrefix != null) { params.put("userPrefix", userPrefix); } if (spacePrefix != null) { params.put("spacePrefix", spacePrefix); } activityInjector.inject(params); // assertEquals(0, activityManager.getActivitiesWithListAccess(user0).getSize()); assertEquals(5, activityManager.getActivitiesWithListAccess(user1).getSize()); assertEquals(5, activityManager.getActivitiesWithListAccess(user2).getSize()); assertEquals(5, activityManager.getActivitiesWithListAccess(user3).getSize()); assertEquals(0, activityManager.getActivitiesWithListAccess(user4).getSize()); // params.put("number", "2"); params.put("fromUser", "1"); params.put("toUser", "3"); params.put("type", "user"); if (userPrefix != null) { params.put("userPrefix", userPrefix); } if (spacePrefix != null) { params.put("spacePrefix", spacePrefix); } spaceInjector.inject(params); // Identity space_user0 = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, spacePrettyBaseName + "0", false); Identity space_user1 = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, spacePrettyBaseName + "1", false); Identity space_user2 = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, spacePrettyBaseName + "2", false); Identity space_user3 = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, spacePrettyBaseName + "3", false); Identity space_user4 = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, spacePrettyBaseName + "4", false); // params.put("number", "5"); params.put("fromUser", "1"); params.put("toUser", "3"); params.put("type", "space"); if (userPrefix != null) { params.put("userPrefix", userPrefix); } if (spacePrefix != null) { params.put("spacePrefix", spacePrefix); } activityInjector.inject(params); // assertEquals(1, activityManager.getActivitiesWithListAccess(space_user0).getSize()); assertEquals(6, activityManager.getActivitiesWithListAccess(space_user1).getSize()); assertEquals(6, activityManager.getActivitiesWithListAccess(space_user2).getSize()); assertEquals(6, activityManager.getActivitiesWithListAccess(space_user3).getSize()); assertEquals(1, activityManager.getActivitiesWithListAccess(space_user4).getSize()); // cleanIdentity(userBaseName, 5); cleanSpace(spacePrettyBaseName, 6); }
/** * Tests {@link SecurityManager#canDeleteComment(PortalContainer, Identity, ExoSocialActivity)}. */ public void testCanDeleteComment() { createActivities(demoIdentity, demoIdentity, 1); ExoSocialActivity demoActivity = activityManager.getActivities(demoIdentity).get(0); createComment(demoActivity, demoIdentity, 1); ExoSocialActivity demoComment = activityManager.getComments(demoActivity).get(0); boolean demoDeleteDemoComment = SecurityManager.canDeleteComment(getContainer(), demoIdentity, demoComment); assertTrue("demoDeleteDemoComment must be true", demoDeleteDemoComment); // BUG #3: TODO FIX THIS boolean maryDeleteDemoComment = SecurityManager.canDeleteComment(getContainer(), maryIdentity, demoComment); assertFalse("maryDeleteDemoComment must be false", maryDeleteDemoComment); connectIdentities(maryIdentity, demoIdentity, true); createActivities(maryIdentity, demoIdentity, 1); ExoSocialActivity maryActivity = activityManager.getActivities(demoIdentity).get(0); createComment(maryActivity, demoIdentity, 1); createComment(maryActivity, maryIdentity, 1); List<ExoSocialActivity> comments = activityManager.getComments(maryActivity); assertEquals(2, comments.size()); // BUG of ActivityManager, FIX IT and change these lines below following its changes. /* assertTrue("comments.get(0).getPostedTime() > comments.get(1).getPostedTime() must return true", comments.get(0).getPostedTime() > comments.get(1).getPostedTime()); */ assertTrue( "comments.get(0).getPostedTime() < comments.get(1).getPostedTime() must return true", comments.get(0).getPostedTime() < comments.get(1).getPostedTime()); // must > ExoSocialActivity demoCommentMaryActivity = comments.get(0); // must be 1 ExoSocialActivity maryCommentMaryActivity = comments.get(1); // must be 0 boolean demoDeleteMaryCommentMaryActivity = SecurityManager.canDeleteComment(getContainer(), demoIdentity, maryCommentMaryActivity); assertTrue("demoDeleteMaryCommentMaryActivity must be true", demoDeleteMaryCommentMaryActivity); boolean johnDeleteDemoCommentMaryActivity = SecurityManager.canDeleteComment(getContainer(), johnIdentity, demoCommentMaryActivity); assertFalse( "johnDeleteDemoCommentMaryActivity must be false", johnDeleteDemoCommentMaryActivity); createSpaces(1); Space createdSpace = tearDownSpaceList.get(0); Identity spaceIdentity = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, createdSpace.getPrettyName(), false); createActivities(spaceIdentity, spaceIdentity, 1); ExoSocialActivity spaceActivity = activityManager.getActivities(spaceIdentity).get(0); createComment(spaceActivity, maryIdentity, 1); createComment(spaceActivity, demoIdentity, 1); List<ExoSocialActivity> spaceActivityComments = activityManager.getComments(spaceActivity); ExoSocialActivity maryCommentSpaceActivity = spaceActivityComments.get(0); // must be demo's comment ExoSocialActivity demoCommentSpaceActivity = spaceActivityComments.get(1); // must be mary's comment boolean maryDeleteDemoCommentSpaceActivity = SecurityManager.canDeleteComment(getContainer(), maryIdentity, demoCommentSpaceActivity); assertFalse( "maryDeleteDemoCommentSpaceActivity must be false", maryDeleteDemoCommentSpaceActivity); boolean demoDeleteMaryCommentSpaceActivity = SecurityManager.canDeleteComment(getContainer(), demoIdentity, maryCommentSpaceActivity); assertTrue( "demoDeleteMaryCommentSpaceActivity must be true", demoDeleteMaryCommentSpaceActivity); }
@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 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); } }
@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); } }
/** * Tests {@link SecurityManager#canAccessActivity(PortalContainer, Identity, ExoSocialActivity)}. */ public void testCanAccessActivity() { createActivities(demoIdentity, demoIdentity, 2); ExoSocialActivity activity = activityManager.getActivities(demoIdentity).get(0); assertTrue(SecurityManager.canAccessActivity(getContainer(), johnIdentity, activity)); }
/** * 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); } } }
/** * 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); } }
/** * @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; } }
/** * initialize * * @throws Exception */ public void init() throws Exception { Validate.notNull(ownerName, "ownerName must not be null."); Validate.notNull(viewerName, "viewerName must not be null."); // synchronized (locker) { removeChild(UIActivitiesLoader.class); activitiesLoader = addChild(UIActivitiesLoader.class, null, "UIActivitiesLoader"); } // String activityId = Utils.getActivityID(); if (activityId != null && activityId.length() > 0) { activitiesLoader.setPostContext(PostContext.SINGLE); } else { activitiesLoader.setPostContext(PostContext.USER); } // Check if current display page is My Activity Stream String currentUserName = URLUtils.getCurrentUser(); if (currentUserName != null) { selectedDisplayMode = DisplayMode.OWNER_STATUS; } activitiesLoader.setLoadingCapacity(ACTIVITY_PER_PAGE); activitiesLoader.setOwnerName(ownerName); activitiesLoader.setSelectedDisplayMode(selectedDisplayMode.toString()); // // UIActivitiesContainer activitiesContainer = // activitiesLoader.getChild(UIActivitiesContainer.class); // Identity ownerIdentity = Utils.getIdentityManager() .getOrCreateIdentity(OrganizationIdentityProvider.NAME, ownerName, false); ActivityManager activityManager = Utils.getActivityManager(); ListAccess<ExoSocialActivity> activitiesListAccess = null; switch (this.selectedDisplayMode) { case MY_ACTIVITIES: activitiesListAccess = activityManager.getActivitiesWithListAccess(ownerIdentity); activitiesLoader.setActivityListAccess(activitiesListAccess); break; case OWNER_STATUS: if (isActivityStreamOwner == false) { Identity viewerIdentity = Utils.getIdentityManager() .getOrCreateIdentity(OrganizationIdentityProvider.NAME, viewerName, false); activitiesListAccess = activityManager.getActivitiesWithListAccess(ownerIdentity, viewerIdentity); activitiesLoader.setActivityListAccess(activitiesListAccess); } else { activitiesListAccess = activityManager.getActivitiesWithListAccess(ownerIdentity); activitiesLoader.setActivityListAccess(activitiesListAccess); } break; case CONNECTIONS: activitiesListAccess = activityManager.getActivitiesOfConnectionsWithListAccess(ownerIdentity); activitiesLoader.setActivityListAccess(activitiesListAccess); break; case MY_SPACE: activitiesListAccess = activityManager.getActivitiesOfUserSpacesWithListAccess(ownerIdentity); activitiesLoader.setActivityListAccess(activitiesListAccess); break; default: activitiesListAccess = activityManager.getActivityFeedWithListAccess(ownerIdentity); activitiesLoader.setActivityListAccess(activitiesListAccess); break; } // String lastVisitedModeCookieKey = String.format(Utils.ACTIVITY_STREAM_TAB_SELECTED_COOKIED, Utils.getViewerRemoteId()); String lastVisitedMode = Utils.getCookies(lastVisitedModeCookieKey); this.notChangedMode = lastVisitedMode == null ? true : this.selectedDisplayMode.toString().equals(lastVisitedMode.trim()); // setNumberOfUpdatedActivities(getActivigetActivitiesUpdatedNumtiesUpdatedNum(notChangedMode)); setNumberOfUpdatedActivities(0); // activitiesLoader.init(); }