Package com.logicaldoc.sharefile
Class ShareFile
java.lang.Object
com.logicaldoc.sharefile.ShareFile
Facade over the ShareFile platform.
- Since:
- 8.5.1
- Author:
- Marco Meschieri - LogicalDOC
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateFolder
(String parentId, String name, String description) Create a new folder in the given parent folder.createPath
(String parentId, String path) Creates a pathvoid
deleteItem
(String id) Delete an Item by Id.void
downloadItem
(String id, File file) Download a single Item.This is the first authentication step to be used when it is the first time you connect or when the previous access token has expired.getItemById
(String id) Gets a single Item by Id.getItemByPath
(String parentId, String path) Retrieves an item from its path.getItemPath
(String parentId, String itemId) Constructs the path of a given element, optionally relative to a given parent folder.getRoot()
Get the root level Item for the provided user.long
Get a folder using some of the common query parameters that are available.listFilesInTree
(String folderId) void
Shortcut for retrieveAccessToken(null);void
retrieveAccessToken
(String authorizationToken) This is the second step of the authentication process.void
Saves the ShareFile settingsvoid
setAccessToken
(String accessToken) void
setApiBaseUrl
(String apiBaseUrl) void
setClientId
(String clientId) void
setClientSecret
(String clientSecret) void
setRefreshToken
(String refreshToken) void
setTokenBaseUrl
(String tokenBaseUrl) void
updateItem
(String id, String name, String description) Update the name and description of an Item.void
uploadFile
(String parentId, File file, String filename) Uploads a File using the Standard upload method with a multipart/form mime encoded POST.void
uploadFileIntoPath
(String parentId, String path, File file) Uploads a File using the Standard upload method with a multipart/form mime encoded POST.
-
Constructor Details
-
ShareFile
public ShareFile(com.logicaldoc.core.generic.Generic settings) Constructor- Parameters:
settings
- bean containing the settings
-
ShareFile
public ShareFile(long userId) throws com.logicaldoc.core.PersistenceException Constructor- Parameters:
userId
- identifier of the user- Throws:
com.logicaldoc.core.PersistenceException
- error at data layer
-
-
Method Details
-
getAuthorizationUrl
This is the first authentication step to be used when it is the first time you connect or when the previous access token has expired. Generates the URL to request the authorization code the user must be redirected to. See https://api.sharefile.com/rest/oauth2.aspx- Returns:
- the URL to redirect the user to
-
getCallbackUrl
-
getUserId
public long getUserId() -
getClientId
-
getClientSecret
-
setClientId
-
setApiBaseUrl
-
getApiBaseUrl
-
setClientSecret
-
getAuthBaseUrl
-
getAccessToken
-
setAccessToken
-
getRefreshToken
-
setRefreshToken
-
getTokenBaseUrl
-
setTokenBaseUrl
-
saveSettings
public void saveSettings()Saves the ShareFile settings -
retrieveAccessToken
public void retrieveAccessToken() throws IOException, com.logicaldoc.core.security.authentication.AuthenticationExceptionShortcut for retrieveAccessToken(null);- Throws:
IOException
- A communication errorcom.logicaldoc.core.security.authentication.AuthenticationException
- The user was not authenticated by ShareFile, probably this means you need another autorization code
-
retrieveAccessToken
public void retrieveAccessToken(String authorizationToken) throws IOException, com.logicaldoc.core.security.authentication.AuthenticationException This is the second step of the authentication process. Invoke this method before invoking the others. If a refresh token is available, then it is used to get the access token, otherwise a new access token is asked using the authorization code previously saved bygetAuthorizationUrl()
.
For a test access token. See https://api.sharefile.com/rest/oauth2.aspx- Parameters:
authorizationToken
- optional authorization code- Throws:
IOException
- A communication errorcom.logicaldoc.core.security.authentication.AuthenticationException
- The user was not authenticated by ShareFile, probably this means you need another autorization code
-
getRoot
Get the root level Item for the provided user. To retrieve Children the $expand=Children parameter can be added- Returns:
- list of files
- Throws:
org.apache.hc.client5.http.ClientProtocolException
- error in the communication with the FileShare serverIOException
- error in the communication with the FileShare serverParseException
- bad communication formatURISyntaxException
- Wrong url specification
-
getItemById
Gets a single Item by Id.- Parameters:
id
- - an Item Id- Returns:
- the file
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wrong URL specification
-
getItemByPath
public SFile getItemByPath(String parentId, String path) throws IOException, ParseException, URISyntaxException Retrieves an item from its path. The path is of format /foldername/foldername/filename- Parameters:
parentId
- - optional ID of the parent pathpath
- - an Item path- Returns:
- the file
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wring URL specification
-
getItemPath
public String getItemPath(String parentId, String itemId) throws IOException, ParseException, URISyntaxException Constructs the path of a given element, optionally relative to a given parent folder.- Parameters:
parentId
- ID of the parent folder (leave null for getting the absolute pathitemId
- ID of the item to process- Returns:
- The path of the given element
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wrong URL specification
-
listFilesInTree
public List<SFile> listFilesInTree(String folderId) throws IOException, ParseException, URISyntaxException -
list
Get a folder using some of the common query parameters that are available. This will add the expand, select parameters. The following are used: expand=Children to get any Children of the folder select=Id,Name,Children/Id,Children/Name to get the Id, Name of the folder and the Id, Name of any Children- Parameters:
folderId
- - a Folder Id- Returns:
- list of files
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wring URL composition
-
createPath
public String createPath(String parentId, String path) throws IOException, ParseException, URISyntaxException Creates a path- Parameters:
parentId
- If specified identifies the parent folderpath
- The path to create /folder1/folder2- Returns:
- identifier of the created folder
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wrong URL composition
-
createFolder
public String createFolder(String parentId, String name, String description) throws IOException, ParseException, URISyntaxException Create a new folder in the given parent folder.- Parameters:
parentId
- - the parent Folder in which to create the new Foldername
- - the Folder namedescription
- - the Folder description- Returns:
- The new Folder's ID
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wring URl composition
-
updateItem
public void updateItem(String id, String name, String description) throws IOException, ParseException, URISyntaxException Update the name and description of an Item.- Parameters:
id
- - the id of the Item to updatename
- - the new name of the Itemdescription
- - the new description of the Item- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wrong URL composition
-
deleteItem
Delete an Item by Id.- Parameters:
id
- - the Id of the Item to delete- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wrong URL composition
-
downloadItem
public void downloadItem(String id, File file) throws IOException, ParseException, URISyntaxException Download a single Item.- Parameters:
id
- - the Id of the Item to downloadfile
- - full path including file name of download destination.- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wrong URL composition
-
uploadFileIntoPath
public void uploadFileIntoPath(String parentId, String path, File file) throws IOException, ParseException, URISyntaxException Uploads a File using the Standard upload method with a multipart/form mime encoded POST.- Parameters:
parentId
- - Id of the parent folderpath
- - Relative path of the file /folder/folder/filenamefile
- - the path of the file to upload- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wrong URL composition
-
uploadFile
public void uploadFile(String parentId, File file, String filename) throws IOException, ParseException, URISyntaxException Uploads a File using the Standard upload method with a multipart/form mime encoded POST.- Parameters:
parentId
- - where to upload the Filefile
- - the path of the file to uploadfilename
- - the name of the file to create- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocolURISyntaxException
- Wrong URL composition
-