Skip to content
This repository was archived by the owner on Jun 6, 2023. It is now read-only.
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/smartsheet/api/SightResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -100,6 +102,26 @@ public interface SightResources {
*/
public Sight getSight(long sightId, EnumSet<SightInclusion> includes, Integer level) throws SmartsheetException;

/**
* <p>Get a specified Sight.</p>
*
* <p>It mirrors to the following Smartsheet REST API method: GET /sights/{sightId}</p>
*
* @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<SightInclusion> includes, EnumSet<SightExclusion> excludes
, Integer level) throws SmartsheetException;

/**
* <p>Get a specified Sight.</p>
*
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/smartsheet/api/internal/SightResourcesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -150,6 +151,35 @@ public Sight getSight(long sightId, EnumSet<SightInclusion> 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<SightInclusion> includes, EnumSet<SightExclusion> excludes, Integer level) throws SmartsheetException {
String path = "sights/" + sightId;

HashMap<String, Object> parameters = new HashMap<String, Object>();
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.
*
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/smartsheet/api/models/enums/SightExclusion.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,4 +49,13 @@ public void before() {
public void updateWithNullSight() throws SmartsheetException {
sightResourcesImpl.updateSight(null);
}
}

@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
28 changes: 28 additions & 0 deletions src/test/resources/getSight.json
Original file line number Diff line number Diff line change
@@ -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": "<p style=\"text-align:center\">sdfas</p>",
"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"
}
10 changes: 10 additions & 0 deletions src/test/resources/getSightWithoutWidgets.json
Original file line number Diff line number Diff line change
@@ -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"
}