Package org.silverpeas.components.community.model

## Class CommunityOfUsers

- java.lang.Object
- - org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<E,​I>
  - - org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity<CommunityOfUsers,​org.silverpeas.core.persistence.datasource.model.identifier.UuidIdentifier>
    - - org.silverpeas.components.community.model.CommunityOfUsers

- All Implemented Interfaces:
    `Serializable`, `org.silverpeas.core.persistence.datasource.model.IdentifiableEntity`

      @Entity
      public class CommunityOfUsers
      extends org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity<CommunityOfUsers,​org.silverpeas.core.persistence.datasource.model.identifier.UuidIdentifier>

  The community of users for a collaborative space. Users in the community are said to be members of this community, and hence of the space for which the community has been spawned. The space is then said a community space. A community is always managed by a Community application instance; it is like the space for which the community has been created delegates its management to that application instance. The difference between a community space with a collaborative space is in the former the users ask to join the community and then gain access rights to the space. Another difference is the community space is visible to all users of the platform without requiring this space to be public; they have just a view of it and of its presentation page.

  The actual members of a community of users are all included in a specific group of users that is automatically created when the community is spawned. This group of members is kept up-to-date with the users playing a role in the community space. The group of members allows to get in one shot all the actual members of the community. To have a glance about the memberships to the community, passed, actual and pending, please asks to the `CommunityMembershipsProvider` object associated with the community of users.

  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `CommunityOfUsers()` | Constructs a new empty Community instance.
    `` | `CommunityOfUsers​(String componentInstanceId, String spaceId)` | Constructs a new Community instance for the specified resource.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `CommunityMembership` | `addAsAPendingMember​(org.silverpeas.core.admin.user.model.User user)` | Adds the specified user as a member pending his membership to this community to be committed.
    `CommunityMembership` | `addAsMember​(org.silverpeas.core.admin.user.model.User user, org.silverpeas.core.admin.user.model.SilverpeasRole role)` | Adds the specified user as a member of this community of users and with the specified role.
    `void` | `delete()` | Deletes this community of users.
    `boolean` | `equals​(Object obj)` |
    `static List<CommunityOfUsers>` | `getAll()` | Gets all the communities of users existing in Silverpeas.
    `static Optional<CommunityOfUsers>` | `getByComponentInstanceId​(String instanceId)` | Gets the community of users managed by the specified component instance.
    `static Optional<CommunityOfUsers>` | `getBySpaceId​(String spaceId)` | Gets the community of users of the specified collaborative space.
    `URL` | `getCharterURL()` | Gets the URL at which the charter (or a community guide) is located.
    `String` | `getComponentInstanceId()` |
    `org.silverpeas.core.admin.user.model.GroupDetail` | `getGroupOfMembers()` | Gets the group of all the members of this community of users.
    `org.silverpeas.kernel.util.Pair<String,​org.silverpeas.core.admin.space.SpaceHomePageType>` | `getHomePage()` | Gets the home page of this community of users for its members.
    `CommunityMembershipsProvider` | `getMembershipsProvider()` | Gets all the memberships to this community of users.
    `String` | `getSpaceId()` | Gets the unique identifier of the community space, that is to say the collaborative space for which this community of users is.
    `org.silverpeas.core.contribution.model.WysiwygContent` | `getSpacePresentationContent()` | Gets the rich content of the presentation of the community space.
    `Set<org.silverpeas.core.admin.user.model.SilverpeasRole>` | `getUserRoles​(org.silverpeas.core.admin.user.model.User user)` | Gets the roles the given user has on the given community.
    `int` | `hashCode()` |
    `boolean` | `isMember​(org.silverpeas.core.admin.user.model.User user)` | Checks the given user is a member of this community of users by verifying he's playing a role in the community space.
    `CommunityMembership` | `refuseMembership​(org.silverpeas.core.admin.user.model.User user)` | Refuses the membership application of the specified user to this community of users.
    `CommunityMembership` | `removeMembership​(org.silverpeas.core.admin.user.model.User user)` | Removes the membership of the specified user to this community of users.
    `void` | `save()` | Saves the modification in this community of users.
    `void` | `setCharterURL​(String charterURL)` | Sets the URL at which the charter (or a community guide) is located.
    `void` | `setCharterURL​(URL charterURL)` | Sets the URL at which the charter (or a community guide) is located.
    `void` | `setHomePage​(String homePage, org.silverpeas.core.admin.space.SpaceHomePageType homePageType)` | y Sets the home page of this community of users to render to the members.
    `void` | `unsetCharterURL()` | Unsets the charter.

    - ### Methods inherited from class org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity

      `performBeforePersist, performBeforeRemove, performBeforeUpdate`

    - ### Methods inherited from class org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity

      `getId, getNativeId, isPersisted, setId`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CommunityOfUsers

          protected CommunityOfUsers()

      Constructs a new empty Community instance.

    - #### CommunityOfUsers

          public CommunityOfUsers​(String componentInstanceId,
                                  String spaceId)

      Constructs a new Community instance for the specified resource.
      Parameters:
        `componentInstanceId` - the unique identifier of a component instance managing the community.
        `spaceId` - the unique identifier of a resource in Silverpeas for which the community is constructed.

  - ### Method Detail

    - #### getAll

          public static List<CommunityOfUsers> getAll()

      Gets all the communities of users existing in Silverpeas.
      Returns:
        a list of exiting community of users.

    - #### getByComponentInstanceId

          public static Optional<CommunityOfUsers> getByComponentInstanceId​(String instanceId)

      Gets the community of users managed by the specified component instance. If the component instance doesn't exist then nothing is returned.
      Parameters:
        `instanceId` - the unique identifier of a Community application instance.
      Returns:
        maybe a community instance or nothing if the component instance doesn't exist.

    - #### getBySpaceId

          public static Optional<CommunityOfUsers> getBySpaceId​(String spaceId)

      Gets the community of users of the specified collaborative space. Nothing is returned if either the space doesn't exist or it isn't a community space.
      Parameters:
        `spaceId` - the unique identifier of a space in Silverpeas.
      Returns:
        maybe a community instance or nothing if there is no community for the specified space.

    - #### getSpacePresentationContent

          public org.silverpeas.core.contribution.model.WysiwygContent getSpacePresentationContent()

      Gets the rich content of the presentation of the community space. A presentation of the parent space can be defined in order for users out of the community to have a glance of what the community space is about. The goal is to give them enough information for deciding to join the community of the space.
      Returns:
        a `WysiwygContent` instance.

    - #### getComponentInstanceId

          public String getComponentInstanceId()

    - #### getSpaceId

          public String getSpaceId()

      Gets the unique identifier of the community space, that is to say the collaborative space for which this community of users is.
      Returns:
        the unique identifier of a space in Silverpeas.

    - #### isMember

          public boolean isMember​(org.silverpeas.core.admin.user.model.User user)

      Checks the given user is a member of this community of users by verifying he's playing a role in the community space.
      Parameters:
        `user` - `User` instance.
      Returns:
        true whether the user is a member of this community, false otherwise.
      Implementation Requirements:
        a user is member of the community if and only if he plays a non-inherited role in the parent space (the community space) among the following ones: `SilverpeasRole.ADMIN`, `SilverpeasRole.PUBLISHER`, `SilverpeasRole.WRITER` and `SilverpeasRole.READER`.

    - #### getUserRoles

          public Set<org.silverpeas.core.admin.user.model.SilverpeasRole> getUserRoles​(org.silverpeas.core.admin.user.model.User user)

      Gets the roles the given user has on the given community.
      Parameters:
        `user` - `User` instance.
      Returns:
        an unmodifiable set of `SilverpeasRole`.

    - #### getHomePage

          public org.silverpeas.kernel.util.Pair<String,​org.silverpeas.core.admin.space.SpaceHomePageType> getHomePage()

      Gets the home page of this community of users for its members.
      Returns:
        the home page of the community of users for the members.

    - #### getCharterURL

          public URL getCharterURL()

      Gets the URL at which the charter (or a community guide) is located. The charter has to be validated by a user in order to join the community of users.
      Returns:
        the URL of the charter.

    - #### setCharterURL

          public void setCharterURL​(@Nonnull
                                    URL charterURL)

      Sets the URL at which the charter (or a community guide) is located. The charter, once set, has to be validated by a user in order to join the community of users.
      Parameters:
        `charterURL` - the URL of the charter to set.

    - #### setCharterURL

          public void setCharterURL​(String charterURL)
                             throws MalformedURLException

      Sets the URL at which the charter (or a community guide) is located. The charter, once set, has to be validated by a user in order to join the community of users.
      Parameters:
        `charterURL` - the URL of the charter to set.
      Throws:
        `MalformedURLException` - if the specified URL is malformed.

    - #### unsetCharterURL

          public void unsetCharterURL()

      Unsets the charter.
      See Also:
        `setCharterURL(String)`

    - #### setHomePage

          public void setHomePage​(String homePage,
                                  org.silverpeas.core.admin.space.SpaceHomePageType homePageType)

      y Sets the home page of this community of users to render to the members.
      Parameters:
        `homePage` - the home page of the community of users.
        `homePageType` - the type of the home page.

    - #### addAsAPendingMember

          public CommunityMembership addAsAPendingMember​(org.silverpeas.core.admin.user.model.User user)

      Adds the specified user as a member pending his membership to this community to be committed.
      Parameters:
        `user` - the user to add as a pending member.
      Returns:
        the pending membership of the user.

    - #### addAsMember

          public CommunityMembership addAsMember​(org.silverpeas.core.admin.user.model.User user,
                                                 org.silverpeas.core.admin.user.model.SilverpeasRole role)

      Adds the specified user as a member of this community of users and with the specified role. In the case a membership application is pending for the user, his membership is then validated, and he's added in the specifying role in the community space.
      Parameters:
        `user` - the user to add as a committed member.
        `role` - the role the user should play in the community.
      Returns:
        the committed membership of the user.
      Throws:
        `org.silverpeas.kernel.SilverpeasRuntimeException` - if an unexpected error occurs while adding the specified user in this community with the given role.

    - #### refuseMembership

          public CommunityMembership refuseMembership​(org.silverpeas.core.admin.user.model.User user)

      Refuses the membership application of the specified user to this community of users. For doing, the user must have a membership application pending for validation, otherwise an `IllegalStateException` is thrown.
      Parameters:
        `user` - the user for whom his membership application is refused.
      Returns:
        the refused membership of the user to this community of users.

    - #### removeMembership

          @Nullable
          public CommunityMembership removeMembership​(org.silverpeas.core.admin.user.model.User user)

      Removes the membership of the specified user to this community of users. The membership of the user isn't actually deleted; only his membership status is updated to `MembershipStatus.REMOVED`. Once removed, a user isn't anymore member of the community and hence his membership status cannot be updated. In others words, when such a user is added again among the members of the community, a new entry in the memberships table of the community is created for this user; he has a new membership data.
      Parameters:
        `user` - the user to remove from this community.
      Returns:
        the removed membership with the status updated or null if the given user isn't member of this community.
      Implementation Requirements:
        the user will be removed from all the roles of the parent space (the community space) and then his membership status is updated to `MembershipStatus.REMOVED`.

    - #### getMembershipsProvider

          public CommunityMembershipsProvider getMembershipsProvider()

      Gets all the memberships to this community of users.
      Returns:
        a provider of memberships to this community with which fine requests can be invoked to get some parts of the memberships of the users to this community.

    - #### save

          public void save()

      Saves the modification in this community of users. If the community isn't a persisted one, then an `IllegalStateException` exception is thrown.

    - #### delete

          public void delete()

      Deletes this community of users. The memberships to this community should be removed before. Take care this deletion will be definitely. This method should be used only by inner administration tasks.

    - #### getGroupOfMembers

          public org.silverpeas.core.admin.user.model.GroupDetail getGroupOfMembers()

      Gets the group of all the members of this community of users. If this community isn't persisted, null is returned. Otherwise, the group of members of this community of users is returned. In the case such a group isn't yet created, then this method will create it before returning it. If no users are currently members in this community, then the returned group of users will be empty.
      Returns:
        the group of users who are all members of this community or null if this community isn't yet persisted.
      Throws:
        `org.silverpeas.kernel.SilverpeasRuntimeException` - if an error occurs while creating or getting the group of members.

    - #### equals

          public boolean equals​(Object obj)

      Overrides:
        `equals` in class `org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<CommunityOfUsers,​org.silverpeas.core.persistence.datasource.model.identifier.UuidIdentifier>`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<CommunityOfUsers,​org.silverpeas.core.persistence.datasource.model.identifier.UuidIdentifier>`