/**
  * 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);
   }
 }
Пример #2
1
  @GET
  @Path("join/{spaceName}")
  public Response join(
      @PathParam("spaceName") String spaceName,
      @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);
      if (spaceService.getSpaceById(spaceName).getRegistration().equals("open"))
        spaceService.addMember(spaceService.getSpaceById(spaceName), userId);

      return Response.ok("{}", MediaType.APPLICATION_JSON).cacheControl(cacheControl).build();
    } catch (Exception e) {
      log.error("Error in space deny rest service: " + e.getMessage(), e);
      return Response.ok("error").cacheControl(cacheControl).build();
    }
  }
  /**
   * 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);
    }
  }
  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);
  }
Пример #5
0
 public void saveAvatar(UIAvatarUploadContent uiAvatarUploadContent, Space space)
     throws Exception {
   SpaceService spaceService = getSpaceService();
   space.setAvatarAttachment(uiAvatarUploadContent.getAvatarAttachment());
   spaceService.updateSpace(space);
   space.setEditor(Utils.getViewerRemoteId());
   spaceService.updateSpaceAvatar(space);
 }
Пример #6
0
 /**
  * Gets the number of members of a space.
  *
  * @return number of members
  * @throws SpaceException
  */
 public int getSpaceMembersNumber() throws SpaceException {
   SpaceService spaceService = getSpaceService();
   Space space = spaceService.getSpaceByUrl(SpaceUtils.getSpaceUrl());
   if (space != null) {
     return SpaceUtils.countMembers(space);
   } else {
     return 0;
   }
 }
Пример #7
0
 /**
  * Gets the full URL of a space.
  *
  * @return the full URL or an empty String
  */
 public String getSpaceFullURL() {
   SpaceService spaceService = getSpaceService();
   Space space = spaceService.getSpaceByUrl(SpaceUtils.getSpaceUrl());
   if (space != null) {
     return Util.getPortalRequestContext().getPortalURI() + space.getUrl();
   } else {
     return "";
   }
 }
Пример #8
0
 /**
  * Gets space display name.
  *
  * @return space display name or an empty String
  */
 public String getSpaceDisplayName() {
   SpaceService spaceService = getSpaceService();
   Space space = spaceService.getSpaceByUrl(SpaceUtils.getSpaceUrl());
   if (space != null) {
     return space.getDisplayName();
   } else {
     return "";
   }
 }
Пример #9
0
 /**
  * Gets space description.
  *
  * @return space description or an empty String
  */
 public String getSpaceDescription() {
   SpaceService spaceService = getSpaceService();
   Space space = spaceService.getSpaceByUrl(SpaceUtils.getSpaceUrl());
   if (space != null) {
     return space.getDescription();
   } else {
     return "";
   }
 }
Пример #10
0
  /** @throws Exception */
  public void testGetSpaceMembers() throws Exception {

    Identity demoIdentity = populateIdentity("demo");
    Identity johnIdentity = populateIdentity("john");
    Identity maryIdentity = populateIdentity("mary");
    int number = 0;
    Space space = new Space();
    space.setDisplayName("my space " + number);
    space.setPrettyName(space.getDisplayName());
    space.setRegistration(Space.OPEN);
    space.setDescription("add new space " + number);
    space.setType(DefaultSpaceApplicationHandler.NAME);
    space.setVisibility(Space.PUBLIC);
    space.setRegistration(Space.VALIDATION);
    space.setPriority(Space.INTERMEDIATE_PRIORITY);
    space.setGroupId("/space/space" + number);
    space.setUrl(space.getPrettyName());
    String[] spaceManagers = new String[] {demoIdentity.getRemoteId()};
    String[] members = new String[] {demoIdentity.getRemoteId()};
    String[] invitedUsers = new String[] {};
    String[] pendingUsers = new String[] {};
    space.setInvitedUsers(invitedUsers);
    space.setPendingUsers(pendingUsers);
    space.setManagers(spaceManagers);
    space.setMembers(members);

    space = this.createSpaceNonInitApps(space, demoIdentity.getRemoteId(), null);

    Space savedSpace = spaceService.getSpaceByDisplayName(space.getDisplayName());
    assertNotNull("savedSpace must not be null", savedSpace);

    // add member to space
    spaceService.addMember(savedSpace, johnIdentity.getRemoteId());
    spaceService.addMember(savedSpace, maryIdentity.getRemoteId());

    {
      ProfileFilter profileFilter = new ProfileFilter();
      ListAccess<Identity> spaceMembers =
          identityManager.getSpaceIdentityByProfileFilter(
              savedSpace, profileFilter, Type.MEMBER, true);
      assertEquals(3, spaceMembers.getSize());
    }

    // remove member to space
    spaceService.removeMember(savedSpace, johnIdentity.getRemoteId());
    {
      ProfileFilter profileFilter = new ProfileFilter();
      ListAccess<Identity> got =
          identityManager.getSpaceIdentityByProfileFilter(
              savedSpace, profileFilter, Type.MEMBER, true);
      assertEquals(2, got.getSize());
    }

    // clear space
    tearDownSpaceList.add(savedSpace);
  }
