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.RuleControlEntity;
27  import fr.ifremer.dali.dto.DaliBeanFactory;
28  import fr.ifremer.dali.dto.configuration.control.ControlElementDTO;
29  
30  import static org.nuiton.i18n.I18n.n;
31  import static org.nuiton.i18n.I18n.t;
32  
33  /**
34   * ElementControl enum.
35   */
36  public enum ControlElementValues {
37  
38      SURVEY(RuleControlEntity.SURVEY, n("dali.core.enums.elementControlValues.observation")),
39      SAMPLING_OPERATION(RuleControlEntity.SAMPLING_OPERATION, n("dali.core.enums.elementControlValues.samplingOperation")),
40      MEASUREMENT(RuleControlEntity.MEASUREMENT, n("dali.core.enums.elementControlValues.measurement")),
41      TAXON_MEASUREMENT(RuleControlEntity.TAXON_MEASUREMENT, n("dali.core.enums.elementControlValues.taxonMeasurement"));
42  
43      private final RuleControlEntity ruleControlEntity;
44      private final String keyLabel;
45  
46      ControlElementValues(RuleControlEntity ruleControlEntity, String keyLabel) {
47          this.ruleControlEntity = ruleControlEntity;
48          this.keyLabel = keyLabel;
49      }
50  
51      /**
52       * <p>getLabel.</p>
53       *
54       * @return a {@link java.lang.String} object.
55       */
56      public String getLabel() {
57          return t(this.keyLabel);
58      }
59  
60      /**
61       * <p>Getter for the field <code>code</code>.</p>
62       *
63       * @return a {@link java.lang.String} object.
64       */
65      public String getCode() {
66          return this.ruleControlEntity.getValue();
67      }
68  
69      /**
70       * <p>toControlElementDTO.</p>
71       *
72       * @return a {@link fr.ifremer.dali.dto.configuration.control.ControlElementDTO} object.
73       */
74      public ControlElementDTO toControlElementDTO() {
75          ControlElementDTO dto = DaliBeanFactory.newControlElementDTO();
76          dto.setId(ordinal());
77          dto.setCode(getCode());
78          dto.setName(getLabel());
79          return dto;
80      }
81  
82      /**
83       * <p>equals.</p>
84       *
85       * @param controlElement a {@link fr.ifremer.dali.dto.configuration.control.ControlElementDTO} object.
86       * @return a boolean.
87       */
88      public boolean equals(ControlElementDTO controlElement) {
89          return controlElement != null && getCode().equals(controlElement.getCode());
90      }
91  
92      /**
93       * <p>toControlElementDTO.</p>
94       *
95       * @param code a {@link java.lang.String} object.
96       * @return a {@link fr.ifremer.dali.dto.configuration.control.ControlElementDTO} object.
97       */
98      public static ControlElementDTO toControlElementDTO(String code) {
99          ControlElementValues value = getByCode(code);
100         if (value != null) {
101             return value.toControlElementDTO();
102         }
103         return null;
104     }
105 
106     /**
107      * <p>getByCode.</p>
108      *
109      * @param code a {@link java.lang.String} object.
110      * @return a {@link fr.ifremer.dali.dto.enums.ControlElementValues} object.
111      */
112     public static ControlElementValues getByCode(String code) {
113         for (ControlElementValues value : values()) {
114             if (value.getCode().equals(code)) {
115                 return value;
116             }
117         }
118         return null;
119     }
120 }