Some changes on queries done from the admin interface concering last login field...
[pithos] / src / gr / ebs / gss / server / admin / AdminServiceImpl.java
1 /*
2  * Copyright 2010 Electronic Business Systems Ltd.
3  *
4  * This file is part of GSS.
5  *
6  * GSS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 package gr.ebs.gss.server.admin;
20
21 import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;
22 import gr.ebs.gss.admin.client.AdminService;
23 import gr.ebs.gss.client.exceptions.InsufficientPermissionsException;
24 import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
25 import gr.ebs.gss.client.exceptions.RpcException;
26 import gr.ebs.gss.server.configuration.GSSConfigurationFactory;
27 import gr.ebs.gss.server.domain.dto.FileBodyDTO;
28 import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
29 import gr.ebs.gss.server.domain.dto.PermissionDTO;
30 import gr.ebs.gss.server.domain.dto.StatsDTO;
31 import gr.ebs.gss.server.domain.dto.SystemStatsDTO;
32 import gr.ebs.gss.server.domain.dto.UserClassDTO;
33 import gr.ebs.gss.server.domain.dto.UserDTO;
34 import gr.ebs.gss.server.ejb.AdminAPI;
35
36 import java.util.Date;
37 import java.util.List;
38 import java.util.Set;
39
40 import javax.naming.Context;
41 import javax.naming.InitialContext;
42 import javax.naming.NamingException;
43 import javax.rmi.PortableRemoteObject;
44
45 import org.apache.commons.logging.Log;
46 import org.apache.commons.logging.LogFactory;
47
48 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
49
50 public class AdminServiceImpl extends RemoteServiceServlet implements AdminService {
51         /**
52          * The logger.
53          */
54         private static Log logger = LogFactory.getLog(AdminServiceImpl.class);
55
56         /**
57          * A helper method that retrieves a reference to the AdminAPI bean and
58          * stores it for future use.
59          *
60          * @return an AdminAPI instance
61          * @throws RpcException in case an error occurs
62          */
63         protected AdminAPI getService() throws RpcException {
64                 try {
65                         final Context ctx = new InitialContext();
66                         final Object ref = ctx.lookup(getConfiguration().getString("adminApiPath"));
67                         return (AdminAPI) PortableRemoteObject.narrow(ref, AdminAPI.class);
68                 } catch (final NamingException e) {
69                         logger.error("Unable to retrieve the AdminAPI EJB", e);
70                         throw new RpcException("An error occurred while contacting the naming service");
71                 }
72         }
73
74         @Override
75         public List<UserDTO> getUsers() throws RpcException {
76                 return getService().searchUsers("");
77         }
78
79         @Override
80         public StatsDTO getUserStatistics(Long userId) throws RpcException, ObjectNotFoundException {
81                 return getService().getUserStatistics(userId);
82         }
83
84
85
86         @Override
87         public void toggleActiveUser(Long userId) throws RpcException, ObjectNotFoundException {
88                 getService().toggleActiveUser(userId);
89
90         }
91
92         @Override
93         public void setFilePermissions(String uri, Set<PermissionDTO> permissions) throws ObjectNotFoundException, RpcException {
94                 getService().setFilePermissions(uri, permissions);
95         }
96
97         @Override
98         public List<UserDTO> searchUsers(String query) throws RpcException {
99                 return getService().searchUsers(query);
100         }
101
102         @Override
103         public SystemStatsDTO getSystemStatistics() throws RpcException {
104                 return getService().getSystemStatistics();
105         }
106
107         @Override
108         public List<UserDTO> getLastLoggedInUsers(Date lastLoginDate) throws RpcException {
109                 return getService().getLastLoggedInUsers(lastLoginDate);
110         }
111
112         @Override
113         public void logout() {
114                 getThreadLocalRequest().getSession().invalidate();
115         }
116
117         @Override
118         public List<FileHeaderDTO> searchFiles(String query) throws RpcException, ObjectNotFoundException, InsufficientPermissionsException {
119                 if(query==null)
120                         throw new ObjectNotFoundException("Invalid query");
121                 String restUrl = GSSConfigurationFactory.getConfiguration().getString("restUrl");
122                 if(query.startsWith(restUrl))
123                         query= query.substring(restUrl.length(),query.length());
124                 if(query.indexOf("/")==-1)//do only a name search
125                         return getService().searchFileByFilename(query);
126                 return getService().getFiles(query);
127         }
128
129         @Override
130         public UserDTO getUser(String username) throws ObjectNotFoundException, RpcException{
131                 return getService().getUser(username);
132         }
133
134         @Override
135         public FileHeaderDTO getFile(long fileId) throws ObjectNotFoundException, RpcException {
136                 return getService().getFile(fileId);
137         }
138
139         @Override
140         public List<FileBodyDTO> getVersions(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException, RpcException {
141                 return getService().getVersions(userId, fileId);
142         }
143
144         @Override
145         public List<UserDTO> getUsersWaitingActivation() throws RpcException {
146                 return getService().getUsersWaitingActivation();
147         }
148
149         @Override
150         public void changeUserClass(Long userId, Long userClassId) throws RpcException, ObjectNotFoundException {
151                 getService().changeUserClass(userId, userClassId);
152
153         }
154
155         @Override
156         public List<UserClassDTO> getUserClasses() throws RpcException {
157                 return getService().getUserClasses();
158         }
159
160         @Override
161         public void saveOrUpdateUserClass(UserClassDTO userClass) throws RpcException, ObjectNotFoundException {
162                 getService().saveOrUpdateUserClass(userClass);
163         }
164
165         @Override
166         public void removeUserClass(UserClassDTO userClass) throws RpcException, ObjectNotFoundException {
167                 getService().removeUserClass(userClass);
168         }
169
170         @Override
171         public void removeUser(Long userId) throws RpcException, ObjectNotFoundException, InsufficientPermissionsException {
172                 getService().removeUser(userId);
173
174         }
175
176         @Override
177         public void fixSharedFlagForAllFoldersAndFiles() throws RpcException {
178                 getService().fixSharedFlagForAllFoldersAndFiles();              
179         }
180 }