]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/admin/ImportUserAction.java
Salome HOME
Refactoring continues: UserService is created instead of UserDirectory. Database...
[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 //  Action methods
38 //  ==============================================================================================================================
39
40     public String doImport () {
41 //  -------------------------
42       Session      connex  = Database.getCurSession();
43       Transaction  transax = connex.beginTransaction();
44       try {
45         User       user    = getConnectedUser();     // The database administrator
46         File       updir   = getRepositoryService().getDownloadDirectory(user);
47         File       upfile  = new File(updir.getPath() + "/" + filename);
48
49         newsers = getUserService().importUsers(upfile);
50         users   = getUserService().selectAllUsers();
51         for (Iterator<User> i=users.iterator(); i.hasNext(); ) {
52           User next = i.next();
53           if (!next.equals(user)) continue;
54           i.remove();                                // Just for not showing the corresponding reserved username
55           break;
56         }
57         transax.commit();
58         return SUCCESS;
59       }
60       catch (Exception error) {
61         return ERROR;           
62       }
63     }
64
65 //  ==============================================================================================================================
66 //  Getters
67 //  ==============================================================================================================================
68
69     public List<User> getUsers () {
70 //  -----------------------------
71       return  users;
72     }
73
74     public boolean isNew (User user) {
75 //  --------------------------------
76       return newsers.contains(user);
77     }
78
79         /**
80          * Get the repositoryService.
81          * @return the repositoryService
82          */
83         public RepositoryService getRepositoryService() {
84                 return _repositoryService;
85         }
86
87         /**
88          * Set the repositoryService.
89          * @param repositoryService the repositoryService to set
90          */
91         public void setRepositoryService(RepositoryService repositoryService) {
92                 _repositoryService = repositoryService;
93         }
94
95         /**
96          * Get the userService.
97          * @return the userService
98          */
99         public UserService getUserService() {
100                 return _userService;
101         }
102
103         /**
104          * Set the userService.
105          * @param userService the userService to set
106          */
107         public void setUserService(UserService userService) {
108                 _userService = userService;
109         }
110 }