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   * ControlFeatureMeasurementValues enum.
36   */
37  public enum ControlFeatureTaxonMeasurementValues {
38  
39       ANALYST(RuleControlAttribute.ANALYST_DEPARTMENT, n("dali.core.enums.featureControlValues.analyst")),
40       TAXON_GROUP(RuleControlAttribute.TAXON_GROUP, n("dali.core.enums.featureControlValues.taxonGroup")),
41       TAXON(RuleControlAttribute.TAXON, n("dali.core.enums.featureControlValues.taxon")),
42       PMFM(RuleControlAttribute.PMFM, n("dali.core.enums.featureControlValues.pmfm")),
43       NUMERICAL_VALUE(RuleControlAttribute.NUMERICAL_VALUE, n("dali.core.enums.featureControlValues.numericalValue")),
44       QUALITATIVE_VALUE(RuleControlAttribute.QUALITATIVE_VALUE, n("dali.core.enums.featureControlValues.qualitativeValue"));
45  
46      private final RuleControlAttribute ruleControlAttribute;
47      private final String keyLabel;
48  
49      ControlFeatureTaxonMeasurementValues(RuleControlAttribute ruleControlAttribute, String key) {
50          this.ruleControlAttribute = ruleControlAttribute;
51          this.keyLabel = key;
52      }
53  
54      /**
55       * <p>getLabel.</p>
56       *
57       * @return a {@link String} object.
58       */
59      public String getLabel() {
60          return t(this.keyLabel);
61      }
62  
63      /**
64       * <p>Getter for the field <code>code</code>.</p>
65       *
66       * @return a {@link String} object.
67       */
68      public String getCode() {
69          return this.ruleControlAttribute.getValue();
70      }
71  
72      /**
73       * <p>toControlFeatureDTO.</p>
74       *
75       * @return a {@link ControlFeatureDTO} object.
76       */
77      public ControlFeatureDTO toControlFeatureDTO() {
78          ControlFeatureDTO dto = DaliBeanFactory.newControlFeatureDTO();
79          dto.setId(ordinal());
80          dto.setCode(getCode());
81          dto.setName(getLabel());
82          return dto;
83      }
84  
85      /**
86       * <p>equals.</p>
87       *
88       * @param controlFeature a {@link ControlFeatureDTO} object.
89       * @return a boolean.
90       */
91      public boolean equals(ControlFeatureDTO controlFeature) {
92          return controlFeature != null && getCode().equals(controlFeature.getCode());
93      }
94  
95      /**
96       * <p>toControlFeatureDTO.</p>
97       *
98       * @param code a {@link String} object.
99       * @return a {@link ControlFeatureDTO} object.
100      */
101     public static ControlFeatureDTO toControlFeatureDTO(String code) {
102         ControlFeatureTaxonMeasurementValues value = getByCode(code);
103         if (value != null) {
104             return value.toControlFeatureDTO();
105         }
106         return null;
107     }
108 
109     /**
110      * <p>getByCode.</p>
111      *
112      * @param code a {@link String} object.
113      * @return a {@link ControlFeatureTaxonMeasurementValues} object.
114      */
115     public static ControlFeatureTaxonMeasurementValues getByCode(String code) {
116         for (ControlFeatureTaxonMeasurementValues enumValue : ControlFeatureTaxonMeasurementValues.values()) {
117             if (StringUtils.isNotBlank(enumValue.getCode()) && enumValue.getCode().equals(code)) {
118                 return enumValue;
119             }
120         }
121         return null;
122     }
123 }