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 ControlFeatureSurveyValues {
40
41 CAMPAIGN(RuleControlAttribute.CAMPAIGN, n("reefdb.core.enums.featureControlValues.campaign")),
42 COMMENT(RuleControlAttribute.COMMENT, n("reefdb.core.enums.featureControlValues.comment")),
43 VALIDATION_COMMENT(RuleControlAttribute.VALIDATION_COMMENT, n("reefdb.core.enums.featureControlValues.validationComment")),
44 DATE(RuleControlAttribute.DATE, n("reefdb.core.enums.featureControlValues.date")),
45 CONTROL_DATE(RuleControlAttribute.CONTROL_DATE, n("reefdb.core.enums.featureControlValues.controlDate")),
46 UPDATE_DATE(RuleControlAttribute.UPDATE_DATE, n("reefdb.core.enums.featureControlValues.updateDate")),
47 VALIDATION_DATE(RuleControlAttribute.VALIDATION_DATE, n("reefdb.core.enums.featureControlValues.validationDate")),
48 TIME(RuleControlAttribute.TIME, n("reefdb.core.enums.featureControlValues.time")),
49 LATITUDE_MAX_LOCATION(RuleControlAttribute.LATITUDE_MAX_LOCATION, n("reefdb.core.enums.featureControlValues.latitudeMaxLocation")),
50 LATITUDE_MIN_LOCATION(RuleControlAttribute.LATITUDE_MIN_LOCATION, n("reefdb.core.enums.featureControlValues.latitudeMinLocation")),
51 LATITUDE_REAL_SURVEY(RuleControlAttribute.LATITUDE_REAL, n("reefdb.core.enums.featureControlValues.latitudeReal")),
52 LONGITUDE_MAX_LOCATION(RuleControlAttribute.LONGITUDE_MAX_LOCATION, n("reefdb.core.enums.featureControlValues.longitudeMaxLocation")),
53 LONGITUDE_MIN_LOCATION(RuleControlAttribute.LONGITUDE_MIN_LOCATION, n("reefdb.core.enums.featureControlValues.longitudeMinLocation")),
54 LONGITUDE_REAL_SURVEY(RuleControlAttribute.LONGITUDE_REAL, n("reefdb.core.enums.featureControlValues.longitudeReal")),
55 NAME(RuleControlAttribute.NAME, n("reefdb.core.enums.featureControlValues.name"), RuleControlAttribute.NAME_REEF_DB),
56 DEPARTMENT(RuleControlAttribute.RECORDER_DEPARTMENT, n("reefdb.core.enums.featureControlValues.department")),
57 POSITIONING(RuleControlAttribute.POSITIONING, n("reefdb.core.enums.featureControlValues.positioning")),
58 POSITIONING_PRECISION(RuleControlAttribute.POSITIONING_PRECISION, n("reefdb.core.enums.featureControlValues.positioningPrecision")),
59 PRECISE_DEPTH(RuleControlAttribute.DEPTH, n("reefdb.core.enums.featureControlValues.preciseDepth")),
60 PROGRAM(RuleControlAttribute.PROGRAM, n("reefdb.core.enums.featureControlValues.program")),
61 LOCATION(RuleControlAttribute.LOCATION, n("reefdb.core.enums.featureControlValues.location"));
62
63 private final RuleControlAttribute ruleControlAttribute;
64 private final String keyLabel;
65 private final RuleControlAttribute oldRuleControlAttribute;
66
67 ControlFeatureSurveyValues(RuleControlAttribute ruleControlAttribute, String key) {
68 this(ruleControlAttribute, key, null);
69 }
70
71 ControlFeatureSurveyValues(RuleControlAttribute ruleControlAttribute, String key, RuleControlAttribute oldRuleControlAttribute) {
72 this.ruleControlAttribute = ruleControlAttribute;
73 this.keyLabel = key;
74 this.oldRuleControlAttribute = oldRuleControlAttribute;
75 }
76
77
78
79
80
81
82 public String getLabel() {
83 return t(this.keyLabel);
84 }
85
86
87
88
89
90
91 public String getCode() {
92 return ruleControlAttribute.getValue();
93 }
94
95 public String getOldCode() {
96 return oldRuleControlAttribute != null ? oldRuleControlAttribute.getValue() : null;
97 }
98
99
100
101
102
103
104 public ControlFeatureDTO toControlFeatureDTO() {
105 ControlFeatureDTO dto = ReefDbBeanFactory.newControlFeatureDTO();
106 dto.setId(ordinal());
107 dto.setCode(getCode());
108 dto.setName(getLabel());
109 return dto;
110 }
111
112
113
114
115
116
117
118 public boolean equals(ControlFeatureDTO controlFeature) {
119 return controlFeature != null && (getCode().equals(controlFeature.getCode()) || Objects.equals(getOldCode(), controlFeature.getCode()));
120 }
121
122
123
124
125
126
127
128 public static ControlFeatureDTO toControlFeatureDTO(String code) {
129 ControlFeatureSurveyValues value = getByCode(code);
130 if (value != null) {
131 return value.toControlFeatureDTO();
132 }
133 return null;
134 }
135
136
137
138
139
140
141
142 public static ControlFeatureSurveyValues getByCode(String code) {
143 for (final ControlFeatureSurveyValues enumValue : ControlFeatureSurveyValues.values()) {
144 if (StringUtils.isNotBlank(enumValue.getCode()) && (enumValue.getCode().equals(code) || Objects.equals(enumValue.getOldCode(), code))) {
145 return enumValue;
146 }
147 }
148 return null;
149 }
150 }