]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/admin/ImportUserAction.java
Salome HOME
Left menu is 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          * Value of the tool bar property. 
44          * It can be: none, standard, study, back.
45          */
46         private String _toolProperty;
47         
48         /**
49          * Value of the left menu property. 
50          * It can be: open, study, knowledge, scenario.
51          */
52         private String _leftMenuProperty;
53
54 //  ==============================================================================================================================
55 //  Action methods
56 //  ==============================================================================================================================
57
58     public String doImport () {
59       try {
60         User       user    = getConnectedUser();     // The database administrator
61         File       updir   = getRepositoryService().getDownloadDirectory(user);
62         File       upfile  = new File(updir.getPath() + "/" + filename);
63
64         newsers = getUserService().importUsers(upfile);
65         users   = getUserService().selectAllUsers();
66         for (Iterator<User> i=users.iterator(); i.hasNext(); ) {
67           User next = i.next();
68           if (!next.equals(user)) continue;
69           i.remove();                                // Just for not showing the corresponding reserved username
70           break;
71         }
72         
73         setMenuProperty("sysadmin");
74         setToolProperty("none");
75         setLeftMenuProperty("open");
76         initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
77         
78         return SUCCESS;
79       }
80       catch (Exception error) {
81         return ERROR;           
82       }
83     }
84     
85 //  ==============================================================================================================================
86 //  Getters
87 //  ==============================================================================================================================
88
89     public List<User> getUsers () {
90 //  -----------------------------
91       return  users;
92     }
93
94     public boolean isNew (User user) {
95 //  --------------------------------
96       return newsers.contains(user);
97     }
98
99         /**
100          * Get the repositoryService.
101          * @return the repositoryService
102          */
103         public RepositoryService getRepositoryService() {
104                 return _repositoryService;
105         }
106
107         /**
108          * Set the repositoryService.
109          * @param repositoryService the repositoryService to set
110          */
111         public void setRepositoryService(RepositoryService repositoryService) {
112                 _repositoryService = repositoryService;
113         }
114
115         /**
116          * Get the userService.
117          * @return the userService
118          */
119         public UserService getUserService() {
120                 return _userService;
121         }
122
123         /**
124          * Set the userService.
125          * @param userService the userService to set
126          */
127         public void setUserService(UserService userService) {
128                 _userService = userService;
129         }
130         
131         /**
132          * Get the menuProperty.
133          * @return the menuProperty
134          */
135         public String getMenuProperty() {
136                 return _menuProperty;
137         }
138
139         /**
140          * Set the menuProperty.
141          * @param menuProperty the menuProperty to set
142          */
143         public void setMenuProperty(String menuProperty) {
144                 this._menuProperty = menuProperty;
145         }
146         
147         /**
148          * Get the toolProperty.
149          * @return the toolProperty
150          */
151         public String getToolProperty() {
152                 return _toolProperty;
153         }
154
155         /**
156          * Set the toolProperty.
157          * @param toolProperty the toolProperty to set
158          */
159         public void setToolProperty(final String toolProperty) {
160                 _toolProperty = toolProperty;
161         }
162         
163         /**
164          * Get the leftMenuProperty.
165          * @return the leftMenuProperty
166          */
167         public String getLeftMenuProperty() {
168                 return _leftMenuProperty;
169         }
170
171         /**
172          * Set the leftMenuProperty.
173          * @param leftMenuProperty the leftMenuProperty to set
174          */
175         public void setLeftMenuProperty(final String leftMenuProperty) {
176                 _leftMenuProperty = leftMenuProperty;
177         }
178 }