Пример #11
0
 /**
  * Gets the uri link to space profile by its pretty name.
  *
  * @param prettyName The pretty name of space.
  * @return the uri link to space @LevelAPI Platform
  * @since 1.2.0 GA
  */
 public static String getSpaceUri(final String prettyName) {
   SpaceService spaceService = getSpaceService();
   Space space = spaceService.getSpaceByPrettyName(prettyName);
   RequestContext ctx = RequestContext.getCurrentInstance();
   if (ctx != null) {
     NodeURL nodeURL = ctx.createURL(NodeURL.TYPE);
     NavigationResource resource =
         new NavigationResource(SiteType.GROUP, space.getGroupId(), space.getUrl());
     return nodeURL.setResource(resource).toString();
   } else {
     return null;
   }
 }
Пример #12
0
 /**
  * initialize administrators, called from {@link #getAdministratorsList()}
  *
  * @throws Exception
  */
 public void initAdministrators() throws Exception {
   SpaceService spaceService = getSpaceService();
   Space space = spaceService.getSpaceByUrl(SpaceUtils.getSpaceUrl());
   administratorsList = new ArrayList<User>();
   OrganizationService orgSrc = getApplicationComponent(OrganizationService.class);
   UserHandler userHandler = orgSrc.getUserHandler();
   String[] managers = space.getManagers();
   if (managers != null) {
     for (String name : managers) {
       administratorsList.add(userHandler.findUserByName(name));
     }
   }
 }
 public boolean isSpaceManager() throws Exception {
   if (spaceService != null) {
     UserNavigation currentUserNavigation =
         Util.getUIPortal().getSelectedUserNode().getNavigation();
     if (SiteType.GROUP.equals((currentUserNavigation.getKey().getType()))
         && currentUserNavigation.getKey().getName().contains("/spaces")) {
       String remoteUser = getUserId();
       String spaceId = currentUserNavigation.getKey().getName();
       Space space = spaceService.getSpaceByGroupId(spaceId);
       return (space != null && spaceService.hasSettingPermission(space, remoteUser));
     }
   }
   return true;
 }
Пример #14
0
 public UISpaceSummaryInfoPortlet() throws Exception {
   iteratorAdministrators =
       createUIComponent(UIPageIterator.class, null, ITERATOR_ADMINISTRATORS_ID);
   addChild(iteratorAdministrators);
   SpaceService spaceService = getSpaceService();
   Space space = spaceService.getSpaceByUrl(SpaceUtils.getSpaceUrl());
   if (space != null) {
     isSpace = true;
   } else {
     if (LOG.isDebugEnabled()) {
       LOG.debug(
           "Can not add the portlet to this page navigation.\nSPACE_URL preference could not be set.");
     }
   }
 }
