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