public class RestUtils extends Object
Modifier and Type | Field and Description |
---|---|
static com.google.gson.Gson |
GSON |
Constructor and Description |
---|
RestUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
getAcceptLanguage(List<String> langs) |
static String |
getUserAgent(ClientInfo info)
Convert ClientInfo object into a User-Agent header value that can be used by the Bridge
server to filter content appropriately for your app.
|
static boolean |
isConsentCurrent(UserSessionInfo session)
Are all the required consents up-to-date?
|
static boolean |
isUserConsented(UserSessionInfo session)
Are all required consents signed?
|
static UploadRequest |
makeUploadRequestForFile(File file)
Creates an upload request for the given file.
|
static UserSessionInfo |
signInWithSynapse(AuthenticationApi authApi,
SignIn signIn)
Sign in to the Synapse server using a Synapse account, and use this to authenticate with Bridge via OAuth.
|
static UserSessionInfo |
signInWithSynapseDev(AuthenticationApi authApi,
SignIn signIn)
Sign in to Bridge using Synapse Dev.
|
static com.google.gson.JsonElement |
toJSON(Object object)
Convert an object returned as part of the API to a JSON object model
|
static <T> T |
toType(Object object,
Class<T> type)
Downcast an object to a specific subtype where GSON does not know the type during
deserialization.
|
static UploadSession |
upload(ForConsentedUsersApi usersApi,
File file)
Manages the conversation with the Bridge server and Amazon's S3 service to upload an encrypted zip
file to Bridge.
|
static String |
uploadHostedFileToS3(HostedFilesApi fileApi,
String fileGuid,
File file)
A utility method for uploading static asset files that are hosted by Bridge and referenceable
from the AppConfig defined for an application.
|
static String |
uploadStudyLogoToS3(StudiesApi studiesApi,
String studyId,
File file) |
static void |
uploadToS3(File file,
String url)
Uploads the given file to the given S3 URL.
|
static void |
uploadToS3(File file,
String url,
String contentType)
Uploads the given file to the given S3 URL.
|
public static <T> T toType(Object object, Class<T> type)
T
- the target type of the castobject
- - an object to cast to the supplied typetype
- - the target type of the castpublic static com.google.gson.JsonElement toJSON(Object object)
object
- public static boolean isUserConsented(UserSessionInfo session)
session
- A UserSessionInfo objectpublic static boolean isConsentCurrent(UserSessionInfo session)
session
- A UserSessionInfo objectpublic static String getUserAgent(ClientInfo info)
Convert ClientInfo object into a User-Agent header value that can be used by the Bridge server to filter content appropriately for your app.
There are three main stanzas in the Bridge User-Agent header, and all parts of a given stanza must be provided or that stanza will be dropped from the final header:
The ClientManager will provide values for the final two groupings (and enforces settings for the SDK information).
info
- a ClientInfo objectpublic static UploadSession upload(ForConsentedUsersApi usersApi, File file) throws IOException
usersApi
- The ForConsentedUsersApi for the user making the uploadfile
- A File referencing a zip file to uploadIOException
- IOException if an issue occurs during upload. Callers are responsible for re-trying the uploadpublic static UploadRequest makeUploadRequestForFile(File file) throws IOException
file
- File to upload to BridgeIOException
- IOException if an issue occurs during upload. Callers are responsible for re-trying the uploadpublic static void uploadToS3(File file, String url) throws IOException
file
- File to upload to Bridgeurl
- S3 URL to upload to, generally as returned by Bridge Upload SessionIOException
- IOException if an issue occurs during upload. Callers are responsible for re-trying the uploadpublic static void uploadToS3(File file, String url, String contentType) throws IOException
file
- File to upload to Bridgeurl
- S3 URL to upload to, generally as returned by Bridge Upload SessioncontentType
- MIME type of the uploaded file, must match what was sent in the upload requestIOException
- IOException if an issue occurs during upload. Callers are responsible for re-trying the uploadpublic static String uploadHostedFileToS3(HostedFilesApi fileApi, String fileGuid, File file) throws IOException
fileApi
- the FileApi client objectfileGuid
- the GUID of the FileMetadata object of which this file is one revisionfile
- a File reference to the content of the FileRevisionIOException
public static String uploadStudyLogoToS3(StudiesApi studiesApi, String studyId, File file) throws IOException
IOException
public static UserSessionInfo signInWithSynapse(AuthenticationApi authApi, SignIn signIn) throws Exception
authApi
- the Bridge REST authentication API (does not require authentication)signIn
- the sign in form with your Synapse credentials and target app to sign in toException
public static UserSessionInfo signInWithSynapseDev(AuthenticationApi authApi, SignIn signIn) throws Exception
Exception
Copyright © 2022 Sage Bionetworks. All rights reserved.