コード例 #1
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();
    }
  }
コード例 #2
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);
  }