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