java.lang.Object
org.exoplatform.social.service.rest.Util

public final class Util extends Object
Util.java: utility class for rest
.
  • Method Details

    • isValidURL

      public static boolean isValidURL(String link)
      Checks a url is in a valid form or not.
      Parameters:
      link -
      Returns:
    • getResponse

      public static javax.ws.rs.core.Response getResponse(Object entity, javax.ws.rs.core.UriInfo uriInfo, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.Response.Status status)
      Gets the response object constructed from the provided params.
      Parameters:
      entity - the identity
      uriInfo - the uri request info
      mediaType - the media type to be returned
      status - the status code
      Returns:
      response the response object
    • getMediaType

      @Deprecated public static javax.ws.rs.core.MediaType getMediaType(String format) throws javax.ws.rs.WebApplicationException
      Deprecated.
      User getMediaType(String, String[]) instead. Will be removed by 1.3.x
      Gets mediaType from string format. Currently supports json and xml only.
      Parameters:
      format -
      Returns:
      mediaType of matched or throw BAD_REQUEST exception
      Throws:
      javax.ws.rs.WebApplicationException
    • getMediaType

      public static javax.ws.rs.core.MediaType getMediaType(String expectedFormat, String[] supportedFormats)
      Gets the media type from an expected format string (usually the input) and an array of supported format strings. If expectedFormat is not found in the supported format array, Status.UNSUPPORTED_MEDIA_TYPE is thrown. The supported format must include one of those format: json, xml, atom or rss, otherwise Status.NOT_ACCEPTABLE could be thrown.
      Parameters:
      expectedFormat - the expected input format
      supportedFormats - the supported format array
      Returns:
      the associated media type
    • getViewerId

      public static String getViewerId()
      Get current user id
      Returns:
    • getViewerIdentity

      @Deprecated public static org.exoplatform.social.core.identity.model.Identity getViewerIdentity(String viewerId)
      Deprecated.
      Use getViewerIdentity(String, String) instead. Will be removed by 1.3.x
      Gets identity of viewer user (logged-in user). Do not load profile.
      Returns:
      identity
      Since:
      1.2.0 GA
    • getViewerIdentity

      public static org.exoplatform.social.core.identity.model.Identity getViewerIdentity(String portalContainerName, String viewerId)
      Gets identity of viewer user (logged-in user). Do not load profile.
      Returns:
      identity
      Since:
      1.2.3
    • getUserIdentity

      @Deprecated public static org.exoplatform.social.core.identity.model.Identity getUserIdentity(String userName, boolean loadProfile)
      Deprecated.
      Use getUserIdentity(String, String, boolean) instead. Will be removed by 1.3.x
      Gets identity from the remote id (user name)
      Parameters:
      userName -
      loadProfile -
      Returns:
      identity
      Since:
      1.2.0 GA
    • getUserIdentity

      public static org.exoplatform.social.core.identity.model.Identity getUserIdentity(String portalContainerName, String userName, boolean loadProfile)
      Gets identity from the remote id (user name)
      Parameters:
      portalContainerName -
      userName -
      loadProfile -
      Returns:
      identity
      Since:
      1.2.3
    • getIdentityManager

      @Deprecated public static final org.exoplatform.social.core.manager.IdentityManager getIdentityManager()
      Deprecated.
      Use getIdentityManager(String) instead. Will be removed by 1.3.x
      Gets identityManager with default portal container.
      Returns:
      identityManager
      Since:
      1.2.0 GA
    • getIdentityManager

      public static final org.exoplatform.social.core.manager.IdentityManager getIdentityManager(String portalContainerName)
      Gets IdentityManager with specified portal container name.
      Parameters:
      portalContainerName - the specified portal container name
      Returns:
      the identity manager
      Since:
      1.2.0-GA
    • getSpaceService

      @Deprecated public static final org.exoplatform.social.core.space.spi.SpaceService getSpaceService()
      Deprecated.
      Use getSpaceService(String) instead. Will be removed by 1.3.x
      Gets SpaceService with default portal container.
      Returns:
      the space service
      Since:
      1.2.0-GA
    • getSpaceService

      public static final org.exoplatform.social.core.space.spi.SpaceService getSpaceService(String portalContainerName)
      Gets SpaceService with specified portal container name.
      Parameters:
      portalContainerName - the specified portal container name
      Returns:
      the space service
      Since:
      1.2.0-GA
    • getActivityManager

      @Deprecated public static final org.exoplatform.social.core.manager.ActivityManager getActivityManager()
      Deprecated.
      Use getActivityManager(String) instead. Will be removed by 1.3.x
      Gets ActivityManager with default portal container.
      Returns:
      the activity manager
      Since:
      1.2.0-GA
    • getActivityManager

      public static final org.exoplatform.social.core.manager.ActivityManager getActivityManager(String portalContainerName)
      Gets ActivityManager with specified portal container name.
      Parameters:
      portalContainerName - the specified portal container
      Returns:
      the activity manager
      Since:
      1.2.0-GA
    • getRelationshipManager

      @Deprecated public static final org.exoplatform.social.core.manager.RelationshipManager getRelationshipManager()
      Deprecated.
      Use getRelationshipManager(String) instead. Will be removed by 1.3.x
      Gets RelationshipManager with default portal container.
      Returns:
      the relationship manager
      Since:
      1.2.0-GA
    • getRelationshipManager

      public static final org.exoplatform.social.core.manager.RelationshipManager getRelationshipManager(String portalContainerName)
      Gets RelationshipManager with specified portal container name.
      Parameters:
      portalContainerName - the specified portal container name
      Returns:
      the relationship manager
      Since:
      1.2.0-GA
    • getPortalContainerByName

      public static final org.exoplatform.container.PortalContainer getPortalContainerByName(String portalContainerName)
      Gets a portal container by its name.
      Parameters:
      portalContainerName - the specified portal container name
      Returns:
      the portal container name
      Since:
      1.2.3
    • convertTimestampToTimeString

      public static final String convertTimestampToTimeString(long timestamp)
      Converts a timestamp string to time string by the pattern: EEE MMM d HH:mm:ss Z yyyy.
      Parameters:
      timestamp - the timestamp to convert
      Returns:
      the time string
    • getOwnerIdentityIdFromActivity

      @Deprecated public static org.exoplatform.social.core.identity.model.Identity getOwnerIdentityIdFromActivity(org.exoplatform.social.core.activity.model.ExoSocialActivity activity)
      Deprecated.
      Use getOwnerIdentityIdFromActivity(String, ExoSocialActivity) instead. Will be removed by 1.3.x
      Gets a owner identity Id from a provided activity.
      Parameters:
      activity - the activity to gets its owner identity
      Returns:
      the owner identity
      Since:
      1.2.3
    • getOwnerIdentityIdFromActivity

      public static org.exoplatform.social.core.identity.model.Identity getOwnerIdentityIdFromActivity(String portalContainerName, org.exoplatform.social.core.activity.model.ExoSocialActivity activity)
      Gets a owner identity Id from a provided activity.
      Parameters:
      portalContainerName - the portal container name
      activity - the activity to gets its owner identity
      Returns:
      the owner identity
      Since:
      1.2.0-GA
    • getBaseUrl

      public static final String getBaseUrl()
      Gets base url (host + post) from a context uriInfo.
      For example: http://localhost:8080
      Returns:
      the base url (host + port)
    • getCurrentServletRequest

      public static jakarta.servlet.http.HttpServletRequest getCurrentServletRequest()
      Gets current http servlet request provided by Rest Service Framework.
      Returns:
      the current http servlet request
    • buildAbsoluteAvatarURL

      public static void buildAbsoluteAvatarURL(IdentityRestOut resultIdentity)
      Build absolute AvatarURL from in IndentityRestOut if avatar == null or "" use default avatar base on Identity's type
      Parameters:
      resultIdentity -
    • buildAbsoluteAvatarURL

      public static String buildAbsoluteAvatarURL(org.exoplatform.social.core.identity.model.Identity resultIdentity)
      Build absolute AvatarURL from in IndentityRestOut if avatar == null or "" use default avatar base on Identity's type
      Parameters:
      resultIdentity -
    • getAuthenticatedUserIdentity

      public static org.exoplatform.social.core.identity.model.Identity getAuthenticatedUserIdentity(String portalContainerName)
      Gets UserIdentity of authenticated user.
      Parameters:
      portalContainerName - current portal container name
      Returns:
      Identity of user, if not authenticated return null
    • isLikedByIdentity

      public static boolean isLikedByIdentity(String identityID, org.exoplatform.social.core.activity.model.ExoSocialActivity activity)
      Check if identityId contained in liked Identity, if yes return true else return false.
      Parameters:
      identityID -
      activity -
      Returns:
    • getMimeTypeOfURL

      public static String getMimeTypeOfURL(String urlString)
      Try to guess the mime type of url using the Content-Type from header, the extension of filename or some bytes of content. This method can be wrong if server don't provide the Content-Type, wrong or unknown file extension. So use it as your risk.
      Parameters:
      urlString -
      Returns:
      Since:
      1.2.7
    • getDecodeQueryURL

      public static String getDecodeQueryURL(String url)
      Decode query parameters of string URL Example: - Input: http://google.com?%3Cscript%3E - Output: http://google.com?<script>
      Parameters:
      url - The string URL to decode
      Returns:
      The URL decoded query parameters
      Since:
      4.1.0
    • hasMentioned

      public static boolean hasMentioned(org.exoplatform.social.core.activity.model.ExoSocialActivity existingActivity, String identityId)
      Checks if user is mentioned or not.
      Parameters:
      existingActivity - Activity to check.
      identityId - Identity Id to check mentioned or not.
      Returns:
      true if input user has been mentioned in activity.
    • getRestUrl

      public static String getRestUrl(String type, String id, String restPath)
      Get base url of rest service
      Parameters:
      type - the type of rest service
      id - the id of object
      Returns:
      base rest url like : http://localhost:8080/rest/v1/social/users/123456
    • getBaseRestUrl

      public static String getBaseRestUrl()
      Get base url of rest service
      Returns:
      base rest url like : http://localhost:8080/rest
    • getMembersSpaceRestUrl

      public static String getMembersSpaceRestUrl(String id, String role, String restPath)
      Get the rest url to load members of a space by role
      Parameters:
      id - the id of space
      role - the role in the space
      restPath - base REST path
      Returns:
      rest url to load members of a space by role
    • getCommentsActivityRestUrl

      public static String getCommentsActivityRestUrl(String activityId, String restPath)
      Get the rest url in order to load all comments of an activity
      Parameters:
      activityId - activity's id
      Returns:
    • isAnonymous

      public static boolean isAnonymous()
      Check if the current user is authenticated
      Returns:
      true if user not authenticated
    • isExternal

      public static boolean isExternal(String userId)
      Check if the user is external
      Returns:
      true if the user is external
    • getResourceBundleLabel

      public static String getResourceBundleLabel(Locale locale, String label)