|
1 | 1 | /* |
2 | | - * Copyright (C) 2004-2019, GoodData(R) Corporation. All rights reserved. |
| 2 | + * Copyright (C) 2004-2021, GoodData(R) Corporation. All rights reserved. |
3 | 3 | * This source code is licensed under the BSD-style license found in the |
4 | 4 | * LICENSE.txt file in the root directory of this source tree. |
5 | 5 | */ |
|
21 | 21 | import java.util.*; |
22 | 22 | import java.util.stream.Collectors; |
23 | 23 |
|
24 | | -import static com.gooddata.sdk.common.util.Validate.noNullElements; |
25 | | -import static com.gooddata.sdk.common.util.Validate.notNull; |
26 | | -import static com.gooddata.sdk.common.util.Validate.notNullState; |
| 24 | +import static com.gooddata.sdk.common.util.Validate.*; |
| 25 | +import static com.gooddata.sdk.model.md.Service.TIMEZONE_URI; |
27 | 26 | import static java.util.Arrays.asList; |
28 | 27 |
|
29 | 28 | /** |
@@ -440,6 +439,32 @@ public List<AttributeElement> getAttributeElements(DisplayForm displayForm) { |
440 | 439 | } |
441 | 440 | } |
442 | 441 |
|
| 442 | + /** |
| 443 | + * Get project/workspace timezone. |
| 444 | + * |
| 445 | + * @param project project from what to return the timezone |
| 446 | + * @return string identifier of the timezone (see IANA/Olson tz database for possible values) |
| 447 | + * @throws com.gooddata.sdk.common.GoodDataRestException if GoodData REST API returns unexpected status code |
| 448 | + * @throws com.gooddata.sdk.common.GoodDataException if no response from API or client-side HTTP error |
| 449 | + */ |
| 450 | + public String getTimezone(final Project project) { |
| 451 | + notNull(project, "project"); |
| 452 | + notNull(project.getId(), "project.id"); |
| 453 | + |
| 454 | + try { |
| 455 | + final Service result = restTemplate.getForObject(TIMEZONE_URI, Service.class, project.getId()); |
| 456 | + |
| 457 | + if (result != null) { |
| 458 | + return result.getTimezone(); |
| 459 | + } else { |
| 460 | + throw new GoodDataException("Received empty response from API call."); |
| 461 | + } |
| 462 | + } catch (RestClientException e) { |
| 463 | + throw new GoodDataException("Unable to get timezone of project/workspace " + project.getId(), e); |
| 464 | + } |
| 465 | + } |
| 466 | + |
| 467 | + |
443 | 468 | private Collection<Entry> filterEntries(Collection<Entry> entries, Restriction... restrictions) { |
444 | 469 | if (restrictions == null || restrictions.length == 0) { |
445 | 470 | return entries; |
|
0 commit comments