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

smartsheet / smartsheet-java-sdk / #41

24 Aug 2023 04:59PM UTC coverage: 50.458% (+0.01%) from 50.444%
#41

push

github-actions

web-flow
Fix Checkstyle Violations in "Impl" Classes (#53)

241 of 241 new or added lines in 32 files covered. (100.0%)

3417 of 6772 relevant lines covered (50.46%)

0.5 hits per line

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

0.0
/src/main/java/com/smartsheet/api/internal/EventResourcesImpl.java
1
package com.smartsheet.api.internal;
2

3
/*
4
 * #[license]
5
 * Smartsheet Java SDK
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.smartsheet.api.AuthorizationException;
24
import com.smartsheet.api.EventResources;
25
import com.smartsheet.api.InvalidRequestException;
26
import com.smartsheet.api.ResourceNotFoundException;
27
import com.smartsheet.api.ServiceUnavailableException;
28
import com.smartsheet.api.SmartsheetException;
29
import com.smartsheet.api.internal.http.HttpMethod;
30
import com.smartsheet.api.internal.http.HttpRequest;
31
import com.smartsheet.api.internal.http.HttpResponse;
32
import com.smartsheet.api.internal.util.QueryUtil;
33
import com.smartsheet.api.models.EventResult;
34

35
import java.text.SimpleDateFormat;
36
import java.util.Date;
37
import java.util.HashMap;
38
import java.util.Map;
39

40
/**
41
 * This is the implementation of the SheetResources.
42
 * <p>
43
 * Thread Safety: This class is thread safe because it is immutable and its base class is thread safe.
44
 */
45
public class EventResourcesImpl extends AbstractResources implements EventResources {
46

47
    /**
48
     * Constructor.
49
     * <p>
50
     * Exceptions: - IllegalArgumentException : if any argument is null
51
     *
52
     * @param smartsheet the smartsheet
53
     */
54
    public EventResourcesImpl(SmartsheetImpl smartsheet) {
55
        super(smartsheet);
×
56
    }
×
57

58
    /**
59
     * <p>List all events.</p>
60
     *
61
     * <p>It mirrors to the following Smartsheet REST API method: GET /events</p>
62
     *
63
     * @param since Starting time for events to return. You must pass in a value for either since or
64
     *              streamPosition and never both.
65
     * @param streamPosition Indicates next set of events to return. Use value of nextStreamPosition returned
66
     *                       from the previous call. You must pass in a value for either since or streamPosition
67
     *                       and never both.
68
     * @param maxCount Maximum number of events to return as response to this call. Must be between
69
     *                 1 through 10,000 (inclusive).
70
     * @param numericDates If true, dates are accepted and returned in Unix epoch time (milliseconds since midnight
71
     *                     on January 1, 1970 in UTC time). Default is false, which means ISO-8601 format
72
     * @return A list of all events (note that an empty list will be returned if there are none).
73
     * @throws IllegalArgumentException if any argument is null or empty string
74
     * @throws InvalidRequestException if there is any problem with the REST API request
75
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
76
     * @throws ResourceNotFoundException if the resource cannot be found
77
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
78
     * @throws SmartsheetException if there is any other error during the operation
79
     */
80
    public EventResult listEvents(Object since, String streamPosition, Integer maxCount,
81
                                  Boolean numericDates) throws SmartsheetException {
82
        String path = "events";
×
83

84
        Map<String, Object> parameters = new HashMap<>();
×
85
        if (since instanceof Date) {
×
86
            String isoDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(since);
×
87
            parameters.put("since", isoDate);
×
88
        } else {
×
89
            parameters.put("since", since);
×
90
        }
91
        parameters.put("streamPosition", streamPosition);
×
92
        parameters.put("maxCount", maxCount);
×
93
        parameters.put("numericDates", numericDates);
×
94

95
        path += QueryUtil.generateUrl(null, parameters);
×
96

97
        HttpRequest request;
98
        request = createHttpRequest(smartsheet.getBaseURI().resolve(path), HttpMethod.GET);
×
99

100
        EventResult obj = null;
×
101
        try {
102
            HttpResponse response = this.smartsheet.getHttpClient().request(request);
×
103
            switch (response.getStatusCode()) {
×
104
                case 200:
105
                    obj = this.smartsheet.getJsonSerializer().deserializeEventResult(response.getEntity().getContent());
×
106
                    break;
×
107
                default:
108
                    handleError(response);
×
109
            }
110
        } finally {
111
            smartsheet.getHttpClient().releaseConnection();
×
112
        }
113

114
        return obj;
×
115
    }
116
}
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