From af1fc8aeac4ce147d70badcba9d003aa85f99103 Mon Sep 17 00:00:00 2001 From: Ryan Quinn Date: Thu, 16 Jun 2022 09:51:47 -0700 Subject: [PATCH] add exclude widget parameter for get dashboard endpoint --- CHANGELOG.md | 1 + .../com/smartsheet/api/SightResources.java | 22 ++++++++++ .../api/internal/SightResourcesImpl.java | 30 ++++++++++++++ .../api/models/enums/SightExclusion.java | 40 +++++++++++++++++++ .../api/internal/SightResourcesImplTest.java | 21 +++++++++- .../internal/http/DefaultHttpClientTest.java | 2 +- src/test/resources/getSight.json | 28 +++++++++++++ .../resources/getSightWithoutWidgets.json | 10 +++++ 8 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/smartsheet/api/models/enums/SightExclusion.java create mode 100644 src/test/resources/getSight.json create mode 100644 src/test/resources/getSightWithoutWidgets.json diff --git a/CHANGELOG.md b/CHANGELOG.md index d5268e7a3..90eb02e98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ 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). ## [Unreleased] +- support exclusions for sights ## [2.146.0] - 2021-11-12 ### Added diff --git a/src/main/java/com/smartsheet/api/SightResources.java b/src/main/java/com/smartsheet/api/SightResources.java index 9c7c05567..65393017b 100644 --- a/src/main/java/com/smartsheet/api/SightResources.java +++ b/src/main/java/com/smartsheet/api/SightResources.java @@ -25,6 +25,7 @@ import com.smartsheet.api.models.PaginationParameters; import com.smartsheet.api.models.Sight; import com.smartsheet.api.models.SightPublish; +import com.smartsheet.api.models.enums.SightExclusion; import com.smartsheet.api.models.enums.SightInclusion; import java.util.Date; @@ -90,6 +91,7 @@ public interface SightResources { * * @param sightId the Id of the Sight * @param level compatibility level + * @param includes optional parameters to include * @return the Sight resource. * @throws IllegalArgumentException if any argument is null or empty string * @throws InvalidRequestException if there is any problem with the REST API request @@ -100,6 +102,26 @@ public interface SightResources { */ public Sight getSight(long sightId, EnumSet includes, Integer level) throws SmartsheetException; + /** + *

Get a specified Sight.

+ * + *

It mirrors to the following Smartsheet REST API method: GET /sights/{sightId}

