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