Mercurial > hg > LGServer
comparison src/main/java/de/mpiwg/web/SessionBean.java @ 0:7682c04c63a8
First commit of the source code!
author | "jurzua <jurzua@mpiwg-berlin.mpg.de>" |
---|---|
date | Tue, 10 Mar 2015 14:50:41 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7682c04c63a8 |
---|---|
1 package de.mpiwg.web; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import javax.faces.event.ActionEvent; | |
7 import javax.faces.event.AjaxBehaviorEvent; | |
8 | |
9 import org.apache.log4j.Logger; | |
10 import org.dom4j.Branch; | |
11 | |
12 import de.mpiwg.gazetteer.bo.LGBranch; | |
13 import de.mpiwg.gazetteer.bo.LGFile; | |
14 import de.mpiwg.gazetteer.dataverse.DataverseUtils; | |
15 import de.mpiwg.gazetteer.dataverse.bo.VDCUser; | |
16 import de.mpiwg.gazetteer.utils.DBService; | |
17 import de.mpiwg.gazetteer.utils.DataProvider; | |
18 import de.mpiwg.gazetteer.utils.SelectableObject; | |
19 | |
20 public class SessionBean extends AbstractBean { | |
21 | |
22 private static Logger logger = Logger.getLogger(SessionBean.class); | |
23 public static final String BEAN_NAME = "sessionBean"; | |
24 | |
25 private List<String> msgList = new ArrayList<String>(); | |
26 | |
27 private List<SelectableObject<LGBranch>> branches; | |
28 | |
29 private VDCUser user; | |
30 private String userName; | |
31 private String password; | |
32 | |
33 private String currentSectionId = "5190882"; | |
34 | |
35 private FileCreator fileCreator = new FileCreator(); | |
36 private BranchEditor branchEditor = new BranchEditor(); | |
37 private SearchBean searchPage = new SearchBean(); | |
38 | |
39 public SessionBean(){ | |
40 logger.info("#### SessionBean #####"); | |
41 } | |
42 | |
43 public void reset(){ | |
44 this.user = null; | |
45 this.branches = null; | |
46 this.fileCreator = new FileCreator(); | |
47 this.branchEditor = new BranchEditor(); | |
48 this.searchPage = new SearchBean(); | |
49 } | |
50 | |
51 public List<String> getMsgList() { | |
52 return msgList; | |
53 } | |
54 | |
55 public void setMsgList(List<String> msgList) { | |
56 this.msgList = msgList; | |
57 } | |
58 | |
59 public void listenerCloseMsgPopup(ActionEvent event){ | |
60 getSessionBean().setMsgList(null); | |
61 } | |
62 | |
63 public void listenerReloadBranches(ActionEvent event){ | |
64 this.reloadBranches(); | |
65 } | |
66 | |
67 public void listenerLogin(ActionEvent event){ | |
68 login0(); | |
69 } | |
70 | |
71 public void ajaxLogin(AjaxBehaviorEvent event){ | |
72 login0(); | |
73 } | |
74 | |
75 private void login0(){ | |
76 try { | |
77 this.user = DataverseUtils.login(userName, password); | |
78 if(user != null){ | |
79 reloadBranches(); | |
80 | |
81 }else{ | |
82 addMsg("User account no found or userName and password do not match!"); | |
83 } | |
84 | |
85 } catch (Exception e) { | |
86 internalError(e); | |
87 } | |
88 } | |
89 | |
90 public void listenerDeleteBranch(ActionEvent event){ | |
91 System.out.println("listenerDeleteBranch"); | |
92 try { | |
93 for(SelectableObject<LGBranch> so : new ArrayList<SelectableObject<LGBranch>>(this.branches)){ | |
94 if(so.isSelected()){ | |
95 this.branches.remove(so); | |
96 DataProvider.getInstance().deleteBranch(so.getObj()); | |
97 } | |
98 } | |
99 | |
100 } catch (Exception e) { | |
101 internalError(e); | |
102 } | |
103 } | |
104 | |
105 public void reloadBranches(){ | |
106 this.branches = new ArrayList<SelectableObject<LGBranch>>(); | |
107 if(user != null){ | |
108 for(LGBranch branch : DataProvider.getInstance().getBranches(this.user.getId())){ | |
109 if(!branch.isTransientDataLoaded()){ | |
110 branch.loadTransientData(); | |
111 } | |
112 this.branches.add(new SelectableObject<LGBranch>(branch)); | |
113 } | |
114 } | |
115 } | |
116 | |
117 public void listenerLogout(ActionEvent event){ | |
118 this.reset(); | |
119 } | |
120 | |
121 public String getPassword() { | |
122 return password; | |
123 } | |
124 | |
125 public void setPassword(String password) { | |
126 this.password = password; | |
127 } | |
128 | |
129 public VDCUser getUser() { | |
130 return user; | |
131 } | |
132 | |
133 public void setUser(VDCUser user) { | |
134 this.user = user; | |
135 } | |
136 | |
137 public String getUserName() { | |
138 return userName; | |
139 } | |
140 | |
141 public void setUserName(String userName) { | |
142 this.userName = userName; | |
143 } | |
144 | |
145 public List<SelectableObject<LGBranch>> getBranches() { | |
146 return branches; | |
147 } | |
148 | |
149 public void setBranches(List<SelectableObject<LGBranch>> branches) { | |
150 this.branches = branches; | |
151 } | |
152 | |
153 public String getCurrentSectionId() { | |
154 return currentSectionId; | |
155 } | |
156 | |
157 public void setCurrentSectionId(String currentSectionId) { | |
158 this.currentSectionId = currentSectionId; | |
159 } | |
160 | |
161 public FileCreator getFileCreator() { | |
162 return fileCreator; | |
163 } | |
164 | |
165 public void setFileCreator(FileCreator fileCreator) { | |
166 this.fileCreator = fileCreator; | |
167 } | |
168 | |
169 public BranchEditor getBranchEditor() { | |
170 return branchEditor; | |
171 } | |
172 | |
173 public void setBranchEditor(BranchEditor branchEditor) { | |
174 this.branchEditor = branchEditor; | |
175 } | |
176 | |
177 public SearchBean getSearchPage() { | |
178 return searchPage; | |
179 } | |
180 | |
181 public void setSearchPage(SearchBean searchPage) { | |
182 this.searchPage = searchPage; | |
183 } | |
184 | |
185 | |
186 } |