1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.prometheus.data;
18
19 import io.github.tonywasher.joceanus.metis.data.MetisDataResource;
20 import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
21 import io.github.tonywasher.joceanus.metis.field.MetisFieldVersionedSet;
22 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
23 import io.github.tonywasher.joceanus.prometheus.data.PrometheusCryptographyData.PrometheusControlDataCtl;
24 import io.github.tonywasher.joceanus.prometheus.data.PrometheusCryptographyData.PrometheusControlKeyCtl;
25 import io.github.tonywasher.joceanus.prometheus.data.PrometheusData.PrometheusDataSetCtl;
26 import io.github.tonywasher.joceanus.prometheus.exc.PrometheusDataException;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class PrometheusControlData
42 extends PrometheusDataItem
43 implements PrometheusControlDataCtl {
44
45
46
47 public static final String OBJECT_NAME = PrometheusCryptographyDataType.CONTROLDATA.getItemName();
48
49
50
51
52 public static final String LIST_NAME = PrometheusCryptographyDataType.CONTROLDATA.getListName();
53
54
55
56
57 private static final MetisFieldVersionedSet<PrometheusControlData> FIELD_DEFS = MetisFieldVersionedSet.newVersionedFieldSet(PrometheusControlData.class);
58
59
60
61
62 static {
63 FIELD_DEFS.declareIntegerField(PrometheusDataResource.CONTROLDATA_VERSION);
64 FIELD_DEFS.declareLinkField(PrometheusCryptographyDataType.CONTROLKEY);
65 }
66
67
68
69
70 public static final String ERROR_CTLEXISTS = PrometheusDataResource.CONTROLDATA_ERROR_EXISTS.getValue();
71
72
73
74
75
76
77
78 protected PrometheusControlData(final PrometheusControlDataList pList,
79 final PrometheusControlData pSource) {
80
81 super(pList, pSource);
82 }
83
84
85
86
87
88
89
90
91 private PrometheusControlData(final PrometheusControlDataList pList,
92 final PrometheusDataValues pValues) throws OceanusException {
93
94 super(pList, pValues);
95
96
97 Object myValue = pValues.getValue(PrometheusDataResource.CONTROLDATA_VERSION);
98 if (myValue instanceof Integer i) {
99 setValueDataVersion(i);
100 } else if (myValue instanceof String s) {
101 setValueDataVersion(Integer.valueOf(s));
102 }
103
104
105 myValue = pValues.getValue(PrometheusCryptographyDataType.CONTROLKEY);
106 if (myValue instanceof Integer myInt) {
107
108 setValueControlKey(myInt);
109
110
111 resolveDataLink(PrometheusCryptographyDataType.CONTROLKEY, PrometheusCryptographyDataType.CONTROLKEY);
112 }
113 }
114
115 @Override
116 public MetisFieldSetDef getDataFieldSet() {
117 return FIELD_DEFS;
118 }
119
120
121
122
123
124
125 public Integer getDataVersion() {
126 return getValues().getValue(PrometheusDataResource.CONTROLDATA_VERSION, Integer.class);
127 }
128
129 @Override
130 public PrometheusControlKey getControlKey() {
131 return getValues().getValue(PrometheusCryptographyDataType.CONTROLKEY, PrometheusControlKey.class);
132 }
133
134
135
136
137
138
139 public Integer getControlKeyId() {
140 final PrometheusControlKey myKey = getControlKey();
141 return (myKey == null)
142 ? null
143 : myKey.getIndexedId();
144 }
145
146
147
148
149
150
151
152 private void setValueDataVersion(final Integer pValue) throws OceanusException {
153 getValues().setValue(PrometheusDataResource.CONTROLDATA_VERSION, pValue);
154 }
155
156
157
158
159
160
161
162 private void setValueControlKey(final PrometheusControlKeyCtl pValue) throws OceanusException {
163 getValues().setValue(PrometheusCryptographyDataType.CONTROLKEY, pValue);
164 }
165
166
167
168
169
170
171
172 private void setValueControlKey(final Integer pId) throws OceanusException {
173 getValues().setValue(PrometheusCryptographyDataType.CONTROLKEY, pId);
174 }
175
176 @Override
177 public PrometheusControlData getBase() {
178 return (PrometheusControlData) super.getBase();
179 }
180
181 @Override
182 public PrometheusControlDataList getList() {
183 return (PrometheusControlDataList) super.getList();
184 }
185
186 @Override
187 public int compareValues(final PrometheusDataItem pThat) {
188
189 final PrometheusControlData myThat = (PrometheusControlData) pThat;
190 return getDataVersion() - myThat.getDataVersion();
191 }
192
193 @Override
194 public void resolveDataSetLinks() throws OceanusException {
195
196 resolveDataLink(PrometheusCryptographyDataType.CONTROLKEY, PrometheusCryptographyDataType.CONTROLKEY);
197 }
198
199 @Override
200 public void setControlKey(final PrometheusControlKeyCtl pControl) throws OceanusException {
201
202 if (getControlKey() == null) {
203
204 setValueControlKey(pControl);
205 return;
206 }
207
208
209 pushHistory();
210
211
212 setValueControlKey(pControl);
213
214
215 checkForHistory();
216 }
217
218
219
220
221 public static class PrometheusControlDataList
222 extends PrometheusDataList<PrometheusControlData> {
223
224
225
226 private static final MetisFieldSet<PrometheusControlDataList> FIELD_DEFS = MetisFieldSet.newFieldSet(PrometheusControlDataList.class);
227
228
229
230
231
232
233 protected PrometheusControlDataList(final PrometheusDataSetCtl pData) {
234 this(pData, PrometheusListStyle.CORE);
235 }
236
237
238
239
240
241
242
243 protected PrometheusControlDataList(final PrometheusDataSetCtl pData,
244 final PrometheusListStyle pStyle) {
245 super(PrometheusControlData.class, pData, PrometheusCryptographyDataType.CONTROLDATA, pStyle);
246 }
247
248
249
250
251
252
253 private PrometheusControlDataList(final PrometheusControlDataList pSource) {
254 super(pSource);
255 }
256
257 @Override
258 public MetisFieldSet<PrometheusControlDataList> getDataFieldSet() {
259 return FIELD_DEFS;
260 }
261
262 @Override
263 public String listName() {
264 return LIST_NAME;
265 }
266
267 @Override
268 public MetisFieldSet<PrometheusControlData> getItemFields() {
269 return PrometheusControlData.FIELD_DEFS;
270 }
271
272 @Override
273 public boolean includeDataXML() {
274 return false;
275 }
276
277
278
279
280
281
282 public PrometheusControlData getControl() {
283 return isEmpty()
284 ? null
285 : get(0);
286 }
287
288 @Override
289 protected PrometheusControlDataList getEmptyList(final PrometheusListStyle pStyle) {
290 final PrometheusControlDataList myList = new PrometheusControlDataList(this);
291 myList.setStyle(pStyle);
292 return myList;
293 }
294
295 @Override
296 public PrometheusControlDataList deriveList(final PrometheusListStyle pStyle) throws OceanusException {
297 return (PrometheusControlDataList) super.deriveList(pStyle);
298 }
299
300 @Override
301 public PrometheusControlDataList deriveDifferences(final PrometheusDataSetCtl pDataSet,
302 final PrometheusDataList<?> pOld) {
303 return (PrometheusControlDataList) super.deriveDifferences(pDataSet, pOld);
304 }
305
306 @Override
307 public PrometheusControlData addCopyItem(final PrometheusDataItem pItem) {
308
309 if (!(pItem instanceof PrometheusControlData)) {
310 return null;
311 }
312
313
314 final PrometheusControlData myControl = new PrometheusControlData(this, (PrometheusControlData) pItem);
315 add(myControl);
316 return myControl;
317 }
318
319 @Override
320 public PrometheusControlData addNewItem() {
321 throw new UnsupportedOperationException();
322 }
323
324
325
326
327
328
329
330 public void addNewControl(final Integer pVersion) throws OceanusException {
331
332 final PrometheusDataValues myValues = new PrometheusDataValues(OBJECT_NAME);
333 myValues.addValue(PrometheusDataResource.CONTROLDATA_VERSION, pVersion);
334
335
336 addValuesItem(myValues);
337 }
338
339 @Override
340 public PrometheusControlData addValuesItem(final PrometheusDataValues pValues) throws OceanusException {
341
342 final PrometheusControlData myControl = new PrometheusControlData(this, pValues);
343
344
345 if (!isIdUnique(myControl.getIndexedId())) {
346 myControl.addError(ERROR_DUPLICATE, MetisDataResource.DATA_ID);
347 throw new PrometheusDataException(myControl, ERROR_VALIDATION);
348 }
349
350
351 add(myControl);
352
353
354 return myControl;
355 }
356
357 @Override
358 public void postProcessOnLoad() throws OceanusException {
359
360 reSort();
361 }
362
363 @Override
364 protected PrometheusDataMapItem allocateDataMap() {
365
366 throw new UnsupportedOperationException();
367 }
368 }
369 }