Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [x.x.x] - unreleased
- Support for the POST /2.0/reports/{id}/scope endpoint
- Support for the DELETE /2.0/reports/{id}/scope endpoint
- WireMock integration tests for contract testing for POST /2.0/reports/{id}/scope and DELETE /2.0/reports/{id}/scope endpoints

## [3.10.0] - 2025-12-04
### Added
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/smartsheet/api/ReportResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import com.smartsheet.api.models.PaginationParameters;
import com.smartsheet.api.models.Report;
import com.smartsheet.api.models.ReportPublish;
import com.smartsheet.api.models.ReportScopeInclusion;
import com.smartsheet.api.models.SheetEmail;
import com.smartsheet.api.models.enums.ReportInclusion;

import java.io.OutputStream;
import java.util.Date;
import java.util.EnumSet;
import java.util.List;

/**
* <p>This interface provides methods to access Report resources.</p>
Expand Down Expand Up @@ -218,4 +220,36 @@ Report getReport(
* @return the created ShareResources object
*/
ShareResources shareResources();

/**
* <p>Adds one or more specified sheet or workspace to the report scope.</p>
*
* @param id the ID of the report
* @param scopes A list of one or more objects denoting the sheets or workspaces associated with
* the report to be added to the report scope.
*
* @throws IllegalArgumentException if any argument is null or empty string
* @throws InvalidRequestException if there is any problem with the REST API request
* @throws AuthorizationException if there is any problem with the REST API authorization (access token)
* @throws ResourceNotFoundException if the resource cannot be found
* @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
* @throws SmartsheetException if there is any other error during the operation
*/
void addReportScope(long id, List<ReportScopeInclusion> scopes) throws SmartsheetException;

/**
* <p>Removes one or more specified sheet or workspace from the report scope.</p>
*
* @param id the ID of the report
* @param scopes A list of one or more objects denoting the sheets or workspaces associated with
* the report to be removed from the report scope.
*
* @throws IllegalArgumentException if any argument is null or empty string
* @throws InvalidRequestException if there is any problem with the REST API request
* @throws AuthorizationException if there is any problem with the REST API authorization (access token)
* @throws ResourceNotFoundException if the resource cannot be found
* @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
* @throws SmartsheetException if there is any other error during the operation
*/
void removeReportScope(long id, List<ReportScopeInclusion> scopes) throws SmartsheetException;
}
91 changes: 91 additions & 0 deletions src/main/java/com/smartsheet/api/internal/ReportResourcesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,30 @@
import com.smartsheet.api.ServiceUnavailableException;
import com.smartsheet.api.ShareResources;
import com.smartsheet.api.SmartsheetException;
import com.smartsheet.api.internal.http.HttpEntity;
import com.smartsheet.api.internal.http.HttpMethod;
import com.smartsheet.api.internal.http.HttpRequest;
import com.smartsheet.api.internal.http.HttpResponse;
import com.smartsheet.api.internal.json.JSONSerializerException;
import com.smartsheet.api.internal.util.QueryUtil;
import com.smartsheet.api.models.PagedResult;
import com.smartsheet.api.models.PaginationParameters;
import com.smartsheet.api.models.Report;
import com.smartsheet.api.models.ReportPublish;
import com.smartsheet.api.models.ReportScopeInclusion;
import com.smartsheet.api.models.SheetEmail;
import com.smartsheet.api.internal.util.Util;
import com.smartsheet.api.models.enums.ReportInclusion;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
* This is the implementation of the ReportResources.
Expand All @@ -53,6 +63,7 @@ public class ReportResourcesImpl extends AbstractResources implements ReportReso
*/
private ShareResources shares;

private static final String JSON_CONTENT_TYPE = "application/json";
private static final String REPORTS_PATH = "reports/";

