View Javadoc
1   package fr.ifremer.reefdb.dto.enums;
2   
3   /*
4    * #%L
5    * Reef DB :: Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
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   * ControlFeatureSurveyValues enum.
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), // FIXME uniformiser l'énumération du modèle
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       * <p>getLabel.</p>
79       *
80       * @return a {@link java.lang.String} object.
81       */
82      public String getLabel() {
83          return t(this.keyLabel);
84      }
85  
86      /**
87       * <p>Getter for the field <code>code</code>.</p>
88       *
89       * @return a {@link java.lang.String} object.
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      * <p>toControlFeatureDTO.</p>
101      *
102      * @return a {@link fr.ifremer.reefdb.dto.configuration.control.ControlFeatureDTO} object.
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      * <p>equals.</p>
114      *
115      * @param controlFeature a {@link fr.ifremer.reefdb.dto.configuration.control.ControlFeatureDTO} object.
116      * @return a boolean.
117      */
118     public boolean equals(ControlFeatureDTO controlFeature) {
119         return controlFeature != null && (getCode().equals(controlFeature.getCode()) || Objects.equals(getOldCode(), controlFeature.getCode()));
120     }
121 
122     /**
123      * <p>toControlFeatureDTO.</p>
124      *
125      * @param code a {@link java.lang.String} object.
126      * @return a {@link fr.ifremer.reefdb.dto.configuration.control.ControlFeatureDTO} object.
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      * <p>getByCode.</p>
138      *
139      * @param code a {@link java.lang.String} object.
140      * @return a {@link fr.ifremer.reefdb.dto.enums.ControlFeatureSurveyValues} object.
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 }