public class RestApiUtil extends Object
| Constructor and Description |
|---|
RestApiUtil() |
| Modifier and Type | Method and Description |
|---|---|
static BadRequestException |
buildBadRequestException(String description)
Returns a new BadRequestException
|
static ConflictException |
buildConflictException(String description)
Returns a new ConflictException
|
static InternalServerErrorException |
buildInternalServerErrorException()
Returns a new InternalServerErrorException
|
static NotFoundException |
buildNotFoundException(String resource,
String id)
Returns a new NotFoundException
|
static PreconditionFailedException |
buildPreconditionFailedRequestException(String description)
Returns a new BadRequestException
|
static String |
getAPIPaginatedURL(Integer offset,
Integer limit,
String query)
Returns the paginated url for APIs API
|
static <T> ErrorDTO |
getConstraintViolationErrorDTO(Set<javax.validation.ConstraintViolation<T>> violations) |
static ErrorDTO |
getErrorDTO(String message,
Long code,
String description)
Returns a generic errorDTO
|
static String |
getLoggedInUsername() |
static org.wso2.carbon.appmgt.api.APIProvider |
getLoggedInUserProvider() |
static String |
getLoggedInUserTenantDomain() |
static Map<String,Integer> |
getPaginationParams(Integer offset,
Integer limit,
Integer size)
Returns the next/previous offset/limit parameters properly when current offset, limit and size parameters are
specified
|
static org.wso2.carbon.appmgt.api.APIProvider |
getProvider(String username) |
static Map<String,String> |
getSearchTerms(String query)
Returns the seach terms of the given query string.
|
static void |
handleBadRequest(String msg,
org.apache.commons.logging.Log log)
Logs the error, builds a BadRequestException with specified details and throws it
|
static void |
handleConflictException(String msg,
org.apache.commons.logging.Log log)
Logs the error, builds a BadRequestException with specified details and throws it
|
static void |
handleInternalServerError(String msg,
Throwable t,
org.apache.commons.logging.Log log)
Logs the error, builds a internalServerErrorException with specified details and throws it
|
static void |
handlePreconditionFailedRequest(String msg,
org.apache.commons.logging.Log log)
Logs the error, builds a BadRequestException with specified details and throws it
|
static void |
handleResourceNotFoundError(String resource,
String id,
Throwable t,
org.apache.commons.logging.Log log)
Logs the error, builds a NotFoundException with specified details and throws it
|
static boolean |
isDueToAuthorizationFailure(Throwable e)
Check if the specified throwable e is due to an authorization failure
|
static boolean |
isDueToResourceNotFound(Throwable e)
Check if the specified throwable e is happened as the required resource cannot be found
|
static boolean |
isExistingRole(String roleName) |
static boolean |
isExistingUser(String username) |
static boolean |
isUUID(String apiId)
Check whether the specified apiId is of type UUID
|
static String |
readFileContentType(String filePath)
Read the given file's content type
|
static File |
readFileFromStorage(String fileName)
Read the given file content from file storage
|
static void |
transferFile(InputStream uploadedInputStream,
String newFileName,
String storageLocation)
This method uploads a given file to specified location
|
public static <T> ErrorDTO getConstraintViolationErrorDTO(Set<javax.validation.ConstraintViolation<T>> violations)
public static org.wso2.carbon.appmgt.api.APIProvider getLoggedInUserProvider()
throws org.wso2.carbon.appmgt.api.AppManagementException
org.wso2.carbon.appmgt.api.AppManagementExceptionpublic static String getLoggedInUsername()
public static org.wso2.carbon.appmgt.api.APIProvider getProvider(String username) throws org.wso2.carbon.appmgt.api.AppManagementException
org.wso2.carbon.appmgt.api.AppManagementExceptionpublic static void handleBadRequest(String msg, org.apache.commons.logging.Log log) throws BadRequestException
msg - error messagelog - Log instanceBadRequestExceptionpublic static void handleConflictException(String msg, org.apache.commons.logging.Log log) throws ConflictException
msg - error messagelog - Log instanceBadRequestExceptionConflictExceptionpublic static void handlePreconditionFailedRequest(String msg, org.apache.commons.logging.Log log) throws BadRequestException
msg - error messagelog - Log instanceBadRequestExceptionpublic static BadRequestException buildBadRequestException(String description)
description - description of the exceptionpublic static ConflictException buildConflictException(String description)
description - description of the exceptionpublic static PreconditionFailedException buildPreconditionFailedRequestException(String description)
description - description of the exceptionpublic static ErrorDTO getErrorDTO(String message, Long code, String description)
message - specifies the error messagepublic static String getAPIPaginatedURL(Integer offset, Integer limit, String query)
offset - starting indexlimit - max number of objects returnedquery - search query valuepublic static Map<String,Integer> getPaginationParams(Integer offset, Integer limit, Integer size)
offset - current starting indexlimit - current max recordssize - maximum index possiblepublic static void handleInternalServerError(String msg, Throwable t, org.apache.commons.logging.Log log) throws InternalServerErrorException
msg - error messaget - Throwable instancelog - Log instanceInternalServerErrorExceptionpublic static InternalServerErrorException buildInternalServerErrorException()
public static String getLoggedInUserTenantDomain()
public static boolean isDueToResourceNotFound(Throwable e)
e - throwable to checkpublic static boolean isDueToAuthorizationFailure(Throwable e)
e - throwable to checkpublic static void handleResourceNotFoundError(String resource, String id, Throwable t, org.apache.commons.logging.Log log) throws NotFoundException
resource - requested resourceid - id of resourcet - Throwable instancelog - Log instanceNotFoundExceptionpublic static NotFoundException buildNotFoundException(String resource, String id)
resource - Resource typeid - identifier of the resourcepublic static boolean isUUID(String apiId)
apiId - api identifierpublic static void transferFile(InputStream uploadedInputStream, String newFileName, String storageLocation) throws org.wso2.carbon.appmgt.api.AppManagementException
uploadedInputStream - input stream of the filenewFileName - name of the file to be createdstorageLocation - destination of the new fileorg.wso2.carbon.appmgt.api.AppManagementException - if the file transfer failspublic static boolean isExistingUser(String username)
public static boolean isExistingRole(String roleName)
public static Map<String,String> getSearchTerms(String query)
query - public static File readFileFromStorage(String fileName) throws org.wso2.carbon.appmgt.api.AppManagementException
fileName - name of the file to be readorg.wso2.carbon.appmgt.api.AppManagementExceptionCopyright © 2016 WSO2. All rights reserved.