View Javadoc
1   package fr.ifremer.dali.dto.enums;
2   
3   /*
4    * #%L
5    * Dali :: 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.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   * ControlFeatureSurveyValues enum.
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       * <p>getLabel.</p>
74       *
75       * @return a {@link java.lang.String} object.
76       */
77      public String getLabel() {
78          return t(this.keyLabel);
79      }
80  
81      /**
82       * <p>Getter for the field <code>code</code>.</p>
83       *
84       * @return a {@link java.lang.String} object.
85       */
86      public String getCode() {
87          return this.ruleControlAttribute.getValue();
88      }
89  
90      /**
91       * <p>toControlFeatureDTO.</p>
92       *
93       * @return a {@link fr.ifremer.dali.dto.configuration.control.ControlFeatureDTO} object.
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      * <p>equals.</p>
105      *
106      * @param controlFeature a {@link fr.ifremer.dali.dto.configuration.control.ControlFeatureDTO} object.
107      * @return a boolean.
108      */
109     public boolean equals(ControlFeatureDTO controlFeature) {
110         return controlFeature != null && getCode().equals(controlFeature.getCode());
111     }
112 
113     /**
114      * <p>toControlFeatureDTO.</p>
115      *
116      * @param code a {@link java.lang.String} object.
117      * @return a {@link fr.ifremer.dali.dto.configuration.control.ControlFeatureDTO} object.
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      * <p>getByCode.</p>
129      *
130      * @param code a {@link java.lang.String} object.
131      * @return a {@link fr.ifremer.dali.dto.enums.ControlFeatureSurveyValues} object.
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 }