aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/aai/cacher/model/CacheEntry.java
blob: ed6715ec841ecee9e26cf94e4fc403e393fb3e6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
 * ============LICENSE_START=======================================================
 * org.onap.aai
 * ================================================================================
 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */
package org.onap.aai.cacher.model;

import com.google.gson.JsonObject;

/**
 * Captures the details of a cache entry to be inserted onto the database
 */
public class CacheEntry {

    protected DBAction dbAction;

    protected String id;
    protected String collection;
    protected JsonObject payload;
    protected JsonObject findQuery;

    protected boolean isNested = false;
    protected String nestedField;
    protected JsonObject nestedFind;
    protected JsonObject nestedFieldIdentifierObj;

    private CacheEntry() {
    }

    public DBAction getDbAction() {
        return dbAction;
    }

    public void setDbAction(DBAction dbAction) {
        this.dbAction = dbAction;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCollection() {
        return collection;
    }

    public void setCollection(String collection) {
        this.collection = collection;
    }

    public JsonObject getPayload() {
        return payload;
    }

    public void setPayload(JsonObject payload) {
        this.payload = payload;
    }

    public JsonObject getFindQuery() {
        return findQuery;
    }

    public void setFindQuery(JsonObject findQuery) {
        this.findQuery = findQuery;
    }

    public boolean isNested() {
        return isNested;
    }

    public void setNested(boolean nested) {
        isNested = nested;
    }

    public String getNestedField() {
        return nestedField;
    }

    public void setNestedField(String nestedField) {
        this.nestedField = nestedField;
    }

    public JsonObject getNestedFind() {
        return nestedFind;
    }

    public void setNestedFind(JsonObject nestedFind) {
        this.nestedFind = nestedFind;
    }

    public JsonObject getNestedFieldIdentifierObj() {
        return nestedFieldIdentifierObj;
    }

    public void setNestedFieldIdentifierObj(JsonObject nestedFieldIdentifierObj) {
        this.nestedFieldIdentifierObj = nestedFieldIdentifierObj;
    }

    public static final class CacheEntryBuilder {
        protected DBAction dbAction;
        protected String id;
        protected String collection;
        protected JsonObject payload;
        protected JsonObject findQuery;
        protected boolean isNested;
        protected String nestedField;
        protected JsonObject nestedFind;
        protected JsonObject nestedFieldIdentifierObj;

        private CacheEntryBuilder() {
        }

        public static CacheEntryBuilder createCacheEntry() {
            return new CacheEntryBuilder();
        }

        public CacheEntryBuilder deepCopy(CacheEntry cacheEntry) {
            dbAction = cacheEntry.getDbAction();
            id = cacheEntry.getId();
            collection = cacheEntry.getCollection();
            payload = cacheEntry.getPayload();
            findQuery = cacheEntry.getFindQuery();
            isNested = cacheEntry.isNested();
            nestedField = cacheEntry.getNestedField();
            nestedFind = cacheEntry.getNestedFind();
            nestedFieldIdentifierObj = cacheEntry.getNestedFieldIdentifierObj();
            return this;
        }

        public CacheEntryBuilder withDbAction(DBAction dbAction) {
            this.dbAction = dbAction;
            return this;
        }

        public CacheEntryBuilder withId(String id) {
            this.id = id;
            return this;
        }

        public CacheEntryBuilder inCollection(String collection) {
            this.collection = collection;
            return this;
        }

        public CacheEntryBuilder withPayload(JsonObject payload) {
            this.payload = payload;
            return this;
        }

        public CacheEntryBuilder withFindQuery(JsonObject findQuery) {
            this.findQuery = findQuery;
            return this;
        }

        public CacheEntryBuilder isNested(boolean isNested) {
            this.isNested = isNested;
            return this;
        }

        public CacheEntryBuilder withNestedField(String nestedField) {
            this.nestedField = nestedField;
            return this;
        }

        public CacheEntryBuilder withNestedFind(JsonObject nestedFind) {
            this.nestedFind = nestedFind;
            return this;
        }

        public CacheEntryBuilder withNestedFieldIdentifierObj(JsonObject nestedFieldIdentifierObj) {
            this.nestedFieldIdentifierObj = nestedFieldIdentifierObj;
            return this;
        }

        public CacheEntry build() {
            CacheEntry cacheEntry = new CacheEntry();
            cacheEntry.setDbAction(dbAction);
            cacheEntry.setId(id);
            cacheEntry.setCollection(collection);
            cacheEntry.setPayload(payload);
            cacheEntry.setFindQuery(findQuery);
            cacheEntry.setNestedField(nestedField);
            cacheEntry.setNestedFind(nestedFind);
            cacheEntry.setNestedFieldIdentifierObj(nestedFieldIdentifierObj);
            cacheEntry.isNested = this.isNested;
            return cacheEntry;
        }
    }
}