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