]> git.basschouten.com Git - openhab-addons.git/blob
499e4617b474c96404b3f3013f5a66f1d252b19d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.amazonechocontrol.internal.jsons;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 import com.google.gson.Gson;
19 import com.google.gson.JsonSyntaxException;
20
21 /**
22  * The {@link JsonActivities} encapsulate the GSON data of the push command for push activity
23  *
24  * @author Michael Geramb - Initial contribution
25  */
26 @NonNullByDefault
27 public class JsonActivities {
28
29     public @Nullable Activity @Nullable [] activities;
30
31     public static class Activity {
32         public @Nullable String activityStatus;
33         public @Nullable Long creationTimestamp;
34         public @Nullable String description;
35         public @Nullable Object domainAttributes;
36         public @Nullable Object domainType;
37         public @Nullable Object feedbackAttributes;
38         public @Nullable String id;
39         public @Nullable String intentType;
40         public @Nullable String providerInfoDescription;
41         public @Nullable String registeredCustomerId;
42         public @Nullable Object sourceActiveUsers;
43         public @Nullable SourceDeviceId @Nullable [] sourceDeviceIds;
44         public @Nullable String utteranceId;
45         public @Nullable Long version;
46
47         public static class SourceDeviceId {
48             public @Nullable String deviceAccountId;
49             public @Nullable String deviceType;
50             public @Nullable String serialNumber;
51         }
52
53         public static class Description {
54
55             public @Nullable String summary;
56             public @Nullable String firstUtteranceId;
57             public @Nullable String firstStreamId;
58         }
59
60         public Description parseDescription() {
61             String description = this.description;
62             if (description == null || description.isEmpty() || !description.startsWith("{")
63                     || !description.endsWith("}")) {
64                 return new Description();
65             }
66             Gson gson = new Gson();
67             try {
68                 Description description1 = gson.fromJson(description, Description.class);
69                 return description1 != null ? description1 : new Description();
70             } catch (JsonSyntaxException e) {
71                 return new Description();
72             }
73         }
74     }
75 }