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