Пример #15
0
 /**
  * data initialization; set space by spaceUrl to work with
  *
  * @throws Exception
  */
 public void initData() throws Exception {
   String spaceUrl = Utils.getSpaceUrlByContext();
   Space space = spaceSrc.getSpaceByUrl(spaceUrl);
   if (space != null) {
     uiSpaceSetting.setValues(space);
   }
 }
  public void reloadTreeData() throws Exception {
    UserPortal userPortal = Util.getUIPortalApplication().getUserPortalConfig().getUserPortal();
    SpaceService spaceService = getApplicationComponent(SpaceService.class);
    String spaceUrl = Utils.getSpaceUrlByContext();
    Space space = spaceService.getSpaceByUrl(spaceUrl);

    UserNavigation groupNav = SpaceUtils.getGroupNavigation(space.getGroupId());

    setOwner(groupNav.getKey().getName());
    setOwnerType(groupNav.getKey().getTypeName());

    UISpaceNavigationNodeSelector selector = getChild(UISpaceNavigationNodeSelector.class);
    selector.setEdittedNavigation(groupNav);
    selector.setUserPortal(userPortal);
    selector.initTreeData();
  }
Пример #17
0
 /**
  * Gets an instance of the space.
  *
  * @param number the number to be created
  */
 private void createSpaces(int number) {
   for (int i = 0; i < number; i++) {
     Space space = new Space();
     space.setDisplayName("my space " + number);
     space.setRegistration(Space.OPEN);
     space.setDescription("add new space " + number);
     space.setType(DefaultSpaceApplicationHandler.NAME);
     space.setVisibility(Space.PUBLIC);
     space.setRegistration(Space.VALIDATION);
     space.setPriority(Space.INTERMEDIATE_PRIORITY);
     space.setGroupId("/space/space" + number);
     String[] managers = new String[] {"demo", "tom"};
     String[] members = new String[] {"raul", "ghost", "dragon", "demo", "mary"};
     String[] invitedUsers = new String[] {"register1", "john"};
     String[] pendingUsers = new String[] {"jame", "paul", "hacker"};
     space.setInvitedUsers(invitedUsers);
     space.setPendingUsers(pendingUsers);
     space.setManagers(managers);
     space.setMembers(members);
     try {
       spaceService.saveSpace(space, true);
       tearDownSpaceList.add(space);
     } catch (SpaceException e) {
       fail("Could not create a new space");
     }
   }
 }
Пример #18
0
  /**
   * shows my spaceList by userId
   *
   * @param userId
   * @return spaceList
   * @see SpaceList
   */
  private SpaceList showMySpaceList(String userId) {
    SpaceList spaceList = new SpaceList();
    _spaceService = getSpaceService();
    List<Space> mySpaces = null;
    List<SpaceRest> mySpacesRest = new ArrayList<SpaceRest>();
    try {
      mySpaces = _spaceService.getSpaces(userId);

      for (Space space : mySpaces) {
        SpaceRest spaceRest = new SpaceRest(space);
        mySpacesRest.add(spaceRest);
      }

      // fix for issue SOC-2039, sets the space url with new navigation controller
      Router router = this.getRouter(this.getConfigurationPath());

      this.fillSpacesURI(mySpacesRest, router);
    } catch (SpaceException e) {
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (Exception e) {
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }

    spaceList.setSpaces(mySpacesRest);
    return spaceList;
  }
 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;
 }
Пример #20
0
  @Override
  public void tearDown() throws Exception {

    //
    for (String space : spaces) {
      spaceService.deleteSpace(spaceService.getSpaceByPrettyName(SpaceUtils.cleanString(space)));
      Identity i = identityStorage.findIdentity(SpaceIdentityProvider.NAME, space.toLowerCase());
      identityStorage.deleteIdentity(i);
    }

    //
    for (String user : users) {
      organizationService.getUserHandler().removeUser(user, false);
      Identity i = identityStorage.findIdentity(OrganizationIdentityProvider.NAME, user);
      identityStorage.deleteIdentity(i);
    }

    //
    end();
  }
