2 * Copyright 2010 Electronic Business Systems Ltd.
4 * This file is part of GSS.
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.
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.
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/>.
19 package gr.ebs.gss.server.admin;
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;
36 import java.util.Date;
37 import java.util.List;
40 import javax.naming.Context;
41 import javax.naming.InitialContext;
42 import javax.naming.NamingException;
43 import javax.rmi.PortableRemoteObject;
45 import org.apache.commons.logging.Log;
46 import org.apache.commons.logging.LogFactory;
48 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
50 public class AdminServiceImpl extends RemoteServiceServlet implements AdminService {
54 private static Log logger = LogFactory.getLog(AdminServiceImpl.class);
57 * A helper method that retrieves a reference to the AdminAPI bean and
58 * stores it for future use.
60 * @return an AdminAPI instance
61 * @throws RpcException in case an error occurs
63 protected AdminAPI getService() throws RpcException {
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");
75 public List<UserDTO> getUsers() throws RpcException, ObjectNotFoundException {
76 return getService().searchUsers("");
80 public StatsDTO getUserStatistics(Long userId) throws RpcException, ObjectNotFoundException {
81 return getService().getUserStatistics(userId);
87 public void toggleActiveUser(Long userId) throws RpcException, ObjectNotFoundException {
88 getService().toggleActiveUser(userId);
93 public void setFilePermissions(String uri, Set<PermissionDTO> permissions) throws ObjectNotFoundException, RpcException {
94 getService().setFilePermissions(uri, permissions);
98 public List<UserDTO> searchUsers(String query) throws RpcException, ObjectNotFoundException {
99 return getService().searchUsers(query);
103 public SystemStatsDTO getSystemStatistics() throws RpcException {
104 return getService().getSystemStatistics();
108 public List<UserDTO> getLastLoggedInUsers(Date lastLoginDate) throws RpcException {
109 return getService().getLastLoggedInUsers(lastLoginDate);
113 public void logout() {
114 getThreadLocalRequest().getSession().invalidate();
118 public List<FileHeaderDTO> searchFiles(String query) throws RpcException, ObjectNotFoundException, InsufficientPermissionsException {
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);
130 public UserDTO getUser(String username) throws ObjectNotFoundException, RpcException{
131 return getService().getUser(username);
135 public FileHeaderDTO getFile(long fileId) throws ObjectNotFoundException, RpcException {
136 return getService().getFile(fileId);
140 public List<FileBodyDTO> getVersions(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException, RpcException {
141 return getService().getVersions(userId, fileId);
145 public List<UserDTO> getUsersWaitingActivation() throws RpcException {
146 return getService().getUsersWaitingActivation();
150 public void changeUserClass(Long userId, Long userClassId) throws RpcException, ObjectNotFoundException {
151 getService().changeUserClass(userId, userClassId);
156 public List<UserClassDTO> getUserClasses() throws RpcException {
157 return getService().getUserClasses();
161 public void saveOrUpdateUserClass(UserClassDTO userClass) throws RpcException, ObjectNotFoundException {
162 getService().saveOrUpdateUserClass(userClass);
166 public void removeUserClass(UserClassDTO userClass) throws RpcException, ObjectNotFoundException {
167 getService().removeUserClass(userClass);
171 public void removeUser(Long userId) throws RpcException, ObjectNotFoundException, InsufficientPermissionsException {
172 getService().removeUser(userId);