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.RuleControlAttribute;
27 import fr.ifremer.dali.dto.DaliBeanFactory;
28 import fr.ifremer.dali.dto.configuration.control.ControlFeatureDTO;
29 import org.apache.commons.lang3.StringUtils;
30
31 import static org.nuiton.i18n.I18n.n;
32 import static org.nuiton.i18n.I18n.t;
33
34
35
36
37 public enum ControlFeatureSamplingOperationValues {
38
39 COMMENT(RuleControlAttribute.COMMENT, n("dali.core.enums.featureControlValues.comment")),
40 TIME(RuleControlAttribute.TIME, n("dali.core.enums.featureControlValues.time")),
41 LATITUDE_REAL(RuleControlAttribute.LATITUDE_REAL, n("dali.core.enums.featureControlValues.latitudeReal")),
42 LONGITUDE_REAL(RuleControlAttribute.LONGITUDE_REAL, n("dali.core.enums.featureControlValues.longitudeReal")),
43 GEAR(RuleControlAttribute.GEAR, n("dali.core.enums.featureControlValues.gear")),
44 NAME(RuleControlAttribute.NAME, n("dali.core.enums.featureControlValues.name")),
45 DEPARTMENT(RuleControlAttribute.SAMPLER_DEPARTMENT, n("dali.core.enums.featureControlValues.samplerDepartment")),
46 POSITIONING(RuleControlAttribute.POSITIONING, n("dali.core.enums.featureControlValues.positioning")),
47 POSITIONING_PRECISION(RuleControlAttribute.POSITIONING_PRECISION, n("dali.core.enums.featureControlValues.positioningPrecision")),
48 DEPTH(RuleControlAttribute.DEPTH, n("dali.core.enums.featureControlValues.depth")),
49 DEPTH_MAX(RuleControlAttribute.MAX_DEPTH, n("dali.core.enums.featureControlValues.depthMax")),
50 DEPTH_MIN(RuleControlAttribute.MIN_DEPTH, n("dali.core.enums.featureControlValues.depthMin")),
51 SIZE(RuleControlAttribute.SIZE, n("dali.core.enums.featureControlValues.size")),
52 SIZE_UNIT(RuleControlAttribute.SIZE_UNIT, n("dali.core.enums.featureControlValues.sizeUnit"));
53
54 private final RuleControlAttribute ruleControlAttribute;
55 private final String keyLabel;
56
57 ControlFeatureSamplingOperationValues(RuleControlAttribute ruleControlAttribute, String key) {
58 this.ruleControlAttribute = ruleControlAttribute;
59 this.keyLabel = key;
60 }
61
62
63
64
65
66
67 public String getLabel() {
68 return t(this.keyLabel);
69 }
70
71
72
73
74
75
76 public String getCode() {
77 return this.ruleControlAttribute.getValue();
78 }
79
80
81
82
83
84
85 public ControlFeatureDTO toControlFeatureDTO() {
86 ControlFeatureDTO dto = DaliBeanFactory.newControlFeatureDTO();
87 dto.setId(ordinal());
88 dto.setCode(getCode());
89 dto.setName(getLabel());
90 return dto;
91 }
92
93
94
95
96
97
98
99 public boolean equals(ControlFeatureDTO controlFeature) {
100 return controlFeature != null && getCode().equals(controlFeature.getCode());
101 }
102
103
104
105
106
107
108
109 public static ControlFeatureDTO toControlFeatureDTO(String code) {
110 ControlFeatureSamplingOperationValues value = getByCode(code);
111 if (value != null) {
112 return value.toControlFeatureDTO();
113 }
114 return null;
115 }
116
117
118
119
120
121
122
123 public static ControlFeatureSamplingOperationValues getByCode(String code) {
124 for (ControlFeatureSamplingOperationValues feature : ControlFeatureSamplingOperationValues.values()) {
125 if (StringUtils.isNotBlank(feature.getCode()) && feature.getCode().equals(code)) {
126 return feature;
127 }
128 }
129 return null;
130 }
131 }