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
.handlers
.HandlerUtil
;
39 * Refreshes the main EBI list, removing nodes which are not referenced by user
42 public class RefreshUsersList
extends AbstractHandler
{
43 private UserAdminService userAdminService
;
44 private Repository repository
;
46 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
47 Set
<String
> users
= userAdminService
.listUsers();
48 Session session
= null;
50 session
= repository
.login();
55 "select * from [" + ArgeoTypes
.ARGEO_USER_HOME
56 + "]", Query
.JCR_SQL2
);
57 NodeIterator nit
= query
.execute().getNodes();
58 while (nit
.hasNext()) {
59 Node node
= nit
.nextNode();
60 String username
= node
.getProperty(ArgeoNames
.ARGEO_USER_ID
)
62 if (!users
.contains(username
))
66 } catch (RepositoryException e
) {
67 JcrUtils
.discardQuietly(session
);
68 throw new ArgeoException("Cannot list users", e
);
70 JcrUtils
.logoutQuietly(session
);
73 userAdminService
.synchronize();
74 UsersView view
= (UsersView
) HandlerUtil
75 .getActiveWorkbenchWindow(event
).getActivePage()
76 .findView(UsersView
.ID
);
81 public void setUserAdminService(UserAdminService userAdminService
) {
82 this.userAdminService
= userAdminService
;
85 public void setRepository(Repository repository
) {
86 this.repository
= repository
;