1 package fr.ifremer.dali.service;
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 com.google.common.collect.ImmutableList;
27 import fr.ifremer.quadrige3.core.dao.referential.StatusCode;
28 import fr.ifremer.quadrige3.ui.core.dto.referential.StatusDTO;
29
30 import java.util.List;
31
32 /**
33 * Enumeration to provide status codes from national status
34 *
35 * @author Ludovic
36 */
37 public enum StatusFilter {
38
39 ALL(ImmutableList.of(StatusCode.ENABLE.getValue(), StatusCode.DISABLE.getValue(), StatusCode.TEMPORARY.getValue())),
40 ACTIVE(ImmutableList.of(StatusCode.ENABLE.getValue()));
41
42 private final List<String> statusCodes;
43
44 StatusFilter(List<String> statusCodes) {
45 this.statusCodes = statusCodes;
46 }
47
48 /**
49 * <p>toStatusCodes.</p>
50 *
51 * @return a {@link java.util.List} object.
52 */
53 public List<String> toStatusCodes() {
54 return statusCodes;
55 }
56
57 /**
58 * <p>intersect.</p>
59 *
60 * @param statusCode a {@link java.lang.String} object.
61 * @return a {@link java.util.List} object.
62 */
63 public List<String> intersect(String statusCode) {
64 if (statusCode == null) {
65 return statusCodes;
66 }
67 if (statusCodes.contains(statusCode)) {
68 return ImmutableList.of(statusCode);
69 } else {
70 return ImmutableList.of("BAD");
71 }
72 }
73
74 /**
75 * <p>intersect.</p>
76 *
77 * @param status a {@link StatusDTO} object.
78 * @return a {@link java.util.List} object.
79 */
80 public List<String> intersect(StatusDTO status) {
81 if (status == null) {
82 return statusCodes;
83 } else {
84 return intersect(status.getCode());
85 }
86 }
87
88 }