Mercurial > hg > ismi-richfaces
comparison src/main/java/de/mpiwg/itgroup/ismi/event/beans/StudyEvent.java @ 1:2e911857a759
(none)
author | jurzua |
---|---|
date | Wed, 29 Oct 2014 14:00:28 +0000 |
parents | |
children | 22a18bfc66b0 |
comparison
equal
deleted
inserted
replaced
0:74df02964906 | 1:2e911857a759 |
---|---|
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 StudyEvent extends AbstractEvent implements Serializable{ | |
21 | |
22 /** | |
23 * | |
24 */ | |
25 private static final long serialVersionUID = 2242991945890055323L; | |
26 | |
27 public static String OC = "STUDY_EVENT"; | |
28 | |
29 private ListenerObject personLo = new ListenerObject(PERSON, name_translit); | |
30 private ListenerObject advisorLo = new ListenerObject(PERSON, name_translit); | |
31 private ListenerObject repositoryLo = new ListenerObject(REPOSITORY, name); | |
32 | |
33 private List<SelectItem> suggestedEngagementOptions = new ArrayList<SelectItem>(); | |
34 | |
35 public StudyEvent(){ | |
36 super(new Entity(Node.TYPE_ABOX, OC, false)); | |
37 refreshEngagementOptions(); | |
38 } | |
39 | |
40 public StudyEvent(Entity event){ | |
41 super(event); | |
42 refreshEngagementOptions(); | |
43 } | |
44 | |
45 public void listenerRefreshEngagementOptions(ActionEvent event){ | |
46 this.refreshEngagementOptions(); | |
47 } | |
48 | |
49 private void refreshEngagementOptions(){ | |
50 this.suggestedEngagementOptions = new ArrayList<SelectItem>(); | |
51 suggestedEngagementOptions.add(new SelectItem(null, "--choose--")); | |
52 Attribute binding = getWrapper().getDefAttributeByOwnValue(OC, "options_for_engagement"); | |
53 if(binding != null){ | |
54 for(String s : binding.getPossibleValuesList()){ | |
55 this.suggestedEngagementOptions.add(new SelectItem(s)); | |
56 } | |
57 } | |
58 } | |
59 | |
60 @Override | |
61 public void setEvent(Entity ev){ | |
62 reset(); | |
63 event = ev; | |
64 if(event != null && event.isPersistent()){ | |
65 if(event.isLightweight()){ | |
66 event = getWrapper().getEntityContent(event); | |
67 } | |
68 | |
69 this.loadAttributes(this.event); | |
70 this.date = updateCalendar(this.event.getAttributeByName("date")); | |
71 | |
72 for (Relation rel : event.getSourceRelations()) { | |
73 Entity target = null; | |
74 if (rel.getOwnValue().equals(was_studied_by)) { | |
75 //EVENT was_studied_by PERSON | |
76 target = getTargetRelation(rel); | |
77 personLo.setEntityAndAttribute0(target); | |
78 }else if (rel.getOwnValue().equals(was_advised_by)) { | |
79 //EVENT was_advised_by PERSON | |
80 target = getTargetRelation(rel); | |
81 advisorLo.setEntityAndAttribute0(target); | |
82 | |
83 } else if (rel.getOwnValue().equals(was_studied_in)) { | |
84 target = getTargetRelation(rel); | |
85 if(target.getObjectClass().equals(PLACE)){ | |
86 //EVENT was_studied_in PLACE | |
87 placeLo.setEntityAndAttribute0(target); | |
88 }else if(target.getObjectClass().equals(REPOSITORY)){ | |
89 //EVENT was_studied_in REPOSITORY | |
90 repositoryLo.setEntityAndAttribute0(target); | |
91 } | |
92 } else if (rel.getOwnValue().equals(is_a_study_of)) { | |
93 //EVENT study_of WITNESS | |
94 //WITNESS is_exemplar_of TEXT | |
95 this.witness = getTargetRelation(rel); | |
96 if(witness != null && witness.isPersistent()){ | |
97 witnessId = witness.getId(); | |
98 this.textLo.setEntityAndAttribute0( getTextOfWitness(witness)); | |
99 refreshWitnesses(textLo.entity); | |
100 } | |
101 } | |
102 } | |
103 } | |
104 } | |
105 | |
106 public void listenerSave(ActionEvent event) { | |
107 this.save(); | |
108 } | |
109 | |
110 @Override | |
111 public String save(){ | |
112 super.save(); | |
113 if(!checkConsistency()){ | |
114 addGeneralMsg("Either the Witness, the Person or the Place is empty."); | |
115 addGeneralMsg("The event could not be saved."); | |
116 return null; | |
117 } | |
118 | |
119 try{ | |
120 getAttributes().put("date", this.date.toJSONString()); | |
121 event = updateEntityAttributes(event); | |
122 | |
123 // EVENT -> was_studied_by -> PERSON | |
124 event.replaceSourceRelation(personLo.entity, PERSON, was_studied_by); | |
125 | |
126 // EVENT -> was_advised_by -> PERSON | |
127 event.replaceSourceRelation(advisorLo.entity, PERSON, was_advised_by); | |
128 | |
129 // EVENT -> was_studied_in -> REPOSITORY | |
130 event.replaceSourceRelation(repositoryLo.entity, REPOSITORY, was_studied_in); | |
131 //event.replaceSourceRelation(getRepositoryLo().entity, REPOSITORY, was_studied_in); | |
132 | |
133 // EVENT -> was_studied_in -> PLACE | |
134 event.replaceSourceRelation(placeLo.entity, PLACE, was_studied_in); | |
135 | |
136 // EVENT -> was_studied_by -> WITNESS | |
137 if(witness.isLightweight()){ | |
138 witness = getWrapper().getEntityByIdWithContent(witness.getId()); | |
139 } | |
140 event.replaceSourceRelation(witness, WITNESS, is_a_study_of); | |
141 | |
142 getWrapper().saveEntity(event, getSessionUserName()); | |
143 | |
144 printSuccessSavingEntity(); | |
145 | |
146 }catch (Exception e) { | |
147 addGeneralMsg(e.getMessage()); | |
148 logger.error(e.getMessage(), e); | |
149 } | |
150 saveEnd(); | |
151 return null; | |
152 } | |
153 | |
154 /* | |
155 public void listenerChangePerson(ValueChangeEvent event) { | |
156 this.person = changeListener(event, person, PERSON, name_translit); | |
157 } | |
158 | |
159 public void listenerChangeAdvisor(ValueChangeEvent event) { | |
160 this.advisor = changeListener(event, advisor, PERSON, name_translit); | |
161 } | |
162 | |
163 public void listenerChangeRepository(ValueChangeEvent event) { | |
164 this.repository = changeListener(event, repository, REPOSITORY, name); | |
165 } | |
166 */ | |
167 @Override | |
168 public void reset(){ | |
169 super.reset(); | |
170 this.defObjectClass = OC; | |
171 if(personLo != null){ | |
172 personLo.reset(); | |
173 }else{ | |
174 personLo = new ListenerObject(PERSON, name_translit); | |
175 } | |
176 | |
177 if(advisorLo != null){ | |
178 advisorLo.reset(); | |
179 }else{ | |
180 advisorLo = new ListenerObject(PERSON, name_translit); | |
181 } | |
182 | |
183 if(textLo != null){ | |
184 textLo.reset(); | |
185 }else{ | |
186 textLo = new EventTextLO(TEXT, full_title_translit, this); | |
187 } | |
188 if(placeLo != null){ | |
189 placeLo.reset(); | |
190 }else{ | |
191 placeLo = new ListenerObject(PLACE, name); | |
192 } | |
193 | |
194 if(repositoryLo != null){ | |
195 repositoryLo.reset(); | |
196 }else{ | |
197 repositoryLo = new ListenerObject(REPOSITORY, name); | |
198 } | |
199 | |
200 this.date = new Calendar(); | |
201 this.witnessList = new ArrayList<SelectItem>(); | |
202 this.refreshEngagementOptions(); | |
203 } | |
204 | |
205 public boolean checkConsistency(){ | |
206 if(this.witness == null || this.textLo.entity == null || this.repositoryLo.entity == null || this.personLo.entity == null){ | |
207 return false; | |
208 } | |
209 return true; | |
210 } | |
211 | |
212 public ListenerObject getPersonLo() { | |
213 return personLo; | |
214 } | |
215 | |
216 public void setPersonLo(ListenerObject personLo) { | |
217 this.personLo = personLo; | |
218 } | |
219 | |
220 public ListenerObject getAdvisorLo() { | |
221 return advisorLo; | |
222 } | |
223 | |
224 public void setAdvisorLo(ListenerObject advisorLo) { | |
225 this.advisorLo = advisorLo; | |
226 } | |
227 | |
228 public ListenerObject getRepositoryLo() { | |
229 return repositoryLo; | |
230 } | |
231 | |
232 public void setRepositoryLo(ListenerObject repositoryLo) { | |
233 this.repositoryLo = repositoryLo; | |
234 } | |
235 | |
236 public List<SelectItem> getSuggestedEngagementOptions() { | |
237 return suggestedEngagementOptions; | |
238 } | |
239 | |
240 public void setSuggestedEngagementOptions( | |
241 List<SelectItem> suggestedEngagementOptions) { | |
242 this.suggestedEngagementOptions = suggestedEngagementOptions; | |
243 } | |
244 | |
245 } |