4533f947c234bdd30be5597d43d5dabc637a6e43
[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 = "JsonTable", description = "Json model for table vlaues insert")
44 @JsonIgnoreProperties(ignoreUnknown = true)
45 public class JsonInsert implements Serializable {
46     private String keyspaceName;
47     private String tableName;
48     private transient Map<String, Object> values;
49     private String ttl;
50     private String timestamp;
51     private transient Map<String, Object> rowSpecification;
52     private Map<String, String> consistencyInfo;
53     private Map<String, byte[]> objectMap;
54     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(JsonInsert.class);
55
56     @ApiModelProperty(value = "objectMap")
57     public Map<String, byte[]> getObjectMap() {
58         return objectMap;
59     }
60     
61     public void setObjectMap(Map<String, byte[]> objectMap) {
62         this.objectMap = objectMap;
63     }
64     
65     @ApiModelProperty(value = "keyspace")
66     public String getKeyspaceName() {
67         return keyspaceName;
68     }
69
70     public void setKeyspaceName(String keyspaceName) {
71         this.keyspaceName = keyspaceName;
72     }
73
74     @ApiModelProperty(value = "Table name")
75     public String getTableName() {
76         return tableName;
77     }
78
79     public void setTableName(String tableName) {
80         this.tableName = tableName;
81     }
82
83     @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic")
84     public Map<String, String> getConsistencyInfo() {
85         return consistencyInfo;
86     }
87
88     public void setConsistencyInfo(Map<String, String> consistencyInfo) {
89         this.consistencyInfo = consistencyInfo;
90     }
91
92     @ApiModelProperty(value = "Time to live information")
93     public String getTtl() {
94         return ttl;
95     }
96
97     public void setTtl(String ttl) {
98         this.ttl = ttl;
99     }
100
101     @ApiModelProperty(value = "Time stamp")
102     public String getTimestamp() {
103         return timestamp;
104     }
105
106     public void setTimestamp(String timestamp) {
107         this.timestamp = timestamp;
108     }
109
110     @ApiModelProperty(value = "values returned")
111     public Map<String, Object> getValues() {
112         return values;
113     }
114
115     public void setValues(Map<String, Object> values) {
116         this.values = values;
117     }
118
119     @ApiModelProperty(value = "Information for selecting specific rows for insert")
120     public Map<String, Object> getRow_specification() {
121         return rowSpecification;
122     }
123
124     public void setRow_specification(Map<String, Object> rowSpecification) {
125         this.rowSpecification = rowSpecification;
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 }