Some bug fixes and Minor Chages.
[music.git] / src / main / java / org / onap / music / datastore / jsonobjects / JsonInsert.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
6  *  Modifications Copyright (C) 2018 IBM.
7  * ===================================================================
8  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  you may not use this file except in compliance with the License.
10  *  You may obtain a copy of the License at
11  * 
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  *  Unless required by applicable law or agreed to in writing, software
15  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  See the License for the specific language governing permissions and
18  *  limitations under the License.
19  * 
20  * ============LICENSE_END=============================================
21  * ====================================================================
22  */
23
24 package org.onap.music.datastore.jsonobjects;
25
26 import java.io.ByteArrayOutputStream;
27 import java.io.IOException;
28 import java.io.ObjectOutput;
29 import java.io.ObjectOutputStream;
30 import java.io.Serializable;
31 import java.util.Map;
32
33 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34
35 import io.swagger.annotations.ApiModel;
36 import io.swagger.annotations.ApiModelProperty;
37
38 import org.onap.music.eelf.logging.EELFLoggerDelegate;
39 import org.onap.music.eelf.logging.format.AppMessages;
40 import org.onap.music.eelf.logging.format.ErrorSeverity;
41 import org.onap.music.eelf.logging.format.ErrorTypes;
42
43 @ApiModel(value = "InsertTable", description = "Json model for table vlaues insert")
44 @JsonIgnoreProperties(ignoreUnknown = true)
45 public class JsonInsert implements Serializable {
46     private static final long serialVersionUID = 1L;
47     private String keyspaceName;
48     private String tableName;
49     private transient Map<String, Object> values;
50     private String ttl;
51     private String timestamp;
52     private transient Map<String, Object> rowSpecification;
53     private Map<String, String> consistencyInfo;
54     private Map<String, byte[]> objectMap;
55     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(JsonInsert.class);
56
57     @ApiModelProperty(value = "objectMap",hidden = true)
58     public Map<String, byte[]> getObjectMap() {
59         return objectMap;
60     }
61     
62     public void setObjectMap(Map<String, byte[]> objectMap) {
63         this.objectMap = objectMap;
64     }
65     
66     @ApiModelProperty(value = "keyspace")
67     public String getKeyspaceName() {
68         return keyspaceName;
69     }
70
71     public void setKeyspaceName(String keyspaceName) {
72         this.keyspaceName = keyspaceName;
73     }
74
75     @ApiModelProperty(value = "Table name")
76     public String getTableName() {
77         return tableName;
78     }
79
80     public void setTableName(String tableName) {
81         this.tableName = tableName;
82     }
83
84     @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic")
85     public Map<String, String> getConsistencyInfo() {
86         return consistencyInfo;
87     }
88
89     public void setConsistencyInfo(Map<String, String> consistencyInfo) {
90         this.consistencyInfo = consistencyInfo;
91     }
92
93     @ApiModelProperty(value = "Columns and tables support an optional "
94         + "expiration period called TTL (time-to-live) in seconds.",
95         notes="TTL precision is one second, which is calculated by the coordinator "
96         + "node. When using TTL, ensure that all nodes in the cluster have synchronized clocks.",allowEmptyValue = true)
97     public String getTtl() {
98         return ttl;
99     }
100
101     public void setTtl(String ttl) {
102         this.ttl = ttl;
103     }
104
105     @ApiModelProperty(value = "Time stamp (epoch_in_microseconds)",
106         notes = "Marks inserted data (write time) with TIMESTAMP. "
107         + "Enter the time since epoch (January 1, 1970) in microseconds."
108         + "By default, the actual time of write is used.", allowEmptyValue = true)
109     public String getTimestamp() {
110         return timestamp;
111     }
112
113     public void setTimestamp(String timestamp) {
114         this.timestamp = timestamp;
115     }
116
117     @ApiModelProperty(value = "Json Object of key/values", notes="Where key is the column name and value is the data value for that column.",
118         example = "{'emp_id': 'df98a3d40cd6','emp_name': 'john',"
119         + "'emp_salary': 50,'address':{'street' : '1 Some way','city' : 'New York'}}")
120     public Map<String, Object> getValues() {
121         return values;
122     }
123
124     public void setValues(Map<String, Object> values) {
125         this.values = values;
126     }
127
128     @ApiModelProperty(value = "Information for selecting specific rows for insert",hidden = true)
129     public Map<String, Object> getRowSpecification() {
130         return rowSpecification;
131     }
132
133     public void setRowSpecification(Map<String, Object> rowSpecification) {
134         this.rowSpecification = rowSpecification;
135     }
136
137     public byte[] serialize() {
138         ByteArrayOutputStream bos = new ByteArrayOutputStream();
139         ObjectOutput out = null;
140         try {
141             out = new ObjectOutputStream(bos);
142             out.writeObject(this);
143         } catch (IOException e) {
144             logger.error(EELFLoggerDelegate.errorLogger, e, AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.DATAERROR);
145         }
146         return bos.toByteArray();
147     }
148
149 }