+ * + * @param sightId the Id of the Sight + * @param level compatibility level + * @param includes optional parameters to include + * @param excludes optional parameters to exclude + * @return the Sight resource. + * @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 + */ + public Sight getSight(long sightId, EnumSet includes, EnumSet excludes + , Integer level) throws SmartsheetException; + /** *

Get a specified Sight.

* diff --git a/src/main/java/com/smartsheet/api/internal/SightResourcesImpl.java b/src/main/java/com/smartsheet/api/internal/SightResourcesImpl.java index 3ef807e55..afc8cd493 100644 --- a/src/main/java/com/smartsheet/api/internal/SightResourcesImpl.java +++ b/src/main/java/com/smartsheet/api/internal/SightResourcesImpl.java @@ -39,6 +39,7 @@ import com.smartsheet.api.models.PaginationParameters; import com.smartsheet.api.models.Sight; import com.smartsheet.api.models.SightPublish; +import com.smartsheet.api.models.enums.SightExclusion; import com.smartsheet.api.models.enums.SightInclusion; public class SightResourcesImpl extends AbstractResources implements SightResources { @@ -150,6 +151,35 @@ public Sight getSight(long sightId, EnumSet includes, Integer le return this.getResource(path, Sight.class); } + /** + * Get a specified Sight. + * + * It mirrors to the following Smartsheet REST API method: GET /sights/{sightId} + * + * @param sightId the Id of the Sight + * @param level compatibility level + * @param includes optional parameters to include + * @param excludes optional parameters to exclude + * @return the Sight resource. + * @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 + */ + public Sight getSight(long sightId, EnumSet includes, EnumSet excludes, Integer level) throws SmartsheetException { + String path = "sights/" + sightId; + + HashMap parameters = new HashMap(); + parameters.put("level", level); + parameters.put("include", QueryUtil.generateCommaSeparatedList(includes)); + parameters.put("exclude", QueryUtil.generateCommaSeparatedList(excludes)); + path += QueryUtil.generateUrl(null, parameters); + + return this.getResource(path, Sight.class); + }; + /** * Update a specified Sight. * diff --git a/src/main/java/com/smartsheet/api/models/enums/SightExclusion.java b/src/main/java/com/smartsheet/api/models/enums/SightExclusion.java new file mode 100644 index 000000000..e6bd6cb36 --- /dev/null +++ b/src/main/java/com/smartsheet/api/models/enums/SightExclusion.java @@ -0,0 +1,40 @@ +package com.smartsheet.api.models.enums; + +/* + * #[license] + * Smartsheet SDK for Java + * %% + * Copyright (C) 2019 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. + * %[license] + */ + +/** + * Represents specific objects that can be excluded in some responses. + */ +public enum SightExclusion { + WIDGET("widget") + ; + + String exclusion; + + SightExclusion(String exclusion) { + this.exclusion = exclusion; + } + + @Override + public String toString() { + return exclusion; + } +} diff --git a/src/test/java/com/smartsheet/api/internal/SightResourcesImplTest.java b/src/test/java/com/smartsheet/api/internal/SightResourcesImplTest.java index e421bab14..646149dcd 100644 --- a/src/test/java/com/smartsheet/api/internal/SightResourcesImplTest.java +++ b/src/test/java/com/smartsheet/api/internal/SightResourcesImplTest.java @@ -22,9 +22,19 @@ import com.smartsheet.api.SmartsheetException; import com.smartsheet.api.internal.http.DefaultHttpClient; +import com.smartsheet.api.models.Sight; +import com.smartsheet.api.models.enums.SightExclusion; +import com.smartsheet.api.models.enums.SightInclusion; import org.junit.Before; import org.junit.Test; +import java.awt.image.ImagingOpException; +import java.io.File; +import java.io.IOException; +import java.util.EnumSet; + +import static org.junit.Assert.assertNotNull; + public class SightResourcesImplTest extends ResourcesImplBase { private SightResourcesImpl sightResourcesImpl; @@ -39,4 +49,13 @@ public void before() { public void updateWithNullSight() throws SmartsheetException { sightResourcesImpl.updateSight(null); } -} \ No newline at end of file + + @Test + public void testGetSight() throws SmartsheetException, IOException { + server.setResponseBody(new File("src/test/resources/getSightWithoutWidgets.json")); + + Sight sight = sightResourcesImpl.getSight(1000018L, EnumSet.noneOf(SightInclusion.class), + EnumSet.of(SightExclusion.WIDGET), 4); + assertNotNull(sight); + } +} diff --git a/src/test/java/com/smartsheet/api/internal/http/DefaultHttpClientTest.java b/src/test/java/com/smartsheet/api/internal/http/DefaultHttpClientTest.java index 090f787f8..4163b1ae5 100644 --- a/src/test/java/com/smartsheet/api/internal/http/DefaultHttpClientTest.java +++ b/src/test/java/com/smartsheet/api/internal/http/DefaultHttpClientTest.java @@ -121,7 +121,7 @@ public void testRequest() throws HttpClientException, URISyntaxException { // Test IOException try{ - request.setUri(new URI("http://bad.domain")); + request.setUri(new URI("http://bad.domain.dontexistplease")); client.request(request); client.releaseConnection(); fail("Exception should have been thrown."); diff --git a/src/test/resources/getSight.json b/src/test/resources/getSight.json new file mode 100644 index 000000000..1a85095c2 --- /dev/null +++ b/src/test/resources/getSight.json @@ -0,0 +1,28 @@ +{ + "id": 1000018, + "name": "New Dashboard", + "accessLevel": "OWNER", + "backgroundColor": "#E2E2E2", + "permalink": "https://app.smartsheet.com/dashboards/87vMqPWJ7rfJr9wjcXcrm39Hmx2MMPQ868XH2Ww1", + "columnCount": 6, + "widgets": [ + { + "id": 1000019, + "type": "TITLE", + "contents": { + "type": "RICHTEXT", + "htmlContent": "

sdfas

", + "backgroundColor": "#F2F2F2" + }, + "xPosition": 0, + "yPosition": 0, + "width": 1, + "height": 1, + "showTitleIcon": false, + "showTitle": false, + "version": 1 + } + ], + "createdAt": "2022-05-23T21:01:08Z", + "modifiedAt": "2022-05-23T21:01:08Z" +} \ No newline at end of file diff --git a/src/test/resources/getSightWithoutWidgets.json b/src/test/resources/getSightWithoutWidgets.json new file mode 100644 index 000000000..ebbb44f82 --- /dev/null +++ b/src/test/resources/getSightWithoutWidgets.json @@ -0,0 +1,10 @@ +{ + "id": 1000018, + "name": "New Dashboard", + "accessLevel": "OWNER", + "backgroundColor": "#E2E2E2", + "permalink": "https://app.smartsheet.com/dashboards/87vMqPWJ7rfJr9wjcXcrm39Hmx2MMPQ868XH2Ww1", + "columnCount": 6, + "createdAt": "2022-05-23T21:01:08Z", + "modifiedAt": "2022-05-23T21:01:08Z" +} \ No newline at end of file