07b50a78ed828d1b5200972effbd520c69da92a0
[oam/tr069-adapter.git] / ves-agent / src / main / java / org / commscope / tr069adapter / vesagent / entity / DeviceDataEntity.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : tr-069-adapter
4  * =================================================================================================
5  * Copyright (C) 2020 CommScope Inc Intellectual Property.
6  * =================================================================================================
7  * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
9  * may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ===============LICENSE_END=======================================================================
17  */
18
19 package org.commscope.tr069adapter.vesagent.entity;\r
20 \r
21 import com.google.gson.Gson;\r
22 \r
23 import java.util.Date;\r
24 import java.util.Map;\r
25 \r
26 import javax.persistence.Column;\r
27 import javax.persistence.Entity;\r
28 import javax.persistence.GeneratedValue;\r
29 import javax.persistence.GenerationType;\r
30 import javax.persistence.Id;\r
31 import javax.persistence.Table;\r
32 import javax.persistence.Transient;\r
33 import javax.persistence.UniqueConstraint;\r
34 \r
35 @Entity\r
36 @Table(name = "VES_DEVICE_DATA",\r
37     uniqueConstraints = @UniqueConstraint(columnNames = {"DEVICE_ID", "ATTR_GROUP"}))\r
38 public class DeviceDataEntity {\r
39 \r
40   @Id\r
41   @Column(name = "ID")\r
42   @GeneratedValue(strategy = GenerationType.AUTO)\r
43   private Long id;\r
44 \r
45   @Column(name = "DEVICE_ID", length = 30)\r
46   private String deviceId;\r
47 \r
48   @Column(name = "ENODEB_NAME", length = 100)\r
49   private String eNodeBName;\r
50 \r
51   @Column(name = "OUI", length = 30)\r
52   private String oui;\r
53 \r
54   @Column(name = "PRODUCT_CLASS", length = 100)\r
55   private String productClass;\r
56 \r
57   @Column(name = "ATTR_JSON", length = 4000)\r
58   private String attrJson;\r
59 \r
60   @Column(name = "ATTR_GROUP", length = 255)\r
61   private String attrGroup;\r
62 \r
63   @Column(name = "LAST_UPDATED_TIME")\r
64   private Date lastUpdateTime = new Date();\r
65 \r
66   public Long getId() {\r
67     return id;\r
68   }\r
69 \r
70   public void setId(Long id) {\r
71     this.id = id;\r
72   }\r
73 \r
74   public String getDeviceId() {\r
75     return deviceId;\r
76   }\r
77 \r
78   public void setDeviceId(String deviceId) {\r
79     this.deviceId = deviceId;\r
80   }\r
81 \r
82   public String geteNodeBName() {\r
83     return eNodeBName;\r
84   }\r
85 \r
86   public void seteNodeBName(String eNodeBName) {\r
87     this.eNodeBName = eNodeBName;\r
88   }\r
89 \r
90   public String getOui() {\r
91     return oui;\r
92   }\r
93 \r
94   public void setOui(String oui) {\r
95     this.oui = oui;\r
96   }\r
97 \r
98   public String getProductClass() {\r
99     return productClass;\r
100   }\r
101 \r
102   public void setProductClass(String productClass) {\r
103     this.productClass = productClass;\r
104   }\r
105 \r
106   public String getAttrJson() {\r
107     return attrJson;\r
108   }\r
109 \r
110   public void setAttrJson(String attrJson) {\r
111     this.attrJson = attrJson;\r
112   }\r
113 \r
114   public String getAttrGroup() {\r
115     return attrGroup;\r
116   }\r
117 \r
118   public void setAttrGroup(String attrGroup) {\r
119     this.attrGroup = attrGroup;\r
120   }\r
121 \r
122   public Date getLastUpdateTime() {\r
123     return lastUpdateTime;\r
124   }\r
125 \r
126   public void setLastUpdateTime(Date lastUpdateTime) {\r
127     this.lastUpdateTime = lastUpdateTime;\r
128   }
129   
130   @Transient
131   private Long startEpochMicrosec;
132
133   public Long getStartEpochMicrosec() {
134     return startEpochMicrosec;
135   }
136
137   public void setStartEpochMicrosec(Long startEpochMicrosec) {
138     this.startEpochMicrosec = startEpochMicrosec;
139   }\r
140 \r
141   @Transient\r
142   public void setAttributesMap(Map<String, String> attributesMap) {\r
143     if (null == attributesMap || attributesMap.isEmpty()) {\r
144       return;\r
145     }\r
146 \r
147     this.attrJson = new Gson().toJson(attributesMap);\r
148 \r
149   }\r
150 \r
151   @Transient\r
152   public Map<String, String> getAttributesMap() {\r
153     Map<String, String> attributesMap = null;\r
154     if (null != this.attrJson && !this.attrJson.isEmpty()) {\r
155       attributesMap = new Gson().fromJson(this.attrJson, Map.class);\r
156     }\r
157     return attributesMap;\r
158   }\r
159 }\r