1
|
1 package de.mpiwg.itgroup.ismi.event.beans;
|
|
2
|
|
3 import java.io.Serializable;
|
|
4 import java.util.ArrayList;
|
|
5 import java.util.List;
|
|
6
|
|
7 import javax.faces.event.ActionEvent;
|
|
8 import javax.faces.event.ValueChangeEvent;
|
|
9 import javax.faces.model.SelectItem;
|
|
10
|
|
11 import org.mpi.openmind.repository.bo.Attribute;
|
|
12 import org.mpi.openmind.repository.bo.Entity;
|
|
13 import org.mpi.openmind.repository.bo.Node;
|
|
14 import org.mpi.openmind.repository.bo.Relation;
|
|
15
|
|
16 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject;
|
|
17 import de.mpiwg.itgroup.ismi.auxObjects.lo.EventTextLO;
|
|
18 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar;
|
|
19
|
|
20 public class TransferEvent extends AbstractEvent implements Serializable{
|
|
21
|
|
22 private static final long serialVersionUID = -3606229569295260209L;
|
|
23
|
|
24 public static String OC = "TRANSFER_EVENT";
|
|
25
|
|
26 private boolean selectedPersonFrom;
|
|
27 private ListenerObject personFromLo = new ListenerObject(PERSON, name_translit);
|
|
28 private ListenerObject repositoryFromLo = new ListenerObject(REPOSITORY, name);
|
|
29
|
|
30 private boolean selectedPersonTo;
|
|
31 private ListenerObject personToLo = new ListenerObject(PERSON, name_translit);
|
|
32 private ListenerObject repositoryToLo = new ListenerObject(REPOSITORY, name);
|
|
33
|
|
34 private boolean selectedPlaceOriginalLocation;
|
|
35 private ListenerObject placeOriginalLocationLo = new ListenerObject(PLACE, name);
|
|
36 private ListenerObject repositoryOriginalLocationLo = new ListenerObject(REPOSITORY, name);
|
|
37
|
|
38 private boolean selectedPlaceNewLocation;
|
|
39 private ListenerObject placeNewLocationLo = new ListenerObject(PLACE, name);
|
|
40 private ListenerObject repositoryNewLocationLo = new ListenerObject(REPOSITORY, name);
|
|
41
|
|
42 private List<SelectItem> suggestedTransferOptions = new ArrayList<SelectItem>();
|
|
43
|
|
44 public TransferEvent(Entity event) {
|
|
45 super(event);
|
|
46 this.refreshTransferOptions();
|
|
47 }
|
|
48
|
|
49 public TransferEvent(){
|
|
50 super(new Entity(Node.TYPE_ABOX, OC, false));
|
|
51 this.refreshTransferOptions();
|
|
52 }
|
|
53
|
|
54 @Override
|
|
55 public void setEvent(Entity ev){
|
|
56 reset();
|
|
57 event = ev;
|
|
58 if(event != null && event.isPersistent()){
|
|
59 if(event.isLightweight()){
|
|
60 event = getWrapper().getEntityContent(event);
|
|
61 }
|
|
62
|
|
63 this.loadAttributes(this.event);
|
|
64 this.date = updateCalendar(this.event.getAttributeByName("date"));
|
|
65
|
|
66 for (Relation rel : event.getSourceRelations()) {
|
|
67 Entity target = null;
|
|
68 if (rel.getOwnValue().equals(was_transferred_from)) {
|
|
69 // EVENT -> was_transferred_from -> PERSON/REPOSITORY
|
|
70 target = getTargetRelation(rel);
|
|
71 if(target.getObjectClass().equals(PERSON)){
|
|
72 personFromLo.setEntityAndAttribute0(target);
|
|
73 selectedPersonFrom = true;
|
|
74 }else{
|
|
75 repositoryFromLo.setEntityAndAttribute0(target);
|
|
76 selectedPersonFrom = false;
|
|
77 }
|
|
78
|
|
79 }else if (rel.getOwnValue().equals(was_transferred_to)) {
|
|
80 // EVENT -> was_transferred_to -> PERSON/REPOSITORY
|
|
81 target = getTargetRelation(rel);
|
|
82 if(target.getObjectClass().equals(PERSON)){
|
|
83 personToLo.setEntityAndAttribute0(target);
|
|
84 selectedPersonTo = true;
|
|
85 }else{
|
|
86 repositoryToLo.setEntityAndAttribute0(target);
|
|
87 selectedPersonTo = false;
|
|
88 }
|
|
89 } else if (rel.getOwnValue().equals(has_original_location)) {
|
|
90 // EVENT -> has_original_location -> PLACE/REPOSITORY
|
|
91 target = getTargetRelation(rel);
|
|
92 if(target.getObjectClass().equals(PLACE)){
|
|
93 placeOriginalLocationLo.setEntityAndAttribute0(target);
|
|
94 selectedPlaceOriginalLocation = true;
|
|
95 }else{
|
|
96 repositoryOriginalLocationLo.setEntityAndAttribute0(target);
|
|
97 selectedPlaceOriginalLocation = false;
|
|
98 }
|
|
99 } else if (rel.getOwnValue().equals(has_new_location)) {
|
|
100 // EVENT -> has_new_location -> PLACE/REPOSITORY
|
|
101 target = getTargetRelation(rel);
|
|
102 if(target.getObjectClass().equals(PLACE)){
|
|
103 placeNewLocationLo.setEntityAndAttribute0(target);
|
|
104 selectedPlaceNewLocation = true;
|
|
105 }else{
|
|
106 repositoryNewLocationLo.setEntityAndAttribute0(target);
|
|
107 selectedPlaceNewLocation = false;
|
|
108 }
|
|
109 } else if (rel.getOwnValue().equals(is_a_transfer_of)) {
|
|
110 //EVENT study_of WITNESS
|
|
111 //WITNESS is_exemplar_of TEXT
|
|
112 this.witness = getTargetRelation(rel);
|
|
113 if(witness != null && witness.isPersistent()){
|
|
114 witnessId = witness.getId();
|
|
115 this.textLo.setEntityAndAttribute0( getTextOfWitness(witness));
|
|
116 refreshWitnesses(textLo.entity);
|
|
117 }
|
|
118 } else if (rel.getOwnValue().equals(was_transferred_in)) {
|
|
119 target = getTargetRelation(rel);
|
|
120 this.placeLo.setEntityAndAttribute0(target);
|
|
121 }
|
|
122 }
|
|
123 }
|
|
124 }
|
|
125
|
|
126 /*
|
|
127 public void listenerChangePersonFrom(ValueChangeEvent event) {
|
|
128 this.personFrom = changeListener(event, personFrom, PERSON, name_translit);
|
|
129 }
|
|
130
|
|
131 public void listenerChangePersonTo(ValueChangeEvent event) {
|
|
132 this.personTo = changeListener(event, personTo, PERSON, name_translit);
|
|
133 }
|
|
134
|
|
135 public void listenerChangeRepositoryFrom(ValueChangeEvent event) {
|
|
136 this.repositoryFrom = changeListener(event, repositoryFrom, REPOSITORY, name);
|
|
137 }
|
|
138
|
|
139 public void listenerChangeRepositoryTo(ValueChangeEvent event) {
|
|
140 this.repositoryTo = changeListener(event, repositoryTo, REPOSITORY, name);
|
|
141 }*/
|
|
142
|
|
143 public void listenerChangeSelectionFrom(ActionEvent event){
|
|
144 this.selectedPersonFrom = !selectedPersonFrom;
|
|
145 }
|
|
146
|
|
147 public void listenerChangeSelectionTo(ActionEvent event){
|
|
148 this.selectedPersonTo = !selectedPersonTo;
|
|
149 }
|
|
150 /*
|
|
151 public void listenerChangePlaceOriginalLocation(ValueChangeEvent event){
|
|
152 this.placeOriginalLocation = changeListener(event, placeOriginalLocation, PLACE, name);
|
|
153 }
|
|
154
|
|
155 public void listenerChangePlaceNewLocation(ValueChangeEvent event){
|
|
156 this.placeNewLocation = changeListener(event, placeNewLocation, PLACE, name);
|
|
157 }
|
|
158
|
|
159 public void listenerChangeRepositoryOriginalLocation(ValueChangeEvent event){
|
|
160 this.repositoryOriginalLocation = changeListener(event, repositoryOriginalLocation, REPOSITORY, name);
|
|
161 }
|
|
162
|
|
163 public void listenerChangeRepositoryNewLocation(ValueChangeEvent event){
|
|
164 this.repositoryNewLocation = changeListener(event, repositoryNewLocation, REPOSITORY, name);
|
|
165 }
|
|
166 */
|
|
167 public void listenerChangeSelectionNewLocation(ActionEvent event){
|
|
168 this.selectedPlaceNewLocation = !selectedPlaceNewLocation;
|
|
169 }
|
|
170
|
|
171 public void listenerChangeSelectionOriginalLocation(ActionEvent event){
|
|
172 this.selectedPlaceOriginalLocation = !selectedPlaceOriginalLocation;
|
|
173 }
|
|
174
|
|
175 @Override
|
|
176 public void reset(){
|
|
177 super.reset();
|
|
178 this.selectedPersonFrom = true;
|
|
179 this.selectedPersonTo = true;
|
|
180 this.selectedPlaceOriginalLocation = true;
|
|
181 this.selectedPlaceNewLocation = true;
|
|
182
|
|
183 this.defObjectClass = OC;
|
|
184 this.personFromLo = new ListenerObject(PERSON, name_translit);
|
|
185 this.repositoryFromLo = new ListenerObject(REPOSITORY, name);
|
|
186 this.personToLo = new ListenerObject(PERSON, name_translit);
|
|
187 this.repositoryToLo = new ListenerObject(REPOSITORY, name);
|
|
188
|
|
189 if(textLo != null){
|
|
190 textLo.reset();
|
|
191 }else{
|
|
192 textLo = new EventTextLO(TEXT, full_title_translit, this);
|
|
193 }
|
|
194
|
|
195 if(placeLo != null){
|
|
196 placeLo.reset();
|
|
197 }else{
|
|
198 placeLo = new ListenerObject(PLACE, name);
|
|
199 }
|
|
200
|
|
201
|
|
202 this.date = new Calendar();
|
|
203 this.witnessList = new ArrayList<SelectItem>();
|
|
204
|
|
205 this.placeNewLocationLo = new ListenerObject(PLACE, name);
|
|
206 this.repositoryNewLocationLo = new ListenerObject(REPOSITORY, name);
|
|
207 this.personToLo = new ListenerObject(PERSON, name_translit);
|
|
208 this.repositoryToLo = new ListenerObject(REPOSITORY, name);
|
|
209 this.placeOriginalLocationLo = new ListenerObject(PLACE, name);
|
|
210 this.repositoryOriginalLocationLo = new ListenerObject(REPOSITORY, name);
|
|
211 /*
|
|
212 this.repositoryFromLo.reset();
|
|
213 this.repositoryToLo.reset();
|
|
214 this.placeNewLocationLo.reset();
|
|
215 this.placeOriginalLocationLo.reset();
|
|
216 this.repositoryNewLocationLo.reset();
|
|
217 this.repositoryOriginalLocationLo.reset();
|
|
218 */
|
|
219 }
|
|
220
|
|
221
|
|
222 public void listenerRefreshTransferOptions(ActionEvent event){
|
|
223 this.refreshTransferOptions();
|
|
224 }
|
|
225
|
|
226 private void refreshTransferOptions(){
|
|
227 this.suggestedTransferOptions = new ArrayList<SelectItem>();
|
|
228 suggestedTransferOptions.add(new SelectItem(null, "--choose--"));
|
|
229 Attribute binding = getWrapper().getDefAttributeByOwnValue(OC, "options_for_transfer");
|
|
230 if(binding != null){
|
|
231 for(String s : binding.getPossibleValuesList()){
|
|
232 this.suggestedTransferOptions.add(new SelectItem(s));
|
|
233 }
|
|
234 }
|
|
235 }
|
|
236
|
|
237 public void listenerSave(ActionEvent event) {
|
|
238 this.save();
|
|
239 }
|
|
240
|
|
241 @Override
|
|
242 public String save(){
|
|
243 super.save();
|
|
244 if(!checkConsistency()){
|
|
245 addGeneralMsg("Either the Witness, the Person or the Place is empty.");
|
|
246 addGeneralMsg("The event could not be saved.");
|
|
247 return null;
|
|
248 }
|
|
249
|
|
250 try{
|
|
251 getAttributes().put("date", this.date.toJSONString());
|
|
252 event = updateEntityAttributes(event);
|
|
253
|
|
254 // EVENT -> was_studied_by -> WITNESS
|
|
255 if(witness.isLightweight()){
|
|
256 this.witness = getWrapper().getEntityByIdWithContent(witness.getId());
|
|
257 }
|
|
258 event.replaceSourceRelation(witness, WITNESS, is_a_transfer_of);
|
|
259
|
|
260 // EVENT -> was_transferred_from -> PERSON/REPOSITORY
|
|
261 if(isSelectedPersonFrom()){
|
|
262 event.replaceSourceRelation(personFromLo.entity, PERSON, was_transferred_from);
|
|
263 event.removeAllSourceRelations(was_transferred_from, REPOSITORY);
|
|
264 }else{
|
|
265 event.replaceSourceRelation(repositoryFromLo.entity, REPOSITORY, was_transferred_from);
|
|
266 event.removeAllSourceRelations(was_transferred_from, PERSON);
|
|
267 }
|
|
268
|
|
269 // EVENT -> was_transferred_to -> PERSON/REPOSITORY
|
|
270 if(isSelectedPersonTo()){
|
|
271 event.replaceSourceRelation(personToLo.entity, PERSON, was_transferred_to);
|
|
272 event.removeAllSourceRelations(was_transferred_to, REPOSITORY);
|
|
273 }else{
|
|
274 event.replaceSourceRelation(repositoryToLo.entity, REPOSITORY, was_transferred_to);
|
|
275 event.removeAllSourceRelations(was_transferred_to, PERSON);
|
|
276 }
|
|
277
|
|
278 // EVENT -> has_original_location -> PLACE/REPOSITORY
|
|
279 if(isSelectedPlaceOriginalLocation()){
|
|
280 event.replaceSourceRelation(placeOriginalLocationLo.entity, PLACE, has_original_location);
|
|
281 event.removeAllSourceRelations(has_original_location, REPOSITORY);
|
|
282 }else{
|
|
283 event.replaceSourceRelation(repositoryOriginalLocationLo.entity, REPOSITORY, has_original_location);
|
|
284 event.removeAllSourceRelations(has_original_location, PLACE);
|
|
285 }
|
|
286
|
|
287 // EVENT -> has_new_location -> PLACE/REPOSITORY
|
|
288 if(isSelectedPlaceNewLocation()){
|
|
289 event.replaceSourceRelation(placeNewLocationLo.entity, PLACE, has_new_location);
|
|
290 event.removeAllSourceRelations(has_new_location, REPOSITORY);
|
|
291 }else{
|
|
292 event.replaceSourceRelation(repositoryNewLocationLo.entity, REPOSITORY, has_new_location);
|
|
293 event.removeAllSourceRelations(has_new_location, PLACE);
|
|
294 }
|
|
295
|
|
296 // EVENT -> was_transferred_in -> PLACE
|
|
297 event.replaceSourceRelation(placeLo.entity, PLACE, was_transferred_in);
|
|
298
|
|
299 getWrapper().saveEntity(event, getSessionUserName());
|
|
300
|
|
301 printSuccessSavingEntity();
|
|
302
|
|
303 }catch (Exception e) {
|
|
304 addGeneralMsg(e.getMessage());
|
|
305 logger.error(e.getMessage(), e);
|
|
306 }
|
|
307 saveEnd();
|
|
308 return null;
|
|
309 }
|
|
310
|
|
311 public boolean checkConsistency(){
|
|
312 //TODO
|
|
313 if(this.witness == null || this.textLo.entity == null ){
|
|
314 return false;
|
|
315 }
|
|
316 return true;
|
|
317 }
|
|
318
|
|
319
|
|
320
|
|
321 public boolean isSelectedPersonFrom() {
|
|
322 return selectedPersonFrom;
|
|
323 }
|
|
324
|
|
325 public boolean isSelectedPersonTo() {
|
|
326 return selectedPersonTo;
|
|
327 }
|
|
328
|
|
329 public List<SelectItem> getSuggestedTransferOptions() {
|
|
330 return suggestedTransferOptions;
|
|
331 }
|
|
332
|
|
333 public void setSuggestedTransferOptions(
|
|
334 List<SelectItem> suggestedTransferOptions) {
|
|
335 this.suggestedTransferOptions = suggestedTransferOptions;
|
|
336 }
|
|
337
|
|
338 public boolean isSelectedPlaceOriginalLocation() {
|
|
339 return selectedPlaceOriginalLocation;
|
|
340 }
|
|
341
|
|
342
|
|
343
|
|
344 public boolean isSelectedPlaceNewLocation() {
|
|
345 return selectedPlaceNewLocation;
|
|
346 }
|
|
347
|
|
348 public ListenerObject getPersonFromLo() {
|
|
349 return personFromLo;
|
|
350 }
|
|
351
|
|
352 public void setPersonFromLo(ListenerObject personFromLo) {
|
|
353 this.personFromLo = personFromLo;
|
|
354 }
|
|
355
|
|
356 public ListenerObject getRepositoryFromLo() {
|
|
357 return repositoryFromLo;
|
|
358 }
|
|
359
|
|
360 public void setRepositoryFromLo(ListenerObject repositoryFromLo) {
|
|
361 this.repositoryFromLo = repositoryFromLo;
|
|
362 }
|
|
363
|
|
364 public ListenerObject getPersonToLo() {
|
|
365 return personToLo;
|
|
366 }
|
|
367
|
|
368 public void setPersonToLo(ListenerObject personToLo) {
|
|
369 this.personToLo = personToLo;
|
|
370 }
|
|
371
|
|
372 public ListenerObject getRepositoryToLo() {
|
|
373 return repositoryToLo;
|
|
374 }
|
|
375
|
|
376 public void setRepositoryToLo(ListenerObject repositoryToLo) {
|
|
377 this.repositoryToLo = repositoryToLo;
|
|
378 }
|
|
379
|
|
380 public ListenerObject getPlaceOriginalLocationLo() {
|
|
381 return placeOriginalLocationLo;
|
|
382 }
|
|
383
|
|
384 public void setPlaceOriginalLocationLo(ListenerObject placeOriginalLocationLo) {
|
|
385 this.placeOriginalLocationLo = placeOriginalLocationLo;
|
|
386 }
|
|
387
|
|
388 public ListenerObject getRepositoryOriginalLocationLo() {
|
|
389 return repositoryOriginalLocationLo;
|
|
390 }
|
|
391
|
|
392 public void setRepositoryOriginalLocationLo(
|
|
393 ListenerObject repositoryOriginalLocationLo) {
|
|
394 this.repositoryOriginalLocationLo = repositoryOriginalLocationLo;
|
|
395 }
|
|
396
|
|
397 public ListenerObject getPlaceNewLocationLo() {
|
|
398 return placeNewLocationLo;
|
|
399 }
|
|
400
|
|
401 public void setPlaceNewLocationLo(ListenerObject placeNewLocationLo) {
|
|
402 this.placeNewLocationLo = placeNewLocationLo;
|
|
403 }
|
|
404
|
|
405 public ListenerObject getRepositoryNewLocationLo() {
|
|
406 return repositoryNewLocationLo;
|
|
407 }
|
|
408
|
|
409 public void setRepositoryNewLocationLo(ListenerObject repositoryNewLocationLo) {
|
|
410 this.repositoryNewLocationLo = repositoryNewLocationLo;
|
|
411 }
|
|
412
|
|
413 public void setSelectedPersonFrom(boolean selectedPersonFrom) {
|
|
414 this.selectedPersonFrom = selectedPersonFrom;
|
|
415 }
|
|
416
|
|
417 public void setSelectedPersonTo(boolean selectedPersonTo) {
|
|
418 this.selectedPersonTo = selectedPersonTo;
|
|
419 }
|
|
420
|
|
421 public void setSelectedPlaceOriginalLocation(
|
|
422 boolean selectedPlaceOriginalLocation) {
|
|
423 this.selectedPlaceOriginalLocation = selectedPlaceOriginalLocation;
|
|
424 }
|
|
425
|
|
426 public void setSelectedPlaceNewLocation(boolean selectedPlaceNewLocation) {
|
|
427 this.selectedPlaceNewLocation = selectedPlaceNewLocation;
|
|
428 }
|
|
429
|
|
430
|
|
431
|
|
432 }
|