2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.security
.ui
.admin
.commands
;
20 import javax
.jcr
.Node
;
21 import javax
.jcr
.NodeIterator
;
22 import javax
.jcr
.Repository
;
23 import javax
.jcr
.RepositoryException
;
24 import javax
.jcr
.Session
;
25 import javax
.jcr
.query
.Query
;
27 import org
.argeo
.ArgeoException
;
28 import org
.argeo
.jcr
.ArgeoNames
;
29 import org
.argeo
.jcr
.ArgeoTypes
;
30 import org
.argeo
.jcr
.JcrUtils
;
31 import org
.argeo
.security
.UserAdminService
;
32 import org
.argeo
.security
.ui
.admin
.views
.UsersView
;
33 import org
.eclipse
.core
.commands
.AbstractHandler
;
34 import org
.eclipse
.core
.commands
.ExecutionEvent
;
35 import org
.eclipse
.core
.commands
.ExecutionException
;
36 import org
.eclipse
.ui
.IWorkbenchPart
;
37 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
40 * Refreshes the main user list, removing nodes which are not referenced by user
43 public class RefreshUsersList
extends AbstractHandler
{
44 private UserAdminService userAdminService
;
45 private Repository repository
;
47 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
48 Set
<String
> users
= userAdminService
.listUsers();
49 Session session
= null;
51 session
= repository
.login();
56 "select * from [" + ArgeoTypes
.ARGEO_USER_HOME
57 + "]", Query
.JCR_SQL2
);
58 NodeIterator nit
= query
.execute().getNodes();
59 while (nit
.hasNext()) {
60 Node node
= nit
.nextNode();
61 String username
= node
.getProperty(ArgeoNames
.ARGEO_USER_ID
)
63 if (!users
.contains(username
))
67 } catch (RepositoryException e
) {
68 JcrUtils
.discardQuietly(session
);
69 throw new ArgeoException("Cannot list users", e
);
71 JcrUtils
.logoutQuietly(session
);
73 userAdminService
.synchronize();
75 // FIXME try to refresh views that extend the UsersView and have another
77 IWorkbenchPart part
= HandlerUtil
.getActiveWorkbenchWindow(event
)
78 .getActivePage().getActivePart();
79 if (part
instanceof UsersView
)
80 ((UsersView
) part
).refresh();
82 // Try to refresh UsersView if opened
83 UsersView view
= (UsersView
) HandlerUtil
84 .getActiveWorkbenchWindow(event
).getActivePage()
85 .findView(UsersView
.ID
);
92 public void setUserAdminService(UserAdminService userAdminService
) {
93 this.userAdminService
= userAdminService
;
96 public void setRepository(Repository repository
) {
97 this.repository
= repository
;