Merge "Fixed Sonar issues in JsonUpdate"
[music.git] / src / main / java / org / onap / music / datastore / jsonobjects / JsonUpdate.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 package org.onap.music.datastore.jsonobjects;
24
25 import java.io.ByteArrayOutputStream;
26 import java.io.IOException;
27 import java.io.ObjectOutput;
28 import java.io.ObjectOutputStream;
29 import java.io.Serializable;
30 import java.util.Map;
31
32 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
33
34 import io.swagger.annotations.ApiModel;
35 import io.swagger.annotations.ApiModelProperty;
36
37 import org.onap.music.eelf.logging.EELFLoggerDelegate;
38 import org.onap.music.eelf.logging.format.AppMessages;
39 import org.onap.music.eelf.logging.format.ErrorSeverity;
40 import org.onap.music.eelf.logging.format.ErrorTypes;
41
42 @ApiModel(value = "JsonTable", description = "Json model for table update")
43 @JsonIgnoreProperties(ignoreUnknown = true)
44 public class JsonUpdate implements Serializable {
45     private String keyspaceName;
46     private String tableName;
47     private transient Map<String, Object> values;
48     private String ttl;
49     private String timestamp;
50     private Map<String, String> consistencyInfo;
51     private transient Map<String, Object> conditions;
52     private transient Map<String, Object> rowSpecification;
53     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(JsonUpdate.class);
54
55     @ApiModelProperty(value = "Conditions")
56     public Map<String, Object> getConditions() {
57         return conditions;
58     }
59
60     public void setConditions(Map<String, Object> conditions) {
61         this.conditions = conditions;
62     }
63
64     @ApiModelProperty(value = "Information for selecting sepcific rows")
65     public Map<String, Object> getRow_specification() {
66         return rowSpecification;
67     }
68
69     public void setRow_specification(Map<String, Object> rowSpecification) {
70         this.rowSpecification = rowSpecification;
71     }
72
73
74     @ApiModelProperty(value = "Keyspace name")
75     public String getKeyspaceName() {
76         return keyspaceName;
77     }
78
79     public void setKeyspaceName(String keyspaceName) {
80         this.keyspaceName = keyspaceName;
81     }
82
83     @ApiModelProperty(value = "Table name")
84     public String getTableName() {
85         return tableName;
86     }
87
88     public void setTableName(String tableName) {
89         this.tableName = tableName;
90     }
91
92     @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic")
93     public Map<String, String> getConsistencyInfo() {
94         return consistencyInfo;
95     }
96
97     public void setConsistencyInfo(Map<String, String> consistencyInfo) {
98         this.consistencyInfo = consistencyInfo;
99     }
100
101     @ApiModelProperty(value = "Time to live value")
102     public String getTtl() {
103         return ttl;
104     }
105
106     public void setTtl(String ttl) {
107         this.ttl = ttl;
108     }
109
110     @ApiModelProperty(value = "Time stamp")
111     public String getTimestamp() {
112         return timestamp;
113     }
114
115     public void setTimestamp(String timestamp) {
116         this.timestamp = timestamp;
117     }
118
119     @ApiModelProperty(value = "Column values")
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     public byte[] serialize() {
129         ByteArrayOutputStream bos = new ByteArrayOutputStream();
130         ObjectOutput out = null;
131         try {
132             out = new ObjectOutputStream(bos);
133             out.writeObject(this);
134         } catch (IOException e) {
135             logger.error(EELFLoggerDelegate.errorLogger, e,AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.DATAERROR);
136         }
137         return bos.toByteArray();
138     }
139
140 }