1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.prometheus.validate;
18
19 import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataItem;
20 import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
21 import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValidator;
22 import io.github.tonywasher.joceanus.prometheus.data.PrometheusStaticDataItem;
23 import io.github.tonywasher.joceanus.prometheus.data.PrometheusStaticDataItem.PrometheusStaticDataMap;
24 import io.github.tonywasher.joceanus.prometheus.data.PrometheusStaticDataItem.PrometheusStaticList;
25
26
27
28
29 public class PrometheusValidateStatic
30 implements PrometheusDataValidator {
31
32
33
34 public PrometheusValidateStatic() {
35 }
36
37 @Override
38 public void validate(final PrometheusDataItem pStatic) {
39 final PrometheusStaticDataItem myStatic = (PrometheusStaticDataItem) pStatic;
40 final PrometheusStaticList<?> myList = myStatic.getList();
41 final String myName = myStatic.getName();
42 final String myDesc = myStatic.getDesc();
43 final PrometheusStaticDataMap<?> myMap = myList.getDataMap();
44
45
46 if (myName == null) {
47 pStatic.addError(PrometheusDataItem.ERROR_MISSING, PrometheusDataResource.DATAITEM_FIELD_NAME);
48
49
50 } else {
51
52 if (PrometheusDataItem.byteLength(myName) > PrometheusDataItem.NAMELEN) {
53 pStatic.addError(PrometheusDataItem.ERROR_LENGTH, PrometheusDataResource.DATAITEM_FIELD_NAME);
54 }
55
56
57 if (!PrometheusDataItem.validString(myName, null)) {
58 pStatic.addError(PrometheusStaticDataItem.ERROR_BADNAME, PrometheusDataResource.DATAITEM_FIELD_NAME);
59 }
60
61
62 if (!myMap.validNameCount(myName)) {
63 pStatic.addError(PrometheusDataItem.ERROR_DUPLICATE, PrometheusDataResource.DATAITEM_FIELD_NAME);
64 }
65 }
66
67
68 if (myDesc != null
69 && PrometheusDataItem.byteLength(myDesc) > PrometheusDataItem.DESCLEN) {
70 pStatic.addError(PrometheusDataItem.ERROR_LENGTH, PrometheusDataResource.DATAITEM_FIELD_DESC);
71 }
72
73
74 if (myStatic.getOrder() < 0) {
75 pStatic.addError(PrometheusDataItem.ERROR_NEGATIVE, PrometheusDataResource.STATICDATA_SORT);
76 }
77
78
79 if (!myMap.validOrderCount(myStatic.getOrder())) {
80 pStatic.addError(PrometheusDataItem.ERROR_DUPLICATE, PrometheusDataResource.STATICDATA_SORT);
81 }
82
83
84 if (!pStatic.hasErrors()) {
85 pStatic.setValidEdit();
86 }
87 }
88 }