/**
Expand Down Expand Up @@ -313,4 +324,84 @@ public ReportPublish updatePublishStatus(long id, ReportPublish reportPublish) t
public ShareResources shareResources() {
return this.shares;
}

/**
* <p>Adds one or more specified sheet or workspace to the report scope.</p>
*
* @param id the ID of the report
* @param scopes A list of one or more objects denoting the sheets or workspaces associated with
* the report to be added to the report scope.
* @throws IllegalArgumentException if any argument is null or empty
* @throws InvalidRequestException if there is any problem with the REST API request
* @throws AuthorizationException if there is any problem with the REST API authorization (access token)
* @throws ResourceNotFoundException if the resource cannot be found
* @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
* @throws SmartsheetException if there is any other error during the operation
*/
@Override
public void addReportScope(long id, List<ReportScopeInclusion> scopes) throws SmartsheetException {
Util.throwIfNull(scopes);

if (scopes.isEmpty()) {
throw new IllegalArgumentException("scopes should not be empty.");
}

String path = REPORTS_PATH + id + "/scope";
HttpRequest request = createHttpRequest(smartsheet.getBaseURI().resolve(path), HttpMethod.POST);
setRequestEntity(request, scopes);

try {
HttpResponse response = this.smartsheet.getHttpClient().request(request);
if (response.getStatusCode() != 200) {
handleError(response);
}
} finally {
smartsheet.getHttpClient().releaseConnection();
}
}

/**
* <p>Removes one or more specified sheet or workspace from the report scope.</p>
*
* @param id the ID of the report
* @param scopes A list of one or more objects denoting the sheets or workspaces associated with
* the report to be removed from the report scope.
* @throws IllegalArgumentException if any argument is null or empty
* @throws InvalidRequestException if there is any problem with the REST API request
* @throws AuthorizationException if there is any problem with the REST API authorization (access token)
* @throws ResourceNotFoundException if the resource cannot be found
* @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
* @throws SmartsheetException if there is any other error during the operation
*/
@Override
public void removeReportScope(long id, List<ReportScopeInclusion> scopes) throws SmartsheetException {
Util.throwIfNull(scopes);

if (scopes.isEmpty()) {
throw new IllegalArgumentException("scopes should not be empty.");
}

String path = REPORTS_PATH + id + "/scope";
HttpRequest request = createHttpRequest(smartsheet.getBaseURI().resolve(path), HttpMethod.DELETE);
setRequestEntity(request, scopes);

try {
HttpResponse response = this.smartsheet.getHttpClient().request(request);
if (response.getStatusCode() != 200) {
handleError(response);
}
} finally {
smartsheet.getHttpClient().releaseConnection();
}
}

private void setRequestEntity(HttpRequest request, Object object) throws JSONSerializerException {
ByteArrayOutputStream objectBytesStream = new ByteArrayOutputStream();
this.smartsheet.getJsonSerializer().serialize(object, objectBytesStream);
HttpEntity entity = new HttpEntity();
entity.setContentType(JSON_CONTENT_TYPE);
entity.setContent(new ByteArrayInputStream(objectBytesStream.toByteArray()));
entity.setContentLength(objectBytesStream.size());
request.setEntity(entity);
}
}
66 changes: 66 additions & 0 deletions src/main/java/com/smartsheet/api/models/ReportScopeInclusion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2025 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.models;

import com.smartsheet.api.models.enums.ReportAssetType;

/**
* Represents the ReportScopeInclusion object used when adding and removing report scopes.
*/
public class ReportScopeInclusion {
/**
* The type of asset that is included in the report.
*/
private ReportAssetType assetType;

/**
* The id of the asset that is included in the report.
*/
private Long assetId;

/**
* Get the type of asset that is included in the report.
* @return the type of asset that is included in the report
*/
public ReportAssetType getAssetType() {
return assetType;
}

/**
* Set the type of asset that is included in the report.
* @param assetType the type of asset that is included in the report
*/
public void setAssetType(ReportAssetType assetType) {
this.assetType = assetType;
}

/**
* Get the id of the asset that is included in the report.
* @return the id of the asset that is included in the report
*/
public Long getAssetId() {
return assetId;
}

/**
* Set the id of the asset that is included in the report.
* @param assetId the id of the asset that is included in the report
*/
public void setAssetId(Long assetId) {
this.assetId = assetId;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/smartsheet/api/models/enums/ReportAssetType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2025 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.models.enums;

/**
* Represents the type of asset that is included in the report.
*/
public enum ReportAssetType {
/**
* A sheet that is included in the report.
*/
SHEET,

/**
* A workspace that is included in the report.
*/
WORKSPACE
}
Loading