]> git.basschouten.com Git - openhab-addons.git/blob
2072600cc5e6e53cacb77a42e97f47e388f54849
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.livisismarthome.internal.client.api.entity.event;
14
15 import org.openhab.binding.livisismarthome.internal.client.api.entity.link.LinkDTO;
16 import org.openhab.binding.livisismarthome.internal.client.api.entity.message.MessageDTO;
17
18 /**
19  * Defines the {@link EventDTO}, which is sent by the LIVISI websocket to inform the clients about changes.
20  *
21  * @author Oliver Kuhl - Initial contribution
22  */
23 public class MessageEventDTO extends BaseEventDTO {
24
25     /**
26      * Reference to the associated entity (instance or metadata) for the given event. Always available.
27      */
28     private String source;
29
30     /**
31      * The product (context) that generated the event.
32      */
33     private String namespace;
34
35     /**
36      * Data for the event, The data container can contain any type of entity dependent on the event type. For example,
37      * the DeviceFound events contains the entire Device entity rather than selected properties.
38      * Optional.
39      */
40     private MessageDTO data;
41
42     /**
43      * @return the link to the source
44      */
45     public String getSource() {
46         return source;
47     }
48
49     /**
50      * @param source the link to the source to set
51      */
52     public void setSource(String source) {
53         this.source = source;
54     }
55
56     /**
57      * @return the namespace
58      */
59     public String getNamespace() {
60         return namespace;
61     }
62
63     /**
64      * @param namespace the namespace to set
65      */
66     public void setNamespace(String namespace) {
67         this.namespace = namespace;
68     }
69
70     /**
71      * @return the dataList
72      */
73     public MessageDTO getData() {
74         return data;
75     }
76
77     /**
78      * @param data the data to set
79      */
80     public void setData(MessageDTO data) {
81         this.data = data;
82     }
83
84     public MessageDTO getMessage() {
85         return data;
86     }
87
88     /**
89      * Returns the id of the link or null, if there is no link or the link does not have an id.
90      *
91      * @return String the id of the link or null
92      */
93     public String getSourceId() {
94         if (source != null) {
95             final String linkType = getSourceLinkType();
96             if (linkType != null && !LinkDTO.LINK_TYPE_UNKNOWN.equals(linkType)
97                     && !LinkDTO.LINK_TYPE_SHC.equals(linkType)) {
98                 return source.replace(linkType, "");
99             }
100         }
101         return null;
102     }
103
104     /**
105      * Returns the Type of the {@link LinkDTO} in the {@link EventDTO}.
106      *
107      * @return type of the {@link LinkDTO}
108      */
109     private String getSourceLinkType() {
110         if (source != null) {
111             return LinkDTO.getLinkType(source);
112         }
113         return null;
114     }
115 }