Salome HOME
Menus are improved
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / admin / ImportUserAction.java
1 package org.splat.simer.admin;
2
3 import java.io.File;
4 import java.util.Iterator;
5 import java.util.List;
6 import java.util.Set;
7
8 import org.hibernate.Session;
9 import org.hibernate.Transaction;
10 import org.splat.dal.bo.kernel.User;
11 import org.splat.service.UserService;
12 import org.splat.service.technical.RepositoryService;
13 import org.splat.simer.UploadBaseNextAction;
14 import org.splat.dal.dao.som.Database;
15
16
17 public class ImportUserAction extends UploadBaseNextAction {
18
19         /**
20          * Serial version ID.
21          */
22     private static final long serialVersionUID = 1516715800624817965L;
23
24     private List<User> users;
25     private Set<User>  newsers;
26         /**
27          * Injected repository service.
28          */
29         private RepositoryService _repositoryService;
30
31         /**
32          * Injected user service.
33          */
34         private UserService _userService;
35         
36         /**
37          * Value of the menu property. 
38          * It can be: none, create, open, study, knowledge, sysadmin, help.
39          */
40         private String _menuProperty;
41
42 //  ==============================================================================================================================
43 //  Action methods
44 //  ==============================================================================================================================
45
46     public String doImport () {
47       try {
48         User       user    = getConnectedUser();     // The database administrator
49         File       updir   = getRepositoryService().getDownloadDirectory(user);
50         File       upfile  = new File(updir.getPath() + "/" + filename);
51
52         newsers = getUserService().importUsers(upfile);
53         users   = getUserService().selectAllUsers();
54         for (Iterator<User> i=users.iterator(); i.hasNext(); ) {
55           User next = i.next();
56           if (!next.equals(user)) continue;
57           i.remove();                                // Just for not showing the corresponding reserved username
58           break;
59         }
60         
61         setMenuProperty("sysadmin");
62         initializationScreenContext(_menuProperty);
63         
64         return SUCCESS;
65       }
66       catch (Exception error) {
67         return ERROR;           
68       }
69     }
70     
71 //  ==============================================================================================================================
72 //  Getters
73 //  ==============================================================================================================================
74
75     public List<User> getUsers () {
76 //  -----------------------------
77       return  users;
78     }
79
80     public boolean isNew (User user) {
81 //  --------------------------------
82       return newsers.contains(user);
83     }
84
85         /**
86          * Get the repositoryService.
87          * @return the repositoryService
88          */
89         public RepositoryService getRepositoryService() {
90                 return _repositoryService;
91         }
92
93         /**
94          * Set the repositoryService.
95          * @param repositoryService the repositoryService to set
96          */
97         public void setRepositoryService(RepositoryService repositoryService) {
98                 _repositoryService = repositoryService;
99         }
100
101         /**
102          * Get the userService.
103          * @return the userService
104          */
105         public UserService getUserService() {
106                 return _userService;
107         }
108
109         /**
110          * Set the userService.
111          * @param userService the userService to set
112          */
113         public void setUserService(UserService userService) {
114                 _userService = userService;
115         }
116         
117         /**
118          * Get the menuProperty.
119          * @return the menuProperty
120          */
121         public String getMenuProperty() {
122                 return _menuProperty;
123         }
124
125         /**
126          * Set the menuProperty.
127          * @param menuProperty the menuProperty to set
128          */
129         public void setMenuProperty(String menuProperty) {
130                 this._menuProperty = menuProperty;
131         }
132 }