Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/search/beans/DisplayBean.java @ 72:70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
author | casties |
---|---|
date | Tue, 22 Dec 2015 20:07:13 +0100 |
parents | 4ec8d4cfad26 |
children | 985dcecba904 |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.search.beans; |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import javax.faces.event.ActionEvent; | |
7 import javax.faces.model.SelectItem; | |
8 | |
9 import org.apache.log4j.Logger; | |
72
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
10 import org.mpi.openmind.repository.bo.Attribute; |
1 | 11 import org.mpi.openmind.repository.bo.Entity; |
12 | |
13 import de.mpiwg.itgroup.ismi.auxObjects.SelectItem0; | |
14 import de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean; | |
15 import de.mpiwg.itgroup.ismi.entry.utils.PrivacityUtils; | |
16 import de.mpiwg.itgroup.ismi.utils.templates.TitleTemplate; | |
17 import de.mpiwg.itgroup.ismi.utils.templates.WitnessTemplate; | |
18 | |
19 public class DisplayBean extends AbstractISMIBean { | |
20 | |
21 /** | |
22 * | |
23 */ | |
24 private static final long serialVersionUID = 1296816397468908012L; | |
25 | |
26 private static Logger logger = Logger.getLogger(DisplayBean.class); | |
27 | |
28 protected TitleTemplate title; | |
29 protected WitnessTemplate witness; | |
30 | |
31 //Witness elements | |
32 protected List<SelectItem0> witnessItems = new ArrayList<SelectItem0>(); | |
33 protected Long selectedWitnessId; | |
72
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
34 protected boolean showWitnessesWithScans = false; |
1 | 35 |
36 //Title elements | |
37 protected Long selectedTitleId; | |
38 protected List<SelectItem0> titleItems = new ArrayList<SelectItem0>(); | |
39 | |
40 protected void resetDisplay(){ | |
41 this.witness = null; | |
42 this.selectedWitnessId = null; | |
43 this.title = null; | |
44 this.selectedTitleId = null; | |
45 this.witnessItems = new ArrayList<SelectItem0>(); | |
46 } | |
47 | |
48 public void showTitle(Long textId){ | |
49 this.selectedTitleId = textId; | |
50 | |
51 this.witness = null; | |
52 this.witnessItems = new ArrayList<SelectItem0>(); | |
53 this.selectedWitnessId = null; | |
54 | |
55 long start = System.currentTimeMillis(); | |
56 | |
57 Entity entTitle = getWrapper().getEntityById(this.selectedTitleId); | |
58 | |
59 if(this.selectedTitleId != null){ | |
60 | |
61 this.titleItems = SelectItem0.valueChange(titleItems, textId); | |
62 this.title = new TitleTemplate(entTitle, getWrapper(), false); | |
63 | |
64 //****** getting witnesses ********************** | |
65 long startWitness = System.currentTimeMillis(); | |
72
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
66 List<Entity> list = new ArrayList<Entity>(); |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
67 List<Entity> allwits = getWrapper().getSourcesForTargetRelation(selectedTitleId, is_exemplar_of, WITNESS, -1); |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
68 for (Entity witness : allwits) { |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
69 if (this.showWitnessesWithScans) { |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
70 List<Entity> codices = getWrapper().getTargetsForSourceRelation(witness.getId(), is_part_of, CODEX, 1); |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
71 Entity codex = codices.get(0); |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
72 // TODO: look at DIGITALIZATION |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
73 Attribute pub = getWrapper().getAttributeByName(codex.getId(), "public"); |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
74 if (pub == null || ! pub.getValue().equals("true")) { |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
75 continue; |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
76 } |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
77 } |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
78 SelectItem0 item = new SelectItem0(witness.getId(), witness.getOwnValue() + " [" + witness.getId() + "]", true); |
1 | 79 this.witnessItems.add(item); |
72
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
80 list.add(witness); |
1 | 81 } |
82 | |
83 if(list.size() > 0){ | |
84 this.showWitness(list.get(0).getId()); | |
85 } | |
86 | |
87 long diff = System.currentTimeMillis() - startWitness; | |
88 if(diff > 1000){ | |
89 logger.info("Time - listenerShowTitle().getSourcesForTargetRelation(title, 'X', WITNESS, -1) = " + diff + " [ms], Text id= " + this.selectedTitleId); | |
90 | |
91 } | |
92 //************************************************ | |
93 } | |
94 long diff = System.currentTimeMillis() - start; | |
95 | |
96 if(diff > 1000){ | |
97 logger.info("Time - listenerShowTitle() " + diff + " [ms], Text id= " + this.selectedTitleId); | |
98 } | |
99 } | |
100 | |
101 | |
102 public void listenerShowWitness0(ActionEvent event){ | |
103 SelectItem0 item = (SelectItem0)getRequestBean("witnessItem"); | |
104 if (item != null) { | |
105 this.redirect(null, "?textId=" + selectedTitleId + "&witnessId=" + item.getValue() + "#witnesses"); | |
106 } | |
107 } | |
108 | |
109 | |
110 public void showWitness(Long selectedWitnessId) { | |
111 | |
112 this.selectedWitnessId = selectedWitnessId; | |
113 | |
114 if (this.selectedWitnessId != null) { | |
115 this.witnessItems = SelectItem0.valueChange(witnessItems, selectedWitnessId); | |
116 Entity entWitness = getWrapper().getEntityById(selectedWitnessId); | |
117 | |
118 if (entWitness != null) { | |
119 this.witness = new WitnessTemplate(entWitness, getWrapper(), true); | |
120 } | |
121 } | |
122 } | |
123 | |
124 /** | |
125 * This method is called from the result of the simple search. It will set the title(text) into the currentText to be edited. | |
126 * @return | |
127 */ | |
128 public String actionEditTitle() { | |
129 if(this.selectedTitleId != null){ | |
130 getSessionBean().editEntity(getWrapper().getEntityById(selectedTitleId)); | |
131 return "entry_edit_entity"; | |
132 } | |
133 return ""; | |
134 } | |
135 | |
136 /** | |
137 * This method is called from the result of the simple search. It will set | |
138 * the witness into the currentWitness to be edited. | |
139 * | |
140 * @return | |
141 */ | |
142 public String actionEditWitness() { | |
143 if (this.selectedWitnessId != null) { | |
144 getSessionBean().editEntity(getWrapper().getEntityById(selectedWitnessId)); | |
145 return "entry_edit_entity"; | |
146 } | |
147 return ""; | |
148 } | |
149 | |
150 //Privacity titles | |
151 public void changePrivacity4Title(ActionEvent event){ | |
152 try { | |
153 if(selectedTitleId != null){ | |
154 List<Entity> saveList = PrivacityUtils.changePrivacity4Title(getWrapper().getEntityById(selectedTitleId), null, getWrapper()); | |
155 getWrapper().saveEntityListAsNodeWithoutContent(saveList, getUserName()); | |
156 this.showTitle(selectedTitleId); | |
157 } | |
158 } catch (Exception e) { | |
159 logger.error(e.getMessage(), e); | |
160 printInternalError(e); | |
161 } | |
162 } | |
163 | |
164 //Privacity witnesses | |
165 public void changePrivacity4Witness(ActionEvent event){ | |
166 try { | |
167 if(selectedWitnessId != null){ | |
168 List<Entity> saveList = PrivacityUtils.changePrivacity4Witness(getWrapper().getEntityById(selectedWitnessId), null, getWrapper()); | |
169 getWrapper().saveEntityListAsNodeWithoutContent(saveList, getUserName()); | |
170 this.showWitness(selectedWitnessId); | |
171 } | |
172 } catch (Exception e) { | |
173 logger.error(e.getMessage(), e); | |
174 printInternalError(e); | |
175 } | |
176 | |
177 } | |
178 | |
179 private void changeAllWitnesses(boolean privacity) throws Exception{ | |
180 List<Entity> saveList = new ArrayList<Entity>(); | |
181 for(SelectItem item : witnessItems){ | |
182 Long id = (Long)item.getValue(); | |
183 Entity witness = getWrapper().getEntityById(id); | |
184 saveList.addAll(PrivacityUtils.changePrivacity4Witness(witness, privacity, getWrapper())); | |
185 } | |
186 getWrapper().saveEntityListAsNodeWithoutContent(saveList, getUserName()); | |
187 this.showWitness(selectedWitnessId); | |
188 } | |
189 | |
190 public void listenerMakeAllWitnessesPublic(ActionEvent event){ | |
191 try { | |
192 this.changeAllWitnesses(true); | |
193 } catch (Exception e) { | |
194 logger.error(e.getMessage(), e); | |
195 printInternalError(e); | |
196 } | |
197 } | |
198 | |
199 public void listenerMakeAllWitnessesPrivate(ActionEvent event){ | |
200 try { | |
201 this.changeAllWitnesses(false); | |
202 } catch (Exception e) { | |
203 logger.error(e.getMessage(), e); | |
204 printInternalError(e); | |
205 } | |
206 | |
207 } | |
208 | |
72
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
209 |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
210 public void changeShowWitnessesWithScans() { |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
211 if (this.selectedTitleId != null) { |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
212 showTitle(this.selectedTitleId); |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
213 } |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
214 } |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
215 |
1 | 216 public int getWitnessItemsSize() { |
217 if(witnessItems != null) | |
218 return witnessItems.size(); | |
219 return 0; | |
220 } | |
221 | |
222 public TitleTemplate getTitle() { | |
223 return title; | |
224 } | |
225 | |
226 public WitnessTemplate getWitness() { | |
227 return witness; | |
228 } | |
229 | |
230 public List<SelectItem0> getWitnessItems() { | |
231 return witnessItems; | |
232 } | |
233 | |
234 public Long getSelectedWitnessId() { | |
235 return selectedWitnessId; | |
236 } | |
237 | |
238 public Long getSelectedTitleId() { | |
239 return selectedTitleId; | |
240 } | |
241 | |
242 public void setSelectedWitnessId(Long selectedWitnessId) { | |
243 this.selectedWitnessId = selectedWitnessId; | |
244 } | |
245 | |
246 public void setSelectedTitleId(Long selectedTitleId) { | |
247 this.selectedTitleId = selectedTitleId; | |
248 } | |
72
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
249 |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
250 public boolean isShowWitnessesWithScans() { |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
251 return showWitnessesWithScans; |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
252 } |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
253 |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
254 public void setShowWitnessesWithScans(boolean showWitnessesWithScans) { |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
255 this.showWitnessesWithScans = showWitnessesWithScans; |
70207f24937e
cleaned displayAuthor. added filter for witnesses with scans.
casties
parents:
60
diff
changeset
|
256 } |
1 | 257 } |