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
38 @Override
39 public void validate(final PrometheusDataItem pStatic) {
40 final PrometheusStaticDataItem myStatic = (PrometheusStaticDataItem) pStatic;
41 final PrometheusStaticList<?> myList = myStatic.getList();
42 final String myName = myStatic.getName();
43 final String myDesc = myStatic.getDesc();
44 final PrometheusStaticDataMap<?> myMap = myList.getDataMap();
45
46
47 if (myName == null) {
48 pStatic.addError(PrometheusDataItem.ERROR_MISSING, PrometheusDataResource.DATAITEM_FIELD_NAME);
49
50
51 } else {
52
53 if (PrometheusDataItem.byteLength(myName) > PrometheusDataItem.NAMELEN) {
54 pStatic.addError(PrometheusDataItem.ERROR_LENGTH, PrometheusDataResource.DATAITEM_FIELD_NAME);
55 }
56
57
58 if (!PrometheusDataItem.validString(myName, null)) {
59 pStatic.addError(PrometheusStaticDataItem.ERROR_BADNAME, PrometheusDataResource.DATAITEM_FIELD_NAME);
60 }
61
62
63 if (!myMap.validNameCount(myName)) {
64 pStatic.addError(PrometheusDataItem.ERROR_DUPLICATE, PrometheusDataResource.DATAITEM_FIELD_NAME);
65 }
66 }
67
68
69 if (myDesc != null
70 && PrometheusDataItem.byteLength(myDesc) > PrometheusDataItem.DESCLEN) {
71 pStatic.addError(PrometheusDataItem.ERROR_LENGTH, PrometheusDataResource.DATAITEM_FIELD_DESC);
72 }
73
74
75 if (myStatic.getOrder() < 0) {
76 pStatic.addError(PrometheusDataItem.ERROR_NEGATIVE, PrometheusDataResource.STATICDATA_SORT);
77 }
78
79
80 if (!myMap.validOrderCount(myStatic.getOrder())) {
81 pStatic.addError(PrometheusDataItem.ERROR_DUPLICATE, PrometheusDataResource.STATICDATA_SORT);
82 }
83
84
85 if (!pStatic.hasErrors()) {
86 pStatic.setValidEdit();
87 }
88 }
89 }