Пример #21
0
  @GET
  @Path("public")
  public Response getPublicSpaces(@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);
      ListAccess<Space> publicSpaces = spaceService.getPublicSpacesWithListAccess(userId);

      JSONArray jsonArray = new JSONArray();

      Space[] spaces = publicSpaces.load(0, publicSpaces.getSize());
      if (spaces != null && spaces.length > 0) {
        for (Space space : spaces) {

          if (space.getVisibility().equals(Space.HIDDEN)) continue;
          if (space.getRegistration().equals(Space.CLOSE)) continue;

          JSONObject json = new JSONObject();
          json.put("name", space.getName());
          json.put("displayName", space.getDisplayName());
          json.put("spaceId", space.getId());
          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();
    }
  }
Пример #22
0
  /**
   * Suggests the space's name for searching.
   *
   * @param uriInfo The requested URI information.
   * @param portalName The name of portal.
   * @param conditionToSearch The input information to search.
   * @param typeOfRelation The type of relationship of the user and the space.
   * @param userId The Id of current user.
   * @param format The format of the returned result, for example, JSON, or XML.
   * @return
   * @throws Exception @LevelAPI Platform
   * @anchor SpacesRestService.suggestSpacenames
   * @deprecated Deprecated from 4.3.x. Replaced by a new API {@link
   *     SpaceRestResourcesV1#getSpaces(org.exoplatform.social.rest.impl.space.UriInfo, String, int,
   *     int, boolean, String)}
   */
  @GET
  @Path("suggest.{format}")
  public Response suggestSpacenames(
      @Context UriInfo uriInfo,
      @PathParam("portalName") String portalName,
      @QueryParam("conditionToSearch") String conditionToSearch,
      @QueryParam("typeOfRelation") String typeOfRelation,
      @QueryParam("currentUser") String userId,
      @PathParam("format") String format)
      throws Exception {

    MediaType mediaType = Util.getMediaType(format);
    SpaceNameList nameList = new SpaceNameList();
    portalContainerName = portalName;
    SpaceService spaceSrv = getSpaceService();

    SpaceListAccess listAccess =
        spaceSrv.getVisibleSpacesWithListAccess(userId, new SpaceFilter(conditionToSearch));
    List<Space> spaces = Arrays.asList(listAccess.load(0, 10));

    for (Space space : spaces) {
      if (ALL_SPACES_STATUS.equals(typeOfRelation)) {
        nameList.addName(space.getDisplayName());
      } else {
        if (PENDING_STATUS.equals(typeOfRelation) && (spaceSrv.isPending(space, userId))) {
          nameList.addName(space.getDisplayName());
          continue;
        } else if (INCOMING_STATUS.equals(typeOfRelation) && (spaceSrv.isInvited(space, userId))) {
          nameList.addName(space.getDisplayName());
          continue;
        } else if (CONFIRMED_STATUS.equals(typeOfRelation) && (spaceSrv.isMember(space, userId))) {
          nameList.addName(space.getDisplayName());
          continue;
        }
      }
    }

    return Util.getResponse(nameList, uriInfo, mediaType, Response.Status.OK);
  }
Пример #23
0
  @GET
  @Path("myspaces")
  public Response request(@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> mySpaces = spaceService.getAccessibleSpaces(userId);

      JSONArray jsonArray = new JSONArray();

      for (Space space : mySpaces) {
        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("members", space.getMembers().length);
        jsonArray.put(json);
      }

      return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON)
          .cacheControl(cacheControl)
          .build();

    } catch (Exception e) {
      log.error("Error in space deny rest service: " + e.getMessage(), e);
      return Response.ok("error").cacheControl(cacheControl).build();
    }
  }
Пример #24
0
 public void tearDown() throws Exception {
   for (Identity identity : tearDownIdentityList) {
     identityManager.deleteIdentity(identity);
   }
   for (Space space : tearDownSpaceList) {
     Identity spaceIdentity =
         identityManager.getOrCreateIdentity(
             SpaceIdentityProvider.NAME, space.getPrettyName(), false);
     if (spaceIdentity != null) {
       identityManager.deleteIdentity(spaceIdentity);
     }
     spaceService.deleteSpace(space);
   }
   super.tearDown();
 }
Пример #25
0
  @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();
  }
