View Javadoc
1   package fr.ifremer.dali.service.administration.user;
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.Lists;
27  import fr.ifremer.dali.dao.administration.user.DaliQuserDao;
28  import fr.ifremer.quadrige3.core.dao.administration.user.PrivilegeCode;
29  import fr.ifremer.quadrige3.core.service.technical.CacheService;
30  import fr.ifremer.dali.dto.configuration.filter.person.PersonCriteriaDTO;
31  import fr.ifremer.dali.dto.referential.PersonDTO;
32  import fr.ifremer.dali.dto.referential.PrivilegeDTO;
33  import fr.ifremer.dali.service.StatusFilter;
34  import org.springframework.beans.factory.annotation.Autowired;
35  import org.springframework.stereotype.Service;
36  
37  import javax.annotation.Resource;
38  import java.util.Collection;
39  import java.util.List;
40  
41  /**
42   * <p>UserServiceImpl class.</p>
43   *
44   */
45  @Service("daliUserService")
46  public class UserServiceImpl extends fr.ifremer.quadrige3.core.service.administration.user.UserServiceImpl implements UserService {
47  
48      @Autowired
49      protected CacheService cacheService;
50  
51      @Resource(name = "daliQuserDao")
52      private DaliQuserDao quserDao;
53  
54      /** {@inheritDoc} */
55      @Override
56      public Integer getDepartmentIdByUserId(int userId) {
57          return quserDao.getDepartmentIdByUserId(userId);
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public List<PersonDTO> getActiveUsers() {
63          return quserDao.getAllUsers(StatusFilter.ACTIVE.toStatusCodes());
64      }
65  
66      @Override
67      public PersonDTO getUser(int userId) {
68          return quserDao.getUserById(userId);
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public List<PersonDTO> searchUser(PersonCriteriaDTO searchCriteria) {
74          List<String> statusCodes = StatusFilter.ALL.intersect(searchCriteria.getStatus());
75          Integer departmentId = searchCriteria.getDepartment() == null ?
76                  null : searchCriteria.getDepartment().getId();
77          String privilegeCode = searchCriteria.getPrivilege() == null ?
78                  null : searchCriteria.getPrivilege().getCode();
79          return quserDao.findUsersByCriteria(
80                  searchCriteria.getName(),
81                  searchCriteria.getFirstName(),
82                  searchCriteria.isStrictName(),
83                  searchCriteria.getLogin(),
84                  departmentId,
85                  privilegeCode, statusCodes);
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public List<PrivilegeDTO> getAllPrivileges() {
91          return quserDao.getAllPrivileges();
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public List<PrivilegeDTO> getAvailablePrivileges() {
97          List<PrivilegeDTO> availablePrivileges = Lists.newArrayList();
98          for (PrivilegeDTO privilege : getAllPrivileges()) {
99              if (PrivilegeCode.VALIDATOR.getValue().equals(privilege.getCode())
100                     || PrivilegeCode.QUALIFIER.getValue().equals(privilege.getCode())) {
101                 availablePrivileges.add(privilege);
102             }
103         }
104         return availablePrivileges;
105     }
106 
107     /** {@inheritDoc} */
108     @Override
109     public Collection<PrivilegeDTO> getPrivilegesByUser(Integer userId) {
110         return quserDao.getPrivilegesByUserId(userId);
111     }
112 
113 }