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