1
|
1 package de.mpiwg.itgroup.ismi.entry.beans;
|
|
2
|
|
3 import java.io.Serializable;
|
|
4 import java.util.Date;
|
|
5 import java.util.HashMap;
|
|
6 import java.util.Map;
|
|
7
|
|
8 import javax.faces.component.UIComponent;
|
|
9 import javax.faces.convert.Converter;
|
|
10 import javax.faces.event.ActionEvent;
|
|
11 import javax.faces.event.AjaxBehaviorEvent;
|
|
12 import javax.faces.event.ValueChangeEvent;
|
|
13
|
|
14 import org.apache.log4j.Logger;
|
|
15 import org.mpi.openmind.cache.WrapperService;
|
|
16 import org.mpi.openmind.repository.bo.Attribute;
|
|
17 import org.mpi.openmind.repository.bo.Entity;
|
|
18 import org.mpi.openmind.repository.bo.Node;
|
|
19 import org.mpi.openmind.repository.bo.Relation;
|
|
20 import org.mpi.openmind.repository.utils.RomanizationLoC;
|
|
21 import org.mpi.openmind.repository.utils.TransliterationUtil;
|
|
22
|
|
23
|
|
24
|
|
25 /* rich
|
|
26 import com.icesoft.faces.async.render.SessionRenderer;
|
|
27 import com.icesoft.faces.component.ext.HtmlCommandButton;
|
|
28 import com.icesoft.faces.component.ext.HtmlInputHidden;
|
|
29 */
|
|
30 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject;
|
|
31 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar;
|
|
32 import de.mpiwg.itgroup.ismi.util.guiComponents.EntityList;
|
|
33
|
|
34 public class CurrentPersonBean extends AbstractISMIBean implements Serializable{
|
|
35 private static final long serialVersionUID = -3366510497089165294L;
|
|
36
|
|
37 private static Logger logger = Logger.getLogger(CurrentPersonBean.class);
|
|
38
|
|
39 //private Entity person;
|
|
40 private String newAlias;
|
|
41
|
|
42 private String romanizedNameTranslit;
|
|
43
|
|
44 public static String birth_date = "birth_date";
|
|
45 public static String death_date = "death_date";
|
|
46
|
|
47 private ListenerObject birthPlaceLo = new ListenerObject(PLACE, name);
|
|
48 private ListenerObject deathPlaceLo = new ListenerObject(PLACE, name);
|
|
49
|
|
50 private String valueShortName;
|
|
51 private Entity shortNameAlias; // is now an alias of type "prime"
|
|
52
|
|
53 private transient Calendar calBirthDate;
|
|
54 private transient Calendar calDeathDate;
|
|
55
|
|
56 private Map<String, Boolean> deletedAliases = new HashMap<String, Boolean>();
|
|
57
|
|
58 private EntityList livedInPlaces;
|
|
59 private EntityList aliasList;
|
|
60 private EntityList roleList;
|
|
61 private EntityList studentOfList;
|
|
62 private EntityList floruitList;
|
|
63
|
|
64 @Override
|
|
65 public void reset(){
|
|
66 super.reset();
|
|
67 this.entity = new Entity(Node.TYPE_ABOX, PERSON, false);
|
|
68
|
|
69 this.newAlias = new String();
|
|
70
|
|
71 this.livedInPlaces = new EntityList(PLACE, name, true);
|
|
72 this.aliasList = new EntityList(ALIAS, "alias", getWrapper(), getUserName());
|
|
73 this.roleList = new EntityList(ROLE, "name", getWrapper(), getUserName());
|
|
74 this.studentOfList = new EntityList(PERSON, "name_translit", "Student of");
|
|
75 this.floruitList = new EntityList(FLORUIT_DATE, "date", getWrapper(), getUserName(), true);
|
|
76
|
|
77 this.valueShortName = "";
|
|
78 this.shortNameAlias = null;
|
|
79
|
|
80 this.birthPlaceLo.reset();
|
|
81
|
|
82 this.deathPlaceLo.reset();
|
|
83
|
|
84 this.deletedAliases = new HashMap<String, Boolean>();
|
|
85
|
|
86 this.calBirthDate = new Calendar();
|
|
87 this.calDeathDate = new Calendar();
|
|
88
|
|
89 }
|
|
90
|
|
91 public EntityList getRoleList() {
|
|
92 return roleList;
|
|
93 }
|
|
94
|
|
95 public void setRoleList(EntityList roleList) {
|
|
96 this.roleList = roleList;
|
|
97 }
|
|
98
|
|
99 public EntityList getAliasList() {
|
|
100 return aliasList;
|
|
101 }
|
|
102
|
|
103 public void setAliasList(EntityList aliasList) {
|
|
104 this.aliasList = aliasList;
|
|
105 }
|
|
106
|
|
107 public CurrentPersonBean() {
|
|
108 this.reset();
|
|
109 setDefObjectClass(PERSON);
|
|
110 registerChecker(birthPlaceLo, "Birth place not valid!");
|
|
111 registerChecker(deathPlaceLo, "Death place not valid!");
|
|
112 }
|
|
113
|
|
114 /**
|
|
115 *
|
|
116 * @param event
|
|
117 */
|
|
118 public void shortNameChangeListener(ValueChangeEvent event) {
|
|
119 try {
|
|
120 if (event.getNewValue() == null) {
|
|
121 return;
|
|
122 }
|
|
123 if (event.getNewValue().equals(event.getOldValue())) {
|
|
124 return;
|
|
125 }
|
|
126
|
|
127 String newShortName = (String) event.getNewValue();
|
|
128
|
|
129 if (shortNameAlias == null) {
|
|
130 shortNameAlias = new Entity(org.mpi.openmind.repository.bo.Node.TYPE_ABOX, ALIAS, false);
|
|
131
|
|
132 }
|
|
133
|
|
134 Attribute attr = this.shortNameAlias.getAttributeByName(alias);
|
|
135 if (attr == null) {
|
|
136 this.shortNameAlias.addAttribute(new Attribute(alias, TEXT,
|
|
137 newShortName));
|
|
138 } else
|
|
139 attr.setValue(newShortName);
|
|
140
|
|
141 } catch (Exception e) {
|
|
142 e.printStackTrace();
|
|
143 }
|
|
144 }
|
|
145
|
|
146 public String translitNameAction() {
|
|
147 String pn = getAttributes().get(name);
|
|
148
|
|
149 String translit = TransliterationUtil.getTransliteration(pn);
|
|
150 this.getAttributes().put(name_translit, translit);
|
|
151
|
|
152 return PAGE_EDITOR;
|
|
153 }
|
|
154
|
|
155 public Calendar getCalBirthDate() {
|
|
156 return calBirthDate;
|
|
157 }
|
|
158
|
|
159 public void setCalBirthDate(Calendar calBirthDate) {
|
|
160 this.calBirthDate = calBirthDate;
|
|
161 }
|
|
162
|
|
163 public Calendar getCalDeathDate() {
|
|
164 return calDeathDate;
|
|
165 }
|
|
166
|
|
167 public void setCalDeathDate(Calendar calDeathDate) {
|
|
168 this.calDeathDate = calDeathDate;
|
|
169 }
|
|
170
|
|
171 @Override
|
|
172 public void setEntity(Entity person) {
|
|
173 this.reset();
|
|
174
|
|
175 this.entity = person;
|
|
176
|
|
177 if(this.entity != null && this.entity.isPersistent()){
|
|
178 if (this.entity.isLightweight()) {
|
|
179 this.entity = this.getWrapper().getEntityContent(person);
|
|
180 }
|
|
181
|
|
182 this.calDeathDate = updateCalendar(this.entity.getAttributeByName(death_date));
|
|
183 this.calBirthDate = updateCalendar(this.entity.getAttributeByName(birth_date));
|
|
184
|
|
185 this.setCurrentId(this.entity.getId().toString());
|
|
186 this.loadAttributes(this.entity);
|
|
187
|
|
188 for (Relation rel : this.entity.getSourceRelations()) {
|
|
189 Entity target = getWrapper().getEntityById(rel.getTargetId());
|
|
190 if (rel.getOwnValue().equals("was_born_in")) {
|
|
191 this.birthPlaceLo.setEntityAndAttribute0(target);
|
|
192 //this.personWasBornInName = (target == null) ? "" : target.getOwnValue();
|
|
193 } else if (rel.getOwnValue().equals(lived_in)) {
|
|
194 this.livedInPlaces.add(target, rel.getAttributeByName("date"));
|
|
195 } else if (rel.getOwnValue().equals(was_student_of)) {
|
|
196 this.studentOfList.add(target);
|
|
197 } else if (rel.getOwnValue().equals(has_role)) {
|
|
198 this.roleList.add(target);
|
|
199 } else if (rel.getOwnValue().equals("died_in")) {
|
|
200 this.deathPlaceLo.setEntityAndAttribute0(target);
|
|
201 } else if (rel.getOwnValue().equals("has_floruit_date")) {
|
|
202 Attribute calAtt = getWrapper().getAttributeByName(target.getId(), "date");
|
|
203 this.floruitList.add(target, calAtt);
|
|
204 }
|
|
205 }
|
|
206
|
|
207 for (Relation rel : this.entity.getTargetRelations()) {
|
|
208 if (rel.getOwnValue().equals("was_created_by") && rel.getSourceObjectClass().equals(TEXT)) {
|
|
209 //Entity title = getWrapper().getEntityById(rel.getSourceId());
|
|
210 } else if (rel.getOwnValue().equals("is_alias_name_of")) {
|
|
211 Entity alias = getWrapper().getEntityById(rel.getSourceId());
|
|
212 this.aliasList.add(alias);
|
|
213 } else if (rel.getOwnValue().equals("is_prime_alias_name_of")) {
|
|
214 Entity alias = getWrapper().getEntityByIdWithContent(rel.getSourceId());
|
|
215 this.shortNameAlias = alias;
|
|
216 this.valueShortName = alias.getAttributeByName("alias").getValue();
|
|
217 }
|
|
218 }
|
|
219
|
|
220 //this.loadReferences(this.entity);
|
|
221 this.loadEndNoteRefs();
|
|
222 this.displayUrl = generateDisplayUrl(person, null, null, getAppBean().getRoot());
|
|
223
|
|
224 }
|
|
225 }
|
|
226
|
|
227 /**
|
|
228 * Saves the current Person. TODO save the target's relations.
|
|
229 *
|
|
230 * @return
|
|
231 */
|
|
232 @Override
|
|
233 public String save() {
|
|
234 super.save();
|
|
235 try {
|
|
236
|
|
237 long start = System.currentTimeMillis();
|
|
238
|
|
239 CheckResults cr = getCheckResults();
|
|
240 if (cr.hasErrors){
|
|
241 getSessionBean().setErrorMessages(cr);
|
|
242 getSessionBean().setDisplayError(true);
|
|
243 return "SAVE_ERROR";
|
|
244 }
|
|
245
|
|
246 getAttributes().put(birth_date, this.calBirthDate.toJSONString());
|
|
247 getAttributes().put(death_date, this.calDeathDate.toJSONString());
|
|
248
|
|
249
|
|
250 this.entity = updateEntityAttributes(this.entity);
|
|
251 this.entity.replaceSourceRelation(birthPlaceLo.entity, PLACE, "was_born_in");
|
|
252
|
|
253 this.entity.replaceSourceRelation(deathPlaceLo.entity, PLACE, "died_in");
|
|
254
|
|
255 this.entity.removeAllTargetRelationsByName(is_prime_alias_name_of);
|
|
256 if (shortNameAlias != null) {
|
|
257 shortNameAlias.setObjectClass(ALIAS);
|
|
258 shortNameAlias = getWrapper().saveEntity(shortNameAlias, getSessionUser().getEmail());
|
|
259 Relation aliasRel = new Relation(shortNameAlias, this.entity, is_alias_name_of);
|
|
260 }
|
|
261
|
|
262 //ALIAS -> is_alias_name_of -> PERSON
|
|
263 this.entity.removeAllTargetRelationsByName(is_alias_name_of);
|
|
264 for(Entity alias : this.aliasList.getEntities()){
|
|
265 Entity alias0 = getWrapper().getEntityByIdWithContent(alias.getId());
|
|
266 Relation aliasRel = new Relation(alias0, this.entity, is_alias_name_of);
|
|
267 }
|
|
268
|
|
269 // PERSON -> lived_in manyToMany -> PLACE
|
|
270 this.entity.removeAllSourceRelationsByName(lived_in);
|
|
271 for(Entity place : this.livedInPlaces.getEntities()){
|
|
272 //loadRelation(this.person, place, PLACE, lived_in);
|
|
273 Entity place0 = getWrapper().getEntityByIdWithContent(place.getId());
|
|
274 Relation livedIn = new Relation(this.entity, place0, lived_in);
|
|
275 Calendar cal = livedInPlaces.getCalendar(place.getId());
|
|
276 if(cal != null){
|
|
277 livedIn.addAttribute(new Attribute("date", "date", cal.toJSONString()));
|
|
278 }
|
|
279 }
|
|
280
|
|
281 // Person -> has_floruit_date -> FLORUIT DATE
|
|
282 this.entity.removeAllSourceRelationsByName(has_floruit_date);
|
|
283 for(Entity floruitDate : this.floruitList.getEntities()){
|
|
284 Entity floruitDate0 = getWrapper().getEntityByIdWithContent(floruitDate.getId());
|
|
285 Calendar cal = floruitList.getCalendar(floruitDate.getId());
|
|
286
|
|
287 if(floruitDate0.getAttributeByName("date") == null){
|
|
288 floruitDate0.addAttribute(new Attribute("date", "date", cal.toJSONString()));
|
|
289 }else{
|
|
290 floruitDate0.getAttributeByName("date").setValue(cal.toJSONString());
|
|
291 }
|
|
292 getWrapper().saveAssertion(floruitDate0, getUserName());
|
|
293 Relation hasFloruitDate = new Relation(this.entity, floruitDate0, has_floruit_date);
|
|
294 }
|
|
295
|
|
296 //PERSON -> student of manyToMany -> PERSON
|
|
297 this.entity.removeAllSourceRelationsByName(was_student_of);
|
|
298 for(Entity teacher : this.studentOfList.getEntities()){
|
|
299 Entity teacher0 = getWrapper().getEntityByIdWithContent(teacher.getId());
|
|
300 Relation studentOf = new Relation(this.entity, teacher0, was_student_of);
|
|
301 }
|
|
302
|
|
303 //PERSON -> has_role -> ROLE
|
|
304 this.entity.removeAllSourceRelationsByName(has_role);
|
|
305 for(Entity role : this.roleList.getEntities()){
|
|
306 Entity role0 = getWrapper().getEntityByIdWithContent(role.getId());
|
|
307 Relation hasRole = new Relation(this.entity, role0, has_role);
|
|
308 }
|
|
309
|
|
310 //REFERENCE -> is_reference_of -> THIS
|
|
311 //this.entity = this.prepareReferencesToSave(this.entity);
|
|
312 this.prepareEndNoteRefs2Save();
|
|
313
|
|
314 this.entity = getWrapper().saveEntity(this.entity, getSessionUser().getEmail());
|
|
315 this.setEntity(this.entity);
|
|
316 this.getCache().setMapDirty(true);
|
|
317 this.getAppBean().getBiographyBean().makeDirty();
|
|
318
|
|
319 logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity);
|
|
320 this.printSuccessSavingEntity();
|
|
321
|
|
322 //getPopup().setRendered(false);
|
|
323
|
|
324
|
|
325 //setPopupText("CHANGING");
|
|
326
|
|
327 } catch (Exception e) {
|
|
328 logger.error(e.getMessage(), e);
|
|
329 e.printStackTrace();
|
|
330 this.printInternalError(e);
|
|
331 }
|
|
332 saveEnd();
|
|
333 return PAGE_EDITOR;
|
|
334 }
|
|
335
|
|
336 public void listenerEditCalendarForLivedInPlaces(ActionEvent event){
|
|
337 Entity entity = (Entity)getRequestBean("item");
|
|
338 if(entity != null){
|
|
339 Calendar cal = this.livedInPlaces.getCalendar(entity.getId());
|
|
340 getSessionBean().editCalendar(cal, livedInPlaces, entity.getId());
|
|
341 }
|
|
342 }
|
|
343
|
|
344 public void listenerEditCalendarForFloruitDate(ActionEvent event){
|
|
345 Entity entity = (Entity)getRequestBean("item");
|
|
346 if(entity != null){
|
|
347 Calendar cal = this.floruitList.getCalendar(entity.getId());
|
|
348 getSessionBean().editCalendar(cal, floruitList, entity.getId());
|
|
349 }
|
|
350 }
|
|
351
|
|
352 public void listenerRomanizeNameTranslit(AjaxBehaviorEvent event){
|
|
353 if(getAttributes().get("name_translit") != null)
|
|
354 this.romanizedNameTranslit = RomanizationLoC.convert(getAttributes().get("name_translit"));
|
|
355 }
|
|
356
|
|
357 public Entity getShortName() {
|
|
358 return shortNameAlias;
|
|
359 }
|
|
360
|
|
361 public void setShortName(Entity shortName) {
|
|
362 this.shortNameAlias = shortName;
|
|
363 }
|
|
364
|
|
365 public String getValueShortName() {
|
|
366 return valueShortName;
|
|
367 }
|
|
368
|
|
369 public void setValueShortName(String valueShortName) {
|
|
370 this.valueShortName = valueShortName;
|
|
371 }
|
|
372
|
|
373 public void setToDate(Object x) {
|
|
374 System.out.println("hello");
|
|
375 }
|
|
376
|
|
377 public Converter getToDate() {
|
|
378 return new myDateTimeConverter();
|
|
379
|
|
380 }
|
|
381
|
|
382 public Map<String, Boolean> getDeletedAliases() {
|
|
383 return deletedAliases;
|
|
384 }
|
|
385
|
|
386 public void setDeletedAliases(Map<String, Boolean> deletedAliases) {
|
|
387 this.deletedAliases = deletedAliases;
|
|
388 }
|
|
389
|
|
390 public void setNewAlias(String newAlias) {
|
|
391 this.newAlias = newAlias;
|
|
392 }
|
|
393
|
|
394 public String getNewAlias() {
|
|
395 return newAlias;
|
|
396 }
|
|
397
|
|
398 public String editMe(){
|
|
399 if(this.entity != null){
|
|
400 getSessionBean().editEntity(this.entity);
|
|
401 return "entry_edit_entity";
|
|
402 }
|
|
403 return "";
|
|
404 }
|
|
405
|
|
406 public void setBirthPlaceLo(ListenerObject birthPlaceLo) {
|
|
407 this.birthPlaceLo = birthPlaceLo;
|
|
408 }
|
|
409
|
|
410 public ListenerObject getBirthPlaceLo() {
|
|
411 return birthPlaceLo;
|
|
412 }
|
|
413
|
|
414 public ListenerObject getDeathPlaceLo() {
|
|
415 return deathPlaceLo;
|
|
416 }
|
|
417
|
|
418 public void setDeathPlaceLo(ListenerObject deathPlaceLo) {
|
|
419 this.deathPlaceLo = deathPlaceLo;
|
|
420 }
|
|
421
|
|
422 public EntityList getLivedInPlaces() {
|
|
423 return livedInPlaces;
|
|
424 }
|
|
425
|
|
426 public void setLivedInPlaces(EntityList livedInPlaces) {
|
|
427 this.livedInPlaces = livedInPlaces;
|
|
428 }
|
|
429
|
|
430 public EntityList getStudentOfList() {
|
|
431 return studentOfList;
|
|
432 }
|
|
433
|
|
434
|
|
435 public void setStudentOfList(EntityList studentOfList) {
|
|
436 this.studentOfList = studentOfList;
|
|
437 }
|
|
438
|
|
439 public EntityList getFloruitList() {
|
|
440 return floruitList;
|
|
441 }
|
|
442
|
|
443 public void setFloruitList(EntityList floruitList) {
|
|
444 this.floruitList = floruitList;
|
|
445 }
|
|
446
|
|
447 public String getRomanizedNameTranslit() {
|
|
448 return romanizedNameTranslit;
|
|
449 }
|
|
450
|
|
451 public void setRomanizedNameTranslit(String romanizedNameTranslit) {
|
|
452 this.romanizedNameTranslit = romanizedNameTranslit;
|
|
453 }
|
|
454 }
|