1 package fr.ifremer.dali.dto.enums;
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 import fr.ifremer.quadrige3.core.dao.system.rule.RuleControlEntity;
27 import fr.ifremer.dali.dto.DaliBeanFactory;
28 import fr.ifremer.dali.dto.configuration.control.ControlElementDTO;
29
30 import static org.nuiton.i18n.I18n.n;
31 import static org.nuiton.i18n.I18n.t;
32
33
34
35
36 public enum ControlElementValues {
37
38 SURVEY(RuleControlEntity.SURVEY, n("dali.core.enums.elementControlValues.observation")),
39 SAMPLING_OPERATION(RuleControlEntity.SAMPLING_OPERATION, n("dali.core.enums.elementControlValues.samplingOperation")),
40 MEASUREMENT(RuleControlEntity.MEASUREMENT, n("dali.core.enums.elementControlValues.measurement")),
41 TAXON_MEASUREMENT(RuleControlEntity.TAXON_MEASUREMENT, n("dali.core.enums.elementControlValues.taxonMeasurement"));
42
43 private final RuleControlEntity ruleControlEntity;
44 private final String keyLabel;
45
46 ControlElementValues(RuleControlEntity ruleControlEntity, String keyLabel) {
47 this.ruleControlEntity = ruleControlEntity;
48 this.keyLabel = keyLabel;
49 }
50
51
52
53
54
55
56 public String getLabel() {
57 return t(this.keyLabel);
58 }
59
60
61
62
63
64
65 public String getCode() {
66 return this.ruleControlEntity.getValue();
67 }
68
69
70
71
72
73
74 public ControlElementDTO toControlElementDTO() {
75 ControlElementDTO dto = DaliBeanFactory.newControlElementDTO();
76 dto.setId(ordinal());
77 dto.setCode(getCode());
78 dto.setName(getLabel());
79 return dto;
80 }
81
82
83
84
85
86
87
88 public boolean equals(ControlElementDTO controlElement) {
89 return controlElement != null && getCode().equals(controlElement.getCode());
90 }
91
92
93
94
95
96
97
98 public static ControlElementDTO toControlElementDTO(String code) {
99 ControlElementValues value = getByCode(code);
100 if (value != null) {
101 return value.toControlElementDTO();
102 }
103 return null;
104 }
105
106
107
108
109
110
111
112 public static ControlElementValues getByCode(String code) {
113 for (ControlElementValues value : values()) {
114 if (value.getCode().equals(code)) {
115 return value;
116 }
117 }
118 return null;
119 }
120 }