Salome HOME
Modifications to respect PMD rules.
[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.splat.dal.bo.kernel.User;
9 import org.splat.service.UserService;
10 import org.splat.service.technical.RepositoryService;
11 import org.splat.simer.UploadBaseNextAction;
12
13
14 public class ImportUserAction extends UploadBaseNextAction {
15
16         /**
17          * Serial version ID.
18          */
19     private static final long serialVersionUID = 1516715800624817965L;
20
21     private transient List<User> _users;
22     private transient Set<User>  _newsers;
23         /**
24          * Injected repository service.
25          */
26         private RepositoryService _repositoryService;
27
28         /**
29          * Injected user service.
30          */
31         private UserService _userService;
32         
33         /**
34          * Value of the menu property. 
35          * It can be: none, create, open, study, knowledge, sysadmin, help.
36          */
37         private String _menuProperty;
38         
39         /**
40          * Value of the tool bar property. 
41          * It can be: none, standard, study, back.
42          */
43         private String _toolProperty;
44         
45         /**
46          * Value of the left menu property. 
47          * It can be: open, study, knowledge, scenario.
48          */
49         private String _leftMenuProperty;
50
51 //  ==============================================================================================================================
52 //  Action methods
53 //  ==============================================================================================================================
54
55     public String doImport () {
56       String res = SUCCESS;
57       try {
58         User       user    = getConnectedUser();     // The database administrator
59         File       updir   = getRepositoryService().getDownloadDirectory(user);
60         File       upfile  = new File(updir.getPath() + "/" + filename);
61
62         _newsers = getUserService().importUsers(upfile);
63         _users   = getUserService().selectAllUsers();
64         for (Iterator<User> i=_users.iterator(); i.hasNext(); ) {
65           User next = i.next();
66           if (!next.equals(user)) {
67                         continue;
68                 }
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       catch (Exception error) {
79         res = ERROR;            
80       }
81       return res;
82     }
83     
84 //  ==============================================================================================================================
85 //  Getters
86 //  ==============================================================================================================================
87
88     public List<User> getUsers () {
89 //  -----------------------------
90       return  _users;
91     }
92
93     public boolean isNew (final User user) {
94 //  --------------------------------
95       return _newsers.contains(user);
96     }
97
98         /**
99          * Get the repositoryService.
100          * @return the repositoryService
101          */
102         public RepositoryService getRepositoryService() {
103                 return _repositoryService;
104         }
105
106         /**
107          * Set the repositoryService.
108          * @param repositoryService the repositoryService to set
109          */
110         public void setRepositoryService(final RepositoryService repositoryService) {
111                 _repositoryService = repositoryService;
112         }
113
114         /**
115          * Get the userService.
116          * @return the userService
117          */
118         public UserService getUserService() {
119                 return _userService;
120         }
121
122         /**
123          * Set the userService.
124          * @param userService the userService to set
125          */
126         public void setUserService(final UserService userService) {
127                 _userService = userService;
128         }
129         
130         /**
131          * Get the menuProperty.
132          * @return the menuProperty
133          */
134         public String getMenuProperty() {
135                 return _menuProperty;
136         }
137
138         /**
139          * Set the menuProperty.
140          * @param menuProperty the menuProperty to set
141          */
142         public void setMenuProperty(final String menuProperty) {
143                 this._menuProperty = menuProperty;
144         }
145         
146         /**
147          * Get the toolProperty.
148          * @return the toolProperty
149          */
150         public String getToolProperty() {
151                 return _toolProperty;
152         }
153
154         /**
155          * Set the toolProperty.
156          * @param toolProperty the toolProperty to set
157          */
158         public void setToolProperty(final String toolProperty) {
159                 _toolProperty = toolProperty;
160         }
161         
162         /**
163          * Get the leftMenuProperty.
164          * @return the leftMenuProperty
165          */
166         public String getLeftMenuProperty() {
167                 return _leftMenuProperty;
168         }
169
170         /**
171          * Set the leftMenuProperty.
172          * @param leftMenuProperty the leftMenuProperty to set
173          */
174         public void setLeftMenuProperty(final String leftMenuProperty) {
175                 _leftMenuProperty = leftMenuProperty;
176         }
177 }