Class Util
java.lang.Object
org.exoplatform.social.service.rest.Util
Util.java: utility class for rest
.
.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildAbsoluteAvatarURL(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 typestatic voidbuildAbsoluteAvatarURL(IdentityRestOut resultIdentity) Build absolute AvatarURL from in IndentityRestOut if avatar == null or "" use default avatar base on Identity's typestatic final StringconvertTimestampToTimeString(long timestamp) Converts a timestamp string to time string by the pattern: EEE MMM d HH:mm:ss Z yyyy.static final org.exoplatform.social.core.manager.ActivityManagerDeprecated.static final org.exoplatform.social.core.manager.ActivityManagergetActivityManager(String portalContainerName) GetsActivityManagerwith specified portal container name.static org.exoplatform.social.core.identity.model.IdentitygetAuthenticatedUserIdentity(String portalContainerName) Gets UserIdentity of authenticated user.static StringGet base url of rest servicestatic final StringGets base url (host + post) from a context uriInfo.static StringgetCommentsActivityRestUrl(String activityId, String restPath) Get the rest url in order to load all comments of an activitystatic jakarta.servlet.http.HttpServletRequestGets current http servlet request provided by Rest Service Framework.static StringgetDecodeQueryURL(String url) Decode query parameters of string URL Example: - Input:http://google.com?%3Cscript%3E- Output:http://google.com?<script>static final org.exoplatform.social.core.manager.IdentityManagerDeprecated.UsegetIdentityManager(String)instead.static final org.exoplatform.social.core.manager.IdentityManagergetIdentityManager(String portalContainerName) GetsIdentityManagerwith specified portal container name.static javax.ws.rs.core.MediaTypegetMediaType(String format) Deprecated.UsergetMediaType(String, String[])instead.static javax.ws.rs.core.MediaTypegetMediaType(String expectedFormat, String[] supportedFormats) Gets the media type from an expected format string (usually the input) and an array of supported format strings.static StringgetMembersSpaceRestUrl(String id, String role, String restPath) Get the rest url to load members of a space by rolestatic StringgetMimeTypeOfURL(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.static org.exoplatform.social.core.identity.model.IdentitygetOwnerIdentityIdFromActivity(String portalContainerName, org.exoplatform.social.core.activity.model.ExoSocialActivity activity) Gets a owner identity Id from a provided activity.static org.exoplatform.social.core.identity.model.IdentitygetOwnerIdentityIdFromActivity(org.exoplatform.social.core.activity.model.ExoSocialActivity activity) Deprecated.static final org.exoplatform.container.PortalContainergetPortalContainerByName(String portalContainerName) Gets a portal container by its name.static final org.exoplatform.social.core.manager.RelationshipManagerDeprecated.UsegetRelationshipManager(String)instead.static final org.exoplatform.social.core.manager.RelationshipManagergetRelationshipManager(String portalContainerName) GetsRelationshipManagerwith specified portal container name.static StringgetResourceBundleLabel(Locale locale, String label) static javax.ws.rs.core.ResponsegetResponse(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.static StringgetRestUrl(String type, String id, String restPath) Get base url of rest servicestatic final org.exoplatform.social.core.space.spi.SpaceServiceDeprecated.UsegetSpaceService(String)instead.static final org.exoplatform.social.core.space.spi.SpaceServicegetSpaceService(String portalContainerName) GetsSpaceServicewith specified portal container name.static org.exoplatform.social.core.identity.model.IdentitygetUserIdentity(String userName, boolean loadProfile) Deprecated.UsegetUserIdentity(String, String, boolean)instead.static org.exoplatform.social.core.identity.model.IdentitygetUserIdentity(String portalContainerName, String userName, boolean loadProfile) Gets identity from the remote id (user name)static StringGet current user idstatic org.exoplatform.social.core.identity.model.IdentitygetViewerIdentity(String viewerId) Deprecated.UsegetViewerIdentity(String, String)instead.static org.exoplatform.social.core.identity.model.IdentitygetViewerIdentity(String portalContainerName, String viewerId) Gets identity of viewer user (logged-in user).static booleanhasMentioned(org.exoplatform.social.core.activity.model.ExoSocialActivity existingActivity, String identityId) Checks if user is mentioned or not.static booleanCheck if the current user is authenticatedstatic booleanisExternal(String userId) Check if the user is externalstatic booleanisLikedByIdentity(String identityID, org.exoplatform.social.core.activity.model.ExoSocialActivity activity) Check if identityId contained in liked Identity, if yes return true else return false.static booleanisValidURL(String link) Checks a url is in a valid form or not.
-
Method Details
-
isValidURL
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 identityuriInfo- the uri request infomediaType- the media type to be returnedstatus- 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.UsergetMediaType(String, String[])instead. Will be removed by 1.3.xGets 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 formatsupportedFormats- the supported format array- Returns:
- the associated media type
-
getViewerId
Get current user id- Returns:
-
getViewerIdentity
@Deprecated public static org.exoplatform.social.core.identity.model.Identity getViewerIdentity(String viewerId) Deprecated.UsegetViewerIdentity(String, String)instead. Will be removed by 1.3.xGets 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.UsegetUserIdentity(String, String, boolean)instead. Will be removed by 1.3.xGets 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.UsegetIdentityManager(String)instead. Will be removed by 1.3.xGets 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) GetsIdentityManagerwith 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.UsegetSpaceService(String)instead. Will be removed by 1.3.xGetsSpaceServicewith 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) GetsSpaceServicewith 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.UsegetActivityManager(String)instead. Will be removed by 1.3.xGetsActivityManagerwith 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) GetsActivityManagerwith 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.UsegetRelationshipManager(String)instead. Will be removed by 1.3.xGetsRelationshipManagerwith 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) GetsRelationshipManagerwith 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
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.UsegetOwnerIdentityIdFromActivity(String, ExoSocialActivity)instead. Will be removed by 1.3.xGets 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 nameactivity- the activity to gets its owner identity- Returns:
- the owner identity
- Since:
- 1.2.0-GA
-
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
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
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
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
Get base url of rest service- Parameters:
type- the type of rest serviceid- the id of object- Returns:
- base rest url like : http://localhost:8080/rest/v1/social/users/123456
-
getBaseRestUrl
Get base url of rest service- Returns:
- base rest url like : http://localhost:8080/rest
-
getMembersSpaceRestUrl
Get the rest url to load members of a space by role- Parameters:
id- the id of spacerole- the role in the spacerestPath- base REST path- Returns:
- rest url to load members of a space by role
-
getCommentsActivityRestUrl
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
Check if the user is external- Returns:
- true if the user is external
-
getResourceBundleLabel
-
getActivityManager(String)instead.