Пример #26
0
 /**
  * shows pending spaceList by userId
  *
  * @param userId
  * @return spaceList
  * @see SpaceList
  */
 private SpaceList showPendingSpaceList(String userId) {
   SpaceList spaceList = new SpaceList();
   _spaceService = getSpaceService();
   List<Space> pendingSpaces;
   List<SpaceRest> pendingSpacesRest = new ArrayList<SpaceRest>();
   try {
     pendingSpaces = _spaceService.getPendingSpaces(userId);
     for (Space space : pendingSpaces) {
       SpaceRest spaceRest = new SpaceRest(space);
       pendingSpacesRest.add(spaceRest);
     }
   } catch (SpaceException e) {
     throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
   }
   spaceList.setSpaces(pendingSpacesRest);
   return spaceList;
 }
Пример #27
0
  /**
   * get my spaceList by userId which user is last visited
   *
   * @param userId
   * @param appId
   * @param limit
   * @return
   */
  private SpaceList getLastVisitedSpace(String userId, String appId, int offset, int limit) {
    SpaceList spaceList = new SpaceList();
    _spaceService = getSpaceService();
    List<Space> mySpaces = null;

    try {
      mySpaces = _spaceService.getLastAccessedSpace(userId, appId, offset, limit);
      SpaceRest spaceRest;
      for (Space space : mySpaces) {
        spaceRest = new SpaceRest(space);
        spaceList.addSpace(spaceRest);
      }
    } catch (SpaceException e) {
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (Exception e) {
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
    return spaceList;
  }
Пример #28
0
  private void assertClean(String userBaseName, String spacePrettyBaseName) throws Exception {

    if (userBaseName != null) {
      assertEquals(null, organizationService.getUserHandler().findUserByName(userBaseName + "0"));
      assertEquals(
          null,
          identityStorage.findIdentity(OrganizationIdentityProvider.NAME, userBaseName + "0"));
    }

    if (spacePrettyBaseName != null) {
      assertEquals(
          null,
          spaceService.getSpaceByPrettyName(SpaceUtils.cleanString(spacePrettyBaseName) + "0"));
      assertEquals(
          null,
          identityStorage.findIdentity(
              SpaceIdentityProvider.NAME, spacePrettyBaseName.toLowerCase() + "0"));
    }
  }
Пример #29
0
  /**
   * @param node : activity raised from this source
   * @param activityMsgBundleKey
   * @param isSystemComment
   * @param systemComment the new value of System Posted activity, if (isSystemComment)
   *     systemComment can not be set to null, set to empty string instead of.
   * @throws Exception
   */
  public static ExoSocialActivity postFileActivity(
      Node node,
      String activityMsgBundleKey,
      boolean needUpdate,
      boolean isSystemComment,
      String systemComment)
      throws Exception {
    Object isSkipRaiseAct =
        DocumentContext.getCurrent().getAttributes().get(DocumentContext.IS_SKIP_RAISE_ACT);
    if (isSkipRaiseAct != null && Boolean.valueOf(isSkipRaiseAct.toString())) {
      return null;
    }
    if (!isSupportedContent(node)) {
      return null;
    }

    // get services
    ExoContainer container = ExoContainerContext.getCurrentContainer();
    ActivityManager activityManager =
        (ActivityManager) container.getComponentInstanceOfType(ActivityManager.class);
    IdentityManager identityManager =
        (IdentityManager) container.getComponentInstanceOfType(IdentityManager.class);
    ActivityCommonService activityCommonService =
        (ActivityCommonService) container.getComponentInstanceOfType(ActivityCommonService.class);

    SpaceService spaceService = WCMCoreUtils.getService(SpaceService.class);

    // refine to get the valid node
    refineNode(node);

    // get owner
    String activityOwnerId = getActivityOwnerId(node);
    String nodeActivityID = StringUtils.EMPTY;
    ExoSocialActivity exa = null;
    if (node.isNodeType(ActivityTypeUtils.EXO_ACTIVITY_INFO)) {
      try {
        nodeActivityID = node.getProperty(ActivityTypeUtils.EXO_ACTIVITY_ID).getString();
        exa = activityManager.getActivity(nodeActivityID);
      } catch (Exception e) {
        LOG.info("No activity is deleted, return no related activity");
      }
    }
    ExoSocialActivity activity = null;
    String commentID;
    boolean commentFlag = false;
    if (node.isNodeType(MIX_COMMENT) && activityCommonService.isEditing(node)) {
      if (node.hasProperty(MIX_COMMENT_ID)) {
        commentID = node.getProperty(MIX_COMMENT_ID).getString();
        if (StringUtils.isNotBlank(commentID)) activity = activityManager.getActivity(commentID);
        commentFlag = (activity != null);
      }
    }
    if (activity == null) {
      activity =
          createActivity(
              identityManager,
              activityOwnerId,
              node,
              activityMsgBundleKey,
              FILE_SPACES,
              isSystemComment,
              systemComment);
    }

    if (exa != null) {
      if (commentFlag) {
        Map<String, String> paramsMap = activity.getTemplateParams();
        String paramMessage = paramsMap.get(ContentUIActivity.MESSAGE);
        String paramContent = paramsMap.get(ContentUIActivity.SYSTEM_COMMENT);
        if (!StringUtils.isEmpty(paramMessage)) {
          paramMessage += ActivityCommonService.VALUE_SEPERATOR + activityMsgBundleKey;
          if (StringUtils.isEmpty(systemComment)) {
            paramContent += ActivityCommonService.VALUE_SEPERATOR + " ";
          } else {
            paramContent += ActivityCommonService.VALUE_SEPERATOR + systemComment;
          }
        } else {
          paramMessage = activityMsgBundleKey;
          paramContent = systemComment;
        }
        paramsMap.put(ContentUIActivity.MESSAGE, paramMessage);
        paramsMap.put(ContentUIActivity.SYSTEM_COMMENT, paramContent);
        activity.setTemplateParams(paramsMap);
        activityManager.updateActivity(activity);
      } else {
        activityManager.saveComment(exa, activity);
        if (activityCommonService.isEditing(node)) {
          commentID = activity.getId();
          if (node.canAddMixin(MIX_COMMENT)) node.addMixin(MIX_COMMENT);
          if (node.isNodeType(MIX_COMMENT)) node.setProperty(MIX_COMMENT_ID, commentID);
        }
      }
      return activity;
    } else {
      String spaceName = getSpaceName(node);
      if (spaceName != null
          && spaceName.length() > 0
          && spaceService.getSpaceByPrettyName(spaceName) != null) {
        // post activity to space stream
        Identity spaceIdentity =
            identityManager.getOrCreateIdentity(SpaceIdentityProvider.NAME, spaceName, true);
        activityManager.saveActivityNoReturn(spaceIdentity, activity);
      } else if (activityOwnerId != null && activityOwnerId.length() > 0) {
        // post activity to user status stream
        Identity ownerIdentity =
            identityManager.getOrCreateIdentity(
                OrganizationIdentityProvider.NAME, activityOwnerId, true);
        activityManager.saveActivityNoReturn(ownerIdentity, activity);
      } else {
        return null;
      }
      String activityId = activity.getId();
      if (!StringUtils.isEmpty(activityId)) {
        ActivityTypeUtils.attachActivityId(node, activityId);
      }

      if (node.isNodeType(ActivityTypeUtils.EXO_ACTIVITY_INFO)) {
        try {
          nodeActivityID = node.getProperty(ActivityTypeUtils.EXO_ACTIVITY_ID).getString();
          exa = activityManager.getActivity(nodeActivityID);
        } catch (Exception e) {
          LOG.info("No activity is deleted, return no related activity");
        }
        if (exa != null && !commentFlag && isSystemComment) {
          activityManager.saveComment(exa, activity);
          if (activityCommonService.isEditing(node)) {
            commentID = activity.getId();
            if (node.canAddMixin(MIX_COMMENT)) node.addMixin(MIX_COMMENT);
            if (node.isNodeType(MIX_COMMENT)) node.setProperty(MIX_COMMENT_ID, commentID);
          }
        }
      }

      return activity;
    }
  }
Пример #30
0
  @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();
    }
  }