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   * FeatureControlSampleValues enum.
36   */
37  public enum ControlFeatureSamplingOperationValues {
38  
39       COMMENT(RuleControlAttribute.COMMENT, n("dali.core.enums.featureControlValues.comment")),
40       TIME(RuleControlAttribute.TIME, n("dali.core.enums.featureControlValues.time")),
41       LATITUDE_REAL(RuleControlAttribute.LATITUDE_REAL, n("dali.core.enums.featureControlValues.latitudeReal")),
42       LONGITUDE_REAL(RuleControlAttribute.LONGITUDE_REAL, n("dali.core.enums.featureControlValues.longitudeReal")),
43       GEAR(RuleControlAttribute.GEAR, n("dali.core.enums.featureControlValues.gear")),
44       NAME(RuleControlAttribute.NAME, n("dali.core.enums.featureControlValues.name")),
45       DEPARTMENT(RuleControlAttribute.SAMPLER_DEPARTMENT, n("dali.core.enums.featureControlValues.samplerDepartment")),
46       POSITIONING(RuleControlAttribute.POSITIONING, n("dali.core.enums.featureControlValues.positioning")),
47       POSITIONING_PRECISION(RuleControlAttribute.POSITIONING_PRECISION, n("dali.core.enums.featureControlValues.positioningPrecision")),
48       DEPTH(RuleControlAttribute.DEPTH, n("dali.core.enums.featureControlValues.depth")),
49       DEPTH_MAX(RuleControlAttribute.MAX_DEPTH, n("dali.core.enums.featureControlValues.depthMax")),
50       DEPTH_MIN(RuleControlAttribute.MIN_DEPTH, n("dali.core.enums.featureControlValues.depthMin")),
51       SIZE(RuleControlAttribute.SIZE, n("dali.core.enums.featureControlValues.size")),
52       SIZE_UNIT(RuleControlAttribute.SIZE_UNIT, n("dali.core.enums.featureControlValues.sizeUnit"));
53  
54      private final RuleControlAttribute ruleControlAttribute;
55      private final String keyLabel;
56  
57      ControlFeatureSamplingOperationValues(RuleControlAttribute ruleControlAttribute, String key) {
58          this.ruleControlAttribute = ruleControlAttribute;
59          this.keyLabel = key;
60      }
61  
62      /**
63       * <p>getLabel.</p>
64       *
65       * @return a {@link java.lang.String} object.
66       */
67      public String getLabel() {
68          return t(this.keyLabel);
69      }
70  
71      /**
72       * <p>Getter for the field <code>code</code>.</p>
73       *
74       * @return a {@link java.lang.String} object.
75       */
76      public String getCode() {
77          return this.ruleControlAttribute.getValue();
78      }
79  
80      /**
81       * <p>toControlFeatureDTO.</p>
82       *
83       * @return a {@link fr.ifremer.dali.dto.configuration.control.ControlFeatureDTO} object.
84       */
85      public ControlFeatureDTO toControlFeatureDTO() {
86          ControlFeatureDTO dto = DaliBeanFactory.newControlFeatureDTO();
87          dto.setId(ordinal());
88          dto.setCode(getCode());
89          dto.setName(getLabel());
90          return dto;
91      }
92  
93      /**
94       * <p>equals.</p>
95       *
96       * @param controlFeature a {@link fr.ifremer.dali.dto.configuration.control.ControlFeatureDTO} object.
97       * @return a boolean.
98       */
99      public boolean equals(ControlFeatureDTO controlFeature) {
100         return controlFeature != null && getCode().equals(controlFeature.getCode());
101     }
102 
103     /**
104      * <p>toControlFeatureDTO.</p>
105      *
106      * @param code a {@link java.lang.String} object.
107      * @return a {@link fr.ifremer.dali.dto.configuration.control.ControlFeatureDTO} object.
108      */
109     public static ControlFeatureDTO toControlFeatureDTO(String code) {
110         ControlFeatureSamplingOperationValues value = getByCode(code);
111         if (value != null) {
112             return value.toControlFeatureDTO();
113         }
114         return null;
115     }
116 
117     /**
118      * <p>getByCode.</p>
119      *
120      * @param code a {@link java.lang.String} object.
121      * @return a {@link fr.ifremer.dali.dto.enums.ControlFeatureSamplingOperationValues} object.
122      */
123     public static ControlFeatureSamplingOperationValues getByCode(String code) {
124         for (ControlFeatureSamplingOperationValues feature : ControlFeatureSamplingOperationValues.values()) {
125             if (StringUtils.isNotBlank(feature.getCode()) && feature.getCode().equals(code)) {
126                 return feature;
127             }
128         }
129         return null;
130     }
131 }