com.smartsheet.api.internal.FolderResourcesImpl Maven / Gradle / Ivy
Show all versions of smartsheet-sdk-java Show documentation
/*
* Copyright (C) 2023 Smartsheet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.smartsheet.api.internal;
import com.smartsheet.api.FolderResources;
import com.smartsheet.api.SmartsheetException;
import com.smartsheet.api.internal.util.QueryUtil;
import com.smartsheet.api.models.ContainerDestination;
import com.smartsheet.api.models.Folder;
import com.smartsheet.api.models.PagedResult;
import com.smartsheet.api.models.PaginationParameters;
import com.smartsheet.api.models.enums.CopyExclusion;
import com.smartsheet.api.models.enums.FolderCopyInclusion;
import com.smartsheet.api.models.enums.FolderRemapExclusion;
import com.smartsheet.api.models.enums.SourceInclusion;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* This is the implementation of the FolderResources.
*
* Thread Safety: This class is thread safe because it is immutable and its base class is thread safe.
*/
public class FolderResourcesImpl extends AbstractResources implements FolderResources {
private static final String FOLDERS_PATH = "folders/";
/**
* Constructor.
*
* Parameters: - smartsheet : the SmartsheetImpl
*
* Exceptions: - IllegalArgumentException : if any argument is null
*
* @param smartsheet the smartsheet
*/
public FolderResourcesImpl(SmartsheetImpl smartsheet) {
super(smartsheet);
}
/**
* Get a folder.
*
* It mirrors to the following Smartsheet REST API method: GET /folder/{id}
*
* Exceptions:
* InvalidRequestException : if there is any problem with the REST API request
* AuthorizationException : if there is any problem with the REST API authorization(access token)
* ResourceNotFoundException : if the resource can not be found
* ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
* SmartsheetRestException : if there is any other REST API related error occurred during the operation
* SmartsheetException : if there is any other error occurred during the operation
*
* @param folderId the folder id
* @param includes the include parameters
* @return the folder (note that if there is no such resource, this method will throw ResourceNotFoundException
* rather than returning null)
* @throws SmartsheetException the smartsheet exception
*/
public Folder getFolder(long folderId, EnumSet includes) throws SmartsheetException {
String path = FOLDERS_PATH + folderId;
Map parameters = new HashMap<>();
parameters.put("include", QueryUtil.generateCommaSeparatedList(includes));
path += QueryUtil.generateUrl(null, parameters);
return this.getResource(path, Folder.class);
}
/**
* Update a folder.
*
* It mirrors to the following Smartsheet REST API method: PUT /folder/{id}
*
* Exceptions:
* IllegalArgumentException : if folder is null
* InvalidRequestException : if there is any problem with the REST API request
* AuthorizationException : if there is any problem with the REST API authorization(access token)
* ResourceNotFoundException : if the resource can not be found
* ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
* SmartsheetRestException : if there is any other REST API related error occurred during the operation
* SmartsheetException : if there is any other error occurred during the operation
*
* @param folder the folder to update
* @return the updated folder (note that if there is no such folder, this method will throw
* ResourceNotFoundException rather than returning null).
* @throws SmartsheetException the smartsheet exception
*/
public Folder updateFolder(Folder folder) throws SmartsheetException {
return this.updateResource(FOLDERS_PATH + folder.getId(), Folder.class, folder);
}
/**
* Delete a folder.
*
* It mirrors to the following Smartsheet REST API method: DELETE /folder{id}
*
* Exceptions:
* InvalidRequestException : if there is any problem with the REST API request
* AuthorizationException : if there is any problem with the REST API authorization(access token)
* ResourceNotFoundException : if the resource can not be found
* ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
* SmartsheetRestException : if there is any other REST API related error occurred during the operation
* SmartsheetException : if there is any other error occurred during the operation
*
* @param folderId the folder id
* @throws SmartsheetException the smartsheet exception
*/
public void deleteFolder(long folderId) throws SmartsheetException {
this.deleteResource(FOLDERS_PATH + folderId, Folder.class);
}
/**
* List child folders of a given folder.
*
* It mirrors to the following Smartsheet REST API method: GET /folder/{id}/folders
*
* Parameters: - parentFolderId : the parent folder ID
*
* Exceptions:
* InvalidRequestException : if there is any problem with the REST API request
* AuthorizationException : if there is any problem with the REST API authorization(access token)
* ResourceNotFoundException : if the resource can not be found
* ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
* SmartsheetRestException : if there is any other REST API related error occurred during the operation
* SmartsheetException : if there is any other error occurred during the operation
*
* @param parentFolderId the parent folder id
* @param parameters the parameters for pagination
* @return the child folders (note that empty list will be returned if no child folder found)
* @throws SmartsheetException the smartsheet exception
*/
public PagedResult listFolders(long parentFolderId, PaginationParameters parameters) throws SmartsheetException {
String path = FOLDERS_PATH + parentFolderId + "/folders";
if (parameters != null) {
path += parameters.toQueryString();
}
return this.listResourcesWithWrapper(path, Folder.class);
}
/**
* Create a folder.
*
* It mirrors to the following Smartsheet REST API method: POST /folder/{id}/folders
*
* Exceptions:
* IllegalArgumentException : if folder is null
* InvalidRequestException : if there is any problem with the REST API request
* AuthorizationException : if there is any problem with the REST API authorization(access token)
* ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
* SmartsheetRestException : if there is any other REST API related error occurred during the operation
* SmartsheetException : if there is any other error occurred during the operation
*
* @param parentFolderId the parent folder id
* @param folder the folder to create
* @return the folder
* @throws SmartsheetException the smartsheet exception
*/
public Folder createFolder(long parentFolderId, Folder folder) throws SmartsheetException {
return this.createResource(FOLDERS_PATH + parentFolderId + "/folders", Folder.class, folder);
}
/**
* Creates a copy of the specified Folder.
*
* It mirrors to the following Smartsheet REST API method: POST /folders/{folderId}/copy
*
* Exceptions:
* IllegalArgumentException : if folder is null
* InvalidRequestException : if there is any problem with the REST API request
* AuthorizationException : if there is any problem with the REST API authorization(access token)
* ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
* SmartsheetRestException : if there is any other REST API related error occurred during the operation
* SmartsheetException : if there is any other error occurred during the operation
*
* @param folderId the folder id
* @param containerDestination describes the destination container
* @param includes optional parameters to include
* @param skipRemap optional parameters to exclude
* @return the folder
* @throws SmartsheetException the smartsheet exception
*/
public Folder copyFolder(
long folderId,
ContainerDestination containerDestination,
EnumSet includes,
EnumSet skipRemap
) throws SmartsheetException {
return copyFolder(folderId, containerDestination, includes, skipRemap, null);
}
/**
* Creates a copy of the specified Folder.
*
* It mirrors to the following Smartsheet REST API method: POST /folders/{folderId}/copy
*
* Exceptions:
* IllegalArgumentException : if folder is null
* InvalidRequestException : if there is any problem with the REST API request
* AuthorizationException : if there is any problem with the REST API authorization(access token)
* ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
* SmartsheetRestException : if there is any other REST API related error occurred during the operation
* SmartsheetException : if there is any other error occurred during the operation
*
* @param folderId the folder id
* @param containerDestination describes the destination container
* @param includes optional parameters to include
* @param skipRemap optional parameters to NOT re-map in the new folder
* @param excludes optional parameters to exclude
* @return the folder
* @throws SmartsheetException the smartsheet exception
*/
public Folder copyFolder(long folderId, ContainerDestination containerDestination, EnumSet includes,
EnumSet skipRemap, EnumSet excludes) throws SmartsheetException {
String path = FOLDERS_PATH + folderId + "/copy";
Map parameters = new HashMap<>();
parameters.put("include", QueryUtil.generateCommaSeparatedList(includes));
parameters.put("skipRemap", QueryUtil.generateCommaSeparatedList(skipRemap));
parameters.put("exclude", QueryUtil.generateCommaSeparatedList(excludes));
path += QueryUtil.generateUrl(null, parameters);
return this.createResource(path, Folder.class, containerDestination);
}
/**
* Moves the specified Folder to another location.
*
* It mirrors to the following Smartsheet REST API method: POST /folders/{folderId}/move
*
* Exceptions:
* IllegalArgumentException : if folder is null
* InvalidRequestException : if there is any problem with the REST API request
* AuthorizationException : if there is any problem with the REST API authorization(access token)
* ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
* SmartsheetRestException : if there is any other REST API related error occurred during the operation
* SmartsheetException : if there is any other error occurred during the operation
*
* @param folderId the folder id
* @param containerDestination describes the destination container
* @return the folder
* @throws SmartsheetException the smartsheet exception
*/
public Folder moveFolder(long folderId, ContainerDestination containerDestination) throws SmartsheetException {
String path = FOLDERS_PATH + folderId + "/move";
return this.createResource(path, Folder.class, containerDestination);
}
}