• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

smartsheet / smartsheet-java-sdk / #44

25 Aug 2023 05:39PM UTC coverage: 50.55% (+0.1%) from 50.427%
#44

push

github-actions

web-flow
Fix remaining Checkstyle violations and Enable Checkstyle (#58)

* Fix remaining Checkstyle violations and Enable Checkstyle

We are now down to `20` checkstyle violations in main and `0` violations in test.

The remaining 20 violations are not trivial to fix, so I've set checkstyle to allow those 20 violations to exist, but to fail the build if we ever exceed 20 violations. This should make the build fail if any new violations are added.

For tests, we do not allow _any_ violations. This means adding a single violation will fail the build. Once the 20 violations in main are cleaned up, we can make main and test have the same config.

Note: This MR also changes our PR pipeline to run `./gradlew clean build` instead of `./gradlew clean test`. The reason for this is that build runs all the tests and performs all the other checks (such as checkstyle), whereas `test` didn't run checkstyle and we wouldn't have noticed violations until we tried to deploy.

148 of 148 new or added lines in 24 files covered. (100.0%)

3448 of 6821 relevant lines covered (50.55%)

0.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.52
/src/main/java/com/smartsheet/api/internal/json/WidgetContentDeserializer.java
1
package com.smartsheet.api.internal.json;
2

3
/*
4
 * #[license]
5
 * Smartsheet SDK for Java
6
 * %%
7
 * Copyright (C) 2023 Smartsheet
8
 * %%
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 *      http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 * %[license]
21
 */
22

23
import com.fasterxml.jackson.core.JsonParser;
24
import com.fasterxml.jackson.core.JsonProcessingException;
25
import com.fasterxml.jackson.core.Version;
26
import com.fasterxml.jackson.databind.DeserializationContext;
27
import com.fasterxml.jackson.databind.DeserializationFeature;
28
import com.fasterxml.jackson.databind.JsonDeserializer;
29
import com.fasterxml.jackson.databind.ObjectMapper;
30
import com.fasterxml.jackson.databind.module.SimpleModule;
31
import com.smartsheet.api.models.CellDataItem;
32
import com.smartsheet.api.models.CellLinkWidgetContent;
33
import com.smartsheet.api.models.ChartWidgetContent;
34
import com.smartsheet.api.models.Column;
35
import com.smartsheet.api.models.ImageWidgetContent;
36
import com.smartsheet.api.models.ObjectValue;
37
import com.smartsheet.api.models.ReportWidgetContent;
38
import com.smartsheet.api.models.SelectionRange;
39
import com.smartsheet.api.models.ShortcutDataItem;
40
import com.smartsheet.api.models.ShortcutWidgetContent;
41
import com.smartsheet.api.models.TitleRichTextWidgetContent;
42
import com.smartsheet.api.models.WebContentWidgetContent;
43
import com.smartsheet.api.models.WidgetContent;
44
import com.smartsheet.api.models.WidgetHyperlink;
45
import com.smartsheet.api.models.enums.WidgetType;
46
import com.smartsheet.api.models.format.Format;
47

48
import java.io.IOException;
49
import java.util.List;
50

51
public class WidgetContentDeserializer extends JsonDeserializer<WidgetContent> {
1✔
52

53
    @Override
54
    public WidgetContent deserialize(JsonParser jp, DeserializationContext ctxt)
55
            throws IOException, JsonProcessingException {
56

57
        WidgetContent widgetContent = null;
×
58

59
        ObjectMapper mapper = new ObjectMapper();
×
60
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
×
61
        mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
×
62
        mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
×
63

64
        // Add the relevant custom deserializers
65
        SimpleModule module = new SimpleModule("FormatDeserializerModule", Version.unknownVersion());
×
66
        module.addDeserializer(Format.class, new FormatDeserializer());
×
67

68
        module = new SimpleModule("ObjectValueDeserializerModule", Version.unknownVersion());
×
69
        module.addDeserializer(ObjectValue.class, new ObjectValueDeserializer());
×
70
        mapper.registerModule(module);
×
71

72
        WidgetContentSuperset superset = mapper.readValue(jp, WidgetContentSuperset.class);
×
73

74
        WidgetType parsedType;
75
        try {
76
            parsedType = WidgetType.valueOf(superset.type);
×
77
        } catch (IllegalArgumentException e) {
×
78
            if (superset.type.equals("WidgetWebContent")) {
×
79
                parsedType = WidgetType.WEBCONTENT;
×
80
            } else {
81
                // If a new object type is introduced to the Smartsheet API that this version of the SDK
82
                // doesn't support, return null instead of throwing an exception.
83
                return null;
×
84
            }
85
        }
×
86

87
        switch (parsedType) {
×
88
            case CHART:
89
                ChartWidgetContent chartWidgetContent = new ChartWidgetContent();
×
90
                chartWidgetContent.setReportId(superset.reportId);
×
91
                chartWidgetContent.setSheetId(superset.sheetId);
×
92
                chartWidgetContent.setAxes(superset.axes);
×
93
                chartWidgetContent.setHyperlink(superset.hyperlink);
×
94
                chartWidgetContent.setIncludedColumnIds(superset.includedColumnIds);
×
95
                chartWidgetContent.setLegend(superset.legend);
×
96
                chartWidgetContent.setSelectionRanges(superset.selectionRanges);
×
97
                chartWidgetContent.setSeries(superset.series);
×
98
                widgetContent = chartWidgetContent;
×
99
                break;
×
100

101
            case IMAGE:
102
                ImageWidgetContent imageWidgetContent = new ImageWidgetContent();
×
103
                imageWidgetContent.setPrivateId(superset.privateId);
×
104
                imageWidgetContent.setFileName(superset.fileName);
×
105
                imageWidgetContent.setFormat(superset.format);
×
106
                imageWidgetContent.setHeight(superset.height);
×
107
                imageWidgetContent.setHyperlink(superset.hyperlink);
×
108
                imageWidgetContent.setWidth(superset.width);
×
109
                widgetContent = imageWidgetContent;
×
110
                break;
×
111

112
            case METRIC:
113
                CellLinkWidgetContent cellLinkWidgetContent = new CellLinkWidgetContent();
×
114
                cellLinkWidgetContent.setSheetId(superset.sheetId);
×
115
                cellLinkWidgetContent.setCellData(superset.cellData);
×
116
                cellLinkWidgetContent.setColumns(superset.columns);
×
117
                cellLinkWidgetContent.setHyperlink(superset.hyperlink);
×
118
                widgetContent = cellLinkWidgetContent;
×
119
                break;
×
120

121
            case GRIDGANTT:
122
                ReportWidgetContent reportWidgetContent = new ReportWidgetContent();
×
123
                reportWidgetContent.setReportId(superset.reportId);
×
124
                reportWidgetContent.setHtmlContent(superset.htmlContent);
×
125
                reportWidgetContent.setHyperlink(superset.hyperlink);
×
126
                widgetContent = reportWidgetContent;
×
127
                break;
×
128

129
            case RICHTEXT:
130
                // Intentional fallthrough
131
            case TITLE:
132
                TitleRichTextWidgetContent titleRichTextWidgetContent = new TitleRichTextWidgetContent();
×
133
                titleRichTextWidgetContent.setBackgroundColor(superset.backgroundColor);
×
134
                titleRichTextWidgetContent.setHtmlContent(superset.htmlContent);
×
135
                widgetContent = titleRichTextWidgetContent;
×
136
                break;
×
137

138
            case SHORTCUT:
139
                ShortcutWidgetContent shortcutWidgetContent = new ShortcutWidgetContent();
×
140
                shortcutWidgetContent.setShortcutData(superset.shortcutData);
×
141
                widgetContent = shortcutWidgetContent;
×
142
                break;
×
143

144
            case WEBCONTENT:
145
                WebContentWidgetContent webContentWidgetContent = new WebContentWidgetContent();
×
146
                webContentWidgetContent.setUrl(superset.url);
×
147
                widgetContent = webContentWidgetContent;
×
148
                break;
×
149

150
            default:
151
                break;
152
        }
153
        return widgetContent;
×
154
    }
155

156
    private static class WidgetContentSuperset {
157

158
        // Common
159
        public String type;
160
        public Long sheetId;
161
        public Long reportId;
162
        public WidgetHyperlink hyperlink;
163
        public String htmlContent;
164

165
        // CellLinkWidgetContent
166
        public List<CellDataItem> cellData;
167
        public List<Column> columns;
168

169
        // ChartWidgetContent
170
        public List<Object> axes;
171
        public List<Long> includedColumnIds;
172
        public Object legend;
173
        public List<SelectionRange> selectionRanges;
174
        public List<Object> series;
175

176
        // ImageWidgetContent
177
        public String privateId;
178
        public String fileName;
179
        public Format format;
180
        public Integer height;
181
        public Integer width;
182

183
        // ReportWidgetContent
184

185
        // RichTextWidgetContent
186

187
        // ShortcutWidgetContent
188
        public List<ShortcutDataItem> shortcutData;
189

190
        // TitleWidgetContent
191
        public String backgroundColor;
192

193
        // WebContentWidgetContent
194
        public String url;
195
    }
196
}
197

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc