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