/** * 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); } }
@Override public void setUp() throws Exception { super.setUp(); identityManager = (IdentityManager) getContainer().getComponentInstanceOfType(IdentityManager.class); relationshipManager = (RelationshipManager) getContainer().getComponentInstanceOfType(RelationshipManager.class); activityManager = (ActivityManager) getContainer().getComponentInstanceOfType(ActivityManager.class); spaceService = (SpaceService) getContainer().getComponentInstanceOfType(SpaceService.class); rootIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "root", false); johnIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "john", false); maryIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "mary", false); demoIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "demo", false); tearDownIdentityList = new ArrayList<Identity>(); tearDownIdentityList.add(rootIdentity); tearDownIdentityList.add(johnIdentity); tearDownIdentityList.add(maryIdentity); tearDownIdentityList.add(demoIdentity); tearDownActivityList = new ArrayList<ExoSocialActivity>(); tearDownRelationshipList = new ArrayList<Relationship>(); tearDownSpaceList = new ArrayList<Space>(); }
private void postActivityToSpace( UIComponent source, WebuiRequestContext requestContext, Map<String, String> activityParams) throws Exception { final UIComposer uiComposer = (UIComposer) source; ActivityManager activityManager = uiComposer.getApplicationComponent(ActivityManager.class); IdentityManager identityManager = uiComposer.getApplicationComponent(IdentityManager.class); SpaceService spaceSrv = uiComposer.getApplicationComponent(SpaceService.class); Space space = spaceSrv.getSpaceByUrl(SpaceUtils.getSpaceUrlByContext()); Identity spaceIdentity = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, space.getPrettyName(), false); String remoteUser = requestContext.getRemoteUser(); ExoSocialActivity activity = saveActivity(activityParams, activityManager, identityManager, spaceIdentity, remoteUser); UISpaceActivitiesDisplay uiDisplaySpaceActivities = (UISpaceActivitiesDisplay) getActivityDisplay(); UIActivitiesContainer activitiesContainer = uiDisplaySpaceActivities.getActivitiesLoader().getActivitiesContainer(); activitiesContainer.addActivity(activity); requestContext.addUIComponentToUpdateByAjax(activitiesContainer); requestContext.addUIComponentToUpdateByAjax(uiComposer); }
/** {@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); } } } }
protected String getIdentityId(String remoteId) { PortalContainer pc = PortalContainer.getInstance(); IdentityManager im = (IdentityManager) pc.getComponentInstanceOfType(IdentityManager.class); Identity id = null; try { id = im.getOrCreateIdentity(OrganizationIdentityProvider.NAME, remoteId); } catch (Exception e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } if (id != null) return id.getId(); return null; }
private void performRelationshipTest(String prefix) throws Exception { // String baseName = (prefix == null ? "bench.user" : prefix); assertClean(baseName, null); // params.put("number", "10"); if (prefix != null) { params.put("prefix", prefix); } identityInjector.inject(params); // Identity user0 = identityManager.getOrCreateIdentity("organization", baseName + "0", false); Identity user1 = identityManager.getOrCreateIdentity("organization", baseName + "1", false); Identity user2 = identityManager.getOrCreateIdentity("organization", baseName + "2", false); Identity user3 = identityManager.getOrCreateIdentity("organization", baseName + "3", false); Identity user4 = identityManager.getOrCreateIdentity("organization", baseName + "4", false); Identity user5 = identityManager.getOrCreateIdentity("organization", baseName + "5", false); Identity user6 = identityManager.getOrCreateIdentity("organization", baseName + "6", false); Identity user7 = identityManager.getOrCreateIdentity("organization", baseName + "7", false); Identity user8 = identityManager.getOrCreateIdentity("organization", baseName + "8", false); Identity user9 = identityManager.getOrCreateIdentity("organization", baseName + "9", false); // params.put("number", "3"); params.put("fromUser", "2"); params.put("toUser", "8"); if (prefix != null) { params.put("prefix", prefix); } relationshipInjector.inject(params); // assertEquals(0, relationshipManager.getConnections(user0).getSize()); assertEquals(0, relationshipManager.getConnections(user1).getSize()); assertEquals(3, relationshipManager.getConnections(user2).getSize()); assertEquals(3, relationshipManager.getConnections(user3).getSize()); assertEquals(3, relationshipManager.getConnections(user4).getSize()); assertEquals(3, relationshipManager.getConnections(user5).getSize()); assertEquals(2, relationshipManager.getConnections(user6).getSize()); assertEquals(2, relationshipManager.getConnections(user7).getSize()); assertEquals(2, relationshipManager.getConnections(user8).getSize()); assertEquals(0, relationshipManager.getConnections(user9).getSize()); // cleanIdentity(baseName, 10); }
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; }
/** * 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); }
/** * 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); }
private void postActivityToUser( UIComponent source, WebuiRequestContext requestContext, Map<String, String> activityParams) throws Exception { UIUserActivitiesDisplay uiUserActivitiesDisplay = (UIUserActivitiesDisplay) getActivityDisplay(); final UIComposer uiComposer = (UIComposer) source; ActivityManager activityManager = uiComposer.getApplicationComponent(ActivityManager.class); IdentityManager identityManager = uiComposer.getApplicationComponent(IdentityManager.class); String ownerName = uiUserActivitiesDisplay.getOwnerName(); Identity ownerIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, ownerName, true); String remoteUser = requestContext.getRemoteUser(); saveActivity(activityParams, activityManager, identityManager, ownerIdentity, remoteUser); }
/** * 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); } }
private Identity getSpaceIdentity(String categoryId) { String spaceGroupId = ActivityUtils.getSpaceGroupId(categoryId); if ("".equals(spaceGroupId)) return null; IdentityManager identityM = (IdentityManager) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(IdentityManager.class); SpaceService spaceService = (SpaceService) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(SpaceService.class); Space space = spaceService.getSpaceByGroupId(spaceGroupId); if (space != null) return identityM.getOrCreateIdentity( SpaceIdentityProvider.NAME, space.getPrettyName(), false); else return null; }
@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(); }
/** Tests {@link SecurityManager#canPostActivity(PortalContainer, Identity, Identity)}. */ public void testCanPostActivity() { boolean demoPostToDemo = SecurityManager.canPostActivity(getContainer(), demoIdentity, demoIdentity); assertTrue("demoPostToDemo must be true", demoPostToDemo); boolean demoPostToJohn = SecurityManager.canPostActivity(getContainer(), demoIdentity, johnIdentity); assertFalse("demoPostToJohn must be false", demoPostToJohn); // demo is connected to mary => they can post activity to each other's activity stream relationshipManager.inviteToConnect(demoIdentity, maryIdentity); boolean demoPostToMary = SecurityManager.canPostActivity(getContainer(), demoIdentity, maryIdentity); boolean maryPostToDemo = SecurityManager.canPostActivity(getContainer(), maryIdentity, demoIdentity); assertFalse("demoPostToMary must be false", demoPostToMary); assertFalse("maryPostToDemo must be false", maryPostToDemo); relationshipManager.confirm(maryIdentity, demoIdentity); tearDownRelationshipList.add(relationshipManager.get(demoIdentity, maryIdentity)); demoPostToMary = SecurityManager.canPostActivity(getContainer(), demoIdentity, maryIdentity); maryPostToDemo = SecurityManager.canPostActivity(getContainer(), maryIdentity, demoIdentity); assertTrue("demoPostToMary must be true", demoPostToMary); assertTrue("maryPostToDemo must be true", maryPostToDemo); // checks user posts to space createSpaces(1); Space createdSpace = tearDownSpaceList.get(0); Identity spaceIdentity = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, createdSpace.getPrettyName(), false); assertNotNull("spaceIdentity must not be null", spaceIdentity); // demo, mary could post activity to this space's activity stream boolean demoPostToSpace = SecurityManager.canPostActivity(getContainer(), demoIdentity, spaceIdentity); assertTrue("demoPostToSpace must be true", demoPostToSpace); boolean maryPostToSpace = SecurityManager.canPostActivity(getContainer(), maryIdentity, spaceIdentity); assertTrue("maryPostToSpace must be false", maryPostToSpace); // john could not boolean johnPostToSpace = SecurityManager.canPostActivity(getContainer(), johnIdentity, spaceIdentity); assertFalse("johnPostToSpace must be false", johnPostToSpace); }
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 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); }
@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()); } } }
/** * 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 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); } }
@GET @Path("suggestions") public Response getSuggestions(@Context SecurityContext sc, @Context UriInfo uriInfo) { try { String userId = getUserId(sc, uriInfo); if (userId == null) { return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build(); } SpaceService spaceService = (SpaceService) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(SpaceService.class); List<Space> suggestedSpaces = spaceService.getPublicSpaces(userId); IdentityManager identityManager = (IdentityManager) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(IdentityManager.class); Identity identity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId); List<Identity> connections = identityManager.getConnections(identity); JSONArray jsonArray = new JSONArray(); for (Space space : suggestedSpaces) { if (space.getVisibility().equals(Space.HIDDEN)) continue; if (space.getRegistration().equals(Space.CLOSE)) continue; List<Identity> identityListMember = new ArrayList<Identity>(); String avatar = space.getAvatarUrl(); if (avatar == null) { avatar = "/social-resources/skin/ShareImages/SpaceImages/SpaceLogoDefault_61x61.gif"; } for (String mem : space.getMembers()) { Identity identityMem = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, mem); identityListMember.add(identityMem); } int k = 0; for (Identity i : identityListMember) { for (Identity j : connections) { if (j.equals(i)) { k++; } } } String spaceType = ""; if (space.getRegistration().equals(Space.OPEN)) { spaceType = "Public"; } else { spaceType = "Private"; } JSONObject json = new JSONObject(); json.put("name", space.getName()); json.put("spaceId", space.getId()); json.put("displayName", space.getDisplayName()); json.put("spaceUrl", space.getUrl()); json.put("avatarUrl", avatar); json.put("registration", space.getRegistration()); json.put("members", space.getMembers().length); json.put("privacy", spaceType); json.put("number", k); jsonArray.put(json); } return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON) .cacheControl(cacheControl) .build(); } catch (Exception e) { log.error("Error in space invitation rest service: " + e.getMessage(), e); return Response.ok("error").cacheControl(cacheControl).build(); } }
@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); } }
/** * 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; } }